VIEW THIS AS

Auto mode follows the Route Engine until you choose a viewpoint.

YOU ARE HERE

ROUTE CHECK

CONNECTED TO

WHAT NEXT

Use the canonical route for this room, or HELP if you are unsure.

Vocabulary | What Is a Document–Term Matrix? How Words Become Searchable Data

A student works in an open notebook beside a laptop and textbooks, with warm evening light outside the window.

A document–term matrix is a table that turns language into numerical features: each row represents a document, each column represents a word or phrase under defined processing rules, and each cell records presence, a count or a weight. This representation makes text collections searchable and comparable. It does not, by itself, preserve who said what, the order of words, negation or the truth of a claim.

Did you know that two sentences can have exactly the same word counts while saying opposite things? ‘The child chased the dog’ and ‘The dog chased the child’ contain the same individual words, but the subject and object have swapped. A basic document–term matrix can make search faster while losing that difference. Understanding this helps students see both the technological power of vocabulary and the limits of treating language as numbers.

This guide explains what document–term matrices are, how binary and count representations work, how stopwords, n-grams, TF–IDF and document frequency change the numbers, and why human context remains essential. It includes a complete original worked matrix and applications across Primary and Secondary English, Mathematics, Science, History, General Paper, translation and workplace writing, with primary references to Stanford’s information-retrieval text and scikit-learn documentation.

Editorial note: The mini-documents and calculations below are original teaching examples, not results from a corpus or data about actual students. Any algorithmic description depends on the documented implementation and its settings.

Contents: how text becomes a searchable numerical map

Open 43 chapters and worked investigations
  1. 1. A document–term matrix is a map of words across texts
  2. 2. Why vocabulary turns into data
  3. 3. Rows are documents under an explicit definition
  4. 4. Columns are defined features, not universal meanings
  5. 5. Binary presence versus occurrence counts
  6. 6. An original three-text demonstration
  7. 7. The same dataset as a count matrix
  8. 8. Document–term and term–document matrices
  9. 9. Tokenisation creates the starting vocabulary
  10. 10. Lowercasing can help and hurt
  11. 11. Stemming and lemmatisation change columns
  12. 12. Stopword filters alter the feature set
  13. 13. N-grams preserve short sequences
  14. 14. Sparse matrices store mostly zero entries
  15. 15. Why a matrix can support keyword search
  16. 16. Boolean AND and OR have precise meanings
  17. 17. Document frequency is a column-level question
  18. 18. Term frequency is a row-level feature
  19. 19. IDF changes the value of common terms
  20. 20. TF–IDF yields a weighted matrix
  21. 21. Different vectoriser settings change the result
  22. 22. A feature vocabulary can be fixed in advance
  23. 23. Training and evaluation must stay separate
  24. 24. A matrix usually loses original word order
  25. 25. Negation can disappear into the same feature set
  26. 26. Synonyms may create different columns
  27. 27. Homonyms may collapse into one column
  28. 28. A document is not always an independent source
  29. 29. Column totals do not establish public belief
  30. 30. A teacher can build a matrix by hand
  31. 31. Primary English: recognise topic words and function words
  32. 32. Secondary English: compare evidence and argument
  33. 33. Mathematics: cells need defined units
  34. 34. Science: a technical term can be rare but essential
  35. 35. History: named entities dominate some documents
  36. 36. General Paper: repeated language can be an echo
  37. 37. Translation: matching concepts across scripts is not automatic
  38. 38. School notices: formal accuracy exceeds keyword overlap
  39. 39. Privacy survives numerical transformation
  40. 40. A matrix does not know whether a word is understood
  41. 41. The best notebook records preprocessing
  42. 42. A five-minute matrix debugging routine
  43. 43. The final reader test: numbers return to sentences

The original three-document matrix

Fictional texts: A is ‘Readers compare evidence.’ B is ‘Evidence supports claims.’ C is ‘Readers question claims.’ The counting rule lowercases words and removes final punctuation. The example matrix uses binary presence, so repeated instances would still be represented as 1.

DocumentreadersevidenceclaimsMeaning of each cell
A110A contains readers and evidence
B011B contains evidence and claims
C101C contains readers and claims
Document frequency222Each term occurs in two different documents

A count-based matrix for these particular sentences happens to be identical, because no selected term is repeated within a single document. Add the extra sentence ‘Evidence matters’ to document B and the count for evidence in B becomes 2, while its binary presence remains 1.

1. A document–term matrix is a map of words across texts

A document–term matrix is a table or numerical array in which rows represent documents, columns represent selected terms and each cell records a defined feature of that term in that document. The simplest versions store zero or one for absence or presence; others store counts or weights.

