Ran Wei/ Maths for AI and LLMs
中文
Maths for AI and LLMs · Reference

Common mistakes

Diagnose errors in probability, evaluation, optimisation and finite arithmetic.

1

Probability and evaluation

  • Reverse the condition without recomputing the denominator. In Module 1, P(A∣S)=3/5P(A\mid S)=3/5 while P(S∣A)=1/2.P(S\mid A)=1/2\mathclose{\text{.}} Compute the marginal of the observed event.
  • Omit the stop token from an exact sequence probability. A prefix of probability 3/203/20 is a completed sequence of probability 1/101/10 when the stop factor is 2/3.2/3\mathclose{\text{.}}
  • Randomly split related paragraphs across training and test. A document can supply similar material to both sets. Group by document before splitting. See Module 2.
  • Treat tokens in the same document as independent replicates. Such a count can overstate how much evidence you have. Choose sampling units and weights that match the estimand.
2

Information and decoding

  • Average an unweighted list of vocabulary log probabilities. Cross-entropy weights log probabilities by the data distribution. An observed single target contributes its own negative log probability.
  • Average document perplexities to get corpus perplexity. Add the losses on the log scale and divide by the number of scored tokens before exponentiating. See Module 4.
  • Score the original model with a sampled distribution after top-k truncation. Report which distribution you score. The discarded tokens can have zero probability under the sampling rule.
3

Updates and finite precision

  • Use the smallest eigenvalue to choose a stable quadratic step. Every direction must be stable. See Module 5.
  • Treat Adam’s squared-gradient average as a variance. It is a raw second moment and has no subtraction of a mean square.
  • Exponentiate large logits and then take a logarithm. Use the shifted expression from Module 7 and keep the result on the log scale when you need a loss.
  • Apply a half-step quantisation bound after clipping. With scale 1/41/4 and largest reconstruction 3/4,3/4\mathclose{\text{,}} a value of 1.201.20 has error 0.45,0.45\mathclose{\text{,}} which exceeds half a step.