Tokenizer Fairness and Data Mixing

Two choices are fixed before training starts: how text becomes tokens, and how much of each source the model reads. One paper cuts the token-cost gap between languages by 89%. The other picks a data mix for 1.4% of the training compute.

Pick a tokenizer, then press Play. Four toy languages share one budget of merges. Watch which language gets them. Then we build, piece by piece, BPE, a fairness score, the fair-max rule and a data mixer made from leverage scores.

You need a little Python and what a probability is. We build the rest from zero.

Session 1 of Georgia Tech CS 8803, LLM seminar. It rests on two papers: Foroutan, Meister, Paul, Niklaus, Ahmadi, Bosselut and Sennrich, Parity-Aware Byte-Pair Encoding: Improving Cross-lingual Fairness in Tokenization (2025), and Xie, Tonin and Cevher, Chameleon: A Flexible Data-mixing Framework for Language Model Pretraining and Finetuning (ICML 2025). Every idea is re-taught here in our own words and devices.

Share one merge budget

80

Toy, run live: real BPE on four made-up languages, each with its own letters and 36 words. Their shares of the training text are 64%, 24%, 8% and 4%. The paper's real result (Table 1, 128k merges, 30 languages): Gini 0.064 for Classical BPE and 0.007 for Parity-aware BPE.

Chapter 0

Two Choices Made Before Training

See why the tokenizer and the data mix set a model's limits before the first gradient step

You have a budget of 100 billion training tokens and a pile of text in 30 languages: web pages, books, code, encyclopedia articles. Before you pick a learning rate, you make two choices. Nothing later can undo them.

Choice one: how to cut text into pieces. A model reads integers, not letters. A tokenizer maps text to a sequence of integer tokens. The map is fixed for the model's whole life: every checkpoint and every fine-tune reuses it.

Choice two: how much of each source to train on. Call each source a domain (a language, or a source such as Wikipedia). A data mixture gives each domain a weight: the share of training batches drawn from it.

TokenizerData mixture
It fixeshow many tokens a piece of text costshow many tokens each domain gets
Usual answerBPE on the pooled corpusequal weights, or weights from a small trained model
This session's paperParity-aware BPEChameleon
Price of the fixone small extra pass per merge0.8 GPU-hours, against 56 for the model

A tokenizer can serve one language well and another badly. Text in the badly served language splits into more tokens. Services bill per token, and context windows count tokens. So the same message costs its writer more. The Parity-aware BPE paper calls this the tokenization tax.

Send one message in four languages

Each bar is the token count for the same 60-character message, using the hero's tokenizers after 80 merges. Switch the tokenizer and compare the bills.

Toy tokenizers from the hero. We made up the price, $2 per million tokens.

With made-up numbers: under the toy Classical tokenizer, Alder packs 3.53 characters into each token and Dunya packs 1.00. A 60-character message costs Alder 60 / 3.53 = 17 tokens and Dunya 60 tokens. At $2 per million tokens, a million messages cost Alder $34 and Dunya $120. Dunya's writers pay 3.5 times more for the same words.

Failure. A multilingual product is slow and costly in some languages, and their chats run out of context early. Measure: count tokens per line on a parallel corpus (the same sentences translated into every language). Fix: change how the tokenizer learns, before pretraining. Once training starts, the vocabulary is fixed.

  1. BPE, from zero: merge the most frequent pair, and measure compression.
  2. The Gini coefficient: one number for how unequal token costs are.
  3. The fair-max rule: give each merge to the worst-off language. The hero's second button.
  4. Variants and costs: the paper's main table, read column by column.
  5. Data mixing: why weights from a training run drift.
  6. Leverage scores: how unique each domain is.
  7. From scores to a mixture: Chameleon's weights on SlimPajama.
  8. New data: reuse the proxy on the Pile and for fine-tuning.
  9. Where they meet: the two choices multiply.
  10. Field guide: numbers, code, links and the credit.
Why can more training compute not repair a poor tokenizer or a poor data mix?

Chapter 1

BPE, From Zero

Build a tokenizer that merges the most frequent pair of tokens, again and again

