Adapted from Lectures by Prabhakar Raghavan (Yahoo and Stanford) and Christopher Manning (Stanford)
Prasad
L3InvertedIndex
Which plays of Shakespeare contain the words Brutus AND Caesar but NOT Calpurnia ? One could grep all of Shakespeares plays for Brutus and Caesar, then strip out plays containing Calpurnia ?
n n
Slow (for large corpora) Other operations (e.g., find the word Romans near countrymen) not feasible
Prasad
L3InvertedIndex
Term-document incidence
Antony and Cleopatra Julius Caesar The Tempest Hamlet Othello Macbeth
1 1 1 0 1 1 1
1 1 1 1 0 0 0
0 0 0 0 0 1 1
0 1 1 0 0 1 1
0 0 1 0 0 1 1
1 0 1 0 0 1 0
Incidence vectors
n
So we have a 0/1 vector for each term. To answer query: take the vectors for Brutus, Caesar and Calpurnia (complemented) bitwise AND. 110100 AND 110111 AND 101111 = 100100.
Prasad
L3InvertedIndex
Answers to query
n
n n n n
n
n n
Prasad
L3InvertedIndex
Collection: Fixed set of documents Goal: Retrieve documents with information that is relevant to users information need and helps him complete a task
Prasad
L3InvertedIndex
Info Need
Verbal form
Query
mouse trap
SEARCH ENGINE
Precision : Fraction of retrieved docs that are relevant to users information need Recall : Fraction of relevant docs in collection that are retrieved
More precise definitions and measurements to follow in later lectures
Prasad
L3InvertedIndex
Bigger corpora
n
Consider N = 1M documents, each with about 1K terms. Avg 6 bytes/term including spaces/punctuation
n
Prasad
500K x 1M matrix has half-a-trillion 0s and 1s. But it has no more than one billion 1s.
n
Why?
Prasad
L3InvertedIndex
10
Inverted index
n
For each term T, we must store a list of all documents that contain T. Do we use an array or a list for this?
2 1 4 2 8 3 16 32 64 128 5 8 13 21 34
Prasad
L3InvertedIndex
11
Inverted index
n
Dynamic space allocation Insertion of terms into documents easy Space overhead of pointers 2 1 13 4 2 16 8 3 16 5 32 8
Posting
64 13 21
128 34
Dictionary
Prasad
Countrymen
countryman 2 1 4 2
Inverted index.
Prasad
roman
L3InvertedIndex
countryman
1313 16
Indexer steps
n
Doc 1 I did enact Julius Caesar I was killed i' the Capitol; Brutus killed me.
Prasad
Doc 2 So let it be with Caesar. The noble Brutus hath told you Caesar was ambitious
L3InvertedIndex
Term I did enact julius caesar I was killed i' the capitol brutus killed me so let it be with caesar the noble brutus hath told you
Doc # 1 1 1 1 1 1 1 1 1 1 1 1 1 1 2 2 2 2 2 2 2 2 2 2 2 2
caesar
was ambitious
14
2 2
Sort by terms.
Core indexing step.
Prasad
L3InvertedIndex
Term Doc # I did enact julius caesar I was killed i' the capitol brutus killed me so let it be with caesar the noble brutus hath told you caesar was ambitious
1 1 1 1 1 1 1 1 1 1 1 1 1 1 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2
Term Doc # ambitious be brutus brutus capitol caesar caesar caesar did enact hath I I i' it julius killed killed let me noble so the the told you was was with
15
2 2 1 2 1 1 2 2 1 1 1 1 1 1 2 1 1 1 2 1 2 2 1 2 2 2 1 2 2
Multiple term entries in a single document are merged. Frequency information is added.
Why frequency? Will discuss later.
Prasad
L3InvertedIndex
Term Doc # ambitious be brutus brutus capitol caesar caesar caesar did enact hath I I i' it julius killed killed let me noble so the the told you was was with
2 2 1 2 1 1 2 2 1 1 1 1 1 1 2 1 1 1 2 1 2 2 1 2 2 2 1 2 2
Term Doc # ambitious be brutus brutus capitol caesar caesar did enact hath I i' it julius killed let me noble so the the told you was was with
2 2 1 2 1 1 2 1 1 2 1 1 2 1 1 2 1 2 2 1 2 2 2 1 2 2
Term freq 1 1 1 1 1 1 2 1 1 1 2 1 1 1 2 1 1 1 1 1 1 1 1 1 1 1
16
Term Doc # ambitious be brutus brutus capitol caesar caesar did enact hath I i' it julius killed let me noble so the the told you was was with
Doc # 2 2 1 2 1 1 2 1 1 2 1 1 2 1 1 2 1 2 2 1 2 2 2 1 2 2
Freq 1 1 1 1 1 1 2 1 1 1 2 1 1 1 2 1 1 1 1 1 1 1 1 1 1 1
Prasad
L3InvertedIndex
17
Freq 2 2 1 2 1 1 2 1 1 2 1 1 2 1 1 2 1 2 2 1 2 2 2 1 2 2 1 1 1 1 1 1 2 1 1 1 2 1 1 1 2 1 1 1 1 1 1 1 1 1 1 1
Terms
Prasad
L3InvertedIndex
Pointers
18
Query Processing
What? How?
Prasad
L3InvertedIndex
19
Consider processing the query: Brutus AND Caesar n Locate Brutus in the Dictionary;
n
Brutus 34 Caesar
20
Prasad
L3InvertedIndex
The merge
n
Walk through the two postings simultaneously, in time linear in the total number of postings entries
2 1
4 2
8 3
16 5
32 8 13
64 21
128
Brutus 34 Caesar
If the list lengths are x and y, the merge takes O(x+y) operations. Crucial: postings sorted by docID.
Prasad L3InvertedIndex
21
Boolean Queries are queries using AND, OR and NOT to join query terms
n n
n n
Primary commercial retrieval tool for 3 decades. Professional searchers (e.g., lawyers) still like Boolean queries:
n
Prasad
Example: WestLaw
n
http://www.westlaw.com/
n n n
Largest commercial (paying subscribers) legal search service (started 1975; ranking added 1992) Tens of terabytes of data; 700,000 users Majority of users still use boolean queries Example query:
n
What is the statute of limitations in cases involving the federal tort claims act? LIMIT! /3 STATUTE ACTION /S FEDERAL /2 TORT /3 CLAIM
L3InvertedIndex 23
Prasad
Example: WestLaw
n
http://www.westlaw.com/
n n
Another example query: n Requirements for disabled people to be able to access a workplace n disabl! /p access! /s work-site work-place (employment /3 place Note that SPACE is disjunction, not conjunction! Long, precise queries; proximity operators; incrementally developed; not like web search Professional searchers often like Boolean search: n Precision, transparency and control But that doesnt mean they actually work better ...
L3InvertedIndex 24
Prasad
Example Queries
n n n n
n n n n
AND/OR Connector ATLEAST n Command COMPANY Command HEADLINE Command LENGTH Command NOCAPS Command PRE/n (Preceded by n Words) Connector W/n (Within n Words) Connector W/p (Within Paragraph) Connector W/s (Within Sentence) Connector
Prasad
n n n
n n
election AND opinion poll ATLEAST5(free) COMPANY(Tivoli NOT IBM) gore vidal AND LENGTH(>1000) NOCAPS(aid) digital PRE/3 television airport W/5 noise W/5 nuisance olympic W/s bid
25
L3InvertedIndex
Query optimization
n n
Consider a query that is an AND of t terms. For each of the t terms, get its postings, then AND them together. What is the best order for query processing?
2 1 4 2 8 3 16 32 64 128 5 8 16 21 34
13 16
L3InvertedIndex 26
Process in order of increasing frequency: n start with smallest set, then keep cutting further.
This is why we kept freq in dictionary
2 1
4 2
8 3
16 32 64 128 5 8 13 21 34
13 16
L3InvertedIndex 27
n n
e.g., (madding OR crowd) AND (ignoble OR strife) Get freqs for all terms. Estimate the size of each OR by the sum of its freqs (conservative). Process in increasing order of OR sizes.
Prasad
L3InvertedIndex
28
Space Requirements
n
The space required for the vocabulary is rather small. According to Heaps law the vocabulary grows as O(n), where is a constant between 0.4 and 0.6 in practice. Size of inverted file as a percentage of text (all words, nonstop words)
Index Addressing words Addressing documents Addressing 256 blocks
Small collection Medium collection Large collection (1Mb) (200Mb)
Prasad
L3InvertedIndex
Space Requirements
n
To reduce space requirements, a technique called block addressing can be used n Advantages: n the number of pointers is smaller than positions n all the occurrences of a word inside a single block are collapsed to one reference n Disadvantages: n online (dynamic) search over the qualifying blocks necessary if exact positions are required
Prasad
L3InvertedIndex
30
What about phrases? n Stanford University Proximity: Find Gates NEAR Microsoft.
n n
Need index to capture position information in docs. Zones in documents: Find documents with (author = Ullman) AND (text contains automata).
Prasad
L3InvertedIndex
31
Even though Inverted Files is the method of choice, in the face of phrase and proximity queries, the following approaches were also developed:
n
Prasad
Adapted from Lectures by Prabhakar Raghavan (Yahoo and Stanford) and Christopher Manning (Stanford)
Prasad
L4DictonaryAndQP
33
Difficulties with tokenization Improving efficiency using enhanced data structures and algorithms : Skip pointers Phrasal queries
n
34
Token stream.
Countrymen
Modified tokens.
roman
countryman 2 1 13 4 2 16
Inverted index.
roman countryman
Parsing a document
n
pdf/word/excel/html?
n n
Each of these is a classification problem. But these tasks are often done heuristically
36
Complications: Format/language
n
Documents being indexed can include docs from many different languages
n
French email with a German pdf attachment. A file? An email? (Perhaps one of many in an mbox.) An email with 5 attachments? A group of files (PPT or LaTeX in HTML) 37
Tokenization
38
Tokenization
n n
Each such token is now a candidate for an index entry, after further processing But what are valid tokens to emit?
39
Tokenization
n
San Francisco: one token or two? How do you decide it is one token?
40
Numbers
n n n n n
3/12/91 Mar. 12, 1991 55 B.C. B-52 My PGP key is 324a3df234cb23e 100.2.86.144
n
But often very useful: think about things like looking up error codes/stacktraces on the web (One answer is using n-grams.) Creation date, format, etc.
41
L'ensemble one token or two? n L ? L ? Le ? n Want lensemble to match with un ensemble German noun compounds are not segmented
n n
42
500$500K(6,000)
Katakana
Hiragana
Kanji
Romaji
43
Arabic (or Hebrew) is basically written right to left, but with certain items like numbers written left to right Words are separated, but letter forms within a word form complex ligatures
. start Algeria achieved its independence in 1962 after 132 years of French occupation. With Unicode, the surface presentation is 44 complex, but the stored form is straightforward
n n
Normalization
n
Need to normalize terms in indexed text as well as query terms into the same form
n
How are your users likely to write their queries for these words?
Even in languages that have accents, users often may not type them German: Tuebingen vs. Tbingen
n
Should be equivalent
46
Need to normalize indexed text as well as query terms into the same form 730 vs. 7/30 Character-level alphabet detection and conversion
n n
Tokenization not separable from this. Sometimes ambiguous: Morgen will ich in MIT
47
Case folding
n
Often best to lower case everything, since users will use lowercase regardless of correct capitalization
48
Stop words
n
With a stop list, you exclude from dictionary entirely, the commonest words. Intuition:
n n
They have little semantic content: the, a, and, to, be They take a lot of space: ~30% of postings for top 30
Good compression techniques mean the space for including stopwords in a system is very small Good query optimization techniques mean you pay little at query time for including stop words. You need them for:
n n n
Phrase queries: King of Denmark Various song titles, etc.: Let it be, To be or not to be Relational queries: flights to London
49
n n
When the document contains automobile, index it under car as well (usually, also viceversa) When the query contains automobile, look under car as well
Or expand query?
n
50
Soundex
n
51
Lemmatization
n
the boy's cars are different colors the boy car be different color Lemmatization implies doing proper reduction to dictionary headword form
52
Stemming
n
Reduce terms to their roots before indexing Stemming suggest crude affix chopping
n n
language dependent e.g., automate(s), automatic, automation all reduced to automat. for exampl compress and compress ar both accept as equival to compress
53
for example compressed and compression are both accepted as equivalent to compress.
Porters algorithm
n
Results suggest at least as good as other stemming options phases applied sequentially each phase consists of a set of commands sample convention: Of the rules in a compound command, select the one that applies to the longest suffix.
54
sses ss ies i ational ate tional tion Weight of word sensitive rules (m>1) EMENT
n n
n n
Other stemmers
n
Single-pass, longest suffix removal (about 250 rules) Motivated by linguistics as well as IR
Full morphological analysis at most modest benefits for retrieval Do stemming and other normalizations help?
n
Often very mixed results: really help recall for some queries but harm precision on others 56
Language-specificity
n
These are plug-in addenda to the indexing process Both open source and commercial plug-ins available for handling these
57
These may be grouped by language (or not). More on this in ranking/query processing.
58
59
Walk through the two postings simultaneously, in time linear in the total number of postings entries
2 1 4 2 8 3 16 5 32 8 64 17 21 128 Brutus 31 Caesar
If the list lengths are m and n, the merge takes O(m+n) operations. Can we do better? Yes, if index isnt changing too fast.
60
2
8
16
32
31
64
128
1
n
17
21
31
Why?
n
To skip postings that will not figure in the search results. Where do we place skip pointers?
How?
n
61
Section 2.3 :
62
2
8
16
32
31
64
128
17
21
31
Suppose weve stepped through the lists until we process 8 on each list. When we get to 16 on the top list, we see that its successor is 32. But the skip successor of 8 on the lower list is 31, so we can skip ahead past the intervening postings. 63
Tradeoff:
n
More skips shorter skip spans more likely to skip. But lots of comparisons to skip pointers. Fewer skips few pointer comparison, but then long skip spans few successful skips.
64
Placing skips
n
n n
Simple heuristic: for postings of length L, use L evenly-spaced skip pointers. This ignores the distribution of query terms. Easy if the index is relatively static; harder if L keeps changing because of updates. This definitely used to help; with modern hardware it may not (Bahle et al. 2002)
n
The cost of loading a bigger postings list outweighs the gain from quicker in-memory merging
65
Phrase queries
66
Phrase queries
n
Want to answer queries such as stanford university as a phrase Thus the sentence I went to university at Stanford is not a match.
n
The concept of phrase queries easily understood by users; about 10% of web queries are phrase queries
Index every consecutive pair of terms in the text as a phrase For example the text Friends, Romans, Countrymen would generate the biwords
n n
Each of these biwords is now a dictionary term Two-word phrase query-processing is now immediate.
68
Without the docs, we cannot verify that the docs matching the above Boolean query do contain the phrase.
Extended biwords
n
Parse the indexed text and perform part-of-speechtagging (POST). Bucket the terms into (say) Nouns (N) and articles/ prepositions (X). Now deem any string of terms of the form NX*N to be an extended biword.
n
70
False positives, as noted before Index blowup due to bigger dictionary For extended biword index, parsing longer queries into conjunctions:
n
E.g., the query tangerine trees and marmalade skies is parsed into tangerine trees AND trees and marmalade AND marmalade skies
71
72
Can compress position values/offsets Nevertheless, this expands postings storage substantially
73
Extract inverted index entries for each distinct term: to, be, or, not. Merge their doc:position lists to enumerate all positions with to be or not to be.
n
to:
n
be:
n
Proximity queries
n
LIMIT! /3 STATUTE /3 FEDERAL /2 TORT Here, /k means within k words of. Clearly, positional indexes can be used for such queries; biword indexes cannot.
75
Can compress position values/offsets Nevertheless, a positional index expands postings storage substantially Nevertheless, it is now used because of the power and usefulness of phrase and proximity queries whether used explicitly or implicitly in a ranking retrieval system.
76
Need an entry for each occurrence, not just once per document Index size depends on average document Why? size
n n
Average web page has <1000 terms SEC filings, books, even some epic poems easily 100,000 terms
Postings 1 1
Positional postings
Rules of thumb
n
A positional index is 24 times as large as a nonpositional index Positional index size 3550% of volume of original text Caveat: all of this holds for English-like languages
For particular phrases (Michael Jackson, Britney Spears) it is inefficient to keep on merging positional postings lists
n
78