DevTools Logo

Finetune Token Length Histogram

Finetune Token Length Histogram

See the length distribution of your training rows and flag examples over the limit.

Runs in your browser
Try an example

JSONL dataset

24 lines · 8,329 chars

Token length distribution

24 examples · p95 127 · 0 over limit
Token counts use a local chars/4 + CJK heuristic, not a tokenizer; overhead is configurable.
Mean79.3
Median78.0
p95126.8
p99129.5
Min / max35 / 130
Examples24
Total tokens≈1902
Over cutoff0

Bins use Freedman–Diaconis (Sturges when IQR is 0), clamped to ≥1 token and ≤120 bins; amber bins start at the cutoff. Counts are heuristic, not tokenizer-exact.

Details

Paste JSONL chat, prompt/completion or text rows to see the distribution of example lengths before training. Freedman–Diaconis bins, mean, median, p95/p99 and a configurable cutoff make it easy to spot truncation risks; over-limit rows are listed with their line numbers and exported as CSV or JSON. Token counts use a transparent local heuristic (ceil(chars/4) with CJK characters counted individually), plus an optional chat-format overhead of +2 base, +3 per message and +3 for reply priming. No dataset is uploaded and no tokenizer wasm is downloaded.

More examples

Chat rows

User text counts as prompt tokens, assistant text as completion tokens, with chat overhead added when enabled.

Cutoff check

The panel highlights the bins beyond the cutoff and lists every over-limit row by line number.

CSV export

Full per-row statistics can be exported for budgeting or for feeding a trimming script.

Examples

Templated dataset

Input
Many rows with identical length, IQR = 0
Output
Sturges fallback bins rather than a divide-by-zero error

The binning rule explicitly handles the common all-same-length case.

8192 cutoff

Input
Dataset with p95 = 6100, p99 = 9400
Output
Offender table listing rows above 8192 with overflow amounts

The tail is where truncation usually damages training signal.

Malformed rows

Input
One invalid JSON line and one object with an unknown shape
Output
Separate malformed and skipped counts with first line numbers

Nothing is silently dropped from the audit.

About this tool

Finetune Token Length Histogram measures how long your training examples are before you spend compute on them. It reads JSONL rows locally, extracts prompt and completion text from chat, prompt/completion or plain text shapes, and plots the resulting length distribution.

Freedman–Diaconis binning adapts to the dataset, with a Sturges fallback when the interquartile range is zero and hard clamps of at least one token and at most 120 bins. Mean, median, p95 and p99 are shown alongside a configurable cutoff; rows above it are listed with their source line numbers.

Counts come from a documented heuristic rather than a downloaded tokenizer: ceil(characters/4) for non-CJK text, one token per CJK character, and an optional chat overhead of +2 base, +3 per message and +3 for reply priming. Nothing is uploaded or persisted.

What this tool does not do

  • No tokenizer wasm is loaded or executed; counts are heuristic.
  • Files are parsed in the browser tab, so extremely large inputs are limited by available memory.
  • Tool-call payloads contribute through their serialized content only.
  • The cutoff shading is approximate because bin edges are rounded to whole tokens.
  • Weighted examples are treated as weight 1.

How to use this tool

  1. Paste or drop JSONL

    One object per line; chat messages, prompt/completion and text fields are all recognized.

  2. Pick a cutoff

    Use a preset such as 8192 or type a custom limit matching your training context window.

  3. Read the distribution

    Check the histogram, p95/p99 and the over-limit table; amber bins begin at the cutoff.

  4. Export the row data

    Download the full CSV for budgeting or the offenders JSON for a trimming script.

Use cases

Training budget planning

Estimate total tokens and spot datasets whose tail will be truncated.

Dataset curation

Export over-limit row indices and trim or summarize them before training.

Model migration

Compare distributions when moving between context-window sizes and providers.

Counting rules

ComponentCount
Non-CJK textceil(characters / 4) per prompt or completion field.
CJK textOne per character; the chars/4 rule would badly underestimate it.
Chat messages+3 per message and +3 reply priming, matching common chat accounting.
Base overheadOptional +2 per chat example; turn it off for pure content counts.
BinsFreedman–Diaconis; Sturges fallback at IQR = 0; 1–120 bins.
PercentilesLinear interpolation between adjacent sorted values (numpy default).

These are estimates for dataset planning; a real tokenizer is required for exact context-window checks.

Common mistakes

Mistake:Treating heuristic counts as tokenizer-exact.

Fix:Use the numbers for relative comparisons; verify critical rows with the target model's tokenizer.

Mistake:Forgetting chat overhead.

Fix:Keep the overhead toggle on when budgeting chat-formatted fine-tuning.

Mistake:Setting the cutoff below the minimum row length.

Fix:The tool honestly reports every row as over-limit; choose a realistic context size.

Mistake:Ignoring skipped rows.

Fix:Check the warning counts: unknown shapes and malformed lines are not included in the histogram.

Mistake:Reading p95 as a guarantee.

Fix:It is a percentile of the sample; 5% of examples are still longer.

Frequently asked questions

Why doesn't this use tiktoken for exact counts?

The tool is deliberately dependency-free and offline: no wasm or vocabulary files are downloaded. It uses ceil(characters/4) for non-CJK text, one token per CJK character, and an optional chat-overhead term. That is accurate enough to compare datasets and find long outliers, but not a substitute for the target model's tokenizer when you need an exact context-window verdict.

What counts as one example in chat format?

One JSONL line. All message content is combined: user and system messages form the prompt side, assistant messages the completion side. When overhead is enabled the tool adds two base tokens, three per message and three reply-priming tokens, mirroring the way chat fine-tuning APIs account for control tokens.

Why is my count higher than the text alone suggests?

Chat rows carry per-message control tokens even when the visible text is short. A two-message example adds 2 + 3×2 + 3 = 11 overhead tokens. Turn off the overhead checkbox to see pure content counts side by side with the chat-inclusive numbers.

Can it handle a huge JSONL file?

The current browser implementation parses the pasted text in memory, so very large files are limited by available RAM rather than a fixed cap. For multi-hundred-megabyte datasets, split the file or run a streaming tokenizer locally. Row ids remain the original 1-based line numbers so exported offender lists stay actionable.

How are bins and percentiles chosen?

Bin width follows the Freedman–Diaconis rule using linearly interpolated quartiles. When the interquartile range is zero — common with templated data — a Sturges-style fallback is used instead. Widths are at least one token and the count is capped at 120. Percentiles use linear interpolation between adjacent sorted values, the same convention as numpy's default.

Does my dataset get uploaded?

No. Parsing, counting, binning, percentile calculations and exports all happen in your browser tab. Nothing is sent to a server, and no dataset contents are stored after you leave the page.

References & standards