Commit
•
1f65586
0
Parent(s):
Update files from the datasets library (from 1.2.0)
Browse filesRelease notes: https://github.com/huggingface/datasets/releases/tag/1.2.0
- .gitattributes +27 -0
- README.md +165 -0
- dataset_infos.json +1 -0
- dummy/4th_grade/0.0.0/dummy_data.zip +3 -0
- dummy/8th_grade/0.0.0/dummy_data.zip +3 -0
- dummy/all/0.0.0/dummy_data.zip +3 -0
- tuple_ie.py +161 -0
.gitattributes
ADDED
@@ -0,0 +1,27 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
*.7z filter=lfs diff=lfs merge=lfs -text
|
2 |
+
*.arrow filter=lfs diff=lfs merge=lfs -text
|
3 |
+
*.bin filter=lfs diff=lfs merge=lfs -text
|
4 |
+
*.bin.* filter=lfs diff=lfs merge=lfs -text
|
5 |
+
*.bz2 filter=lfs diff=lfs merge=lfs -text
|
6 |
+
*.ftz filter=lfs diff=lfs merge=lfs -text
|
7 |
+
*.gz filter=lfs diff=lfs merge=lfs -text
|
8 |
+
*.h5 filter=lfs diff=lfs merge=lfs -text
|
9 |
+
*.joblib filter=lfs diff=lfs merge=lfs -text
|
10 |
+
*.lfs.* filter=lfs diff=lfs merge=lfs -text
|
11 |
+
*.model filter=lfs diff=lfs merge=lfs -text
|
12 |
+
*.msgpack filter=lfs diff=lfs merge=lfs -text
|
13 |
+
*.onnx filter=lfs diff=lfs merge=lfs -text
|
14 |
+
*.ot filter=lfs diff=lfs merge=lfs -text
|
15 |
+
*.parquet filter=lfs diff=lfs merge=lfs -text
|
16 |
+
*.pb filter=lfs diff=lfs merge=lfs -text
|
17 |
+
*.pt filter=lfs diff=lfs merge=lfs -text
|
18 |
+
*.pth filter=lfs diff=lfs merge=lfs -text
|
19 |
+
*.rar filter=lfs diff=lfs merge=lfs -text
|
20 |
+
saved_model/**/* filter=lfs diff=lfs merge=lfs -text
|
21 |
+
*.tar.* filter=lfs diff=lfs merge=lfs -text
|
22 |
+
*.tflite filter=lfs diff=lfs merge=lfs -text
|
23 |
+
*.tgz filter=lfs diff=lfs merge=lfs -text
|
24 |
+
*.xz filter=lfs diff=lfs merge=lfs -text
|
25 |
+
*.zip filter=lfs diff=lfs merge=lfs -text
|
26 |
+
*.zstandard filter=lfs diff=lfs merge=lfs -text
|
27 |
+
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
README.md
ADDED
@@ -0,0 +1,165 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
---
|
2 |
+
annotations_creators:
|
3 |
+
- found
|
4 |
+
language_creators:
|
5 |
+
- machine-generated
|
6 |
+
languages:
|
7 |
+
- en
|
8 |
+
licenses:
|
9 |
+
- unknown
|
10 |
+
multilinguality:
|
11 |
+
- monolingual
|
12 |
+
size_categories:
|
13 |
+
- 100K<n<1M
|
14 |
+
source_datasets:
|
15 |
+
- original
|
16 |
+
task_categories:
|
17 |
+
- other
|
18 |
+
task_ids:
|
19 |
+
- other-other-open-information-extraction
|
20 |
+
---
|
21 |
+
|
22 |
+
# Dataset Card for [Dataset Name]
|
23 |
+
|
24 |
+
## Table of Contents
|
25 |
+
- [Dataset Card for [Dataset Name]](#dataset-card-for-dataset-name)
|
26 |
+
- [Table of Contents](#table-of-contents)
|
27 |
+
- [Dataset Description](#dataset-description)
|
28 |
+
- [Dataset Summary](#dataset-summary)
|
29 |
+
- [Supported Tasks and Leaderboards](#supported-tasks-and-leaderboards)
|
30 |
+
- [Languages](#languages)
|
31 |
+
- [Dataset Structure](#dataset-structure)
|
32 |
+
- [Data Instances](#data-instances)
|
33 |
+
- [Data Fields](#data-fields)
|
34 |
+
- [Data Splits](#data-splits)
|
35 |
+
- [Dataset Creation](#dataset-creation)
|
36 |
+
- [Curation Rationale](#curation-rationale)
|
37 |
+
- [Source Data](#source-data)
|
38 |
+
- [Initial Data Collection and Normalization](#initial-data-collection-and-normalization)
|
39 |
+
- [Who are the source language producers?](#who-are-the-source-language-producers)
|
40 |
+
- [Annotations](#annotations)
|
41 |
+
- [Annotation process](#annotation-process)
|
42 |
+
- [Who are the annotators?](#who-are-the-annotators)
|
43 |
+
- [Personal and Sensitive Information](#personal-and-sensitive-information)
|
44 |
+
- [Considerations for Using the Data](#considerations-for-using-the-data)
|
45 |
+
- [Social Impact of Dataset](#social-impact-of-dataset)
|
46 |
+
- [Discussion of Biases](#discussion-of-biases)
|
47 |
+
- [Other Known Limitations](#other-known-limitations)
|
48 |
+
- [Additional Information](#additional-information)
|
49 |
+
- [Dataset Curators](#dataset-curators)
|
50 |
+
- [Licensing Information](#licensing-information)
|
51 |
+
- [Citation Information](#citation-information)
|
52 |
+
|
53 |
+
## Dataset Description
|
54 |
+
|
55 |
+
- **Homepage: [Tuple IE Homepage](https://allenai.org/data/tuple-ie)**
|
56 |
+
- **Repository:**
|
57 |
+
- **Paper: [Answering Complex Questions Using Open Information Extraction](https://www.semanticscholar.org/paper/Answering-Complex-Questions-Using-Open-Information-Khot-Sabharwal/0ff595f0645a3e25a2f37145768985b10ead0509)**
|
58 |
+
- **Leaderboard:**
|
59 |
+
- **Point of Contact:**
|
60 |
+
|
61 |
+
### Dataset Summary
|
62 |
+
|
63 |
+
The TupleInf Open IE dataset contains Open IE tuples extracted from 263K sentences that were used by the solver in “Answering Complex Questions Using Open Information Extraction” (referred as Tuple KB, T). These sentences were collected from a large Web corpus using training questions from 4th and 8th grade as queries. This dataset contains 156K sentences collected for 4th grade questions and 107K sentences for 8th grade questions. Each sentence is followed by the Open IE v4 tuples using their simple format.
|
64 |
+
|
65 |
+
### Supported Tasks and Leaderboards
|
66 |
+
|
67 |
+
[More Information Needed]
|
68 |
+
|
69 |
+
### Languages
|
70 |
+
|
71 |
+
The text in the dataset is in English, collected from a large Web corpus using training questions from 4th and 8th grade as queries.
|
72 |
+
|
73 |
+
## Dataset Structure
|
74 |
+
|
75 |
+
### Data Instances
|
76 |
+
|
77 |
+
This dataset contains setences with corresponding relation tuples extracted from each sentence. Each instance should contain a sentence and followed by the [Open IE v4](https://github.com/allenai/openie-standalone) tuples using their *simple format*.
|
78 |
+
An example of an instance:
|
79 |
+
|
80 |
+
```JSON
|
81 |
+
{
|
82 |
+
"sentence": "0.04593 kg Used a triple beam balance to mass a golf ball.",
|
83 |
+
"tuples": {
|
84 |
+
"score": 0.8999999761581421,
|
85 |
+
"tuple_text": "(0.04593 kg; Used; a triple beam balance; to mass a golf ball)",
|
86 |
+
"context": "",
|
87 |
+
"arg1": "0.04593 kg",
|
88 |
+
"rel": "Used",
|
89 |
+
"arg2s": ["a triple beam balance", "to mass a golf ball"],
|
90 |
+
}
|
91 |
+
}
|
92 |
+
```
|
93 |
+
|
94 |
+
### Data Fields
|
95 |
+
|
96 |
+
- `setence`: the input text/sentence.
|
97 |
+
- `tuples`: the extracted relation tuples from the sentence.
|
98 |
+
- `score`: the confident score for each tuple.
|
99 |
+
- `tuple_text`: the relationship representation text of the extraction, in the *simple format* of [Open IE v4](https://github.com/allenai/openie-standalone).
|
100 |
+
- `context`: an optional representation of the context for this extraction. Defaults to `""` if there's no context.
|
101 |
+
- `arg1`: the first argument in the relationship.
|
102 |
+
- `rel`: the relation.
|
103 |
+
- `arg2s`: a sequence of the 2nd arguments in the realtionship.
|
104 |
+
|
105 |
+
### Data Splits
|
106 |
+
|
107 |
+
[More Information Needed]
|
108 |
+
|
109 |
+
## Dataset Creation
|
110 |
+
|
111 |
+
### Curation Rationale
|
112 |
+
|
113 |
+
[More Information Needed]
|
114 |
+
|
115 |
+
### Source Data
|
116 |
+
|
117 |
+
#### Initial Data Collection and Normalization
|
118 |
+
|
119 |
+
[More Information Needed]
|
120 |
+
|
121 |
+
#### Who are the source language producers?
|
122 |
+
|
123 |
+
[More Information Needed]
|
124 |
+
|
125 |
+
### Annotations
|
126 |
+
|
127 |
+
#### Annotation process
|
128 |
+
|
129 |
+
[More Information Needed]
|
130 |
+
|
131 |
+
#### Who are the annotators?
|
132 |
+
|
133 |
+
[More Information Needed]
|
134 |
+
|
135 |
+
### Personal and Sensitive Information
|
136 |
+
|
137 |
+
[More Information Needed]
|
138 |
+
|
139 |
+
## Considerations for Using the Data
|
140 |
+
|
141 |
+
### Social Impact of Dataset
|
142 |
+
|
143 |
+
[More Information Needed]
|
144 |
+
|
145 |
+
### Discussion of Biases
|
146 |
+
|
147 |
+
[More Information Needed]
|
148 |
+
|
149 |
+
### Other Known Limitations
|
150 |
+
|
151 |
+
[More Information Needed]
|
152 |
+
|
153 |
+
## Additional Information
|
154 |
+
|
155 |
+
### Dataset Curators
|
156 |
+
|
157 |
+
[More Information Needed]
|
158 |
+
|
159 |
+
### Licensing Information
|
160 |
+
|
161 |
+
[More Information Needed]
|
162 |
+
|
163 |
+
### Citation Information
|
164 |
+
|
165 |
+
[More Information Needed]
|
dataset_infos.json
ADDED
@@ -0,0 +1 @@
|
|
|
|
|
1 |
+
{"all": {"description": "The TupleInf Open IE dataset contains Open IE tuples extracted from 263K sentences that were used by the solver in \u201cAnswering Complex Questions Using Open Information Extraction\u201d (referred as Tuple KB, T). These sentences were collected from a large Web corpus using training questions from 4th and 8th grade as queries. This dataset contains 156K sentences collected for 4th grade questions and 107K sentences for 8th grade questions. Each sentence is followed by the Open IE v4 tuples using their simple format.\n", "citation": "@article{Khot2017AnsweringCQ,\n title={Answering Complex Questions Using Open Information Extraction},\n author={Tushar Khot and A. Sabharwal and Peter Clark},\n journal={ArXiv},\n year={2017},\n volume={abs/1704.05572}\n}\n", "homepage": "https://allenai.org/data/tuple-ie", "license": "", "features": {"sentence": {"dtype": "string", "id": null, "_type": "Value"}, "tuples": {"feature": {"score": {"dtype": "float32", "id": null, "_type": "Value"}, "tuple_text": {"dtype": "string", "id": null, "_type": "Value"}, "context": {"dtype": "string", "id": null, "_type": "Value"}, "arg1": {"dtype": "string", "id": null, "_type": "Value"}, "rel": {"dtype": "string", "id": null, "_type": "Value"}, "arg2s": {"feature": {"dtype": "string", "id": null, "_type": "Value"}, "length": -1, "id": null, "_type": "Sequence"}}, "length": -1, "id": null, "_type": "Sequence"}}, "post_processed": null, "supervised_keys": null, "builder_name": "tuple_ie", "config_name": "all", "version": {"version_str": "0.0.0", "description": null, "major": 0, "minor": 0, "patch": 0}, "splits": {"train": {"name": "train", "num_bytes": 115621096, "num_examples": 267719, "dataset_name": "tuple_ie"}}, "download_checksums": {"https://ai2-datasets.s3-us-west-2.amazonaws.com/tuple-ie/TupleInfKB.zip": {"num_bytes": 18026102, "checksum": "5ae98009e45ef2d29570d9c6c4575ff5339ddd019f9524d8b5c62b8a50aba56d"}}, "download_size": 18026102, "post_processing_size": null, "dataset_size": 115621096, "size_in_bytes": 133647198}, "4th_grade": {"description": "The TupleInf Open IE dataset contains Open IE tuples extracted from 263K sentences that were used by the solver in \u201cAnswering Complex Questions Using Open Information Extraction\u201d (referred as Tuple KB, T). These sentences were collected from a large Web corpus using training questions from 4th and 8th grade as queries. This dataset contains 156K sentences collected for 4th grade questions and 107K sentences for 8th grade questions. Each sentence is followed by the Open IE v4 tuples using their simple format.\n", "citation": "@article{Khot2017AnsweringCQ,\n title={Answering Complex Questions Using Open Information Extraction},\n author={Tushar Khot and A. Sabharwal and Peter Clark},\n journal={ArXiv},\n year={2017},\n volume={abs/1704.05572}\n}\n", "homepage": "https://allenai.org/data/tuple-ie", "license": "", "features": {"sentence": {"dtype": "string", "id": null, "_type": "Value"}, "tuples": {"feature": {"score": {"dtype": "float32", "id": null, "_type": "Value"}, "tuple_text": {"dtype": "string", "id": null, "_type": "Value"}, "context": {"dtype": "string", "id": null, "_type": "Value"}, "arg1": {"dtype": "string", "id": null, "_type": "Value"}, "rel": {"dtype": "string", "id": null, "_type": "Value"}, "arg2s": {"feature": {"dtype": "string", "id": null, "_type": "Value"}, "length": -1, "id": null, "_type": "Sequence"}}, "length": -1, "id": null, "_type": "Sequence"}}, "post_processed": null, "supervised_keys": null, "builder_name": "tuple_ie", "config_name": "4th_grade", "version": {"version_str": "0.0.0", "description": null, "major": 0, "minor": 0, "patch": 0}, "splits": {"train": {"name": "train", "num_bytes": 65363445, "num_examples": 158910, "dataset_name": "tuple_ie"}}, "download_checksums": {"https://ai2-datasets.s3-us-west-2.amazonaws.com/tuple-ie/TupleInfKB.zip": {"num_bytes": 18026102, "checksum": "5ae98009e45ef2d29570d9c6c4575ff5339ddd019f9524d8b5c62b8a50aba56d"}}, "download_size": 18026102, "post_processing_size": null, "dataset_size": 65363445, "size_in_bytes": 83389547}, "8th_grade": {"description": "The TupleInf Open IE dataset contains Open IE tuples extracted from 263K sentences that were used by the solver in \u201cAnswering Complex Questions Using Open Information Extraction\u201d (referred as Tuple KB, T). These sentences were collected from a large Web corpus using training questions from 4th and 8th grade as queries. This dataset contains 156K sentences collected for 4th grade questions and 107K sentences for 8th grade questions. Each sentence is followed by the Open IE v4 tuples using their simple format.\n", "citation": "@article{Khot2017AnsweringCQ,\n title={Answering Complex Questions Using Open Information Extraction},\n author={Tushar Khot and A. Sabharwal and Peter Clark},\n journal={ArXiv},\n year={2017},\n volume={abs/1704.05572}\n}\n", "homepage": "https://allenai.org/data/tuple-ie", "license": "", "features": {"sentence": {"dtype": "string", "id": null, "_type": "Value"}, "tuples": {"feature": {"score": {"dtype": "float32", "id": null, "_type": "Value"}, "tuple_text": {"dtype": "string", "id": null, "_type": "Value"}, "context": {"dtype": "string", "id": null, "_type": "Value"}, "arg1": {"dtype": "string", "id": null, "_type": "Value"}, "rel": {"dtype": "string", "id": null, "_type": "Value"}, "arg2s": {"feature": {"dtype": "string", "id": null, "_type": "Value"}, "length": -1, "id": null, "_type": "Sequence"}}, "length": -1, "id": null, "_type": "Sequence"}}, "post_processed": null, "supervised_keys": null, "builder_name": "tuple_ie", "config_name": "8th_grade", "version": "0.0.0", "splits": {"train": {"name": "train", "num_bytes": 50257651, "num_examples": 108809, "dataset_name": "tuple_ie"}}, "download_checksums": {"https://ai2-datasets.s3-us-west-2.amazonaws.com/tuple-ie/TupleInfKB.zip": {"num_bytes": 18026102, "checksum": "5ae98009e45ef2d29570d9c6c4575ff5339ddd019f9524d8b5c62b8a50aba56d"}}, "download_size": 18026102, "post_processing_size": null, "dataset_size": 50257651, "size_in_bytes": 68283753}}
|
dummy/4th_grade/0.0.0/dummy_data.zip
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:8f8fbec7bf534df82acbc71152dc2f1215d601db1a72f010a25ecd82b7308c62
|
3 |
+
size 790
|
dummy/8th_grade/0.0.0/dummy_data.zip
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:4940a7ef5497200be453d45a9853c273e354a48c5f626f1fe8c23f350900453d
|
3 |
+
size 790
|
dummy/all/0.0.0/dummy_data.zip
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:8f8fbec7bf534df82acbc71152dc2f1215d601db1a72f010a25ecd82b7308c62
|
3 |
+
size 790
|
tuple_ie.py
ADDED
@@ -0,0 +1,161 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# coding=utf-8
|
2 |
+
# Copyright 2020 The HuggingFace Datasets Authors and 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 |
+
"""TupleInf Open IE Dataset"""
|
16 |
+
|
17 |
+
from __future__ import absolute_import, division, print_function
|
18 |
+
|
19 |
+
import os
|
20 |
+
|
21 |
+
import datasets
|
22 |
+
|
23 |
+
|
24 |
+
_CITATION = """\
|
25 |
+
@article{Khot2017AnsweringCQ,
|
26 |
+
title={Answering Complex Questions Using Open Information Extraction},
|
27 |
+
author={Tushar Khot and A. Sabharwal and Peter Clark},
|
28 |
+
journal={ArXiv},
|
29 |
+
year={2017},
|
30 |
+
volume={abs/1704.05572}
|
31 |
+
}
|
32 |
+
"""
|
33 |
+
|
34 |
+
_DESCRIPTION = """\
|
35 |
+
The TupleInf Open IE dataset contains Open IE tuples extracted from 263K sentences that were used by the solver \
|
36 |
+
in “Answering Complex Questions Using Open Information Extraction” (referred as Tuple KB, T). \
|
37 |
+
These sentences were collected from a large Web corpus using training questions from 4th and 8th grade as queries. \
|
38 |
+
This dataset contains 156K sentences collected for 4th grade questions and 107K sentences for 8th grade questions. \
|
39 |
+
Each sentence is followed by the Open IE v4 tuples using their simple format.
|
40 |
+
"""
|
41 |
+
|
42 |
+
_HOMEPAGE = "https://allenai.org/data/tuple-ie"
|
43 |
+
|
44 |
+
_URL = "https://ai2-datasets.s3-us-west-2.amazonaws.com/tuple-ie/TupleInfKB.zip"
|
45 |
+
|
46 |
+
_DOMAIN_FILES = {"4th_grade": "4thGradeOpenIE.txt", "8th_grade": "8thGradeOpenIE.txt"}
|
47 |
+
|
48 |
+
|
49 |
+
class TupleIEConfig(datasets.BuilderConfig):
|
50 |
+
"""BuilderConfig for TupleIE"""
|
51 |
+
|
52 |
+
def __init__(self, *args, domains=None, **kwargs):
|
53 |
+
super().__init__(*args, **kwargs)
|
54 |
+
self.domains = domains
|
55 |
+
|
56 |
+
|
57 |
+
class TupleIE(datasets.GeneratorBasedBuilder):
|
58 |
+
"""TupleInf Open IE Dataset"""
|
59 |
+
|
60 |
+
BUILDER_CONFIGS = [
|
61 |
+
TupleIEConfig(
|
62 |
+
name="all",
|
63 |
+
domains=list(_DOMAIN_FILES.keys()),
|
64 |
+
description="collected using training questions from 4th and 8th grade as queries.",
|
65 |
+
)
|
66 |
+
] + [
|
67 |
+
TupleIEConfig(
|
68 |
+
name=name, domains=[name], description=f"collected using training questions from {name} as queries."
|
69 |
+
)
|
70 |
+
for name in _DOMAIN_FILES.keys()
|
71 |
+
]
|
72 |
+
BUILDER_CONFIG_CLASS = TupleIEConfig
|
73 |
+
DEFAULT_CONFIG_NAME = "all"
|
74 |
+
|
75 |
+
def _info(self):
|
76 |
+
return datasets.DatasetInfo(
|
77 |
+
description=_DESCRIPTION,
|
78 |
+
features=datasets.Features(
|
79 |
+
{
|
80 |
+
"sentence": datasets.Value("string"),
|
81 |
+
"tuples": datasets.features.Sequence(
|
82 |
+
{
|
83 |
+
"score": datasets.Value("float"),
|
84 |
+
"tuple_text": datasets.Value("string"),
|
85 |
+
"context": datasets.Value("string"),
|
86 |
+
"arg1": datasets.Value("string"),
|
87 |
+
"rel": datasets.Value("string"),
|
88 |
+
"arg2s": datasets.features.Sequence(datasets.Value("string")),
|
89 |
+
}
|
90 |
+
),
|
91 |
+
}
|
92 |
+
),
|
93 |
+
supervised_keys=None,
|
94 |
+
homepage=_HOMEPAGE,
|
95 |
+
citation=_CITATION,
|
96 |
+
)
|
97 |
+
|
98 |
+
def _split_generators(self, dl_manager):
|
99 |
+
"""Returns SplitGenerators."""
|
100 |
+
data_dir = os.path.join(dl_manager.download_and_extract(_URL), "TupleInfKB")
|
101 |
+
return [
|
102 |
+
datasets.SplitGenerator(
|
103 |
+
name=datasets.Split.TRAIN,
|
104 |
+
gen_kwargs={"data_dir": data_dir},
|
105 |
+
)
|
106 |
+
]
|
107 |
+
|
108 |
+
def _generate_examples(self, data_dir):
|
109 |
+
""" Yields examples. """
|
110 |
+
id_ = -1
|
111 |
+
for domain in self.config.domains:
|
112 |
+
with open(os.path.join(data_dir, _DOMAIN_FILES[domain]), encoding="utf-8") as f:
|
113 |
+
all_text = f.read()
|
114 |
+
samples = all_text.split("\n\n")
|
115 |
+
for sample in samples:
|
116 |
+
rows = sample.split("\n")
|
117 |
+
item = {"sentence": rows[0], "tuples": []}
|
118 |
+
tuple_lines = rows[1:]
|
119 |
+
for tuple_line in tuple_lines:
|
120 |
+
score, tuple_text = tuple_line.split(" ", 1)
|
121 |
+
context, arg1, rel, arg2s = self._decode_tuple_text(tuple_text)
|
122 |
+
item["tuples"].append(
|
123 |
+
{
|
124 |
+
"score": score,
|
125 |
+
"tuple_text": tuple_text,
|
126 |
+
"context": context,
|
127 |
+
"arg1": arg1,
|
128 |
+
"rel": rel,
|
129 |
+
"arg2s": arg2s,
|
130 |
+
}
|
131 |
+
)
|
132 |
+
id_ += 1
|
133 |
+
yield id_, item
|
134 |
+
|
135 |
+
def _decode_tuple_text(self, tuple_text):
|
136 |
+
"""Decompose the tuple text into arguments and relations
|
137 |
+
|
138 |
+
Args:
|
139 |
+
tuple_text (str): Format of extraction text:
|
140 |
+
.. code-block::
|
141 |
+
{Context(<context>):}(<arg1>; <rel>; {[L|T]:}<arg2_1>; {[L|T]:}<arg2_2>; ...)
|
142 |
+
|
143 |
+
.. note::
|
144 |
+
* ``{}`` means one can be optionally appear
|
145 |
+
* ``[L|T]`` means ``L`` or ``T``
|
146 |
+
* ``L`` means spatial/location argument
|
147 |
+
* ``T`` means temporal argument
|
148 |
+
* We can have multiple arg2s
|
149 |
+
"""
|
150 |
+
context = ""
|
151 |
+
arg1 = ""
|
152 |
+
rel = ""
|
153 |
+
arg2s = []
|
154 |
+
if tuple_text.startswith("Context("):
|
155 |
+
context, tuple_text = tuple_text.split(":", 1)
|
156 |
+
context = context[len("Context(") : -1]
|
157 |
+
|
158 |
+
args = tuple_text[1:-1].split("; ")
|
159 |
+
arg1, rel = args[:2]
|
160 |
+
arg2s = args[2:]
|
161 |
+
return context, arg1, rel, arg2s
|