Datasets:

Size Categories:
10K<n<100K
ArXiv:
Tags:
License:
PereLluis13 commited on
Commit
7fab33b
1 Parent(s): 74b2895

Upload 20 files

Browse files
.gitattributes CHANGED
@@ -52,3 +52,4 @@ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
52
  *.jpg filter=lfs diff=lfs merge=lfs -text
53
  *.jpeg filter=lfs diff=lfs merge=lfs -text
54
  *.webp filter=lfs diff=lfs merge=lfs -text
 
 
52
  *.jpg filter=lfs diff=lfs merge=lfs -text
53
  *.jpeg filter=lfs diff=lfs merge=lfs -text
54
  *.webp filter=lfs diff=lfs merge=lfs -text
55
+ data/train.en.jsonl filter=lfs diff=lfs merge=lfs -text
data/dev.ar.jsonl ADDED
The diff for this file is too large to render. See raw diff
 
data/dev.de.jsonl ADDED
The diff for this file is too large to render. See raw diff
 
data/dev.en.jsonl ADDED
The diff for this file is too large to render. See raw diff
 
data/dev.es.jsonl ADDED
The diff for this file is too large to render. See raw diff
 
data/dev.fr.jsonl ADDED
The diff for this file is too large to render. See raw diff
 
data/dev.it.jsonl ADDED
The diff for this file is too large to render. See raw diff
 
data/dev.zh.jsonl ADDED
The diff for this file is too large to render. See raw diff
 
data/test.ar.jsonl ADDED
The diff for this file is too large to render. See raw diff
 
data/test.de.jsonl ADDED
The diff for this file is too large to render. See raw diff
 
data/test.en.jsonl ADDED
The diff for this file is too large to render. See raw diff
 
data/test.es.jsonl ADDED
The diff for this file is too large to render. See raw diff
 
data/test.fr.jsonl ADDED
The diff for this file is too large to render. See raw diff
 
data/test.it.jsonl ADDED
The diff for this file is too large to render. See raw diff
 
data/test.zh.jsonl ADDED
The diff for this file is too large to render. See raw diff
 
data/train.de.jsonl ADDED
The diff for this file is too large to render. See raw diff
 
data/train.en.jsonl ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:98b30669ead8e4fb39f1ae06e0488b39087e235c49118cdb9480bc04b6c5e8f3
3
+ size 10595695
data/train.es.jsonl ADDED
The diff for this file is too large to render. See raw diff
 
data/train.fr.jsonl ADDED
The diff for this file is too large to render. See raw diff
 
data/train.it.jsonl ADDED
The diff for this file is too large to render. See raw diff
 
