Abstract
Word embeddings are commonly used as a starting point in many NLP models to achieve state-of-the-art performances. However, with a large vocabulary and many dimensions, these floating-point representations are expensive both in terms of memory and calculations which makes them unsuitable for use on low-resource devices. The method proposed in this paper transforms real-valued embeddings into binary embeddings while preserving semantic information, requiring only 128 or 256 bits for each vector. This leads to a small memory footprint and fast vector operations. The model is based on an autoencoder architecture, which also allows to reconstruct original vectors from the binary ones. Experimental results on semantic similarity, text classification and sentiment analysis tasks show that the binarization of word embeddings only leads to a loss of ∼2% in accuracy while vector size is reduced by 97%. Furthermore, a top-k benchmark demonstrates that using these binary vectors is 30 times faster than using real-valued vectors.
Introduction
Standard word embeddings like GloVe or fastText represent words as vectors of 32-bit floating-point numbers. While powerful, these models are massive; a typical vocabulary of 2 million words can require over 2 GB of memory. This creates a significant bottleneck for "edge" computing. Mobile and embedded devices often lack the RAM to store these models or the specialized hardware to perform floating-point arithmetic efficiently. Consequently, most mobile NLP applications send user data to a central server for processing, raising privacy concerns and requiring a constant internet connection. The authors aim to enable offline, private, and fast NLP by shrinking these embeddings into a format that fits directly into CPU registers.
Methods
The authors propose a specialized autoencoder architecture designed to map real-valued vectors ($x$) to binary codes ($\Phi(x)$) and back again ($\hat{y}$).
The Encoder uses a weight matrix $W$ and a Heaviside step function $h(x)$ to produce a binary vector. Crucially, the size of $W$ determines the output bit-length (e.g., 128 or 256 bits), allowing the model to target specific CPU register sizes. The Decoder attempts to reconstruct the original real-valued vector from the binary code using the transpose of the same weight matrix ($W^T$) and a non-linear activation (tanh).
Because the Heaviside function is non-differentiable, training is tricky. The authors use a specific regularization term—$||W^T W - I||^2$—to minimize correlation between different bits. This forces the model to encode as much unique information as possible in each bit, preventing redundancy and ensuring that words close in the original space remain close in the binary space.
Results
Evaluation across three popular pre-trained embedding sets (dict2vec, fastText, and GloVe) demonstrates that 256-bit binary vectors are 37.5 times smaller than 300-dimensional 32-bit float vectors (9600 bits vs 256 bits).
Key findings include:
- Massive Compression: Vector size is reduced by 97%, enabling models to fit on low-resource devices.
- High Speed: Top-K neighbor queries are 30 times faster with binary vectors than with real-valued ones. When including file loading times, the binary approach is 75 times faster.
- Near-Lossless Accuracy: On tasks like document classification and sentiment analysis, the accuracy drop is usually less than 2%. In some cases, the binarized version actually outperformed the original "raw" vectors.
- Hardware Alignment: Targeting 64, 128, and 256 bits allows distance calculations to be performed using a single
XORandpopcountinstruction, which are significantly faster than floating-point multiplications.
Conclusion and Future Work
The proposed autoencoder approach consistently outperformed simpler methods like Locality Sensitive Hashing (LSH) or naive thresholding. While standard vector arithmetic for analogy tasks remains a challenge in the binary space, the massive gains in speed and memory efficiency make this approach highly suitable for offline mobile NLP applications. Future work could involve developing more sophisticated binary logic that better mimics the linear algebraic properties of the original vector space.
Summary updated