bert-base-uncased 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 13).

P R F1
Chemical 89.00 92.09 90.52
Disease 79.94 81.71 80.82
micro average 84.94 87.41 86.16

Cross-dataset check without further training, NCBI-disease test split, diseases only: P 60.86, R 50.21, F1 55.02. Part of that drop comes from different annotation and tokenization conventions of the two datasets, not from the model alone.

Training

  • base model: google-bert/bert-base-uncased, revision 86b5e0934494bd15c9632b12f734a8a67f723594
  • data: BC5CDR train split as published in tner/bc5cdr (5228 sentences); best epoch chosen on the validation split
  • 4 epochs (best: 3), 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 168 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-bert-base-uncased"
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
25
Safetensors
Model size
0.1B params
Tensor type
F32
ยท
Inference Providers NEW
This model isn't deployed by any Inference Provider. ๐Ÿ™‹ Ask for provider support

Model tree for Z-Bach/bc5cdr-ner-bert-base-uncased

Finetuned
(7,279)
this model

Dataset used to train Z-Bach/bc5cdr-ner-bert-base-uncased