HomeAI & Machine LearningBag of Words vs TF-IDF: How Machines Turn Sentences into Numbers

📊 Bag of Words vs TF-IDF

An interactive 3D bar-chart lab comparing raw Bag-of-Words counts against TF-IDF weighted scores across a small document corpus, showing exactly how rarity-based weighting suppresses common words.

AI & Machine Learning3DAdvanced60 FPS
tfidf-vs-bag-of-words-text-classification-lab ↗ Open standalone

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.

🔬 What It Demonstrates

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.

🎮 How to Use

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.

💡 Did You Know?

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.

⚙ Under the hood

An interactive 3D bar-chart lab comparing raw Bag-of-Words counts against TF-IDF weighted scores across a small document corpus, showing exactly how rarity-based weighting suppresses common words.

machine learningnatural language processingtext analysistfidfbag of wordsdata mininginformation retrievalThree.js

3D · Three.js / WebGL renderer · 60 FPS target · runs fully client-side, no install

What did you find?

Add reproduction steps (optional)