Fashions specialised for a website or a process by fine-tuning basic open-source fashions, comparable to Qwen and Gemma, inherit a vocabulary constructed for a lot of domains and basic purposes.
In an essay grader we run in manufacturing, that vocabulary cut up the textual content the mannequin writes most into many tokens. This text previews some outcomes from the VocabX paper, which we’ll publish quickly: how we specialised the vocabulary round the price of every token moderately than its frequency, and reduce measured inference value by 77% with out altering the bottom mannequin.

The tokenizer is often handled as a hard and fast property of the bottom mannequin, inherited and left alone. For a mannequin specialised in a single area, it may be one of many largest value levers, and it’s set earlier than any coaching step.
One of many techniques we run in manufacturing is an automatic grader for Portuguese essays, constructed on Qwen3-4B. It receives the essay, the immediate and the supporting texts, and returns a JSON evaluation with a grade and a remark for every competency.
The mannequin was already small, at 4 billion parameters, and had already been educated for the duty. Its tokenizer, nonetheless, was nonetheless the unique Qwen3-4B one, constructed for a lot of languages and plenty of sorts of textual content. Within the grader, it was used for a single language, Portuguese, and a single response format. That had two prices: the textual content the grader writes on each request took extra tokens than it wanted, and at each generated token the mannequin scored a vocabulary of 151,669 entries, together with many this process virtually by no means makes use of.
We rebuilt that vocabulary with a way we name VocabX, conserving the identical base mannequin, the identical knowledge and the identical coaching recipe. The numbers on this article come from the present model of the paper, nonetheless underneath overview, and should change earlier than publication.
A Vocabulary Constructed for Everybody
The main language fashions learn and write in tokens, and the tokenizer decides how textual content turns into tokens. The tokenizers of the main general-purpose fashions are educated on giant collections of textual content from many domains and languages, from supply code to contracts to Chinese language. For a general-purpose mannequin, that selection is sensible.
For a mannequin utilized in a single area, it creates two sorts of waste without delay.
The primary is fragmentation. The tokenizer splits into many items precisely what the area repeats most. Within the grader, each response begins with the identical JSON envelope, the identical competency names, the identical analysis phrases. In contracts, it’s the boilerplate clauses. In code, the identifiers. Every of those sequences prices a number of tokens the place one would do, and the mannequin pays for each one in all them on each request.

The second is extra. The vocabulary carries tens of hundreds of entries the area by no means makes use of, and the mannequin computes a rating for all of them at each token it generates. A mannequin tuned to grade American college biology exams will virtually by no means write in Chinese language, but it computes the chance of each Chinese language-language token at each step. The vocabulary splits into many items what the area repeats most, and carries entries the area by no means makes use of.

Studying Is Low cost, Writing Is Costly
The pure response is to rely tokens and attempt to cut back the rely. However the rely will not be the invoice.
To see why a generated token prices extra, it helps to take a look at how inference works. It has two phases. In prefill, the mannequin processes the entire enter in a single cross by way of the community: every weight learn from GPU reminiscence is reused for each enter token, and the restrict is compute. In decode, the mannequin generates the response one token at a time, and every token wants a full cross. Every weight learn is used only some occasions, and the GPU spends most of its time ready for knowledge to reach from reminiscence: the restrict turns into reminiscence bandwidth.
This impact is strongest precisely the place we function: small fashions served with reasonable batches. Batching requests splits the load reads throughout them and eases the issue, however doesn’t clear up it. At each decode step, the mannequin additionally reads the KV cache, the eye reminiscence that holds the context already processed and grows with it. Within the case we measured, the grader, a generated token prices 7.4 occasions a token learn, however the ratio varies with the {hardware}, the issue, the batch measurement, the context size and different components, and it may be bigger than that. Normally, the course holds: producing prices greater than studying.

Consider a delivery firm that expenses per field, however expenses seven occasions extra for outgoing containers than for incoming ones. Lowering the full variety of containers helps. Lowering the outgoing containers helps seven occasions extra. A technique that compresses enter and output equally misses a lot of the attainable financial savings.
The third part of the invoice is the vocabulary itself. The mannequin’s final layer, the LM head, turns the interior state right into a rating for each attainable token. To try this, it holds one row of parameters per vocabulary entry. In a mannequin the scale of Qwen3-4B, that matrix accounts for nearly 10% of the parameters. It’s a share that giant fashions soak up with out noticing, nevertheless it weighs on a small mannequin.
And the fee will not be paid solely as soon as. The enter layer seems up solely the row of the token being learn, however the LM head reads and multiplies all the matrix for each generated token. Since decode is already memory-bound, each further row is extra knowledge to maneuver at each step. An entry the area by no means makes use of prices precisely the identical as a frequent one. That’s the reason including tokens can decrease the rely and lift the invoice on the similar time. VocabX doesn’t embody this time period in its choice criterion, nevertheless it controls vocabulary measurement in two steps: the sub-word merge replaces the bottom vocabulary with a smaller, domain-specific one, and macros enter underneath a hard and fast funds. Within the grader, the output layer went from about 152,000 to about 65,000 rows.
Why Present Options Fell Brief
Adapting a mannequin’s vocabulary will not be a brand new concept. Reference strategies within the literature, comparable to quick vocabulary switch (FVT), multi-word tokenization (MWT) and Liquid AI’s in-place tokenizer growth (in-place BPE), which continues BPE coaching from the unique vocabulary, already cut back fragmentation. Once we examined them on our downside, we discovered two limitations.
They select tokens by frequency, not by value. An expression that seems typically within the enter is price extra to them than one which seems much less typically within the response, even when the second is the dearer one to serve.
They work on a single layer. They both regulate how phrases are reduce into items, or merge complete phrases into one token. None of those three does each underneath the identical criterion. And the grader’s greatest waste was exactly in lengthy, repeated spans such because the JSON envelope, which a sub-word methodology solely reaches after merging every half, one after the other.
How We Solved It
VocabX addresses each limitations, plus a 3rd downside that seems on the plain path to fixing the primary.
First, we modified the query. As an alternative of asking what number of tokens a candidate saves, we ask how a lot value and time it saves. Every eradicated token is multiplied by the worth of the sphere it seems in: system immediate, person message or mannequin response. Within the case we measured, the grader, a token saved within the response is price 7.4 occasions one saved within the enter, and the vocabulary is constructed accordingly.
Second, we work on each layers without delay. Again to the delivery firm: you’ll be able to reduce containers by packing every merchandise higher, or by recognizing that the identical twelve-item equipment ships each week and sending the equipment in a single field. VocabX does each. On the sub-word layer, it rebuilds how area phrases are reduce into items. On the multi-word layer, it seems for complete spans that repeat, from quick expressions to full traces and JSON envelopes, and turns every right into a single token, which we name a macro token. Each layers are chosen underneath the identical value criterion, every with its personal funds.

