Improving OOD Generalization of Pre-trained Encoders via Aligned Embedding-Space Ensembles

Shuman Peng, Arash Khoeini, Sharan Vaswani, Martin Ester · DOI

Abstract

Self-supervised learning (SSL) produces powerful encoders, but these models often struggle with out-of-distribution (OOD) data. While deep ensembles typically improve robustness, ensembling SSL encoders is challenging due to the lack of shared output spaces and the misalignment of their high-dimensional embedding spaces. We present Ensemble-InfoNCE, a novel method that aligns disparate embedding spaces using unsupervised orthogonal transformations. Our approach significantly boosts zero-shot performance on OOD data without requiring labels or fine-tuning, preserving semantic integrity across models.

Introduction

Self-supervised learning has revolutionized the creation of feature encoders from unlabeled data. However, a persistent challenge remains: generalization to out-of-distribution (OOD) inputs—data that differs significantly from the training distribution, such as colored variants of grayscale training images.

Deep ensembling is a standard technique for improving model robustness. However, SSL encoders present unique difficulties. Weight-space ensembling (averaging parameters) is often incompatible across different architectures or training runs, and output-space ensembling is impossible because SSL models lack fixed classification labels. The embedding space is the natural candidate for aggregation, but it suffers from a "misalignment" problem. Even if two models learn the same underlying concepts, they may represent them in different orientations. As shown in Figure 1, averaging these misaligned vectors can destroy the semantic meaning of the representation.

Misalignment in embedding spaces leads to broken semantic integrity during ensembling.

Methodology: Ensemble-InfoNCE

The proposed Ensemble-InfoNCE framework addresses the alignment problem through a three-step pipeline:

  1. Theoretical Foundation: The authors prove that encoders trained with InfoNCE loss on identical data recover the same latent features up to an orthogonal transformation (rotation or reflection).
  2. Unsupervised Alignment: To synchronize the models, one encoder is designated as an "anchor." A single-layer neural network is trained to find the orthogonal matrix $R$ that rotates other encoders' embeddings to match the anchor. This process is entirely unsupervised, minimizing the geodesic distance between embeddings of the same input across models.
  3. Spherical Aggregation: Because embeddings reside on a hypersphere, simple arithmetic averaging is insufficient. The framework utilizes the Karcher Mean, an iterative algorithm that computes a mathematically sound average position on the curved surface of the hypersphere.

Experimental Setup

The method was evaluated using the MNIST dataset as a benchmark:

  • In-Distribution (ID): The standard black-and-white MNIST test set.
  • Out-of-Distribution (OOD):
  • Colored MNIST: Digits are randomly colored, introducing a feature absent during training.
  • Cropped MNIST: Digits are randomly cropped to various scales.

Results and Analysis

The aligned ensemble was compared against single models and unaligned ensembles. The results demonstrate that alignment is critical; without it, ensembling actually degrades performance compared to a single model.

Performance comparison (Recall@1) between single models, unaligned ensembles, and the proposed aligned ensemble on ID and OOD data.

Key findings include:

  • OOD Robustness: On Colored MNIST, the aligned ensemble improved Recall@1 by 6.99% and Mean Average Precision (MAP@R) by 17.38% over the average single model.
  • ID Stability: The method maintained and slightly improved performance on standard MNIST (~1.18% gain in Recall@1), indicating that the alignment process does not compromise known-distribution accuracy.
  • Comparison to Weight-Averaging: The proposed method significantly outperformed standard weight-space ensembles (WSE), which frequently saw performance drops of up to 66% in certain configurations.

Discussion and Limitations

Ensemble-InfoNCE provides a flexible and interpretable way to combine SSL encoders. By operating in the embedding space, it allows the resulting ensemble to be used for any downstream task while maintaining the ability to inspect individual model contributions.

However, several areas for future research remain. The current study focused on synthetic OOD shifts in the MNIST domain. Scaling this approach to massive datasets like ImageNet and investigating "natural" OOD shifts (e.g., different sensor types or environmental conditions) is a priority. Additionally, while the alignment layers are computationally light, the overhead of aligning a very large number of high-dimensional encoders warrants further investigation.

Summary updated

BibTeX
@inproceedings{peng2024improving,
  author = {Shuman Peng and Arash Khoeini and Sharan Vaswani and Martin Ester},
  title = {{Improving OOD Generalization of Pre-trained Encoders via Aligned Embedding-Space Ensembles}},
  booktitle = {UniReps @ NeurIPS},
  year = {2024},
  url = {https://openreview.net/forum?id=RYSVQitYZY},
}
Figure