Every text, in any language, is a sequence of bytes: integers from 0 to 255. A tokenizer that starts from bytes never meets an unknown character.

Byte Pair Encoding (BPE) learns a list of merges. A merge is an ordered pair of tokens that becomes one new token. To apply a merge, replace every adjacent copy of the pair with the new token. Each replacement makes the sequence one token shorter.

Learning is a loop. Count every adjacent pair over the whole corpus. Take the most frequent pair, add it to the vocabulary, and apply it everywhere. Repeat K times. To encode new text later, apply the K merges in the same order.

The paper's own example: the merges (b, a) then (ba, b), on the text "babab". It starts as five tokens, b a b a b. The first merge gives ba ba b. The second gives ba bab. Step it yourself below.

Merge the most frequent pair

The bars count each adjacent pair. Press Merge to fuse the top pair everywhere. Pick another text to start again.

"babab" is the paper's Example 3.1; for it the device applies the paper's two merges, (b, a) then (ba, b). The other texts take the top pair, with ties going to the pair seen first. Spaces split words, a simple stand-in for pre-tokenization: no merge crosses a space, and spaces are not counted in CR.

How much did the tokenizer shrink the text? Call a text b, its length in some unit u (bytes, characters or lines) |b|u, and the tokenizer τ. The tokens it makes for b are τ(b), and their count is |τ(b)|.

Say it aloud

C-R of b under tau equals the length of b in units u, divided by the number of tokens in tau of b.

CR(b; τ)
C-R of b under tau the compression rate: units of text packed into each token. Higher is better.
|b|u
the length of b in units u how long the text is, counted in bytes, characters or lines.
|τ(b)|
the number of tokens in tau of b how many tokens the tokenizer τ makes from b.
In plain words

Tokenize the text b with τ. Count the tokens. Divide the length of b by that count. The result is CR.

With numbers

"babab" is 5 bytes. Before any merge it is 5 tokens, so CR = 5 / 5 = 1.0. After two merges it is 2 tokens, so CR = 5 / 2 = 2.5. Two merges packed 2.5 bytes into each token.

For a whole corpus, add all the lengths and divide by all the token counts. So long documents weigh more than short ones. Classical BPE picks the K merges that make this one corpus-wide CR as large as it can, one greedy step at a time.

pythondef learn_bpe(corpus, K):              # corpus: list of token lists (start: bytes)
    merges = []
    for _ in range(K):
        counts = count_pairs(corpus)         # every adjacent pair, over ALL text
        best = max(counts, key=counts.get)    # the most frequent pair
        merges.append(best)
        corpus = [apply_merge(doc, best) for doc in corpus]
    return merges                         # encoding = apply merges in this order

The count line runs over all the text at once. If one language holds 64% of the text, its pairs win most of the votes.

Failure. A small language's text tokenizes at close to one token per byte. Measure: per-language CR on held-out text. Fix: Chapter 3 changes which text casts the votes.

Classical BPE maximizes one compression rate over the pooled corpus. What does that ignore?

Chapter 2

Measuring Unfairness: The Gini Coefficient

Turn the token cost of every language into one number that says how unequal the costs are

To compare languages, you need a fair ruler. Bytes fail: a Latin letter is 1 byte in UTF-8, and a Chinese character is 3. Words fail too: some languages put no spaces between words.

With made-up numbers: an English sentence has 20 characters, so 20 bytes. Its Chinese translation has 10 characters, so 30 bytes. In bytes, the same content looks 1.5 times longer.

The paper uses a parallel corpus, FLORES+: the same sentences, translated by people into each language. Every line holds the same content. So the cost of a language is the number of tokens per line. A gap in cost then comes from the tokenizer, not from the script.

Now turn many costs into one number. The paper borrows the Gini coefficient from economics, where it measures how unequal incomes are. Call the number of languages n. Sort the costs cheapest first and call them c1 to cn; i is a language's place in that order.

Say it aloud

Gini of T equals one over n, times: n plus one, minus two times the sum over i of n plus one minus i, times c-i, divided by the sum over i of c-i.

