The Jaccard similarity of two finite sets and is . A MinHash signature of a set is the vector of minima over independent random hash functions . For each , the two sets’ minima are equal with probability exactly , so the fraction of equal coordinates in two signatures is an unbiased estimate of with variance . Locality-sensitive hashing (LSH) with banding groups the coordinates into bands of and reports a pair as a candidate when all coordinates of some band agree, which happens with probability .

MinHash replaces each set, of any size, with numbers from which the similarity of any two sets can be estimated. Banding then finds the similar pairs without comparing all pairs. Each band’s values are hashed into a table, and only sets that share a bucket in some band are compared. The probability of sharing a bucket is a steep S-shaped function of , so pairs well above a threshold near are almost always found and pairs well below it are almost never compared.

Broder (1997) introduced MinHash to estimate the resemblance of web documents represented as sets of shingles, the overlapping runs of consecutive words. Indyk and Motwani (1998) defined locality-sensitive hash families for approximate nearest-neighbor search, and MinHash is such a family for Jaccard similarity. The same pipeline removes near-duplicate documents from the training corpora of language models.

The data

The series’ other notes use Wikimedia pageview records. Near-duplicate detection needs document text, and the Wikipedia article dumps were not reachable from the machine that ran the experiments, so the experiments use the minicrawl dataset that ClickHouse publishes. It holds the front page of each domain in a Tranco ranking of popular sites, fetched with curl, in one Parquet file dated 23 September 2023 with 7,613,078 rows. Front pages of popular sites contain many real near-duplicates, such as localized versions of one site, default server pages and the error pages of content delivery networks.

The experiments read the first 40 of the file’s 1,081 row groups, 156,432 pages from ranks 1 to 156,448. Each page’s HTML was reduced to its visible text (script, style, head and SVG elements removed), and pages with fewer than 50 words were dropped, leaving 91,548. A page’s set is its distinct word 5-shingles, each hashed to 64 bits. Pages with fewer than 50 distinct shingles were dropped and only the first page of each domain kept, leaving 91,116 pages with 100,765,252 shingles in total, a median of 732 per page, and 4,151,017,170 pairs.

An exact similarity join finds every pair with . It uses prefix filtering (Bayardo, Ma and Srikant 2007). With the tokens of every set ordered by one global order, rarest first, the prefixes of length of two sets with share at least one token, so an inverted index over the prefixes generates every qualifying pair, and each candidate is verified by merging the two full sets.

Pairs
0.31,153,538
0.51,140,543
0.71,106,443
0.81,071,859
0.9149,497
1.050,694

The distribution is bimodal. In 20,000 random pairs the mean similarity was 0.00041 and 99.13% had no shingle in common, while 93% of the pairs with have . Grouping pages connected by pairs with gives 16,222 clusters that hold 38,277 pages. The largest has 1,333 pages, nearly all the block page a security service returns to a blocked client (“Sorry, you have been blocked”), followed by 420 localized Google home pages, 260 CloudFront 403 pages and 152 Apache test pages. Because the number of pairs grows with the square of a cluster’s size, the largest cluster alone accounts for 887,397 (82.8%) of the pairs with and the four largest for 94.9%. Recall counted over pairs, as in the tables below, therefore mostly measures these clusters.

MinHash

Let be a random hash function that is injective on , and let be the element of with the smallest hash value. Each element of is equally likely to be . The minima of over and over are equal exactly when , so

With independent hash functions the number of equal coordinates is binomial with parameters and , and has mean and standard deviation . The error does not depend on the sizes of the sets. At it is at most , at .

The argument needs the minimum to be uniform over the elements of , which a fully random function provides. Broder, Charikar, Frieze and Mitzenmacher (2000) called families with this property min-wise independent; exact min-wise independence requires exponentially many permutations, and -approximate versions and -wise independent hashing give the property up to a small bias (see Hashing for sketches for the families). The experiments rehash each 64-bit shingle hash with , where is the splitmix64 finalizer and a random 64-bit seed.

The pairs found by the join overlap heavily (most lie in a few clusters), so their errors are correlated. To measure the estimator on independent pairs, the error was computed on a random maximal matching of the join’s pairs, 21,138 pairs with no page in two of them, together with 19,993 random pairs.

PairsRMSE, TheoryRMSE, TheoryRMSE, Theory
0 to 0.119,9930.00120.00110.00090.00060.00040.0003
0.3 to 0.51,1330.12270.12090.06210.06050.02990.0302
0.5 to 0.71,2090.12340.12160.06100.06080.02960.0304
0.7 to 0.92,9270.09380.09570.05040.04790.02340.0239
0.9 to 115,8690.02280.02220.01110.01110.00560.0056

The theory column is averaged over each bin’s pairs. The mean error was below 0.005 in every bin. Computing all 256 signatures took 19.8 seconds for the 100.8 million shingles on one core, 0.77 nanoseconds per shingle and hash function.

b-bit MinHash

A signature of 64-bit minima occupies bytes. Li and König (2010) showed that keeping only the lowest bits of each minimum loses less information per bit than keeping all of them when similarities of interest are high. Two -bit values agree when the full minima agree, or by chance with probability close to when they differ. For sets that are small relative to the hash range,

For and near 0 the variance is , so one-bit values estimate the similarity of unrelated pages with standard deviation . For near 1 the full minima rarely differ, so chance agreements contribute little, and the variance approaches , at most twice the variance with full minima. At a fixed budget of bits, a few wide values estimate low similarities better and many narrow values estimate high similarities better. The table gives the root mean squared errors at 256 bits per page, on the join’s pairs with and on the random pairs.

