Skip to main content

MedCAT Transformer NER

A MedCAT plugin that provides an transformer based NER component using transformer models from HuggingFace.

Overview

This plugin replaces MedCAT's default NER component with a transformer-based approach that uses BIOES token classifcation to identify spans of text that contain medical entities.

Key features:

  • BIOES token format for accurate labeling of longer / shorter spans.
  • CRF head to ensure consistent label generation.
  • Trainable and configurable for all potential transformer huggingface language models.

Requirements

  • MedCAT: 2.0+ (PyPI | GitHub)
  • Python 3.10+
  • PyTorch
  • Transformers

Installation

pip install medcat-transformer-ner

Quick Start

Replacing current NER with transformer NER

from medcat.cat import CAT
from medcat_transformer_ner.transformer_ner import NER
from medcat_transformer_ner.config import TransformerNER

cat = CAT.load_model_pack("..")

cat.config.components.ner = TransformerNER()
cat.config.components.ner.comp_name = NER.name

cat.config.components.addons.clear()
cat._recreate_pipe()

cat.save_model_pack(target_folder="/data/adam/models/trainable/",
                    pack_name="kch_gstt_v2_NER_BioLinkBERT",
                    add_hash_to_pack_name=False,
                    make_archive=False
)

How It Works

Component Registration

The transformer NER has a default untrained transformers model from huggingface it downloads. Using .load_transformers() with another huggingface model will use that model instead.

Inference Process

Pass a document through the transformer BIOES model tagging if each entity is:

  1. Beginning Of Entity Span
  2. Intermediate Of Entity Span
  3. Outside Of Entity Span
  4. End Of Entity Span
  5. Single Span Of Entity - Meaning it is a single entity within its own token

Configuration

Key Parameters

from medcat_transformer_ner.config import TransformerNER
from medcat.cat import CAT
cat = CAT.load_model_pack("..your transformer ner model..")

ner_component = cat._pipeline.get_component(CoreComponentType.ner)

# Do you want to only pass forward detected entities where there is a 
# perfect match in the name vocabulary?
ner_component.cnf_ner.require_link_candidates = True
# What pretrained transformers model would you like to use?
ner_component.load_transformers("michiyasunaga/BioLinkBERT-large")

Suggested Models

Any HuggingFace model will work. However smaller models will be unable to model the task appropriately leading to significantly reduced performances. We strongly reccomend BioLinkBERT-large, as this is one of the smaller models that can appropriately detect entities. All models will be worth testing.

Citation

If you use this plugin, please cite MedCAT:

@article{medcat2021,
    title={Medical Concept Annotation Tool (MedCAT)},
    author={Kraljevic, Zeljko and et al.},
    journal={arXiv preprint arXiv:2010.01165},
    year={2021}
}

Metadata

Release files for medcat-transformer-ner 0.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for medcat-transformer-ner 0.1.0
File Size Uploaded Provenance Actions
medcat_transformer_ner-0.1.0.tar.gz 17.0 kB With provenance Details for medcat_transformer_ner-0.1.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for medcat-transformer-ner 0.1.0
File Interpreter ABI Platform Actions
medcat_transformer_ner-0.1.0-py3-none-any.whl Python 3 none any Details for medcat_transformer_ner-0.1.0-py3-none-any.whl

Total release size: 31.0 kB

Release files / medcat_transformer_ner-0.1.0.tar.gz

Download URL medcat_transformer_ner-0.1.0.tar.gz
Size 17.0 kB
Tags Source
SHA-256 checksum
How to use checksums
f7b694b84093437738bfefe09ca26c54181fa6516ef6025ed513c5fa0bd90b0a
BLAKE2b-256 checksum
How to use checksums
b77ce23dc01c91644069459dd927b8e0b97663815ca9f92c820d527b3e98e7c7
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Aug 12, 2026.

Transparency log

Release files / medcat_transformer_ner-0.1.0-py3-none-any.whl

Download URL medcat_transformer_ner-0.1.0-py3-none-any.whl
Size 14.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
9a84f4a9e5feb6106a8328251e9ecd9e0a00235022a11f56d9772b42e2ac2327
BLAKE2b-256 checksum
How to use checksums
66f9c37117e8a65bcb4e8473bc4e1893c4f40b3afcf0fb4bf2afb26c4af54fbb
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Aug 12, 2026.

Transparency log

Security for medcat-transformer-ner 0.1.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

Full provenance

All 2 files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for medcat_transformer_ner-0.1.0.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Aug 12, 2026.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.1.0 This release

2 release files Full provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page