# Tokenizer: RO and EN balance (/docs/research/tokenizer)

The Romanian tokenizer is pinned at 1.3093 tokens per word, and the EN-balanced build holds both the Romanian and English bars at once, at vocabulary 7530.

The tokenizer is the one limit Codwen inherited from its base model and cannot move from the serving side: the base BPE spends **2.834 tokens per Romanian word** against **1.191** for English, and **44.9 %** of Romanian words need three tokens or more. The tail — the long, rare words — is exactly where the production errors live.

## The shipped point [#the-shipped-point]

A pure-JS byte-level BPE trained on the assembled RO/EN corpus (no Python, no network) brings Romanian down, and the result is a **gated artifact**, not a paragraph:

| tokenizer | vocab | RO tok/word | EN tok/word | RO words ≥ 3 tok |
| --- | --- | --- | --- | --- |
| baseline `hf:gpt2` | — | 2.834 | 1.191 | 44.9 % |
| trained `bpe:artifact` | 6 706 | **1.3093** | 1.486 | 4.6 % |

The shipped tokenizer meets the Romanian bar — **RO ≤ 1.35** — by upsampling Romanian (a build weight of 2), and pays for it in English: **RO 1.3093 / EN 1.4859**.

## The EN-balanced build [#the-en-balanced-build]

Upsampling Romanian starves English: a Romanian pair seen once weighs 2 and survives the merge floor, an English pair seen once weighs 1 and is dropped. The fix is not less Romanian but English too — with both weights at 2, an English singleton pair also clears the floor:

| build | vocab | RO tok/word | EN tok/word | verdict |
| --- | --- | --- | --- | --- |
| shipped | 6 706 | 1.3093 | 1.4859 | EN fails |
| **chosen** | **7 530** | **1.3135** | **1.2176** | **both pass** |
| `hf:gpt2` baseline | — | 2.834 | 1.191 | RO fails |

Both bars hold at the chosen point — RO **1.3135**, EN **1.2176**, vocab **7 530** — and the English penalty the round-3 recipe accepted (**+24.8 %** over GPT-2) is removed: English is now **+2.2 %** over GPT-2 while Romanian stays 0.036 under its bar. The share of words costing three or more tokens falls to **RO 4.81 % / EN 1.63 %**.

## A flooring question, not a slope [#a-flooring-question-not-a-slope]

The English curve is a step, not a slope: English sits near 1.48 until its weight reaches 2 and then drops to about 1.21, because that is the moment its singleton pairs clear the merge floor. Two invariants make the mechanism testable:

1. a language is starved unless its weight is at least the merge floor;
2. equal weights with an equal floor reproduce the no-upsampling build exactly.

The honest reading: meeting both bars requires admitting pairs that occur **once** in the corpus, so this is a measured candidate instrument, not yet a production vocabulary.

## How it is pinned [#how-it-is-pinned]

The gate at `scripts/ci/check-tokenizer-fertility.mjs` reads the committed artifact and fails the build when either the absolute bar is exceeded or the measured value no longer matches the figure the research document quotes. The gate is what turns the number into a build condition.

<Callout type="warn">
The committed 1.3093 is an **in-sample** figure: the instrument trains and measures on the same corpus, so the number describes a fit, not a held-out generalisation. The vocabulary here is an instrument, not a shipped vocabulary.
</Callout>
