Downloads · 30 days
0
salmanhadli/medical-bpe-16k
medical-bpe-16k is a machine learning model from salmanhadli. Use it for the machine learning task on the model card, and read the license before you ship it in a product. It is set up for transformers. The card lists the license as mit.
A 16,000-token byte-level BPE tokenizer trained on 45,000 PubMed abstracts.
Downloads · 30 days
0
Access
Public
Updated Sep 17, 2026
Repo size
—
Likes
1
Public
Click a slice to open those files.
.json1.1 MB · 99%
From the Hugging Face model README
A 16,000-token byte-level BPE tokenizer trained on 45,000 PubMed abstracts.
On biomedical text it encodes more efficiently than cl100k_base (GPT-4) and o200k_base (GPT-4o), despite a vocabulary 6–12x smaller. On general English it is clearly worse than both. Both halves of that sentence are the point — a domain tokenizer reallocates vocabulary, it does not add any.
Fertility is tokens per whitespace word: lower is better. Evaluated on 5,000 held-out PubMed abstracts and 5,000 held-out wikitext-103 paragraphs, neither of which appeared in training.
| tokenizer | vocab | fertility | mean tokens/abstract |
|---|---|---|---|
| medical-bpe-16k | 16k | 1.375 | 188.8 |
| o200k_base (GPT-4o) | 200k | 1.430 | 196.3 |
| cl100k_base (GPT-4) | 100k | 1.460 | 200.5 |
| general-bpe (control) | 16k | 1.747 | 239.9 |
5.8% fewer tokens per abstract than GPT-4's tokenizer, 3.8% fewer than GPT-4o's.
| tokenizer | vocab | fertility | mean tokens/paragraph |
|---|---|---|---|
| o200k_base (GPT-4o) | 200k | 1.163 | 163.9 |
| cl100k_base (GPT-4) | 100k | 1.173 | 165.3 |
| general-bpe (control) | 16k | 1.208 | 170.3 |
| medical-bpe-16k | 16k | 1.577 | 222.2 |
35.6% more tokens than o200k on ordinary prose. This tokenizer is not a general-purpose replacement.
Out of 20 common clinical terms, encoded as exactly one token:
| tokenizer | rate |
|---|---|
| medical-bpe-16k | 2/20 (hemoglobin, lymphocyte) |
| cl100k_base | 0/20 |
| o200k_base | 0/20 |
| general-bpe | 0/20 |
acetylcholinesterase inhibitor costs 3 pieces here, 6 under o200k, 7 under cl100k, and 10 under a same-sized BPE trained on wikitext.
Trained on abstracts, the merge table spends its early slots learning that -ation, -osis, -emia and -inib are load-bearing morphology. Trained on Wikipedia, the same budget goes to Ġ, and Ġ. — the first merges of the control tokenizer are punctuation, while this one's are in, ti, al, ra.
from transformers import AutoTokenizer
tok = AutoTokenizer.from_pretrained("salmanhadli/medical-bpe-16k")
tok.tokenize("acetylcholinesterase inhibitor")
# ['acetyl', 'cholinesterase', 'Ġinhibitor']
Or with the tokenizers library directly:
from tokenizers import Tokenizer
from huggingface_hub import hf_hub_download
tok = Tokenizer.from_file(
hf_hub_download("salmanhadli/medical-bpe-16k", "tokenizer.json")
)
tok.encode("serum creatinine 1.4 mg/dL").tokens
| Algorithm | Byte-level BPE (tokenizers.models.BPE) |
| Vocab size | 16,000 |
| Min frequency | 2 |
| Pre-tokenizer | ByteLevel(add_prefix_space=False) |
| Decoder / post-processor | ByteLevel (trim_offsets=True) |
| Special tokens | <|endoftext|> (eos), <pad> |
| Corpus | 45,000 abstracts from slinusc/PubMedAbstractsSubset |
| Held-out | 5,000 abstracts, disjoint from training |
There is no unk_token — byte-level BPE has full byte coverage, so any UTF-8 input round-trips losslessly.
Intended for tokenizing biomedical text: abstracts, clinical notes, literature corpora. Useful when context length or token cost is the binding constraint on a domain pipeline.
Not intended for general-purpose text, where it is measurably worse than the standard tokenizers above. It is a tokenizer only — there are no model weights here, and it carries no medical knowledge and makes no clinical claims. Any model trained on it inherits whatever biases live in PubMed abstracts: a literature corpus is not a patient population.
The vocabulary reflects abstract prose. Clinical shorthand, drug names post-dating the corpus, and non-English text will fragment more than the numbers above suggest.
Trained with tokenization-explainer:
uv run python scripts/train_medical_tokenizer.py \
--corpus data/pubmed_train.jsonl \
--vocab-size 16000 \
--out artifacts/medical-bpe-pubmed/tokenizer.json
The comparison above is scripts/compare_tokenizers.py, which also trains the same-sized wikitext control so the win can be attributed to the corpus rather than to the algorithm or the vocabulary size.
MIT