SYNTOLOGY HomeExplorerAtlasCodeMethodologyAboutDevelopersFeedPricing
Paper · 2211.10797 · 2022

An Empirical Study On Contrastive Search And Contrastive Decoding For Open-ended Text Generation

arXiv · PDF · Open in the Atlas

Code that ran

9 of 9 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; 9 failures of our instrument; 0 no recorded run), measured 2026-11-23; 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/2211.10797.json · badge: /api/ran/2211.10797.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
yxuansu/contrastive_search_versus_contrastive_decoding canonical (classifier label)
classifier basis: classifier_2025
5 ran · 0 no recorded run
copy not recorded community
not in the paper's declared repositories
4 ran · 0 no recorded run
FunctionStatusWhere it lives
decode Ran
ran; our contract draft was wrong, not the code
yxuansu/contrastive_search_versus_contrastive_decoding/compute_CD_coherence.py
code served (permissive licence) · get_code("fa974683b3309bff")
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 torch
import numpy as np

class MockTokenizer:
    def __init__(self):
        self.vocab = {
            "[CLS]": 101,
            "[SEP]": 102,
            "hello": 7592,
            "world": 2088,
            "[PAD]": 0,
            "[UNK]": 100,
        }
        self.id_to_token = {v: k for k, v in self.vocab.items()}
    
    def convert_tokens_to_ids(self, tokens):
        """Convert token strings to their IDs."""
        return [self.vocab.get(token, self.vocab["[UNK]"]) for token in tokens]
    
    def decode(self, token_id_list):
        """Convert token IDs back to text."""
        tokens = [self.id_to_token.get(tid, "[UNK]") for tid in token_id_list]
        return " ".join(tokens)

tokenizer = MockTokenizer()
tokens = ["hello", "world"]

ARGS = {
    "tokens": tokens,
    "tokenizer": tokenizer,
}
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 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
generate_one_instance Ran
ran; our contract draft was wrong, not the code
this paper's copy was not recorded; identical code first harvested from yxuansu/contrastive_search_is_what_you_need
pointer only; the stored copy get_code serves, from yxuansu/contrastive_search_is_what_you_need, is pointer only (licence: NONE) · get_code("cac40e03d91cfcd2")
How it ran

The body of this sample is withheld: this paper's copy of the code was not recorded (its link names no repository or source path), so no licence was read for it. 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.

inference_one_instance Ran
ran; our contract draft was wrong, not the code
this paper's copy was not recorded; identical code first harvested from yxuansu/contrastive_search_is_what_you_need
pointer only; the stored copy get_code serves, from yxuansu/contrastive_search_is_what_you_need, is pointer only (licence: NONE) · get_code("bd4a83f85a760a62")
How it ran

The body of this sample is withheld: this paper's copy of the code was not recorded (its link names no repository or source path), so no licence was read for it. 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.

load_data Ran
ran; our contract draft was wrong, not the code
yxuansu/contrastive_search_versus_contrastive_decoding/inference.py
code served (permissive licence) · get_code("4fa756ab2e71d478")
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. 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 json
import tempfile
import os

class MockTokenizer:
    def tokenize(self, text):
        # Simple whitespace tokenization
        return text.split()
    
    def convert_tokens_to_ids(self, tokens):
        # Simple hash-based token IDs
        return [hash(token) % 1000 for token in tokens]
    
    def decode(self, token_ids):
        # Simple reverse mapping - just reconstruct approximate text
        return f"decoded_{len(token_ids)}_tokens"

# Create a temporary JSON file with test data
temp_file = tempfile.NamedTemporaryFile(mode='w', suffix='.jsonl', delete=False)
temp_filename = temp_file.name

# Write test data in JSONL format (one JSON object per line)
test_data = [
    {'prompt': 'Hello world', 'gold_ref': 'Hello world this is a test'},
    {'prompt': 'The quick brown', 'gold_ref': 'The quick brown fox jumps over'}
]

for item in test_data:
    json.dump([item], temp_file)
    temp_file.write('\n')

temp_file.close()

