Lecture 3: Index Representation and Tolerant Retrieval Information - - PowerPoint PPT Presentation

lecture 3 index representation and tolerant retrieval
SMART_READER_LITE
LIVE PREVIEW

Lecture 3: Index Representation and Tolerant Retrieval Information - - PowerPoint PPT Presentation

Lecture 3: Index Representation and Tolerant Retrieval Information Retrieval Computer Science Tripos Part II Helen Yannakoudakis 1 Natural Language and Information Processing (NLIP) Group helen.yannakoudakis@cl.cam.ac.uk 2018 1 Based on slides


slide-1
SLIDE 1

Lecture 3: Index Representation and Tolerant Retrieval

Information Retrieval Computer Science Tripos Part II Helen Yannakoudakis1

Natural Language and Information Processing (NLIP) Group helen.yannakoudakis@cl.cam.ac.uk

2018

1Based on slides from Simone Teufel and Ronan Cummins 99

slide-2
SLIDE 2

Overview

1 Recap 2 Dictionaries 3 Wildcard queries 4 Spelling correction

slide-3
SLIDE 3

IR System components

IR System Query Document Collection Set of relevant documents

Document Normalisation

Indexer UI Ranking/Matching Module

Query Norm.

Indexes

Last time: The indexer

100

slide-4
SLIDE 4

Challenges with equivalence classing

A term is an equivalence class of tokens. How do we define equivalence classes? Example: we want to match U.S.A. to USA – can this fail? Numbers (3/20/91 vs. 20/3/91) Case folding Stemming (Porter stemmer) Lemmatisation Equivalence classing challenges in other languages

101

slide-5
SLIDE 5

Positional indexes

Postings lists in a non-positional index: each posting is just a docID Postings lists in a positional index: each posting is a docID and a list of positions Example query: “to be or not to be” With a positional index, we can answer

phrase queries proximity queries

102

slide-6
SLIDE 6

IR System components

IR System Query Document Collection Set of relevant documents

Today: more indexing, some query normalisation

103

slide-7
SLIDE 7

Upcoming

Data structures for dictionaries

Hashes Trees k-term index Permuterm index

Tolerant retrieval: What to do if there is no exact match between query term and document term Spelling correction

104

slide-8
SLIDE 8

Overview

1 Recap 2 Dictionaries 3 Wildcard queries 4 Spelling correction

slide-9
SLIDE 9

Inverted Index

Brutus 1 2 4 45 31 11 174 173 Caesar 132 1 2 4 5 6 16 57 Calpurnia 54 101 2 31 8 9 4 179

105

slide-10
SLIDE 10

Dictionaries

Dictionary: the data structure for storing the term vocabulary Term vocabulary: the data For each term, we need to store a couple of items:

document frequency pointer to postings list

How do we look up a query term qi in the dictionary at query time?

106

slide-11
SLIDE 11

Data structures for looking up terms

Two different types of implementations: hashes and search trees. Some IR systems use hashes, some use search trees. Criteria for when to use hashes vs. search trees:

How many terms are we likely to have? Is the number likely to remain fixed, or will it keep growing? What are the relative frequencies with which various terms will be accessed?

107

slide-12
SLIDE 12

Hashes

Hash table: an array with a hash function

Input key; output integer: index in array. Hash function: determine where to store / search key. Hash function that minimises chance of collisions

Use all info provided by key (among others).

Each vocabulary term (key) is hashed into an integer. At query time: hash each query term, locate entry in array.

108

slide-13
SLIDE 13

Hashes

Hash table: an array with a hash function

Input key; output integer: index in array. Hash function: determine where to store / search key. Hash function that minimises chance of collisions

Use all info provided by key (among others).

Each vocabulary term (key) is hashed into an integer. At query time: hash each query term, locate entry in array. Pros: Lookup in a hash is faster than lookup in a tree. (Lookup time is constant.) Cons:

No easy way to find minor variants (resume vs. r´ esum´ e) No prefix search (all terms starting with automat) Need to rehash everything periodically if vocabulary keeps growing Hash function designed for current needs may not suffice in a few years’ time

108

slide-14
SLIDE 14

Search trees overcome many of these issues