The representation allows a computer to compare many documents efficiently. It can answer questions such as which texts mention evidence and which contain claim. But it is a compressed view of language: the numbers do not preserve all the words’ relationships, tone or truth.

Return to contents

2. Why vocabulary turns into data

People read whole sentences, but many search and classification systems first build simpler numerical representations. A document–term matrix converts selected features into columns that algorithms can count, compare or weight. This bridges language and computation.

For students, the important insight is that a term is not merely a dictionary item. It can also become a searchable signal. Understanding how the signal is created helps learners recognise what is visible to a machine and what might disappear when it is reduced to counts.

Return to contents

3. Rows are documents under an explicit definition

A document might be a short story, Science report, school notice or one paragraph. Whichever unit is chosen becomes a row in the matrix. If one essay is divided into five paragraphs, the matrix now contains five rows rather than one.

This boundary changes the values and comparisons. The researcher must decide whether the question concerns whole documents or smaller passages, then keep the same rule throughout the analysis. A row label needs to identify its source, not just a convenient number.

Return to contents

4. Columns are defined features, not universal meanings

A column might represent the exact word evidence, a lowercased spelling, a lemma or a multiword expression. The chosen analyser decides which terms belong to the vocabulary used by the matrix.

That means a column is a computational feature under stated processing rules. It does not automatically represent one concept. Bank can denote money or a riverbank; unless a method explicitly disambiguates senses, the same column may mix both.

Return to contents

5. Binary presence versus occurrence counts

In a binary matrix, a cell contains 1 if the term occurs at least once and 0 otherwise. A count matrix records how many times it occurs. One document mentioning a word twenty times has binary value 1 but count value 20.

Both can be useful. Binary representation answers whether a term is present; counts answer how often it appears. Confusing them can make a highly repetitive source seem like many independent documents or make two essays appear equally focused when their repetition differs.

Return to contents

6. An original three-text demonstration

Consider three invented mini-documents: A says ‘Readers compare evidence.’ B says ‘Evidence supports claims.’ C says ‘Readers question claims.’ We lower-case the words, remove end punctuation and treat each space-separated word as a token for this illustration.

Choose the three columns readers, evidence and claims. Text A receives 1,1,0; B receives 0,1,1; C receives 1,0,1. The numbers capture presence. They do not show whether a claim is sound or why a reader questioned it.

Return to contents

7. The same dataset as a count matrix

In the illustrative three-document collection, each selected term happens to occur no more than once per document, so binary and count values are identical. If we add another instance of evidence to document A, its count becomes 2 while its binary presence remains 1.

A student can extend this toy collection by repeating a word and observing which representation changes. The exercise clarifies the meaning of each cell before introducing larger datasets or mathematical transformations.

Return to contents

8. Document–term and term–document matrices

Some texts display terms as rows and documents as columns, calling the result a term–document matrix or incidence matrix. Others use documents as rows and terms as columns. These are transposes of one another when they encode the same data.

Always read the axis labels before computing sums. A row sum might mean words per document in one orientation and document frequency for a term in the other. A good spreadsheet gives unambiguous headings rather than relying on terminology alone.

Return to contents

9. Tokenisation creates the starting vocabulary

Before filling the matrix, a program must decide how to divide text into units. Apostrophes, hyphens, punctuation, digits and languages without routine word-separating spaces can complicate this step.

A matrix made from one tokeniser may differ from one produced by another. Even if both show the same document names, the columns could represent different units. For comparable results, document the preprocessing choices.

Return to contents

10. Lowercasing can help and hurt

Lowercasing can combine sentence-initial and ordinary spellings of the same word. It can also mix distinct uses such as May the month with may as a modal verb.

When the study involves permissions, months or names, a case-insensitive matrix may require additional filtering or interpretation. The same transformation that reduces superficial variation can erase a distinction needed for the question.

Return to contents

11. Stemming and lemmatisation change columns

A stemmer may reduce word forms to shortened character stems; a lemmatiser maps forms to dictionary-like base entries using linguistic analysis. Either operation can group multiple visible words under one feature.

This is useful when the learning objective concerns a word family, but it can combine forms whose grammatical roles differ or fail on ambiguous words. The original text should remain available so a reader can check what an aggregated feature actually represented.

Return to contents

12. Stopword filters alter the feature set

A vectoriser may ignore frequent function words such as the or and when building a topic-oriented representation. That can make subject terms more visible and reduce the number of columns.

The danger is losing logically important material. Not, only and unless can determine a sentence’s meaning. A filtered matrix should not be trusted to reproduce an instruction or legal condition word for word.

