Concept - Underflow

Definition

“Every computer has a limit to how close a number can get to 0 before it can no longer accurately keep track of that number. When a number gets smaller than that limit, we run into Underflow problems and errors occur.” (s.209-210)

Why it matters

Multiplying a prior by many small likelihoods (e.g. ) gives extremely small numbers (s.206). Remedy: “take the log() of everything to prevent … Underflow” (s.207).

Added context

Taking logs turns the product into a sum of logs, which stays in a representable range; the slides in this chunk only state the remedy, not the calculation.

Concept - Likelihood, Concept - Gaussian Naive Bayes

Source chunk: 03 Text Classification - Chunk 07 (s.181-210)

The log trick worked through (s.211-222, s.231-236)

  • Any log works; the natural log (base ) is most common in statistics and machine learning (s.211).
  • Take the log of the whole score; the log turns the multiplication into a sum of individual logs (s.212-214): .
  • Loves Troll 2: (s.215-221). The tiny number only becomes -115, which is easily representable.
  • Does Not Love Troll 2: (-47.66) (s.235-236, s.238).
  • Compare log scores: the larger (less negative) wins, so -48 beats -124 (s.237).

Source chunk: 03 Text Classification - Chunk 08 (s.211-240)

Seen in 03 Text Classification - Chunk 04 (s.91-120)

  • Even a 5-word message gives a tiny normal score: (s.106). Longer messages shrink further, which is why implementations use log-probabilities. (Not stated on s.91-120; this link is added context.)