Bag of Words Lab 🧺🔢

Type 3 messages, then click Build Vocabulary to see how vectorization turns text into numbers (Bag of Words = just word counts).
🧠 Vocabulary Size: 0
📄 Messages: 3
🧊 Non-Zero Cells: 0

🛠️ Mission Control

Click “Build Vocabulary” to fill the bag.
✅ Tip: Click a word-chip to highlight its column in the table.
👋 Start with the example, or type your own messages. Then build the vocabulary and vectorize.
📚 Step 1: Vocabulary (word → column index) Not built

Vocabulary Dictionary

{}
📊 Step 2: Count Table (rows = messages, cols = words) Waiting
Click “Vectorize” to generate the table.
🧊 Step 3: Sparse Matrix (only non-zero cells) Waiting

What the computer stores

Shape (0, 0)

🧠 Bag of Words Explanation

  1. Vectorization means converting text into numbers. The model can’t learn from words directly — it needs numbers.
  2. Bag of Words means we ignore grammar and order. We only care:
    ➡️ Which words exist?
    ➡️ How many times each word appears?
  3. We build a vocabulary (a list of all unique words). Each word gets a column index like:
    { "again": 0, "hello": 1, "hi": 2, "there": 3 }
  4. Each message becomes a row of numbers. Each number is the count for one vocabulary word.
  5. The result is usually mostly zeros, so we store it as a sparse matrix (only the important non-zero values).
🎯 If you see (0, 2) 1 that means:
→ message row 0
→ word column 2
→ count is 1