Term Frequency › Worked Example
Language AI HandbookAll chapters Term Frequency › Worked ExampleOne section · Sections in this chapter8 / 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
Let's work through all five variants on a small example to build concrete intuition. Consider two documents:
- Doc A: "the cat sat on the mat the cat" (8 tokens)
- Doc B: "the dog chased the cat across the yard the dog" (10 tokens)
The vocabulary is: {across, cat, chased, dog, mat, on, sat, the, yard}
Raw counts:
| Term | Doc A | Doc B |
|---|---|---|
| across | 0 | 1 |
| cat | 2 | 1 |
| chased | 0 | 1 |
| dog | 0 | 2 |
| mat | 1 | 0 |
| on | 1 | 0 |
| sat | 1 | 0 |
| the | 3 | 4 |
| yard | 0 | 1 |
Applying each weighting scheme to the term "the":
- Raw: Doc A = 3, Doc B = 4
- Log: Doc A = , Doc B =
- Boolean: Doc A = 1, Doc B = 1 (both contain "the")
- Augmented (): In Doc A, the maximum count is 3 (for "the"), so . In Doc B, the maximum count is 4 (also "the"), so . Both get weight 1.0 since "the" is the dominant term in both.
- L2 normalization: Divide each raw count vector by its Euclidean norm before comparison.
Notice how augmented TF reveals that "the" dominates both documents equally (weight 1.0 in both), while "cat" gets weight in Doc A and in Doc B, correctly showing that "cat" is proportionally more important in Doc A.
Now let's compute the L2 norms for these two documents:
After normalization, the "cat" entry in Doc A becomes , and in Doc B it becomes . So the L2 representation also correctly reflects that "cat" plays a larger role in Doc A than in Doc B, and does so without requiring any free parameter like .
This worked example illustrates a key insight: all five variants agree qualitatively on the relative importance of terms within each document, but they differ in how much weight they assign to high-count terms like "the" versus low-count terms like "sat." The choice of variant affects the geometry of the document space, which in turn affects the behavior of any downstream classifier or retrieval system.