tokenizer = MockTokenizer()
in_f = temp_filename
mode = 'default'

ARGS = {
    'in_f': in_f,
    'tokenizer': tokenizer,
    'mode': mode
}
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 — a tuple output has no array shape of its own; none is 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
parse_data Ran
ran; our contract draft was wrong, not the code
yxuansu/contrastive_search_versus_contrastive_decoding/compute_CD_coherence.py
code served (permissive licence) · get_code("0714e04d4711a1fe")
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 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
from transformers import AutoTokenizer

# Create a minimal stand-in tokenizer that has the required methods
class MinimalTokenizer:
    def __init__(self):
        self.vocab = {
            "hello": 101,
            "world": 102,
            "this": 103,
            "is": 104,
            "a": 105,
            "test": 106,
            "[UNK]": 100,
            "[CLS]": 107,
            "[SEP]": 108,
        }
        self.id_to_token = {v: k for k, v in self.vocab.items()}
    
    def tokenize(self, text):
        # Simple tokenization by splitting on spaces
        words = text.lower().split()
        tokens = []
        for word in words:
            if word in self.vocab:
                tokens.append(word)
            else:
                tokens.append("[UNK]")
        return tokens
    
    def convert_tokens_to_ids(self, tokens):
        # Convert token strings to IDs
        token_ids = []
        for token in tokens:
            if token in self.vocab:
                token_ids.append(self.vocab[token])
            else:
                token_ids.append(self.vocab["[UNK]"])
        return token_ids
    
    def decode(self, token_ids):
        # Convert token IDs back to text
        tokens = []
        for token_id in token_ids:
            if token_id in self.id_to_token:
                tokens.append(self.id_to_token[token_id])
            else:
                tokens.append("[UNK]")
        return " ".join(tokens)

tokenizer = MinimalTokenizer()

prefix_text_list = [
    "hello world",
    "this is"
]

prediction_text_list = [
    "hello world a test",
    "this is a test"
]

ARGS = {
    "prefix_text_list": prefix_text_list,
    "prediction_text_list": prediction_text_list,
    "tokenizer": tokenizer
}
Setup block drafted by
a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API
Imports
torch, transformers — 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
parse_one_text Ran
ran; our contract draft was wrong, not the code
yxuansu/contrastive_search_versus_contrastive_decoding/compute_CD_coherence.py
code served (permissive licence) · get_code("2b22d120b73eca34")
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 torch
import numpy as np

class MockTokenizer:
    def __init__(self):
        self.vocab = {
            "hello": 1,
            "world": 2,
            "this": 3,
            "is": 4,
            "a": 5,
            "test": 6,
            "[UNK]": 0,
            "[CLS]": 7,
            "[SEP]": 8,
        }
        self.id_to_token = {v: k for k, v in self.vocab.items()}
    
    def tokenize(self, text):
        tokens = text.lower().split()
        return [t if t in self.vocab else "[UNK]" for t in tokens]
    
    def convert_tokens_to_ids(self, tokens):
        return [self.vocab.get(token, 0) for token in tokens]
    
    def decode(self, token_ids):
        tokens = [self.id_to_token.get(tid, "[UNK]") for tid in token_ids]
        return " ".join(tokens)

tokenizer = MockTokenizer()
text = "hello world this is a test"
prefix_len = 2

ARGS = {
    "text": text,
    "tokenizer": tokenizer,
    "prefix_len": prefix_len,
}
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 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
parse_output Ran
ran; our contract draft was wrong, not the code
this paper's copy was not recorded; identical code first harvested from yxuansu/contrastive_search_is_what_you_need
pointer only; the stored copy get_code serves, from yxuansu/contrastive_search_is_what_you_need, is pointer only (licence: NONE) · get_code("a115616e0c6ba1e8")
How it ran

The body of this sample is withheld: this paper's copy of the code was not recorded (its link names no repository or source path), so no licence was read for it. 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.

parse_text Ran
ran; our contract draft was wrong, not the code
yxuansu/contrastive_search_versus_contrastive_decoding/inference.py
code served (permissive licence) · get_code("66a2664f44c5cb07")
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. 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
import numpy as np
from transformers import AutoTokenizer

