DeDeckerThomas commited on
Commit
4ad6746
β€’
1 Parent(s): 2ef9d8f

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +72 -29
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,18 +33,23 @@ model-index:
23
  type: midas/inspec
24
  name: inspec
25
  metrics:
26
- - type: seqeval
27
  value: 0.509
28
- name: F1-score
 
 
 
29
  ---
30
- # πŸ”‘ Keyphrase Extraction model: distilbert-inspec
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 distilbert model on the Inspec dataset. More information can be found here: https://huggingface.co/distilbert-base-uncased.
36
 
37
- The model is fine-tuned as a token classification problem where the text is labeled using the BIO scheme.
38
 
39
  | Label | Description |
40
  | ----- | ------------------------------- |
@@ -46,11 +61,11 @@ Kulkarni, Mayank, Debanjan Mahata, Ravneet Arora, and Rajarshi Bhowmik. "Learnin
46
 
47
  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.
48
 
49
- ## βœ‹ Intended uses & limitations
50
  ### πŸ›‘ Limitations
51
  * This keyphrase extraction 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.
52
  * Only works for English documents.
53
- * For a custom model, please consult the training notebook for more information (link incoming).
54
 
55
  ### ❓ How to use
56
  ```python
@@ -75,7 +90,7 @@ class KeyphraseExtractionPipeline(TokenClassificationPipeline):
75
  def postprocess(self, model_outputs):
76
  results = super().postprocess(
77
  model_outputs=model_outputs,
78
- aggregation_strategy=AggregationStrategy.SIMPLE,
79
  )
80
  return np.unique([result.get("word").strip() for result in results])
81
 
@@ -89,16 +104,22 @@ extractor = KeyphraseExtractionPipeline(model=model_name)
89
  ```python
90
  # Inference
91
  text = """
92
- Keyphrase extraction is a technique in text analysis where you extract the important keyphrases from a text.
93
- Since this is a time-consuming process, Artificial Intelligence is used to automate it.
94
- Currently, classical machine learning methods, that use statistics and linguistics,
95
- are widely used for the extraction process. The fact that these methods have been widely used in the community
96
- has the advantage that there are many easy-to-use libraries. Now with the recent innovations in NLP,
97
- transformers can be used to improve keyphrase extraction. Transformers also focus on the semantics
98
- and context of a document, which is quite an improvement.
99
- """.replace(
100
- "\n", ""
101
- )
 
 
 
 
 
 
102
 
103
  keyphrases = extractor(text)
104
 
@@ -107,20 +128,20 @@ print(keyphrases)
107
 
108
  ```
109
  # Output
110
- ['artificial intelligence', 'classical machine learning methods',
111
- 'keyphrase extraction', 'linguistics', 'statistics',
112
  'text analysis']
113
  ```
114
 
115
  ## πŸ“š Training Dataset
116
- 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.
117
 
118
- You can find more information here: https://huggingface.co/datasets/midas/inspec
119
 
120
- ## πŸ‘·β€β™‚οΈ Training procedure
121
  For more in detail information, you can take a look at the training notebook (link incoming).
122
 
123
- ### Training parameters
124
 
125
  | Parameter | Value |
126
  | --------- | ------|