Simplest tree: binary search tree Figure: partition vocabulary terms into two subtrees, those whose first letter is between a and m, and the rest (actual terms stored in the leafs). Anything that is on the left subtree is smaller than what’s on the right. Trees solve the prefix problem (find all terms starting with automat).

109

slide-15
SLIDE 15

Binary search tree

Cost of operations depends on height of tree. Keep height minimum / keep binary tree balanced: for each node, heights of subtrees differ by no more than 1. O(log M) search for balanced trees, where M is the size of the vocabulary. Search is slightly slower than in hashes But: re-balancing binary trees is expensive (insertion and deletion of terms).

110

slide-16
SLIDE 16

B-tree

Need to mitigate re-balancing problem – allow the number of sub-trees under an internal node to vary in a fixed interval. B-tree definition: every internal node has a number of children in the interval [a, b] where a, b are appropriate positive integers, e.g., [2, 4]. Figure: every internal node has between 2 and 4 children.

111

slide-17
SLIDE 17

Trie (from trie in retrieval)

t

  • e

d n a n n i A

An ordered tree data structure for strings

A tree where the keys are strings (keys “tea”, “ted”) Each node is associated with a string inferred from the position of the node in the tree (node stores bit indicating whether string is in collection)

Tries can be searched by prefixes: all descendants of a node have a common prefix of the string associated with that node Search time linear on length of term / key 2 The trie is sometimes called radix tree or prefix tree

2See https://thenextcode.wordpress.com/2015/04/12/trie-vs-bst-vs-hashtable/ 112

slide-18
SLIDE 18

Trie with postings

t

  • e

d n a n n i A

67444 206 117 2476 302 57743 10993 1 2 3 5 6 7 8 ... 10423 14301 17998 ... 15 28 29 100 103 298 ... 1 3 4 7 8 9 .... 249 11234 23001 ... 12 56 233 1009 ... 20451 109987 ... 113

slide-19
SLIDE 19

Overview

1 Recap 2 Dictionaries 3 Wildcard queries 4 Spelling correction

slide-20
SLIDE 20

Wildcard queries

hel* Find all docs containing any term beginning with “hel” Easy with trie: follow letters h-e-l and then lookup every term you find there *hel Find all docs containing any term ending with “hel” Maintain an additional trie for terms backwards Then retrieve all terms in subtree rooted at l-e-h In both cases: This procedure gives us a set of terms that are matches for the wildcard queries Then retrieve documents that contain any of these terms

114

slide-21
SLIDE 21

How to handle * in the middle of a term

hel*o We could look up “hel*” and “*o” in the tries as before and intersect the two term sets (expensive!). Solution: permuterm index – special index for general wildcard queries

115

slide-22
SLIDE 22

Permuterm index

For term hello$ (given $ to match the end of a term), store each of these rotations in the dictionary (trie): hello$, ello$h, llo$he, lo$hel, o$hell, $hello : permuterm vocabulary Rotate every wildcard query, so that the * occurs at the end: for hel*o$, look up o$hel* Problem: Permuterm more than quadrupels the size of the dictionary compared to normal trie (empirical number).

116

slide-23
SLIDE 23

k-gram indexes

More space-efficient than permuterm index Enumerate all character k-grams (sequence of k characters)

  • ccurring in a term and store in a dictionary

Character bi-grams from April is the cruelest month $a ap pr ri il l$ $i is s$ $t th he e$ $c cr ru ue el le es st t$ $m mo

  • n nt th h$

$ special word boundary symbol A postings list that points to all vocabulary terms containing a k-gram

117

slide-24
SLIDE 24

k-gram indexes

Note that we have two different kinds of inverted indexes: The term–document inverted index for finding documents based on a query consisting of terms The k-gram index for finding terms based on a query consisting of k-grams

118

slide-25
SLIDE 25

Processing wildcard queries in a (char) bigram index

Query hel* can now be run as: $h AND he AND el ... but this will show up many false positives like heel. Post-filter, then look up surviving terms in term–document inverted index. k-gram vs. permuterm index

k-gram index is more space-efficient permuterm index does not require post-filtering.

119

slide-26
SLIDE 26

Overview

1 Recap 2 Dictionaries 3 Wildcard queries 4 Spelling correction

slide-27
SLIDE 27

Spelling correction

