DeDeckerThomas commited on
Commit
2ec5a90
1 Parent(s): 5032a92

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +79 -30
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: "FoodEx is the largest trade exhibition for food and drinks in Asia, with about 70,000 visitors checking out the products presented by hundreds of participating companies. I was lucky to enter as press; otherwise, visitors must be affiliated with the food industry— and pay ¥5,000 — to enter. The FoodEx menu is global, including everything from cherry beer from Germany and premium Mexican tequila to top-class French and Chinese dumplings. The event was a rare chance to try out both well-known and exotic foods and even see professionals making them. In addition to booths offering traditional Japanese favorites such as udon and maguro sashimi, there were plenty of innovative twists, such as dorayaki , a sweet snack made of two pancakes and a red-bean filling, that came in coffee and tomato flavors. While I was there I was lucky to catch the World Sushi Cup Japan 2013, where top chefs from around the world were competing … and presenting a wide range of styles that you would not normally see in Japan, like the flower makizushi above."
15
  example_title: "Example 2"
@@ -23,18 +33,23 @@ model-index:
23
  type: midas/openkp
24
  name: openkp
25
  metrics:
26
- - type: seqeval
27
  value: 0.430
28
- name: F1-score
 
 
 
29
  ---
30
- # 🔑 Keyphrase Extraction model: distilbert-openkp
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 OpenKP 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
  | ----- | ------------------------------- |
@@ -42,11 +57,11 @@ The model is fine-tuned as a token classification problem where the text is labe
42
  | I-KEY | Inside a keyphrase |
43
  | O | Outside a keyphrase |
44
 
45
- ## ✋ Intended uses & limitations
46
  ### 🛑 Limitations
47
  * Limited amount of predicted keyphrases.
48
  * Only works for English documents.
49
- * For a custom model, please consult the training notebook for more information (link incoming).
50
 
51
  ### ❓ How to use
52
  ```python
@@ -71,7 +86,7 @@ class KeyphraseExtractionPipeline(TokenClassificationPipeline):
71
  def postprocess(self, model_outputs):
72
  results = super().postprocess(
73
  model_outputs=model_outputs,
74
- aggregation_strategy=AggregationStrategy.SIMPLE,
75
  )
76
  return np.unique([result.get("word").strip() for result in results])
77
 
@@ -81,41 +96,49 @@ class KeyphraseExtractionPipeline(TokenClassificationPipeline):
81
  # Load pipeline
82
  model_name = "ml6team/keyphrase-extraction-distilbert-openkp"
83
  extractor = KeyphraseExtractionPipeline(model=model_name)
 
84
  ```
85
 
86
  ```python
87
  # Inference
88
  text = """
89
- Keyphrase extraction is a technique in text analysis where you extract the important keyphrases from a text.
90
- Since this is a time-consuming process, Artificial Intelligence is used to automate it.
91
- Currently, classical machine learning methods, that use statistics and linguistics,
92
- are widely used for the extraction process. The fact that these methods have been widely used in the community
93
- has the advantage that there are many easy-to-use libraries. Now with the recent innovations in NLP,
94
- transformers can be used to improve keyphrase extraction. Transformers also focus on the semantics
95
- and context of a document, which is quite an improvement.
96
- """.replace(
97
- "\n", ""
98
- )
 
 
 
 
 
 
99
 
100
  keyphrases = extractor(text)
101
 
102
  print(keyphrases)
 
103
  ```
104
 
105
  ```
106
  # Output
107
- ['keyphrase extraction', 'text analysis']
108
  ```
109
 
110
  ## 📚 Training Dataset
111
- 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.
112
 
113
- You can find more information here: https://github.com/microsoft/OpenKP
114
 
115
- ## 👷‍♂️ Training procedure
116
- For more in detail information, you can take a look at the training notebook (link incoming).
117
 
118
- ### Training parameters
119
 
120
  | Parameter | Value |
121
  | --------- | ------|
