log⁡\log

Logarithm

Read "log of x". It undoes the exponential: log(eᶻ) = z. It turns products into sums, which is why loss functions use it.

log⁡(ab)=log⁡a+log⁡b\log(ab) = \log a + \log b. A sentence's probability is a product of hundreds of small numbers. Multiplied directly in floating point, the result gets so small it rounds to zero (called underflow). Taking the log turns the product into a sum of moderate negative numbers, which computers handle easily.

ln⁡\ln is the natural log, the log to base ee. In machine learning, log⁡\log almost always means ln⁡\ln as well. A probability is at most 1, so its log is zero or negative. That is why losses put a minus sign in front: it makes the loss a positive number to minimize.

Example

log⁡(0.5×0.1)=log⁡0.5+log⁡0.1≈−0.69+(−2.30)≈−3.00\log(0.5 \times 0.1) = \log 0.5 + \log 0.1 \approx -0.69 + (-2.30) \approx -3.00

Natural log. A product of probabilities becomes a sum of their logs.

Where the course uses it

Related terms