Skip to main content
QUICK REVIEW

[Paper Review] Fully Understanding the Hashing Trick

Casper Benjamin Freksen, Lior Kamma|arXiv (Cornell University)|May 22, 2018
Face and Expression RecognitionComputer Science10 citations
TL;DR

This paper provides a tight, asymptotic analysis of the hashing trick in feature hashing, establishing the exact tradeoff between the ℓ∞/ℓ2 ratio of input vectors, target dimension m, and error parameters ε, δ. It proves that feature hashing preserves ℓ2 norm up to ε relative error with probability at least 1−δ when m ≥ 2/(ε²δ), and shows empirically that the hidden constants in the asymptotic bounds are close to 1, confirming theoretical tightness in practice.

ABSTRACT

Feature hashing, also known as {\em the hashing trick}, introduced by Weinberger et al. (2009), is one of the key techniques used in scaling-up machine learning algorithms. Loosely speaking, feature hashing uses a random sparse projection matrix $A : \mathbb{R}^n o \mathbb{R}^m$ (where $m \ll n$) in order to reduce the dimension of the data from $n$ to $m$ while approximately preserving the Euclidean norm. Every column of $A$ contains exactly one non-zero entry, equals to either $-1$ or $1$. Weinberger et al. showed tail bounds on $\|Ax\|_2^2$. Specifically they showed that for every $\varepsilon, δ$, if $\|x\|_{\infty} / \|x\|_2$ is sufficiently small, and $m$ is sufficiently large, then $$\Pr[ \; | \;\|Ax\|_2^2 - \|x\|_2^2\; | < \varepsilon \|x\|_2^2 \;] \ge 1 - δ\;.$$ These bounds were later extended by Dasgupta \etal (2010) and most recently refined by Dahlgaard et al. (2017), however, the true nature of the performance of this key technique, and specifically the correct tradeoff between the pivotal parameters $\|x\|_{\infty} / \|x\|_2, m, \varepsilon, δ$ remained an open question. We settle this question by giving tight asymptotic bounds on the exact tradeoff between the central parameters, thus providing a complete understanding of the performance of feature hashing. We complement the asymptotic bound with empirical data, which shows that the constants "hiding" in the asymptotic notation are, in fact, very close to $1$, thus further illustrating the tightness of the presented bounds in practice.

Motivation & Objective

  • To resolve the long-standing open question of the precise tradeoff between ℓ∞/ℓ2 ratio, target dimension m, and error parameters ε, δ in feature hashing.
  • To provide a complete and tight characterization of the performance limits of feature hashing, settling prior asymptotic bounds.
  • To validate theoretical bounds with extensive empirical evaluation, showing that hidden constants in asymptotic notation are close to 1 in real-world scenarios.
  • To demonstrate that feature hashing achieves optimal performance when input vectors have well-distributed mass (low ℓ∞/ℓ2 ratio), outperforming denser methods in practice.

Proposed method

  • Proposes a new theoretical framework to derive tight asymptotic bounds on the concentration of ‖Ax‖₂² around ‖x‖₂² for feature hashing matrices A.
  • Analyzes the performance of feature hashing by modeling the distribution of the ℓ2 norm of the projected vector as a sum of independent, bounded random variables.
  • Uses a three-phase empirical evaluation: (1) generate random vectors with controlled ℓ∞/ℓ2 ratios, (2) measure failure probability δ for fixed m, ε, (3) estimate the maximal allowable ℓ∞/ℓ2 ratio ν(m, ε, δ) for which δ remains below target.
  • Empirically estimates the constant hidden in the Θ-notation of the theoretical bound by comparing measured ν values to theoretical predictions.
  • Employs double tabulation hashing for efficient and statistically strong random projections, ensuring the randomness required for theoretical guarantees.
  • Uses high-quality random number generators (Mersenne prime modulus) to ensure reproducibility and statistical independence across experiments.

Experimental results

Research questions

  • RQ1What is the exact asymptotic tradeoff between the ℓ∞/ℓ2 ratio of input vectors, target dimension m, and error parameters ε, δ in feature hashing?
  • RQ2Is the theoretical bound m ≥ 2/(ε²δ) tight for ensuring ‖Ax‖₂² ∈ [(1−ε)‖x‖₂², (1+ε)‖x‖₂²] with probability at least 1−δ?
  • RQ3How close are the hidden constants in the asymptotic bounds to 1 in practical settings, particularly for real-world machine learning data with well-distributed features?
  • RQ4Can both terms in the minimum expression of the theoretical bound be necessary, or is one term always dominant in practice?

Key findings

  • The paper establishes that m ≥ 2/(ε²δ) is a necessary and sufficient condition for feature hashing to preserve the ℓ2 norm within ε relative error with probability at least 1−δ.
  • Empirical evaluation shows that the constant hidden in the Θ-notation of the theoretical bound is at least 0.725 for most practical parameter ranges, with some outliers at 0.6 due to sparse vectors.
  • The bound is tight: there exist vectors where ‖Ax‖₂² deviates from ‖x‖₂² by more than ε‖x‖₂² when m < 2/(ε²δ), confirming the necessity of this threshold.
  • Both terms in the theoretical minimum expression are empirically necessary, as neither term alone suffices to bound the ℓ∞/ℓ2 ratio across all parameter regimes.
  • The empirical failure probability δ matches theoretical predictions closely, with measured ν(m, ε, δ) values aligning tightly with the theoretical bound across a wide range of ε and δ.
  • For vectors with ℓ∞/ℓ2 ratio ≤ 1, feature hashing achieves norm preservation with high probability even when m is significantly smaller than the Johnson-Lindenstrauss bound, demonstrating its practical superiority in well-distributed settings.

Read this paper

Open the full text in the Nubint reader and ask about any passage as you read.

Read this paper on Nubint

This review was generated by AI from the original paper. Please check the paper before citing it.