Compare term frequency across short passages
Read identifiers and quoted passages in short groups. · 206 words
Term frequency (TF) counts how often a term occurs in one passage. For a fair comparison, we can divide that count by the number of tokens, where a token is a whitespace-separated word. Passage A says: "The solar map shows a bright sun. A solar icon marks the north trail." It has 14 tokens and 2 occurrences of "solar," so its normalized TF is 2/14, about 0.143. Passage B says: "The shop sells a solar lantern. Its solar panel charges a phone. The manual also explains the solar switch and solar care." It has 22 tokens and 3 occurrences, so normalized TF is 3/22, about 0.136.
Raw TF tells a different story: Passage B has 3 hits, compared with 2 in Passage A. If a search engine uses raw TF, it may favor the longer passage even though Passage A has the higher density. If it uses normalized TF, it gives Passage A a slightly higher score. A grounded generator should keep this distinction visible. For the query "Which passage discusses both solar power and a phone?", it can retrieve Passage B and answer, "The solar panel charges a phone." That answer is supported by the retrieved passage rather than inferred from the word count alone.
Check your recall
Which passage has the higher raw TF for "solar," and which has the higher normalized TF?
Check your answer
Passage B has the higher raw TF, with 3 occurrences compared with 2. Passage A has the higher normalized TF: about 0.143 compared with about 0.136.
Sources and credits
Original KeyTouch lesson. Background reading · Lewis et al. · Retrieval-Augmented Generation.