Datasets:

Modalities:
Tabular
Text
Languages:
English
ArXiv:
Libraries:
Datasets
License:
phucdev commited on
Commit
643d6a8
·
1 Parent(s): d2377d6

Add data loading script and README.md

Browse files
Files changed (2) hide show
  1. README.md +334 -0
  2. kbp37.py +234 -0
README.md ADDED
@@ -0,0 +1,334 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ annotations_creators:
3
+ - other
4
+ language:
5
+ - en
6
+ language_creators:
7
+ - found
8
+ license:
9
+ - other
10
+ multilinguality:
11
+ - monolingual
12
+ pretty_name: KBP37 is an English Relation Classification dataset
13
+ size_categories:
14
+ - 10K<n<100K
15
+ source_datasets:
16
+ - extended|other
17
+ tags:
18
+ - relation extraction
19
+ task_categories:
20
+ - text-classification
21
+ task_ids:
22
+ - multi-class-classification
23
+ dataset_info:
24
+ - config_name: kbp37
25
+ features:
26
+ - name: id
27
+ dtype: string
28
+ - name: sentence
29
+ dtype: string
30
+ - name: relation
31
+ dtype:
32
+ class_label:
33
+ names:
34
+ '0': no_relation
35
+ '1': org:alternate_names(e1,e2)
36
+ '2': org:alternate_names(e2,e1)
37
+ '3': org:city_of_headquarters(e1,e2)
38
+ '4': org:city_of_headquarters(e2,e1)
39
+ '5': org:country_of_headquarters(e1,e2)
40
+ '6': org:country_of_headquarters(e2,e1)
41
+ '7': org:founded(e1,e2)
42
+ '8': org:founded(e2,e1)
43
+ '9': org:founded_by(e1,e2)
44
+ '10': org:founded_by(e2,e1)
45
+ '11': org:members(e1,e2)
46
+ '12': org:members(e2,e1)
47
+ '13': org:stateorprovince_of_headquarters(e1,e2)
48
+ '14': org:stateorprovince_of_headquarters(e2,e1)
49
+ '15': org:subsidiaries(e1,e2)
50
+ '16': org:subsidiaries(e2,e1)
51
+ '17': org:top_members/employees(e1,e2)
52
+ '18': org:top_members/employees(e2,e1)
53
+ '19': per:alternate_names(e1,e2)
54
+ '20': per:alternate_names(e2,e1)
55
+ '21': per:cities_of_residence(e1,e2)
56
+ '22': per:cities_of_residence(e2,e1)
57
+ '23': per:countries_of_residence(e1,e2)
58
+ '24': per:countries_of_residence(e2,e1)
59
+ '25': per:country_of_birth(e1,e2)
60
+ '26': per:country_of_birth(e2,e1)
61
+ '27': per:employee_of(e1,e2)
62
+ '28': per:employee_of(e2,e1)
63
+ '29': per:origin(e1,e2)
64
+ '30': per:origin(e2,e1)
65
+ '31': per:spouse(e1,e2)
66
+ '32': per:spouse(e2,e1)
67
+ '33': per:stateorprovinces_of_residence(e1,e2)
68
+ '34': per:stateorprovinces_of_residence(e2,e1)
69
+ '35': per:title(e1,e2)
70
+ '36': per:title(e2,e1)
71
+ splits:
72
+ - name: train
73
+ num_bytes: 3570626
74
+ num_examples: 15917
75
+ - name: validation
76
+ num_bytes: 388935
77
+ num_examples: 1724
78
+ - name: test
79
+ num_bytes: 762806
80
+ num_examples: 3405
81
+ download_size: 5106673
82
+ dataset_size: 4722367
83
+ - config_name: kbp37_formatted
84
+ features:
85
+ - name: id
86
+ dtype: string
87
+ - name: token
88
+ sequence: string
89
+ - name: subj_start
90
+ dtype: int32
91
+ - name: subj_end
92
+ dtype: int32
93
+ - name: obj_start
94
+ dtype: int32
95
+ - name: obj_end
96
+ dtype: int32
97
+ - name: relation
98
+ dtype:
99
+ class_label:
100
+ names:
101
+ '0': no_relation
102
+ '1': org:alternate_names(e1,e2)
103
+ '2': org:alternate_names(e2,e1)
104
+ '3': org:city_of_headquarters(e1,e2)
105
+ '4': org:city_of_headquarters(e2,e1)
106
+ '5': org:country_of_headquarters(e1,e2)
107
+ '6': org:country_of_headquarters(e2,e1)
108
+ '7': org:founded(e1,e2)
109
+ '8': org:founded(e2,e1)
110
+ '9': org:founded_by(e1,e2)
111
+ '10': org:founded_by(e2,e1)
112
+ '11': org:members(e1,e2)
113
+ '12': org:members(e2,e1)
114
+ '13': org:stateorprovince_of_headquarters(e1,e2)
115
+ '14': org:stateorprovince_of_headquarters(e2,e1)
116
+ '15': org:subsidiaries(e1,e2)
117
+ '16': org:subsidiaries(e2,e1)
118
+ '17': org:top_members/employees(e1,e2)
119
+ '18': org:top_members/employees(e2,e1)
120
+ '19': per:alternate_names(e1,e2)
121
+ '20': per:alternate_names(e2,e1)
122
+ '21': per:cities_of_residence(e1,e2)
123
+ '22': per:cities_of_residence(e2,e1)
124
+ '23': per:countries_of_residence(e1,e2)
125
+ '24': per:countries_of_residence(e2,e1)
126
+ '25': per:country_of_birth(e1,e2)
127
+ '26': per:country_of_birth(e2,e1)
128
+ '27': per:employee_of(e1,e2)
129
+ '28': per:employee_of(e2,e1)
130
+ '29': per:origin(e1,e2)
131
+ '30': per:origin(e2,e1)
132
+ '31': per:spouse(e1,e2)
133
+ '32': per:spouse(e2,e1)
134
+ '33': per:stateorprovinces_of_residence(e1,e2)
135
+ '34': per:stateorprovinces_of_residence(e2,e1)
136
+ '35': per:title(e1,e2)
137
+ '36': per:title(e2,e1)
138
+ splits:
139
+ - name: train
140
+ num_bytes: 4975792
141
+ num_examples: 15917
142
+ - name: validation
143
+ num_bytes: 542576
144
+ num_examples: 1724
145
+ - name: test
146
+ num_bytes: 1062977
147
+ num_examples: 3405
148
+ download_size: 5106673
149
+ dataset_size: 6581345
150
+ ---
151
+ # Dataset Card for "kbp37"
152
+ ## Table of Contents
153
+ - [Table of Contents](#table-of-contents)
154
+ - [Dataset Description](#dataset-description)
155
+ - [Dataset Summary](#dataset-summary)
156
+ - [Supported Tasks and Leaderboards](#supported-tasks-and-leaderboards)
157
+ - [Languages](#languages)
158
+ - [Dataset Structure](#dataset-structure)
159
+ - [Data Instances](#data-instances)
160
+ - [Data Fields](#data-fields)
161
+ - [Data Splits](#data-splits)
162
+ - [Dataset Creation](#dataset-creation)
163
+ - [Curation Rationale](#curation-rationale)
164
+ - [Source Data](#source-data)
165
+ - [Annotations](#annotations)
166
+ - [Personal and Sensitive Information](#personal-and-sensitive-information)
167
+ - [Considerations for Using the Data](#considerations-for-using-the-data)
168
+ - [Social Impact of Dataset](#social-impact-of-dataset)
169
+ - [Discussion of Biases](#discussion-of-biases)
170
+ - [Other Known Limitations](#other-known-limitations)
171
+ - [Additional Information](#additional-information)
172
+ - [Dataset Curators](#dataset-curators)
173
+ - [Licensing Information](#licensing-information)
174
+ - [Citation Information](#citation-information)
175
+ - [Contributions](#contributions)
176
+
177
+ ## Dataset Description
178
+ - **Homepage:** [More Information Needed](https://github.com/huggingface/datasets/blob/master/CONTRIBUTING.md#how-to-contribute-to-the-dataset-cards)
179
+ - **Repository:** [kbp37](https://github.com/zhangdongxu/kbp37)
180
+ - **Paper:** [Relation Classification via Recurrent Neural Network](https://arxiv.org/abs/1508.01006)
181
+ - **Point of Contact:** [More Information Needed](https://github.com/huggingface/datasets/blob/master/CONTRIBUTING.md#how-to-contribute-to-the-dataset-cards)
182
+ - **Size of downloaded dataset files:** 5.11 MB
183
+ - **Size of the generated dataset:** 6.58 MB
184
+
185
+ ### Dataset Summary
186
+ KBP37 is a revision of MIML-RE annotation dataset, provided by Gabor Angeli et al. (2014). They use both the 2010 and
187
+ 2013 KBP official document collections, as well as a July 2013 dump of Wikipedia as the text corpus for annotation.
188
+ There are 33811 sentences been annotated. Zhang and Wang made several refinements:
189
+ 1. They add direction to the relation names, e.g. '`per:employee_of`' is split into '`per:employee of(e1,e2)`'
190
+ and '`per:employee of(e2,e1)`'. They also replace '`org:parents`' with '`org:subsidiaries`' and replace
191
+ '`org:member of’ with '`org:member`' (by their reverse directions).
192
+ 2. They discard low frequency relations such that both directions of each relation occur more than 100 times in the
193
+ dataset.
194
+
195
+ KBP37 contains 18 directional relations and an additional '`no_relation`' relation, resulting in 37 relation classes.
196
+
197
+ Note:
198
+ - There is a formatted version that you can load with `datasets.load_dataset('kbp37', name='kbp37_formatted')`. This version is tokenized with spaCy and provides entity offsets.
199
+
200
+
201
+ ### Supported Tasks and Leaderboards
202
+
203
+ [More Information Needed](https://github.com/huggingface/datasets/blob/master/CONTRIBUTING.md#how-to-contribute-to-the-dataset-cards)
204
+
205
+ ### Languages
206
+
207
+ The language data in KBP37 is in English (BCP-47 en)
208
+
209
+ ## Dataset Structure
210
+
211
+ ### Data Instances
212
+
213
+ #### kbp37
214
+ An example of 'train' looks as follows:
215
+ ```json
216
+ {
217
+ "id": "0",
218
+ "sentence": "<e1> Thom Yorke </e1> of <e2> Radiohead </e2> has included the + for many of his signature distortion sounds using a variety of guitars to achieve various tonal options .",
219
+ "relation": 27
220
+ }
221
+ ```
222
+
223
+ #### kbp37_formatted
224
+ An example of 'train' looks as follows:
225
+ ```json
226
+ {
227
+ "id": "1",
228
+ "token": ["Leland", "High", "School", "is", "a", "public", "high", "school", "located", "in", "the", "Almaden", "Valley", "in", "San", "Jose", "California", "USA", "in", "the", "San", "Jose", "Unified", "School", "District", "."],
229
+ "subj_start": 0,
230
+ "subj_end": 3,
231
+ "obj_start": 14,
232
+ "obj_end": 16,
233
+ "relation": 3
234
+ }
235
+ ```
236
+
237
+ ### Data Fields
238
+
239
+ #### kbp37
240
+ - `id`: the instance id of this sentence, a `string` feature.
241
+ - `sentence`: the sentence, a `string` features.
242
+ - `relation`: the relation label of this instance, a `string` classification label.
243
+
244
+ #### kbp37_formatted
245
+ - `id`: the instance id of this sentence, a `string` feature.
246
+ - `token`: the list of tokens of this sentence, obtained with spaCy, a `list` of `string` features.
247
+ - `subj_start`: the 0-based index of the start token of the relation subject mention, an `ìnt` feature.
248
+ - `subj_end`: the 0-based index of the end token of the relation subject mention, exclusive, an `ìnt` feature.
249
+ - `obj_start`: the 0-based index of the start token of the relation object mention, an `ìnt` feature.
250
+ - `obj_end`: the 0-based index of the end token of the relation object mention, exclusive, an `ìnt` feature.
251
+ - `relation`: the relation label of this instance, a `string` classification label.
252
+
253
+ ### Data Splits
254
+
255
+ | | Train | Dev | Test |
256
+ |-------|-------|------|------|
257
+ | KBP37 | 15917 | 1724 | 3405 |
258
+
259
+ ## Dataset Creation
260
+
261
+ ### Curation Rationale
262
+
263
+ [More Information Needed](https://github.com/huggingface/datasets/blob/master/CONTRIBUTING.md#how-to-contribute-to-the-dataset-cards)
264
+
265
+ ### Source Data
266
+
267
+ #### Initial Data Collection and Normalization
268
+
269
+ [More Information Needed](https://github.com/huggingface/datasets/blob/master/CONTRIBUTING.md#how-to-contribute-to-the-dataset-cards)
270
+
271
+ #### Who are the source language producers?
272
+
273
+ [More Information Needed](https://github.com/huggingface/datasets/blob/master/CONTRIBUTING.md#how-to-contribute-to-the-dataset-cards)
274
+
275
+ ### Annotations
276
+
277
+ #### Annotation process
278
+
279
+ [More Information Needed](https://github.com/huggingface/datasets/blob/master/CONTRIBUTING.md#how-to-contribute-to-the-dataset-cards)
280
+
281
+ #### Who are the annotators?
282
+
283
+ [More Information Needed](https://github.com/huggingface/datasets/blob/master/CONTRIBUTING.md#how-to-contribute-to-the-dataset-cards)
284
+
285
+ ### Personal and Sensitive Information
286
+
287
+ [More Information Needed](https://github.com/huggingface/datasets/blob/master/CONTRIBUTING.md#how-to-contribute-to-the-dataset-cards)
288
+
289
+ ## Considerations for Using the Data
290
+
291
+ ### Social Impact of Dataset
292
+
293
+ [More Information Needed](https://github.com/huggingface/datasets/blob/master/CONTRIBUTING.md#how-to-contribute-to-the-dataset-cards)
294
+
295
+ ### Discussion of Biases
296
+
297
+ [More Information Needed](https://github.com/huggingface/datasets/blob/master/CONTRIBUTING.md#how-to-contribute-to-the-dataset-cards)
298
+
299
+ ### Other Known Limitations
300
+
301
+ [More Information Needed](https://github.com/huggingface/datasets/blob/master/CONTRIBUTING.md#how-to-contribute-to-the-dataset-cards)
302
+
303
+ ## Additional Information
304
+
305
+ ### Dataset Curators
306
+
307
+ [More Information Needed](https://github.com/huggingface/datasets/blob/master/CONTRIBUTING.md#how-to-contribute-to-the-dataset-cards)
308
+
309
+ ### Licensing Information
310
+
311
+ [More Information Needed](https://github.com/huggingface/datasets/blob/master/CONTRIBUTING.md#how-to-contribute-to-the-dataset-cards)
312
+
313
+ ### Citation Information
314
+
315
+ ```
316
+ @article{DBLP:journals/corr/ZhangW15a,
317
+ author = {Dongxu Zhang and
318
+ Dong Wang},
319
+ title = {Relation Classification via Recurrent Neural Network},
320
+ journal = {CoRR},
321
+ volume = {abs/1508.01006},
322
+ year = {2015},
323
+ url = {http://arxiv.org/abs/1508.01006},
324
+ eprinttype = {arXiv},
325
+ eprint = {1508.01006},
326
+ timestamp = {Fri, 04 Nov 2022 18:37:50 +0100},
327
+ biburl = {https://dblp.org/rec/journals/corr/ZhangW15a.bib},
328
+ bibsource = {dblp computer science bibliography, https://dblp.org}
329
+ }
330
+ ```
331
+
332
+ ### Contributions
333
+
334
+ Thanks to [@phucdev](https://github.com/phucdev) for adding this dataset.
kbp37.py ADDED
@@ -0,0 +1,234 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # coding=utf-8
2
+ # Copyright 2022 The current dataset script contributor.
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
+ """The KBP37 dataset for English Relation Classification"""
17
+
18
+ import datasets
19
+
20
+ _CITATION = """\
21
+ @article{DBLP:journals/corr/ZhangW15a,
22
+ author = {Dongxu Zhang and
23
+ Dong Wang},
24
+ title = {Relation Classification via Recurrent Neural Network},
25
+ journal = {CoRR},
26
+ volume = {abs/1508.01006},
27
+ year = {2015},
28
+ url = {http://arxiv.org/abs/1508.01006},
29
+ eprinttype = {arXiv},
30
+ eprint = {1508.01006},
31
+ timestamp = {Fri, 04 Nov 2022 18:37:50 +0100},
32
+ biburl = {https://dblp.org/rec/journals/corr/ZhangW15a.bib},
33
+ bibsource = {dblp computer science bibliography, https://dblp.org}
34
+ }
35
+ """
36
+
37
+ _DESCRIPTION = """\
38
+ KBP37 is a revision of MIML-RE annotation dataset, provided by Gabor Angeli et al. (2014). They use both the 2010 and
39
+ 2013 KBP official document collections, as well as a July 2013 dump of Wikipedia as the text corpus for annotation.
40
+ There are 33811 sentences been annotated. Zhang and Wang made several refinements:
41
+ 1. They add direction to the relation names, e.g. '`per:employee_of`' is split into '`per:employee of(e1,e2)`'
42
+ and '`per:employee of(e2,e1)`'. They also replace '`org:parents`' with '`org:subsidiaries`' and replace
43
+ '`org:member of’ with '`org:member`' (by their reverse directions).
44
+ 2. They discard low frequency relations such that both directions of each relation occur more than 100 times in the
45
+ dataset.
46
+
47
+ KBP37 contains 18 directional relations and an additional '`no_relation`' relation, resulting in 37 relation classes.
48
+ """
49
+
50
+ _HOMEPAGE = ""
51
+
52
+ _LICENSE = ""
53
+
54
+
55
+ # The HuggingFace dataset library don't host the datasets but only point to the original files
56
+ # This can be an arbitrary nested dict/list of URLs (see below in `_split_generators` method)
57
+ _URLs = {
58
+ "train": "https://raw.githubusercontent.com/zhangdongxu/kbp37/master/train.txt",
59
+ "validation": "https://raw.githubusercontent.com/zhangdongxu/kbp37/master/dev.txt",
60
+ "test": "https://raw.githubusercontent.com/zhangdongxu/kbp37/master/test.txt"
61
+ }
62
+
63
+ _VERSION = datasets.Version("1.0.0")
64
+
65
+ _CLASS_LABELS = [
66
+ "no_relation",
67
+ "org:alternate_names(e1,e2)",
68
+ "org:alternate_names(e2,e1)",
69
+ "org:city_of_headquarters(e1,e2)",
70
+ "org:city_of_headquarters(e2,e1)",
71
+ "org:country_of_headquarters(e1,e2)",
72
+ "org:country_of_headquarters(e2,e1)",
73
+ "org:founded(e1,e2)",
74
+ "org:founded(e2,e1)",
75
+ "org:founded_by(e1,e2)",
76
+ "org:founded_by(e2,e1)",
77
+ "org:members(e1,e2)",
78
+ "org:members(e2,e1)",
79
+ "org:stateorprovince_of_headquarters(e1,e2)",
80
+ "org:stateorprovince_of_headquarters(e2,e1)",
81
+ "org:subsidiaries(e1,e2)",
82
+ "org:subsidiaries(e2,e1)",
83
+ "org:top_members/employees(e1,e2)",
84
+ "org:top_members/employees(e2,e1)",
85
+ "per:alternate_names(e1,e2)",
86
+ "per:alternate_names(e2,e1)",
87
+ "per:cities_of_residence(e1,e2)",
88
+ "per:cities_of_residence(e2,e1)",
89
+ "per:countries_of_residence(e1,e2)",
90
+ "per:countries_of_residence(e2,e1)",
91
+ "per:country_of_birth(e1,e2)",
92
+ "per:country_of_birth(e2,e1)",
93
+ "per:employee_of(e1,e2)",
94
+ "per:employee_of(e2,e1)",
95
+ "per:origin(e1,e2)",
96
+ "per:origin(e2,e1)",
97
+ "per:spouse(e1,e2)",
98
+ "per:spouse(e2,e1)",
99
+ "per:stateorprovinces_of_residence(e1,e2)",
100
+ "per:stateorprovinces_of_residence(e2,e1)",
101
+ "per:title(e1,e2)",
102
+ "per:title(e2,e1)"
103
+ ]
104
+
105
+
106
+ class KBP37(datasets.GeneratorBasedBuilder):
107
+ """KBP37 is a relation extraction dataset"""
108
+
109
+ BUILDER_CONFIGS = [
110
+ datasets.BuilderConfig(
111
+ name="kbp37", version=_VERSION, description="The KBP37 dataset."
112
+ ),
113
+ datasets.BuilderConfig(
114
+ name="kbp37_formatted", version=_VERSION, description="The formatted KBP37 dataset."
115
+ )
116
+ ]
117
+
118
+ DEFAULT_CONFIG_NAME = "kbp37" # type: ignore
119
+
120
+ def _info(self):
121
+ if self.config.name == "kbp37_formatted":
122
+ features = datasets.Features(
123
+ {
124
+ "id": datasets.Value("string"),
125
+ "token": datasets.Sequence(datasets.Value("string")),
126
+ "subj_start": datasets.Value("int32"),
127
+ "subj_end": datasets.Value("int32"),
128
+ "obj_start": datasets.Value("int32"),
129
+ "obj_end": datasets.Value("int32"),
130
+ "relation": datasets.ClassLabel(names=_CLASS_LABELS),
131
+ }
132
+ )
133
+ else:
134
+ features = datasets.Features(
135
+ {
136
+ "id": datasets.Value("string"),
137
+ "sentence": datasets.Value("string"),
138
+ "relation": datasets.ClassLabel(names=_CLASS_LABELS),
139
+ }
140
+ )
141
+
142
+ return datasets.DatasetInfo(
143
+ # This is the description that will appear on the datasets page.
144
+ description=_DESCRIPTION,
145
+ # This defines the different columns of the dataset and their types
146
+ features=features, # Here we define them above because they are different between the two configurations
147
+ # If there's a common (input, target) tuple from the features,
148
+ # specify them here. They'll be used if as_supervised=True in
149
+ # builder.as_dataset.
150
+ supervised_keys=None,
151
+ # Homepage of the dataset for documentation
152
+ homepage=_HOMEPAGE,
153
+ # License for the dataset if available
154
+ license=_LICENSE,
155
+ # Citation for the dataset
156
+ citation=_CITATION,
157
+ )
158
+
159
+ def _split_generators(self, dl_manager):
160
+ """Returns SplitGenerators."""
161
+ # If several configurations are possible (listed in BUILDER_CONFIGS), the configuration selected by the user is in self.config.name
162
+
163
+ # dl_manager is a datasets.download.DownloadManager that can be used to download and extract URLs
164
+ # 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.
165
+ # By default the archives will be extracted and a path to a cached folder where they are extracted is returned instead of the archive
166
+
167
+ downloaded_files = dl_manager.download_and_extract(_URLs)
168
+
169
+ return [datasets.SplitGenerator(name=i, gen_kwargs={"filepath": downloaded_files[str(i)]})
170
+ for i in [datasets.Split.TRAIN, datasets.Split.VALIDATION, datasets.Split.TEST]]
171
+
172
+ def _generate_examples(self, filepath):
173
+ """Yields examples."""
174
+ # This method will receive as arguments the `gen_kwargs` defined in the previous `_split_generators` method.
175
+ # It is in charge of opening the given file and yielding (key, example) tuples from the dataset
176
+ # The key is not important, it's more here for legacy reason (legacy from tfds)
177
+
178
+ with open(filepath, encoding="utf-8") as f:
179
+ data = []
180
+ example_line = None
181
+ for idx, line in enumerate(f.readlines()):
182
+ line_no = idx % 4 # first line contains example, second line relation, third and fourth lines are \n
183
+ if line_no == 0:
184
+ example_line = line.strip().split("\t")
185
+ elif line_no == 1:
186
+ data.append({"example": example_line, "relation": line.strip()})
187
+ for example in data:
188
+ id_ = example["example"][0]
189
+ text = example["example"][1]
190
+ assert text[:2] == "\" " and text[-2:] == " \""
191
+ text = text[2:-2]
192
+ relation = example["relation"]
193
+
194
+ if self.config.name == "kbp37_formatted":
195
+ text = text.replace("<e1>", " <e1> ")
196
+ text = text.replace("<e2>", " <e2> ")
197
+ text = text.replace("</e1>", " </e1> ")
198
+ text = text.replace("</e2>", " </e2> ")
199
+ text = text.strip().replace(r"\s\s+", r"\s")
200
+ tokens = text.split()
201
+ subj_start = tokens.index("<e1>")
202
+ obj_start = tokens.index("<e2>")
203
+ if subj_start < obj_start:
204
+ tokens.pop(subj_start)
205
+ subj_end = tokens.index("</e1>")
206
+ tokens.pop(subj_end)
207
+ obj_start = tokens.index("<e2>")
208
+ tokens.pop(obj_start)
209
+ obj_end = tokens.index("</e2>")
210
+ tokens.pop(obj_end)
211
+ else:
212
+ tokens.pop(obj_start)
213
+ obj_end = tokens.index("</e2>")
214
+ tokens.pop(obj_end)
215
+ subj_start = tokens.index("<e1>")
216
+ tokens.pop(subj_start)
217
+ subj_end = tokens.index("</e1>")
218
+ tokens.pop(subj_end)
219
+
220
+ yield int(id_), {
221
+ "id": id_,
222
+ "token": tokens,
223
+ "subj_start": subj_start,
224
+ "subj_end": subj_end,
225
+ "obj_start": obj_start,
226
+ "obj_end": obj_end,
227
+ "relation": relation,
228
+ }
229
+ else:
230
+ yield int(id_), {
231
+ "id": id_,
232
+ "sentence": text,
233
+ "relation": relation,
234
+ }