Beruflich Dokumente
Kultur Dokumente
Introduction to
Information Retrieval
Hinrich Schtze and Christina Lioma Lecture 3: Dictionaries and tolerant retrieval
Outline
Sec. 3.1
Sec. 3.1
A nave dictionary
An array of struct:
char[20] int Postings * 20 bytes 4/8 bytes 4/8 bytes How do we store a dictionary in memory efficiently? How do we quickly look up elements at query time?
Sec. 3.1
Sec. 3.1
Hashes
Each vocabulary term is hashed to an integer
(We assume youve seen hashtables before)
Pros:
Lookup is faster than for a tree: O(1)
Cons:
No easy way to find minor variants:
judgment/judgement
No prefix search [tolerant retrieval] If vocabulary keeps growing, need to occasionally do the expensive operation of rehashing everything
Sec. 3.1
Trees
Simplest: binary tree More usual: B-trees Trees require a standard ordering of characters and hence strings but we standardly have one Pros: Solves the prefix problem (terms starting with hyp) Cons: Slower: O(log M) [and this requires balanced tree] Rebalancing binary trees is expensive
But B-trees mitigate the rebalancing problem
Binary tree
Sec. 3.1
Tree: B-tree
a-hu hy-m
n-z
Definition: Every internal node has a number of children in the interval [a,b] where a, b are appropriate natural numbers, e.g., [2,4].
Outline
Sec. 3.2
Wild-card queries: *
mon*: find all docs containing any word beginning mon. Easy with binary tree (or B-tree) lexicon: retrieve all words in range: mon w < moo *mon: find words ending in mon: harder
Maintain an additional B-tree for terms backwards. Can retrieve all words in range: nom w < non.
Exercise: from this, how can we enumerate all terms meeting the wild-card query pro*cent ?
12
Sec. 3.2
How can we handle *s in the middle of query term? We could look up co* AND *tion in a B-tree and intersect the two term sets
Expensive
The solution: transform wild-card queries so that the *s occur at the end This gives rise to the Permuterm Index.
Permuterm index
For term HELLO: add hello$, ello$h, llo$he, lo$hel, and o$hell to the B-tree where $ is a special symbol
14
15
Permuterm index
For HELLO, weve stored: hello$, ello$h, llo$he, lo$hel, and o$hell Queries
For X, look up X$ For X*, look up $X* For *X, look up X$* For *X*, look up X*
Permuterm index would better be called a permuterm tree. But permuterm index is the more common name.
16
Rotate query wildcard to the right Use B-tree lookup as before Problem: Permuterm more than quadruples the size of the dictionary compared to a regular B-tree. (empirical number)
17
k-gram indexes
More space-efficient than permuterm index Enumerate all character k-grams (sequence of k characters) occurring in a term 2-grams are called bigrams. Example: from April is the cruelest month we get the bigrams: $a ap pr ri il l$ $i is s$ $t th he e$ $c cr ru ue el le es st t$ $m mo on nt h$ $ is a special word boundary symbol, as before. Maintain an inverted index from bigrams to the terms that contain the bigram
18
19
20
21
Sec. 3.2.2
Outline
We will study several alternatives. weighted edit distance Edit distance and Levenshtein distance k-gram overlap
24
25
Edit distance
The edit distance between string s1 and string s2 is the minimum number of basic operations that convert s1 to s2. Levenshtein distance: The admissible basic operations are insert, delete, and replace Levenshtein distance dog-do: 1 Levenshtein distance cat-cart: 1 Levenshtein distance cat-cut: 1 Levenshtein distance cat-act: 2
26
27
28
29
30
31
32
33
Exercise
Compute
Levenshtein distance matrix for OSLO SNOW What are the Levenshtein editing operations that transform cat into catcat?
34
35
36
37
38
39
40
41
How do I read out the editing operations that transform OSLO into SNOW?
42
43
44
45
46
47
48
49
50
51
52
Outline
Sec. 3.3
Spell correction
Two main flavors:
Isolated word
Check each word on its own for misspelling Will not catch typos resulting in correctly spelled words e.g., from form
Context-sensitive
Look at surrounding words, e.g., I flew form Heathrow to Narita.
Correcting queries
First: isolated word spelling correction Premise 1: There is a list of correct words from which the correct spellings come. Premise 2: We have a way of computing the distance between a misspelled word and a correct word. Simple spelling correction algorithm: return the correct word that has the smallest distance to the misspelled word. Example: informaton information For the list of correct words, we can use the vocabulary of all words that occur in our collection. Why is this problematic?
55
A standard dictionary (Websters, OED etc.) An industry-specific dictionary (for specialized IR systems)
56
57
58
Sec. 3.3.4
Jaccard coefficient
A commonly-used measure of overlap Let X and Y be two sets; then the J.C. is
X Y / X Y
Equals 1 when X and Y have the same elements and zero when they are disjoint X and Y dont have to be of the same size
60
Sec. 3.3.5
Sec. 3.3.5
Context-sensitive correction
Need surrounding context to catch this. First idea: retrieve dictionary terms close (in weighted edit distance) to each query term Now try all possible resulting phrases with one word fixed at a time
flew from heathrow fled form heathrow flea form heathrow
Hit-based spelling correction: Suggest the alternative that has lots of hits.
Outline
Soundex
Soundex is the basis for finding phonetic (as opposed to orthographic) alternatives. Example: chebyshev / tchebyscheff Algorithm:
Turn every token to be indexed into a 4-character reduced form Do the same with query terms
64
Soundex algorithm
Retain
the first letter of the term. Change all occurrences of the following letters to 0 (zero): A, E, I, O, U, H, W, Y Change letters to digits as follows: B, F, P, V to 1 C, G, J, K, Q, S, X, Z to 2 D,T to 3 L to 4 M, N to 5 R to 6 Repeatedly remove one out of each pair of consecutive identical digits Remove all zeros from the resulting string; pad the resulting string with trailing zeros and return the first four positions, which will consist of a letter followed by three digits 65
66
67