Instructions to use Z-Bach/bc5cdr-ner-pubmedbert with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use Z-Bach/bc5cdr-ner-pubmedbert with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("token-classification", model="Z-Bach/bc5cdr-ner-pubmedbert")# pip install -U transformers accelerate # Load model directly from transformers import AutoTokenizer, AutoModelForTokenClassification tokenizer = AutoTokenizer.from_pretrained("Z-Bach/bc5cdr-ner-pubmedbert") model = AutoModelForTokenClassification.from_pretrained("Z-Bach/bc5cdr-ner-pubmedbert", device_map="auto") - Notebooks
- Google Colab
- Kaggle
BiomedNLP-BiomedBERT-base-uncased-abstract fine-tuned for chemical and disease NER (BC5CDR)
For demonstration and teaching only. Not for clinical, diagnostic or regulatory use.
Token classification model that marks chemicals and diseases in English biomedical abstracts
(labels B-Chemical, I-Chemical, B-Disease, I-Disease, O). It was trained in a course
project (AI centar Lipik, Croatia) that asks where NER performance comes from: memorised names,
new names of known concepts, or concepts never seen in training.
Evaluation
BC5CDR test split, strict entity match (seqeval, mode="strict", IOB2): both boundaries and the
type must be right. Some published results use lenient matching and are not comparable. This
checkpoint is the median of three training seeds by validation F1 (seed 87).
| P | R | F1 | |
|---|---|---|---|
| Chemical | 92.64 | 94.89 | 93.75 |
| Disease | 82.51 | 88.40 | 85.36 |
| micro average | 87.96 | 91.97 | 89.92 |
Cross-dataset check without further training, NCBI-disease test split, diseases only: P 71.56, R 65.00, F1 68.12. Part of that drop comes from different annotation and tokenization conventions of the two datasets, not from the model alone.
Training
- base model:
microsoft/BiomedNLP-BiomedBERT-base-uncased-abstract, revisiond673b8835373c6fa116d6d8006b33d48734e305d - data: BC5CDR train split as published in
tner/bc5cdr(5228 sentences); best epoch chosen on the validation split - 4 epochs (best: 4), learning rate 5e-05, batch size 16, warmup ratio 0.1, weight decay 0.01, linear schedule, max length 512 sub-tokens, fp16 mixed precision
- device: Tesla T4; training time 149 s
- weights are stored in fp32, and evaluation predictions were made in fp32
How to use
The input must be split into words as in tner/bc5cdr: punctuation separated from words, hyphens
inside names kept in the word. A word gets the label of its first sub-token. Before reading
entities, an orphan I-X (after O or after another type) is turned into B-X.
import torch
from transformers import AutoModelForTokenClassification, AutoTokenizer
repo = "Z-Bach/bc5cdr-ner-pubmedbert"
tokenizer = AutoTokenizer.from_pretrained(repo)
model = AutoModelForTokenClassification.from_pretrained(repo).eval()
words = ["Naloxone", "reverses", "the", "antihypertensive", "effect", "of", "clonidine", "."]
encoding = tokenizer(words, is_split_into_words=True, return_tensors="pt")
with torch.no_grad():
predicted = model(**encoding).logits.argmax(-1)[0].tolist()
labels, previous = [], None
for position, word in enumerate(encoding.word_ids()):
if word is not None and word != previous:
labels.append(model.config.id2label[predicted[position]])
previous = word
print(list(zip(words, labels)))
Limitations
- Trained on a single benchmark from 2016 (1500 PubMed abstracts about chemical-induced diseases). Expect lower performance on other kinds of text.
- Each sentence is processed on its own, so abbreviations defined in another sentence are often missed or given the wrong type.
- Dedicated biomedical NLP tools such as scispaCy or Stanza are better suited for real use.
- Downloads last month
- 29