SYNTOLOGY HomeExplorerAtlasCodeMethodologyAboutDevelopersFeedPricing
Paper · 2010.04592 · ICLR · 2021

Contrastive Learning with Hard Negative Samples

Stefanie Jegelka, Joshua Robinson, Ching-Yao Chuang, Suvrit Sra

arXiv · PDF · Open in the Atlas

Code that ran

2 of 8 samples (functions and classes) lifted from this paper's linked repositories executed on a synthesized input in Syntology's jail (0 of them constructed an object rather than computing a result; 0 honoured the contract we drafted, 0 violated it and 0 have no contract verdict; 2 failures of our instrument; 6 no recorded run), measured 2026-11-22; bodies inline only under a permissive licence as GitHub detects it. Not a reproduction of the paper's results.

"Ran" means the function executed on a synthesized input and returned a value. It is not a reproduction of the paper's results. This record, dated, as JSON: /api/ran/2010.04592.json · badge: /api/ran/2010.04592.svg

Each repository's role is a label: a classifier's output recorded on the link, or, where no role is recorded, what the Papers with Code archive marked. The line under it names its basis. Neither says who wrote the code.

RepositoryRoleRan
joshr17/hcl canonical (classifier label)
classifier basis: classifier_2025
1 ran · 0 no recorded run
lajanugen/S2V canonical (classifier label)
classifier basis: census
0 ran · 4 no recorded run
joshr17/HCL marked official in Papers with Code
Papers with Code archive
1 ran · 2 no recorded run
FunctionStatusWhere it lives
adj_loss_ Ran
ran; the contract check could not run (RAISES, DEP_MISSING or TIMEOUT)
joshr17/hcl/graph/losses.py
code served (permissive licence) · get_code("de8796ee0c167c5a")
How it ran

Ran in Syntology's sandbox on this synthesized input (drafted by a language model, Claude Haiku 4.5, prompt python_fixture_v1) and returned Tensor, ndim 0, dtype family float; no output shape is stated. The image it ran in was not recorded. The code mentions cuda, and the harness aliases cuda to the CPU for every sample; whether this run needed that is not recorded. If your copy returns the same type and ndim on these inputs, it matched what we observed; nothing here checks that. It does NOT mean the output is correct: nothing has compared it to the paper.

import torch
import torch.nn as nn

torch.manual_seed(0)

# l_enc: local node embeddings, shape (num_nodes, embedding_dim)
# The function uses l_enc.shape[0] to get num_nodes
# and performs torch.mm(l_enc, l_enc.t()) so needs 2D tensor
num_nodes = 5
embedding_dim = 4
l_enc = torch.randn(num_nodes, embedding_dim)

# g_enc: graph embeddings, shape (num_graphs, embedding_dim)
# The function uses g_enc.shape[0] to get num_graphs
num_graphs = 2
g_enc = torch.randn(num_graphs, embedding_dim)

# edge_index: COO format edge indices, shape (2, num_edges)
# The function iterates: for node1, node2 in zip(edge_index[0], edge_index[1])
# and calls .item() on each, so needs 1D tensors of node indices
num_edges = 4
edge_index = torch.tensor([
    [0, 1, 2, 3],  # source nodes
    [1, 2, 3, 4]   # target nodes
])

# batch: graph assignment for nodes
# The function doesn't actually use batch, but it's a parameter
batch = torch.tensor([0, 0, 0, 1, 1])

ARGS = {
    "l_enc": l_enc,
    "g_enc": g_enc,
    "edge_index": edge_index,
    "batch": batch
}
Setup block drafted by
a language model, Claude Haiku 4.5, prompt python_fixture_v1
Imports
torch — import names as written, not package names to install; a name the repository itself provides is not a package
Returned
type Tensor, ndim 0, dtype family float — no output shape is stated: observe_signature.py could not observe it (call:AssertionError)
dtype family
int means an integer dtype; float means any other dtype the instrument saw, bool and complex included (fixture_check.py records only these two families)
Environment
image not recorded; re-verify against syntology-harvest-sandbox:v5-deps; not recorded for this sample: the harness installs a cuda-to-cpu shim (cuda_shim.py) before every sample and no run records whether a sample needed it; seed: none by the harness; any seed is in the setup block
get_negative_expectation Ran
ran; the contract check could not run (RAISES, DEP_MISSING or TIMEOUT)
joshr17/HCL/graph/cortex_DIM/functions/gan_losses.py
code served (permissive licence) · get_code("be77056dd1897169")
How it ran

Ran in Syntology's sandbox on this synthesized input (drafted by a language model, Claude Haiku 4.5, prompt python_fixture_v1) and returned Tensor, ndim 0, dtype family float, shape () as a later run recorded it. The image it ran in was not recorded. If your copy returns the same type, ndim and shape on these inputs, it matched what we observed; nothing here checks that. It does NOT mean the output is correct: nothing has compared it to the paper.

import torch
import math

torch.manual_seed(0)

# Create a small tensor for q_samples
# Shape: (batch_size, feature_dim) = (2, 4)
q_samples = torch.randn(2, 4)