an asterorid that fell form the sky information need: britney spears queries: britian spears, britney’s spears, brandy spears, prittany spears In an IR system, spelling correction is only ever run on queries. The general philosophy in IR is: don’t change the documents (exception: OCR’ed documents)

120

slide-28
SLIDE 28

Spelling correction

In an IR system, spelling correction is only ever run on queries. The general philosophy in IR is: don’t change the documents (exception: OCR’ed documents) Two different methods for spelling correction:

Isolated word spelling correction

Check each word on its own for misspelling Will only attempt to catch first typo above

Context-sensitive spelling correction

Look at surrounding words Should correct both typos above

121

slide-29
SLIDE 29

Isolated word spelling correction

There is a list of “correct” words – for instance a standard dictionary (Webster’s, OED. . . ) Then we need a way of computing the distance between a misspelled word and a correct word

for instance Edit/Levenshtein distance k-gram overlap

Return the “correct” word that has the smallest distance to the misspelled word. informaton → information

122

slide-30
SLIDE 30

Edit distance

Edit distance between two strings s1 and s2 is defined as the minimum number of basic operations that transform s1 into s2. Levenshtein distance: Admissible operations are insert, delete and replace Levenshtein distance dog – do 1 (delete) cat – cart 1 (insert) cat – cut 1 (replace) cat – act 2 (delete+insert)

123

slide-31
SLIDE 31

Levenshtein distance: Distance matrix

s n

  • w

1 2 3 4

  • 1

1 2 3 4 s 2 1 3 3 3 l 3 3 2 3 4

  • 4

3 3 2 3

124

slide-32
SLIDE 32

Dynamic Programming

Cormen et al: Optimal substructure: The optimal solution contains within it subsolutions, i.e, optimal solutions to subproblems Overlapping subsolutions: The subsolutions overlap and would be computed over and over again by a brute-force algorithm. For edit distance: Subproblem: edit distance of two prefixes Overlap: most distances of prefixes are needed 3 times (when moving right, diagonally, down in the matrix)

125

slide-33
SLIDE 33

Example: Edit Distance oslo – snow

s n

  • w

1 1 2 2 3 3 4 4

  • 1

1 s 2 2 l 3 3

  • 4

4

126

slide-34
SLIDE 34

Example: Edit Distance oslo – snow

s n

  • w

1 1 2 2 3 3 4 4

  • 1

1 1 2 2 s 2 2 l 3 3

  • 4

4

126

slide-35
SLIDE 35

Example: Edit Distance oslo – snow

s n

  • w

1 1 2 2 3 3 4 4

  • 1

1 1 2 2 1 s 2 2 l 3 3

  • 4

4

126

slide-36
SLIDE 36

Example: Edit Distance oslo – snow

s n

  • w

1 1 2 2 3 3 4 4

  • 1

1 1 2 2 1 2 3 2 s 2 2 l 3 3

  • 4

4

126

slide-37
SLIDE 37

Example: Edit Distance oslo – snow

s n

  • w

1 1 2 2 3 3 4 4

  • 1

1 1 2 2 1 2 3 2 2 s 2 2 l 3 3

  • 4

4

126

slide-38
SLIDE 38

Example: Edit Distance oslo – snow

s n

  • w

1 1 2 2 3 3 4 4

  • 1

1 1 2 2 1 2 3 2 2 2 4 3 s 2 2 l 3 3

  • 4

4

126

slide-39
SLIDE 39

Example: Edit Distance oslo – snow

s n

  • w

1 1 2 2 3 3 4 4

  • 1

1 1 2 2 1 2 3 2 2 2 4 3 2 s 2 2 l 3 3

  • 4

4

126

slide-40
SLIDE 40

Example: Edit Distance oslo – snow

s n

  • w

1 1 2 2 3 3 4 4

  • 1

1 1 2 2 1 2 3 2 2 2 4 3 2 4 5 3 s 2 2 l 3 3

  • 4

4

126

slide-41
SLIDE 41

Example: Edit Distance oslo – snow

s n

  • w

1 1 2 2 3 3 4 4

  • 1

1 1 2 2 1 2 3 2 2 2 4 3 2 4 5 3 3 s 2 2 l 3 3

  • 4

4

126

slide-42
SLIDE 42

Example: Edit Distance oslo – snow

s n

  • w

1 1 2 2 3 3 4 4

  • 1