Gini(T)
Gini of T how unequal the token costs of tokenizer T are. 0 means all languages cost the same.
1/n
one over n n is the number of languages; 30 in the paper's main test.
Σi
the sum over i add one term for each language, from i = 1 to n.
(n + 1 − i)
n plus one minus i the weight: n for the cheapest language, 1 for the most costly.
ci
c-i the cost of the language in place i: tokens per line of the parallel corpus.
Σi ci
the sum over i of c-i the total cost of all languages.
In plain words

Sort the costs c-i cheapest first. Give the cheapest the weight n, the next n − 1, down to 1 for the most costly. Add weight times cost and divide by the total cost. Double it, take it from n + 1, and divide by n.

With numbers

With made-up costs 2, 3 and 7 (n = 3): the total is 12. The weighted sum is 3 × 2 + 2 × 3 + 1 × 7 = 19. Gini = (1/3) × (4 − 2 × 19 / 12) = (1/3) × 0.833 = 0.278. The most costly language pays 3.5 times the cheapest.

Equal costs, such as 5, 5, 5 and 5, give exactly 0. If one of four languages carries all the cost, the formula gives 0.75. Its largest value is (n − 1) / n, which nears 1 as n grows.

Spread the costs apart

Left: five languages' token costs. Right: the Lorenz curve, the running share of total cost as you add languages cheapest first. Gini is twice the area between it and the diagonal. Drag the spread, then turn off sorting.

35

Five toy costs. The two marks on the scale are the paper's measured values on 30 languages (Table 1): 0.064 for Classical BPE and 0.007 for Parity-aware BPE.

Failure. Your fairness report shows a negative Gini. Measure: check the order of the costs. Fix: sort them cheapest first. The costs 7, 2, 3 left unsorted give (1/3) × (4 − 2 × 28 / 12) = −0.222, a number with no meaning.

Why does the paper measure each language's cost on a parallel corpus?

Chapter 3

The Fair-Max Rule

Change one step of BPE so that each merge goes to the language that is worst off

Classical BPE asks: which merge saves the most tokens over all the text? Parity-aware BPE asks: which merge helps the language that is worst off right now? It aims to make the smallest per-language compression rate as large as it can. The paper calls this a fair-max objective.

The loop keeps its shape. Only the pair count changes. At each step, find the worst-compressed language. Count pairs only in that language's training text. Then apply the chosen merge to every language.

Which language is worst off at step k? Call the set of languages ℒ. Call the tokenizer made from the merges so far τm<k. Call a language's compression rate under it CR(ℓ; τm<k), measured on a small parallel development set.

Say it aloud

L-star equals the arg-min, over l in script L, of C-R of l under tau m-before-k.

ℓ★
l-star the worst-off language: its text picks the next merge.
argminℓ ∈ ℒ
the arg-min over l in script L try every language l in the set ℒ; return the one with the smallest value.
CR(ℓ; ·)
C-R of l the compression rate of language l on its development lines.
τm<k
tau m-before-k the tokenizer built from the merges learned before step k.
In plain words

Tokenize each language's development text with the merges so far. Compute each language's CR. The language with the lowest CR is ℓ-star. Count pairs in ℓ-star's training text and merge the top pair everywhere.

With numbers

From the toy run after 4 merges: Alder 1.069, Brisa 1.084, Corvo 1.067, Dunya 1.051. The lowest is Dunya, so merge 5 comes from Dunya's text and lifts it to 1.098. Now Corvo, at 1.067, is lowest, so merge 6 comes from Corvo.

Step the loop one merge at a time

Pink marks the worst-off language, the one whose text picks the next merge. Press Step. Then switch to Classical and step the same budget.

The same toy as the hero. Here the development text is the training text itself; the paper uses the FLORES+ dev split.

Why apply the merge to every language? Two languages can share a piece of text, such as a common root or a number pattern. A merge found for one helps the other too. Gluing separate per-language vocabularies together would lose that.

