SYNTOLOGY HomeExplorerAtlasCodeMethodologyAboutDevelopersFeedPricing
Paper · 2310.18700 · NeurIPS · 2023

Empowering Collaborative Filtering with Principled Adversarial Contrastive Loss

Xiang Wang, An Zhang, Tat-Seng Chua, Zhibo Cai, Leheng Sheng

arXiv · PDF · Open in the Atlas

Code that ran

7 of 8 samples (functions and classes) lifted from this paper's linked repositories executed on a synthesized input in Syntology's jail (2 of them constructed an object rather than computing a result; 0 honoured the contract we drafted, 0 violated it and 2 have no contract verdict; 5 failures of our instrument; 1 no recorded run), measured 2026-11-22; repository links from the Papers with Code archive attributed under CC BY-SA, no affiliation; 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/2310.18700.json · badge: /api/ran/2310.18700.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
lehengthu/advinfonce canonical (classifier label)
classifier basis: classifier_2025
5 ran · 1 no recorded run
LehengTHU/AdvInfoNCE canonical (classifier label)
classifier basis not recorded on the link
2 ran · 0 no recorded run
FunctionStatusWhere it lives
AdvInfoNCE Ran
ran on a synthesized input · constructed an object; no result was computed
lehengthu/advinfonce/model.py
code served (permissive licence) · get_code("cf3edb57afbf264e")
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, through the batch API) and returned an instance of its own class, AdvInfoNCE: the run constructed the object and did not call it, so no result was computed. 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 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
import numpy as np

torch.manual_seed(0)

class MockData:
    def __init__(self):
        self.n_users = 5
        self.n_items = 7
        self.train_user_list = {0: [0, 1], 1: [2, 3], 2: [1, 4], 3: [5, 6], 4: [0, 2]}
        self.valid_user_list = {0: [2], 1: [4], 2: [0], 3: [1], 4: [3]}
        self.user_pop_idx = np.array([1, 2, 1, 3, 2])
        self.item_pop_idx = np.array([2, 1, 3, 1, 2, 1, 3])
        self.user_pop_max = 3
        self.item_pop_max = 3
    
    def getSparseGraph(self):
        # Create a sparse adjacency matrix for the bipartite graph
        # Shape: (n_users + n_items) x (n_users + n_items)
        indices = torch.LongTensor([[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11],
                                     [5, 6, 7, 8, 5, 7, 9, 10, 0, 1, 2, 3]])
        values = torch.FloatTensor([1.0] * 12)
        size = (12, 12)
        return torch.sparse.FloatTensor(indices, values, size)

class MockArgs:
    def __init__(self):
        self.modeltype = 'AdvInfoNCE'
        self.lr = 0.001
        self.embed_size = 4
        self.batch_size = 2
        self.regs = 0.01
        self.cuda = 'cpu'
        self.saveID = 'test_model'
        self.train_norm = True
        self.pred_norm = True
        self.n_layers = 2
        self.tau = 0.1
        self.k_neg = 3
        self.w_embed_size = 8
        self.neg_sample = 2
        self.model_version = 'mlp'

ARGS = {
    'args': MockArgs(),
    'data': MockData(),
}
Setup block drafted by
a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API
Imports
numpy, torch — import names as written, not package names to install; a name the repository itself provides is not a package
Returned
type AdvInfoNCE — the run constructed an instance of its own class and did not call it; no shape is stated — the instrument coerces any output to an array; for a AdvInfoNCE output the recorded ndim 0 and dtype family float describe that coercion, not the output, and are not stated
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
MF Ran
ran on a synthesized input · constructed an object; no result was computed
lehengthu/advinfonce/model.py
code served (permissive licence) · get_code("d08e6a8f2f8b1da8")
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, through the batch API) and returned an instance of its own class, MF: the run constructed the object and did not call it, so no result was computed. 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 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)

class MockData:
    def __init__(self):
        self.n_users = 5
        self.n_items = 7
        self.train_user_list = [[0, 1], [2, 3], [1, 4]]
        self.valid_user_list = [[0, 2], [1, 3]]
        self.user_pop_idx = [0, 1, 2, 1, 0]
        self.item_pop_idx = [0, 1, 2, 1, 0, 2, 1]
        self.user_pop_max = 2
        self.item_pop_max = 2

class MockArgs:
    def __init__(self):
        self.modeltype = 'MF'
        self.lr = 0.001
        self.embed_size = 4
        self.batch_size = 2
        self.regs = 0.0001
        self.cuda = 'cpu'
        self.saveID = 'test_model'
        self.train_norm = True
        self.pred_norm = True

