Before a machine-learning model can read text, every sentence must become a vector of numbers. Bag-of-Words (BoW) simply counts how many times each vocabulary word appears in a document. TF-IDF (term frequency–inverse document frequency) multiplies that raw count by a weight that falls as a word becomes more common across the whole corpus — so words that appear in nearly every document contribute almost nothing, while rare, distinctive words stand out.
ln((1+N)/(1+df)) + 1, where df is how many of the N corpus documents contain that word.N, more synthetic documents are assumed to contain common filler words ("the", "was", "and"), so their document frequency df climbs and their idf weight collapses toward the bar chart's floor.df and stay tall — TF-IDF automatically promotes exactly the words a spam filter or sentiment classifier should care about.TF-IDF was introduced by Karen Spärck Jones in 1972 as "term specificity" and remains a baseline feature representation for spam filters and search engines decades later — it needs no training and no neural network, just word counts across a corpus.
A 3D bar chart grid — one row per document, one column per vocabulary word — lets you switch between raw Bag-of-Words counts and TF-IDF weighted scores, and watch common words collapse as the simulated corpus grows.
Bag-of-Words treats every occurrence equally, so filler words like "the" tower over rare, meaning-carrying words. TF-IDF multiplies each count by an inverse-document-frequency weight, shrinking common words and boosting distinctive ones.
Toggle between Bag-of-Words and TF-IDF, pick which document to highlight, and drag the corpus-size slider to see how adding more documents pushes down the idf weight — and bar height — of common words in real time.
TF-IDF was introduced by Karen Spärck Jones in 1972 and still underlies many production spam filters and search-ranking systems today, decades before deep learning embeddings existed.