# Bag of Words

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

**Field:** Artificial Intelligence  
**Category:** NLP & Language  
**Also known as:** BoW, Bag-of-Words Model

## Think of it like

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

## 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.

## 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.

## Common mistake

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

## Three principles

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

## Related terms

- [Term Frequency-Inverse Document Frequency (TF-IDF)](https://learn.benibix.com/term/ai/tf-idf)
- [Word Embedding](https://learn.benibix.com/term/ai/word-embedding)
- [Stop Words](https://learn.benibix.com/term/ai/stop-words)
- [Vector](https://learn.benibix.com/term/general/vector)

## Told apart from

- [Bag of Words vs Word Embedding](https://learn.benibix.com/compare/bag-of-words-vs-word-embedding): People often think any way of turning words into numbers keeps their meaning. Bag of words only counts words, so 'car' and 'vehicle' are as far apart as 'car' and 'cake'. A word embedding gives each word a learned vector, so words with close meanings sit close. Counts are quick and clear; embeddings know which words are alike.

![Two sentences with the same words in a different order point to one table of word counts. The table is the same for both, so the order is lost.](https://learn.benibix.com/diagrams/nlp-bag-of-words.svg)

---

Source: https://learn.benibix.com/term/ai/bag-of-words
Author: Behnia Zarei (a developer in Vienna, Austria, who builds and teaches data, AI and business intelligence at BENIBIX)
Publisher: BENIBIX Learn (https://learn.benibix.com/)
Last updated: 2026-11-18
Licence: CC BY 4.0 (https://creativecommons.org/licenses/by/4.0/). Quote freely with attribution.