The extra cost is one pass per merge to recompute each language's CR on the small development set. The paper writes it as O(|ℒ|) per merge; the slow part of BPE, counting pairs, stays the same. Encoding new text stays the same too, so the new tokenizer drops into any pipeline.

pythonfor _ in range(K):
    cr = {l: compression_rate(dev[l], merges) for l in langs}   # NEW
    worst = min(cr, key=cr.get)                                   # NEW: l-star
    counts = count_pairs(train[worst])                            # NEW: only l-star votes
    best = max(counts, key=counts.get)
    merges.append(best)
    for l in langs:                                               # same as before:
        train[l] = [apply_merge(d, best) for d in train[l]]     # apply to ALL

Failure. A language gets stuck. Its development set is too small, or its text is already almost one token per pre-token, so its picks stop helping. Measure: count how often the rule picks each language in recent merges. Fix: the moving window. Among the last W = 100 picks, a language may appear at most α × W / |ℒ| times. With α = 2 and 30 languages that is 6.67, so at most 6 picks in every 100 merges.

At one merge step, ℓ-star is found. Whose text picks the pair, and whose text does the merge change?

Chapter 4

Variants, and What They Cost

Read the paper's main table and find what moved, what held still and what got worse

The paper tests the base rule and four variants. All use 128,000 merges, trained on 30 languages of FineWeb2 in their natural, uneven proportions, and scored on FLORES+.

VariantWhat changesWhy
Basefair-max at every mergestrict parity
Windowcap picks per language (W = 100, α = 2)stop a stuck language
Hybridfirst half of the merges classical, second half fair-maxkeep cheap shared merges
Hybrid + windowbothboth
Ratiospick the language furthest below a target rate rℓ, as CR / rℓno parallel dev set needed

Read Table 1 one column at a time

Blue is Classical BPE; teal is each Parity-aware variant. Pick a column. The last button shows what happens with more languages.

All values from the paper: Table 1 (FineWeb2, 30 languages, 128k), Table 5 (mC4, 30 languages) and Table 6 (mC4, 60 languages).

The headline: Gini falls from 0.064 to 0.007. That is (0.064 − 0.007) / 0.064 = 0.89, an 89% cut. Global compression on FLORES+ goes from 0.0275 to 0.0276 lines per token: no loss. Vocabulary use, the share of the vocabulary that appears in the test text, rises from 67.0% to 70.4%.

One column moves the wrong way. Fertility, the average number of tokens per word, rises from 3.990 to 4.080, a 2.3% cost. Merges spent on small languages are merges the big languages do not get.

The gain shrinks as you add languages. On mC4 with 30 languages, Gini falls from 0.067 to 0.027 (60%). With 60 languages, it falls from 0.144 to 0.083 (42%). More languages share the same budget, so each gets fewer turns.

Does fairness cost accuracy? The authors trained 3-billion-parameter models on 100 billion tokens and tested 22 languages on 12 benchmarks. With the hybrid tokenizer, 14 languages went up and 6 went down, mostly within the error bars. Persian fell from 42.80 to 39.15. Bengali stayed at chance (23.54 against 25.00) with every tokenizer.

Failure. The ratios variant cuts Gini only to 0.040. Its targets come from FLORES+ byte counts, but its pair counts come from FineWeb2, whose text differs by language. Measure: Gini on a parallel set after training. Fix: use a small parallel dev set; in the paper, 100 lines already gave 0.014.

Why does the ratios variant lower Gini the least?

Chapter 5

Data Mixing as a Choice

See how small proxy models pick domain weights, and why their answer drifts

Now the second choice. You have k domains, D1 to Dk. You need one weight per domain, each at least 0, all adding to 1. A set of such weights is a point on the probability simplex. Weight 0.25 on Wikipedia means a quarter of the training batches come from Wikipedia.

Early models picked weights by hand, favouring text that looked good, such as Wikipedia. The Chameleon paper's verdict: "neither optimal nor scalable." Newer methods train a small, cheap proxy model, read weights from it, and train the large base model with those weights. Weights found on a small model tend to help a larger one.

