EncoderMI: Membership Inference against Pre-trained Encoders in Contrastive Learning

Hongbin Liu, Jinyuan Jia, Wenjie Qu, Neil Zhenqiang Gong

Introduction

Contrastive learning has become the gold standard for pre-training powerful image encoders on massive, often unlabeled, datasets. Models like OpenAI’s CLIP are widely used as feature extractors for downstream tasks. However, the use of large-scale data raises significant privacy and copyright concerns: were private or copyrighted images used in training without consent?

Membership Inference Attacks (MIA) aim to determine if a specific data point was part of a training set. While well-studied for classifiers that output confidence scores, MIAs for encoders are challenging because encoders only output feature vectors (embeddings) without inherent "confidence" signals. EncoderMI addresses this gap, providing the first systematic MIA designed specifically for image encoders trained via contrastive learning (e.g., MoCo, SimCLR, CLIP).

Methodology: Exploiting Local Smoothness

The core intuition behind EncoderMI is rooted in the contrastive learning objective: models are trained to ensure that different augmentations of the same image result in similar feature vectors. The authors observe that encoders "overfit" to their training data. For a member image (seen during training), the encoder produces highly similar feature vectors for its various augmentations. For a non-member, this similarity is significantly lower.

The attack follows a four-step process:

  1. Shadow Training: The attacker trains a "shadow encoder" on a controlled dataset to learn the statistical differences between member and non-member behavior.
  2. Feature Extraction: For a target image, $n$ random augmentations (e.g., crops, color jitters) are generated and passed through the encoder to obtain $n$ embeddings.
  3. Similarity Scoring: Pairwise cosine similarities are calculated between all generated vectors.
  4. Inference Classification: A secondary classifier determines membership based on these scores.
The EncoderMI attack algorithm, detailing the steps from augmentation to membership inference for the three proposed variants.

The paper explores three architectural variants for the inference classifier:

  • EncoderMI-V: A neural network processing a ranked vector of similarity scores.
  • EncoderMI-S: A set-based architecture (DeepSets) invariant to augmentation order.
  • EncoderMI-T: A simple threshold-based approach using the average similarity score.

Experimental Setup

The method was evaluated on standard benchmarks including CIFAR10, STL10, and Tiny-ImageNet. To test real-world applicability, the authors also targeted OpenAI’s CLIP. Since CLIP's training set is private, the authors curated a set of "potential members" using keywords from the original CLIP paper and created "non-members" by stitching unrelated image halves together.

Results and Key Insights

EncoderMI demonstrates high effectiveness across various settings. On Tiny-ImageNet, EncoderMI-V achieved between 88.7% and 96.5% accuracy, depending on the attacker's background knowledge. Even against the black-box CLIP model, the attack maintained 66% to 75% accuracy, despite the authors having no access to CLIP’s actual training data or parameters.

Performance metrics for EncoderMI variants: (a) Precision-Recall curves showing high precision across recall levels, and (b) the impact of the number of augmented inputs $n$ on inference accuracy.

Key findings include:

  • Shift in Perspective: Effective MIA for encoders requires analyzing the relationship between multiple outputs (augmentations) rather than a single point, effectively measuring the model's local "smoothness."
  • Robustness: The attack remains effective even without knowledge of the target model's specific architecture or training algorithm.
  • Baseline Comparison: Traditional MIAs adapted for encoders performed near random guessing (~50%), highlighting the necessity of EncoderMI’s augmentation-based approach.
  • Privacy-Utility Tradeoff: While defenses like early stopping can reduce attack success by limiting overfitting, they also degrade the encoder's performance on downstream tasks, suggesting a fundamental tension between privacy and utility.

Conclusion and Future Work

EncoderMI exposes a significant privacy vulnerability in state-of-the-art contrastive learning models. While this study focuses on black-box image-based attacks, future research could explore "white-box" scenarios or multi-modal inference (e.g., text-image relationships in CLIP). Potential defenses like Differential Privacy (DP-SGD) or adversarial training remain avenues for investigation, though they often come with high computational costs.

Summary updated

BibTeX
@inproceedings{liu2021encodermi,
  author = {Hongbin Liu and Jinyuan Jia and Wenjie Qu and Neil Zhenqiang Gong},
  title = {{EncoderMI: Membership Inference against Pre-trained Encoders in Contrastive Learning}},
  booktitle = {CCS},
  year = {2021},
  doi = {10.1145/3460120.3484749},
}
Figure