Bag of Words
Now the text is clean, it has to become numbers. Bag of Words is how — and drawing its table is a 4-mark question that has come up in consecutive years.
1What it is
1. A vocabulary of words for the corpus.
2. The frequency of those words — how many times each has occurred.
A shopping receipt
2The four steps
- Text processing — collect the data and pre-process it.
- Create a dictionary — list all the unique words occurring in the corpus. This is the vocabulary.
- Create a document vector — for a document, count how many times each dictionary word occurs in it.
- Create document vectors for all the documents.
This is exactly the table a 4-mark question asks you to produce. Step through it once and the shape sticks.
Collect the documents and normalise them — lowercase, punctuation gone, split into tokens.
3From the board papers
Document 1: Data Science requires information.
Document 2: Information analysis requires data.CBSE board exam 2026
▶Show the answer
Step 1 — text processing. Lowercase, drop the full stops, tokenise:
D1: [data, science, requires, information]
D2: [information, analysis, requires, data]
Step 2 — dictionary (5 unique words): data, science, requires, information, analysis
Steps 3 and 4 — document vectors:
| data | science | requires | information | analysis | |
| Doc 1 | 1 | 1 | 1 | 1 | 0 |
| Doc 2 | 1 | 0 | 1 | 1 | 1 |
Document 1: NLP is a domain of AI.
Document 2: NLP stands for Natural Language Processing.CBSE board exam 2025
▶Show the answer
D1: [nlp, is, a, domain, of, ai] D2: [nlp, stands, for, natural, language, processing]
Dictionary (11 words): nlp, is, a, domain, of, ai, stands, for, natural, language, processing
| nlp | is | a | domain | of | ai | stands | for | natural | language | processing | |
| Doc 1 | 1 | 1 | 1 | 1 | 1 | 1 | 0 | 0 | 0 | 0 | 0 |
| Doc 2 | 1 | 0 | 0 | 0 | 0 | 0 | 1 | 1 | 1 | 1 | 1 |
Note the stop words are still there. Text normalisation says to remove is, a, of, for— but the handbook’s own worked example keeps them in the dictionary, and so do the board’s. Follow the book: keep them unless the question says otherwise.
D1: [students, love, studying, ai] D2: [ai, is, transforming, education] D3: [teachers, and, students, explore, ai, tools]
(a) Create the dictionary. (b) Construct the document vector for Document 3. (c) Explain how Bag of Words helps in feature extraction. (d) Why is the order of words not considered important?CBSE sample paper 2025–26
▶Show the answer
(a) 11 unique words: students, love, studying, ai, is, transforming, education, teachers, and, explore, tools
(b) Document 3 in that order:
1, 0, 0, 1, 0, 0, 0, 1, 1, 1, 1
(c) It converts text into numbers a machine learning algorithm can use: each document becomes a vector of word counts, and those counts are the features.
(d) Because the model only records which words occur and how often. It is called a bag precisely because the sequence is thrown away — the vocabulary and the frequencies are all that is kept.
4Check yourself
What two things does Bag of Words give you?
Why is it called a 'bag' of words?
In a document vector, a word that does not appear in that document is written as:
Which algorithm creates a vocabulary of all unique words in the corpus?