SYNTOLOGY HomeExplorerAtlasCodeMethodologyAboutDevelopersFeedPricing
Paper · 2007.00808 · 2020

Approximate Nearest Neighbor Negative Contrastive Learning for Dense Text Retrieval

arXiv · PDF · Open in the Atlas

Code that ran

11 of 12 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; 1 honoured the contract we drafted, 0 violated it and 6 have no contract verdict; 4 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/2007.00808.json · badge: /api/ran/2007.00808.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
microsoft/ANCE canonical (classifier label)
classifier basis: census
10 ran · 1 no recorded run
microsoft/seed-encoder extension (classifier label)
classifier basis: classifier_2025
1 ran · 0 no recorded run
FunctionStatusWhere it lives
GetProcessingFn Ran
ran; our contract draft was wrong, not the code
microsoft/seed-encoder/data/msmarco_data.py
code served (permissive licence) · get_code("4ccfcf15369dfbea")
How it ran

Ran in Syntology's sandbox on this synthesized input (drafted by a language model, Claude Sonnet 4.5, prompt python_fixture_v1) and returned function. 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 torch
from torch.utils.data import DataLoader, Dataset, TensorDataset, IterableDataset, get_worker_info

torch.manual_seed(0)

class Args:
    def __init__(self):
        self.max_query_length = 10
        self.max_seq_length = 15

args = Args()

ARGS = {
    "args": args,
    "query": False
}
Setup block drafted by
a language model, Claude Sonnet 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 function — a function output has no array shape of its own; none is stated — the instrument coerces any output to an array; for a function 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
convert_to_unicode Ran
ran on a synthesized input
microsoft/ANCE/model/SEED_Encoder/tokenization_seed_encoder.py
code served (permissive licence) · get_code("e8a98cc72991f258")
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 str. 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 six

# Test cases for convert_to_unicode function
# The function accepts a single parameter 'text' which can be:
# - str (in Python 3)
# - bytes (in Python 3)
# - str (in Python 2, but we're on Python 3)

# Create test arguments
ARGS = {
    'text': 'hello world'
}

# Additional test cases can be created like this:
# ARGS = {'text': b'hello world'}  # bytes input
# ARGS = {'text': 'unicode string with émojis 🎉'}  # unicode string
Setup block drafted by
a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API
Imports
six — import names as written, not package names to install; a name the repository itself provides is not a package
Returned
type str — a str output has no array shape of its own; none is stated — the instrument coerces any output to an array; for a str 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
fill_with_neg_inf Ran
ran, honoured the contract we drafted
microsoft/ANCE/model/SEED_Encoder/transformer_sentence_encoder.py
pointer only (licence: MIT); the stored copy get_code serves, from kenford953/graphcage, is pointer only (licence: NONE) · get_code("8f266b9d616de9b9")
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 kenford953/graphcage, 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.

get_encoder_params_state Ran
ran; our contract draft was wrong, not the code
microsoft/ANCE/utils/dpr_utils.py
pointer only (licence: MIT); the stored copy get_code serves, from MiuLab/UMR, is pointer only (licence: NONE) · get_code("538cfaef12b25b54")
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 MiuLab/UMR, 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.

get_model_obj Ran
ran on a synthesized input
microsoft/ANCE/utils/dpr_utils.py
code served (permissive licence) · get_code("59da6f907f4e84f2")
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 Linear. 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 torch
from torch import nn

torch.manual_seed(0)

# Create a simple model
simple_model = nn.Linear(4, 3)

# Create a wrapped model (DataParallel-like wrapper)
class ModelWrapper(nn.Module):
    def __init__(self, model):
        super().__init__()
        self.module = model
    
    def forward(self, x):
        return self.module(x)

wrapped_model = ModelWrapper(simple_model)

# Test case 1: model with .module attribute
model_with_module = wrapped_model

ARGS = {
    "model": model_with_module
}
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 Linear — a Linear output has no array shape of its own; none is stated — the instrument coerces any output to an array; for a Linear 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
item Ran
ran on a synthesized input
microsoft/ANCE/model/SEED_Encoder/transformer_sentence_encoder.py
code served (permissive licence) · get_code("07179da1319d3649")
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 float, 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 numpy as np

