Download presentation
Presentation is loading. Please wait.
Published byAshlee Bennett Modified over 9 years ago
1
1
2
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
3
Unstructured (text) vs. structured (database) data 3 1996
4
Unstructured (text) vs. structured (database) data 4 2006
5
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 ?
6
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
7
Term-document incidence 7 1 if file contains word, 0 otherwise Brutus AND Caesar but NOT Calpurnia N documents m terms
8
Incidence vectors 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. 8 N documents m terms Brutus AND Caesar but NOT Calpurnia
9
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
10
Space requirements 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 N=1mil documents M=0.5mil terms
11
Does the matrix fits in memory? 500K x 1M matrix has 500 Billion 0’s and 1’s. But matrix is extremely sparse it has no more than 1 Billion 1’s. What’s a better representation than a matrix? We only record the 1 positions. 11 Why? N documents m terms 1 1 1 1 1 1 1 1 11 1 1 11 1 1 11 1 1 11 1 1 11 1 11 1 1 11 1 1 11 1 11 1 11 1 1
12
“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? 12 Brutus Calpurnia Caesar 12358132134 248163264128 1316 What happens if the word Caesar is added to document 14?
13
Inverted index Linked lists generally preferred to arrays + Dynamic space allocation + Insertion of terms into documents easy – Space overhead of pointers 13 Brutus Calpurnia Caesar 248163264128 2358132134 1316 1 Dictionary Postings lists Sorted by docID Posting
14
Inverted index construction 14 Tokenizer Token stream. Friends Romans countrymen Linguistic modules Modified tokens. friend romancountryman Indexer Inverted index. friend roman countryman 24 2 13 16 1 More on these later. Documents to be indexed. Friends, Romans, countrymen.
15
Indexer step 1: Token sequence INPUT: Sequence of pairs: (Modified token, Document ID) 15 I did enact Julius Caesar I was killed i' the Capitol; Brutus killed me. Doc 1 So let it be with Caesar. The noble Brutus hath told you Caesar was ambitious Doc 2
16
Indexer step 2: Sort Sort by terms. 16 Core indexing step.
17
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. 17 Why frequency? Will discuss later. DictionaryPostings
18
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: 18 128 34 248163264123581321 Brutus Caesar
19
The Intersection Walk through the two postings simultaneously. What did we call this process in CS230? Time? _______ in the total number of postings entries 19 34 12824816 3264 12 3 581321 128 34 248163264123581321 Brutus Caesar 2 8 If the list lengths are x and y, the merge takes O(x+y) operations. Crucial: postings sorted by docID.
20
Intersecting two postings lists 20
21
Query Optimization Best order for processing pairs of postings? (Brutus AND Calpurnia) AND Caesar (Calpurnia AND Caesar) AND Brutus (Brutus AND Caesar) AND Calpurnia 21 Query: Brutus AND Calpurnia AND Caesar Brutus Calpurnia Caesar 12358132134 248163264128 1316
22
Query optimization example Process in order of increasing freq: start with smallest set, then keep cutting further. 22 Brutus Calpurnia Caesar 12358132134 248163264128 1316 This is why we kept freq in dictionary Execute the query as (Caesar AND Brutus) AND Calpurnia. Query: Brutus AND Calpurnia AND Caesar
23
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
24
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
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.