Jon Gauthier
commited on
Commit
·
d482c79
1
Parent(s):
452d201
support loading all suites by default; represent multiple suites within dataset with suite_name feature
Browse files- syntaxgym.py +40 -21
syntaxgym.py
CHANGED
@@ -53,6 +53,14 @@ class SyntaxGymSuiteConfig(datasets.BuilderConfig):
|
|
53 |
**kwargs)
|
54 |
|
55 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
56 |
SUITE_DATASET_CONDITION_SPEC = {
|
57 |
"condition_name": datasets.Value("string"),
|
58 |
"content": datasets.Value("string"),
|
@@ -63,6 +71,7 @@ SUITE_DATASET_CONDITION_SPEC = {
|
|
63 |
}
|
64 |
|
65 |
SUITE_DATASET_SPEC = {
|
|
|
66 |
"item_number": datasets.Value("int32"),
|
67 |
"conditions": datasets.Sequence(SUITE_DATASET_CONDITION_SPEC),
|
68 |
"predictions": datasets.Sequence(datasets.Value("string")),
|
@@ -86,8 +95,10 @@ class SyntaxGym(datasets.GeneratorBasedBuilder):
|
|
86 |
"subordination", "subordination_orc-orc",
|
87 |
"subordination_pp-pp", "subordination_src-src",
|
88 |
]
|
89 |
-
BUILDER_CONFIGS =
|
90 |
-
|
|
|
|
|
91 |
|
92 |
def _info(self):
|
93 |
citation = ""
|
@@ -103,24 +114,32 @@ class SyntaxGym(datasets.GeneratorBasedBuilder):
|
|
103 |
citation=citation,
|
104 |
)
|
105 |
|
106 |
-
def
|
107 |
-
|
108 |
-
downloaded_file = dl_manager.download_and_extract(download_url)
|
109 |
-
return [datasets.SplitGenerator(name=datasets.Split.TEST,
|
110 |
-
gen_kwargs={"filepath": downloaded_file})]
|
111 |
-
|
112 |
-
def _generate_examples(self, filepath):
|
113 |
-
with open(filepath, "r", encoding="utf-8") as f:
|
114 |
-
suite_json = json.load(f)
|
115 |
|
116 |
-
|
117 |
-
|
118 |
-
|
119 |
-
|
120 |
-
|
121 |
-
|
122 |
-
|
123 |
-
|
124 |
-
|
125 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
126 |
|
|
|
53 |
**kwargs)
|
54 |
|
55 |
|
56 |
+
class SyntaxGymAll2020SuitesConfig(datasets.BuilderConfig):
|
57 |
+
|
58 |
+
def __init__(self, **kwargs):
|
59 |
+
super().__init__(
|
60 |
+
name="all-2020",
|
61 |
+
description="All SyntaxGym test suites from Hu et al. (2020).\n" + _DESCRIPTION)
|
62 |
+
|
63 |
+
|
64 |
SUITE_DATASET_CONDITION_SPEC = {
|
65 |
"condition_name": datasets.Value("string"),
|
66 |
"content": datasets.Value("string"),
|
|
|
71 |
}
|
72 |
|
73 |
SUITE_DATASET_SPEC = {
|
74 |
+
"suite_name": datasets.Value("string"),
|
75 |
"item_number": datasets.Value("int32"),
|
76 |
"conditions": datasets.Sequence(SUITE_DATASET_CONDITION_SPEC),
|
77 |
"predictions": datasets.Sequence(datasets.Value("string")),
|
|
|
95 |
"subordination", "subordination_orc-orc",
|
96 |
"subordination_pp-pp", "subordination_src-src",
|
97 |
]
|
98 |
+
BUILDER_CONFIGS = \
|
99 |
+
[SyntaxGymSuiteConfig(suite_name) for suite_name in SUITES] + \
|
100 |
+
[SyntaxGymAll2020SuitesConfig()]
|
101 |
+
DEFAULT_CONFIG_NAME = "all-2020"
|
102 |
|
103 |
def _info(self):
|
104 |
citation = ""
|
|
|
114 |
citation=citation,
|
115 |
)
|
116 |
|
117 |
+
def _download_suite(self, name, dl_manager: datasets.DownloadManager):
|
118 |
+
return dl_manager.download_and_extract(_DOWNLOAD_URL + f"{name}.json")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
119 |
|
120 |
+
def _split_generators(self, dl_manager: datasets.DownloadManager) -> List[datasets.SplitGenerator]:
|
121 |
+
if isinstance(self.config, SyntaxGymAll2020SuitesConfig):
|
122 |
+
paths = [self._download_suite(suite_name, dl_manager) for suite_name in self.SUITES]
|
123 |
+
else:
|
124 |
+
paths = [self._download_suite(self.config.name, dl_manager)]
|
125 |
+
|
126 |
+
return [datasets.SplitGenerator(name=datasets.Split.TEST, gen_kwargs={"paths": paths})]
|
127 |
+
|
128 |
+
def _generate_examples(self, paths):
|
129 |
+
for path in paths:
|
130 |
+
with open(path, "r", encoding="utf-8") as f:
|
131 |
+
suite_json = json.load(f)
|
132 |
+
|
133 |
+
suite_name = suite_json["meta"]["name"]
|
134 |
+
predictions = [p["formula"] for p in suite_json["predictions"]]
|
135 |
+
|
136 |
+
for item in suite_json["items"]:
|
137 |
+
# Convert to sentence input.
|
138 |
+
for cond in item["conditions"]:
|
139 |
+
cond["content"] = condition_to_string(cond)
|
140 |
+
|
141 |
+
item["suite_name"] = suite_name
|
142 |
+
item["predictions"] = predictions
|
143 |
+
|
144 |
+
yield f"{suite_name}/{item['item_number']}", item
|
145 |
|