DeDeckerThomas
commited on
Commit
β’
da1898a
1
Parent(s):
f804ef4
Update README.md
Browse files
README.md
CHANGED
@@ -6,7 +6,17 @@ tags:
|
|
6 |
datasets:
|
7 |
- midas/inspec
|
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,24 +44,25 @@ model-index:
|
|
34 |
name: F1@O (Absent)
|
35 |
---
|
36 |
|
37 |
-
# π Keyphrase Generation
|
38 |
-
Keyphrase extraction is a technique in text analysis where you extract the important keyphrases from a
|
|
|
|
|
39 |
|
40 |
## π Model Description
|
41 |
-
This model
|
42 |
-
KeyBART focuses on learning a better representation of keyphrases in a generative setting. It produces the keyphrases associated with the input. This is accomplished by predicting the original input based on a changed input. The input is changed by token masking, keyphrase masking and keyphrase replacement. This model can already be used without any fine-tuning, but can be fine-tuned if needed.
|
43 |
You can find more information about the architecture in this paper: https://arxiv.org/abs/2112.08547.
|
44 |
|
45 |
Kulkarni, Mayank, Debanjan Mahata, Ravneet Arora, and Rajarshi Bhowmik. "Learning Rich Representation of Keyphrases from Text." arXiv preprint arXiv:2112.08547 (2021).
|
46 |
|
47 |
-
## β Intended
|
48 |
### π Limitations
|
49 |
* This keyphrase generation model is very domain-specific and will perform very well on abstracts of scientific papers. It's not recommended to use this model for other domains, but you are free to test it out.
|
50 |
* Only works for English documents.
|
51 |
-
* For a custom model, please consult the training notebook for more information
|
52 |
* Sometimes the output doesn't make any sense.
|
53 |
|
54 |
-
### β How
|
55 |
```python
|
56 |
# Model parameters
|
57 |
from transformers import (
|
@@ -85,17 +96,24 @@ model_name = "ml6team/keyphrase-generation-keybart-inspec"
|
|
85 |
generator = KeyphraseGenerationPipeline(model=model_name)
|
86 |
|
87 |
```python
|
|
|
88 |
text = """
|
89 |
-
Keyphrase extraction is a technique in text analysis where you extract the
|
90 |
-
|
91 |
-
|
92 |
-
|
93 |
-
|
94 |
-
|
95 |
-
|
96 |
-
|
97 |
-
|
98 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
99 |
|
100 |
keyphrases = generator(text)
|
101 |
|
@@ -105,18 +123,18 @@ print(keyphrases)
|
|
105 |
|
106 |
```
|
107 |
# Output
|
108 |
-
[['keyphrase extraction', 'text analysis', '
|
109 |
```
|
110 |
|
111 |
## π Training Dataset
|
112 |
-
Inspec is a keyphrase extraction/generation dataset consisting of 2000 English scientific papers from the scientific domains of Computers and Control and Information Technology published between 1998 to 2002. The keyphrases are annotated by professional indexers or editors.
|
113 |
|
114 |
-
You can find more information
|
115 |
|
116 |
-
## π·ββοΈ Training
|
117 |
-
For more in detail information, you can take a look at the training notebook
|
118 |
|
119 |
-
### Training
|
120 |
|
121 |
| Parameter | Value |
|
122 |
| --------- | ------|
|
@@ -125,9 +143,22 @@ For more in detail information, you can take a look at the training notebook (li
|
|
125 |
| Early Stopping Patience | 1 |
|
126 |
|
127 |
### Preprocessing
|
128 |
-
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(
|
129 |
```python
|
130 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
131 |
kp_order_list = []
|
132 |
kp_set = set(kp_list)
|
133 |
text = tokenizer.decode(
|
@@ -159,7 +190,7 @@ def preprocess_fuction(samples):
|
|
159 |
padding="max_length",
|
160 |
truncation=True,
|
161 |
)
|
162 |
-
present_kp, absent_kp =
|
163 |
text_ids=inputs["input_ids"],
|
164 |
kp_list=samples["extractive_keyphrases"][i]
|
165 |
+ samples["abstractive_keyphrases"][i],
|
@@ -181,6 +212,12 @@ def preprocess_fuction(samples):
|
|
181 |
processed_samples[key].append(inputs[key])
|
182 |
processed_samples["labels"].append(targets["input_ids"])
|
183 |
return processed_samples
|
|
|
|
|
|
|
|
|
|
|
|
|
184 |
```
|
185 |
|
186 |
### Postprocessing
|
@@ -190,25 +227,24 @@ def extract_keyphrases(examples):
|
|
190 |
return [example.split(keyphrase_sep_token) for example in examples]
|
191 |
```
|
192 |
## π Evaluation results
|
193 |
-
|
194 |
-
One of the traditional evaluation methods is 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.
|
195 |
The model achieves the following results on the Inspec test set:
|
196 |
|
197 |
|
198 |
-
### Extractive
|
199 |
|
200 |
| Dataset | P@5 | R@5 | F1@5 | P@10 | R@10 | F1@10 | P@M | R@M | F1@M | P@O | R@O | F1@O |
|
201 |
|:-----------------:|:----:|:----:|:----:|:----:|:----:|:-----:|:----:|:----:|:----:|:----:|:----:|:----:|
|
202 |
| Inspec Test Set | 0.40 | 0.37 | 0.35 | 0.20 | 0.37 | 0.24 | 0.42 | 0.37 | 0.36 | 0.33 | 0.33 | 0.33 |
|
203 |
|
204 |
-
### Abstractive
|
205 |
|
206 |
| Dataset | P@5 | R@5 | F1@5 | P@10 | R@10 | F1@10 | P@M | R@M | F1@M | P@O | R@O | F1@O |
|
207 |
|:-----------------:|:----:|:----:|:----:|:----:|:----:|:-----:|:----:|:----:|:----:|:----:|:----:|:----:|
|
208 |
| Inspec Test Set | 0.07 | 0.12 | 0.08 | 0.03 | 0.12 | 0.05 | 0.08 | 0.12 | 0.08 | 0.08 | 0.12 | 0.08 |
|
209 |
|
210 |
|
211 |
-
For more information on the evaluation process, you can take a look at the keyphrase extraction evaluation notebook.
|
212 |
|
213 |
## π¨ Issues
|
214 |
Please feel free to start discussions in the Community Tab.
|
|
|
6 |
datasets:
|
7 |
- midas/inspec
|
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 |
|
47 |
+
# π Keyphrase Generation Model: KeyBART-inspec
|
48 |
+
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 β³.
|
49 |
+
|
50 |
+
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.
|
51 |
|
52 |
## π Model Description
|
53 |
+
This model uses [KeyBART](https://huggingface.co/bloomberg/KeyBART) as its base model and fine-tunes it on the [Inspec dataset](https://huggingface.co/datasets/midas/inspec). KeyBART focuses on learning a better representation of keyphrases in a generative setting. It produces the keyphrases associated with the input. This is accomplished by predicting the original input based on a changed input. The input is changed by token masking, keyphrase masking and keyphrase replacement. This model can already be used without any fine-tuning, but can be fine-tuned if needed.
|
|
|
54 |
You can find more information about the architecture in this paper: https://arxiv.org/abs/2112.08547.
|
55 |
|
56 |
Kulkarni, Mayank, Debanjan Mahata, Ravneet Arora, and Rajarshi Bhowmik. "Learning Rich Representation of Keyphrases from Text." arXiv preprint arXiv:2112.08547 (2021).
|
57 |
|
58 |
+
## β Intended Uses & Limitations
|
59 |
### π Limitations
|
60 |
* This keyphrase generation model is very domain-specific and will perform very well on abstracts of scientific papers. It's not recommended to use this model for other domains, but you are free to test it out.
|
61 |
* Only works for English documents.
|
62 |
+
* For a custom model, please consult the [training notebook]() for more information.
|
63 |
* Sometimes the output doesn't make any sense.
|
64 |
|
65 |
+
### β How To Use
|
66 |
```python
|
67 |
# Model parameters
|
68 |
from transformers import (
|
|
|
96 |
generator = KeyphraseGenerationPipeline(model=model_name)
|
97 |
|
98 |
```python
|
99 |
+
# Inference
|
100 |
text = """
|
101 |
+
Keyphrase extraction is a technique in text analysis where you extract the
|
102 |
+
important keyphrases from a document. Thanks to these keyphrases humans can
|
103 |
+
understand the content of a text very quickly and easily without reading it
|
104 |
+
completely. Keyphrase extraction was first done primarily by human annotators,
|
105 |
+
who read the text in detail and then wrote down the most important keyphrases.
|
106 |
+
The disadvantage is that if you work with a lot of documents, this process
|
107 |
+
can take a lot of time.
|
108 |
+
|
109 |
+
Here is where Artificial Intelligence comes in. Currently, classical machine
|
110 |
+
learning methods, that use statistical and linguistic features, are widely used
|
111 |
+
for the extraction process. Now with deep learning, it is possible to capture
|
112 |
+
the semantic meaning of a text even better than these classical methods.
|
113 |
+
Classical methods look at the frequency, occurrence and order of words
|
114 |
+
in the text, whereas these neural approaches can capture long-term
|
115 |
+
semantic dependencies and context of words in a text.
|
116 |
+
""".replace("\n", " ")
|
117 |
|
118 |
keyphrases = generator(text)
|
119 |
|
|
|
123 |
|
124 |
```
|
125 |
# Output
|
126 |
+
[['keyphrase extraction', 'text analysis', 'keyphrases', 'human annotators', 'artificial']]
|
127 |
```
|
128 |
|
129 |
## π Training Dataset
|
130 |
+
[Inspec](https://huggingface.co/datasets/midas/inspec) is a keyphrase extraction/generation dataset consisting of 2000 English scientific papers from the scientific domains of Computers and Control and Information Technology published between 1998 to 2002. The keyphrases are annotated by professional indexers or editors.
|
131 |
|
132 |
+
You can find more information in the [paper](https://dl.acm.org/doi/10.3115/1119355.1119383).
|
133 |
|
134 |
+
## π·ββοΈ Training Procedure
|
135 |
+
For more in detail information, you can take a look at the [training notebook]().
|
136 |
|
137 |
+
### Training Parameters
|
138 |
|
139 |
| Parameter | Value |
|
140 |
| --------- | ------|
|
|
|
143 |
| Early Stopping Patience | 1 |
|
144 |
|
145 |
### Preprocessing
|
146 |
+
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( ```;``` ).
|
147 |
```python
|
148 |
+
from datasets import load_dataset
|
149 |
+
from transformers import AutoTokenizer
|
150 |
+
|
151 |
+
# Tokenizer
|
152 |
+
tokenizer = AutoTokenizer.from_pretrained("bloomberg/KeyBART", add_prefix_space=True)
|
153 |
+
|
154 |
+
# Dataset parameters
|
155 |
+
dataset_full_name = "midas/inspec"
|
156 |
+
dataset_subset = "raw"
|
157 |
+
dataset_document_column = "document"
|
158 |
+
|
159 |
+
keyphrase_sep_token = ";"
|
160 |
+
|
161 |
+
def preprocess_keyphrases(text_ids, kp_list):
|
162 |
kp_order_list = []
|
163 |
kp_set = set(kp_list)
|
164 |
text = tokenizer.decode(
|
|
|
190 |
padding="max_length",
|
191 |
truncation=True,
|
192 |
)
|
193 |
+
present_kp, absent_kp = preprocess_keyphrases(
|
194 |
text_ids=inputs["input_ids"],
|
195 |
kp_list=samples["extractive_keyphrases"][i]
|
196 |
+ samples["abstractive_keyphrases"][i],
|
|
|
212 |
processed_samples[key].append(inputs[key])
|
213 |
processed_samples["labels"].append(targets["input_ids"])
|
214 |
return processed_samples
|
215 |
+
|
216 |
+
# Load dataset
|
217 |
+
dataset = load_dataset(dataset_full_name, dataset_subset)
|
218 |
+
# Preprocess dataset
|
219 |
+
tokenized_dataset = dataset.map(preprocess_fuction, batched=True)
|
220 |
+
|
221 |
```
|
222 |
|
223 |
### Postprocessing
|
|
|
227 |
return [example.split(keyphrase_sep_token) for example in examples]
|
228 |
```
|
229 |
## π Evaluation results
|
230 |
+
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.
|
|
|
231 |
The model achieves the following results on the Inspec test set:
|
232 |
|
233 |
|
234 |
+
### Extractive Keyphrases
|
235 |
|
236 |
| Dataset | P@5 | R@5 | F1@5 | P@10 | R@10 | F1@10 | P@M | R@M | F1@M | P@O | R@O | F1@O |
|
237 |
|:-----------------:|:----:|:----:|:----:|:----:|:----:|:-----:|:----:|:----:|:----:|:----:|:----:|:----:|
|
238 |
| Inspec Test Set | 0.40 | 0.37 | 0.35 | 0.20 | 0.37 | 0.24 | 0.42 | 0.37 | 0.36 | 0.33 | 0.33 | 0.33 |
|
239 |
|
240 |
+
### Abstractive Keyphrases
|
241 |
|
242 |
| Dataset | P@5 | R@5 | F1@5 | P@10 | R@10 | F1@10 | P@M | R@M | F1@M | P@O | R@O | F1@O |
|
243 |
|:-----------------:|:----:|:----:|:----:|:----:|:----:|:-----:|:----:|:----:|:----:|:----:|:----:|:----:|
|
244 |
| Inspec Test Set | 0.07 | 0.12 | 0.08 | 0.03 | 0.12 | 0.05 | 0.08 | 0.12 | 0.08 | 0.08 | 0.12 | 0.08 |
|
245 |
|
246 |
|
247 |
+
For more information on the evaluation process, you can take a look at the keyphrase extraction [evaluation notebook]().
|
248 |
|
249 |
## π¨ Issues
|
250 |
Please feel free to start discussions in the Community Tab.
|