On the Dimensionality of Sentence Embeddings

Hongwei Wang, Hongming Zhang, Dong Yu · DOI

Abstract

In Natural Language Processing (NLP), sentence embeddings are typically generated with high dimensionality (e.g., 768 or 1024) by default. However, these large vectors impose significant computational and memory overheads. This paper investigates whether such high dimensionality is necessary and proposes a novel two-step training methodology to reduce embedding size without sacrificing performance. By decoupling encoder optimization from pooler fine-tuning, the researchers demonstrate that embeddings can be compressed by a factor of six (from 768 to 128 dimensions) with negligible loss in accuracy, consistently outperforming traditional reduction techniques like PCA.

Introduction

Sentence embeddings—fixed-length vector representations of text—are fundamental to modern NLP tasks such as semantic search, clustering, and document classification. Models like BERT and RoBERTa typically produce embeddings with 768 or 1,024 dimensions. While effective, these high-dimensional vectors suffer from the "curse of dimensionality," leading to increased memory requirements, slower similarity searches, and higher latency in production environments.

Traditionally, practitioners have relied on post-processing techniques like Principal Component Analysis (PCA) to shrink these vectors after training. However, these methods are often lossy and cannot recover information once the model is fixed. This research asks two critical questions: Is the default dimensionality truly optimal? And can we train models to produce low-dimensional embeddings directly without a drop in quality?

The Bottleneck Problem

The researchers identified a significant hurdle in training low-dimensional models from scratch: the bottleneck effect. When a model is trained end-to-end with a very small output dimension (e.g., $d=16$), the narrow output layer acts as a bottleneck that hinders the encoder's ability to learn rich linguistic representations.

Performance degradation in low-dimensional settings is attributed to two factors:

  1. Encoder's Loss: The model fails to learn the underlying language features because of the tight constraint during training.
  2. Pooler's Loss: The final layer (the pooler) is unable to map the encoder's knowledge into the target dimension effectively.

Proposed Methodology: Two-Step Training

To overcome the bottleneck effect, the authors propose a Two-Step Training Approach that ensures the encoder remains high-quality even when the final output is small.

Step 1: Encoder Optimization

Instead of training the target low-dimensional model in isolation, the researchers train several models with varying dimensions. They identify a "well-trained" encoder—one that achieves peak performance on validation sets, regardless of its original output dimension. This high-performing encoder is then extracted to serve as the foundation for the target model.

Step 2: Pooler Fine-Tuning

The "well-trained" encoder is paired with a pooler of the desired target dimension ($d$). To prevent the bottleneck from corrupting the encoder's learned weights, the encoder is frozen. Only the pooler (typically a linear layer with a tanh activation) is fine-tuned. This process aligns the small-dimension pooler to the high-quality features already present in the encoder.

Experimental Results

The methodology was evaluated across 14 benchmarks, including seven Semantic Textual Similarity (STS) tasks and seven sentence classification tasks (e.g., TREC, MR, SST).

Massive Compression with Minimal Loss

On STS tasks, the researchers successfully reduced embedding dimensions from 768 to 128—a 6x reduction—with a negligible performance change (from 76.57% to 76.46%). This suggests that the default dimensions used by models like BERT are often redundant for many downstream applications.

Superiority Over Baselines

The two-step method consistently outperformed traditional dimensionality reduction techniques such as PCA, Isomap, and LLE. The advantage was most pronounced at extremely low dimensions. For instance, at $d=16$, the proposed method improved Spearman’s correlation on the STS-Benchmark by over 7 points compared to standard end-to-end training.

Efficiency

Because the second step only involves training a single fully connected layer, the computational cost of this adaptation is minimal. This makes it a practical solution for optimizing existing models for resource-constrained environments.

Discussion and Insights

The study reveals that the "optimal" dimension for many NLP tasks is significantly lower than the industry standard. For example, on the MRPC (paraphrase) task, a dimension of 16 performed as well as 768. The researchers also noted that the neural pooler acts as a learned, task-specific version of PCA, capturing nuances that unsupervised linear projections often miss.

Conclusion and Future Work

This research demonstrates that for sentence embeddings, "less is more." By using a decoupled training strategy, developers can achieve significant gains in efficiency without the performance penalties usually associated with dimensionality reduction.

Future work remains to be done in establishing a rigorous theoretical framework for why low-dimension bottlenecks degrade encoder training. Additionally, exploring how these findings scale to massive Transformer models (LLMs) could provide further avenues for optimizing the next generation of AI systems.

Summary updated

BibTeX
@inproceedings{wang2023dimensionality,
  author = {Hongwei Wang and Hongming Zhang and Dong Yu},
  title = {{On the Dimensionality of Sentence Embeddings}},
  booktitle = {Conference on Empirical Methods in Natural Language Processing},
  year = {2023},
  doi = {10.18653/v1/2023.findings-emnlp.694},
}
Figure