Example sampling is not token weighting
Specify task proportions together with target lengths and loss normalization before calling a mixture balanced.
On this page
The question for today
What you’ll understand
- Distinguish task sampling probability from supervised-token contribution.
- Calculate effective weighting for unequal response lengths.
- Evaluate mixture changes against held-out task and retention objectives.
An instruction dataset can contain equal numbers of two tasks while one supplies most of the supervised tokens. A token-mean objective then gives that task more loss mass, even before examples differ in difficulty. Mixture design therefore includes sampling, selected target length, normalization, and training duration. Define what balanced means for the intended product and evaluation rather than using row percentages as a complete description of the optimization objective.
Choose the unit whose weight you intend to control
Task probabilities can govern which example is sampled, which conversation is sampled, or which token contributes to a loss. Those are different objectives. Equal-example means weight a short answer and a long answer equally after their internal normalization;global token means give more mass to examples with more selected targets. Padding and masked prompt tokens do not belong in a target-token count. Track effective counts after formatting and truncation, not only the original dataset's row table.
A large dataset can dominate without explicit resampling, while oversampling a small dataset repeats its few examples more often. That can help coverage or amplify artifacts and memorization. Task labels may also hide source clusters, language differences, and response-format styles. Keep provenance and group-aware splits alongside the mixture. A mixture change is a new training intervention that needs controlled comparison, rather than a harmless input shuffle assumed to improve every task.
Sampling and loss weights are separate levers
One can sample tasks at chosen rates and also apply explicit per-task loss weights. Document both, and verify that trainer reductions do not accidentally undo the intended scheme. Averaging local batch means with unequal target counts can change weights again. If curriculum or temperature-based sampling varies over training, the final model has seen a time-dependent mixture;report exposures and steps by stage rather than one nominal starting ratio.
The best mixture depends on held-out use cases and capability-retention requirements. A domain-specific instruction corpus may improve its target format while harming general tasks or changing refusal and verbosity behavior. Evaluate subgroups and failure severity, not merely a grand average that lets one easy task mask another's regression. Keep validation for mixture selection and avoid repeatedly using the final test to pick the weights. No algebraic balancing rule guarantees downstream quality.
Audit effective exposure before explaining a result
Record sampled examples, unique source groups, selected target tokens, and optimizer steps for every task. Compare those realized values with the planned mixture and inspect records that were truncated or rejected. A long-answer task can lose target tokens disproportionately at a context limit, changing its effective weight. Repeated examples do not create independent evidence of generalization. Use multiple seeds or justified uncertainty estimates when claiming a small benefit from a mixture change.
The probability lab models task sampling only. Reset and set both p=0.5, n=20, predict ten selections of a named task on average, then inspect. Reset and re-set p=0.8, n=20 to predict sixteen. Its independent Bernoulli draws contain no response lengths, loss weights, or training dynamics. Play highlights possible counts rather than sampling an actual dataset. Explain why equal task-selection counts in this diagram cannot establish equal supervised-token contribution or equal learning progress.
Work it through
Equal examples, unequal token mass
A batch collection contains 100 task-A examples with ten selected targets each and 100 task-B examples with one hundred each. Use a global token-mean loss with no extra weights and fixed declared lengths.
Task A supplies 100×10=1000 targets;task B supplies 100×100=10,000. Total selected targets are 11,000 despite equal example counts.
B contributes 10,000/11,000≈90.91% of token mass. That fraction does not include differences in per-token loss or gradient direction, but it already shows unequal target weighting.
To equalize target counts under these fixed lengths using sampling alone, ten A examples are needed per B example. Whether that repeated exposure improves quality is an evaluation question;an equal-example objective or explicit task weights would define other interventions.
A mixture must state its units. Row balance, token balance, and desired task performance are not interchangeable.
The living notebook
Explore the model
Interactive lab · probability
Sampling proportions omit response length
Reset, set p=0.5, n=20, predict mean 10 task selections. Reset and re-set p=0.8, n=20, predict 16. Exact iid binomial counts do not include token lengths, loss weights, or adaptation quality.
- Mean · np
- 5
- Variance · np(1−p)
- 2.5
- Total probability
- 1
These are exact binomial probabilities for independent trials with one fixed success probability. Playback tours the distribution; it does not resample outcomes. Parameter changes pause playback and recompute the model at the current elapsed time. Reset restores both parameters and returns time to zero. Playback starts paused. Adjust either parameter, then choose Play or Step.
Look forMeasure realized supervised tokens and normalization alongside example-sampling probabilities.
Pause & reason
Check your understanding
Your turn
Try it yourself
A task is selected with probability 0.25 and averages forty targets;another has probability 0.75 and averages twenty. Estimate the first task's long-run token-mass fraction, and state the normalization assumption.
Take a moment to make a prediction or work it out on paper. Open a hint when you need one.
Give me a hint
Compare 0.25×40 with 0.75×20 before dividing.
Compare with the solution
The contributions are ten and fifteen expected targets per draw, so the first task has 10/25=40% of token mass. This assumes stable lengths and a global token-mean objective without extra weights. Equal-example averaging, changing truncation, or different distributed reductions can produce another effective objective, and none of these weights alone guarantees task quality.
Keep the idea
Take it with you
- Sampling probabilities and target-token weights are different quantities.
- Normalization and curricula can change a mixture's effective objective.
- Choose mixtures using realized exposure and held-out task/retention evidence.
Read further
Original sources and deeper explanations to follow at your own pace.
Optional progress, saved in this browser when available. Revisit any lesson at any time.
Lesson not marked complete.