Lecture4 Compression V1
Lecture4 Compression V1
Introduction to
Information Retrieval
CS276: Information Retrieval and Web Search
Christopher Manning and Pandu Nayak
Today
3
Introduction to Information Retrieval Ch. 5
4
Introduction to Information Retrieval Ch. 5
7
Introduction to Information Retrieval Sec. 5.1
8
Introduction to Information Retrieval Ch. 5
Compression
Now, we will consider compressing the space
for the dictionary and postings. We’ll do:
Basic Boolean index only
No study of positional indexes, etc.
But these ideas can be extended
9
Introduction to Information Retrieval Sec. 5.2
DICTIONARY COMPRESSION
10
Introduction to Information Retrieval Sec. 5.2
11
Introduction to Information Retrieval Sec. 5.2
14
Introduction to Information Retrieval Sec. 5.2
15
Introduction to Information Retrieval Sec. 5.2
Blocking
Store pointers to every kth term string.
Example below: k=4.
Need to store term lengths (1 extra byte)
….7systile9syzygetic8syzygial6syzygy11szaibelyite8szczecin9szomo….
17
Introduction to Information Retrieval Sec. 5.2
Exercises
Estimate the space usage (and savings compared to
7.6 MB) with blocking, for block sizes of k = 4, 8 and
16.
20
Introduction to Information Retrieval Sec. 5.2
Front coding
Front-coding:
Sorted words commonly have long common prefix – store
differences only
(for last k-1 in a block of k)
8automata8automate9automatic10automation
8automat*a1e2ic3ion
+ blocking, k = 4 7.1
22
Introduction to Information Retrieval Sec. 5.3
POSTINGS COMPRESSION
23
Introduction to Information Retrieval Sec. 5.3
Postings compression
The postings file is much larger than the dictionary,
factor of at least 10, often over 100 times larger
Key desideratum: 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.
24
Introduction to Information Retrieval Sec. 5.3
25
Introduction to Information Retrieval Sec. 5.3
26
Introduction to Information Retrieval Sec. 5.3
27
Introduction to Information Retrieval Sec. 5.3
Unary code
Represent n as n 1s with a final 0.
Unary code for 3 is 1110.
Unary code for 40 is
11111111111111111111111111111111111111110 .
Unary code for 80 is:
11111111111111111111111111111111111111111111
1111111111111111111111111111111111110
This doesn’t look promising, but….
Optimal if P(n) = 2–n
We can use it as part of our solution
29
Introduction to Information Retrieval 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
30
Introduction to Information Retrieval Sec. 5.3
31
Introduction to Information Retrieval
34
Introduction to Information Retrieval Sec. 5.3
Example
docIDs 824 829 215406
gaps 5 214577
VB code 00000110 10000101 00001101
10111000 00001100
10110001
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
37
Introduction to Information Retrieval Sec. 5.3
38
Introduction to Information Retrieval
39
Introduction to Information Retrieval
28 1-bit numbers
14 2-bit numbers
9 3-bit numbers
7 4-bit numbers
“selectors”
(9 total ways)
Introduction to Information Retrieval
43