Algorithm Search⌘K

Definitionintro

Term-document incidence matrix

Also called term-document matrix.

A 0-1 matrix with a row for each term and a column for each document, set where the term occurs in the document.

The term-document incidence matrix of a collection is the 0-1 matrix with one row for each term and one column for each document, whose entry is 1 exactly when the term occurs in the document. Each row is a bit vector that gives the set of documents of a term, so a Boolean query is a bitwise expression over rows. The matrix is the model behind the Boolean retrieval model. For a real collection it is almost all zeros, so engines store each row as a posting list of its 1 positions, which is an inverted index.

Definition

Let D=(d1,…,dN)D = (d_1, \ldots, d_N) be a collection of NN documents, each a sequence of terms, and let V=(t1,…,tM)V = (t_1, \ldots, t_M) be its vocabulary: the MM distinct terms that occur in at least one document, after the same tokenization for all documents. The term-document incidence matrix is the matrix A∈{0,1}M×NA \in \{0, 1\}^{M \times N} with

Aij={1if ti occurs in dj,0otherwise,1≤i≤M, 1≤j≤N.A_{ij} = \begin{cases} 1 & \text{if } t_i \text{ occurs in } d_j, \\ 0 & \text{otherwise,} \end{cases} \qquad 1 \le i \le M,\ 1 \le j \le N.

The row Ai⋅A_{i\cdot} is the incidence vector of term tit_i, and the number of 1s in it is the document frequency dfti\mathrm{df}_{t_i}. The column A⋅jA_{\cdot j} is the set of terms of djd_j, with no count and no order. The number of 1s in AA is the number of postings ∑idfti\sum_i \mathrm{df}_{t_i}, which is at most the number of tokens.

A Boolean query maps to bit operations on rows: t AND ut \text{ AND } u is At⋅∧Au⋅A_{t\cdot} \wedge A_{u\cdot}, t OR ut \text{ OR } u is At⋅∨Au⋅A_{t\cdot} \vee A_{u\cdot}, and NOT tt is the complement ¬At⋅\neg A_{t\cdot}, with all operations bitwise over the NN columns. The documents that match are the columns with a 1 in the result.

Examples and non-examples

A toy collection. The toy collection of the information retrieval pages has N=8N = 8 short documents and M=50M = 50 terms, so AA has 400400 entries. Exactly 7474 of them are 1, so 18.5%18.5\% of the matrix is set. Five rows, with the columns d1d_1 to d8d_8 from left to right:

term d1d_1 d2d_2 d3d_3 d4d_4 d5d_5 d6d_6 d7d_7 d8d_8
sorted 1 1 0 1 0 0 0 1
array 1 1 0 0 0 0 0 1
search 1 0 0 0 0 0 1 0
posting 0 0 1 1 1 0 0 0
list 0 0 1 1 0 0 0 0

The query sorted AND array AND NOT search is the bitwise expression 11010001∧11000001∧¬10000010=11010001∧11000001∧01111101=0100000111010001 \wedge 11000001 \wedge \neg 10000010 = 11010001 \wedge 11000001 \wedge 01111101 = 01000001. The 1s are in columns 2 and 8, so the answer is {d2,d8}\{d_2, d_8\}. Document d1d_1 holds all three terms, and the NOT removes it. The query sorted OR search gives 1101001111010011, the documents {1,2,4,7,8}\{1, 2, 4, 7, 8\}.

The row of "sorted" has a 1 in column 2 although d2d_2 ("merge sort merges two sorted runs into one sorted array") holds the term twice. The matrix records only that the term occurs, not how often.

A large collection. Manning, Raghavan and Schuetze take a collection of one million documents with 500,000 distinct terms. The matrix has 5×10115 \times 10^{11} entries. With about 1000 tokens in each document, at most 10910^9 entries are 1, so at least 99.8%99.8\% of the entries are 0. Such a matrix is never stored in full. Its rows are kept as sorted lists of the column numbers of their 1s, which are the posting lists.

Non-example: the term-document count matrix. The matrix with entry tft,d\mathrm{tf}_{t,d}, the number of times tt occurs in dd, is not an incidence matrix: its entry for "sorted" and d2d_2 is 2. The weighted matrix with tf-idf entries of the vector space model, and the matrix that latent semantic analysis factors, are not 0-1 either. The name "term-document matrix" often means one of these weighted matrices.

Non-example: a phrase. The incidence matrix cannot answer the phrase query "list sorted". The rows of "list" and "sorted" have a common 1 only in column 4, but d4d_4 is "a posting list is a sorted list of document ids", where "list" is never right before "sorted". The matrix has lost the order of the words; a positional index keeps it.

  • Posting list. The posting list of tit_i is the sorted list of the column numbers jj with Aij=1A_{ij} = 1, the sparse form of row ii. Its length is dfti\mathrm{df}_{t_i}.
  • Inverted index. The set of all rows in posting list form, with a dictionary from terms to rows, is an inverted index. The columns in sparse form are a forward index.
  • Document-term matrix. The transpose ATA^{\mathsf T}, with documents as rows, is the same relation in the other orientation.
  • Bitmap index. A database bitmap index is the same idea for the values of a column of a table: one bit vector for each value.
  • Sparse matrix. Posting lists are the compressed sparse row form of AA as a sparse matrix.
  • Posting list intersection. The AND of two rows, computed on their sparse forms, is the posting list intersection problem.

References

  1. Christopher D. Manning, Prabhakar Raghavan and Hinrich Schuetze, Introduction to Information Retrieval, Cambridge University Press, 2008, Chapter 1, Section 1.1 (the term-document incidence matrix, Boolean queries as bitwise operations on its rows, and the size of the matrix for a large collection)
  2. Ian H. Witten, Alistair Moffat and Timothy C. Bell, Managing Gigabytes, second edition, Morgan Kaufmann, 1999, Chapter 3 (indexing, with bitmaps and inverted files as two ways to store the same term-document relation)

Where this leads

About this page

The build computes these levels from the evidence in the repository. Each row says what the next level needs. Read what the levels mean.

LadderLevelWhat the next level needs
Human proofH0 no proof
  • add a proof in proofs/ (06.5)
LeanL0 no Lean part
  • name a Lean module in the lean field (07)
VisualV0 none
  • add viz/scene.ts or a figure (10)
WritingW4 complete
  • a review of the text: no review record reviews/Q35WK6/text.yaml