Join pairs, Random pairs
12560.0330.062
21280.0370.051
4640.0530.032
8320.0590.011

The full 64-bit signatures with , at 16,384 bits per page, give 0.021 and 0.0004. For near-duplicate detection, where the decision concerns pairs with above 0.5, one-bit values give errors 1.6 times those of 64-bit values at 1/64 of the space.

Banding

Comparing all signatures still takes time proportional to the number of pairs, 4.15 billion here. Banding, in the form described by Leskovec, Rajaraman and Ullman (chapter 3), splits the coordinates into bands of consecutive coordinates and, for each band, hashes the values of every page into a table. Two pages become a candidate pair if they share a bucket in at least one band. Their values in one band all agree with probability , and the bands use disjoint coordinates, so

As a function of this is an S-curve. Its steepest point lies near , the similarity at which the expected number of agreeing bands is 1. Larger makes the curve steeper and moves it right; larger moves it left. With 32 bands of 8 rows (), a pair with is missed with probability and a pair with becomes a candidate with probability .

The table gives each setting’s results on all 4,151,017,170 pairs, against the exact join. Candidates are distinct pairs; recall is the fraction of the 1,071,859 pairs with that became candidates.

CandidatesRecall, Candidates with
64 × 40.3541,156,9241.00005,852
50 × 50.4571,144,5751.0000510
32 × 80.6481,120,9650.999910
25 × 100.7251,092,4900.99140
20 × 100.7411,054,1730.96650
16 × 160.841701,9750.65060
8 × 320.937154,4130.14410

With 32 bands of 8, the candidates are 0.027% of all pairs and contain all but 68 of the pairs with . Within each similarity bin the measured fraction of pairs that became candidates matched averaged over the bin. The low counts of dissimilar candidates follow from the bimodal distribution. Of the random pairs, 99.13% have , which can never become candidates, and a pair with becomes a candidate with 50 bands of 5 with probability . The last two rows place the threshold above 0.8, and recall falls accordingly.

A candidate is a pair to verify, by comparing signatures or the full sets. Banding sets the recall; the verification step sets the precision.

The figure

Share of pairs that become candidates, by similarity

1 − (1 − sr)bmeasured, 20 bins of about 100 pairs
0.000.250.500.751.000.00.20.40.60.81.0(1/b)1/r = 0.648Jaccard similarity of the pair

With 32 bands of 8 rows, using 256 of the 256 hash functions, 813 of the 2,000 pairs are candidates: 400 of 400 with similarity 0.8 or more and 1 of 600 below 0.3. The MinHash estimate from the same 256 functions is off by 0.025 on average (root mean square).

On the full crawl of 91,116 pages, these settings made 1,120,965 candidate pairs out of 4,151,017,170, 0.027% of all pairs, and found 99.99% of the 1,071,859 pairs with similarity 0.8 or more.

MinHash estimate from the 256 hash functions in use

candidatenot a candidate±2 standard deviations, √(s(1 − s)/k)
0.000.250.500.751.000.00.20.40.60.81.0Jaccard similarity of the pair
Each point is a pair of front pages from the crawl, 2,000 pairs in all, 100 drawn from each similarity bin of width 0.05, with no page in two pairs. Their 256 MinHash agreements were recorded once; the figure groups the first b·r of them into b bands of r and marks a pair as a candidate when all r agree in at least one band. The product b·r is held at 256 or less.

The figure’s 2,000 pairs were chosen so that every similarity bin of width 0.05 is represented, which the crawl’s pairs do not provide. There are 100 pairs per bin, drawn from the join’s pairs, random pairs and pairs that share one of their first 64 MinHash values, with no page in two pairs. Their 256 MinHash agreements were recorded once from the same signatures as above, so moving a slider regroups recorded agreements and recomputes the candidates exactly as banding would. The upper chart compares each bin’s measured candidate fraction with the S-curve; the lower chart shows the MinHash estimate from the hash functions in use.

In practice

Lee et al. (2022) removed near-duplicate documents from language-model training corpora with MinHash over word 5-grams, a signature of 9,000 values and 450 bands of 20, whose S-curve has ; candidate pairs were kept as duplicates when their edit similarity exceeded 0.8. FineWeb (Penedo et al. 2024) uses 112 hash functions in 14 bands of 8 on word 5-grams, targeting documents at least 75% similar. By the formula above, that setting makes a pair with a candidate with probability 0.77 and a pair with with probability 0.988. Documents that share a bucket are merged into clusters transitively.

Computing hash values per shingle dominates the cost of signatures. One permutation hashing (Li, Owen and Zhang 2012) hashes each element once, divides the hash range into bins and keeps the minimum in each bin, with densification schemes filling empty bins for small sets. SuperMinHash (Ertl 2017) correlates the minima to reduce the estimator’s variance below for small sets.

Consequences

For near-duplicate detection on sets of shingles, MinHash with a few hundred hash functions estimates similarity within a few hundredths, at a cost independent of the size of the documents, and the measured error matched on independent pairs. Banding then reduces the 4.15 billion pairs to about a million candidates with recall above 0.99 for , when is placed about 0.1 below the similarity that matters. A steep S-curve requires both and to be large, so the number of hash functions is set by banding and can exceed what estimation alone requires, as with the 9,000 values of Lee et al.

On this crawl an exact join with prefix filtering finished in 108 seconds on one core at and 114 seconds at , because almost all pairs share no shingle and the prefixes are selective. Prefix filtering’s candidate set grows as the threshold falls and when sets share frequent tokens, while banding’s work is proportional to times the number of documents plus the number of candidates. The training-corpus pipelines above, over billions of documents, use banding.