ARGS = {
    'args': MockArgs(),
    'data': MockData()
}
Setup block drafted by
a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API
Imports
torch — import names as written, not package names to install; a name the repository itself provides is not a package
Returned
type MF — the run constructed an instance of its own class and did not call it; no shape is stated — the instrument coerces any output to an array; for a MF output the recorded ndim 0 and dtype family float describe that coercion, not the output, and are not stated
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
helper_load Ran
ran; our contract draft was wrong, not the code
LehengTHU/AdvInfoNCE/data.py
pointer only (licence: MIT); the stored copy get_code serves, from lehengthu/alpharec, is pointer only (licence: NONE) · get_code("029327c4f6fb55d0")
How it ran

The body of this sample is withheld: this paper's link allows the body inline (MIT), but get_code serves the stored copy, first harvested from lehengthu/alpharec, and GitHub detected no licence in that repository when it was checked. The setup block that called it is withheld with it, because it is written against that body. source_path and origin say where the code lives, to read under the repository's own terms. A run is recorded.

helper_load_train Ran
ran; our contract draft was wrong, not the code
LehengTHU/AdvInfoNCE/data.py
pointer only (licence: MIT); the stored copy get_code serves, from lehengthu/alpharec, is pointer only (licence: NONE) · get_code("f1fe817c737b6fed")
How it ran

The body of this sample is withheld: this paper's link allows the body inline (MIT), but get_code serves the stored copy, first harvested from lehengthu/alpharec, and GitHub detected no licence in that repository when it was checked. The setup block that called it is withheld with it, because it is written against that body. source_path and origin say where the code lives, to read under the repository's own terms. A run is recorded.

merge_user_list Ran
ran; our contract draft was wrong, not the code
lehengthu/advinfonce/train_AdvInfoNCE.py
code served (permissive licence) · get_code("7513663e5a710c16")
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 defaultdict. The image it ran in was not recorded. If your copy returns the same type 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 collections

# Analyze the function: merge_user_list takes user_lists parameter
# It iterates over user_lists, and for each user_list:
#   - iterates over items() (so each element is dict-like)
#   - accesses key and item from the dict
#   - concatenates item to out[key] using + operator (so items are lists)

# Create sample user_lists - a list of dicts where values are lists
user_list_1 = {
    'user_a': [1, 2, 3],
    'user_b': [4, 5]
}

user_list_2 = {
    'user_a': [6, 7],
    'user_c': [8, 9, 10]
}

user_list_3 = {
    'user_b': [11],
    'user_c': [12]
}

user_lists = [user_list_1, user_list_2, user_list_3]

ARGS = {
    'user_lists': user_lists
}
Setup block drafted by
a language model, Claude Haiku 4.5, prompt python_fixture_v1
Imports
none outside the standard library — import names as written, not package names to install; a name the repository itself provides is not a package
Returned
type defaultdict — a defaultdict output has no array shape of its own; none is stated — the instrument coerces any output to an array; for a defaultdict output the recorded ndim 0 and dtype family float describe that coercion, not the output, and are not stated
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
merge_user_list_no_dup Ran
ran; our contract draft was wrong, not the code
lehengthu/advinfonce/train_AdvInfoNCE.py
code served (permissive licence) · get_code("63bb511f56afa437")
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 defaultdict. The image it ran in was not recorded. If your copy returns the same type 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 collections

# Analyze the function:
# - Takes user_lists as parameter
# - Iterates over user_lists (so it's iterable)
# - Each element (user_list) is a dict with .items()
# - Each item is (key, item) where item is something that can be added to a list
# - The values are converted to sets and back to lists (so they should be hashable)

# Create sample data matching the function's usage
user_list_1 = {
    'user_a': [1, 2, 3],
    'user_b': [4, 5],
}

user_list_2 = {
    'user_a': [2, 3, 6],
    'user_c': [7, 8],
}

user_list_3 = {
    'user_b': [5, 9],
    'user_a': [1],
}

user_lists = [user_list_1, user_list_2, user_list_3]

