Skip to content
AI360Xpert
Glossary
Definition

Logarithm

The inverse of exponentiation: the power a base must be raised to in order to produce a given number.

logbx\log_b x is the exponent that turns bb into xx: since 23=82^3 = 8, log28=3\log_2 8 = 3. In machine learning log\log with no base written means the natural log, base ee, and that convention is worth stating out loud because base 2 appears constantly in information theory. Base 2 gives bits, base ee gives nats, and the conversion factor is ln20.693\ln 2 \approx 0.693.

Three properties are why it appears in nearly every loss function. It turns products into sums, log(ab)=loga+logb\log(ab) = \log a + \log b, which converts a product of thousands of per-example probabilities into a sum that a computer can actually represent. It is monotonically increasing, so whatever maximises a likelihood also maximises its log — the transformation is free. And it stretches the region near zero, so the difference between a predicted probability of 0.01 and 0.001 becomes a difference of 2.3 rather than 0.009, which is what gives a confidently wrong prediction a large gradient.

The catch is log0=\log 0 = -\infty. Any probability that underflows to exactly zero produces an infinite loss or a nan, which is why stable implementations work in log space from the start rather than exponentiating and taking a log at the end.