torch.manual_seed(0)

# Test case 1: torch tensor with .item() method
tensor_with_item = torch.tensor(42.5)

# Test case 2: indexable object (list, numpy array, etc.)
indexable_tensor = np.array([3.14, 2.71, 1.41])

# Test case 3: plain Python scalar
plain_scalar = 7

ARGS = {
    "tensor": tensor_with_item
}
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 float, 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
load_positive_ids Ran
ran on a synthesized input
microsoft/ANCE/drivers/run_ann_data_gen.py
code served (permissive licence) · get_code("8340872a93ffe88f")
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 tuple, 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 os
import tempfile
import csv

class Args:
    def __init__(self, data_dir):
        self.data_dir = data_dir

# Create temporary directory with test data files
temp_dir = tempfile.mkdtemp()

# Create train-qrel.tsv
train_qrel_path = os.path.join(temp_dir, 'train-qrel.tsv')
with open(train_qrel_path, 'w', newline='', encoding='utf8') as f:
    writer = csv.writer(f, delimiter='\t')
    writer.writerow(['1', '100', '1'])
    writer.writerow(['2', '200', '1'])
    writer.writerow(['3', '300', '1'])

# Create dev-qrel.tsv
dev_qrel_path = os.path.join(temp_dir, 'dev-qrel.tsv')
with open(dev_qrel_path, 'w', newline='', encoding='utf8') as f:
    writer = csv.writer(f, delimiter='\t')
    writer.writerow(['1', '101', '1'])
    writer.writerow(['1', '102', '0'])
    writer.writerow(['2', '201', '2'])
    writer.writerow(['3', '301', '1'])

ARGS = {
    'args': Args(data_dir=temp_dir)
}
Setup block drafted by
a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API
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 tuple, ndim 1, dtype family float — a tuple 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
log_softmax Ran
ran on a synthesized input
microsoft/ANCE/model/SEED_Encoder/modules.py
code served (permissive licence) · get_code("6ad0e0ed0c9a7ee4")
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 Tensor, ndim 2, dtype family float, shape (2, 4) 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 torch.nn.functional as F

torch.manual_seed(0)

# Create a small tensor for testing
x = torch.randn(2, 4)

# Define ARGS dict with all parameters
ARGS = {
    "x": x,
    "dim": 1,
    "onnx_trace": False
}
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 Tensor, ndim 2, dtype family float, shape (2, 4) — shape (2, 4) 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
set_encoder_params_from_state Ran
ran; our contract draft was wrong, not the code
microsoft/ANCE/utils/dpr_utils.py
pointer only (licence: MIT); the stored copy get_code serves, from MiuLab/UMR, is pointer only (licence: NONE) · get_code("e44c1974fb9752d3")
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 MiuLab/UMR, 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.

softmax Ran
ran; the contract check could not run (RAISES, DEP_MISSING or TIMEOUT)
microsoft/ANCE/model/SEED_Encoder/modules.py
code served (permissive licence) · get_code("f4d9cafead3a750e")
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 Tensor, ndim 2, dtype family float, shape (2, 4) 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 torch.nn.functional as F

torch.manual_seed(0)

# Create a small tensor for testing
x = torch.randn(2, 4)

# Define arguments for the softmax function
ARGS = {
    "x": x,
    "dim": 1,
    "onnx_trace": False
}
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 Tensor, ndim 2, dtype family float, shape (2, 4) — shape (2, 4) 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
triplet_fwd_pass Ran
ran on a synthesized input
microsoft/ANCE/drivers/run_ann_dpr.py
code served (permissive licence) · get_code("06aa628bdeb1eed9")
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 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 torch.nn as nn

torch.manual_seed(0)