@@ -125,7 +148,26 @@ For more in detail information, you can take a look at the training notebook (li
125
 
126
  ### Preprocessing
127
  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.
 
128
  ```python
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
129
  def preprocess_fuction(all_samples_per_split):
130
  tokenized_samples = tokenizer.batch_encode_plus(
131
  all_samples_per_split[dataset_document_column],
@@ -159,10 +201,17 @@ def preprocess_fuction(all_samples_per_split):
159
  total_adjusted_labels.append(adjusted_label_ids)
160
  tokenized_samples["labels"] = total_adjusted_labels
161
  return tokenized_samples
 
 
 
 
 
 
 
162
  ```
163
 
164
- ### Postprocessing
165
- 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.
166
  ```python
167
  # Define post_process functions
168
  def concat_tokens_by_tag(keyphrases):
@@ -194,9 +243,9 @@ def extract_keyphrases(example, predictions, tokenizer, index=0):
194
  return np.unique([kp.strip() for kp in extracted_kps])
195
 
196
  ```
197
- ## 📝 Evaluation results
198
 
199
- 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.
 
200
  The model achieves the following results on the OpenKP test set:
201
 
202
  | 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: "FoodEx is the largest trade exhibition for food and drinks in Asia, with about 70,000 visitors checking out the products presented by hundreds of participating companies. I was lucky to enter as press; otherwise, visitors must be affiliated with the food industry— and pay ¥5,000 — to enter. The FoodEx menu is global, including everything from cherry beer from Germany and premium Mexican tequila to top-class French and Chinese dumplings. The event was a rare chance to try out both well-known and exotic foods and even see professionals making them. In addition to booths offering traditional Japanese favorites such as udon and maguro sashimi, there were plenty of innovative twists, such as dorayaki , a sweet snack made of two pancakes and a red-bean filling, that came in coffee and tomato flavors. While I was there I was lucky to catch the World Sushi Cup Japan 2013, where top chefs from around the world were competing … and presenting a wide range of styles that you would not normally see in Japan, like the flower makizushi above."
25
  example_title: "Example 2"
 
33
  type: midas/openkp
34
  name: openkp
35
  metrics:
36
+ - type: F1 (Seqeval)
37
  value: 0.430
38
+ name: F1 (Seqeval)
39
+ - type: F1@M
40
+ value: 0.314
41
+ name: F1@M
42
  ---
43
+ # 🔑 Keyphrase Extraction Model: distilbert-openkp
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/distilbert-base-uncased) as its base model and fine-tunes it on the [OpenKP dataset](https://huggingface.co/datasets/midas/openkp).
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
  | ----- | ------------------------------- |
 
57
  | I-KEY | Inside a keyphrase |
58
  | O | Outside a keyphrase |
59
 
60
+ ## ✋ Intended Uses & Limitations
61
  ### 🛑 Limitations
62
  * Limited amount of predicted keyphrases.
63
  * Only works for English documents.
64
+ * For a custom model, please consult the [training notebook]() for more information.
65
 
66
  ### ❓ How to use
67
  ```python
 
86
  def postprocess(self, model_outputs):
87
  results = super().postprocess(
88
  model_outputs=model_outputs,
89
+ aggregation_strategy=AggregationStrategy.FIRST,
90
  )
91
  return np.unique([result.get("word").strip() for result in results])
92
 
 
96
  # Load pipeline
97
  model_name = "ml6team/keyphrase-extraction-distilbert-openkp"
98
  extractor = KeyphraseExtractionPipeline(model=model_name)
99
+
100
  ```
101
 
102
  ```python
103
  # Inference
104
  text = """
105
+ Keyphrase extraction is a technique in text analysis where you extract the
106
+ important keyphrases from a document. Thanks to these keyphrases humans can
107
+ understand the content of a text very quickly and easily without reading it
108
+ completely. Keyphrase extraction was first done primarily by human annotators,
109
+ who read the text in detail and then wrote down the most important keyphrases.
110
+ The disadvantage is that if you work with a lot of documents, this process
111
+ can take a lot of time.
112
+
113
+ Here is where Artificial Intelligence comes in. Currently, classical machine
114
+ learning methods, that use statistical and linguistic features, are widely used
115
+ for the extraction process. Now with deep learning, it is possible to capture
116
+ the semantic meaning of a text even better than these classical methods.
117
+ Classical methods look at the frequency, occurrence and order of words
118
+ in the text, whereas these neural approaches can capture long-term
119
+ semantic dependencies and context of words in a text.
120
+ """.replace("\n", " ")
121
 
122
  keyphrases = extractor(text)
123
 
124
  print(keyphrases)
125
+
126
  ```
127
 
128
  ```
129
  # Output
130
+ ['keyphrase extraction' 'text analysis']
131
  ```
132
 
133
  ## 📚 Training Dataset
134
+ [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.
135
 
136
+ You can find more information in the [paper](https://arxiv.org/abs/1911.02671).
137
 
138
+ ## 👷‍♂️ Training Procedure
139
+ For more in detail information, you can take a look at the [training notebook]().
140
 
141
+ ### Training Parameters
142
 
143
  | Parameter | Value |
144
  | --------- | ------|
 
148
 
149
  ### Preprocessing
150
  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.
151
+
152
  ```python
153
+ from datasets import load_dataset
154
+ from transformers import AutoTokenizer
155
+
156
+ # Labels
157
+ label_list = ["B", "I", "O"]
158
+ lbl2idx = {"B": 0, "I": 1, "O": 2}
159
+ idx2label = {0: "B", 1: "I", 2: "O"}
160
+
161
+ # Tokenizer
162
+ tokenizer = AutoTokenizer.from_pretrained("distilbert-base-uncased")
163
+ max_length = 512
164
+
165
+ # Dataset parameters
166
+ dataset_full_name = "midas/openkp"
167
+ dataset_subset = "raw"
168
+ dataset_document_column = "document"
169
+ dataset_biotags_column = "doc_bio_tags"
170
+
171
  def preprocess_fuction(all_samples_per_split):
172
  tokenized_samples = tokenizer.batch_encode_plus(
173
  all_samples_per_split[dataset_document_column],
 
201
  total_adjusted_labels.append(adjusted_label_ids)
202
  tokenized_samples["labels"] = total_adjusted_labels
203
  return tokenized_samples
204
+
205
+ # Load dataset
206
+ dataset = load_dataset(dataset_full_name, dataset_subset)
207
+
208
+ # Preprocess dataset
209
+ tokenized_dataset = dataset.map(preprocess_fuction, batched=True)
210
+
211
  ```
212
 
213
+ ### Postprocessing (Without Pipeline Function)
214
+ 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.
215
  ```python
216
  # Define post_process functions
217
  def concat_tokens_by_tag(keyphrases):
 
243
  return np.unique([kp.strip() for kp in extracted_kps])
244
 
245
  ```
 
246
 
247
+ ## 📝 Evaluation Results
248
+ 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.
249
  The model achieves the following results on the OpenKP test set:
250
 
251
  | Dataset | P@5 | R@5 | F1@5 | P@10 | R@10 | F1@10 | P@M | R@M | F1@M |