Datasets:

Languages:
English
ArXiv:
License:
phucdev commited on
Commit
21dd623
1 Parent(s): 9b5c795

Add builder config for Re-TACRED and update _generate_examples method

Browse files
Files changed (1) hide show
  1. tacred.py +82 -5
tacred.py CHANGED
@@ -52,6 +52,22 @@ _CITATION = """\
52
  doi = "10.18653/v1/2020.acl-main.142",
53
  pages = "1558--1569",
54
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
55
  """
56
 
57
  _DESCRIPTION = """\
@@ -86,6 +102,11 @@ _PATCH_URLs = {
86
  "dev": "https://raw.githubusercontent.com/DFKI-NLP/tacrev/master/patch/dev_patch.json",
87
  "test": "https://raw.githubusercontent.com/DFKI-NLP/tacrev/master/patch/test_patch.json",
88
  }
 
 
 
 
 
89
 
90
  _VERSION = datasets.Version("1.0.0")
91
 
@@ -134,6 +155,49 @@ _CLASS_LABELS = [
134
  "per:title",
135
  ]
136
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
137
  _NER_CLASS_LABELS = [
138
  "LOCATION",
139
  "ORGANIZATION",
@@ -183,10 +247,15 @@ class Tacred(datasets.GeneratorBasedBuilder):
183
  name="original", version=_VERSION, description="The original TACRED."
184
  ),
185
  datasets.BuilderConfig(
186
- name="revised",
187
  version=_VERSION,
188
- description="The revised TACRED (corrected labels in dev and test split).",
189
  ),
 
 
 
 
 
190
  ]
191
 
192
  DEFAULT_CONFIG_NAME = "original" # type: ignore
@@ -245,8 +314,10 @@ class Tacred(datasets.GeneratorBasedBuilder):
245
  # It can accept any type or nested list/dict and will give back the same structure with the url replaced with path to local files.
246
  # By default the archives will be extracted and a path to a cached folder where they are extracted is returned instead of the archive
247
  patch_files = {}
248
- if self.config.name == "revised":
249
  patch_files = dl_manager.download_and_extract(_PATCH_URLs)
 
 
250
 
251
  data_dir = os.path.abspath(os.path.expanduser(dl_manager.manual_dir))
252
 
@@ -262,7 +333,7 @@ class Tacred(datasets.GeneratorBasedBuilder):
262
  name=datasets.Split.TRAIN,
263
  gen_kwargs={
264
  "filepath": os.path.join(data_dir, "train.json"),
265
- "patch_filepath": None,
266
  },
267
  ),
268
  datasets.SplitGenerator(
@@ -289,7 +360,10 @@ class Tacred(datasets.GeneratorBasedBuilder):
289
  patch_examples = {}
290
  if patch_filepath is not None:
291
  with open(patch_filepath, encoding="utf-8") as f:
292
- patch_examples = {example["id"]: example for example in json.load(f)}
 
 
 
293
 
294
  with open(filepath, encoding="utf-8") as f:
295
  data = json.load(f)
@@ -298,6 +372,9 @@ class Tacred(datasets.GeneratorBasedBuilder):
298
 
299
  if id_ in patch_examples:
300
  example.update(patch_examples[id_])
 
 
 
301
 
302
  yield id_, {
303
  "id": example["id"],
 
52
  doi = "10.18653/v1/2020.acl-main.142",
53
  pages = "1558--1569",
54
  }
55
+
56
+ @article{stoica2021re,
57
+ author = {George Stoica and
58
+ Emmanouil Antonios Platanios and
59
+ Barnab{\'{a}}s P{\'{o}}czos},
60
+ title = {Re-TACRED: Addressing Shortcomings of the {TACRED} Dataset},
61
+ journal = {CoRR},
62
+ volume = {abs/2104.08398},
63
+ year = {2021},
64
+ url = {https://arxiv.org/abs/2104.08398},
65
+ eprinttype = {arXiv},
66
+ eprint = {2104.08398},
67
+ timestamp = {Mon, 26 Apr 2021 17:25:10 +0200},
68
+ biburl = {https://dblp.org/rec/journals/corr/abs-2104-08398.bib},
69
+ bibsource = {dblp computer science bibliography, https://dblp.org}
70
+ }
71
  """
72
 
