TensorTonic
Study Plans
Study Plan
Compute Temperature-Based Data Mixtures
Language ModelsData Processing
Medium

Compute sampling probabilities and expected exposure for a mixture of data sources. Let nin_ini​ be source i's token count, α\alphaα the supplied exponent, and T the training-token budget. For positive-size sources:

pi=niα∑j:nj>0njαp_i=\frac{n_i^\alpha}{\sum_{j:n_j>0} n_j^\alpha}pi​=∑j:nj​>0​njα​niα​​ ti=Tpit_i=Tp_iti​=Tpi​ ei=tini.e_i=\frac{t_i}{n_i}.ei​=ni​ti​​.

Here, pip_ipi​ is the sampling probability, tit_iti​ the expected sampled tokens, and eie_iei​ the expected passes through source i. The sum includes only positive-size sources. A zero-size source receives zero for all three values, including when the exponent is zero. If all sources are empty, return zero arrays.

Return a Python dictionary with probabilities, expected_tokens, and expected_epochs, each a float64 NumPy array of shape (N,) in source order, where N is the number of sources.

Loading visualization...

Examples

Input: token_counts = [100,400], alpha = 1, training_budget = 1000

Output: {"probabilities":[0.2,0.8],"expected_tokens":[200,800],"expected_epochs":[2,2]}

Explanation: With exponent one, sampling probability is proportional to source size.

Input: token_counts = [1,100], alpha = 0, training_budget = 20

Output: {"probabilities":[0.5,0.5],"expected_tokens":[10,10],"expected_epochs":[10,0.1]}

Input: token_counts = [0,10], alpha = 0.5, training_budget = 30

Output: {"probabilities":[0,1],"expected_tokens":[0,30],"expected_epochs":[0,3]}

Hint 1

np.log expresses power weights on a logarithmic scale.

Hint 2

Subtracting a shared log-weight offset leaves normalized probabilities unchanged.

Hint 3

np.divide supports a mask through its where argument.

Requirements

  • Use NumPy float64 arithmetic.
  • Results must remain finite for large counts and exponents.
  • Do not modify the token counts.

Constraints

  • token_counts is a list of nonnegative Python integers.
  • alpha is finite and nonnegative.
  • training_budget is a nonnegative Python integer.
  • An empty token_counts list is valid.
Try Similar Problems
Build Deterministic MinHash SignaturesMediumPerform Stable Exact DeduplicationEasyCanonicalize Pairwise Preference DataMediumTrain a BPE Tokenizer From Scratch in PythonMediumApply Ranked BPE MergesMediumParallel and Recurrent Linear AttentionMediumMamba 2 Gated State ScanMediumParameter-Matched SwiGLU BlockMediumTile and DiffMediumBox Encode and DecodeMediumDrop DuplicatesMediumFancy IndexingMedium

Accepts: array

Accepts: number

Accepts: number

You must run your code first.

Compute Temperature-Based Data Mixtures

Language ModelsData Processing
Medium

Compute sampling probabilities and expected exposure for a mixture of data sources. Let nin_ini​ be source i's token count, α\alphaα the supplied exponent, and T the training-token budget. For positive-size sources:

pi=niα∑j:nj>0njαp_i=\frac{n_i^\alpha}{\sum_{j:n_j>0} n_j^\alpha}pi​=∑j:nj​>0​njα​niα​​ ti=Tpit_i=Tp_iti​=Tpi​ ei=tini.e_i=\frac{t_i}{n_i}.ei​=ni​ti​​.

Here, pip_ipi​ is the sampling probability, tit_iti​ the expected sampled tokens, and eie_iei​ the expected passes through source i. The sum includes only positive-size sources. A zero-size source receives zero for all three values, including when the exponent is zero. If all sources are empty, return zero arrays.

Return a Python dictionary with probabilities, expected_tokens, and expected_epochs, each a float64 NumPy array of shape (N,) in source order, where N is the number of sources.

Loading visualization...

Examples

Input: token_counts = [100,400], alpha = 1, training_budget = 1000

Output: {"probabilities":[0.2,0.8],"expected_tokens":[200,800],"expected_epochs":[2,2]}

Explanation: With exponent one, sampling probability is proportional to source size.

Input: token_counts = [1,100], alpha = 0, training_budget = 20

Output: {"probabilities":[0.5,0.5],"expected_tokens":[10,10],"expected_epochs":[10,0.1]}

Input: token_counts = [0,10], alpha = 0.5, training_budget = 30

Output: {"probabilities":[0,1],"expected_tokens":[0,30],"expected_epochs":[0,3]}

Hint 1

np.log expresses power weights on a logarithmic scale.

Hint 2

Subtracting a shared log-weight offset leaves normalized probabilities unchanged.

Hint 3

np.divide supports a mask through its where argument.

Requirements

  • Use NumPy float64 arithmetic.
  • Results must remain finite for large counts and exponents.
  • Do not modify the token counts.

Constraints

  • token_counts is a list of nonnegative Python integers.
  • alpha is finite and nonnegative.
  • training_budget is a nonnegative Python integer.
  • An empty token_counts list is valid.
Try Similar Problems
Build Deterministic MinHash SignaturesMediumPerform Stable Exact DeduplicationEasyCanonicalize Pairwise Preference DataMediumTrain a BPE Tokenizer From Scratch in PythonMediumApply Ranked BPE MergesMediumParallel and Recurrent Linear AttentionMediumMamba 2 Gated State ScanMediumParameter-Matched SwiGLU BlockMediumTile and DiffMediumBox Encode and DecodeMediumDrop DuplicatesMediumFancy IndexingMedium

Accepts: array

Accepts: number

Accepts: number

You must run your code first.