CoolFace
Modelpublic

Francesco-A/BiomedNLP-PubMedBERT-base-uncased-abstract-bc5cdr-ner-LoRA-v1

sourceHugging Facemitupdated 11mo agoView on Hugging Face
0likes34downloads
Model Card

🧬 BiomedNLP-PubMedBERT-base-uncased-abstract-bc5cdr-ner-LoRA-v1

This is a LoRA fine-tuned adapter based on microsoft/BiomedNLP-PubMedBERT-base-uncased-abstract. It has been fine-tuned on the BC5CDR dataset, which focuses on biomedical named entity recognition (NER) for chemicals and diseases. The adapter is designed to enhance PubMedBERT’s performance on biomedical text-mining tasks by improving its ability to recognize and classify domain-specific entities while maintaining computational efficiency. It achieves the following results on the evaluation set:

  • β€”Loss: 0.1423
  • β€”Precision: 0.8909
  • β€”Recall: 0.9094
  • β€”F1: 0.9000
  • β€”Accuracy: 0.9755

⚠️ Note: This model is shared for educational and testing purposes only. It is not intended for clinical or production use and may not generalize beyond the BC5CDR dataset.

Model overview

  • β€”Base model: PubMedBERT (abstracts) (domain-specific transformer)
  • β€”Task: Named Entity Recognition (token classification)
  • β€”Entities:
  • β€”Chemical
  • β€”Disease
  • β€”O (non-entity tokens)

The model predicts entity spans following the standard BIO tagging scheme, e.g. B-Chemical, I-Disease, O.

Training notebook

The full training and preprocessing pipeline β€” including dataset preparation, sentence splitting, BIO tagging, and evaluation β€” is documented in this Kaggle notebook

Example usage

python
from peft import AutoPeftModelForTokenClassification
from transformers import AutoTokenizer, AutoModelForTokenClassification
from transformers import pipeline

# Define labels
LABEL_NAMES = ["O", "B-Chemical", "I-Chemical", "B-Disease", "I-Disease"]
id2label = {i: label for i, label in enumerate(LABEL_NAMES)}
label2id = {label: i for i, label in enumerate(LABEL_NAMES)}

tokenizer = AutoTokenizer.from_pretrained("Francesco-A/BiomedNLP-PubMedBERT-base-uncased-abstract-bc5cdr-ner-LoRA-v1")
model = AutoPeftModelForTokenClassification.from_pretrained(
            "Francesco-A/BiomedNLP-PubMedBERT-base-uncased-abstract-bc5cdr-ner-LoRA-v1",
            num_labels=len(id2label),
            id2label=id2label,
            label2id=label2id,          
)

ner = pipeline("token-classification", model=model, tokenizer=tokenizer, aggregation_strategy="first")

demo_texts = [
    "Aspirin is often used to treat inflammation, but may cause gastric bleeding.",
    "Naloxone reverses the antihypertensive effect of clonidine.",
]

for t in demo_texts:
    print("\nText:", t)
    preds = ner(t)
    for p in preds:
        print(f'  - {p["word"]}: {p["entity_group"]} (score {p["score"]:.2f})')

Training procedure

Training hyperparameters

The following hyperparameters were used during training:

  • β€”learning_rate: 1e-3
  • β€”trainbatchsize: 32
  • β€”evalbatchsize: 32
  • β€”seed: 42
  • β€”optimizer: Adam with betas=(0.9,0.999) and epsilon=1e-08
  • β€”lrschedulertype: linear
  • β€”lrschedulerwarmup_ratio: 0.1
  • β€”num_epochs: 20
  • β€”loadbestmodelatend: True,
  • β€”metricforbest_model: "f1",
  • β€”mixedprecisiontraining: Native AMP

Training results

Training LossEpochStepValidation LossPrecisionRecallF1Accuracy
0.64981.01210.11740.80150.83800.81930.9617
0.10572.02420.08880.86630.87210.86920.9719
0.07473.03630.08440.85680.89420.87510.9707
0.06244.04840.08020.88020.88120.88070.9729
0.04865.06050.09300.85750.90370.880.9704
0.04126.07260.09610.87700.90190.88930.9728
0.03247.08470.08950.89840.89090.89470.9752
0.02748.09680.10820.88560.90150.89350.9750
0.02099.010890.12780.89690.89760.89720.9749
0.017610.012100.11820.88910.90070.89480.9733
0.015311.013310.14060.89860.89830.89840.9751
0.013412.014520.14130.89090.90140.89610.9745
0.011113.015730.14230.89090.90940.90000.9755
0.008814.016940.15190.89270.90520.89890.9748
0.006915.018150.17200.89420.90250.89840.9754

Framework versions

  • β€”PEFT 0.16.0
  • β€”Transformers 4.45.0
  • β€”Pytorch 2.6.0+cu124
  • β€”Datasets 3.6.0
  • β€”Tokenizers 0.20.3