# Create a minimal tokenizer-like object that implements the required methods
class MinimalTokenizer:
    def __init__(self):
        self.vocab = {
            'hello': 0,
            'world': 1,
            'this': 2,
            'is': 3,
            'a': 4,
            'test': 5,
            'prefix': 6,
            'gold': 7,
            'reference': 8,
            'text': 9,
        }
        self.id_to_token = {v: k for k, v in self.vocab.items()}
    
    def tokenize(self, text):
        # Simple whitespace tokenization
        tokens = text.lower().split()
        return tokens
    
    def convert_tokens_to_ids(self, tokens):
        # Convert tokens to IDs, using vocab
        ids = []
        for token in tokens:
            if token in self.vocab:
                ids.append(self.vocab[token])
            else:
                ids.append(0)  # unknown token maps to 0
        return ids
    
    def decode(self, token_ids):
        # Convert token IDs back to text
        tokens = [self.id_to_token.get(tid, 'unk') for tid in token_ids]
        return ' '.join(tokens)

# Create sample item with required structure
item = [
    {
        'prompt': 'hello world this is',
        'gold_ref': 'hello world this is a test reference text'
    }
]

# Create tokenizer
tokenizer = MinimalTokenizer()

# Define mode
mode = 'other'

# Construct ARGS dictionary
ARGS = {
    'item': item,
    'tokenizer': tokenizer,
    'mode': mode
}
Setup block drafted by
a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API
Imports
numpy, torch, transformers — import names as written, not package names to install; a name the repository itself provides is not a package
Returned
type tuple — a tuple output has no array shape of its own; none is 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_result Ran
ran; our contract draft was wrong, not the code
this paper's copy was not recorded; identical code first harvested from yxuansu/contrastive_search_is_what_you_need
pointer only; the stored copy get_code serves, from yxuansu/contrastive_search_is_what_you_need, is pointer only (licence: NONE) · get_code("08a4d22e5a9f3b60")
How it ran

The body of this sample is withheld: this paper's copy of the code was not recorded (its link names no repository or source path), so no licence was read for it. 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.

Also present in other papers' code

Of 9 samples lifted from this paper's linked repositories, 9 carry a function identity and 0 do not. Of the 9 distinct functions with an identity, 4 are also present in other papers whose code we hold (4 with at least one paper dated earlier, 0 the same month, 0 later) and 5 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
generate_one_instance 1 other paper
1 dated earlier
2210.14140 (2022-10)
Contrastive Search Is What You Need For Neural Text Generation
inference_one_instance 1 other paper
1 dated earlier
2210.14140 (2022-10)
Contrastive Search Is What You Need For Neural Text Generation
parse_output 1 other paper
1 dated earlier
2210.14140 (2022-10)
Contrastive Search Is What You Need For Neural Text Generation
save_result 1 other paper
1 dated earlier
2210.14140 (2022-10)
Contrastive Search Is What You Need For Neural Text Generation

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-23.

Repositories linked to this paper

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

Abstract

In the study, we empirically compare the two recently proposed decoding methods, i.e. Contrastive Search (CS) and Contrastive Decoding (CD), for open-ended text generation. The automatic evaluation results suggest that, while CS performs worse than CD on the MAUVE metric, it substantially surpasses CD on the diversity and coherence metrics. More notably, extensive human evaluations across three different domains demonstrate that human annotators are universally more in favor of CS over CD with substantial margins. The contradicted results between MAUVE and human evaluations reveal that MAUVE does not accurately reflect human preferences. Therefore, we call upon the research community to develop better evaluation metrics for open-ended text generation. To ensure the reproducibility of our work, we have open-sourced all our code, evaluation results, as well as human annotations at https://github.com/yxuansu/Contrastive_Search_versus_Contrastive_Decoding.

For agents

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

get_harvested_code_for_paper("2211.10797")
get_code_for_paper("2211.10797")
have("2211.10797")

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

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

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

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

Connect an agent — have() is free.