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
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:
- Beginning Of Entity Span
- Intermediate Of Entity Span
- Outside Of Entity Span
- End Of Entity Span
- 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
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
f7b694b84093437738bfefe09ca26c54181fa6516ef6025ed513c5fa0bd90b0a
|
|
| MD5 |
cc293c3319bd805d1a1d56e3015e6e37
|
|
| BLAKE2b-256 |
b77ce23dc01c91644069459dd927b8e0b97663815ca9f92c820d527b3e98e7c7
|
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
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
medcat_transformer_ner-0.1.0.tar.gz -
Subject digest:
f7b694b84093437738bfefe09ca26c54181fa6516ef6025ed513c5fa0bd90b0a - Sigstore transparency entry: 2435847817
- Sigstore integration time:
-
Permalink:
CogStack/cogstack-nlp@d002fa580912af72afcc3bec8f720b1e4628518e -
Branch / Tag:
refs/tags/medcat-transformer-ner/v0.1.0 - Owner: https://github.com/CogStack
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
medcat-transformer-ner-ci.yml@d002fa580912af72afcc3bec8f720b1e4628518e -
Trigger Event:
push
-
Statement type:
File details
Details for the file medcat_transformer_ner-0.1.0-py3-none-any.whl.
File metadata
- Download URL: medcat_transformer_ner-0.1.0-py3-none-any.whl
- Upload date:
- Size: 14.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via:
twine/7.0.0 CPython/3.13.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
9a84f4a9e5feb6106a8328251e9ecd9e0a00235022a11f56d9772b42e2ac2327
|
|
| MD5 |
dff2bd2894fa7963fad91eda93d71533
|
|
| BLAKE2b-256 |
66f9c37117e8a65bcb4e8473bc4e1893c4f40b3afcf0fb4bf2afb26c4af54fbb
|
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
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
medcat_transformer_ner-0.1.0-py3-none-any.whl -
Subject digest:
9a84f4a9e5feb6106a8328251e9ecd9e0a00235022a11f56d9772b42e2ac2327 - Sigstore transparency entry: 2435847997
- Sigstore integration time:
-
Permalink:
CogStack/cogstack-nlp@d002fa580912af72afcc3bec8f720b1e4628518e -
Branch / Tag:
refs/tags/medcat-transformer-ner/v0.1.0 - Owner: https://github.com/CogStack
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
medcat-transformer-ner-ci.yml@d002fa580912af72afcc3bec8f720b1e4628518e -
Trigger Event:
push
-
Statement type: