Learning Compressed Sentence Representations for On-Device Text Processing

Dinghan Shen, Pengyu Cheng, Dhanasekar Sundararaman, Xinyuan Zhang, Qian Yang, Meng Tang, Asli Celikyilmaz, Lawrence Carin

Introduction

Modern Natural Language Processing (NLP) relies heavily on sentence embeddings—high-dimensional continuous vectors that represent semantic meaning. While effective, these embeddings (often 4096-dimensional float32 vectors) require significant memory and computational power for similarity searches. This poses a major hurdle for "on-device" processing on smartphones or IoT devices. This paper investigates methods to "binarize" these embeddings into compact bitstrings, aiming to reduce storage footprints and accelerate computation without sacrificing semantic integrity.

Methodology

The authors evaluated four distinct strategies to transform continuous embeddings into binary codes:

  1. Hard Threshold (HT): A baseline approach where values are converted to 1 or 0 based on a fixed threshold.
  2. Random Projection (Rand): Embeddings are multiplied by a random matrix before binarization, allowing for flexible output dimensions.
  3. Principal Component Analysis (PCA): Data is projected onto its most informative axes prior to thresholding.
  4. Autoencoder with Semantic-Preserving Loss (AE-SP): The core contribution of the paper. An autoencoder is trained to compress embeddings into a binary latent space. Crucially, a Semantic-Preserving Loss is introduced to ensure that the Hamming distance between binary codes reflects the cosine similarity of the original continuous vectors.
Architectural overview of binarization methods: (a) Hard Thresholding, (b) Random Projection or PCA, and (c) the proposed Autoencoder with Semantic-Preserving Loss.

To overcome the non-differentiable nature of the binary threshold during backpropagation, the researchers employed a Straight-Through Estimator, allowing the model to be trained end-to-end.

Results and Discussion

The evaluation, conducted using the SentEval toolkit, demonstrated that the AE-SP method provides the best balance of compression and accuracy.

Comparison of accuracy across different bit lengths for various binarization methods. AE-SP shows superior performance as the number of bits increases, eventually outperforming simpler projection methods.

Key findings include:

  • Storage Efficiency: Converting 4096-dimensional float32 vectors to 4096-bit strings resulted in a 98.5% reduction in storage (from 16 KB to 0.5 KB per sentence).
  • Search Speed: Similarity searches using Hamming distance were 12 times faster than traditional cosine similarity calculations on continuous vectors.
  • Performance Retention: The AE-SP model maintained performance within ~2% of the original continuous model across various classification and matching tasks.
  • Robustness of Simple Methods: Interestingly, Random Projections performed remarkably well at lower bit counts (e.g., 512 bits), offering a computationally "cheap" alternative to neural training.

Conclusion

This research demonstrates that continuous sentence embeddings are often over-parameterized. By using a specialized autoencoder with semantic-preserving constraints, these embeddings can be compressed into binary forms that are highly efficient for on-device deployment. This approach enables sophisticated NLP features on hardware with limited RAM and battery life, paving the way for more private and responsive local AI applications.

Summary updated

BibTeX
@inproceedings{shen2019learning,
  author = {Dinghan Shen and Pengyu Cheng and Dhanasekar Sundararaman and Xinyuan Zhang and Qian Yang and Meng Tang and Asli Celikyilmaz and Lawrence Carin},
  title = {{Learning Compressed Sentence Representations for On-Device Text Processing}},
  booktitle = {Annual Meeting of the Association for Computational Linguistics},
  year = {2019},
  doi = {10.18653/v1/p19-1011},
}
Figure