Gradivex
  • Home
  • Academy
  • Arena
  • Visualizer
  • Models
Log in
NLP & Transformers/Embeddings/Lesson 1

Bag of words

Module 2 · Lesson 1 of 5 · 6 min read
Theory

The first idea anyone has

You need to turn a sentence into a vector. The obvious move, and for decades the standard one: make a giant checklist of every word in the language, and for each sentence, count. "The cat chased the cat" becomes: the=2, cat=2, chased=1, everything else zero. One sentence, one long sparse vector of counts.

This is bag of words, and the name is the confession. Tear the sentence apart, throw the words in a bag, shake. Order? Gone. Grammar? Gone. What survives is pure inventory.

Before laughing at it, respect what it ran: spam filters that actually worked (count "viagra" and "winner", weigh the evidence), search engines, sentiment analysis, topic detection. Through the 2000s this bag powered most of the text-processing economy.

Interactive

Two sentences, one bag each

Pick a pair. Both sentences get counted into vectors, and the meter shows how similar the two vectors are. Watch where counting succeeds and where it embarrasses itself.

“the dog bit the postman”
“the postman bit the dog”
wordsentence 1sentence 2
bit11
dog11
postman11
the22
Vector similarity:
100%

100% similar. Identical bags, identical vectors. One sentence is an insurance claim, the other is local news, and bag of words physically cannot tell them apart.

Theory

Diagnosis: every word is a stranger

Put the failures side by side and they share one root:

  • Order blindness: "dog bites man" = "man bites dog". The bag stores counts, and counts commute.
  • Synonym blindness: "movie" and "film" occupy two unrelated slots in the checklist. Similarity between slots is exactly zero, always.
  • Dimension bloat: one slot per vocabulary word means vectors with 100,000+ entries, almost all zeros.

The root: in bag of words, every word is a direction of its own, at right angles to every other word. The representation has no concept of "these two words resemble each other". Similarity between words is not weak; it is undefined.

The fix requires a different kind of vector: short, dense, and positioned so that related words sit NEAR each other. Build that, and synonyms stop being strangers. That vector is called an embedding, and it is the rest of this module.

Interactive

Check your understanding

A bag-of-words system rates "the movie was fantastic" and "that film felt amazing" as almost completely unrelated. Why?

Takeaway

What to remember

  • ✓Bag of words: one slot per vocabulary word, count occurrences, done. Order and grammar discarded.
  • ✓It powered real systems for decades wherever vocabulary itself was the signal: spam, topics, search.
  • ✓Two structural failures: word order is invisible, and different words are ALWAYS unrelated, even synonyms.
  • ✓The vectors are huge and almost entirely zeros: one dimension per word does not scale to meaning.
  • ✓Wanted: short dense vectors where similar words sit close together. That is an embedding, next lesson.
Mentor-0

Stuck on something in this lesson? Ask.

0/1000

Every lesson is free to read. Log in to save your progress, complete lessons, and earn Compute and XP.

Log in free
Word embeddings
Gradivex

Understand AI from the inside, read it, see it, prove it.

Platform

AcademyVisualizerRoadmapsModels

Community

DiscordLeaderboard

Company

PrivacyTerms

© 2026 Gradivex. All rights reserved.