[Paper Review] Hash Embeddings for Efficient Word Representations
This paper introduces hash embeddings, a novel method for efficient word representation that combines the benefits of standard word embeddings and feature hashing. By using k hash functions to select from a shared pool of embedding vectors and learning k trainable weights per token, hash embeddings enable dynamic vocabulary handling, implicit pruning, and reduced parameter count—achieving performance on par with or better than standard embeddings across multiple NLP tasks while drastically cutting model size.
We present hash embeddings, an efficient method for representing words in a continuous vector form. A hash embedding may be seen as an interpolation between a standard word embedding and a word embedding created using a random hash function (the hashing trick). In hash embeddings each token is represented by $k$ $d$-dimensional embeddings vectors and one $k$ dimensional weight vector. The final $d$ dimensional representation of the token is the product of the two. Rather than fitting the embedding vectors for each token these are selected by the hashing trick from a shared pool of $B$ embedding vectors. Our experiments show that hash embeddings can easily deal with huge vocabularies consisting of millions of tokens. When using a hash embedding there is no need to create a dictionary before training nor to perform any kind of vocabulary pruning after training. We show that models trained using hash embeddings exhibit at least the same level of performance as models trained using regular embeddings across a wide range of tasks. Furthermore, the number of parameters needed by such an embedding is only a fraction of what is required by a regular embedding. Since standard embeddings and embeddings constructed using the hashing trick are actually just special cases of a hash embedding, hash embeddings can be considered an extension and improvement over the existing regular embedding types.
Motivation & Objective
- To address the challenge of large vocabulary sizes in neural NLP models, which lead to excessive parameters and training overhead.
- To eliminate the need for pre-training vocabulary dictionaries and post-training pruning in models with large or dynamic vocabularies.
- To develop a hybrid approach that combines the expressiveness of standard embeddings with the efficiency of feature hashing.
- To enable online learning and dynamic vocabulary expansion without retraining or dictionary construction.
- To reduce model size and parameter count while maintaining or improving performance on downstream NLP tasks.
Proposed method
- Each token is represented by k d-dimensional embedding vectors selected via k hash functions from a shared pool of B vectors.
- A learnable k-dimensional weight vector is used to compute a weighted sum of the k selected embedding vectors, forming the final d-dimensional representation.
- The method uses the same hashing function for both component vectors and importance weights, though alternative hashing functions for weights are explored to reduce collision risks.
- The approach implicitly performs vocabulary pruning by only learning weights for relevant hash buckets, reducing effective parameter count.
- The final representation is a differentiable, continuous function of the model parameters, enabling end-to-end training with gradient-based optimization.
- The method supports both dictionary-free training and standard dictionary-based training, enabling flexibility across online and offline learning settings.
Experimental results
Research questions
- RQ1Can a hybrid embedding method combining hashing and learnable weights achieve performance comparable to standard word embeddings while reducing parameter count?
- RQ2How does the performance of hash embeddings compare to standard embeddings and feature hashing across diverse NLP classification tasks?
- RQ3To what extent can hash embeddings handle large or dynamically growing vocabularies without requiring a pre-defined dictionary or post-training pruning?
- RQ4Does the use of learnable weights over hash buckets provide a regularizing effect that improves generalization compared to standard embeddings?
- RQ5Can hash embeddings be effectively used in online learning scenarios where vocabulary is not known in advance?
Key findings
- Hash embeddings achieve performance on par with or better than standard embeddings across seven benchmark datasets, including AG, DBP, Yelp, and Amazon sentiment tasks.
- In five out of seven datasets, hash embeddings rank in the top three among state-of-the-art models, demonstrating strong competitive performance.
- The method reduces the number of parameters significantly compared to standard embeddings, especially for large vocabularies, while maintaining high accuracy.
- Performance remains stable and competitive even without a pre-defined vocabulary dictionary, enabling seamless online learning and dynamic vocabulary handling.
- Using different hash functions for component vectors and importance weights leads to a small but consistent performance improvement, reducing collision-related information loss.
- The model exhibits an inherent regularizing effect: only parameters relevant to active tokens are learned, effectively reducing overfitting and parameter count from the start.
Read this paper
Open the full text in the Nubint reader and ask about any passage as you read.
Read this paper on NubintThis review was generated by AI from the original paper. Please check the paper before citing it.