Consistent Weighted Sampling Made Fast, Small, and Easy

Bernhard Haeupler, Mark S. Manasse, Kunal TalwararXiv 2014

Abstract

Document sketching using Jaccard similarity has been a workable effective technique in reducing near-duplicates in Web page and image search results, and has also proven useful in file system synchronization, compression and learning applications. Min-wise sampling can be used to derive an unbiased estimator for Jaccard similarity and taking a few hundred independent consistent samples leads to compact sketches which provide good estimates of pairwise-similarity. Subsequent works extended this technique to weighted sets and show how to produce samples with only a constant number of hash evaluations for any element, independent of its weight. Another improvement by Li et al. shows how to speedup sketch computations by computing many (near-)independent samples in one shot. Unfortunately this latter improvement works only for the unweighted case. In this paper we give a simple, fast and accurate procedure which reduces weighted sets to unweighted sets with small impact on the Jaccard similarity. This leads to compact sketches consisting of many (near-)independent weighted samples which can be computed with just a small constant number of hash function evaluations per weighted element. The size of the produced unweighted set is furthermore a tunable parameter which enables us to run the unweighted scheme of Li et al. in the regime where it is most efficient. Even when the sets involved are unweighted, our approach gives a simple solution to the densification problem that other works attempted to address. Unlike previously known schemes, ours does not result in an unbiased estimator. However, we prove that the bias introduced by our reduction is negligible and that the standard deviation is comparable to the unweighted case. We also empirically evaluate our scheme and show that it gives significant gains in computational efficiency, without any measurable loss in accuracy.

Introduction

In large-scale data mining and web search, identifying "near-duplicate" documents or images is a critical computational challenge. The standard metric for this task is Jaccard Similarity, defined as the size of the intersection of two sets divided by the size of their union. While Min-wise hashing (MinHash) provides an efficient way to estimate this for unweighted sets, many real-world applications involve weighted sets, where items have varying levels of importance or frequency.

Previous methods for weighted Jaccard similarity were often computationally expensive—proportional to the total weight—or required a high number of hash function evaluations per element. While "one-permutation" hashing techniques have drastically accelerated unweighted sketching, they have historically been difficult to extend to the weighted case. This paper introduces a randomized rounding technique that bridges this gap, transforming weighted sets into unweighted ones while preserving their similarity characteristics.

Methodology

The core of the proposed approach is a two-step process: Randomized Rounding followed by Fast Unweighted Sketching.

1. Weighted-to-Unweighted Reduction

For an element with weight $w$, the algorithm decomposes the weight into an integer part ($j$) and a fractional part ($f$). The algorithm keeps the $j$ instances and includes the fractional part as an additional element with probability $f$ using a consistent hash. This transformation effectively maps a weighted set into a standard unweighted set.

2. Scaling and Multi-scaling

Because Jaccard similarity is scale-invariant, the authors scale the weights so the resulting unweighted set is large enough to ensure accuracy but small enough to maintain computational efficiency. To handle comparisons where the weights of the target set are unknown, a "multi-scale" approach is employed. This generates sketches at several different geometric scales (e.g., powers of 2), ensuring that at least one scale provides a dense enough representation for accurate estimation.

3. Integration with One-Permutation Hashing

Once the set is unweighted and "densified" (forced to a specific size via scaling), the authors apply the "one-permutation" hashing technique. This allows for the computation of hundreds of samples in a single pass over the data, rather than requiring independent hash evaluations for every desired sample.

Key Insights

Rounding and Bias

A primary insight of this work is that simple randomized rounding is "good enough" for practical applications. Although it introduces a non-zero bias, the authors demonstrate mathematically that this bias is $O(1/W)$ (where $W$ is the total weight). In real-world datasets with significant total weights, this bias becomes practically invisible.

Solving the Densification Problem

By choosing a specific scaling factor, users can control the size of the produced unweighted set. This ensures that the "one-permutation" bins are consistently filled, elegantly solving the accuracy issues (densification) that typically plague small or sparse sets in traditional MinHash implementations.

Computational Efficiency

The reduction acts as a wrapper, allowing any advancement in unweighted similarity estimation to be applied to weighted data. By reducing the number of hash evaluations from $O(nk)$ (where $k$ is the number of samples) to approximately $O(n + k)$, the scheme achieves massive speedups.

Results and Evaluation

The authors evaluated the scheme using synthetic datasets with Jaccard similarity levels ranging from 40% to 95%. This allowed for precise measurement of bias and variance against a known ground truth.

  • Speed: The proposed scheme is approximately two orders of magnitude faster than the previous gold standard (Ioffe’s consistent weighted sampling) under typical parameter settings.
  • Accuracy: Empirical tests showed that the average absolute error was comparable to existing unbiased estimators. In certain similarity ranges (0.8 to 0.9), the proposed method even outperformed existing techniques.
  • Theoretical Soundness: The authors provided rigorous proofs for size expectation and tail inequalities, confirming that the probability of large errors is exponentially small.

Conclusion

This paper provides a simple, fast, and accurate procedure to reduce weighted sets to unweighted sets with minimal impact on Jaccard similarity. By enabling the use of one-permutation hashing for weighted data, the method offers a significant leap in computational efficiency without a measurable loss in accuracy. Future work may involve exploring more complex averaging techniques across scales and validating the approach on massive real-world web corpuses.

Summary updated

BibTeX
@misc{haeupler2014consistent,
  author = {Bernhard Haeupler and Mark S. Manasse and Kunal Talwar},
  title = {{Consistent Weighted Sampling Made Fast, Small, and Easy}},
  year = {2014},
  eprint = {1410.4266},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/1410.4266},
}
Figure