CoolFace
Modelpublic

durganani60/medical-bpe-16k

sourceHugging Facemitupdated 21d agoView on Hugging Face
0likes
Model Card

πŸ₯ Medical BPE 16k Tokenizer

A domain-specific Byte-Pair Encoding (BPE) tokenizer trained on PubMed abstracts, designed to demonstrate that training domainβ€”not vocabulary sizeβ€”is the primary driver of tokenization efficiency on specialized text.


🎯 Model Overview

  • β€”Vocabulary Size: 16,000
  • β€”Algorithm: Byte-Level BPE
  • β€”Training Data: 45,000 PubMed abstracts (~180MB text stream)
  • β€”Fairness Baseline: Compared directly against general-bpe (16k vocab, trained on Wikitext-103) as well as modern general-purpose tokenizers (cl100k_base, o200k_base).

Key Benchmarks & Fertility Comparison

Fertility measures average tokens produced per word (lower is better):

TokenizerVocab SizeTraining DomainHeld-out Medical FertilityHeld-out General Fertility
πŸ₯ `medical-bpe-16k`16,000PubMed abstracts1.375 βœ… (Best)1.575 ❌
πŸ€– o200k_base (GPT-4o)~200,000General web1.4301.163 βœ…
πŸ€– cl100k_base (GPT-4)~100,000General web1.4601.173
πŸ“° general-bpe16,000Wikitext-1031.747 ❌1.208

Key Takeaways

  1. 1.Domain Over Size: medical-bpe-16k beats general-bpe by 0.372 on held-out medical text with identical vocabulary sizes and algorithms.
  2. 2.Efficiency vs. Scale: Despite having an order of magnitude smaller vocabulary, a 16k domain-trained tokenizer outperforms 100k–200k scale general tokenizers on domain-specific text.
  3. 3.Single-Token Rate: In a spot-check of 20 medical terms, medical-bpe-16k retains 2 as single tokens, whereas cl100k and o200k retain 0.

πŸš€ Quickstart & Usage

Installation

bash
pip install transformers

from transformers import PreTrainedTokenizerFast

tokenizer = PreTrainedTokenizerFast.from_pretrained("durganani60/medical-bpe-16k")

# Test on medical text
text = "The patient presented with acute myocardial infarction and hypercholesterolemia."
tokens = tokenizer.tokenize(text)
print("Tokens:", tokens)
print("Token Count:", len(tokens))