Skip to content

Tokenizer

Sudhanshu edited this page Nov 23, 2026 · 4 revisions

Healthcare BPE Tokenizer

The project trains a tokenizer using healthcare-domain text, independently of pretrained LM weights. Its training entrypoint is train_healthcare_tokenizer.py.

Train from healthcare publications

python -m scripts.train_healthcare_tokenizer `
  --source hf `
  --dataset common-pile/pubmed_filtered `
  --sample-docs 200000 `
  --vocab-size 32000 `
  --output artifacts/healthcare_tokenizer.json

The tokenizer trainer uses ByteLevel pre-tokenization and a BPE model. Its trainer explicitly registers <pad>, <unk>, <bos>, and <eos> as special tokens.

Fixed on 23 November 2026: earlier versions of the script built this trainer but did not pass it to train_from_iterator, so --vocab-size and the special tokens were ignored. Retrain any tokenizer made with an older version before using it for a new run. Released tokenizers and checkpoints are unaffected.

Inspect tokenizer and configuration together

@'
from tokenizers import Tokenizer
from mixtral_lab.config import ModelConfig

t = Tokenizer.from_file('artifacts/healthcare_tokenizer.json')
c = ModelConfig.from_json('configs/healthcare_moe_single.json')
print('Tokenizer vocabulary:', t.get_vocab_size())
print('Model vocabulary:', c.vocab_size)
print('Special token IDs:', {x: t.token_to_id(x) for x in ['<pad>', '<unk>', '<bos>', '<eos>']})
assert t.get_vocab_size() == c.vocab_size
'@ | python -

Invariants

  • <eos> must exist for both pretraining document boundaries and SFT response termination.
  • <unk> must be genuinely registered in the tokenizer vocabulary when the BPE model is configured with that unknown token; otherwise unfamiliar text can raise Unk token ... not found in the vocabulary.
  • Keep token IDs, vocabulary size and tokenizer JSON unchanged when loading trained checkpoints.
  • Preprocessing repairs that skip malformed samples may keep a run alive, but they are not substitutes for tokenizer coverage tests and corpus-quality review.

The bundled byte tokenizer is for the isolated offline smoke test and is not a replacement for the healthcare tokenizer used in full training.

Clone this wiki locally