DeDeckerThomas commited on
Commit
d876c89
β€’
1 Parent(s): ac2ec8c

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +71 -26
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 text. Since this is a time-consuming process, Artificial Intelligence is used to automate it. Currently, classical machine learning methods, that use statistics and linguistics, are widely used for the extraction process. The fact that these methods have been widely used in the community has the advantage that there are many easy-to-use libraries. Now with the recent innovations in NLP, transformers can be used to improve keyphrase extraction. Transformers also focus on the semantics and context of a document, which is quite an improvement."
 
 
 
 
 
 
 
 
 
 
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"
@@ -33,21 +43,23 @@ model-index:
33
  value: 0.065
34
  name: F1@O (Absent)
35
  ---
36
- # πŸ”‘ Keyphrase Generation model: T5-small-inspec
37
- Keyphrase extraction is a technique in text analysis where you extract the important keyphrases from a text. Since this is a time-consuming process, Artificial Intelligence is used to automate it. Currently, classical machine learning methods, that use statistics and linguistics, are widely used for the extraction process. The fact that these methods have been widely used in the community has the advantage that there are many easy-to-use libraries. Now with the recent innovations in NLP, transformers can be used to improve keyphrase extraction. Transformers also focus on the semantics and context of a document, which is quite an improvement.
 
 
38
 
39
 
40
  ## πŸ““ Model Description
