Build a Biomedical NER System with BioBERT + LoRA (Step-by-Step) | Humanitarians AI

A step-by-step walkthrough of fine-tuning BioBERT with LoRA adapters on BC5CDR, from label alignment to a working pipeline that extracts chemical and disease entities from clinical text.

4:03 video3 min readWatch on YouTube

Fine-tuning a full biomedical language model to recognize chemicals and diseases inside clinical notes is normally expensive: updating every parameter in a BERT-scale model takes GPU memory and training time most labs would rather spend elsewhere. This walkthrough shows a lighter path, fine-tuning BioBERT for named entity recognition using LoRA adapters, so the bulk of the pretrained model stays frozen while only a small set of new parameters learns the biomedical task.

The target is a working pipeline: start with raw clinical-style text, run it through the fine-tuned model, and get back a clean table of the chemicals and diseases the model found, ready to feed into research or safety-monitoring work.

The BC5CDR dataset and the BIO tagging scheme

The pipeline starts with the BC5CDR dataset, a widely used benchmark for biomedical entity recognition. Its sentences are annotated with two entity types: chemicals and diseases. Rather than a simple yes-or-no label, each token gets tagged using the BIO scheme, beginning of a chemical, inside a chemical, beginning of a disease, inside a disease, or outside any entity, which gives five labels in total and lets the model mark entities that span multiple words.

That labeling has to survive tokenization, and this is where things get tricky. When BioBERT's tokenizer processes a word, it can split it into multiple subword tokens, but the original data only has one label per word. To keep the labels correct, the first subword keeps the original label and the remaining subwords get the matching inside-entity tag. Getting this alignment right is what separates a model that learns real entity boundaries from one that learns noise.

Fine-tuning BioBERT efficiently with LoRA

Rather than retraining every weight in BioBERT, the pipeline adds LoRA adapters from the PEFT library. LoRA inserts small trainable layers into the model while keeping most of the pretrained weights frozen, which lets the model adapt to the chemical and disease task without the memory and time cost of full fine-tuning, and without giving up much accuracy.

Training and evaluating the model

Training runs through the Hugging Face Trainer API for five epochs with a batch size of 16, and evaluation uses the seqeval library to compute precision, recall, F1 score, and accuracy at each stage. Watching these metrics climb epoch over epoch is the signal that the model is actually learning to tell chemicals and diseases apart, not just memorizing training examples.

From tokens to structured clinical insight

Once training finishes, both the tokenizer and the LoRA adapter get saved separately from the base model. That separation matters: instead of retraining the whole system every time, you can reload BioBERT, attach the saved adapter, and start making predictions right away, which is useful for sharing the trained model with collaborators or moving it into production.

Running the model on new clinical text produces token-level labels, but because of subword splitting, a post-processing step is needed to merge those subwords back into complete words before the entities mean anything. Once entities are merged, they get organized into a table with columns for the input text, the chemicals found, and the diseases found, turning unstructured, messy clinical notes into clean, structured data that downstream tools can actually use.

Key takeaways

  • The BC5CDR dataset uses BIO tagging across five labels to mark chemical and disease entities, including multi-word spans.
  • Subword tokenization breaks single words into multiple tokens, so labels must be realigned: the first subword keeps the label, later subwords get the inside-entity tag.
  • LoRA adapters from the PEFT library let you fine-tune BioBERT by training a small set of new parameters instead of the entire model, cutting memory and training time.
  • The Hugging Face Trainer API, run for five epochs with a batch size of 16, is evaluated with the seqeval library for precision, recall, F1, and accuracy.
  • Saving the tokenizer and LoRA adapter separately from the base model means you can reload and reuse the fine-tuned system without retraining it.
  • A post-processing step that merges subwords back into full words turns raw token predictions into a clean table of chemicals and diseases.

Who this is for

This walkthrough is for anyone building biomedical NLP tools on a budget: researchers extracting structured data from clinical notes, teams working on drug safety monitoring, or developers exploring efficient fine-tuning techniques like LoRA before committing to full model training. It's part of the applied AI tutorials Humanitarians AI publishes for people learning by building real pipelines rather than reading theory.

Full transcript(auto-generated, with timestamps)

[0:03]Hi every welcome back. In this video I will walk you through how we can fine-tune a biomedical language model called bioert for named entity recognition. We will use the BC5 CDR data set which contains biomedical text and notated with chemicals and diseases. To make the training lightweight and efficient, we will add Laura adapters on top of BioBird and then test the model on some clinical text to extract structured information. The data set is widely used for biomedical entity recognition task. It contains sentences annotated with two main types chemical and diseases. We use the standard BIO tagging scheme which means tokens are labeled as beginning of a chemical, inside a

[0:53]Chemical, beginning of a disease, inside a disease or simply outside if they don't belong to any entity. This gives us five labels in total. As you can see on the screen, when we tokenize our text with Biobot can break into multiple server words tokens. This creates a challenge because each word has only one label but now it's split. To fix this, we align labels so that the first subword keeps the original label and all other subwords gets the appropriate I tag. This alignment is critical for training a reliable NE model. Now, instead of fine-tuning the entire bio model which has over 100 billion parameters, we use Laura adapters from

[1:45]The PFT library, Laura inserts small trainable layers into the model, allowing us to adapt bio to our data sets while keeping most of the base model frozen. This also makes training much faster, requires less memory and still give excellent performance. For training, we use hugging face trainer API. We train for five epochs with a batch size of 16 and we evaluate using the CQL library. The the evaluation gives us precision, recall, F1 score and accuracy. During training, we can see these matrices improve with each epoch, showing that the model is learning to correctly identify chemicals and diseases in text. After training, we save both the

[2:33]Tokenizer and the Laura adapter. This means we don't need to retrain the whole model every time. We can just reload bio, attach the Laura adapter and start making predictions. This is especially useful if you want to share the train model with others or deploy it into production. When we run the model on new clinical text, it outputs tokens with the update labels. But because of subword splitting, we add a post-processing strip to merge subwords back into complete words. Once entities are merged, we can easily extract structured information. We build a table with columns like input, text, chemicals, and diseases. This transforms messy and structured clinical nodes into a clean structured

[3:26]Data. So yes, in just few t few steps we fine-tuned bioert with Laura for biometical named entity recognition. We trained efficiently aligning labels correctly, saved and deluded the adapter and finally build a practical pipeline that turns free text into structured information. This is really powerful for use cases like clinical research, drug safety monitoring or analyzing electronic health records. Thanks for watching.

More videos

Humanitarians AI Lyrical Literacy Project