TF-IDF and term rarity 00:00:01 A rare mark in the rail archive I'm searching a thousand-doc archive and need to know which term cuts the results more: rail or glissando? The first thing I check is how often each appears across the whole collection. Rail shows up in half the documents—five hundred—while glissando appears in just five, making it far less common across the entire set. Since glissando appears in only five documents, it should narrow the search more than rail, which is in half the archive. A word can carry different evidence in different collections. Five documents mentioning a musical term is unusual in a transport archive; the same word could be routine in a conservatory catalogue. 00:00:38 Count documents separately from mentions Document frequency counts each document only once, even if the term repeats many times inside it. Term frequency counts how many times a word appears within a single document, not how many documents contain it. Even if rail appears ten times in one document, it still only counts as one document in the frequency tally. Count unique matching documents for document frequency, and per-document occurrences for term frequency. If both are called frequency without naming the denominator, a scoring change can look like an indexing error. 00:01:09 Compute the rarity weights With the unsmoothed inverse document frequency in this exercise, rail has the natural logarithm of one thousand divided by five hundred. That is the natural logarithm of two, about zero point six nine. For glissando, divide one thousand by five, then take the natural logarithm of two hundred. Its weight is about five point three zero. These values come from the unsmoothed natural log formula, a baseline for comparing term rarity. Write the ratio before taking its logarithm. A thousand divided by five is two hundred; a thousand divided by five hundred is just two. The logarithm compresses that enormous raw ratio while preserving the rarity order. 00:01:50 Combine evidence for one candidate If both terms appear once in a document, glissando’s higher IDF gives it a much stronger weight in the score. If this exercise uses raw term frequency, ten rail mentions can outweigh one glissando mention. That conclusion would need checking again under logarithmic or saturated term frequency. To compare fairly, both scores must use the same smoothing and log base throughout the system. Under raw term frequency times these IDF values, ten mentions of rail contribute about six point nine and one mention of glissando contributes about five point three. Other scoring variants saturate repeated terms, so the comparison must name the formula. 00:02:28 A rare typo can dominate Glissando is a legitimate musical term. A separate rare typo could receive a similarly high rarity weight despite being useless to the person searching. Rarity alone cannot distinguish those cases. We must check real user queries and whether exact matches are needed to avoid false relevance. The final score should reflect real relevance, not just how rare a term is—use human judgment to filter nonsense. Keep retrieval and usefulness separate. A rare exact string can pinpoint a technical document or merely preserve an accidental spelling. Check actual judgments on held-out queries before treating rarity as relevance.