redfm.py ADDED
@@ -0,0 +1,266 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # coding=utf-8
2
+ # Copyright 2020 The TensorFlow Datasets Authors and the HuggingFace Datasets Authors.
3
+ #
4
+ # Licensed under the Apache License, Version 2.0 (the "License");
5
+ # you may not use this file except in compliance with the License.
6
+ # You may obtain a copy of the License at
7
+ #
8
+ # http://www.apache.org/licenses/LICENSE-2.0
9
+ #
10
+ # Unless required by applicable law or agreed to in writing, software
11
+ # distributed under the License is distributed on an "AS IS" BASIS,
12
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ # See the License for the specific language governing permissions and
14
+ # limitations under the License.
15
+
16
+ # Lint as: python3
17
+ """RedFM: a Filtered and Multilingual Relation Extraction Dataset."""
18
+
19
+
20
+ import collections
21
+ import json
22
+ import os
23
+ from contextlib import ExitStack
24
+ import logging
25
+ import datasets
26
+
27
+
28
+ _CITATION = """\
29
+ @InProceedings{redfm2023,
30
+ author = {Huguet Cabot, Pere-Lluis
31
+ and Tedeschi, Simone
32
+ and Ngonga Ngomo, Axel-Cyrille
33
+ and Navigli, Roberto},
34
+ title = {RED\textsuperscript{FM}: a Filtered and Multilingual Relation Extraction Dataset},
35
+ booktitle = {Proceedings of the 2023 Conference on Association for Computational Linguistics},
36
+ year = {2023},
37
+ publisher = {Association for Computational Linguistics},
38
+ location = {Toronto, Canada},
39
+ }"""
40
+
41
+ _DESCRIPTION = """\
42
+ Relation Extraction (RE) is a task that identifies relationships between entities in a text, enabling the acquisition of relational facts and bridging the gap between natural language and structured knowledge. However, current RE models often rely on small datasets with low coverage of relation types, particularly when working with languages other than English. \\
43
+ In this paper, we address the above issue and provide two new resources that enable the training and evaluation of multilingual RE systems.
44
+ First, we present SRED\textsuperscript{FM}, an automatically annotated dataset covering 18 languages, 400 relation types, 13 entity types, totaling more than 40 million triplet instances. Second, we propose RED\textsuperscript{FM}, a smaller, human-revised dataset for seven languages that allows for the evaluation of multilingual RE systems.
45
+ To demonstrate the utility of these novel datasets, we experiment with the first end-to-end multilingual RE model, mREBEL,
46
+ that extracts triplets, including entity types, in multiple languages. We release our resources and model checkpoints at \href{https://www.github.com/babelscape/rebel}{https://www.github.com/babelscape/rebel}.
47
+ """
48
+
49
+ _LANGUAGES = ("ar", "de", "en", "es", "fr", "it", "zh")
50
+
51
+ _URL_train = f"data/train."
52
+ _URL_dev = f"data/dev."
53
+ _URL_test = f"data/test."
54
+
55
+ class RedFMConfig(datasets.BuilderConfig):
56
+ """BuilderConfig for RedFM."""
57
+
58
+ def __init__(self, language: str, languages=None, **kwargs):
59
+ """BuilderConfig for RedFM.
60
+ Args:
61
+ language: One of ar,de,en,es,fr,it,zh, or all_languages
62
+ **kwargs: keyword arguments forwarded to super.
63
+ """
64
+ super(RedFMConfig, self).__init__(**kwargs)
65
+ self.language = language
66
+ if language != "all_languages":
67
+ self.languages = [language]
68
+ else:
69
+ self.languages = languages if languages is not None else _LANGUAGES
70
+
71
+
72
+ class RedFM(datasets.GeneratorBasedBuilder):
73
+ """RedFM: a Filtered and Multilingual Relation Extraction Dataset. Version 1.0.0"""
74
+
75
+ VERSION = datasets.Version("1.0.0", "")
76
+ BUILDER_CONFIG_CLASS = RedFMConfig
77
+ BUILDER_CONFIGS = [
78
+ RedFMConfig(
79
+ name=lang,
80
+ language=lang,
81
+ version=datasets.Version("1.0.0", ""),
82
+ description=f"Plain text import of RedFM for the {lang} language",
83
+ )
84
+ for lang in _LANGUAGES
85
+ ] + [
86
+ RedFMConfig(
87
+ name="all_languages",
88
+ language="all_languages",
89
+ version=datasets.Version("1.0.0", ""),
90
+ description="Plain text import of RedFM for all languages",
91
+ )
92
+ ]
93
+
94
+ def _info(self):
95
+ if self.config.language == "all_languages":
96
+ features = datasets.Features(
97
+ {
98
+ "docid": datasets.Value("string"),
99
+ "title": datasets.Value("string"),
100
+ "uri": datasets.Value("string"),
101
+ "lan": datasets.Value("string"),
102
+ "text": datasets.Value("string"),
103
+ "entities": datasets.Sequence(feature={'uri': datasets.Value(dtype='string'), 'surfaceform': datasets.Value(dtype='string'), 'type': datasets.Value(dtype='string'), 'start': datasets.Value(dtype='int32'), 'end': datasets.Value(dtype='int32')}),
104
+ "relations": datasets.Sequence(feature={'subject': datasets.Features({'uri': datasets.Value(dtype='string'), 'surfaceform': datasets.Value(dtype='string'), 'type': datasets.Value(dtype='string'), 'start': datasets.Value(dtype='int32'), 'end': datasets.Value(dtype='int32')}),
105
+ 'predicate': datasets.ClassLabel(num_classes=32, names=['country', 'place of birth', 'spouse', 'country of citizenship', 'instance of', 'capital', 'child', 'shares border with', 'author', 'director', 'occupation', 'founded by', 'league', 'owned by', 'genre', 'named after', 'follows', 'headquarters location', 'cast member', 'manufacturer', 'located in or next to body of water', 'location', 'part of', 'mouth of the watercourse', 'member of', 'sport', 'characters', 'participant', 'notable work', 'replaces', 'sibling', 'inception']),
106
+ 'object': datasets.Features({'uri': datasets.Value(dtype='string'), 'surfaceform': datasets.Value(dtype='string'), 'type': datasets.Value(dtype='string'), 'start': datasets.Value(dtype='int32'), 'end': datasets.Value(dtype='int32')})}),
107
+ }
108
+ )
109
+ else:
110
+ features = datasets.Features(
111
+ {
112
+ "docid": datasets.Value("string"),
113
+ "title": datasets.Value("string"),
114
+ "uri": datasets.Value("string"),
115
+ "text": datasets.Value("string"),
116
+ "entities": datasets.Sequence(feature={'uri': datasets.Value(dtype='string'), 'surfaceform': datasets.Value(dtype='string'), 'type': datasets.Value(dtype='string'), 'start': datasets.Value(dtype='int32'), 'end': datasets.Value(dtype='int32')}),
117
+ "relations": datasets.Sequence(feature={'subject': datasets.Features({'uri': datasets.Value(dtype='string'), 'surfaceform': datasets.Value(dtype='string'), 'type': datasets.Value(dtype='string'), 'start': datasets.Value(dtype='int32'), 'end': datasets.Value(dtype='int32')}),
118
+ 'predicate': datasets.ClassLabel(num_classes=32, names=['country', 'place of birth', 'spouse', 'country of citizenship', 'instance of', 'capital', 'child', 'shares border with', 'author', 'director', 'occupation', 'founded by', 'league', 'owned by', 'genre', 'named after', 'follows', 'headquarters location', 'cast member', 'manufacturer', 'located in or next to body of water', 'location', 'part of', 'mouth of the watercourse', 'member of', 'sport', 'characters', 'participant', 'notable work', 'replaces', 'sibling', 'inception']),
119
+ 'object': datasets.Features({'uri': datasets.Value(dtype='string'), 'surfaceform': datasets.Value(dtype='string'), 'type': datasets.Value(dtype='string'), 'start': datasets.Value(dtype='int32'), 'end': datasets.Value(dtype='int32')})}),
120
+ }
121
+ )
122
+ return datasets.DatasetInfo(
123
+ description=_DESCRIPTION,
124
+ features=features,
125
+ # No default supervised_keys (as we have to pass both premise
126
+ # and hypothesis as input).
127
+ supervised_keys=None,
128
+ homepage="https://www.github.com/babelscape/rebel",
129
+ citation=_CITATION,
130
+ )
131
+
132
+ def _split_generators(self, dl_manager):
133
+ data_dir = dl_manager.download(
134
+ {
135
+ "train": [f"{_URL_train}{lang}.jsonl" for lang in self.config.languages if lang not in ["zh", "ar"]],
136
+ "dev": [f"{_URL_dev}{lang}.jsonl" for lang in self.config.languages],
137
+ "test": [f"{_URL_test}{lang}.jsonl" for lang in self.config.languages],
138
+ }
139
+ )
140
+ if len(data_dir["train"]) == 0:
141
+ return [
142
+ datasets.SplitGenerator(
143
+ name=datasets.Split.TEST,
144
+ gen_kwargs={
145
+ "filepaths": data_dir["test"],
146
+ "data_format": "RedFM",
147
+ },
148
+ ),
149
+ datasets.SplitGenerator(
150
+ name=datasets.Split.VALIDATION,
151
+ gen_kwargs={
152
+ "filepaths": data_dir["dev"],
153
+ "data_format": "RedFM",
154
+ },
155
+ ),
156
+ ]
157
+ return [
158
+ datasets.SplitGenerator(
159
+ name=datasets.Split.TRAIN,
160
+ gen_kwargs={
161
+ "filepaths": data_dir["train"],
162
+ "data_format": "RedFM",
163
+ },
164
+ ),
165
+ datasets.SplitGenerator(
166
+ name=datasets.Split.TEST,
167
+ gen_kwargs={
168
+ "filepaths": data_dir["test"],
169
+ "data_format": "RedFM",
170
+ },
171
+ ),
172
+ datasets.SplitGenerator(
173
+ name=datasets.Split.VALIDATION,
174
+ gen_kwargs={
175
+ "filepaths": data_dir["dev"],
176
+ "data_format": "RedFM",
177
+ },
178
+ ),
179
+ ]
180
+
181
+ def _generate_examples(self, data_format, filepaths):
182
+ """This function returns the examples in the raw (text) form."""
183
+ logging.info("generating examples from = %s", filepaths)
184
+ if self.config.language == "all_languages":
185
+ for filepath in filepaths:
186
+ with open(filepath, encoding="utf-8") as f:
187
+ for idx, row in enumerate(f):
188
+ data = json.loads(row)
189
+ entities = []
190
+ for entity in data["entities"]:
191
+ entities.append({
192
+ "uri": entity["uri"],
193
+ "surfaceform": entity["surfaceform"],
194
+ "start": entity["boundaries"][0],
195
+ "end": entity["boundaries"][1],
196
+ "type": entity["type"],
197
+ })
198
+ relations = []
199
+ for relation in data["relations"]:
200
+ relations.append({
201
+ "subject": {
202
+ "uri": relation["subject"]["uri"],
203
+ "surfaceform": relation["subject"]["surfaceform"],
204
+ "start": relation["subject"]["boundaries"][0],
205
+ "end": relation["subject"]["boundaries"][1],
206
+ "type": relation["subject"]["type"],
207
+ },
208
+ "predicate": relation["predicate"]["surfaceform"],
209
+ "object": {
210
+ "uri": relation["object"]["uri"],
211
+ "surfaceform": relation["object"]["surfaceform"],
212
+ "start": relation["object"]["boundaries"][0],
213
+ "end": relation["object"]["boundaries"][1],
214
+ "type": relation["object"]["type"],
215
+ },
216
+ })
217
+ yield data["docid"]+ '-' + data["lan"], {
218
+ "docid": data["docid"],
219
+ "title": data["title"],
220
+ "uri": data["uri"],
221
+ "lan": data["lan"],
222
+ "text": data["text"],
223
+ "entities": entities,
224
+ "relations": relations,
225
+ }
226
+ else:
227
+ for filepath in filepaths:
228
+ with open(filepath, encoding="utf-8") as f:
229
+ for idx, row in enumerate(f):
230
+ data = json.loads(row)
231
+ entities = []
232
+ for entity in data["entities"]:
233
+ entities.append({
234
+ "uri": entity["uri"],
235
+ "surfaceform": entity["surfaceform"],
236
+ "start": entity["boundaries"][0],
237
+ "end": entity["boundaries"][1],
238
+ "type": entity["type"],
239
+ })
240
+ relations = []
241
+ for relation in data["relations"]:
242
+ relations.append({
243
+ "subject": {
244
+ "uri": relation["subject"]["uri"],
245
+ "surfaceform": relation["subject"]["surfaceform"],
246
+ "start": relation["subject"]["boundaries"][0],
247
+ "end": relation["subject"]["boundaries"][1],
248
+ "type": relation["subject"]["type"],
249
+ },
250
+ "predicate": relation["predicate"]["surfaceform"],
251
+ "object": {
252
+ "uri": relation["object"]["uri"],
253
+ "surfaceform": relation["object"]["surfaceform"],
254
+ "start": relation["object"]["boundaries"][0],
255
+ "end": relation["object"]["boundaries"][1],
256
+ "type": relation["object"]["type"],
257
+ },
258
+ })
259
+ yield data["docid"], {
260
+ "docid": data["docid"],
261
+ "title": data["title"],
262
+ "uri": data["uri"],
263
+ "text": data["text"],
264
+ "entities": entities,
265
+ "relations": relations,
266
+ }