Introduction
Word embeddings such as GloVe and fasttext have become fundamental components of modern Natural Language Processing (NLP). However, their deployment is often hindered by significant memory and computational requirements. A standard embedding model containing 2 million words represented as 300-dimensional floating-point vectors requires approximately 2.4 GB of storage. This footprint makes it challenging to run state-of-the-art models locally on resource-constrained devices like smartphones, often forcing a reliance on cloud-based processing that introduces latency and privacy concerns.
Furthermore, calculating similarities between real-valued vectors requires floating-point arithmetic, which is computationally expensive compared to bitwise operations. This paper introduces a novel autoencoder-based method to compress these high-dimensional embeddings into compact binary vectors (64 to 512 bits), achieving massive efficiency gains with minimal impact on accuracy.
Methodology
The proposed approach utilizes a specialized autoencoder architecture designed to transform real-valued embeddings into a binary latent space while preserving semantic information.
The Autoencoder Architecture
- Encoder: The encoder maps a real-valued vector $x$ through a linear layer followed by a Heaviside step function $h(\cdot)$. This function acts as a hard threshold, outputting a 1 for positive values and 0 otherwise, resulting in a compact binary vector $\Phi(x)$.
- Decoder: To ensure the binary representation retains the original information, a decoder attempts to reconstruct the original vector $\hat{y}$ from the binary code using a $tanh$ activation function.
Optimization and Regularization
Training such a model is non-trivial because the step function is non-differentiable. The authors overcome this by using the decoder's gradients to update the weights. A critical component of the loss function is a regularization term ($||W^T W - I||^2$) that forces the learned binary features to be uncorrelated. This ensures that each bit captures unique information, effectively maximizing the utility of the limited bit budget and preserving the semantic structure of the original space.
Experimental Setup
The model was evaluated using three major pre-trained embedding sets: dict2vec (2.3M words), fasttext (1M words), and GloVe (400k words). Performance was measured across a variety of benchmarks, including semantic similarity (MEN, SimLex-999), word analogy (Google dataset), and downstream document classification tasks (AG-News, Yelp).
Key Results and Discussion
The binarized embeddings demonstrate remarkable efficiency and near-lossless performance across most tasks.
Efficiency Gains
The transition to binary vectors enables a 37.5x reduction in memory (for 256-bit vectors) and a 30x speedup in top-k nearest neighbor queries. By leveraging bitwise XOR and popcount operations—which can often be executed in a single CPU cycle—the system achieves up to a 75x speedup when including model loading times.
Accuracy Preservation
As shown in the performance plots, the average semantic scores for binarized vectors rapidly approach the performance of the raw 9600-bit (300-dimensional float) vectors. At 256 bits, the accuracy drop is typically only around 2%.
Interestingly, the binarization process occasionally acts as a form of denoising, where the compressed vectors slightly outperform the originals on specific similarity tasks. However, the method faces challenges with word analogy tasks, as standard vector arithmetic (addition/subtraction) does not translate perfectly to the binary domain.
Conclusion
This autoencoder-based binarization method provides a viable path for deploying sophisticated NLP models on mobile and edge devices. By aligning vector sizes with hardware registers and learning optimal bit distributions, the approach offers a significant leap over traditional methods like Local Sensitive Hashing (LSH). Future work may explore the integration of these binary embeddings into more complex sequence-to-sequence architectures for tasks like translation and summarization.
Summary updated