class TripletModel(nn.Module):
    def __init__(self):
        super().__init__()
        self.embedding = nn.Embedding(100, 8)
        self.linear = nn.Linear(8, 1)
    
    def forward(self, query_ids, attention_mask_q, input_ids_a, attention_mask_a, input_ids_b, attention_mask_b):
        q_emb = self.embedding(query_ids).mean(dim=1)
        a_emb = self.embedding(input_ids_a).mean(dim=1)
        b_emb = self.embedding(input_ids_b).mean(dim=1)
        
        loss = self.linear(q_emb).mean() + self.linear(a_emb).mean() + self.linear(b_emb).mean()
        return (loss,)

class Args:
    def __init__(self):
        self.device = 'cpu'
        self.n_gpu = 1
        self.gradient_accumulation_steps = 1

batch = (
    torch.randint(0, 100, (2, 4)),
    torch.ones((2, 4)),
    torch.randint(0, 100, (2, 4)),
    torch.randint(0, 100, (2, 4)),
    torch.ones((2, 4)),
    torch.randint(0, 100, (2, 4)),
    torch.randint(0, 100, (2, 4)),
    torch.ones((2, 4)),
)

model = TripletModel()
args = Args()

ARGS = {
    'args': args,
    'model': model,
    'batch': batch
}
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 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
LayerNorm Not yet run
unverified (harvested, no recorded run)
microsoft/ANCE/model/SEED_Encoder/modules.py
code served (permissive licence) · get_code("932bcadd912b1422")
How it ran

no invocation recorded.

Also present in other papers' code

Of 12 samples lifted from this paper's linked repositories, 12 carry a function identity and 0 do not. Of the 12 distinct functions with an identity, 5 are also present in other papers whose code we hold (1 with at least one paper dated earlier, 1 the same month, 4 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
fill_with_neg_inf 16 other papers
1 dated earlier, 15 later · 3 only as an assembly brick
1906.00295 (2019-06)
Multimodal Transformer for Unaligned Multimodal Language Sequences
2109.04096 (2021-09)
A Three-Stage Learning Framework for Low-Resource Knowledge-Grounded Dialogue Generation
2111.08456 (2021-11)
Trustworthy Multimodal Regression with Mixture of Normal-inverse Gamma Distributions
and 13 more not named here
get_encoder_params_state 2 other papers
2 later
2024.findings-acl.708 (2024 (year only))
Analyze, Generate and Refine: Query Expansion with LLMs for Zero-Shot Open-Domain QA
2403.03516 (2024-03)
Unsupervised Multilingual Dense Retrieval via Generative Pseudo Labeling
set_encoder_params_from_state 2 other papers
2 later
2024.findings-acl.708 (2024 (year only))
Analyze, Generate and Refine: Query Expansion with LLMs for Zero-Shot Open-Domain QA
2403.03516 (2024-03)
Unsupervised Multilingual Dense Retrieval via Generative Pseudo Labeling
item 1 other paper
1 the same month
2007.04785 (2020-07)
Accuracy Prediction with Non-neural Model for Neural Architecture Search
softmax 1 other paper
1 later
2407.03575 (2024-07)
DGR-MIL: Exploring Diverse Global Representation in Multiple Instance Learning for Whole Slide Image Classification

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

Conducting text retrieval in a dense learned representation space has many intriguing advantages over sparse retrieval. Yet the effectiveness of dense retrieval (DR) often requires combination with sparse retrieval. In this paper, we identify that the main bottleneck is in the training mechanisms, where the negative instances used in training are not representative of the irrelevant documents in testing. This paper presents Approximate nearest neighbor Negative Contrastive Estimation (ANCE), a training mechanism that constructs negatives from an Approximate Nearest Neighbor (ANN) index of the corpus, which is parallelly updated with the learning process to select more realistic negative training instances. This fundamentally resolves the discrepancy between the data distribution used in the training and testing of DR. In our experiments, ANCE boosts the BERT-Siamese DR model to outperform all competitive dense and sparse retrieval baselines. It nearly matches the accuracy of sparse-retrieval-and-BERT-reranking using dot-product in the ANCE-learned representation space and provides almost 100x speed-up.

For agents

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

get_harvested_code_for_paper("2007.00808")
get_code_for_paper("2007.00808")
have("2007.00808")

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

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

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

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

Connect an agent — have() is free.