@@ -130,12 +151,26 @@ For more in detail information, you can take a look at the training notebook (li
130
 
131
  ### Preprocessing
132
  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.
 
133
  ```python
 
 
 
134
  # Labels
135
  label_list = ["B", "I", "O"]
136
  lbl2idx = {"B": 0, "I": 1, "O": 2}
137
  idx2label = {0: "B", 1: "I", 2: "O"}
138
 
 
 
 
 
 
 
 
 
 
 
139
  def preprocess_fuction(all_samples_per_split):
140
  tokenized_samples = tokenizer.batch_encode_plus(
141
  all_samples_per_split[dataset_document_column],
@@ -169,10 +204,17 @@ def preprocess_fuction(all_samples_per_split):
169
  total_adjusted_labels.append(adjusted_label_ids)
170
  tokenized_samples["labels"] = total_adjusted_labels
171
  return tokenized_samples
 
 
 
 
 
 
 
172
  ```
173
 
174
- ### Postprocessing
175
- For the post-processing, you will need to filter out the B and I labeled tokens and concat the consecutive Bs and Is. As last you strip the keyphrase to ensure all spaces are removed.
176
  ```python
177
  # Define post_process functions
178
  def concat_tokens_by_tag(keyphrases):
@@ -204,9 +246,10 @@ def extract_keyphrases(example, predictions, tokenizer, index=0):
204
  return np.unique([kp.strip() for kp in extracted_kps])
205
 
206
  ```
 
207
  ## πŸ“ Evaluation results
208
 
209
- 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.
210
  The model achieves the following results on the Inspec test set:
211
 
212
  | Dataset | P@5 | R@5 | F1@5 | P@10 | R@10 | F1@10 | P@M | R@M | F1@M |
 
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/inspec
34
  name: inspec
35
  metrics:
36
+ - type: F1 (Seqeval)
37
  value: 0.509
38
+ name: F1 (Seqeval)
39
+ - type: F1@M
40
+ value: 0.490
41
+ name: F1@M
42
  ---
43
+ # πŸ”‘ Keyphrase Extraction Model: distilbert-inspec
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 [distilbert](https://huggingface.co/distilbert-base-uncased) as its base model and fine-tunes it on the [Inspec dataset](https://huggingface.co/datasets/midas/inspec).
51
 
52
+ 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.
53
 
54
  | Label | Description |
55
  | ----- | ------------------------------- |
 
61
 
62
  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.
63
 
64
+ ## βœ‹ Intended Uses & Limitations
65
  ### πŸ›‘ Limitations
66
  * This keyphrase extraction 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.
67
  * Only works for English documents.
68
+ * For a custom model, please consult the [training notebook]() for more information.
69
 
70
  ### ❓ How to use
71
  ```python
 
90
  def postprocess(self, model_outputs):
91
  results = super().postprocess(
92
  model_outputs=model_outputs,
93
+ aggregation_strategy=AggregationStrategy.FIRST,
94
  )
95
  return np.unique([result.get("word").strip() for result in results])
96
 
 
104
  ```python
105
  # Inference
106
  text = """
107
+ Keyphrase extraction is a technique in text analysis where you extract the
108
+ important keyphrases from a document. Thanks to these keyphrases humans can
109
+ understand the content of a text very quickly and easily without reading it
110
+ completely. Keyphrase extraction was first done primarily by human annotators,
111
+ who read the text in detail and then wrote down the most important keyphrases.
112
+ The disadvantage is that if you work with a lot of documents, this process
113
+ can take a lot of time.
114
+
115
+ Here is where Artificial Intelligence comes in. Currently, classical machine
116
+ learning methods, that use statistical and linguistic features, are widely used
117
+ for the extraction process. Now with deep learning, it is possible to capture
118
+ the semantic meaning of a text even better than these classical methods.
119
+ Classical methods look at the frequency, occurrence and order of words
120
+ in the text, whereas these neural approaches can capture long-term
121
+ semantic dependencies and context of words in a text.
122
+ """.replace("\n", " ")
123
 
124
  keyphrases = extractor(text)
125
 
 
128
 
129
  ```
130
  # Output
131
+ ['artificial intelligence' 'classical machine learning' 'deep learning'
132
+ 'keyphrase extraction' 'linguistic features' 'statistical'
133
  'text analysis']
134
  ```
135
 
136
  ## πŸ“š Training Dataset
137
+ [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.
138
 
139
+ You can find more information in the [paper](https://dl.acm.org/doi/10.3115/1119355.1119383).
140
 
141
+ ## πŸ‘·β€β™‚οΈ Training Procedure
142
  For more in detail information, you can take a look at the training notebook (link incoming).
143
 
144
+ ### Training Parameters
145
 
146
  | Parameter | Value |
147
  | --------- | ------|
 
151
 
152
  ### Preprocessing
153
  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.
154
+
155
  ```python
156
+ from datasets import load_dataset
157
+ from transformers import AutoTokenizer
158
+
159
  # Labels
160
  label_list = ["B", "I", "O"]
161
  lbl2idx = {"B": 0, "I": 1, "O": 2}
162
  idx2label = {0: "B", 1: "I", 2: "O"}
163
 
164
+ # Tokenizer
165
+ tokenizer = AutoTokenizer.from_pretrained("distilbert-base-uncased", add_prefix_space=True)
166
+ max_length = 512
167
+
168
+ # Dataset parameters
169
+ dataset_full_name = "midas/inspec"
170
+ dataset_subset = "raw"
171
+ dataset_document_column = "document"
172
+ dataset_biotags_column = "doc_bio_tags"
173
+
174
  def preprocess_fuction(all_samples_per_split):
175
  tokenized_samples = tokenizer.batch_encode_plus(
176
  all_samples_per_split[dataset_document_column],
 
204
  total_adjusted_labels.append(adjusted_label_ids)
205
  tokenized_samples["labels"] = total_adjusted_labels
206
  return tokenized_samples
207
+
208
+ # Load dataset
209
+ dataset = load_dataset(dataset_full_name, dataset_subset)
210
+
211
+ # Preprocess dataset
212
+ tokenized_dataset = dataset.map(preprocess_fuction, batched=True)
213
+
214
  ```
215
 
216
+ ### Postprocessing (Without Pipeline Function)
217
+ 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.
218
  ```python
219
  # Define post_process functions
220
  def concat_tokens_by_tag(keyphrases):
 
246
  return np.unique([kp.strip() for kp in extracted_kps])
247
 
248
  ```
249
+
250
  ## πŸ“ Evaluation results
251
 
252
+ 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.
253
  The model achieves the following results on the Inspec test set:
254
 
255
  | Dataset | P@5 | R@5 | F1@5 | P@10 | R@10 | F1@10 | P@M | R@M | F1@M |