Nix commited on
Commit
2be5882
1 Parent(s): f44d9f7

Upload v1.py

Browse files
Files changed (1) hide show
  1. v1.py +152 -0
v1.py ADDED
@@ -0,0 +1,152 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # -*- coding: utf-8 -*-
2
+ """CLUTRR_Dataset Loading 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
+ "clean_story": datasets.Value("string"),
71
+ "proof_state": datasets.Value("string"),
72
+ "f_comb": datasets.Value("string"),
73
+ "task_name": datasets.Value("string"),
74
+ "story_edges": datasets.Value("string"),
75
+ "edge_types": datasets.Value("string"),
76
+ "query_edge": datasets.Value("string"),
77
+ "genders": datasets.Value("string"),
78
+ "task_split": datasets.Value("string"),
79
+ }
80
+ ),
81
+ # No default supervised_keys (as we have to pass both premise
82
+ # and hypothesis as input).
83
+ supervised_keys=None,
84
+ homepage="https://www.cs.mcgill.ca/~ksinha4/clutrr/",
85
+ citation=_CLUTRR_CITATION,
86
+ )
87
+
88
+ def _split_generators(self, dl_manager):
89
+ """Returns SplitGenerators."""
90
+ # dl_manager is a datasets.download.DownloadManager that can be used to
91
+ # download and extract URLs
92
+
93
+ task = str(self.config.name)
94
+ urls_to_download = {
95
+ "test": _URL + task + "/test.csv",
96
+ "train": _URL + task + "/train.csv",
97
+ "validation": _URL + task + "/validation.csv",
98
+ }
99
+ downloaded_files = dl_manager.download_and_extract(urls_to_download)
100
+
101
+
102
+ return [
103
+ datasets.SplitGenerator(
104
+ name=datasets.Split.TRAIN,
105
+ # These kwargs will be passed to _generate_examples
106
+ gen_kwargs={
107
+ "filepath": downloaded_files["train"],
108
+ "task": task,
109
+ },
110
+ ),
111
+ datasets.SplitGenerator(
112
+ name=datasets.Split.VALIDATION,
113
+ # These kwargs will be passed to _generate_examples
114
+ gen_kwargs={
115
+ "filepath": downloaded_files["validation"],
116
+ "task": task,
117
+ },
118
+ ),
119
+ datasets.SplitGenerator(
120
+ name=datasets.Split.TEST,
121
+ # These kwargs will be passed to _generate_examples
122
+ gen_kwargs={
123
+ "filepath": downloaded_files["test"],
124
+ "task": task,
125
+ },
126
+ ),
127
+ ]
128
+
129
+ def _generate_examples(self, filepath, task):
130
+ """Yields examples."""
131
+ with open(filepath, encoding="utf-8") as f:
132
+ reader = csv.reader(f)
133
+ for id_, data in enumerate(reader):
134
+ if id_ == 0:
135
+ continue
136
+ # yield id_, data
137
+ # id_ += 1
138
+ yield id_, {
139
+ "id": data[1],
140
+ "story": data[2],
141
+ "query": data[3],
142
+ "target": data[4],
143
+ "clean_story": data[5],
144
+ "proof_state": data[6],
145
+ "f_comb": data[7],
146
+ "task_name": data[8],
147
+ "story_edges": data[9],
148
+ "edge_types": data[10],
149
+ "query_edge": data[11],
150
+ "genders": data[12],
151
+ "task_split": data[13],
152
+ }