Term Frequency › Log-Scaled Term Frequency
Language AI HandbookAll chapters Term Frequency › Log-Scaled Term FrequencyOne section · Sections in this chapter4 / 17 ↓
Reading tools Definitions & inline links
Choose your expertise level to adjust how many terms are explained. Beginners see more tooltips, experts see fewer to maintain reading flow. Hover over underlined terms for instant definitions.
Article links
Make inline references clickable
To address diminishing returns, logarithmic scaling compresses the count scale. The key insight is that each successive doubling of count should add a fixed increment of importance, not double it.
where:
- : the log-scaled term frequency weight
- : the natural logarithm (base ), though other bases work equally well since log base conversion is just a constant scale factor
- The offset ensures that a term appearing exactly once receives weight 1, making the zero-versus-nonzero distinction crisp. Without the , a term appearing once would receive weight , which would be indistinguishable from an absent term.
Some formulations instead use , which maps count 0 to 0 continuously without needing a piecewise definition. The two forms give very similar results in practice, but the piecewise version is more common in information retrieval literature because it preserves the conceptually clear distinction between "absent" (weight exactly 0) and "present once" (weight exactly 1).
The intuition behind log scaling. The log function captures diminishing returns mathematically. Moving from 0 to 1 occurrence is the most important jump: from absent to present. Moving from 1 to 10 occurrences is meaningful but less dramatic. Moving from 100 to 1000 occurrences adds barely any signal. The log function maps these ratios to equal intervals:
Each tenfold increase in count adds roughly 2.3 to the weight, rather than multiplying it by 10. This reflects how human language behaves: an author who mentions "photosynthesis" 20 times is not necessarily ten times more focused on the topic than one who mentions it twice. Both documents are clearly about photosynthesis; the high count in the first document likely reflects a longer article or a different writing style rather than ten times more relevance.
The in the log formula is not arbitrary. Without it, a term appearing exactly once has log-weight of 0, which is the same as a term that doesn't appear at all. That would mean a document mentioning "quantum" once is treated identically to a document that never mentions quantum at all, which is clearly wrong. The shift lifts all present terms above zero while still compressing the high-count range.
The choice of logarithm base does not change the relative ordering of term weights. It only rescales all weights by a constant factor (since ). In practice, natural log () is most common in implementations. Log base 2 is theoretically meaningful in information-theoretic contexts where it measures bits of information. Log base 10 gives weights that are easy to reason about in decimal terms. scikit-learn uses with natural log in its TF-IDF implementation.
When to use log TF: Log scaling is the most commonly used variant in information retrieval and is the default in most TF-IDF implementations. It's a good default choice whenever you want to weight by frequency but reduce the influence of very high counts. For most classification and retrieval tasks, log TF is a better starting point than raw TF.