A fine-tuned
PubMedBERT model for classifying whether a medical term mentioned in a drug product label represents a true adverse drug event or an incidental mention.
This is the production model used by
OnSIDES, an international database of adverse drug events extracted from product labels across four countries (USA, EU, UK, Japan).
1import torch
2from transformers import AutoTokenizer, AutoModelForSequenceClassification
3
4tokenizer = AutoTokenizer.from_pretrained("tatonettilab/onsides-bert")
5model = AutoModelForSequenceClassification.from_pretrained("tatonettilab/onsides-bert")
6model.eval()
7
8text = "Patients receiving EXAMPLE DRUG reported nausea, headache, and dizziness."
9inputs = tokenizer(text, return_tensors="pt", max_length=256, truncation=True, padding="max_length")
10
11with torch.no_grad():
12 outputs = model(**inputs)
13
14# outputs.logits shape: (batch_size, 2)
15# Column 0 = not_event score, Column 1 = is_event score
16predicted_class = outputs.logits.argmax(dim=1).item()
17print("is_event" if predicted_class == 1 else "not_event")
The OnSIDES training pipeline applies a ReLU activation after the classification head.
The standard BertForSequenceClassification used here does not include that ReLU. For
simple classification (argmax), this makes no difference. If you are applying the
threshold-based scoring used in the OnSIDES pipeline, apply ReLU to the logits first:
1import torch.nn.functional as F
2scores = F.relu(outputs.logits)
The model expects text constructed from drug label sections with MedDRA term context. In the OnSIDES pipeline, each input is a window of up to 125 words surrounding a candidate MedDRA term match, with the event term and source section prepended. See the
OnSIDES repository for the full text construction pipeline.
For the OnSIDES v3.2.0 database, section-specific thresholds were applied to the ReLU-activated logit scores:
1@article{tanaka2025onsides,
2 title={OnSIDES database: Extracting adverse drug events from drug labels using natural language processing models},
3 author={Tanaka, Yutaro and Chen, Hsin Yi and Belloni, Payal and Gisladottir, Undina and Kefeli, Jaden and Patterson, Joshua and Srinivasan, Ashwin and Zietz, Michael and Sirdeshmukh, Gaurav and Berkowitz, Jacob and LaRow Brown, Kathleen and Tatonetti, Nicholas P},
4 journal={Med},
5 year={2025},
6 publisher={Elsevier},
7 doi={10.1016/j.medj.2025.100642}
8}