DeDeckerThomas
commited on
Commit
β’
d23943e
1
Parent(s):
31531b7
Update README.md
Browse files
README.md
CHANGED
@@ -6,7 +6,17 @@ tags:
|
|
6 |
datasets:
|
7 |
- midas/openkp
|
8 |
widget:
|
9 |
-
- text: "Keyphrase extraction is a technique in text analysis where you extract the important keyphrases from a
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
10 |
example_title: "Example 1"
|
11 |
- text: "In this work, we explore how to learn task specific language models aimed towards learning rich representation of keyphrases from text documents. We experiment with different masking strategies for pre-training transformer language models (LMs) in discriminative as well as generative settings. In the discriminative setting, we introduce a new pre-training objective - Keyphrase Boundary Infilling with Replacement (KBIR), showing large gains in performance (up to 9.26 points in F1) over SOTA, when LM pre-trained using KBIR is fine-tuned for the task of keyphrase extraction. In the generative setting, we introduce a new pre-training setup for BART - KeyBART, that reproduces the keyphrases related to the input text in the CatSeq format, instead of the denoised original input. This also led to gains in performance (up to 4.33 points inF1@M) over SOTA for keyphrase generation. Additionally, we also fine-tune the pre-trained language models on named entity recognition(NER), question answering (QA), relation extraction (RE), abstractive summarization and achieve comparable performance with that of the SOTA, showing that learning rich representation of keyphrases is indeed beneficial for many other fundamental NLP tasks."
|
12 |
example_title: "Example 2"
|
@@ -34,19 +44,20 @@ model-index:
|
|
34 |
name: F1@O (Absent)
|
35 |
---
|
36 |
# π Keyphrase Generation model: T5-small-OpenKP
|
37 |
-
Keyphrase extraction is a technique in text analysis where you extract the important keyphrases from a
|
|
|
38 |
|
39 |
|
40 |
## π Model Description
|
41 |
-
This model
|
42 |
|
43 |
-
## β Intended
|
44 |
### π Limitations
|
45 |
* Only works for English documents.
|
46 |
* For a custom model, please consult the training notebook for more information (link incoming).
|
47 |
* Sometimes the output doesn't make any sense.
|
48 |
|
49 |
-
### β How
|
50 |
```python
|
51 |
# Model parameters
|
52 |
from transformers import (
|
@@ -78,19 +89,25 @@ class KeyphraseGenerationPipeline(Text2TextGenerationPipeline):
|
|
78 |
# Load pipeline
|
79 |
model_name = "ml6team/keyphrase-generation-t5-small-openkp"
|
80 |
generator = KeyphraseGenerationPipeline(model=model_name)
|
|
|
81 |
|
82 |
```python
|
83 |
text = """
|
84 |
-
Keyphrase extraction is a technique in text analysis where you extract the
|
85 |
-
|
86 |
-
|
87 |
-
|
88 |
-
|
89 |
-
|
90 |
-
|
91 |
-
|
92 |
-
|
93 |
-
|
|
|
|
|
|
|
|
|
|
|
94 |
|
95 |
keyphrases = generator(text)
|
96 |
|
@@ -104,14 +121,13 @@ print(keyphrases)
|
|
104 |
```
|
105 |
|
106 |
## π Training Dataset
|
107 |
-
OpenKP is a large-scale, open-domain keyphrase extraction dataset with 148,124 real-world web documents along with 1-3 most relevant human-annotated keyphrases.
|
108 |
-
|
109 |
-
You can find more information here: https://github.com/microsoft/OpenKP.
|
110 |
|
111 |
-
## π·ββοΈ Training
|
112 |
-
For more in detail information, you can take a look at the training notebook
|
113 |
|
114 |
-
### Training
|
115 |
|
116 |
| Parameter | Value |
|
117 |
| --------- | ------|
|
@@ -120,9 +136,18 @@ For more in detail information, you can take a look at the training notebook (li
|
|
120 |
| Early Stopping Patience | 1 |
|
121 |
|
122 |
### Preprocessing
|
123 |
-
The documents in the dataset are already preprocessed into list of words with the corresponding keyphrases. The only thing that must be done is tokenization and joining all keyphrases into one string with a certain seperator of choice(
|
124 |
```python
|
125 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
126 |
kp_order_list = []
|
127 |
kp_set = set(kp_list)
|
128 |
text = tokenizer.decode(
|
@@ -141,7 +166,6 @@ def pre_process_keyphrases(text_ids, kp_list):
|
|
141 |
else:
|
142 |
present_kp.append(kp)
|
143 |
return present_kp, absent_kp
|
144 |
-
|
145 |
def preprocess_fuction(samples):
|
146 |
processed_samples = {"input_ids": [], "attention_mask": [], "labels": []}
|
147 |
for i, sample in enumerate(samples[dataset_document_column]):
|
@@ -151,7 +175,7 @@ def preprocess_fuction(samples):
|
|
151 |
padding="max_length",
|
152 |
truncation=True,
|
153 |
)
|
154 |
-
present_kp, absent_kp =
|
155 |
text_ids=inputs["input_ids"],
|
156 |
kp_list=samples["extractive_keyphrases"][i]
|
157 |
+ samples["abstractive_keyphrases"][i],
|
@@ -171,7 +195,13 @@ def preprocess_fuction(samples):
|
|
171 |
processed_samples[key].append(inputs[key])
|
172 |
processed_samples["labels"].append(targets["input_ids"])
|
173 |
return processed_samples
|
|
|
|
|
|
|
|
|
|
|
174 |
```
|
|
|
175 |
### Postprocessing
|
176 |
For the post-processing, you will need to split the string based on the keyphrase separator.
|
177 |
```python
|
@@ -179,9 +209,9 @@ def extract_keyphrases(examples):
|
|
179 |
return [example.split(keyphrase_sep_token) for example in examples]
|
180 |
```
|
181 |
|
182 |
-
## π Evaluation
|
183 |
|
184 |
-
|
185 |
The model achieves the following results on the OpenKP test set:
|
186 |
|
187 |
|
|
|
6 |
datasets:
|
7 |
- midas/openkp
|
8 |
widget:
|
9 |
+
- text: "Keyphrase extraction is a technique in text analysis where you extract the important keyphrases from a document.
|
10 |
+
Thanks to these keyphrases humans can understand the content of a text very quickly and easily without reading
|
11 |
+
it completely. Keyphrase extraction was first done primarily by human annotators, who read the text in detail
|
12 |
+
and then wrote down the most important keyphrases. The disadvantage is that if you work with a lot of documents,
|
13 |
+
this process can take a lot of time.
|
14 |
+
|
15 |
+
Here is where Artificial Intelligence comes in. Currently, classical machine learning methods, that use statistical
|
16 |
+
and linguistic features, are widely used for the extraction process. Now with deep learning, it is possible to capture
|
17 |
+
the semantic meaning of a text even better than these classical methods. Classical methods look at the frequency,
|
18 |
+
occurrence and order of words in the text, whereas these neural approaches can capture long-term semantic dependencies
|
19 |
+
and context of words in a text."
|
20 |
example_title: "Example 1"
|
21 |
- text: "In this work, we explore how to learn task specific language models aimed towards learning rich representation of keyphrases from text documents. We experiment with different masking strategies for pre-training transformer language models (LMs) in discriminative as well as generative settings. In the discriminative setting, we introduce a new pre-training objective - Keyphrase Boundary Infilling with Replacement (KBIR), showing large gains in performance (up to 9.26 points in F1) over SOTA, when LM pre-trained using KBIR is fine-tuned for the task of keyphrase extraction. In the generative setting, we introduce a new pre-training setup for BART - KeyBART, that reproduces the keyphrases related to the input text in the CatSeq format, instead of the denoised original input. This also led to gains in performance (up to 4.33 points inF1@M) over SOTA for keyphrase generation. Additionally, we also fine-tune the pre-trained language models on named entity recognition(NER), question answering (QA), relation extraction (RE), abstractive summarization and achieve comparable performance with that of the SOTA, showing that learning rich representation of keyphrases is indeed beneficial for many other fundamental NLP tasks."
|
22 |
example_title: "Example 2"
|
|
|
44 |
name: F1@O (Absent)
|
45 |
---
|
46 |
# π Keyphrase Generation model: T5-small-OpenKP
|
47 |
+
Keyphrase extraction is a technique in text analysis where you extract the important keyphrases from a document. Thanks to these keyphrases humans can understand the content of a text very quickly and easily without reading it completely. Keyphrase extraction was first done primarily by human annotators, who read the text in detail and then wrote down the most important keyphrases. The disadvantage is that if you work with a lot of documents, this process can take a lot of time β³.
|
48 |
+
Here is where Artificial Intelligence π€ comes in. Currently, classical machine learning methods, that use statistical and linguistic features, are widely used for the extraction process. Now with deep learning, it is possible to capture the semantic meaning of a text even better than these classical methods. Classical methods look at the frequency, occurrence and order of words in the text, whereas these neural approaches can capture long-term semantic dependencies and context of words in a text.
|
49 |
|
50 |
|
51 |
## π Model Description
|
52 |
+
This model uses [T5-small model](https://huggingface.co/t5-small) as its base model and fine-tunes it on the [OpenKP dataset](https://huggingface.co/datasets/midas/openkp). Keyphrase generation transformers are fine-tuned as a text-to-text generation problem where the keyphrases are generated. The result is a concatenated string with all keyphrases separated by a given delimiter (i.e. β;β). These models are capable of generating present and absent keyphrases.
|
53 |
|
54 |
+
## β Intended Uses & Limitations
|
55 |
### π Limitations
|
56 |
* Only works for English documents.
|
57 |
* For a custom model, please consult the training notebook for more information (link incoming).
|
58 |
* Sometimes the output doesn't make any sense.
|
59 |
|
60 |
+
### β How To Use
|
61 |
```python
|
62 |
# Model parameters
|
63 |
from transformers import (
|
|
|
89 |
# Load pipeline
|
90 |
model_name = "ml6team/keyphrase-generation-t5-small-openkp"
|
91 |
generator = KeyphraseGenerationPipeline(model=model_name)
|
92 |
+
```
|
93 |
|
94 |
```python
|
95 |
text = """
|
96 |
+
Keyphrase extraction is a technique in text analysis where you extract the
|
97 |
+
important keyphrases from a document. Thanks to these keyphrases humans can
|
98 |
+
understand the content of a text very quickly and easily without reading it
|
99 |
+
completely. Keyphrase extraction was first done primarily by human annotators,
|
100 |
+
who read the text in detail and then wrote down the most important keyphrases.
|
101 |
+
The disadvantage is that if you work with a lot of documents, this process
|
102 |
+
can take a lot of time.
|
103 |
+
Here is where Artificial Intelligence comes in. Currently, classical machine
|
104 |
+
learning methods, that use statistical and linguistic features, are widely used
|
105 |
+
for the extraction process. Now with deep learning, it is possible to capture
|
106 |
+
the semantic meaning of a text even better than these classical methods.
|
107 |
+
Classical methods look at the frequency, occurrence and order of words
|
108 |
+
in the text, whereas these neural approaches can capture long-term
|
109 |
+
semantic dependencies and context of words in a text.
|
110 |
+
""".replace("\n", " ")
|
111 |
|
112 |
keyphrases = generator(text)
|
113 |
|
|
|
121 |
```
|
122 |
|
123 |
## π Training Dataset
|
124 |
+
[OpenKP](https://github.com/microsoft/OpenKP) is a large-scale, open-domain keyphrase extraction dataset with 148,124 real-world web documents along with 1-3 most relevant human-annotated keyphrases.
|
125 |
+
You can find more information in the [paper](https://arxiv.org/abs/1911.02671).
|
|
|
126 |
|
127 |
+
## π·ββοΈ Training Procedure
|
128 |
+
For more in detail information, you can take a look at the [training notebook]().
|
129 |
|
130 |
+
### Training Parameters
|
131 |
|
132 |
| Parameter | Value |
|
133 |
| --------- | ------|
|
|
|
136 |
| Early Stopping Patience | 1 |
|
137 |
|
138 |
### Preprocessing
|
139 |
+
The documents in the dataset are already preprocessed into list of words with the corresponding keyphrases. The only thing that must be done is tokenization and joining all keyphrases into one string with a certain seperator of choice( ```;``` ).
|
140 |
```python
|
141 |
+
from datasets import load_dataset
|
142 |
+
from transformers import AutoTokenizer
|
143 |
+
# Tokenizer
|
144 |
+
tokenizer = AutoTokenizer.from_pretrained("t5-small", add_prefix_space=True)
|
145 |
+
# Dataset parameters
|
146 |
+
dataset_full_name = "midas/inspec"
|
147 |
+
dataset_subset = "raw"
|
148 |
+
dataset_document_column = "document"
|
149 |
+
keyphrase_sep_token = ";"
|
150 |
+
def preprocess_keyphrases(text_ids, kp_list):
|
151 |
kp_order_list = []
|
152 |
kp_set = set(kp_list)
|
153 |
text = tokenizer.decode(
|
|
|
166 |
else:
|
167 |
present_kp.append(kp)
|
168 |
return present_kp, absent_kp
|
|
|
169 |
def preprocess_fuction(samples):
|
170 |
processed_samples = {"input_ids": [], "attention_mask": [], "labels": []}
|
171 |
for i, sample in enumerate(samples[dataset_document_column]):
|
|
|
175 |
padding="max_length",
|
176 |
truncation=True,
|
177 |
)
|
178 |
+
present_kp, absent_kp = preprocess_keyphrases(
|
179 |
text_ids=inputs["input_ids"],
|
180 |
kp_list=samples["extractive_keyphrases"][i]
|
181 |
+ samples["abstractive_keyphrases"][i],
|
|
|
195 |
processed_samples[key].append(inputs[key])
|
196 |
processed_samples["labels"].append(targets["input_ids"])
|
197 |
return processed_samples
|
198 |
+
# Load dataset
|
199 |
+
dataset = load_dataset(dataset_full_name, dataset_subset)
|
200 |
+
# Preprocess dataset
|
201 |
+
tokenized_dataset = dataset.map(preprocess_fuction, batched=True)
|
202 |
+
|
203 |
```
|
204 |
+
|
205 |
### Postprocessing
|
206 |
For the post-processing, you will need to split the string based on the keyphrase separator.
|
207 |
```python
|
|
|
209 |
return [example.split(keyphrase_sep_token) for example in examples]
|
210 |
```
|
211 |
|
212 |
+
## π Evaluation Results
|
213 |
|
214 |
+
Traditional evaluation methods are the precision, recall and F1-score @k,m where k is the number that stands for the first k predicted keyphrases and m for the average amount of predicted keyphrases. In keyphrase generation you also look at F1@O where O stands for the number of ground truth keyphrases.
|
215 |
The model achieves the following results on the OpenKP test set:
|
216 |
|
217 |
|