TF-IDF
Weighting each word count by how rare the word is across documents, so common words stop dominating.
Term frequency times inverse document frequency: , where counts a token in one document, is the number of documents, and counts how many contain the token at all.
Read it as a rarity discount. A token frequent here and rare elsewhere scores highest. A token in every document has , so the fraction lands near 1 and the log near 0 — grammar cancels itself out, which is why stopword removal matters much less once you're using TF-IDF.
Two practical notes. L2-normalise the rows or long documents dominate every distance, and once you do the dot product between two rows is their cosine similarity. And df is counted over whatever corpus you fit on, so fitting on all your documents leaks test information into every training weight.