MinHash › Worked Example
Language AI HandbookAll chapters MinHash › Worked ExampleOne section · Sections in this chapter5 / 13 ↓
Reading tools Definitions & inline links
Choose your expertise level to adjust how many terms are explained. Beginners see more tooltips, experts see fewer to maintain reading flow. Hover over underlined terms for instant definitions.
Article links
Make inline references clickable
Let's walk through a concrete MinHash computation with a small example that you can follow step by step. This will solidify both the mechanics of the algorithm and the intuition behind why it works.
Suppose we have two documents:
- Document A: "data science is great"
- Document B: "data science is wonderful"
We extract 2-word shingles:
- A's shingles:
{data science, science is, is great} - B's shingles:
{data science, science is, is wonderful}
The intersection is {data science, science is}, with 2 elements. The union has 4 distinct shingles: {data science, science is, is great, is wonderful}. So the exact Jaccard similarity is:
Now suppose we assign integer IDs to the 4 distinct shingles: data science = 0, science is = 1, is great = 2, is wonderful = 3. We use two hash functions:
Computing hash values for each shingle ID:
- , , ,
- , , ,
Document A contains shingle IDs , so its MinHash signature is:
Document B contains shingle IDs , so its MinHash signature is:
The estimated Jaccard similarity is the fraction of positions where the signatures agree:
Both positions disagree, giving an estimate of 0. The true Jaccard is 0.5. This is a bad estimate, but that's expected: with only 2 hash functions, variance is enormous. The standard deviation at with is , so getting an estimate anywhere from 0 to 1 is quite plausible.
With hash functions, the standard deviation would be , and the estimate would almost certainly fall close to 0.5. This variance reduction is why practical MinHash implementations use 128 to 256 hash functions.