Menu Big Learning

Hashing and sketching

When a vocabulary or stream is too large to store item by item, a compact representation can make a calculation feasible. Its collisions and approximations become part of the meaning of the answer.

A bank of thin upright cards set into rows in a slotted wooden tray.
Slots shared by many possible keys

A smaller feature vector

In a text classifier, a conventional dictionary might give every distinct word a separate coordinate. Feature hashing instead applies a function to a word and uses the result to choose one of a fixed number of buckets. Training and prediction must use the same function and bucket count.

Two words can land in one bucket. The model then has less freedom to give them separate effects. A signed hash can reduce systematic interference in some calculations, but it does not make the representation reversible. A larger vector trades memory for fewer collisions.

One feature contribution
  1. Read the word
  2. Choose a bucket
  3. Add its signed value

Counting an unbounded stream

A count–min sketch keeps several rows of counters. Each row uses its own hash function. An arriving item increments one counter in every row. To estimate the frequency of a particular item, read those counters and take the smallest value.

Suppose the three counters read 11, 9 and 12 after a stream of positive unit updates. The estimate is 9. A different item may have increased a shared counter, so even the smallest can be too high. The sketch can answer this query without retaining the sequence of arrivals.

What information survives?

Alex Smola’s 2011 talk used sketches for real-time data. Posters considered several hash functions, compressed minimum hashes and the interaction between the representation and a learning task. In 2013, a poster asked whether the hash function itself could be learned for a particular objective.

Principal component analysis has a different aim. It finds directions of variation in numerical data and projects observations onto a smaller set of axes. A contributed 2013 paper asked how such a projection could support distributed k-means clustering. A representation good for frequency queries and one good for distances need different evidence.

Further reading