1 1 2 2 1 2 3 2 2 2 4 3 2 4 5 3 3 s 2 2 1 2 3 l 3 3

  • 4

4

126

slide-43
SLIDE 43

Example: Edit Distance oslo – snow

s n

  • w

1 1 2 2 3 3 4 4

  • 1

1 1 2 2 1 2 3 2 2 2 4 3 2 4 5 3 3 s 2 2 1 2 3 1 l 3 3

  • 4

4

126

slide-44
SLIDE 44

Example: Edit Distance oslo – snow

s n

  • w

1 1 2 2 3 3 4 4

  • 1

1 1 2 2 1 2 3 2 2 2 4 3 2 4 5 3 3 s 2 2 1 2 3 1 2 3 2 l 3 3

  • 4

4

126

slide-45
SLIDE 45

Example: Edit Distance oslo – snow

s n

  • w

1 1 2 2 3 3 4 4

  • 1

1 1 2 2 1 2 3 2 2 2 4 3 2 4 5 3 3 s 2 2 1 2 3 1 2 3 2 2 3 3 3 3 3 4 4 3 l 3 3 3 2 4 2 2 3 3 2 3 4 3 3 4 4 4 4

  • 4

4 4 3 5 3 3 3 4 3 2 4 4 2 4 5 3 3

126

slide-46
SLIDE 46

Example: Edit Distance oslo – snow

s n

  • w

1 1 2 2 3 3 4 4

  • 1

1 1 2 2 1 2 3 2 2 2 4 3 2 4 5 3 3 s 2 2 1 2 3 1 2 3 2 2 3 3 3 3 3 4 4 3 l 3 3 3 2 4 2 2 3 3 2 3 4 3 3 4 4 4 4

  • 4

4 4 3 5 3 3 3 4 3 2 4 4 2 4 5 3 3 Edit distance oslo–snow is 3!

126

slide-47
SLIDE 47

Example: Edit Distance oslo – snow

s n

  • w

1 1 2 2 3 3 4 4

  • 1

1 1 2 2 1 2 3 2 2 2 4 3 2 4 5 3 3 s 2 2 1 2 3 1 2 3 2 2 3 3 3 3 3 4 4 3 l 3 3 3 2 4 2 2 3 3 2 3 4 3 3 4 4 4 4

  • 4

4 4 3 5 3 3 3 4 3 2 4 4 2 4 5 3 3 How do I read out the editing operations that transform oslo into snow?

126

slide-48
SLIDE 48

Example: Edit Distance oslo – snow

s n

  • w

1 1 2 2 3 3 4 4

  • 1

1 1 2 2 1 2 3 2 2 2 4 3 2 4 5 3 3 s 2 2 1 2 3 1 2 3 2 2 3 3 3 3 3 4 4 3 l 3 3 3 2 4 2 2 3 3 2 3 4 3 3 4 4 4 4

  • 4

4 4 3 5 3 3 3 4 3 2 4 4 2 4 5 3 3

cost

  • peration

input

  • utput

1 insert * w

126

slide-49
SLIDE 49

Example: Edit Distance oslo – snow

s n

  • w

1 1 2 2 3 3 4 4

  • 1

1 1 2 2 1 2 3 2 2 2 4 3 2 4 5 3 3 s 2 2 1 2 3 1 2 3 2 2 3 3 3 3 3 4 4 3 l 3 3 3 2 4 2 2 3 3 2 3 4 3 3 4 4 4 4

  • 4

4 4 3 5 3 3 3 4 3 2 4 4 2 4 5 3 3

cost

  • peration

input

  • utput

(copy)

  • 1

insert * w

126

slide-50
SLIDE 50

Example: Edit Distance oslo – snow

s n

  • w

1 1 2 2 3 3 4 4

  • 1

1 1 2 2 1 2 3 2 2 2 4 3 2 4 5 3 3 s 2 2 1 2 3 1 2 3 2 2 3 3 3 3 3 4 4 3 l 3 3 3 2 4 2 2 3 3 2 3 4 3 3 4 4 4 4

  • 4

4 4 3 5 3 3 3 4 3 2 4 4 2 4 5 3 3

cost

  • peration

input

  • utput

1 replace l n (copy)

  • 1

insert * w

126