MethodWhere the weights come fromWhen a domain is added
DoReMia reference model and a proxy; weights favour domains where the proxy trails the referenceretrain both
DoGEone gradient per domain at every proxy step: 1.7× the time per step at 7 domains, 2.5× at 17retrain
Chameleonthe proxy's embeddings of each domain’s textembed the new domain

DoReMi and DoGE read their weights from the proxy's training run: its losses, or its gradients. That makes the weights depend on when you stop. Chameleon trains its proxy for 2,000 steps; the paper trains the others' proxies for 10,000.

Stop the proxy early

Each bar is one SlimPajama domain's weight. The grey tick is the equal weight, 1/7. Pick a method and slide the proxy's training steps.

1k

All weights from the Chameleon paper, Table 14 (82M proxy on SlimPajama at 1k, 2k, 5k and 10k steps).

Read the Arxiv domain. DoReMi gives it 0.251 at 1,000 steps and 0.057 at 10,000: (0.251 − 0.057) / 0.251 = 77% lower. Chameleon gives it 0.088 and then 0.096, a change of 9%. Stopping DoReMi early would hand you a different mixture.

Failure. You stop a proxy early to save compute, and the base model trains on a mix that the full run would not pick. Measure: compute the weights at two checkpoints and compare. Fix: train until the weights settle, or use a method whose weights do not come from the training trace.

Why must DoReMi and DoGE retrain when a new domain arrives?

Chapter 6

Leverage Scores: How Unique Is a Domain?

Embed each domain, compare the embeddings, and score how hard each one is to rebuild from the rest

Chameleon asks what the data is, not how hard the proxy finds it. Step one turns each domain into one vector. Run a batch of the domain's examples through the proxy and average their hidden vectors. Call the domain Di, one example a, and the proxy's layer-L vector for that example h(L)(a).

Say it aloud

X-i equals one over the size of D-i, times the sum over a in D-i of h-L of a.