73
  _DESCRIPTION = """\
 
102
  "dev": "https://raw.githubusercontent.com/DFKI-NLP/tacrev/master/patch/dev_patch.json",
103
  "test": "https://raw.githubusercontent.com/DFKI-NLP/tacrev/master/patch/test_patch.json",
104
  }
105
+ _RETACRED_PATCH_URLs = {
106
+ "train": "https://raw.githubusercontent.com/gstoica27/Re-TACRED/master/Re-TACRED/train_id2label.json",
107
+ "dev": "https://raw.githubusercontent.com/gstoica27/Re-TACRED/master/Re-TACRED/dev_id2label.json",
108
+ "test": "https://raw.githubusercontent.com/gstoica27/Re-TACRED/master/Re-TACRED/test_id2label.json"
109
+ }
110
 
111
  _VERSION = datasets.Version("1.0.0")
112
 
 
155
  "per:title",
156
  ]
157
 
158
+ _RETACRED_CLASS_LABELS = [
159
+ "no_relation",
160
+ "org:alternate_names",
161
+ "org:city_of_branch",
162
+ "org:country_of_branch",
163
+ "org:dissolved",
164
+ "org:founded",
165
+ "org:founded_by",
166
+ "org:member_of",
167
+ "org:members",
168
+ "org:number_of_employees/members",
169
+ "org:political/religious_affiliation",
170
+ "org:shareholders",
171
+ "org:stateorprovince_of_branch",
172
+ "org:top_members/employees",
173
+ "org:website",
174
+ "per:age",
175
+ "per:cause_of_death",
176
+ "per:charges",
177
+ "per:children",
178
+ "per:cities_of_residence",
179
+ "per:city_of_birth",
180
+ "per:city_of_death",
181
+ "per:countries_of_residence",
182
+ "per:country_of_birth",
183
+ "per:country_of_death",
184
+ "per:date_of_birth",
185
+ "per:date_of_death",
186
+ "per:employee_of",
187
+ "per:identity",
188
+ "per:origin",
189
+ "per:other_family",
190
+ "per:parents",
191
+ "per:religion",
192
+ "per:schools_attended",
193
+ "per:siblings",
194
+ "per:spouse",
195
+ "per:stateorprovince_of_birth",
196
+ "per:stateorprovince_of_death",
197
+ "per:stateorprovinces_of_residence",
198
+ "per:title"
199
+ ]
200
+
201
  _NER_CLASS_LABELS = [
202
  "LOCATION",
203
  "ORGANIZATION",
 
247
  name="original", version=_VERSION, description="The original TACRED."
248
  ),
249
  datasets.BuilderConfig(
250
+ name="revisited",
251
  version=_VERSION,
252
+ description="TACRED Revisited (corrected labels for 5k most challenging examples in dev and test split).",
253
  ),
254
+ datasets.BuilderConfig(
255
+ name="re-tacred",
256
+ version=datasets.Version("1.1.0"),
257
+ description="Relabeled TACRED (corrected labels for all splits and pruned)"
258
+ )
259
  ]
260
 
261
  DEFAULT_CONFIG_NAME = "original" # type: ignore
 
314
  # It can accept any type or nested list/dict and will give back the same structure with the url replaced with path to local files.
315
  # By default the archives will be extracted and a path to a cached folder where they are extracted is returned instead of the archive
316
  patch_files = {}
317
+ if self.config.name == "revisited":
318
  patch_files = dl_manager.download_and_extract(_PATCH_URLs)
319
+ elif self.config.name == "re-tacred":
320
+ patch_files = dl_manager.download_and_extract(_RETACRED_PATCH_URLs)
321
 
322
  data_dir = os.path.abspath(os.path.expanduser(dl_manager.manual_dir))
323
 
 
333
  name=datasets.Split.TRAIN,
334
  gen_kwargs={
335
  "filepath": os.path.join(data_dir, "train.json"),
336
+ "patch_filepath": patch_files.get("train"),
337
  },
338
  ),
339
  datasets.SplitGenerator(
 
360
  patch_examples = {}
361
  if patch_filepath is not None:
362
  with open(patch_filepath, encoding="utf-8") as f:
363
+ if self.config.name == "revisited":
364
+ patch_examples = {example["id"]: example for example in json.load(f)}
365
+ elif self.config.name == "re-tacred":
366
+ patch_examples = {_id: {"id": _id, "label": label} for _id, label in json.load(f).items()}
367
 
368
  with open(filepath, encoding="utf-8") as f:
369
  data = json.load(f)
 
372
 
373
  if id_ in patch_examples:
374
  example.update(patch_examples[id_])
375
+ elif self.config.name == "re-tacred":
376
+ # RE-TACRED was pruned, skip example if its id is not in patch_examples
377
+ continue
378
 
379
  yield id_, {
380
  "id": example["id"],