BatchSampler: Sampling Mini-Batches for Contrastive Learning in Vision, Language, and Graphs

Zhen Yang,Tinglin Huang,Ming Ding,Yuxiao Dong,Rex Ying,Yukuo Cen,Yangliao Geng,Jie Tang
2023-06-06
Abstract:In-Batch contrastive learning is a state-of-the-art self-supervised method that brings semantically-similar instances close while pushing dissimilar instances apart within a mini-batch. Its key to success is the negative sharing strategy, in which every instance serves as a negative for the others within the mini-batch. Recent studies aim to improve performance by sampling hard negatives \textit{within the current mini-batch}, whose quality is bounded by the mini-batch itself. In this work, we propose to improve contrastive learning by sampling mini-batches from the input data. We present BatchSampler\footnote{The code is available at \url{<a class="link-external link-https" href="https://github.com/THUDM/BatchSampler" rel="external noopener nofollow">this https URL</a>}} to sample mini-batches of hard-to-distinguish (i.e., hard and true negatives to each other) instances. To make each mini-batch have fewer false negatives, we design the proximity graph of randomly-selected instances. To form the mini-batch, we leverage random walk with restart on the proximity graph to help sample hard-to-distinguish instances. BatchSampler is a simple and general technique that can be directly plugged into existing contrastive learning models in vision, language, and graphs. Extensive experiments on datasets of three modalities show that BatchSampler can consistently improve the performance of powerful contrastive models, as shown by significant improvements of SimCLR on ImageNet-100, SimCSE on STS (language), and GraphCL and MVGRL on graph datasets.
Machine Learning,Computation and Language,Computer Vision and Pattern Recognition
What problem does this paper attempt to address?
The core problem that this paper attempts to solve is: **How to improve the performance of contrastive learning by improving the sampling method of mini - batch?** Specifically, the authors propose a new method named BatchSampler, which aims to globally sample mini - batch from the input data to ensure that each mini - batch contains as many "hard negatives" as possible, that is, those samples that have similar representations to positive samples but different actual labels. ### Problem Background In traditional contrastive learning, especially in in - batch contrastive learning, the negative sample selection strategy has a crucial impact on the model performance. Usually, all other instances in each mini - batch will be used as negative samples for the current instance. However, this method has some limitations: 1. **Uniform Sampler**: Simple random or sequential loading of mini - batch easily leads to negative samples being too easy (easy negatives), and these negative samples contribute less to the optimization process. 2. **kNN Sampler**: Selecting neighboring instances by clustering to form a mini - batch. Although some hard negative samples can be introduced, it may also lead to a high proportion of false negatives, that is, cases where the actual labels are the same but are wrongly regarded as negative samples. ### Solution To solve the above problems, BatchSampler proposes a new mini - batch sampling method, and its main features include: - **Global Sampling**: Select instances globally from the entire data set instead of being limited to the inside of the current mini - batch. - **Construct Proximity Graph**: By constructing a proximity graph for randomly selected instances, control the representational similarity between each pair of instances, thereby ensuring that the sampled negative samples are "difficult to distinguish". - **Random Walk with Restart**: Use the random walk with restart algorithm to sample instances on the proximity graph to ensure that the sampled instances are both similar and different, thereby increasing the number of hard negative samples in the mini - batch. ### Experimental Results The experimental results show that BatchSampler has achieved significant performance improvements in contrastive learning tasks in multiple fields, including: - **Image Field**: SimCLR and MoCo v3 - **Text Field**: SimCSE - **Graph Field**: GraphCL and MVGRL These results verify the effectiveness and universality of BatchSampler and can significantly improve the performance of contrastive learning models. ### Summary BatchSampler solves the problems of easy negative samples and false negative samples in traditional sampling methods by improving the sampling method of mini - batch, thereby improving the performance of contrastive learning. This method is not only applicable to data in multiple modalities such as vision, language, and graphs, but also provides a new research direction for contrastive learning.