Delete inspec_ke_tagged.py
Browse files- inspec_ke_tagged.py +0 -121
inspec_ke_tagged.py
DELETED
@@ -1,121 +0,0 @@
|
|
1 |
-
# Lint as: python3
|
2 |
-
"""Keyphrase extraction as sequence labeling using contextualized embeddings"""
|
3 |
-
|
4 |
-
import datasets
|
5 |
-
|
6 |
-
|
7 |
-
logger = datasets.logging.get_logger(__name__)
|
8 |
-
|
9 |
-
|
10 |
-
_CITATION = """\
|
11 |
-
@article{sahrawat2020keyphrase,
|
12 |
-
title={Keyphrase extraction as sequence labeling using contextualized embeddings},
|
13 |
-
author={Sahrawat, Dhruva and Mahata, Debanjan and Zhang, Haimin and Kulkarni, Mayank and Sharma, Agniv and Gosangi, Rakesh and Stent, Amanda and Kumar, Yaman and Shah, Rajiv Ratn and Zimmermann, Roger},
|
14 |
-
journal={Advances in Information Retrieval},
|
15 |
-
volume={12036},
|
16 |
-
pages={328},
|
17 |
-
year={2020},
|
18 |
-
publisher={Nature Publishing Group}
|
19 |
-
}
|
20 |
-
"""
|
21 |
-
|
22 |
-
_DESCRIPTION = """\
|
23 |
-
This dataset is one of the datasets used in the paper entitled, Keyphrase Extraction from Scholarly Articles as Sequence
|
24 |
-
Labeling using Contextualized Embeddings https://arxiv.org/abs/1910.08840. The dataset consists of the Inspec corpus
|
25 |
-
which has been tagged using the BIO tagging scheme. The dataset should be used for training and evaluating keyphrase
|
26 |
-
extraction models when modeled as a sequence tagging task
|
27 |
-
"""
|
28 |
-
|
29 |
-
_URL = "https://huggingface.co/datasets/midas/inspec_ke_tagged/blob/main/"
|
30 |
-
_TRAINING_FILE = "train.txt"
|
31 |
-
_DEV_FILE = "valid.txt"
|
32 |
-
_TEST_FILE = "test.txt"
|
33 |
-
|
34 |
-
|
35 |
-
class InspecKETaggedConfig(datasets.BuilderConfig):
|
36 |
-
"""BuilderConfig for InspecKETagged"""
|
37 |
-
|
38 |
-
def __init__(self, **kwargs):
|
39 |
-
"""BuilderConfig for InspecKETagged.
|
40 |
-
|
41 |
-
Args:
|
42 |
-
**kwargs: keyword arguments forwarded to super.
|
43 |
-
"""
|
44 |
-
super(InspecKETaggedConfig, self).__init__(**kwargs)
|
45 |
-
|
46 |
-
|
47 |
-
class InspecKETagged(datasets.GeneratorBasedBuilder):
|
48 |
-
"""InspecKETagged dataset."""
|
49 |
-
|
50 |
-
BUILDER_CONFIGS = [
|
51 |
-
InspecKETaggedConfig(name="inspec_ke_tagged", version=datasets.Version("1.0.0"), description="InspecKETagged "
|
52 |
-
"dataset"),
|
53 |
-
]
|
54 |
-
|
55 |
-
def _info(self):
|
56 |
-
return datasets.DatasetInfo(
|
57 |
-
description=_DESCRIPTION,
|
58 |
-
features=datasets.Features(
|
59 |
-
{
|
60 |
-
"id": datasets.Value("string"),
|
61 |
-
"tokens": datasets.Sequence(datasets.Value("string")),
|
62 |
-
"ke_tags": datasets.Sequence(
|
63 |
-
datasets.features.ClassLabel(
|
64 |
-
names=[
|
65 |
-
"O",
|
66 |
-
"B-KEY",
|
67 |
-
"I-KEY",
|
68 |
-
]
|
69 |
-
)
|
70 |
-
),
|
71 |
-
}
|
72 |
-
),
|
73 |
-
supervised_keys=None,
|
74 |
-
homepage="https://www.ncbi.nlm.nih.gov/pmc/articles/PMC7148038/",
|
75 |
-
citation=_CITATION,
|
76 |
-
)
|
77 |
-
|
78 |
-
def _split_generators(self, dl_manager):
|
79 |
-
"""Returns SplitGenerators."""
|
80 |
-
urls_to_download = {
|
81 |
-
"train": f"{_URL}{_TRAINING_FILE}",
|
82 |
-
"dev": f"{_URL}{_DEV_FILE}",
|
83 |
-
"test": f"{_URL}{_TEST_FILE}",
|
84 |
-
}
|
85 |
-
downloaded_files = dl_manager.download_and_extract(urls_to_download)
|
86 |
-
|
87 |
-
return [
|
88 |
-
datasets.SplitGenerator(name=datasets.Split.TRAIN, gen_kwargs={"filepath": downloaded_files["train"]}),
|
89 |
-
datasets.SplitGenerator(name=datasets.Split.VALIDATION, gen_kwargs={"filepath": downloaded_files["dev"]}),
|
90 |
-
datasets.SplitGenerator(name=datasets.Split.TEST, gen_kwargs={"filepath": downloaded_files["test"]}),
|
91 |
-
]
|
92 |
-
|
93 |
-
def _generate_examples(self, filepath):
|
94 |
-
logger.info("⏳ Generating examples from = %s", filepath)
|
95 |
-
with open(filepath, encoding="utf-8") as f:
|
96 |
-
guid = 0
|
97 |
-
tokens = []
|
98 |
-
ke_tags = []
|
99 |
-
for line in f:
|
100 |
-
if line == "" or line == "\n":
|
101 |
-
if tokens:
|
102 |
-
yield guid, {
|
103 |
-
"id": str(guid),
|
104 |
-
"tokens": tokens,
|
105 |
-
"ke_tags": ke_tags,
|
106 |
-
}
|
107 |
-
guid += 1
|
108 |
-
tokens = []
|
109 |
-
ke_tags = []
|
110 |
-
else:
|
111 |
-
# the tokens are space separated
|
112 |
-
splits = line.split()
|
113 |
-
print(splits)
|
114 |
-
tokens.append(splits[0])
|
115 |
-
ke_tags.append(splits[1].rstrip())
|
116 |
-
# last example
|
117 |
-
yield guid, {
|
118 |
-
"id": str(guid),
|
119 |
-
"tokens": tokens,
|
120 |
-
"ke_tags": ke_tags,
|
121 |
-
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|