# Test with different measures
measure = 'GAN'

# average parameter
average = True

# beta parameter (used in JSD_hard)
beta = 0.5

# tau_plus parameter (used in JSD_hard)
tau_plus = 0.5

ARGS = {
    'q_samples': q_samples,
    'measure': measure,
    'average': average,
    'beta': beta,
    'tau_plus': tau_plus
}
Setup block drafted by
a language model, Claude Haiku 4.5, prompt python_fixture_v1
Imports
torch — import names as written, not package names to install; a name the repository itself provides is not a package
Returned
type Tensor, ndim 0, dtype family float, shape () — shape () as a later run recorded it
dtype family
int means an integer dtype; float means any other dtype the instrument saw, bool and complex included (fixture_check.py records only these two families)
Environment
image not recorded; re-verify against syntology-harvest-sandbox:v5-deps; not recorded for this sample: the harness installs a cuda-to-cpu shim (cuda_shim.py) before every sample and no run records whether a sample needed it; seed: none by the harness; any seed is in the setup block
log_sum_exp Not yet run
unverified (harvested, no recorded run)
joshr17/HCL/graph/cortex_DIM/functions/gan_losses.py
code served (permissive licence) · get_code("c03feba6bc4986f6")
How it ran

no invocation recorded.

parse_example_batch Not yet run
unverified (harvested, no recorded run)
lajanugen/S2V/src/ops/input_ops.py
code served (permissive licence) · get_code("796cd317f00fce83")
How it ran

no invocation recorded.

prefetch_input_data Not yet run
unverified (harvested, no recorded run)
lajanugen/S2V/src/ops/input_ops.py
code served (permissive licence) · get_code("bf0cc947768c5673")
How it ran

no invocation recorded.

raise_measure_error Not yet run
unverified (harvested, no recorded run)
joshr17/HCL/graph/cortex_DIM/functions/gan_losses.py
code served (permissive licence) · get_code("b05ca027e5d64bc6")
How it ran

no invocation recorded.

read_vocab Not yet run
unverified (harvested, no recorded run)
lajanugen/S2V/src/s2v_model.py
code served (permissive licence) · get_code("3b50276530bcaf11")
How it ran

no invocation recorded.

read_vocab_embs Not yet run
unverified (harvested, no recorded run)
lajanugen/S2V/src/s2v_model.py
code served (permissive licence) · get_code("29fde95b295e9702")
How it ran

no invocation recorded.

Also present in other papers' code

Of 8 samples lifted from this paper's linked repositories, 8 carry a function identity and 0 do not. Of the 8 distinct functions with an identity, 1 are also present in other papers whose code we hold (0 with at least one paper dated earlier, 0 the same month, 1 later) and 7 are only here among the 52,977 papers whose code Syntology holds (as of 2026-09-26).

Only here means: among the 52,977 papers whose code Syntology holds (51,887 with lifted samples, 1,090 through their assemblies only), as of 2026-09-26, no other paper's lifted samples or current assembly bricks contain an identical function body after normalisation.

FunctionAlso present inEarliest-datedOthers named
log_sum_exp
brick of this paper's assembly: helper
2 other papers
2 later
2105.06247 (2021-05)
Video Corpus Moment Retrieval with Contrastive Learning
2402.16302 (2024-02)
Graph Diffusion Policy Optimization

Presence, not direction: an identical function body in two papers' repositories does not say who wrote it, which came from which, or that either paper's method rests on it. Matching is exact after normalisation, so a renamed or edited function is not matched. Dates are when papers appeared, not when code was written. Only .py files the harvester lifted are covered; notebooks are not read. A new-style arXiv id YYMM.NNNN dates a paper to the month 20YY-MM; otherwise Paper.year dates it to the year; otherwise it is undated. Dates are when the paper appeared, not when the code was written. Read 2026-11-22.

Repositories linked to this paper

Some links come from the archived Papers with Code dataset (CC BY-SA 4.0): attribution and licence.

Abstract

How can you sample good negative examples for contrastive learning? We argue that, as with metric learning, contrastive learning of representations benefits from hard negative samples (i.e., points that are difficult to distinguish from an anchor point). The key challenge toward using hard negatives is that contrastive methods must remain unsupervised, making it infeasible to adopt existing negative sampling strategies that use true similarity information. In response, we develop a new family of unsupervised sampling methods for selecting hard negative samples where the user can control the hardness. A limiting case of this sampling results in a representation that tightly clusters each class, and pushes different classes as far apart as possible. The proposed method improves downstream performance across multiple modalities, requires only few additional lines of code to implement, and introduces no computational overhead.

For agents

The same record, over MCP at https://syntology.ai/mcp:

get_harvested_code_for_paper("2010.04592")
get_code_for_paper("2010.04592")
have("2010.04592")

The run record, dated, one paper per request, free:

curl https://syntology.ai/api/ran/2010.04592.json

A badge for a README (the split and the date, never a ratio):

[![Syntology run record](https://syntology.ai/api/ran/2010.04592.svg)](https://syntology.ai/paper/2010.04592)

Connect an agent — have() is free.