Estimate how similar two big sets are by comparing tiny fingerprints.
MinHash shrinks a big set (for example, all the words in a web page) into a tiny signature of a few numbers. By comparing two signatures you can estimate how similar the two sets are, without looking at the sets again.
Suppose you have millions of documents and you want to find near-duplicates. Comparing every pair, word by word, is far too slow. We need a small fingerprint for each document, where similar documents get similar fingerprints.
First turn each document into a set, for example the set of all overlapping 5-word pieces (called shingles). The similarity of two documents is then the Jaccard index of their sets:
Now the trick. Take a random-looking hash function h and compute h(x) for every item in a set. Look at the smallest value. For two sets A and B, the smallest hash over A โช B belongs to a random item of the union. It is the same for A and B exactly when that item is in both sets. So:
In this made-up example 2 of 4 positions match, so the estimate is 2 / 4 = 0.5. (The true Jaccard is 2 shared / 4 total = 0.5.)
| Method | What it does | Note |
|---|---|---|
| MinHash with k hash functions | k min values per set | The classic form. Needs k hash computations for every item. |
| One permutation hashing and variants | Split items into k buckets and keep the min per bucket | Much cheaper to compute, with similar accuracy. |
| Locality-sensitive hashing (LSH) for MinHash | Cut the signature into bands, and compare only items that share a whole band | Finds likely-similar pairs without checking every pair. |
| SimHash | A different fingerprint, based on bit votes, for cosine similarity | Common for near-duplicate text, but not the same as MinHash. |
| Set A | 0 | 0 | 1 | 0 | 0 | 1 | 0 | 1 | 0 | 0 | 0 | 0 |
| Set B | 0 | 16 | 1 | 0 | 0 | 1 | 0 | 2 | 0 | 0 | 0 | 0 |
The estimate for k = 4 / 16 / 64 / 128 is 0.75 / 0.81 / 0.77 / 0.76. The true value is 0.82. Similarity here is the Jaccard index: items in both sets divided by items in either set. The hash functions are fixed, so the same choices always give the same numbers.
| Term | Meaning in easy words |
|---|---|
| Set | A group of different items, such as the shingles of a document |
| Jaccard index | Size of the intersection divided by size of the union. From 0 to 1 |
| Shingle | A short run of words or characters used as one item of a text set |
| Hash function | A function that maps each item to a number in a mixed-up order |
| Min-hash | The smallest hash value among a set's items, for one hash function |
| Signature (sketch) | The k min-hash values that stand for a set |
| Estimate | The share of equal signature positions, close to the true Jaccard |
| Near-duplicate | Two items that are almost, but not exactly, the same |
| LSH (locality-sensitive hashing) | A way to put similar items in the same bucket, so you avoid comparing all pairs |
| Band | A group of consecutive signature rows used by LSH |
| Unbiased estimator | An estimate that is right on average. Its errors have no built-in lean |
| Choice | We gain | We lose |
|---|---|---|
| Larger k | A more accurate estimate | More memory and more hashing work |
| Smaller k | Tiny signatures, fast to build | A noisy estimate |
| Short shingles | Catches small edits | Unrelated texts share many common shingles |
| Long shingles | More meaningful matches | Small edits break many shingles |
| Many LSH bands | Fewer missed similar pairs | More false candidates to check |
| Few LSH bands | Few candidates to check | More missed similar pairs |