MedLex RaNER — Chinese Medical Operations NER
A community fine-tune of RaNER for Chinese hospital operations queries, recognizing ten entity categories including medical consumables. Public release v0.1.0 corresponds to frozen internal checkpoint V10r6 / seed42 / epoch1. It is a transformer–CRF tagger, not a generative model or medical coding system. Recognition does not require a terminology dictionary.
Scope: synthetic engineering acceptance passed; independently annotated real production quality remains unverified. Do not interpret the scores below as clinical accuracy. No claim of universal non-regression on the upstream CMeEE task is made.
Download and run
Python 3.11 is the tested runtime. CPU FP32 inference is verified. CUDA is supported by the adapter but was not validated for this release. Apple MPS was used for training, not serving.
python3.11 -m venv .venv
source .venv/bin/activate
pip install 'git+https://github.com/Siriuser/medlex-raner.git@v0.1.0'
curl -L --fail https://github.com/Siriuser/medlex-raner/releases/download/v0.1.0/medlex-raner-v10r6.zip -o model.zip
mkdir -p bundle
unzip model.zip -d bundle
medlex-raner --bundle bundle --text '本月PICC和输液器分别使用多少?'
from medlex_raner import Recognizer
model = Recognizer("bundle", device="cpu", threads=4)
print(model.predict("本月PICC和输液器分别使用多少?"))
# [{"text":"PICC","start":2,"end":6,"type":"CONSUMABLE"},
# {"text":"输液器","start":7,"end":10,"type":"CONSUMABLE"}]
Bundle layout is model/ (seven original runtime files) plus manifest.json. Keep the manifest outside model/: every runtime file is hash-verified. The model is not interchangeable with a generic AutoModelForTokenClassification/pipeline: use the supplied CRF, character alignment and decoding implementation. Model hub snapshots use the same bundle layout; pass their snapshot directory to Recognizer.
Offsets count Unicode code points with an exclusive end. Maximum window: 510 content tokens with up to 64 overlapping tokens. Long documents use multiple windows. Incomplete BIOES spans are discarded; an entity longer than the overlap can still be missed at a window boundary. Scores are not calibrated confidence values.
Entity types
BODY, DEPARTMENT, DISEASE, DRUG, EQUIPMENT, EXAMINATION, MICROORGANISM, PROCEDURE, SYMPTOM, CONSUMABLE.
Annotation conventions are task-specific. For example, standalone 心动过速 is SYMPTOM, 房性心动过速 is DISEASE; bare 角膜 is BODY, while supply/procedure contexts can be ambiguous. See the data card. No ICD/DRG coding or diagnostic interpretation is provided.
Evaluation
Exact start/end/type matching. New frozen final: 1800 synthetic sentences, 2800 entities, including 200 long documents and 280 negatives. Weight selection occurred before its first evaluation. The original predictions and strict metrics are provided in evaluation/.
| Metric | Frozen final result |
|---|---|
| Overall entity precision / recall / F1 | 99.89% / 99.89% / 99.89% |
| Consumable F1 / recall (460 mentions) | 100% / 100% |
| Chinese abbreviation F1 / recall (135 mentions) | 98.52% / 98.52% |
| Latin abbreviation F1 / recall (75 mentions) | 100% / 100% |
| Long-document F1 (1000 mentions) | 99.90% |
| Minimum class recall | 99.55% |
| Negative-sentence false positives | 0/280 |
Both seeds 42 and 43 passed development and historical regression criteria. They vary batch order from the same warm initialization, not independent random initializations. Seed42 was selected by the predeclared development-F1 first-tie rule. The other seed was not evaluated on final for selection.
An older 1500-sentence diagnostic set improved from upstream F1 59.77% and V9 93.93% to 100%. It includes the added consumable class unsupported by the upstream model. On its 1140 sentences without consumables, upstream F1 was 77.11%. This old diagnostic set was used during iteration and is not independent generalization evidence. The new final is also synthetic, shares terminology, and was authored by the same assistant. No private real patient data was used for this acceptance.
Known final errors remain unchanged: 甲减/气切 absorb the following 重 in two sentences; 达格列净 loses its first character in one long document. Historical regressions include an extra prefix 内 and ambiguous 先取消内. Do not tune on the public final and then report it as a fresh independent benchmark.
Independent local MedLex processes replayed the frozen 1800 cases twice with identical spans/types after export and reload, plus a 40-case V9 rollback-load rehearsal. Sequential CPU median latency was about 20 ms, overall p95 178–181 ms and long-text p95 207–215 ms with 4 threads. These are local measurements, not a production concurrency/SLA claim.
Training and reproducibility
15838 synthetic training sentences, 2663 development sentences. Final round: full participating-parameter FP32 training on Apple MPS, one epoch, batch8, max_tokens256, encoder LR1e-6, head/CRF LR3e-6, AdamW weight decay0.01, constant schedule, clipping1.0. Teacher KL uses temperature2, coefficient0.25 and only positions where teacher argmax agrees with training gold. Student dropout is disabled while gradients remain enabled. Teacher is frozen and absent from serving.
The parent is V10r5 seed42 epoch1, not the original upstream checkpoint. The separately versioned warm-start archive and original base revision are required to rerun this last round; training once from the upstream base with these hyperparameters would not reproduce V10r6. See training instructions, data card and recipe. Cross-hardware bit-identical retraining is not promised. The public standalone code is verified by replaying all frozen final predictions.
# From a clone of this repository after installing the package:
python scripts/evaluate.py --bundle bundle --data data/test.jsonl --output final-replay.json
This replay is reproducibility verification, not a new independent acceptance test.
License and provenance
Apache-2.0; retain LICENSE and NOTICE. Upstream model: iic/nlp_raner_named-entity-recognition_chinese-base-cmeee, revision af6a1b17ebeec8a5a2432d638bdbd11170c3bfb6. Its fixed-revision model card and official metadata declare Apache License 2.0. Original synthetic corpus and adaptation code are distributed under Apache-2.0; linked source documents are not relicensed. Upstream framework licenses are separate.
Weights SHA256: 718f6d8d3ec37c21a25ba887e6be4c37a2d9d23ceb0fe3c1ef192e6e4b9d7783.
Final dataset SHA256: 728f9f1dfe1314513de2d264971ffd06799f977e355cc910f30b516263776d31.
Report issues with a minimal synthetic or properly de-identified example, expected spans/types, version and environment. Do not post patient data, credentials or internal service configuration.