xi
x-i the embedding of domain i: one vector of length p (768 for the paper's 82M proxy).
1/|Di|
one over the size of D-i divide by the number of examples; the paper uses 4,000 per domain.
Σa ∈ Di
the sum over a in D-i add one vector for each example a of the domain.
h(L)(a)
h-L of a the proxy's hidden vector for example a at layer L.
In plain words

Feed each example a of domain D-i through the proxy. Take its layer-L vector h-L of a. Average all of them. The average is x-i.

With numbers

With made-up 2-number vectors: two examples give [1, 0] and [0.6, 0.4]. Their average is x-i = [0.8, 0.2]. A real x-i has 768 numbers.

Step two compares every pair of domains with a dot product. The k-by-k table of these is the domain affinity matrix Ω. The paper keeps this simple linear kernel, "as the LM itself already introduces significant non-linearity."

Step three scores each domain. Call the number of domains k, a small positive number that steadies the result λ, and the k-by-k identity matrix I. The score is a kernel ridge leverage score (KRLS).

Say it aloud

S-lambda of D-i equals the i-i entry of omega times the inverse of, omega plus k lambda I.

Sλ(Di)
S-lambda of D-i the leverage score of domain i, between 0 and 1. High means unique.
Ω
omega the affinity matrix: entry i, j is the dot product of x-i and x-j.
kλI
k lambda I adds k times λ to each diagonal entry. It keeps the inverse stable.
( · )−1
the inverse of the matrix that undoes this one.
[ · ]ii
the i-i entry row i, column i of the result.
In plain words

Build Ω from the dot products. Add k-lambda to its diagonal and invert. Multiply Ω by that inverse. Domain i's score is the i-th number on the diagonal.

With numbers

Take k = 2 and λ = 0.5, so kλ = 1. Two independent domains, [1, 0] and [0, 1], give Ω = I and a score of 1/2 each. Two identical domains, [1, 0] and [1, 0], give 1/3 each. Add a third, unique domain [0, 1] (now kλ = 1.5): the identical pair falls to 0.286 each and the unique one scores 0.400.

Drag the domains

Left: three domain embeddings as arrows. Drag a tip. Right: each domain's leverage score. Bring two arrows together and watch both scores drop.

0.5

Toy embeddings with 2 numbers each; real ones have 768. The formula is the paper's Definition 3.1.

A high score means the other vectors cannot rebuild this domain's vector well: it is unique. A low score means the others already cover it. Computing it costs one matrix inverse of size k, and k is the number of domains, not documents.

Failure. Two domains hold the same text under two names. Both score low, and pretraining upweights low scores (next chapter). In the toy above, the pair gets 0.42 + 0.42 = 84% of the mix. Measure: look for off-diagonal entries of Ω close to the diagonal ones. Fix: merge duplicate domains before you score.

A domain's embedding sits almost on the line between two other domains' embeddings. What is its leverage score like?

Chapter 7

From Scores to a Mixture

Invert the score for pretraining, keep it for fine-tuning, and test the weights on SlimPajama

Pretraining and fine-tuning want opposite things. A base model needs broad, shared knowledge. Fine-tuning needs what the base model has not seen. So Chameleon uses one score two ways.

For pretraining, take the inverse of each domain's score, Sλ−1(Di), which is large for well-covered domains. Turn these into weights with a softmax: exponentiate and divide by the total. A temperature τmix sets how sharp the weights are.

Say it aloud

Alpha-i P-T equals e to the power of: one over S-lambda of D-i, divided by tau-mix; all divided by the sum over j of the same term for D-j.

αiPT
alpha-i P-T domain i's pretraining weight: its share of training batches.
exp
e to the power of always positive, and it keeps the order of the scores.
Sλ−1(Di)
one over S-lambda of D-i the inverse leverage score: large for well-covered domains.
τmix
tau-mix the temperature. Large values flatten the weights; the paper uses 5 to 10 for pretraining.
Σj …
the sum over j the same term for every domain j, so the weights add to 1.
In plain words

Invert each score S-lambda. Divide by tau-mix. Exponentiate. Divide each result by the total. The shares are the weights alpha-i. For fine-tuning, use S-lambda itself in place of its inverse.

With numbers

Use the scores of the pair and the loner from Chapter 6: 0.286, 0.286, 0.400. The inverses are 3.5, 3.5, 2.5. With tau-mix = 1 the weights are 0.42, 0.42, 0.16. With tau-mix = 5 they are 0.355, 0.355, 0.290: the same order, flatter.

Why invert? The inverse score is proportional to the Christoffel function, a standard measure of how dense the data is near a point. Dense regions hold the knowledge most domains share, which a base model needs most.

Check the weights on SlimPajama

Grey is Uniform, blue is DoReMi and DoGE (lighter), teal is Chameleon. Switch between the weights, the test perplexity they give a 684M model, and what each method cost.

All values from the Chameleon paper: Table 12 (weights), Table 2 (perplexity of 684M models) and Table 13 (H100 GPU-hours).

The paper's numbers: C4 gets 0.247, which is 1.73 times the equal share of 0.143. Wikipedia gets 0.073, half the equal share. The two broad web domains, CC and C4, take 0.449 together. Average perplexity falls from 24.20 (Uniform) to 22.31, a 7.8% drop, level with DoGE (22.32). The weights cost 0.8 GPU-hours, against 7.4 for DoReMi, 6.3 for DoGE and 56 for training the model: 1.4%.

The weights also scale up. With a 1.2B model, average perplexity falls from 16.86 to 15.03. Accuracy on 13 tasks rises from 40.5 to 41.5, the best of the methods tested.

Failure. The average improves while a domain you care about gets worse: Wikipedia goes from 12.42 to 13.90. Measure: per-domain perplexity, not only the average; Chameleon beats Uniform on 4 of 7 domains. Fix: if that domain matters, raise its weight by hand, or add a fine-tuning stage that uses the direct score.

For pretraining, Chameleon upweights domains with a low leverage score. Why?

Chapter 8

New Data Without Retraining

Reuse the same proxy on a new dataset and on fine-tuning sets, and count the compute saved

Data changes during a project. A new source arrives, or you split a domain in two. A method that reads weights from a training run must run again. Chameleon's proxy only embeds text, so a new domain needs only a forward pass over its samples.

The paper's test: take the proxy trained on SlimPajama and point it at the Pile. Of the Pile's original 22 domains, 17 are still available. Chameleon embeds 4,000 samples per Pile domain and recomputes the scores. DoReMi, DoGE and RegMix need new proxies. RegMix is a method that trains many tiny models on random mixes and fits a regression to pick the best mix for a target task.

Move to new data

Pick a test. On the Pile, the top bars are the extra compute on a log scale; the bottom bars are test perplexity. For fine-tuning, each row is one language.

All values from the Chameleon paper: Table 7 (the Pile, 684M models; Human is the Pile's hand-set mix), Table 9 (Wiki40b) and Table 10 (the Stack).

The extra compute: 4.62 × 1015 FLOPs for Chameleon, against 1.34 × 1018 for DoReMi. That is 1.34 × 1018 / 4.62 × 1015 = 290 times less. RegMix needs 758 times more. Average perplexity: 19.94 for Chameleon, 23.05 for the Pile's hand-set mix, a 13.5% drop.

Fine-tuning flips the sign: use the score itself, so unique domains get more weight. The paper fine-tunes the Pile-trained model for 10,000 steps. On 7 languages of Wiki40b, average perplexity falls from 9.43 to 8.58. On 7 programming languages of the Stack, it falls from 22.02 to 17.18. Every domain improves in both sets. Using the inverse score here does worse.

Failure. The average drops while some domains get worse. On the Pile, Chameleon beats the hand-set mix on 11 of 17 domains; PubMed abstracts go from 17.87 to 21.87. Measure: per-domain perplexity on the new data. Fix: check the domains your users need. A proxy can only embed text it can represent, so test it on a few samples of each new domain first.

Why does Chameleon's extra compute on the Pile stay tiny even though the domains grow from 7 to 17?

Chapter 9

Where the Two Choices Meet

Multiply the tokenizer's exchange rate by the mixture's share to get what the model reads

Neither paper cites the other, but both act on the same training run. The mixture decides how many tokens a language gets. The tokenizer decides how much text each token carries. So the text a model reads in a language is the product of the two.

Call the language's mixture weight αℓ, the total training budget in tokens N, and its compression rate under the tokenizer CR(ℓ; τ), in characters per token.

Say it aloud

Text-l equals alpha-l times N times C-R of l under tau.

textℓ
text-l how many characters of language l the model reads in training.
αℓ
alpha-l the language's share of training tokens, set by the mixture.
N
N the total training budget, in tokens.
CR(ℓ; τ)
C-R of l under tau characters per token for language l, set by the tokenizer.
In plain words

Multiply the budget N by the share alpha-l to get the tokens the language gets. Multiply by CR to turn tokens into characters. If either factor is small, the product is small.

With numbers

With the toy: N = 100 billion tokens and Dunya's share alpha = 0.04 give 4 billion tokens. Under Classical BPE, Dunya's CR is 1.00, so the model reads 4 billion characters. Under Parity-aware BPE it is 2.16, so 8.64 billion. Same share, 2.16 times the text.

Turn both knobs

Bars show billions of characters read in a 100-billion-token run, for big Alder and small Dunya. Slide Dunya's share and switch the tokenizer.

4%

Toy CR values from the hero after 80 merges. Alder takes whatever share Dunya does not, out of 68% (the toy's other two languages keep 32%).

A caveat. The two papers split data on different axes. Parity-aware BPE splits by language; Chameleon's SlimPajama test splits by source, mostly English. Neither ran the joint experiment, so the product above is logic, not a measured result. One more open question: Chameleon's proxy tokenizes its input too. An unfair tokenizer might distort the domain embeddings. Neither paper tests this.

The order is fixed. Learn the tokenizer first. Then train the proxy on tokenized text and compute the weights. Then start the base run, which uses both.

Failure. A language stays weak after both fixes, like Bengali at chance. Measure: estimate text-ℓ, not only its weight or its token cost. Fix: raise whichever factor is small.

A language gets 2% of a 50-billion-token run. Classical BPE gives it half the CR that Parity-aware BPE would. How much text does it see under Classical BPE?

Chapter 10

Field Guide

Keep the terms, the numbers, the code and the open questions in one place

Two choices sit upstream of every pretraining run. Parity-aware BPE changes who votes on each merge, and cuts the Gini of token costs by 89% with no loss in compression. Chameleon scores how unique each domain is from a proxy's embeddings. It gets a strong mix for 1.4% of the training compute and needs no retraining when data changes.

TermMeaningNumber to remember
Compression rate (CR)units of text per token"babab": 1.0, then 2.5 after two merges
Gini coefficientinequality of per-language token cost0.064 to 0.007 (89% lower)
Fair-maxeach merge serves the worst-off languageextra cost: O(|ℒ|) per merge
Moving windowcap on picks per languageW = 100, α = 2: 6 of 100 for 30 languages
Fertilitytokens per word3.990 to 4.080 (2.3% worse)
Proxy modelsmall model used to pick weights82M, 2,000 steps
KRLShow hard a domain is to rebuild from the otherspair 0.286, loner 0.400
αPT, αFTsoftmax of the inverse score, or of the scoreτmix 5 to 10 (PT), 0.2 to 0.5 (FT)
Cost of the weightsGPU-hours to get the mix0.8 vs 7.4 (DoReMi), 6.3 (DoGE); model 56
Transfer to the Pilereuse the proxy on new domains290× less compute than DoReMi

Checklist

  1. Measure per-language tokens per line on a parallel set before you train. Sort costs before you compute Gini.
  2. If you have a parallel dev set, use fair-max with the moving window. If not, use target ratios and expect a smaller gain.
  3. Expect less gain per language as the number of languages grows.
  4. Pick domain weights with a method that survives new data. Merge duplicate domains first.
  5. Use the inverse score for pretraining and the score itself for fine-tuning.
  6. Read per-domain results, not only averages.
  7. Estimate the text each language gets: share times budget times CR.
pythonimport numpy as np

def gini(costs):                                  # tokens per parallel line, one per language
    c = np.sort(np.asarray(costs, float)); n = len(c)    # sort first!
    w = np.arange(n, 0, -1)                         # n, n-1, ..., 1
    return (n + 1 - 2 * (w @ c) / c.sum()) / n

def chameleon_weights(X, lam=0.5, tau=1.0, phase="pretrain"):
    k = X.shape[0]                                # X: (k domains, p dims), mean hidden states
    omega = X @ X.T                                # (k, k) affinity matrix
    S = np.diag(omega @ np.linalg.inv(omega + k * lam * np.eye(k)))  # KRLS
    z = (1 / S if phase == "pretrain" else S) / tau
    e = np.exp(z - z.max())
    return e / e.sum()

print(gini([2, 3, 7]))                                        # 0.278
print(chameleon_weights(np.array([[1., 0], [1, 0], [0, 1]])))   # [0.42 0.42 0.16]

What the authors leave open

The Parity-aware BPE authors say that their fairness counts tokens only. They tested up to 60 languages and two vocabulary sizes, and call for larger models, more languages, code and other modalities. BPE also cannot compress past the pre-tokenized length, so some gap remains. The Chameleon authors plan an online version that updates weights during training, and a version aimed at a chosen task.

Keep going

Credit: Session 1 of Georgia Tech CS 8803, LLM seminar. Papers: Parity-Aware Byte-Pair Encoding (Foroutan et al., arXiv 2508.04796) and Chameleon (Xie, Tonin and Cevher, ICML 2025, arXiv 2505.24844). The toy languages and all made-up numbers are ours.

The takeaway. The tokenizer sets the exchange rate from tokens to text. The mixture sets how many tokens each domain gets. Fix both before training, and measure each language by the text it actually reads.

Teach it back: open Present or Teach and explain the fair-max rule and the leverage score to a friend. Then go back to the merge budget and predict the Gini before you press Play.

CS 8803 LLM Seminar, Session 01: Tokenizer Fairness and Data Mixing
Parity-aware BPE paper · Chameleon paper · Back to Gleams