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script.ipynb
|
| 3 |
+
Automatically generated by Colaboratory.
|
| 4 |
+
Original file is located at
|
| 5 |
+
https://colab.research.google.com/drive/1q9DdeHA5JbgTHkH6kfZe_KWHQOwHZA97
|
| 6 |
+
"""
|
| 7 |
+
# coding=utf-8
|
| 8 |
+
# Copyright 2019 The CLUTRR Datasets Authors and the HuggingFace Datasets Authors.
|
| 9 |
+
#
|
| 10 |
+
# CLUTRR is CC-BY-NC 4.0 (Attr Non-Commercial Inter.) licensed, as found in the LICENSE file.
|
| 11 |
+
#
|
| 12 |
+
# Unless required by applicable law or agreed to in writing, software
|
| 13 |
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
| 14 |
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
| 15 |
+
# See the License for the specific language governing permissions and
|
| 16 |
+
# limitations under the License.
|
| 17 |
+
|
| 18 |
+
# Lint as: python3
|
| 19 |
+
"""The CLUTRR (Compositional Language Understanding and Text-based Relational Reasoning) benchmark."""
|
| 20 |
+
|
| 21 |
+
|
| 22 |
+
import csv
|
| 23 |
+
import os
|
| 24 |
+
import textwrap
|
| 25 |
+
|
| 26 |
+
import numpy as np
|
| 27 |
+
|
| 28 |
+
import datasets
|
| 29 |
+
import json
|
| 30 |
+
|
| 31 |
+
_CLUTRR_CITATION = """\
|
| 32 |
+
@article{sinha2019clutrr,
|
| 33 |
+
Author = {Koustuv Sinha and Shagun Sodhani and Jin Dong and Joelle Pineau and William L. Hamilton},
|
| 34 |
+
Title = {CLUTRR: A Diagnostic Benchmark for Inductive Reasoning from Text},
|
| 35 |
+
Year = {2019},
|
| 36 |
+
journal = {Empirical Methods of Natural Language Processing (EMNLP)},
|
| 37 |
+
arxiv = {1908.06177}
|
| 38 |
+
}
|
| 39 |
+
"""
|
| 40 |
+
|
| 41 |
+
_CLUTRR_DESCRIPTION = """\
|
| 42 |
+
CLUTRR (Compositional Language Understanding and Text-based Relational Reasoning),
|
| 43 |
+
a diagnostic benchmark suite, is first introduced in (https://arxiv.org/abs/1908.06177)
|
| 44 |
+
to test the systematic generalization and inductive reasoning capabilities of NLU systems.
|
| 45 |
+
"""
|
| 46 |
+
_URL = "https://raw.githubusercontent.com/kliang5/CLUTRR_huggingface_dataset/main/"
|
| 47 |
+
_TASK = ["gen_train23_test2to10", "gen_train234_test2to10", "rob_train_clean_23_test_all_23", "rob_train_disc_23_test_all_23", "rob_train_irr_23_test_all_23","rob_train_sup_23_test_all_23"]
|
| 48 |
+
|
| 49 |
+
class v1(datasets.GeneratorBasedBuilder):
|
| 50 |
+
"""BuilderConfig for CLUTRR."""
|
| 51 |
+
|
| 52 |
+
BUILDER_CONFIGS = [
|
| 53 |
+
datasets.BuilderConfig(
|
| 54 |
+
name=task,
|
| 55 |
+
version=datasets.Version("1.0.0"),
|
| 56 |
+
description="",
|
| 57 |
+
)
|
| 58 |
+
for task in _TASK
|
| 59 |
+
]
|
| 60 |
+
|
| 61 |
+
def _info(self):
|
| 62 |
+
return datasets.DatasetInfo(
|
| 63 |
+
description=_CLUTRR_DESCRIPTION,
|
| 64 |
+
features=datasets.Features(
|
| 65 |
+
{
|
| 66 |
+
"id": datasets.Value("string"),
|
| 67 |
+
"story": datasets.Value("string"),
|
| 68 |
+
"query": datasets.Value("string"),
|
| 69 |
+
"target": datasets.Value("int32"),
|
| 70 |
+
"target_text": datasets.Value("string"),
|
| 71 |
+
"clean_story": datasets.Value("string"),
|
| 72 |
+
"proof_state": datasets.Value("string"),
|
| 73 |
+
"f_comb": datasets.Value("string"),
|
| 74 |
+
"task_name": datasets.Value("string"),
|
| 75 |
+
"story_edges": datasets.Value("string"),
|
| 76 |
+
"edge_types": datasets.Value("string"),
|
| 77 |
+
"query_edge": datasets.Value("string"),
|
| 78 |
+
"genders": datasets.Value("string"),
|
| 79 |
+
"task_split": datasets.Value("string"),
|
| 80 |
+
}
|
| 81 |
+
),
|
| 82 |
+
# No default supervised_keys (as we have to pass both premise
|
| 83 |
+
# and hypothesis as input).
|
| 84 |
+
supervised_keys=None,
|
| 85 |
+
homepage="https://www.cs.mcgill.ca/~ksinha4/clutrr/",
|
| 86 |
+
citation=_CLUTRR_CITATION,
|
| 87 |
+
)
|
| 88 |
+
|
| 89 |
+
def _split_generators(self, dl_manager):
|
| 90 |
+
"""Returns SplitGenerators."""
|
| 91 |
+
# dl_manager is a datasets.download.DownloadManager that can be used to
|
| 92 |
+
# download and extract URLs
|
| 93 |
+
|
| 94 |
+
task = str(self.config.name)
|
| 95 |
+
urls_to_download = {
|
| 96 |
+
"test": _URL + task + "/test.csv",
|
| 97 |
+
"train": _URL + task + "/train.csv",
|
| 98 |
+
"validation": _URL + task + "/validation.csv",
|
| 99 |
+
}
|
| 100 |
+
downloaded_files = dl_manager.download_and_extract(urls_to_download)
|
| 101 |
+
|
| 102 |
+
|
| 103 |
+
return [
|
| 104 |
+
datasets.SplitGenerator(
|
| 105 |
+
name=datasets.Split.TRAIN,
|
| 106 |
+
# These kwargs will be passed to _generate_examples
|
| 107 |
+
gen_kwargs={
|
| 108 |
+
"filepath": downloaded_files["train"],
|
| 109 |
+
"task": task,
|
| 110 |
+
},
|
| 111 |
+
),
|
| 112 |
+
datasets.SplitGenerator(
|
| 113 |
+
name=datasets.Split.VALIDATION,
|
| 114 |
+
# These kwargs will be passed to _generate_examples
|
| 115 |
+
gen_kwargs={
|
| 116 |
+
"filepath": downloaded_files["validation"],
|
| 117 |
+
"task": task,
|
| 118 |
+
},
|
| 119 |
+
),
|
| 120 |
+
datasets.SplitGenerator(
|
| 121 |
+
name=datasets.Split.TEST,
|
| 122 |
+
# These kwargs will be passed to _generate_examples
|
| 123 |
+
gen_kwargs={
|
| 124 |
+
"filepath": downloaded_files["test"],
|
| 125 |
+
"task": task,
|
| 126 |
+
},
|
| 127 |
+
),
|
| 128 |
+
]
|
| 129 |
+
|
| 130 |
+
def _generate_examples(self, filepath, task):
|
| 131 |
+
"""Yields examples."""
|
| 132 |
+
with open(filepath, encoding="utf-8") as f:
|
| 133 |
+
reader = csv.reader(f)
|
| 134 |
+
for id_, data in enumerate(reader):
|
| 135 |
+
if id_ == 0:
|
| 136 |
+
continue
|
| 137 |
+
# yield id_, data
|
| 138 |
+
# id_ += 1
|
| 139 |
+
yield id_, {
|
| 140 |
+
"id": data[1],
|
| 141 |
+
"story": data[2],
|
| 142 |
+
"query": data[3],
|
| 143 |
+
"target": data[4],
|
| 144 |
+
"target_text": data[5],
|
| 145 |
+
"clean_story": data[6],
|
| 146 |
+
"proof_state": data[7],
|
| 147 |
+
"f_comb": data[8],
|
| 148 |
+
"task_name": data[9],
|
| 149 |
+
"story_edges": data[10],
|
| 150 |
+
"edge_types": data[11],
|
| 151 |
+
"query_edge": data[12],
|
| 152 |
+
"genders": data[13],
|
| 153 |
+
"task_split": data[14],
|
| 154 |
+
}
|