Robust Contrastive Learning With Dynamic Mixed Margin

Junhyuk So, YongTaek Lim, Yewon Kim, Changdae Oh, Kyungwoo SongIEEE Access 2023 · DOI

Abstract

Contrastive learning techniques, such as Triplet Loss and InfoNCE, are foundational for learning meaningful representations by pulling similar pairs together and pushing dissimilar ones apart. However, these methods often struggle with vanishing gradients when positive and negative pairs are easily distinguishable, leading to suboptimal convergence. This paper introduces Dynamic Mixed Margin (DMM), a plug-and-play loss function that leverages Mixup to generate synthetic "hard" pairs in the embedding space while dynamically scaling the contrastive margin. DMM consistently enhances performance and robustness across diverse domains, including video-text retrieval, recommender systems, and multimodal sentiment analysis.

Introduction: The Challenge of Vanishing Gradients

Standard contrastive learning relies on a fixed distance margin $\alpha$ to separate positive and negative pairs. While effective, this approach faces a significant hurdle: if a dataset is small or the samples are easily separable, the model quickly satisfies the margin requirement. Once the distance between pairs exceeds $\alpha$, the loss drops to zero, gradients vanish, and learning stalls. This prevents the model from discovering more nuanced, robust representations. Conversely, an excessively large fixed margin can lead to overfitting by forcing unnatural distances. DMM addresses this by continuously generating appropriately challenging pairs to maintain a steady learning signal.

Methodology: Dynamic Mixed Margin (DMM)

The DMM framework introduces two core innovations to the standard contrastive objective:

  1. Embedding Mixup: Rather than relying solely on existing data points, DMM creates virtual "hard" samples. It interpolates between instances in the embedding space using a random ratio $\lambda$ (sampled from a uniform distribution). This process generates samples that lie between known positive and negative clusters.
  2. Dynamic Margin Scaling: Unlike standard triplet loss with a fixed $\alpha$, DMM scales the margin based on the interpolation ratio, resulting in a dynamic margin of $\lambda\alpha$.
Geometric illustration of DMM: Mixup generates intermediate samples, and the margin $\alpha$ is dynamically scaled by $\lambda$ to adapt to the sample's "hardness".

By placing augmented samples near the decision boundaries, DMM ensures that heavily mixed (harder) samples have a smaller, more flexible margin, while lightly mixed samples maintain a larger one. This mechanism acts as a natural regularizer, pulling distant positive pairs closer while preventing tight clusters from collapsing.

Experimental Evaluation

The authors validated DMM across three distinct application domains:

  • Video-Text Retrieval: Evaluated on ActivityNet-caption (20K videos) and YouCook2 (2,000 cooking videos).
  • Recommender Systems: Benchmarked using MovieLens-1M and Amazon-digital-music interaction data.
  • Multimodal Sentiment Classification: Tested on CMU-MOSEI, which features aligned video, audio, and text modalities.
  • Synthetic Analysis: A 2D toy dataset was used to visualize how DMM effectively rescues vanishing gradients compared to standard triplet loss.

Key Insights and Results

Performance Gains

DMM demonstrated significant improvements over baseline architectures:

  • Retrieval: On ActivityNet, integrating DMM into the COOT baseline increased Paragraph $\rightarrow$ Video Recall@1 from 59.9% to 64.6%.
  • Recommendation: CML + DMM achieved 30.2% NDCG@1 on MovieLens-1M, significantly outperforming standard BPR (14.0%).
  • Sentiment: On CMU-MOSEI, DMM showed superior robustness to missing modalities. When the audio stream was removed during inference, GMC + DMM maintained 77.50% accuracy, whereas standard Multimodal Transformers dropped to 57.83%.

Robustness and Regularization

Mathematical proofs and synthetic experiments confirmed that DMM maintains non-zero gradients even when standard losses flatline. Furthermore, ablation studies highlighted that symmetric mixing—interpolating both positive and negative pairs—is essential for maintaining performance; mixing only one side leads to a loss mismatch that degrades representation quality.

Conclusion and Future Directions

Dynamic Mixed Margin provides a simple, effective way to prevent gradient vanishing and improve the robustness of contrastive learning. While the current implementation requires some tuning of the Mixup ratio $\lambda$ and introduces slight computational overhead, its plug-and-play nature makes it a promising candidate for large-scale foundation models like CLIP, where efficient hard-negative mining is a critical bottleneck. Future work could explore automated tuning of the interpolation parameters to further generalize the method across even more diverse datasets.

Summary updated

BibTeX
@article{so2023robust,
  author = {Junhyuk So and YongTaek Lim and Yewon Kim and Changdae Oh and Kyungwoo Song},
  title = {{Robust Contrastive Learning With Dynamic Mixed Margin}},
  journal = {IEEE Access},
  year = {2023},
  doi = {10.1109/access.2023.3286931},
}
Figure