Lecture 5p2 - Index Construction & Compressing
Lecture 5p2 - Index Construction & Compressing
Lecture 5 part 2.
Index Construction & Compressing
Information Retrieval and Analysis
Vasily Sidorov
1
Ch. 5
Next up
2
Ch. 5
3
Ch. 5
5
Sec. 5.1
Exercise: give intuitions for all the ‘0’ entries. Why do some zero entries
correspond to big deltas in other columns?
6
Sec. 5.1
7
Sec. 5.1
8
Sec. 5.1
9
Sec. 5.1
Thus, M = 101.64T0.49 so
k = 101.64 ≈ 44 and b = 0.49.
10
Sec. 5.1
Exercises
• What is the effect of including spelling errors, vs.
automatically correcting spelling errors on Heaps’
law?
• Compute the vocabulary size M for this scenario:
—Looking at a collection of web pages, you find that
there are 3000 different terms in the first 10,000
tokens and 30,000 different terms in the first
1,000,000 tokens.
—Assume a search engine indexes a total of
20,000,000,000 (2 × 1010) pages, containing 200
tokens on average
—What is the size of the vocabulary of the indexed
collection as predicted by Heaps’ law? 11
Sec. 5.1
Zipf’s law
12
Sec. 5.1
Zipf consequences
• If the most frequent term (the) occurs cf1 times
—then the second most frequent term (of) occurs
cf1/2 times
—the third most frequent term (and) occurs cf1/3
times …
• Equivalent: cfi = K/i where K is a normalizing factor,
so
—log cfi = log K - log i
—Linear relationship between log cfi and log i
14
Ch. 5
Compression
•Now, we will consider compressing the space
for the dictionary and postings
—Basic Boolean index only
—Not considering positional indexes, etc.
—We will consider compression schemes
15
Sec. 5.2
16
Sec. 5.2
17
Sec. 5.2
18
Compressing the term list:
Dictionary-as-a-String
◼ Store dictionary as a (long) string of characters:
◼ Pointer to next word shows end of current word
◼ Hope to save up to 60% of dictionary space.
….systilesyzygeticsyzygialsyzygyszaibelyiteszczecinszomo….
19
Space for dictionary as a string
• 4 bytes per term for Freq
• 4 bytes per term for pointer to Postings
• 3 bytes per term pointer Now avg. 11
bytes/term,
• Avg. 8 bytes per term in term string not 20
20
Blocking
• Store pointers to every kth term string.
—Example below: k=4.
• Need to store term lengths (1 extra byte)
….7systile9syzygetic8syzygial6syzygy11szaibelyite8szczecin9szomo….
21
Net savings
• Example for block size k = 4
• Where we used 3 bytes/pointer without blocking
—3 x 4 = 12 bytes,
now we use 3 + 4 = 7 bytes.
Shaved another ~0.5MB. This reduces the size of the
dictionary from 7.6 MB to 7.1 MB.
• We can save more with larger k
• Will cause slower term lookup
Exercise: Why is it slower? Estimate the performance impact of k
Exercise: Estimate the space usage (and savings compared to
7.6 MB) with blocking, for block sizes of k = 8 and 16
22
Front coding
• Front-coding:
—Sorted words commonly have a long common prefix
– store differences only
—(for last k-1 in a block of k)
8automata8automate9automatic10automation
→8automat*a1e2ic3ion
Technique Size in MB
24
Sec. 5.3
Postings compression
• The postings file is much larger than the dictionary,
factor of at least 10
• Key goal: store each posting compactly
• A posting for our purposes is a docID
—For Reuters (800,000 documents), we would use 32
bits per docID when using 4-byte integers
—Alternatively, we can use log2 800,000 ≈ 20 bits per
docID
• Our goal: use far fewer than 20 bits per docID
25
Sec. 5.3
26
Sec. 5.3
27
Sec. 5.3
28
Sec. 5.3
29
Sec. 5.3
30
Sec. 5.3
Example
docIDs 824 829 215406
gaps 5 214577
VB code 00000110 10000101 00001101
10111000 00001100
10110001
33
Sec. 5.3
Gamma codes
• We can compress better with bit-level codes
—The Gamma code is the best known of these.
• Represent a gap G as a pair length and offset
• offset is G in binary, with the leading bit cut off
—For example 13 → 1101 → 101
• length is the length of offset
—For 13 (offset 101), this is 3.
• We encode length with unary code: 1110.
• Gamma code of 13 is the concatenation of length
and offset: 1110101
34
Sec. 5.3
35
Sec. 5.3
36
Sec. 5.3
37
Sec. 5.3
RCV1 compression
Data structure Size in MB
dictionary, fixed-width 11.2
dictionary, term pointers into string 7.6
with blocking, k = 4 7.1
with blocking & front coding 5.9
collection (text, xml markup etc) 3,600.0
collection (text) 960.0
Term-doc incidence matrix 40,000.0
postings, uncompressed (32-bit words) 400.0
postings, uncompressed (20 bits) 250.0
postings, variable byte encoded 116.0
postings, g-encoded 101.0
38
Sec. 5.3
39
Ch. 4