Return to contents

13. N-grams preserve short sequences

A unigram feature represents one token; a bigram feature represents a sequence of two, while an n-gram can represent a longer sequence. In scikit-learn, ngram_range controls the minimum and maximum n-gram sizes when using relevant analysers.

Features such as not approved may preserve a local distinction that separate-word counts overlook. Yet a few fixed-length phrases still cannot encode an entire argument, a distant negation or who asserted a claim. N-grams improve representation for some purposes without solving semantics completely.

Return to contents

14. Sparse matrices store mostly zero entries

If a corpus has thousands of documents and tens of thousands of distinct terms, most documents do not contain most terms. A dense matrix would store enormous numbers of zero values. A sparse representation records nonzero positions and associated values more efficiently.

Scikit-learn’s CountVectorizer produces a sparse document–term matrix. The efficiency matters for real systems, but students can understand the idea with a small table: keep the entries that contain information instead of writing every absence repeatedly.

Return to contents

15. Why a matrix can support keyword search

If the term evidence has a column, a system can find the rows in which the column is nonzero. This simple presence query is related to Boolean retrieval: documents can be selected based on the presence or absence of specified terms.

A matrix is a teaching representation of this principle, not a claim that modern search engines inspect a huge literal table on every query. Production systems commonly use inverted indexes and more sophisticated ranking methods to scale the task.

Return to contents

16. Boolean AND and OR have precise meanings

A query for documents containing evidence AND claims requires both features in the same document under the matching rule. OR admits documents containing either. NOT is a restriction on a defined set and must not be confused with sentence-level negation.

In the fictional three-document example, document B has both evidence and claims. That shows presence, not that B’s statement is true. A student should understand that search logic and argument logic are not interchangeable.

Return to contents

17. Document frequency is a column-level question

Document frequency counts how many documents contain a term. In a binary document–term matrix, it is the sum of the relevant term column when rows represent documents. For a count matrix, one first converts each nonzero entry to presence.

A document repeating a word ten times still contributes one to the document-frequency total. This is why a matrix makes the distinction between repetition and breadth visible, but only when the chosen cell meaning is clear.

Return to contents

18. Term frequency is a row-level feature

Term frequency concerns occurrences of a term in a particular document. In a count matrix it is the number stored at the document–term intersection. It may be transformed or normalised in later analyses.

A raw count is affected by document length and structure. A long Science report may repeat experiment far more often than a short story simply because it has more space and a specialist topic. The cell is an observation, not an immediate quality score.

Return to contents

19. IDF changes the value of common terms

Inverse document frequency assigns a form of retrieval weight based on how broadly a term occurs across a collection. Very common terms may offer less discrimination among documents than terms appearing in relatively few.

IDF does not measure how difficult a word is for a child or how important it is to the world. A specialist word can be rare in a general corpus yet common in a textbook. Each weighting scheme answers a retrieval question, not a complete educational one.

Return to contents

20. TF–IDF yields a weighted matrix

A TF–IDF vectoriser replaces or transforms raw counts with weights involving within-document use and cross-document spread. The exact details, including smoothing and normalisation, depend on the implementation.

It is tempting to call the highest-weight word the document’s ‘most important idea’. That claim is usually too strong. The feature may distinguish the text statistically while being a name, a narrow topic or a repeated term without central conceptual importance.

Return to contents

21. Different vectoriser settings change the result

CountVectorizer can vary whether it lowercases, uses stopwords, chooses n-gram lengths or includes terms above or below document-frequency thresholds. Each option changes what the output columns mean.

When two students get different matrices from the same texts, first compare the configurations and library versions. A discrepancy may be due to preprocessing rather than mathematical error. Reproducibility starts before the multiplication or search.

Return to contents

22. A feature vocabulary can be fixed in advance

Some workflows supply a predetermined set of terms, producing consistent columns across new documents. This helps compare texts against the same vocabulary or apply a model trained earlier.

The cost is that new words outside the fixed feature list may have no dedicated column. A system that appears indifferent to a new technical term may simply lack the feature. The absence of a column is not evidence that the term lacks meaning.

Return to contents

23. Training and evaluation must stay separate

If a model’s feature vocabulary is learned from all documents before an evaluation, information from test data may influence the representation. Depending on the learning setup, this can create leakage and overoptimistic results.

In a standard supervised-learning workflow, fit preprocessing and feature selection on the training portion and apply the learned transformation to evaluation data. This is a technical discipline with an educational parallel: do not inspect the answers before claiming that a method predicts them.

Return to contents

24. A matrix usually loses original word order

