Transcript Title

1
L01: Corpuses, Terms and Search
Basic terminology
The need for unstructured text search
Boolean Retrieval Model
Algorithms for compressing data
Algorithms for answering Boolean queries
Read Chapter 1 of MRS
Unstructured (text) vs.
structured (database) data
1996
3
Unstructured (text) vs.
structured (database) data
2006
4
Text Information Retrieval
You have all the Shakespeare plays stored in files
Which plays contain the word Caesar?

Your algorithm here:
Which plays of Shakespeare contain the words
Brutus AND Caesar ?
Processing unstructured data
Which plays of Shakespeare contain the words
Brutus AND Caesar but NOT Calpurnia?

One could grep all of Shakespeare’s plays
for Brutus and Caesar,
then strip out lines containing Calpurnia, but…
It Is Slow! (for large corpora)

Computing NOT Calpurnia is non-trivial
Other operations not feasible
(e.g., find Romans near countrymen)
Ranked retrieval (find “best” documents to return)
also not possible
6
Term-document incidence
m terms
N documents
Antony and Cleopatra
Julius Caesar
The Tempest
Hamlet
Othello
Macbeth
Antony
1
1
0
0
0
1
Brutus
1
1
0
1
0
0
Caesar
1
1
0
1
1
1
Calpurnia
0
1
0
0
0
0
Cleopatra
1
0
0
0
0
0
mercy
1
0
1
1
1
1
worser
1
0
1
1
1
0
1 if file contains word,
0 otherwise
Brutus AND Caesar but NOT Calpurnia
7
Incidence vectors
m terms
N documents
Antony and Cleopatra
Julius Caesar
The Tempest
Hamlet
Othello
Macbeth
Antony
1
1
0
0
0
1
Brutus
1
1
0
1
0
0
Caesar
1
1
0
1
1
1
Calpurnia
0
1
0
0
0
0
Cleopatra
1
0
0
0
0
0
mercy
1
0
1
1
1
1
worser
1
1
0
0
1
1
1
1
1
1
0
1
NOT Calpurn
So we have a 0/1 binary vector for each term.
To answer query: take the vectors for Brutus,
Caesar and (complement) Calpurnia  bitwise
AND.
110100 AND 110111 AND 101111  100100.
Brutus AND Caesar but NOT Calpurnia
8
Answers to query
Antony and Cleopatra, Act III, Scene ii
Agrippa [Aside to DOMITIUS ENOBARBUS]: Why, Enobarbus,
When Antony found Julius Caesar dead,
He cried almost to roaring; and he wept
When at Philippi he found Brutus slain.
Hamlet, Act III, Scene ii
Lord Polonius: I did enact Julius Caesar I was killed i' the
Capitol; Brutus killed me.
9
Space requirements
M=0.5mil terms
N=1mil documents
Say, N = 1M documents, each with about 1K terms.
How many terms all together?
Average 6 bytes/term including spaces/punctuation.
How many GB of data?
Say there are m = 500K distinct terms among these.
How many 0’s and 1’s in the Term-doc incidence
matrix?
10
Does the matrix fits in memory?
m terms
N documents
1
1
1
1
1
1
1
1 1
1
1
1
1
1
1
1
1
1
1
1
1 1 11
1
1
1
1
1
1
1 1
1
1
1
1
1
1
1
1
1
1
1
1
500K x 1M matrix has 500 Billion 0’s and 1’s.
But matrix is extremely sparse

1
it has no more than 1 Billion 1’s.
Why?
What’s a better representation than a matrix?
We only record the 1 positions.
11
“Inverted” Index
For each term T, we must store
a listing of all document id’s that contain T.
Do we use an array or a linked list for this?
Brutus
2
Calpurnia
1
Caesar
4
2
8
16 32 64 128
3
5
8
13 21 34
13 16
What happens if the word Caesar
is added to document 14?
12
Inverted index
Linked lists generally preferred to arrays



+ Dynamic space allocation
+ Insertion of terms into documents easy
– Space overhead of pointers
Posting
Brutus
2
4
8
16
Calpurnia
1
2
3
5
Caesar
13
Dictionary
32
8
64
13
128
21
34
16
Postings lists
Sorted by docID
13
Inverted index construction
Documents to
be indexed.
Friends, Romans, countrymen.
Tokenizer
Token stream.
More on
these later.
Modified tokens.
Inverted index.
Friends Romans
countrymen
Linguistic modules
friend
roman
countryman
Indexer friend
2
4
roman
1
2
countryman
1314 16
Indexer step 1: Token sequence
INPUT: Sequence of pairs:
(Modified token, Document ID)
Doc 1
I did enact Julius
Caesar I was killed
i' the Capitol;
Brutus killed me.
Doc 2
So let it be with
Caesar. The noble
Brutus hath told you
Caesar was ambitious
15
Indexer step 2: Sort
Sort by terms.
Core indexing step.
16
Indexer step 3: Dictionary & Postings
Merge multiple term entries
in a single document

Note two entries for caesar!
We merge PER DOCUMENT.
Add frequency information.
Why frequency?
Will discuss later.
Dictionary
Postings
17
Query processing: AND
Consider processing the query:
Brutus AND Caesar
 Locate Brutus in the Dictionary;
 Retrieve its postings.

Locate Caesar in the Dictionary;
 Retrieve its postings.

“Intersect” the two postings:
2
4
8
16
1
2
3
5
32
8
64
13
128
21
Brutus
34 Caesar
18
The Intersection
Walk through the two postings simultaneously.
What did we call this process in CS230?
Time?

2
8
_______ in the total number of postings entries
2
4
8
16
1
2
3
5
32
8
64
13
Brutus
34 Caesar
128
21
If the list lengths are x and y,
the merge takes O(x+y) operations.
Crucial: postings sorted by docID.
19
Intersecting two postings lists
20
Query Optimization
Query: Brutus AND Calpurnia AND Caesar
Best order for processing pairs of postings?



(Brutus AND Calpurnia) AND Caesar
(Calpurnia AND Caesar) AND Brutus
(Brutus AND Caesar) AND Calpurnia
Brutus
2
Calpurnia
1
Caesar
4
2
8
16 32 64 128
3
5
8
13 21 34
13 16
21
Query optimization example
Query: Brutus AND Calpurnia AND Caesar
Process in order of increasing freq:

start with smallest set, then keep cutting further.
This is why we kept
freq in dictionary
Brutus
2
Calpurnia
1
Caesar
4
2
8
16 32 64 128
3
5
8
13 21 34
13 16
Execute the query as (Caesar AND Brutus) AND Calpurnia.
22
More General Optimization
Query:
(madding OR crowd) AND (ignoble OR strife)
Get freq’s for all terms.
Estimate the size of each OR
by the sum of its freq’s (conservative).
Process in increasing order of OR sizes.
23
Boolean Queries: Exact match
The Boolean Retrieval model is being able to ask a
query that is a Boolean expression:

Boolean Queries are queries using AND, OR and NOT to join
query terms
 Views each document as a set of words
 Is precise: document matches condition or not.
Primary commercial retrieval tool for 3 decades.
Professional searchers (e.g., lawyers)
still like Boolean queries: (e.g. Westlaw)

You know exactly what you’re getting.
24