DeDeckerThomas commited on
Commit
0496356
β€’
1 Parent(s): 3a6fbf2

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +82 -38
README.md CHANGED
@@ -9,7 +9,17 @@ datasets:
9
  metrics:
10
  - seqeval
11
  widget:
12
- - 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."
 
 
 
 
 
 
 
 
 
 
13
  example_title: "Example 1"
14
  - 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."
15
  example_title: "Example 2"
@@ -23,19 +33,24 @@ model-index:
23
  type: midas/kpcrowd
24
  name: kpcrowd
25
  metrics:
26
- - type: seqeval
27
  value: 0.427
28
- name: F1-score
 
 
 
29
  ---
30
- # πŸ”‘ Keyphrase Extraction model: KBIR-KPCrowd
31
- 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.
 
 
32
 
33
 
34
  ## πŸ““ Model Description
35
- This model is a fine-tuned KBIR model on the KPCrowd dataset. KBIR or Keyphrase Boundary Infilling with Replacement is a pre-trained model which utilizes a multi-task learning setup for optimizing a combined loss of Masked Language Modeling (MLM), Keyphrase Boundary Infilling (KBI) and Keyphrase Replacement Classification (KRC).
36
- You can find more information about the architecture in this paper: https://arxiv.org/abs/2112.08547.
37
 
38
- The model is fine-tuned as a token classification problem where the text is labeled using the BIO scheme.
39
 
40
  | Label | Description |
41
  | ----- | ------------------------------- |
@@ -47,14 +62,14 @@ Kulkarni, Mayank, Debanjan Mahata, Ravneet Arora, and Rajarshi Bhowmik. "Learnin
47
 
48
  Sahrawat, Dhruva, Debanjan Mahata, Haimin Zhang, Mayank Kulkarni, Agniv Sharma, Rakesh Gosangi, Amanda Stent, Yaman Kumar, Rajiv Ratn Shah, and Roger Zimmermann. "Keyphrase extraction as sequence labeling using contextualized embeddings." In European Conference on Information Retrieval, pp. 328-335. Springer, Cham, 2020.
49
 
50
- ## βœ‹ Intended uses & limitations
51
  ### πŸ›‘ Limitations
52
  * This keyphrase extraction model is very dataset-specific. It's not recommended to use this model for other domains, but you are free to test it out.
53
  * Only works for English documents.
54
  * Large number of annotated keyphrases.
55
- * For a custom model, please consult the training notebook for more information (link incoming).
56
 
57
- ### ❓ How to use
58
  ```python
59
  from transformers import (
60
  TokenClassificationPipeline,
@@ -87,47 +102,54 @@ class KeyphraseExtractionPipeline(TokenClassificationPipeline):
87
  # Load pipeline
88
  model_name = "ml6team/keyphrase-extraction-kbir-kpcrowd"
89
  extractor = KeyphraseExtractionPipeline(model=model_name)
 
90
  ```
91
  ```python
92
  # Inference
93
  text = """
94
- Keyphrase extraction is a technique in text analysis where you extract the important keyphrases from a text.
95
- Since this is a time-consuming process, Artificial Intelligence is used to automate it.
96
- Currently, classical machine learning methods, that use statistics and linguistics,
97
- are widely used for the extraction process. The fact that these methods have been widely used in the community
98
- has the advantage that there are many easy-to-use libraries. Now with the recent innovations in NLP,
99
- transformers can be used to improve keyphrase extraction. Transformers also focus on the semantics
100
- and context of a document, which is quite an improvement.
101
- """.replace(
102
- "\n", ""
103
- )
 
 
 
 
 
 
104
 
105
  keyphrases = extractor(text)
106
 
107
  print(keyphrases)
 
108
  ```
109
 
110
  ```
111
  # Output
112
- ['Artificial Intelligence', 'Keyphrase extraction', 'NLP',
113
- 'Transformers also', 'advantage', 'automate',
114
- 'classical machine learning', 'community', 'context', 'document',
115
- 'extract', 'extraction', 'extraction process', 'focus',
116
- 'important', 'improvement', 'innovations', 'keyphrase',
117
- 'keyphrases', 'libraries', 'linguistics', 'methods', 'process',
118
- 'recent', 'semantics', 'statistics', 'technique', 'text',
119
- 'text analysis', 'time-consuming', 'transformers', 'widely']
120
  ```