To seek out these spans, we use 5 miners, automated searches for spans that repeat throughout the corpus, every specialised in a single type of repetition: lengthy phrases, complete traces, expressions, full sentences, and constructions with punctuation comparable to JSON and tags. Averaged over eight corpora, the final one contributed essentially the most, and on code it alone accounted for 17.5 factors. With out all 5, token discount on the grader would drop by 55.6 factors.

Third, we estimate what the pattern can’t see. Selecting tokens by value requires understanding how a lot every candidate nonetheless saves after those already chosen. Measuring that precisely would require reprocessing all the corpus after each selection, tens of hundreds of occasions. A standard method to do that at scale is to measure on a pattern of paperwork, after which a candidate absent from the pattern will get zero acquire.
An expression that seems 37 occasions in 50,000 paperwork exhibits up in a 400-document pattern solely about 26% of the time. In a contracts corpus, solely 16.6% of the candidates seem in a 400-document pattern; the remainder are by no means evaluated.

A candidate’s acquire has two components. One is how a lot it saves over all the corpus, and that may be counted precisely, with no pattern. The opposite is how a lot of that saving will not be but lined by the tokens already chosen, and solely that half must be estimated. For candidates the pattern can’t see, we use a statistical estimate primarily based on the habits of those it may well see, as a substitute of zero. A candidate that’s uncommon within the pattern however frequent within the corpus is again within the operating.
That change alone, with the identical pattern and the identical funds, raised token discount on a contracts corpus from 44.7% to 52.8%.

What Modified within the Grader
To measure the true impact, we educated seven variations of the grader with the identical base mannequin, the identical knowledge, the identical recipe and the identical seed. The one distinction between them is the tokenizer. All of them ran the identical 500 requests on the identical check machine, with an RTX 5090 GPU and the vLLM inference server, and price was calculated from measured runtime.

The mannequin’s response dropped from 350 to 101 tokens on common. Price dropped 77.0%. High quality, measured by the bench rating, which mixes grading accuracy and the accuracy of screening off-topic or rule-breaking essays, rose from 0.703 to 0.810.
Getting there required a course correction. The primary model of the vocabulary fused every competency’s grade with the encircling JSON right into a single macro token. It was essentially the most compact possibility, however high quality dropped: its bench rating was 0.689, under the manufacturing grader’s 0.703. With the grade contained in the macro, every mixture of grade and construction grew to become a unique variant of the identical token, and the mannequin selected each in a single step. Giving the grade its personal token value 2 further tokens per response, raised the bench rating to 0.810 and, within the measurement, was even cheaper: a 77.0% discount, towards 73.3% for the fused model.
The lesson applies past the grader. Compression has a price when the compressed span carries the very choice the mannequin exists to make. The aim will not be the most cost effective attainable vocabulary, however the most cost-effective one which preserves the tokens that matter.
Past the Grader
To seek out out whether or not the acquire was particular to our case, we in contrast VocabX with the three reference strategies on 5 public domains (contracts, medical papers, scientific papers, information and Python code) and three mannequin households (Qwen3, Llama-3.1 and Gemma-3). All strategies used the identical mining and check paperwork, and the identical vocabulary ceiling.
VocabX compressed greater than the strongest reference methodology in all fifteen mixtures, by 1.2 to 9.3 factors. In estimated inference value, the pruned model of VocabX additionally led in all fifteen, with common margins of 10.2 factors on Qwen3, 7.5 on Llama-3.1 and 13.6 on Gemma-3. On contracts, the pruned model reached 62.6% token discount with 113,426 vocabulary entries, towards 61.8% for one of the best in-place BPE configuration, which makes use of 207,803.

Paying Just for the Tokens That Matter
VocabX doesn’t make the mannequin smarter. It makes the mannequin cease paying for textual content it doesn’t want to write down piece by piece, and cease scoring a vocabulary it can by no means use. In our grader, that reduce measured inference value by 77%, with the identical base mannequin and the identical coaching recipe.
Specialization often begins with knowledge and weights. It will probably additionally begin one layer earlier, within the vocabulary.
The complete methodology, the tables for each experiment and the discarded interventions will probably be within the VocabX paper, which we’ll publish quickly.
Sources
Additional Studying
Discover Dharma AI on Hugging Face to strive our demos, obtain our open fashions, and see how specialised AI techniques outperform general-purpose fashions in actual enterprise purposes.

