Datasets:
update files with spacy tokenizer
Browse files- README.md +21 -11
- dev.jsonl +0 -0
- prmu.py +99 -0
- test.jsonl +0 -0
- train.jsonl +0 -0
README.md
CHANGED
@@ -5,25 +5,24 @@
|
|
5 |
Inspec is a dataset for benchmarking keyphrase extraction and generation models.
|
6 |
The dataset is composed of 2,000 abstracts of scientific papers collected from the [Inspec database](https://www.theiet.org/resources/inspec/).
|
7 |
Keyphrases were annotated by professional indexers in an uncontrolled setting (that is, not limited to thesaurus entries).
|
8 |
-
Details about the inspec dataset can be found in the original paper
|
9 |
-
- Anette Hulth. 2003.
|
10 |
-
[Improved automatic keyword extraction given more linguistic knowledge](https://aclanthology.org/W03-1028).
|
11 |
-
In Proceedings of the 2003 Conference on Empirical Methods in Natural Language Processing, pages 216-223.
|
12 |
-
|
13 |
-
Reference (indexer-assigned) keyphrases are also categorized under the PRMU (<u>P</u>resent-<u>R</u>eordered-<u>M</u>ixed-<u>U</u>nseen) scheme as proposed in the following paper:
|
14 |
-
- Florian Boudin and Ygor Gallina. 2021.
|
15 |
-
[Redefining Absent Keyphrases and their Effect on Retrieval Effectiveness](https://aclanthology.org/2021.naacl-main.330/).
|
16 |
-
In Proceedings of the 2021 Conference of the North American Chapter of the Association for Computational Linguistics: Human Language Technologies, pages 4185–4193, Online. Association for Computational Linguistics.
|
17 |
|
18 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
19 |
|
20 |
The dataset is divided into the following three splits:
|
21 |
|
22 |
| Split | # documents | # keyphrases | % Present | % Reordered | % Mixed | % Unseen |
|
23 |
| :--------- | ----------: | -----------: | --------: | ----------: | ------: | -------: |
|
24 |
| Train | 1,000 | 9.79 | 77.83 | 9.90 | 6.30 | 5.98 |
|
25 |
-
| Test | 500 | 9.83 | 78.49 | 9.82 | 6.76 | 4.92 |
|
26 |
| Validation | 500 | 9.15 | 77.90 | 9.82 | 6.74 | 5.54 |
|
|
|
27 |
|
28 |
The following data fields are available :
|
29 |
|
@@ -33,3 +32,14 @@ The following data fields are available :
|
|
33 |
- **keyphrases**: list of reference keyphrases.
|
34 |
- **prmu**: list of <u>P</u>resent-<u>R</u>eordered-<u>M</u>ixed-<u>U</u>nseen categories for reference keyphrases.
|
35 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
5 |
Inspec is a dataset for benchmarking keyphrase extraction and generation models.
|
6 |
The dataset is composed of 2,000 abstracts of scientific papers collected from the [Inspec database](https://www.theiet.org/resources/inspec/).
|
7 |
Keyphrases were annotated by professional indexers in an uncontrolled setting (that is, not limited to thesaurus entries).
|
8 |
+
Details about the inspec dataset can be found in the original paper [(Hulth, 2003)][hulth-2003].
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
9 |
|
10 |
+
|
11 |
+
Reference (indexer-assigned) keyphrases are also categorized under the PRMU (<u>P</u>resent-<u>R</u>eordered-<u>M</u>ixed-<u>U</u>nseen) scheme as proposed in [(Boudin and Gallina, 2021)][boudin-2021].
|
12 |
+
|
13 |
+
Text pre-processing (tokenization) is carried out using `spacy` (`en_core_web_sm` model) with a special rule to avoid splitting words with hyphens (e.g. graph-based is kept as one token).
|
14 |
+
Stemming (Porter's stemmer implementation provided in `nltk`) is performed before reference keyphrases are matched against the source text.
|
15 |
+
Details about the process can be found in `prmu.py`.
|
16 |
+
|
17 |
+
## Content and statistics
|
18 |
|
19 |
The dataset is divided into the following three splits:
|
20 |
|
21 |
| Split | # documents | # keyphrases | % Present | % Reordered | % Mixed | % Unseen |
|
22 |
| :--------- | ----------: | -----------: | --------: | ----------: | ------: | -------: |
|
23 |
| Train | 1,000 | 9.79 | 77.83 | 9.90 | 6.30 | 5.98 |
|
|
|
24 |
| Validation | 500 | 9.15 | 77.90 | 9.82 | 6.74 | 5.54 |
|
25 |
+
| Test | 500 | 9.83 | 78.49 | 9.82 | 6.76 | 4.92 |
|
26 |
|
27 |
The following data fields are available :
|
28 |
|
|
|
32 |
- **keyphrases**: list of reference keyphrases.
|
33 |
- **prmu**: list of <u>P</u>resent-<u>R</u>eordered-<u>M</u>ixed-<u>U</u>nseen categories for reference keyphrases.
|
34 |
|
35 |
+
## References
|
36 |
+
|
37 |
+
- (Hulth, 2003) Anette Hulth. 2003.
|
38 |
+
[Improved automatic keyword extraction given more linguistic knowledge](https://aclanthology.org/W03-1028).
|
39 |
+
In Proceedings of the 2003 Conference on Empirical Methods in Natural Language Processing, pages 216-223.
|
40 |
+
- (Boudin and Gallina, 2021) Florian Boudin and Ygor Gallina. 2021.
|
41 |
+
[Redefining Absent Keyphrases and their Effect on Retrieval Effectiveness](https://aclanthology.org/2021.naacl-main.330/).
|
42 |
+
In Proceedings of the 2021 Conference of the North American Chapter of the Association for Computational Linguistics: Human Language Technologies, pages 4185–4193, Online. Association for Computational Linguistics.
|
43 |
+
|
44 |
+
[hulth-2003]: https://aclanthology.org/W03-1028/
|
45 |
+
[boudin-2021]: https://aclanthology.org/2021.naacl-main.330/
|
dev.jsonl
CHANGED
The diff for this file is too large to render.
See raw diff
|
|
prmu.py
ADDED
@@ -0,0 +1,99 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# -*- coding: utf-8 -*-
|
2 |
+
|
3 |
+
import sys
|
4 |
+
import json
|
5 |
+
import spacy
|
6 |
+
|
7 |
+
from nltk.stem.snowball import SnowballStemmer as Stemmer
|
8 |
+
|
9 |
+
nlp = spacy.load("en_core_web_sm")
|
10 |
+
|
11 |
+
# https://spacy.io/usage/linguistic-features#native-tokenizer-additions
|
12 |
+
|
13 |
+
from spacy.lang.char_classes import ALPHA, ALPHA_LOWER, ALPHA_UPPER
|
14 |
+
from spacy.lang.char_classes import CONCAT_QUOTES, LIST_ELLIPSES, LIST_ICONS
|
15 |
+
from spacy.util import compile_infix_regex
|
16 |
+
|
17 |
+
# Modify tokenizer infix patterns
|
18 |
+
infixes = (
|
19 |
+
LIST_ELLIPSES
|
20 |
+
+ LIST_ICONS
|
21 |
+
+ [
|
22 |
+
r"(?<=[0-9])[+\-\*^](?=[0-9-])",
|
23 |
+
r"(?<=[{al}{q}])\.(?=[{au}{q}])".format(
|
24 |
+
al=ALPHA_LOWER, au=ALPHA_UPPER, q=CONCAT_QUOTES
|
25 |
+
),
|
26 |
+
r"(?<=[{a}]),(?=[{a}])".format(a=ALPHA),
|
27 |
+
# ✅ Commented out regex that splits on hyphens between letters:
|
28 |
+
# r"(?<=[{a}])(?:{h})(?=[{a}])".format(a=ALPHA, h=HYPHENS),
|
29 |
+
r"(?<=[{a}0-9])[:<>=/](?=[{a}])".format(a=ALPHA),
|
30 |
+
]
|
31 |
+
)
|
32 |
+
|
33 |
+
infix_re = compile_infix_regex(infixes)
|
34 |
+
nlp.tokenizer.infix_finditer = infix_re.finditer
|
35 |
+
|
36 |
+
|
37 |
+
def contains(subseq, inseq):
|
38 |
+
return any(inseq[pos:pos + len(subseq)] == subseq for pos in range(0, len(inseq) - len(subseq) + 1))
|
39 |
+
|
40 |
+
|
41 |
+
def find_pmru(tok_title, tok_text, tok_kp):
|
42 |
+
"""Find PRMU category of a given keyphrase."""
|
43 |
+
|
44 |
+
# if kp is present
|
45 |
+
if contains(tok_kp, tok_title) or contains(tok_kp, tok_text):
|
46 |
+
return "P"
|
47 |
+
|
48 |
+
# if kp is considered as absent
|
49 |
+
else:
|
50 |
+
|
51 |
+
# find present and absent words
|
52 |
+
present_words = [w for w in tok_kp if w in tok_title or w in tok_text]
|
53 |
+
|
54 |
+
# if "all" words are present
|
55 |
+
if len(present_words) == len(tok_kp):
|
56 |
+
return "R"
|
57 |
+
# if "some" words are present
|
58 |
+
elif len(present_words) > 0:
|
59 |
+
return "M"
|
60 |
+
# if "no" words are present
|
61 |
+
else:
|
62 |
+
return "U"
|
63 |
+
|
64 |
+
|
65 |
+
if __name__ == '__main__':
|
66 |
+
|
67 |
+
data = []
|
68 |
+
|
69 |
+
# read the dataset
|
70 |
+
with open(sys.argv[1], 'r') as f:
|
71 |
+
# loop through the documents
|
72 |
+
for line in f:
|
73 |
+
doc = json.loads(line.strip())
|
74 |
+
|
75 |
+
title_spacy = nlp(doc['title'])
|
76 |
+
abstract_spacy = nlp(doc['abstract'])
|
77 |
+
|
78 |
+
title_tokens = [token.text for token in title_spacy]
|
79 |
+
abstract_tokens = [token.text for token in abstract_spacy]
|
80 |
+
|
81 |
+
title_stems = [Stemmer('porter').stem(w.lower()) for w in title_tokens]
|
82 |
+
abstract_stems = [Stemmer('porter').stem(w.lower()) for w in abstract_tokens]
|
83 |
+
|
84 |
+
keyphrases_stems = []
|
85 |
+
for keyphrase in doc['keyphrases']:
|
86 |
+
keyphrase_spacy = nlp(keyphrase)
|
87 |
+
keyphrase_tokens = [token.text for token in keyphrase_spacy]
|
88 |
+
keyphrase_stems = [Stemmer('porter').stem(w.lower()) for w in keyphrase_tokens]
|
89 |
+
keyphrases_stems.append(keyphrase_stems)
|
90 |
+
|
91 |
+
prmu = [find_pmru(title_stems, abstract_stems, kp) for kp in keyphrases_stems]
|
92 |
+
doc['prmu'] = prmu
|
93 |
+
|
94 |
+
data.append(json.dumps(doc))
|
95 |
+
print(doc['id'])
|
96 |
+
|
97 |
+
# write the json
|
98 |
+
with open(sys.argv[2], 'w') as o:
|
99 |
+
o.write("\n".join(data))
|
test.jsonl
CHANGED
The diff for this file is too large to render.
See raw diff
|
|
train.jsonl
CHANGED
The diff for this file is too large to render.
See raw diff
|
|