The dataset was first tokenized with Spacy for better results of the model, so
even though you can use the model with the pipeline API (described in Direct Use) it is highly recommended to use this way:
python
1from transformers import AutoTokenizer, AutoModelForTokenClassification
2import spacy
34nlp = spacy.load("en_core_web_sm")5tokenizer = AutoTokenizer.from_pretrained("JonyC/scibert-NER-finetuned-improved")6model = AutoModelForTokenClassification.from_pretrained("JonyC/scibert-NER-finetuned-improved")7id2label = model.config.id2label
89defpredict_scibert_labels(sentence):10# Step 1: SpaCy tokenization11 words =[token.text for token in nlp(sentence)ifnot token.is_space]12# alternative remove entities:13# words = [token.text for token in nlp(sentence) if not token.is_space and not token.ent_type_]14# Step 2: Tokenize with SciBERT using the words15 inputs = tokenizer(16 words,17 is_split_into_words=True,18 return_tensors="pt",19 truncation=True,20 padding=True21)2223with torch.no_grad():24 outputs = model(**inputs).logits # (1, seq_len, num_labels)2526 predictions = torch.argmax(outputs, dim=-1).squeeze().tolist()27 word_ids = inputs.word_ids()2829# Step 3: Align predictions to original words (skip subwords)30 final_tokens =[]31 final_labels =[]3233 previous_word_idx =None34for i, word_idx inenumerate(word_ids):35if word_idx isNoneor word_idx == previous_word_idx:36continue37 label = id2label[predictions[i]]38 final_tokens.append(words[word_idx])39 final_labels.append(label)40 previous_word_idx = word_idx
4142returnlist(zip(final_tokens, final_labels))
output:
CRISPR -> B-Scns
- -> I-Scns
Cas9 -> I-Scns
is -> O
a -> O
powerful -> O
tool -> O
for -> O
genome -> B-Scns
editing -> O
. -> O
Model Card for Model ID
This model is a fine-tuned version of allenai/scibert_scivocab_uncased for scientific terms/phrases detection in text. It is trained on a custom dataset JonyC/ScienceGlossary-NER_fit for Named Entity Recognition (NER), aiming to identify scientific terms in a variety of academic and technical texts.
Model Details
Model Description
This model has been fine-tuned for the task of scientific term detection. It classifies words as scientific terms, using the Scns label to denote scientific terms and the O label for non-scientific terms. The model has been trained on a custom dataset, which makes it effective for extracting scientific terms from academic and technical texts.
Developed by: [JonyC]
Model type: BERT-based token classifier
Language(s) (NLP): English
License: Apache 2.0
Finetuned from model: allenai/scibert_scivocab_uncased
Uses
Direct Use
This model can be used directly to detect scientific terms in text. You can apply it to text data where you want to extract scientific terminology with the huggingface pipline like this:
python
1from transformers import pipeline
23# Use a model from Hugging Face Hub directly in the notebook4pipe = pipeline("token-classification", model="JonyC/scibert-NER-finetuned-improved")5sentence ="CRISPR-Cas9 is a powerful tool for genome editing."67result = pipe(sentence)8result
This model is not intended for general-purpose NER tasks outside the scope of scientific term detection. It may perform poorly on tasks unrelated to scientific term extraction, for example entities recognition.
Bias, Risks, and Limitations
While this model is designed to identify scientific terms, there may be limitations in recognizing terms from specialized subfields of science that were not represented in the training data. Additionally, the model might struggle with terms that are ambiguous or have multiple meanings depending on the context.
The model mainly trained on less familiar terms so it might recognise the most special term and less the superfical terms (e.g. it doesnt label computer as scientific). and it very bais towards people name and places, so you might want to combine the use of ner in Spacy.
Recommendations
Users should be cautious when applying the model to texts that differ significantly from the training data. The model is optimized for extracting scientific terms but may not perform well for general NER tasks. Further fine-tuning might be necessary for specific domains or types of terminology.
best use with Spacy to remove entities.
Training Details
Training Data
The model was fine-tuned on the JonyC/ScienceGlossary-NER_fit dataset, which consists of scientific texts annotated with scientific terms.
Training Procedure
The model was trained using the following parameters:
The evaluation metrics include precision, recall, F1 score, and accuracy, which are standard for token classification tasks. These metrics provide a comprehensive understanding of the model's ability to identify scientific terms.
metric = evaluate.load("seqeval")
Results
On the test set, the model achieved an accuracy of 98.34% with a F1 score of 0.934, demonstrating its effectiveness at detecting scientific terms.