What are logarithms and exponentials in machine learning?
The exponential function exp(x) = eˣ raises Euler's number e ≈ 2.718 to the power x, and the natural logarithm ln(x) is its inverse: ln(eˣ) = x. Exponentials turn sums into products and grow faster than any polynomial. Logarithms turn products into sums and compress huge ranges of numbers into small ones.
Both appear throughout machine learning. Softmax and sigmoid use exponentials to turn raw scores into probabilities. Cross-entropy loss, log-likelihood, KL divergence, and perplexity all use logarithms. Log scales are also standard for learning-rate searches, and models often predict log-variance or log-odds because those quantities can be any number, positive or negative.
Key ideas
- exp(x) is its own derivative, and it is always positive.
- ln(x) is the inverse of exp(x) and is defined only for x > 0.
- Logarithms turn products into sums: log(ab) = log(a) + log(b).
- Cross-entropy loss is −log of the probability assigned to the correct answer.
- Softmax exponentiates logits and normalizes them; temperature controls how sharp the result is.
- Working in log space keeps likelihoods of large datasets from underflowing to zero.
Common questions
Why is e the base used in machine learning?
Because the derivative of eˣ is eˣ and the derivative of ln(x) is 1/x, with no extra constants. Any other base adds a factor of ln(b) to every gradient. The choice does not change which parameters are optimal, only the units of the loss.
What does log loss mean?
Log loss is another name for binary cross-entropy: −[y·log(p) + (1 − y)·log(1 − p)], averaged over examples. A model that always predicts 0.5 scores ln 2 ≈ 0.693, which is a useful baseline. Lower is better, and a perfect model scores 0.
Why do models predict log-variance instead of variance?
Variance must be positive, but a network's output can be any real number. Predicting s = log σ² and using σ² = exp(s) guarantees a positive variance without a constraint. Variational autoencoders and many uncertainty models use this parameterization.
What is the relationship between sigmoid and exp?
The sigmoid is σ(x) = 1/(1 + e⁻ˣ), and it equals a two-class softmax with logits x and 0. Its inverse is the logit, ln(p/(1 − p)), the log-odds of p. Logistic regression models these log-odds as a linear function of the features.
Related explainers
- Softmax, Logits & Temperature — Turning raw scores into probabilities
- Loss Functions — How networks measure their mistakes
- Entropy & Cross-Entropy — Measuring surprise, uncertainty, and prediction quality
- MLE & MAP Estimation — Maximum likelihood and maximum a posteriori — why training works
- Derivatives — The calculus behind gradient descent
- Probability & Distributions — Spam, densities, and the math of uncertainty
References
- Goodfellow, Bengio & Courville, "Deep Learning", ch. 3 Probability and Information Theory
- Deisenroth, Faisal & Ong, "Mathematics for Machine Learning"
- Zhang et al., "Dive into Deep Learning", section 4.1 Softmax Regression
Last updated