Maths for AI and LLMs · Reference
Formula sheet
Keep the conditions and units beside each equation.
| Quantity |
Formula |
Conditions |
| Conditional probability |
P(A∣B)=P(A∩B)/P(B) |
P(B)>0 |
| Sequence probability |
∏i=1TP(ti∣t<i) |
Condition on the prompt if given. Include stop for a completed sequence. |
| Bayes’ rule |
P(B∣A)=P(A∣B)P(B)/P(A) |
P(A)>0 and the stated right-hand conditional is defined. |
| Bernoulli maximum-likelihood estimate |
p^=k/n |
n>0 independent trials share the same probability. |
| Estimated standard error |
s/n |
Independent observations with common distribution and n≥2. |
| Quantity |
Formula |
Conditions |
| Entropy |
H(p)=−∑ipilnpi |
Sum over positive pi. |
| Cross-entropy |
H(p,q)=−∑ipilnqi |
Average over positive pi. Infinite if any such qi is zero. |
| KL divergence |
DKL(p∣q)=H(p,q)−H(p) |
Nonnegative. Zero exactly for equal distributions. |
| Token negative log-likelihood |
ℓ=−∑ilnq(ti∣t<i)/N |
Use the same mask for the sum and count N>0. |
| Perplexity |
eℓ |
Use natural logarithms in ℓ. |
| Temperature odds |
e(zi−zj)/T |
T>0. |
| Quantity |
Formula |
Conditions |
| Mean half-squared-loss gradient |
XT(Xw−y)/n |
One example per row of X. |
| Quadratic stability |
0<η<2/λmax(H) |
Positive definite Hessian H of a quadratic loss, fixed step. |
| Mini-batch gradient covariance |
Σ/b |
b independent uniform samples with replacement, fixed parameters. |
| Log softmax |
(zj−m)−ln∑iezi−m |
m=maxizi, finite logits and nonempty input. |
| Dot-product quantisation error bound |
2s∥x∥1 |
Unchanged input x, common scale s, no clipping, exact arithmetic. |