A simple bag-of-words matrix does not retain the order in which individual terms appeared. The two sentences ‘The dog chased the child’ and ‘The child chased the dog’ have the same word counts even though the event reverses.

This is a major limitation. A matrix may identify topic overlap without preserving who acted on whom. For comprehension, translation or safety instructions, return to the original sentences and check grammatical relationships.

Return to contents

25. Negation can disappear into the same feature set

A document containing approved and one containing not approved differ in meaning, but simple keyword-based matching may overemphasise the shared term. If not is removed as a stopword, the distinction may vanish in the representation.

Never use a bag-of-words matrix alone to decide whether permission was granted or a scientific claim proved. The authoritative text and complete conditions must be checked, especially when people could act on the result.

Return to contents

26. Synonyms may create different columns

Two texts can describe the same idea using purchase and buy. A surface-form matrix may create separate columns, making them appear unrelated at the feature level. A synonym ring or semantic model can add connections.

But synonym expansion also introduces risk because near-synonyms differ in tone, scope and grammar. A good retrieval system improves recall while preserving the intended meaning. Students should learn that a missing exact term does not necessarily imply a missing concept.

Return to contents

27. Homonyms may collapse into one column

The spelling bank can describe a financial institution or a river edge. A naive matrix may count both under one feature even though they refer to different concepts.

Sense-aware techniques, metadata and full-sentence reading can distinguish them. A learner’s job is not to memorise a matrix as truth, but to recognise when an apparently precise number is built on an ambiguous label.

Return to contents

28. A document is not always an independent source

Several rows may be copies of the same press release or template. A matrix can count them separately unless deduplication or source grouping is applied. That can make one phrase appear widespread across the document collection.

If the research claims independent corroboration, source provenance matters. Five copied reports are not necessarily five separate pieces of evidence. Word presence is not source credibility.

Return to contents

29. Column totals do not establish public belief

Suppose many documents mention the word fraud. A matrix can show that the term appears often in the stored texts; it cannot tell us whether authors accuse someone, deny an allegation or quote a disputed claim.

For History and media literacy, inspect quotation, evidence and speaker. Searchable language features point to passages for investigation, not verified facts about the world.

Return to contents

30. A teacher can build a matrix by hand

Choose four invented short passages and five target terms. Create a table with one row per passage and one column per term. Have pupils circle each appearance and enter 1 for presence or the actual count for a count matrix.

Then ask what information the numbers preserve and what disappears. The activity becomes much more meaningful when students read two sentences with the same feature counts but different meanings. Data literacy should lead back to language.

Return to contents

31. Primary English: recognise topic words and function words

A Primary child can compare a story about a storm with instructions for staying indoors. The two texts may share rain or door but organise the information differently.

After counting familiar vocabulary, the teacher asks the child to explain one instruction precisely. This prevents the table from becoming a list-learning exercise that neglects logical words such as before and until.

Return to contents

32. Secondary English: compare evidence and argument

Two persuasive paragraphs may contain the same terms evidence, claim and reason. A count matrix could suggest topic similarity without showing whether one paragraph offers valid support and the other merely repeats assertions.

Students should test each paragraph by identifying its main claim, evidence, qualifications and counterargument. The numerical representation is a map of vocabulary signals, not an essay-marking rubric.

Return to contents

33. Mathematics: cells need defined units

The table itself provides a useful Mathematics exercise in matrix organisation, counts and binary variables. But students should not treat each number as meaningful without naming its row, column and counting convention.

A column sum can calculate document frequency; a row sum of counts can calculate occurrences among the selected terms. Neither sum necessarily equals the total number of words in a passage because only selected features may appear.

Return to contents

34. Science: a technical term can be rare but essential

In a collection of Science and general reading, a word such as photosynthesis may occur in relatively few documents yet be indispensable to one subject. A weighted matrix might distinguish those specialist texts efficiently.

This is not a reason to teach the term according to its global frequency alone. Curriculum relevance, conceptual understanding and evidence from the actual lesson determine which vocabulary students need.

Return to contents

35. History: named entities dominate some documents

The names of people, places and events can become high-frequency features in a historical corpus. These help retrieve relevant documents but may not distinguish an author’s interpretation of the event.

A student must still examine verbs, claims and source context. Two histories mentioning the same leader can disagree sharply. A matrix establishes common vocabulary, not common historical judgement.

Return to contents

36. General Paper: repeated language can be an echo

A GP student may find the same phrase in many online articles and assume it reflects independent consensus. A document–term matrix would indeed show broad presence if the pages are stored separately.

Source examination may reveal they all copied one announcement. The lesson is to distinguish a feature appearing in many files from multiple independent confirmations. Good critical reading complements retrieval.

