Evaluate a Tokenizer#
Use tokenizer_extension/evaluate to compare fertility across tokenizers, and tokenizer_extension/eval_init to compare bits per byte (BPB) across resized checkpoints.
For the reasoning behind the metrics, see Evaluation Metrics.
Compare Fertility#
The evaluate step is CPU-only and streams its corpus.
Choose an evaluation corpus that is distinct from the corpus that trained the extension. The default is
ai4bharat/samanantarwithhf_config: hiandtext_field: tgt. When the two share a source, setcorpus.skip_docsto skip the slice thatextendtrained on.Run the step once per tokenizer with the same
corpusblock. Include the base tokenizer as a reference.$ uv run nemotron steps run tokenizer_extension/evaluate -c default \ tokenizer=nvidia/NVIDIA-Nemotron-3-Nano-30B-A3B-BF16 label=base \ output=./output/eval/fertility_base.json $ uv run nemotron steps run tokenizer_extension/evaluate -c default \ tokenizer=./output/tokenizer_extension/add label=add-30k \ output=./output/eval/fertility_add.json $ uv run nemotron steps run tokenizer_extension/evaluate -c default \ tokenizer=./output/tokenizer_extension/replace label=replace-30k \ output=./output/eval/fertility_replace.json
tokenizeraccepts a Hugging Face identifier or a local directory.labelis a free-text tag recorded in the output JSON.Compare
fertilityacross the reports. Lower is better. Before comparing two arms, confirm that theirsummary.jsonfiles report the sametokens_spliced.
To use a local corpus, set corpus.hf_dataset=null corpus.path=<dir-or-glob> and the matching corpus.text_field.
corpus.num_docs=0 scores the full corpus.
Compare Bits per Byte#
The eval_init step needs a GPU and reads a local corpus by default: a JSON Lines file with text_field, or a text file with one document per line.
Prepare held-out target-language text at
data_file, and a second file in English or the base language if you want a regression check.Score the resized checkpoints against the base model.
$ uv run nemotron steps run tokenizer_extension/eval_init -c default \ models=[./output/resized_checkpoint,./output/resized_checkpoint_replace] \ data_file=./data/eval/target_val.jsonl max_docs=2000 \ output_json=./output/eval/bpb_target.json
base_modeldefaults tonvidia/NVIDIA-Nemotron-3-Nano-30B-A3B-Base-BF16and is scored first as the reference; the report includes the delta for each model.Repeat with the English or base-language file to check for regression.
Read
bpb, notlossorperplexity, when the models carry different tokenizers.
Keep the Comparison Valid#
Always bound the run with max_docs (-1 scores the whole corpus).
If more than one model would be scored under max_tokens with no max_docs, the step refuses to run because each tokenizer would stop after a different amount of text.
Setting allow_token_cap_comparison: true overrides the refusal and exists only to reproduce a historical result.
Next Steps#
Field reference: Evaluate YAML Reference and Eval Init YAML Reference
Output file layout: Output Files