dibyaaaaax
commited on
Commit
•
0db8b3f
1
Parent(s):
d392c84
Upload semeval2017.py
Browse files- semeval2017.py +148 -0
semeval2017.py
ADDED
@@ -0,0 +1,148 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import json
|
2 |
+
import datasets
|
3 |
+
|
4 |
+
# _SPLIT = ['test']
|
5 |
+
_CITATION = """\
|
6 |
+
@article{DBLP:journals/corr/AugensteinDRVM17,
|
7 |
+
author = {Isabelle Augenstein and
|
8 |
+
Mrinal Das and
|
9 |
+
Sebastian Riedel and
|
10 |
+
Lakshmi Vikraman and
|
11 |
+
Andrew McCallum},
|
12 |
+
title = {SemEval 2017 Task 10: ScienceIE - Extracting Keyphrases and Relations
|
13 |
+
from Scientific Publications},
|
14 |
+
journal = {CoRR},
|
15 |
+
volume = {abs/1704.02853},
|
16 |
+
year = {2017},
|
17 |
+
url = {http://arxiv.org/abs/1704.02853},
|
18 |
+
eprinttype = {arXiv},
|
19 |
+
eprint = {1704.02853},
|
20 |
+
timestamp = {Mon, 13 Aug 2018 16:46:36 +0200},
|
21 |
+
biburl = {https://dblp.org/rec/journals/corr/AugensteinDRVM17.bib},
|
22 |
+
bibsource = {dblp computer science bibliography, https://dblp.org}
|
23 |
+
}
|
24 |
+
"""
|
25 |
+
|
26 |
+
_DESCRIPTION = """\
|
27 |
+
|
28 |
+
"""
|
29 |
+
|
30 |
+
_HOMEPAGE = ""
|
31 |
+
|
32 |
+
# TODO: Add the licence for the dataset here if you can find it
|
33 |
+
_LICENSE = ""
|
34 |
+
|
35 |
+
# TODO: Add link to the official dataset URLs here
|
36 |
+
|
37 |
+
_URLS = {
|
38 |
+
"test": "test.jsonl"
|
39 |
+
}
|
40 |
+
|
41 |
+
|
42 |
+
# TODO: Name of the dataset usually match the script name with CamelCase instead of snake_case
|
43 |
+
class SemEval2017(datasets.GeneratorBasedBuilder):
|
44 |
+
"""TODO: Short description of my dataset."""
|
45 |
+
|
46 |
+
VERSION = datasets.Version("0.0.1")
|
47 |
+
|
48 |
+
BUILDER_CONFIGS = [
|
49 |
+
datasets.BuilderConfig(name="extraction", version=VERSION,
|
50 |
+
description="This part of my dataset covers extraction"),
|
51 |
+
datasets.BuilderConfig(name="generation", version=VERSION,
|
52 |
+
description="This part of my dataset covers generation"),
|
53 |
+
datasets.BuilderConfig(name="raw", version=VERSION, description="This part of my dataset covers the raw data"),
|
54 |
+
]
|
55 |
+
|
56 |
+
DEFAULT_CONFIG_NAME = "extraction"
|
57 |
+
|
58 |
+
def _info(self):
|
59 |
+
if self.config.name == "extraction": # This is the name of the configuration selected in BUILDER_CONFIGS above
|
60 |
+
features = datasets.Features(
|
61 |
+
{
|
62 |
+
"id": datasets.Value("string"),
|
63 |
+
"document": datasets.features.Sequence(datasets.Value("string")),
|
64 |
+
"doc_bio_tags": datasets.features.Sequence(datasets.Value("string"))
|
65 |
+
|
66 |
+
}
|
67 |
+
)
|
68 |
+
elif self.config.name == "generation":
|
69 |
+
features = datasets.Features(
|
70 |
+
{
|
71 |
+
"id": datasets.Value("string"),
|
72 |
+
"document": datasets.features.Sequence(datasets.Value("string")),
|
73 |
+
"extractive_keyphrases": datasets.features.Sequence(datasets.Value("string")),
|
74 |
+
"abstractive_keyphrases": datasets.features.Sequence(datasets.Value("string"))
|
75 |
+
|
76 |
+
}
|
77 |
+
)
|
78 |
+
else:
|
79 |
+
features = datasets.Features(
|
80 |
+
{
|
81 |
+
"id": datasets.Value("string"),
|
82 |
+
"document": datasets.features.Sequence(datasets.Value("string")),
|
83 |
+
"doc_bio_tags": datasets.features.Sequence(datasets.Value("string")),
|
84 |
+
"extractive_keyphrases": datasets.features.Sequence(datasets.Value("string")),
|
85 |
+
"abstractive_keyphrases": datasets.features.Sequence(datasets.Value("string")),
|
86 |
+
"other_metadata": datasets.features.Sequence(
|
87 |
+
{
|
88 |
+
"text": datasets.features.Sequence(datasets.Value("string")),
|
89 |
+
"bio_tags": datasets.features.Sequence(datasets.Value("string"))
|
90 |
+
}
|
91 |
+
)
|
92 |
+
|
93 |
+
}
|
94 |
+
)
|
95 |
+
return datasets.DatasetInfo(
|
96 |
+
# This is the description that will appear on the datasets page.
|
97 |
+
description=_DESCRIPTION,
|
98 |
+
# This defines the different columns of the dataset and their types
|
99 |
+
features=features,
|
100 |
+
homepage=_HOMEPAGE,
|
101 |
+
# License for the dataset if available
|
102 |
+
license=_LICENSE,
|
103 |
+
# Citation for the dataset
|
104 |
+
citation=_CITATION,
|
105 |
+
)
|
106 |
+
|
107 |
+
def _split_generators(self, dl_manager):
|
108 |
+
|
109 |
+
data_dir = dl_manager.download_and_extract(_URLS)
|
110 |
+
return [
|
111 |
+
datasets.SplitGenerator(
|
112 |
+
name=datasets.Split.TEST,
|
113 |
+
# These kwargs will be passed to _generate_examples
|
114 |
+
gen_kwargs={
|
115 |
+
"filepath": data_dir['test'],
|
116 |
+
"split": "test"
|
117 |
+
},
|
118 |
+
),
|
119 |
+
]
|
120 |
+
|
121 |
+
# method parameters are unpacked from `gen_kwargs` as given in `_split_generators`
|
122 |
+
def _generate_examples(self, filepath, split):
|
123 |
+
with open(filepath, encoding="utf-8") as f:
|
124 |
+
for key, row in enumerate(f):
|
125 |
+
data = json.loads(row)
|
126 |
+
if self.config.name == "extraction":
|
127 |
+
# Yields examples as (key, example) tuples
|
128 |
+
yield key, {
|
129 |
+
"id": data['paper_id'],
|
130 |
+
"document": data["document"],
|
131 |
+
"doc_bio_tags": data.get("doc_bio_tags")
|
132 |
+
}
|
133 |
+
elif self.config.name == "generation":
|
134 |
+
yield key, {
|
135 |
+
"id": data['paper_id'],
|
136 |
+
"document": data["document"],
|
137 |
+
"extractive_keyphrases": data.get("extractive_keyphrases"),
|
138 |
+
"abstractive_keyphrases": data.get("abstractive_keyphrases")
|
139 |
+
}
|
140 |
+
else:
|
141 |
+
yield key, {
|
142 |
+
"id": data['paper_id'],
|
143 |
+
"document": data["document"],
|
144 |
+
"doc_bio_tags": data.get("doc_bio_tags"),
|
145 |
+
"extractive_keyphrases": data.get("extractive_keyphrases"),
|
146 |
+
"abstractive_keyphrases": data.get("abstractive_keyphrases"),
|
147 |
+
"other_metadata": data["other_metadata"]
|
148 |
+
}
|