ARGS = {
    'user_lists': user_lists,
}
Setup block drafted by
a language model, Claude Haiku 4.5, prompt python_fixture_v1
Imports
none outside the standard library — import names as written, not package names to install; a name the repository itself provides is not a package
Returned
type defaultdict — a defaultdict output has no array shape of its own; none is stated — the instrument coerces any output to an array; for a defaultdict output the recorded ndim 0 and dtype family float describe that coercion, not the output, and are not stated
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
save_checkpoint Ran
ran; our contract draft was wrong, not the code
lehengthu/advinfonce/train_AdvInfoNCE.py
code served (permissive licence) · get_code("380a5cea5655f733")
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 list, ndim 1, dtype family float; no output shape is stated. The image it ran in was 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
import tempfile
import os

torch.manual_seed(0)

# Create a minimal model that has state_dict() method
class MinimalModel(nn.Module):
    def __init__(self):
        super().__init__()
        self.linear = nn.Linear(4, 3)
    
    def forward(self, x):
        return self.linear(x)

# Create temporary directory for checkpoints
checkpoint_dir = tempfile.mkdtemp()

# Create model instance
model = MinimalModel()

# Create buffer list to track checkpoint filenames
buffer = []

# Define arguments
ARGS = {
    'model': model,
    'epoch': 1,
    'checkpoint_dir': checkpoint_dir,
    'buffer': buffer,
    'max_to_keep': 10
}
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 list, ndim 1, dtype family float — a list output has no array shape of its own; none is stated
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
LGN Not yet run
unverified (harvested, no recorded run)
lehengthu/advinfonce/model.py
code served (permissive licence) · get_code("6cab2d4c2ffaeb32")
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, 5 are also present in other papers whose code we hold (5 with at least one paper dated earlier, 2 the same month, 2 later) and 3 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
helper_load_train 5 other papers
2 dated earlier, 2 the same month, 1 later
2210.11054 (2022-10)
Incorporating Bias-aware Margins into Contrastive Loss for Collaborative Filtering
2302.05328 (2023-02)
Invariant Collaborative Filtering to Popularity Distribution Shift
2310.10108 (2023-10)
On Generative Agents in Recommendation
and 2 more not named here
helper_load 4 other papers
2 dated earlier, 1 the same month, 1 later
2210.11054 (2022-10)
Incorporating Bias-aware Margins into Contrastive Loss for Collaborative Filtering
2302.05328 (2023-02)
Invariant Collaborative Filtering to Popularity Distribution Shift
2310.10108 (2023-10)
On Generative Agents in Recommendation
and 1 more not named here
merge_user_list 1 other paper
1 dated earlier
2302.05328 (2023-02)
Invariant Collaborative Filtering to Popularity Distribution Shift
merge_user_list_no_dup 1 other paper
1 dated earlier
2302.05328 (2023-02)
Invariant Collaborative Filtering to Popularity Distribution Shift
save_checkpoint 1 other paper
1 dated earlier
2302.05328 (2023-02)
Invariant Collaborative Filtering to Popularity Distribution Shift

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

Contrastive Learning (CL) has achieved impressive performance in self-supervised learning tasks, showing superior generalization ability. Inspired by the success, adopting CL into collaborative filtering (CF) is prevailing in semi-supervised top-K recommendations. The basic idea is to routinely conduct heuristic-based data augmentation and apply contrastive losses (e.g., InfoNCE) on the augmented views. Yet, some CF-tailored challenges make this adoption suboptimal, such as the issue of out-of-distribution, the risk of false negatives, and the nature of top-K evaluation. They necessitate the CL-based CF scheme to focus more on mining hard negatives and distinguishing false negatives from the vast unlabeled user-item interactions, for informative contrast signals. Worse still, there is limited understanding of contrastive loss in CF methods, especially w.r.t. its generalization ability. To bridge the gap, we delve into the reasons underpinning the success of contrastive loss in CF, and propose a principled Adversarial InfoNCE loss (AdvInfoNCE), which is a variant of InfoNCE, specially tailored for CF methods. AdvInfoNCE adaptively explores and assigns hardness to each negative instance in an adversarial fashion and further utilizes a fine-grained hardness-aware ranking criterion to empower the recommender's generalization ability. Training CF models with AdvInfoNCE, we validate the effectiveness of AdvInfoNCE on both synthetic and real-world benchmark datasets, thus showing its generalization ability to mitigate out-ofdistribution problems. Given the theoretical guarantees and empirical superiority of AdvInfoNCE over most contrastive loss functions, we advocate its adoption as a standard loss in recommender systems, particularly for the out-of-distribution tasks. Codes are available at https://github.com/LehengTHU/AdvInfoNCE.

For agents

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

get_harvested_code_for_paper("2310.18700")
get_code_for_paper("2310.18700")
have("2310.18700")

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

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

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

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

Connect an agent — have() is free.