Update README.md
This commit is contained in:
parent
2ef9d8fee5
commit
4ad67468b2
101
README.md
101
README.md
|
@ -9,7 +9,17 @@ datasets:
|
|||
metrics:
|
||||
- seqeval
|
||||
widget:
|
||||
- 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."
|
||||
- text: "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.
|
||||
|
||||
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."
|
||||
example_title: "Example 1"
|
||||
- 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."
|
||||
example_title: "Example 2"
|
||||
|
@ -23,18 +33,23 @@ model-index:
|
|||
type: midas/inspec
|
||||
name: inspec
|
||||
metrics:
|
||||
- type: seqeval
|
||||
- type: F1 (Seqeval)
|
||||
value: 0.509
|
||||
name: F1-score
|
||||
name: F1 (Seqeval)
|
||||
- type: F1@M
|
||||
value: 0.490
|
||||
name: F1@M
|
||||
---
|
||||
# 🔑 Keyphrase Extraction model: distilbert-inspec
|
||||
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.
|
||||
# 🔑 Keyphrase Extraction Model: distilbert-inspec
|
||||
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 ⏳.
|
||||
|
||||
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.
|
||||
|
||||
|
||||
## 📓 Model Description
|
||||
This model is a fine-tuned distilbert model on the Inspec dataset. More information can be found here: https://huggingface.co/distilbert-base-uncased.
|
||||
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).
|
||||
|
||||
The model is fine-tuned as a token classification problem where the text is labeled using the BIO scheme.
|
||||
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.
|
||||
|
||||
| Label | Description |
|
||||
| ----- | ------------------------------- |
|
||||
|
@ -46,11 +61,11 @@ Kulkarni, Mayank, Debanjan Mahata, Ravneet Arora, and Rajarshi Bhowmik. "Learnin
|
|||
|
||||
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.
|
||||
|
||||
## ✋ Intended uses & limitations
|
||||
## ✋ Intended Uses & Limitations
|
||||
### 🛑 Limitations
|
||||
* 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.
|
||||
* Only works for English documents.
|
||||
* For a custom model, please consult the training notebook for more information (link incoming).
|
||||
* For a custom model, please consult the [training notebook]() for more information.
|
||||
|
||||
### ❓ How to use
|
||||
```python
|
||||
|
@ -75,7 +90,7 @@ class KeyphraseExtractionPipeline(TokenClassificationPipeline):
|
|||
def postprocess(self, model_outputs):
|
||||
results = super().postprocess(
|
||||
model_outputs=model_outputs,
|
||||
aggregation_strategy=AggregationStrategy.SIMPLE,
|
||||
aggregation_strategy=AggregationStrategy.FIRST,
|
||||
)
|
||||
return np.unique([result.get("word").strip() for result in results])
|
||||
|
||||
|
@ -89,16 +104,22 @@ extractor = KeyphraseExtractionPipeline(model=model_name)
|
|||
```python
|
||||
# Inference
|
||||
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.
|
||||
""".replace(
|
||||
"\n", ""
|
||||
)
|
||||
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.
|
||||
|
||||
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.
|
||||
""".replace("\n", " ")
|
||||
|
||||
keyphrases = extractor(text)
|
||||
|
||||
|
@ -107,20 +128,20 @@ print(keyphrases)
|
|||
|
||||
```
|
||||
# Output
|
||||
['artificial intelligence', 'classical machine learning methods',
|
||||
'keyphrase extraction', 'linguistics', 'statistics',
|
||||
['artificial intelligence' 'classical machine learning' 'deep learning'
|
||||
'keyphrase extraction' 'linguistic features' 'statistical'
|
||||
'text analysis']
|
||||
```
|
||||
|
||||
## 📚 Training Dataset
|
||||
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.
|
||||
[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.
|
||||
|
||||
You can find more information here: https://huggingface.co/datasets/midas/inspec
|
||||
You can find more information in the [paper](https://dl.acm.org/doi/10.3115/1119355.1119383).
|
||||
|
||||
## 👷♂️ Training procedure
|
||||
## 👷♂️ Training Procedure
|
||||
For more in detail information, you can take a look at the training notebook (link incoming).
|
||||
|
||||
### Training parameters
|
||||
### Training Parameters
|
||||
|
||||
| Parameter | Value |
|
||||
| --------- | ------|
|
||||
|
@ -130,12 +151,26 @@ For more in detail information, you can take a look at the training notebook (li
|
|||
|
||||
### Preprocessing
|
||||
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.
|
||||
|
||||
```python
|
||||
from datasets import load_dataset
|
||||
from transformers import AutoTokenizer
|
||||
|
||||
# Labels
|
||||
label_list = ["B", "I", "O"]
|
||||
lbl2idx = {"B": 0, "I": 1, "O": 2}
|
||||
idx2label = {0: "B", 1: "I", 2: "O"}
|
||||
|
||||
# Tokenizer
|
||||
tokenizer = AutoTokenizer.from_pretrained("distilbert-base-uncased", add_prefix_space=True)
|
||||
max_length = 512
|
||||
|
||||
# Dataset parameters
|
||||
dataset_full_name = "midas/inspec"
|
||||
dataset_subset = "raw"
|
||||
dataset_document_column = "document"
|
||||
dataset_biotags_column = "doc_bio_tags"
|
||||
|
||||
def preprocess_fuction(all_samples_per_split):
|
||||
tokenized_samples = tokenizer.batch_encode_plus(
|
||||
all_samples_per_split[dataset_document_column],
|
||||
|
@ -169,10 +204,17 @@ def preprocess_fuction(all_samples_per_split):
|
|||
total_adjusted_labels.append(adjusted_label_ids)
|
||||
tokenized_samples["labels"] = total_adjusted_labels
|
||||
return tokenized_samples
|
||||
|
||||
# Load dataset
|
||||
dataset = load_dataset(dataset_full_name, dataset_subset)
|
||||
|
||||
# Preprocess dataset
|
||||
tokenized_dataset = dataset.map(preprocess_fuction, batched=True)
|
||||
|
||||
```
|
||||
|
||||
### Postprocessing
|
||||
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.
|
||||
### Postprocessing (Without Pipeline Function)
|
||||
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.
|
||||
```python
|
||||
# Define post_process functions
|
||||
def concat_tokens_by_tag(keyphrases):
|
||||
|
@ -204,9 +246,10 @@ def extract_keyphrases(example, predictions, tokenizer, index=0):
|
|||
return np.unique([kp.strip() for kp in extracted_kps])
|
||||
|
||||
```
|
||||
|
||||
## 📝 Evaluation results
|
||||
|
||||
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.
|
||||
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.
|
||||
The model achieves the following results on the Inspec test set:
|
||||
|
||||
| Dataset | P@5 | R@5 | F1@5 | P@10 | R@10 | F1@10 | P@M | R@M | F1@M |
|
||||
|
|
Loading…
Reference in New Issue