Skip to content
BENIBIX Learn

Bag of Words

AI🔤 NLP & LanguageText Representation

Also known as BoW, Bag-of-Words Model

Text turned into word counts. The word order is thrown away.

Think of it like

Think of it like you tip all the words on a page into a bag. Then you count them.

Example

Emma's spam filter counts words in each email. An email with 'free' 3 times and 'winner' 2 times gets a high spam score.

Why it matters

It was the first common way to turn text into numbers. It is still a quick test to beat.

Definition

Bag of words turns a text into a list of word counts. It makes one slot for every word in the vocabulary and counts how often each word shows up. The order of the words is thrown away. That makes it simple and fast, and it works well for jobs like sorting emails by topic. But 'dog bites man' and 'man bites dog' look exactly the same to it.
Two sentences with opposite meanings give the same counts. That is what losing the order costs.

Common mistake

Using it where order matters. 'Not good' and 'good, not' get the same counts, so meaning can be lost.

Key takeaways

  1. 1
    Counts each word. One slot per word.
  2. 2
    Order is lost. Only the counts stay.
  3. 3
    Simple and fast. A good first try.

Compare