slide-51
SLIDE 51

Example: Edit Distance oslo – snow

s n

  • w

1 1 2 2 3 3 4 4

  • 1

1 1 2 2 1 2 3 2 2 2 4 3 2 4 5 3 3 s 2 2 1 2 3 1 2 3 2 2 3 3 3 3 3 4 4 3 l 3 3 3 2 4 2 2 3 3 2 3 4 3 3 4 4 4 4

  • 4

4 4 3 5 3 3 3 4 3 2 4 4 2 4 5 3 3

cost

  • peration

input

  • utput

(copy) s s 1 replace l n (copy)

  • 1

insert * w

126

slide-52
SLIDE 52

Example: Edit Distance oslo – snow

s n

  • w

1 1 2 2 3 3 4 4

  • 1

1 1 2 2 1 2 3 2 2 2 4 3 2 4 5 3 3 s 2 2 1 2 3 1 2 3 2 2 3 3 3 3 3 4 4 3 l 3 3 3 2 4 2 2 3 3 2 3 4 3 3 4 4 4 4

  • 4

4 4 3 5 3 3 3 4 3 2 4 4 2 4 5 3 3

cost

  • peration

input

  • utput

1 delete

  • *

(copy) s s 1 replace l n (copy)

  • 1

insert * w

126

slide-53
SLIDE 53

Each cell of Levenshtein matrix

Cost of getting here from my upper left neighbour (by copy or replace) Cost of getting here from my upper neighbour (by delete) Cost of getting here from my left neighbour (by insert) Minimum cost out of these

127

slide-54
SLIDE 54

Levenshtein Distance: Four cells

s n

  • w

1 1 2 2 3 3 4 4

  • 1

1 1 2 2 1 2 3 2 2 2 4 3 2 4 5 3 3 s 2 2 1 2 3 1 2 3 2 2 3 3 3 3 3 4 4 3 l 3 3 3 2 4 2 2 3 3 2 3 4 3 3 4 4 4 4

  • 4

4 4 3 5 3 3 3 4 3 2 4 4 2 4 5 3 3

Example: (2, 2): Upper left: cost to replace “o” to “s” (cost: 0+1) Upper right: come from above where I have already inserted “s”: all I need to do is delete “o” (cost: 1+1) Bottom left: come from left neighbour where I have deleted “o”: all I need to do is insert “s” (cost: 1+1) Then choose the minimum of the three (bottom right).

128

slide-55
SLIDE 55

Using edit distance for spelling correction

Given a query, enumerate all character sequences within a pre-set edit distance. Intersect this list with our list of “correct” words. Suggest terms in the intersection to user.

129

slide-56
SLIDE 56

k-gram indexes for spelling correction

Enumerate all k-grams in the query term Misspelled word bordroom bo – or – rd – dr – ro – oo – om Use k-gram index to retrieve “correct” words that match query term k-grams Threshold by number of matching k-grams

  • Eg. only vocabularly terms that differ by at most 3 k-grams

rd aboard ardent

boardroom

border

  • r

border lord morbid sordid bo aboard about

boardroom

border

✲ ✲ ✲ ✲ ✲ ✲ ✲ ✲ ✲ ✲ ✲ ✲

130

slide-57
SLIDE 57

Context-sensitive Spelling correction

One idea: hit-based spelling correction flew form munich Enumerate corrections of each of the query terms flew → flea form → from munich → munch Holding all other terms fixed, try all possible phrase queries for each replacement candidate flea form munich – 62 results flew from munich –78900 results flew form munch – 66 results Not efficient. Better source of information: large corpus of queries, not documents

131

slide-58
SLIDE 58

General issues in spelling correction

User interface

automatic vs. suggested correction “Did you mean” only works for one suggestion; what about multiple possible corrections? Trade-off: Simple UI vs. powerful UI

Cost

Potentially very expensive Avoid running on every query Maybe just those that match few documents

132

slide-59
SLIDE 59

Takeaway

What to do if there is no exact match between query term and document term Data structures for tolerant retrieval:

Dictionary as hash, B-tree or trie k-gram index and permuterm for wildcards k-gram index and edit-distance for spelling correction

133

slide-60
SLIDE 60

Reading

Wikipedia article ”trie” MRS chapter 3.1, 3.2, 3.3

134