Token-estimation calibration

June 11, 2026 · View on GitHub

Divergence of the dependency-free heuristic (HeuristicEstimator, heuristic/v2) and the tiktoken default from real tokenizers, across fixed corpus shapes. Generated by benchmarks/token_calibration.py (issue #493).

  • Generated: 2026-06-11
  • tiktoken model: cl100k_base
  • ⚠️ tiktoken encoding unavailable when generated (offline / no warmed TIKTOKEN_CACHE_DIR). The tiktoken and relative-error columns read n/a; regenerate in an environment with a warmed cache to populate them.
  • Provider tokenizers (Anthropic / Gemini): not run (opt-in via CW_TOKEN_CALIBRATION_PROVIDERS + a registered counter; never run in CI).
ShapeCharsHeuristictiktokenHeuristic vs tiktoken
prose_en13232n/an/a
prose_cjk9688n/an/a
json14436n/an/a
code12330n/an/a
logs14736n/an/a

Reading the table: a large negative Heuristic vs tiktoken error on prose_cjk is the failure mode issue #525 fixes — the script-aware heuristic keeps CJK within roughly ±30% of tiktoken instead of under-counting ~4×. For Latin prose, JSON, code, and logs the heuristic tracks len // 4, which is adequate for budget headroom decisions.