41
- This model is a fine-tuned [T5-small model](https://huggingface.co/t5-small) on the Inspec dataset.
42
 
43
- ## βœ‹ Intended uses & limitations
44
  ### πŸ›‘ Limitations
45
  * 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.
46
  * Only works for English documents.
47
- * For a custom model, please consult the training notebook for more information (link incoming).
48
  * Sometimes the output doesn't make any sense.
49
 
50
- ### ❓ How to use
51
  ```python
52
  # Model parameters
53
  from transformers import (
@@ -80,18 +92,26 @@ class KeyphraseGenerationPipeline(Text2TextGenerationPipeline):
80
  model_name = "ml6team/keyphrase-generation-t5-small-inspec"
81
  generator = KeyphraseGenerationPipeline(model=model_name)
82
 
 
 
83
  ```python
84
  text = """
85
- Keyphrase extraction is a technique in text analysis where you extract the important keyphrases from a text.
86
- Since this is a time-consuming process, Artificial Intelligence is used to automate it.
87
- Currently, classical machine learning methods, that use statistics and linguistics,
88
- are widely used for the extraction process. The fact that these methods have been widely used in the community
89
- has the advantage that there are many easy-to-use libraries. Now with the recent innovations in NLP,
90
- transformers can be used to improve keyphrase extraction. Transformers also focus on the semantics
91
- and context of a document, which is quite an improvement.
92
- """.replace(
93
- "\n", ""
94
- )
 
 
 
 
 
 
95
 
96
  keyphrases = generator(text)
97
 
@@ -105,14 +125,14 @@ print(keyphrases)
105
  ```
106
 
107
  ## πŸ“š Training Dataset
108
- 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.
109
 
110
- You can find more information here: https://huggingface.co/datasets/midas/inspec.
111
 
112
- ## πŸ‘·β€β™‚οΈ Training procedure
113
- For more in detail information, you can take a look at the training notebook (link incoming).
114
 
115
- ### Training parameters
116
 
117
  | Parameter | Value |
118
  | --------- | ------|
@@ -121,9 +141,22 @@ For more in detail information, you can take a look at the training notebook (li
121
  | Early Stopping Patience | 1 |
122
 
123
  ### Preprocessing
124
- 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(;).
125
  ```python
126
- def pre_process_keyphrases(text_ids, kp_list):
 
 
 
 
 
 
 
 
 
 
 
 
 
127
  kp_order_list = []
128
  kp_set = set(kp_list)
129
  text = tokenizer.decode(
@@ -134,8 +167,10 @@ def pre_process_keyphrases(text_ids, kp_list):
134
  kp = kp.strip()
135
  kp_index = text.find(kp.lower())
136
  kp_order_list.append((kp_index, kp))
 
137
  kp_order_list.sort()
138
  present_kp, absent_kp = [], []
 
139
  for kp_index, kp in kp_order_list:
140
  if kp_index < 0:
141
  absent_kp.append(kp)
@@ -143,6 +178,7 @@ def pre_process_keyphrases(text_ids, kp_list):
143
  present_kp.append(kp)
144
  return present_kp, absent_kp
145
 
 
146
  def preprocess_fuction(samples):
147
  processed_samples = {"input_ids": [], "attention_mask": [], "labels": []}
148
  for i, sample in enumerate(samples[dataset_document_column]):
@@ -152,14 +188,16 @@ def preprocess_fuction(samples):
152
  padding="max_length",
153
  truncation=True,
154
  )
155
- present_kp, absent_kp = pre_process_keyphrases(
156
  text_ids=inputs["input_ids"],
157
  kp_list=samples["extractive_keyphrases"][i]
158
  + samples["abstractive_keyphrases"][i],
159
  )
160
  keyphrases = present_kp
161
  keyphrases += absent_kp
 
162
  target_text = f" {keyphrase_sep_token} ".join(keyphrases)
 
163
  with tokenizer.as_target_tokenizer():
164
  targets = tokenizer(
165
  target_text, max_length=40, padding="max_length", truncation=True
@@ -172,7 +210,14 @@ def preprocess_fuction(samples):
172
  processed_samples[key].append(inputs[key])
173
  processed_samples["labels"].append(targets["input_ids"])
174
  return processed_samples
 
 
 
 
 
 
175
  ```
 
176
  ### Postprocessing
177
  For the post-processing, you will need to split the string based on the keyphrase separator.
178
  ```python
@@ -180,7 +225,7 @@ def extract_keyphrases(examples):
180
  return [example.split(keyphrase_sep_token) for example in examples]
181
  ```
182
 
183
- ## πŸ“ Evaluation results
184
 
185
  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.
186
  The model achieves the following results on the Inspec test set:
 
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"
 
43
  value: 0.065
44
  name: F1@O (Absent)
45
  ---
46
+ # πŸ”‘ Keyphrase Generation Model: T5-small-inspec
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
+
49
+ 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.
50
 
51
 
52
  ## πŸ““ Model Description
53
+ This model uses [T5-small model](https://huggingface.co/t5-small) as its base model and fine-tunes it on the [Inspec dataset](https://huggingface.co/datasets/midas/inspec). 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.
54
 
55
+ ## βœ‹ Intended Uses & Limitations
56
  ### πŸ›‘ Limitations
57
  * 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.
58
  * Only works for English documents.
59
+ * For a custom model, please consult the [training notebook]() for more information.
60
  * Sometimes the output doesn't make any sense.
61
 
62
+ ### ❓ How To Use
63
  ```python
64
  # Model parameters
65
  from transformers import (
 
92
  model_name = "ml6team/keyphrase-generation-t5-small-inspec"
93
  generator = KeyphraseGenerationPipeline(model=model_name)
94
 
95
+ ```
96
+
97
  ```python
98
  text = """
99
+ Keyphrase extraction is a technique in text analysis where you extract the
100
+ important keyphrases from a document. Thanks to these keyphrases humans can
101
+ understand the content of a text very quickly and easily without reading it
102
+ completely. Keyphrase extraction was first done primarily by human annotators,
103
+ who read the text in detail and then wrote down the most important keyphrases.
104
+ The disadvantage is that if you work with a lot of documents, this process
105
+ can take a lot of time.
106
+
107
+ Here is where Artificial Intelligence comes in. Currently, classical machine
108
+ learning methods, that use statistical and linguistic features, are widely used
109
+ for the extraction process. Now with deep learning, it is possible to capture
110
+ the semantic meaning of a text even better than these classical methods.
111
+ Classical methods look at the frequency, occurrence and order of words
112
+ in the text, whereas these neural approaches can capture long-term
113
+ semantic dependencies and context of words in a text.
114
+ """.replace("\n", " ")
115
 
116
  keyphrases = generator(text)
117
 
 
125
  ```
126
 
127
  ## πŸ“š Training Dataset
128
+ [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.
129
 
130
+ You can find more information in the [paper](https://dl.acm.org/doi/10.3115/1119355.1119383).
131
 
132
+ ## πŸ‘·β€β™‚οΈ Training Procedure
133
+ For more in detail information, you can take a look at the [training notebook]().
134
 
135
+ ### Training Parameters
136
 
137
  | Parameter | Value |
138
  | --------- | ------|
 
141
  | Early Stopping Patience | 1 |
142
 
143
  ### Preprocessing
144
+ 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( ```;``` ).
145
  ```python
146
+ from datasets import load_dataset
147
+ from transformers import AutoTokenizer
148
+
149
+ # Tokenizer
150
+ tokenizer = AutoTokenizer.from_pretrained("t5-small", add_prefix_space=True)
151
+
152
+ # Dataset parameters
153
+ dataset_full_name = "midas/inspec"
154
+ dataset_subset = "raw"
155
+ dataset_document_column = "document"
156
+
157
+ keyphrase_sep_token = ";"
158
+
159
+ def preprocess_keyphrases(text_ids, kp_list):
160
  kp_order_list = []
161
  kp_set = set(kp_list)
162
  text = tokenizer.decode(
 
167
  kp = kp.strip()
168
  kp_index = text.find(kp.lower())
169
  kp_order_list.append((kp_index, kp))
170
+
171
  kp_order_list.sort()
172
  present_kp, absent_kp = [], []
173
+
174
  for kp_index, kp in kp_order_list:
175
  if kp_index < 0:
176
  absent_kp.append(kp)
 
178
  present_kp.append(kp)
179
  return present_kp, absent_kp
180
 
181
+
182
  def preprocess_fuction(samples):
183
  processed_samples = {"input_ids": [], "attention_mask": [], "labels": []}
184
  for i, sample in enumerate(samples[dataset_document_column]):
 
188
  padding="max_length",
189
  truncation=True,
190
  )
191
+ present_kp, absent_kp = preprocess_keyphrases(
192
  text_ids=inputs["input_ids"],
193
  kp_list=samples["extractive_keyphrases"][i]
194
  + samples["abstractive_keyphrases"][i],
195
  )
196
  keyphrases = present_kp
197
  keyphrases += absent_kp
198
+
199
  target_text = f" {keyphrase_sep_token} ".join(keyphrases)
200
+
201
  with tokenizer.as_target_tokenizer():
202
  targets = tokenizer(
203
  target_text, max_length=40, padding="max_length", truncation=True
 
210
  processed_samples[key].append(inputs[key])
211
  processed_samples["labels"].append(targets["input_ids"])
212
  return processed_samples
213
+
214
+ # Load dataset
215
+ dataset = load_dataset(dataset_full_name, dataset_subset)
216
+ # Preprocess dataset
217
+ tokenized_dataset = dataset.map(preprocess_fuction, batched=True)
218
+
219
  ```
220
+
221
  ### Postprocessing
222
  For the post-processing, you will need to split the string based on the keyphrase separator.
223
  ```python
 
225
  return [example.split(keyphrase_sep_token) for example in examples]
226
  ```
227
 
228
+ ## πŸ“ Evaluation Results
229
 
230
  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.
231
  The model achieves the following results on the Inspec test set: