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}
}

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

medcat_transformer_ner-0.1.0.tar.gz (17.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

medcat_transformer_ner-0.1.0-py3-none-any.whl (14.0 kB view details)

Uploaded Python 3

File details

Details for the file medcat_transformer_ner-0.1.0.tar.gz.

File metadata

  • Download URL: medcat_transformer_ner-0.1.0.tar.gz
  • Upload date:
  • Size: 17.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/7.0.0 CPython/3.13.14

File hashes

Hashes for medcat_transformer_ner-0.1.0.tar.gz
Algorithm Hash digest
SHA256 f7b694b84093437738bfefe09ca26c54181fa6516ef6025ed513c5fa0bd90b0a
MD5 cc293c3319bd805d1a1d56e3015e6e37
BLAKE2b-256 b77ce23dc01c91644069459dd927b8e0b97663815ca9f92c820d527b3e98e7c7

See more details on using hashes here.

Provenance

The following attestation bundles were made for medcat_transformer_ner-0.1.0.tar.gz:

Publisher: medcat-transformer-ner-ci.yml on CogStack/cogstack-nlp

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file medcat_transformer_ner-0.1.0-py3-none-any.whl.

File metadata

File hashes

Hashes for medcat_transformer_ner-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 9a84f4a9e5feb6106a8328251e9ecd9e0a00235022a11f56d9772b42e2ac2327
MD5 dff2bd2894fa7963fad91eda93d71533
BLAKE2b-256 66f9c37117e8a65bcb4e8473bc4e1893c4f40b3afcf0fb4bf2afb26c4af54fbb

See more details on using hashes here.

Provenance

The following attestation bundles were made for medcat_transformer_ner-0.1.0-py3-none-any.whl:

Publisher: medcat-transformer-ner-ci.yml on CogStack/cogstack-nlp

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Release history Release notifications | RSS feed

This release

0.1.0 This release

2 files

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