Return to contents

37. Translation: matching concepts across scripts is not automatic

A source and its translation may have different word counts, grammatical structures and term boundaries. A surface-level matrix in one language cannot be directly compared with another without appropriate tokenisation and mappings.

The goal is preserving who acts, what changes and what conditions apply. Cross-language retrieval can use more advanced techniques, but a simple term-count matrix is not proof of accurate translation.

Return to contents

38. School notices: formal accuracy exceeds keyword overlap

Two versions of an attendance notice may contain nearly identical words except may versus must. Their document–term vectors can look similar while the obligations differ.

For consequential wording, use complete-sentence comparison and the current authoritative policy. A spreadsheet of counts is not enough to approve a notice that families will rely upon.

Return to contents

39. Privacy survives numerical transformation

A matrix may still contain sensitive signals about individual students or rare personal experiences, especially when rows can be linked back to identifiable documents. Converting text to numbers is not automatically anonymisation.

Use authorised datasets, appropriate access controls and a minimal feature set. A public classroom demonstration can use fictional passages rather than uploading genuine pupil writing to unapproved services.

Return to contents

40. A matrix does not know whether a word is understood

A child may copy an unfamiliar word into an essay without understanding it, or may demonstrate deep knowledge through a common word used precisely. The matrix counts the appearance; it cannot measure the learner’s mental representation.

Vocabulary assessment should include contextual explanation, accurate use and transfer to a new situation. Computational counts can help identify patterns worth teaching but should not replace instructional judgement.

Return to contents

41. The best notebook records preprocessing

A responsible project log names the documents, tokeniser, case rule, vocabulary, stopword list, n-gram setting, weighting scheme and software version. It also records what interpretation the researcher was trying to support.

That transparency makes the result reproducible and prevents a chart from appearing more authoritative than its source. A well-documented small example is more educational than a huge matrix whose cells cannot be explained.

Return to contents

42. A five-minute matrix debugging routine

When a number looks wrong, check the original sentence, confirm how it was tokenised, inspect the exact column term and verify whether the matrix stores counts or binary values. Then check whether duplicates or filters changed the dataset.

This routine resembles debugging in coding or checking units in Mathematics. It turns surprise into a testable problem rather than a reason to distrust every computation. The outcome is a corrected observation and a better-defined question.

Return to contents

43. The final reader test: numbers return to sentences

Ask a learner to look at a small matrix and identify two texts that share a word. Then have the learner read both originals and explain how the word is used differently or similarly in context.

If the student understands that the matrix is a useful index into texts rather than a complete account of meaning, the lesson has succeeded. Vocabulary becomes technology when words can be found, compared and used without losing the human relationships they express.

Return to contents

Eight-step document–term matrix exercise

  1. Choose three or four original passages and specify the document boundary.
  2. Decide whether to count exact surface words, lowercased forms or lemmas.
  3. Select the terms to be used as column features.
  4. Build a binary presence table and explain each 0 and 1.
  5. Build a count table using the same documents and terms.
  6. Compare column sums for document frequency and individual cells for repeated occurrences.
  7. Read two texts with similar feature counts and identify meaning the matrix omitted.
  8. Write a fresh sentence and explain why a word choice must still be checked in context.

Frequently asked questions

1. What is a document–term matrix?

A numerical representation of documents and term features, usually with documents as rows and terms as columns.

2. Is a binary matrix a frequency matrix?

Not in the same sense. It records presence, whereas a count matrix records occurrences.

3. Is term–document matrix another name?

Yes, sometimes with the axes transposed. Always inspect row and column labels.

4. Why are most cells zero?

Most individual documents contain only a small fraction of the vocabulary in a large collection.

5. Can a matrix preserve grammar?

A simple bag-of-words matrix usually loses word order; n-grams add some local structure but not full understanding.

6. Does TF–IDF measure the truth of a statement?

No. It weights term features for retrieval or analysis under particular rules.

7. Can a school child build one?

Yes. A four-document presence table is a suitable introductory activity.

8. Can two opposite sentences have the same counts?

Yes, if they contain the same words in different orders or differ in relationships not represented by the features.

9. Does a matrix protect confidential data?

Not automatically. Rare features and document identifiers can still expose sensitive information.

10. What is the real vocabulary goal?

Use the table to locate language evidence, then return to full sentences and make an accurate communication decision.

Research sources and the wider vocabulary system

A document–term matrix is a powerful index into language, not a replacement for language. Once learners understand which information it keeps and discards, they can use counts to discover texts without surrendering meaning, evidence or judgement.