121
 
122
  ## πŸ“š Training Dataset
123
- KPCrowd is a broadcast news transcription dataset consisting of 500 English broadcast news stories from 10 different categories (art and culture, business, crime, fashion, health, politics us, politics world, science, sports, technology) with 50 docs per category. This dataset is annotated by multiple annotators that were required to look at the same news story and assign a set of keyphrases from the text itself.
124
 
125
- You can find more information here: https://huggingface.co/datasets/midas/kpcrowd and https://github.com/LIAAD/KeywordExtractor-Datasets.
126
 
127
- ## πŸ‘·β€β™‚οΈ Training procedure
128
- For more in detail information, you can take a look at the training notebook (link incoming).
129
 
130
- ### Training parameters
131
 
132
  | Parameter | Value |
133
  | --------- | ------|
@@ -137,12 +159,26 @@ For more in detail information, you can take a look at the training notebook (li
137
 
138
  ### Preprocessing
139
  The documents in the dataset are already preprocessed into list of words with the corresponding labels. The only thing that must be done is tokenization and the realignment of the labels so that they correspond with the right subword tokens.
 
140
  ```python
 
 
 
141
  # Labels
142
  label_list = ["B", "I", "O"]
143
  lbl2idx = {"B": 0, "I": 1, "O": 2}
144
  idx2label = {0: "B", 1: "I", 2: "O"}
145
 
 
 
 
 
 
 
 
 
 
 
146
  def preprocess_fuction(all_samples_per_split):
147
  tokenized_samples = tokenizer.batch_encode_plus(
148
  all_samples_per_split[dataset_document_column],
@@ -176,10 +212,17 @@ def preprocess_fuction(all_samples_per_split):
176
  total_adjusted_labels.append(adjusted_label_ids)
177
  tokenized_samples["labels"] = total_adjusted_labels
178
  return tokenized_samples
 
 
 
 
 
 
 
179
  ```
180
 
181
- ### Postprocessing
182
- For the post-processing, you will need to filter out the B and I labeled tokens and concat the consecutive B and Is. As last you strip the keyphrase to ensure all spaces are removed.
183
  ```python
184
  # Define post_process functions
185
  def concat_tokens_by_tag(keyphrases):
@@ -211,16 +254,17 @@ def extract_keyphrases(example, predictions, tokenizer, index=0):
211
  return np.unique([kp.strip() for kp in extracted_kps])
212
 
213
  ```
 
214
  ## πŸ“ Evaluation results
215
 
216
- 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.
217
  The model achieves the following results on the Inspec test set:
218
 
219
  | Dataset | P@5 | R@5 | F1@5 | P@10 | R@10 | F1@10 | P@M | R@M | F1@M |
220
  |:-----------------:|:----:|:----:|:----:|:----:|:----:|:-----:|:----:|:----:|:----:|
221
  | Inspec Test Set | 0.47 | 0.07 | 0.12 | 0.46 | 0.13 | 0.20 | 0.37 | 0.33 | 0.33 |
222
 
223
- For more information on the evaluation process, you can take a look at the keyphrase extraction evaluation notebook.
224
 
225
  ## 🚨 Issues
226
  Please feel free to start discussions in the Community Tab.
 
9
  metrics:
10
  - seqeval
11
  widget:
12
+ - text: "Keyphrase extraction is a technique in text analysis where you extract the important keyphrases from a document.
13
+ Thanks to these keyphrases humans can understand the content of a text very quickly and easily without reading
14
+ it completely. Keyphrase extraction was first done primarily by human annotators, who read the text in detail
15
+ and then wrote down the most important keyphrases. The disadvantage is that if you work with a lot of documents,
16
+ this process can take a lot of time.
17
+
18
+ Here is where Artificial Intelligence comes in. Currently, classical machine learning methods, that use statistical
19
+ and linguistic features, are widely used for the extraction process. Now with deep learning, it is possible to capture
20
+ the semantic meaning of a text even better than these classical methods. Classical methods look at the frequency,
21
+ occurrence and order of words in the text, whereas these neural approaches can capture long-term semantic dependencies
22
+ and context of words in a text."
23
  example_title: "Example 1"
24
  - 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."
25
  example_title: "Example 2"
 
33
  type: midas/kpcrowd
34
  name: kpcrowd
35
  metrics:
36
+ - type: F1 (Seqeval)
37
  value: 0.427
38
+ name: F1 (Seqeval)
39
+ - type: F1@M
40
+ value: 0.335
41
+ name: F1@M
42
  ---
43
+ # πŸ”‘ Keyphrase Extraction Model: KBIR-KPCrowd
44
+ 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 ⏳.
45
+
46
+ 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.
47
 
48
 
49
  ## πŸ““ Model Description
50
+ This model uses [KBIR](https://huggingface.co/bloomberg/KBIR) as its base model and fine-tunes it on the [KPCrowd dataset](https://huggingface.co/datasets/midas/kpcrowd). KBIR or Keyphrase Boundary Infilling with Replacement is a pre-trained model which utilizes a multi-task learning setup for optimizing a combined loss of Masked Language Modeling (MLM), Keyphrase Boundary Infilling (KBI) and Keyphrase Replacement Classification (KRC).
51
+ You can find more information about the architecture in this [paper](https://arxiv.org/abs/2112.08547).
52
 
53
+ Keyphrase extraction models are transformer models fine-tuned as a token classification problem where each word in the document is classified as being part of a keyphrase or not.
54
 
55
  | Label | Description |
56
  | ----- | ------------------------------- |
 
62
 
63
  Sahrawat, Dhruva, Debanjan Mahata, Haimin Zhang, Mayank Kulkarni, Agniv Sharma, Rakesh Gosangi, Amanda Stent, Yaman Kumar, Rajiv Ratn Shah, and Roger Zimmermann. "Keyphrase extraction as sequence labeling using contextualized embeddings." In European Conference on Information Retrieval, pp. 328-335. Springer, Cham, 2020.
64
 
65
+ ## βœ‹ Intended Uses & Limitations
66
  ### πŸ›‘ Limitations
67
  * This keyphrase extraction model is very dataset-specific. It's not recommended to use this model for other domains, but you are free to test it out.
68
  * Only works for English documents.
69
  * Large number of annotated keyphrases.
70
+ * For a custom model, please consult the [training notebook]() for more information.
71
 
72
+ ### ❓ How To Use
73
  ```python
74
  from transformers import (
75
  TokenClassificationPipeline,
 
102
  # Load pipeline
103
  model_name = "ml6team/keyphrase-extraction-kbir-kpcrowd"
104
  extractor = KeyphraseExtractionPipeline(model=model_name)
105
+
106
  ```
107
  ```python
108
  # Inference
109
  text = """
110
+ Keyphrase extraction is a technique in text analysis where you extract the
111
+ important keyphrases from a document. Thanks to these keyphrases humans can
112
+ understand the content of a text very quickly and easily without reading it
113
+ completely. Keyphrase extraction was first done primarily by human annotators,
114
+ who read the text in detail and then wrote down the most important keyphrases.
115
+ The disadvantage is that if you work with a lot of documents, this process
116
+ can take a lot of time.
117
+
118
+ Here is where Artificial Intelligence comes in. Currently, classical machine
119
+ learning methods, that use statistical and linguistic features, are widely used
120
+ for the extraction process. Now with deep learning, it is possible to capture
121
+ the semantic meaning of a text even better than these classical methods.
122
+ Classical methods look at the frequency, occurrence and order of words
123
+ in the text, whereas these neural approaches can capture long-term
124
+ semantic dependencies and context of words in a text.
125
+ """.replace("\n", " ")
126
 
127
  keyphrases = extractor(text)
128
 
129
  print(keyphrases)
130
+
131
  ```
132
 
133
  ```
134
  # Output
135
+ ['Artificial Intelligence' 'Classical' 'Keyphrase' 'Keyphrase extraction'
136
+ 'classical' 'content' 'context' 'disadvantage' 'document' 'documents'
137
+ 'extract' 'extraction' 'extraction process' 'frequency' 'human' 'humans'
138
+ 'important' 'keyphrases' 'learning' 'linguistic' 'long-term'
139
+ 'machine learning' 'meaning' 'methods' 'neural approaches' 'occurrence'
140
+ 'process' 'quickly' 'semantic' 'statistical' 'technique' 'text'
141
+ 'text analysis' 'understand' 'widely' 'words' 'work']
 
142
  ```
143
 
144
  ## πŸ“š Training Dataset
145
+ [KPCrowd](https://huggingface.co/datasets/midas/kpcrowd) is a broadcast news transcription dataset consisting of 500 English broadcast news stories from 10 different categories (art and culture, business, crime, fashion, health, politics us, politics world, science, sports, technology) with 50 docs per category. This dataset is annotated by multiple annotators that were required to look at the same news story and assign a set of keyphrases from the text itself.
146
 
147
+ You can find more information in the [paper](https://arxiv.org/abs/1306.4606).
148
 
149
+ ## πŸ‘·β€β™‚οΈ Training Procedure
150
+ For more in detail information, you can take a look at the [training notebook]().
151
 
152
+ ### Training Parameters
153
 
154
  | Parameter | Value |
155
  | --------- | ------|
 
159
 
160
  ### Preprocessing
161
  The documents in the dataset are already preprocessed into list of words with the corresponding labels. The only thing that must be done is tokenization and the realignment of the labels so that they correspond with the right subword tokens.
162
+
163
  ```python
164
+ from datasets import load_dataset
165
+ from transformers import AutoTokenizer
166
+
167
  # Labels
168
  label_list = ["B", "I", "O"]
169
  lbl2idx = {"B": 0, "I": 1, "O": 2}
170
  idx2label = {0: "B", 1: "I", 2: "O"}
171
 
172
+ # Tokenizer
173
+ tokenizer = AutoTokenizer.from_pretrained("bloomberg/KBIR", add_prefix_space=True)
174
+ max_length = 512
175
+
176
+ # Dataset parameters
177
+ dataset_full_name = "midas/kpcrowd"
178
+ dataset_subset = "raw"
179
+ dataset_document_column = "document"
180
+ dataset_biotags_column = "doc_bio_tags"
181
+
182
  def preprocess_fuction(all_samples_per_split):
183
  tokenized_samples = tokenizer.batch_encode_plus(
184
  all_samples_per_split[dataset_document_column],
 
212
  total_adjusted_labels.append(adjusted_label_ids)
213
  tokenized_samples["labels"] = total_adjusted_labels
214
  return tokenized_samples
215
+
216
+ # Load dataset
217
+ dataset = load_dataset(dataset_full_name, dataset_subset)
218
+
219
+ # Preprocess dataset
220
+ tokenized_dataset = dataset.map(preprocess_fuction, batched=True)
221
+
222
  ```
223
 
224
+ ### Postprocessing (Without Pipeline Function)
225
+ If you do not use the pipeline function, you must filter out the B and I labeled tokens. Each B and I will then be merged into a keyphrase. Finally, you need to strip the keyphrases to make sure all unnecessary spaces have been removed.
226
  ```python
227
  # Define post_process functions
228
  def concat_tokens_by_tag(keyphrases):
 
254
  return np.unique([kp.strip() for kp in extracted_kps])
255
 
256
  ```
257
+
258
  ## πŸ“ Evaluation results
259
 
260
+ 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.
261
  The model achieves the following results on the Inspec test set:
262
 
263
  | Dataset | P@5 | R@5 | F1@5 | P@10 | R@10 | F1@10 | P@M | R@M | F1@M |
264
  |:-----------------:|:----:|:----:|:----:|:----:|:----:|:-----:|:----:|:----:|:----:|
265
  | Inspec Test Set | 0.47 | 0.07 | 0.12 | 0.46 | 0.13 | 0.20 | 0.37 | 0.33 | 0.33 |
266
 
267
+ For more information on the evaluation process, you can take a look at the keyphrase extraction [evaluation notebook]().
268
 
269
  ## 🚨 Issues
270
  Please feel free to start discussions in the Community Tab.