Papers › EMC²: Efficient MCMC Negative Sampling for Contrastive Learning with Global Convergence

EMC²: Efficient MCMC Negative Sampling for Contrastive Learning with Global Convergence

16 Apr 2024arXiv:2404.10575archive 2025-07-28

Chung-Yiu Yau, Hoi-To Wai, Parameswaran Raman, Soumajyoti Sarkar, Mingyi Hong

A key challenge in contrastive learning is to generate negative samples from a large sample set to contrast with positive samples, for learning better encoding of the data. These negative samples often follow a softmax distribution which are dynamically updated during the training process. However, sampling from this distribution is non-trivial due to the high computational costs in computing the partition function. In this paper, we propose an Efficient Markov Chain Monte Carlo negative sampling method for Contrastive learning (EMC²). We follow the global contrastive learning loss as introduced in SogCLR, and propose EMC² which utilizes an adaptive Metropolis-Hastings subroutine to generate hardness-aware negative samples in an online fashion during the optimization. We prove that EMC² finds an 𝒪(1/√(T))-stationary point of the global contrastive loss in T iterations. Compared to prior works, EMC² is the first algorithm that exhibits global convergence (to stationarity) regardless of the choice of batch size while exhibiting low computation and memory cost. Numerical experiments validate that EMC² is effective with small batch training and achieves comparable or better performance than baseline algorithms. We report the results for pre-training image encoders on STL-10 and Imagenet-100.

PaperPDFCodeCode Syntology ran

In Syntology Open this paper in Syntology's Atlas, the map of the papers in Syntology's graph and their citations.

For agents, Syntology's MCP tool lists every function and class Syntology harvested from this paper and whether it ran (how to connect): get_harvested_code_for_paper(arxiv_id="2404.10575")

Code

Syntology Ran 11 of 14 code samples harvested from 1 repository linked to this paper; 3 have no recorded run. Of those that ran: 11 ran with no contract checked.

By repository: official repository: 14 samples from 1 repository, 11 ran. The run record, sample by sample. “Ran” means executed on a synthesized input, not that the code is correct or reproduces the paper.

amazon-science/contrastive_emc2 officialmentioned on GitHubpytorchApache-2.0 report

Repository list and official/mentioned flags are the archive's, frozen 2025-07-28. Reachability, where shown, is from one Syntology probe window (2026-09-16 to 2026-09-18); repositories not probed show nothing. GitHub stars are not tracked.

Code Syntology ran Syntology

14 samples harvested; 11 ran; 0 honoured the contract we drafted; 3 have no recorded run. Read from Syntology's graph 2026-09-24; that is when this build read the record, not when the samples ran.

11ran
3unverified

Licence: 0 of the 14 samples are pointer only, meaning Syntology does not serve that copy's text. This page shows no code text for any sample; each one links to its file in the repository.

Harvested from amazon-science/contrastive_emc2. “Ran” means the sample executed on a synthesized input. It does not mean the output is correct, and nothing here reproduces the paper's results. “Honoured” and “violated” refer to a contract Syntology drafted from the code itself; “our draft was wrong” and “fixture could not drive it” are failures of Syntology's instrument, not of the code.

Each sample ends with its code_sha256, Syntology's identity for that exact code. An agent fetches the stored sample with Syntology's MCP tool get_code(code_sha256="…") (how to connect); click an identity to copy that call.

Repository labels, per sample. official repository: The archive marks this repository official for the paper. named in the paper: The archive records that the paper mentions this repository; it is not marked official. community (archive-listed): In the archive's code links for this paper, not marked official and not recorded as mentioned in the paper. found in paper text by Syntology: Syntology found this repository in the paper's own text; whether it is the authors' implementation is not asserted. community: Not in the archive's code links for this paper; a community repository Syntology harvested. Samples from a repository marked official are listed first. Licence labels name the repository's licence as recorded at harvest. “Pointer only” means Syntology does not serve that copy's text, for one of four reasons: no licence file was found; the licence was not identified; the licence is recorded as permissive but that copy's record is not marked cleared; or the licence is outside the permissive list Syntology serves text under (MIT, Apache-2.0, BSD and similar). Some licences outside that list permit redistribution, such as WTFPL, and GPL-3.0 under its conditions; they are simply not on the list. Hover a licence label for the reason. File links open the file on GitHub at the default branch, which may have changed since the harvest.

all_gather_matrices amazon-science/contrastive_emc2/communication.py official repository ran Apache-2.0 (permissive) · a05a54f3fc3dbfa9 · report
all_gather_vectors amazon-science/contrastive_emc2/communication.py official repository ran Apache-2.0 (permissive) · a4d6e26b346c837e · report
convert_layers amazon-science/contrastive_emc2/model.py official repository ran Apache-2.0 (permissive) · fdcddcdef8722c34 · report
estimate_inner_prod amazon-science/contrastive_emc2/cache.py official repository ran fingerprinted Apache-2.0 (permissive) · 6e1acdb5ff584cbb · report
find_classes amazon-science/contrastive_emc2/folder.py official repository ran Apache-2.0 (permissive) · 904c357058bab2d9 · report
get_diagonal_blocks amazon-science/contrastive_emc2/evaluation.py official repository ran Apache-2.0 (permissive) · cd3d80672004efc8 · report
has_file_allowed_extension amazon-science/contrastive_emc2/folder.py official repository ran Apache-2.0 (permissive) · aec20ef76445c38c · report
info_nce_loss amazon-science/contrastive_emc2/main_simclr.py official repository ran Apache-2.0 (permissive) · 044dd7c8dd4adba5 · report
is_image_file amazon-science/contrastive_emc2/folder.py official repository ran Apache-2.0 (permissive) · d9fa6dde50b3f702 · report
parse_args amazon-science/contrastive_emc2/arguments.py official repository ran fingerprinted Apache-2.0 (permissive) · d73de0f2b46b2268 · report
remove_diagonal_blocks amazon-science/contrastive_emc2/evaluation.py official repository ran fingerprinted Apache-2.0 (permissive) · 5ceb2c36a8c88939 · report
all_gather_tensors amazon-science/contrastive_emc2/communication.py official repository unverified Apache-2.0 (permissive) · 0f11d82afcfe7ee7 · report
build_model amazon-science/contrastive_emc2/model.py official repository unverified Apache-2.0 (permissive) · 7e5b6f7d2706cbc7 · report
linear_evaluation amazon-science/contrastive_emc2/linear_eval.py official repository unverified Apache-2.0 (permissive) · 2553afafba450290 · report

Tasks

Contrastive Learning

Results from the paper archive 2025-07-28

No leaderboard rows for this paper in the archive.

Methods

Contrastive LearningSETSoftmax

Report a problem or propose a change · a person checks every report against the paper or source before anything changes; decisions are listed on /corrections