SYNTOLOGY HomeExplorerAtlasCodeMethodologyAboutDevelopersFeedPricing
Paper · 2210.01185 · 2022

ContraCLM: Contrastive Learning For Causal Language Model

arXiv · PDF · Open in the Atlas

Code that ran

9 of 13 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 9 have no contract verdict; 0 failures of our instrument; 4 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/2210.01185.json · badge: /api/ran/2210.01185.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
amazon-science/contraclm community (classifier label)
classifier basis not recorded on the link
9 ran · 4 no recorded run
FunctionStatusWhere it lives
add_model_args Ran
ran on a synthesized input
amazon-science/contraclm/pl_args.py
code served (permissive licence) · get_code("008a4d21086f7138")
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 ArgumentParser. 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 argparse
import torch

torch.manual_seed(0)

# Create a parent parser
parent_parser = argparse.ArgumentParser(add_help=False)

ARGS = {
    'parent_parser': parent_parser
}
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 ArgumentParser — a ArgumentParser output has no array shape of its own; none is stated — the instrument coerces any output to an array; for a ArgumentParser 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
add_pl_args Ran
ran on a synthesized input
amazon-science/contraclm/pl_args.py
code served (permissive licence) · get_code("0df5b55bef0786f2")
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 ArgumentParser. 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 argparse
import os
import tempfile

# Create a temporary directory to serve as the default_root_dir
temp_dir = tempfile.mkdtemp()

# Create the ARGS dictionary with all parameters for add_pl_args
ARGS = {
    'parent_parser': argparse.ArgumentParser()
}
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 ArgumentParser — a ArgumentParser output has no array shape of its own; none is stated — the instrument coerces any output to an array; for a ArgumentParser 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
chunk Ran
ran on a synthesized input
amazon-science/contraclm/preprocess/preprocess_bq.py
code served (permissive licence) · get_code("290fcdb620dd0473")
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 dict. 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

# Construct a simple raw string with multiple lines
raw_str = "Line 1 with some text\nLine 2 with more content\nLine 3\nLine 4 with even longer content here\nLine 5\n"

# Set max_chars_per_seq to a reasonable value that will cause chunking
max_chars_per_seq = 50

ARGS = {
    'raw_str': raw_str,
    'max_chars_per_seq': max_chars_per_seq
}
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 dict — a dict output has no array shape of its own; none is stated — the instrument coerces any output to an array; for a dict 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
dataset_from_all_data Ran
ran on a synthesized input
amazon-science/contraclm/preprocess/preprocess_bq.py
code served (permissive licence) · get_code("6e58b45e167db47f")
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 DatasetDict. 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 datasets import Dataset, DatasetDict

torch.manual_seed(0)

# Construct all_data as a dictionary with text and label fields
all_data = {
    'text': ['hello world', 'foo bar', 'baz qux', 'test data', 'sample text', 'another example'],
    'label': [0, 1, 0, 1, 0, 1]
}

ARGS = {
    'all_data': all_data,
    'seed': 42,
    'test_and_valid_combined_size': 0.4
}
Setup block drafted by
a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API
Imports
datasets, numpy, torch — import names as written, not package names to install; a name the repository itself provides is not a package
Returned
type DatasetDict — a DatasetDict output has no array shape of its own; none is stated — the instrument coerces any output to an array; for a DatasetDict 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
get_single_indent_function_by_indent Ran
ran on a synthesized input
amazon-science/contraclm/evaluation/code_generation/execution_utils.py
code served (permissive licence) · get_code("0901fceaa134a507")
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

# Analyze the function:
# - It takes a single parameter: completion
# - completion is a string that gets split by '\n'
# - The function processes each line, checking for comments, empty lines, line continuations, and indentation
# - It returns a truncated string

ARGS = {
    "completion": """    def example_func():
        # This is a comment
        x = 1
        y = 2
        return x + y
    
def next_function():
    pass"""
}
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 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
load_deepspeed_state_dict Ran
ran on a synthesized input
amazon-science/contraclm/utils.py
code served (permissive licence) · get_code("cf3156865f00c5bd")
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 dict. 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 tempfile
import os

torch.manual_seed(0)

# Create a temporary directory for the state dict file
temp_dir = tempfile.mkdtemp()
state_dict_path = os.path.join(temp_dir, "deepspeed_state.pt")

# Test case 1: state_dict with 'state_dict' attribute
state_dict_content = {
    'state_dict': {
        'model.layer1.weight': torch.randn(4, 3),
        'model.layer1.bias': torch.randn(4),
        'model.layer2.weight': torch.randn(3, 2),
    }
}

torch.save(state_dict_content, state_dict_path)

ARGS = {
    'state_dict_path': state_dict_path,
}
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 dict — a dict output has no array shape of its own; none is stated — the instrument coerces any output to an array; for a dict 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
process_bq Ran
ran on a synthesized input
amazon-science/contraclm/preprocess/preprocess_bq.py
code served (permissive licence) · get_code("39c140c1814b8a50")
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 dict. 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 tempfile
import os
import json

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

# Create a subdirectory to match the expected structure
data_subdir = os.path.join(temp_dir, 'test_data')
os.makedirs(data_subdir)

# Create sample JSONL files
file1_path = os.path.join(data_subdir, 'file1.jsonl')
with open(file1_path, 'w') as f:
    f.write(json.dumps({'content': 'sample content 1'}) + '\n')
    f.write(json.dumps({'content': 'sample content 2'}) + '\n')

file2_path = os.path.join(data_subdir, 'file2.jsonl')
with open(file2_path, 'w') as f:
    f.write(json.dumps({'content': 'sample content 3'}) + '\n')
    f.write(json.dumps({'content': 'sample content 4'}) + '\n')

ARGS = {
    'bq_dir': data_subdir
}
Setup block drafted by
a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API
Imports
tqdm — import names as written, not package names to install; a name the repository itself provides is not a package
Returned
type dict — a dict output has no array shape of its own; none is stated — the instrument coerces any output to an array; for a dict 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
setup_filename Ran
ran on a synthesized input
amazon-science/contraclm/evaluation/code_generation/execution_utils.py
code served (permissive licence) · get_code("2c4c6622f834965b")
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 os

class Args:
    def __init__(self):
        self.decoding_strategy = 'temperature_sampling'
        self.sampling_temperature = 0.7
        self.ranked_pass_at_k = True
        self.max_completion_length = 256
        self.num_samples_per_task = 10
        self.ckpt_dir = '/tmp/checkpoints'

ARGS = {
    'args': Args(),
    'task_name': 'code_generation'
}
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 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
setup_log_path Ran
ran on a synthesized input
amazon-science/contraclm/utils.py
code served (permissive licence) · get_code("bd7e0765146e36f7")
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 Args:
    def __init__(self):
        self.expt_prefix = "experiment"
        self.loss = "cross_entropy"
        self.train_batch_size = 32
        self.lr = 1e-4
        self.max_steps = -1
        self.num_training_examples = 10000
        self.devices = 1
        self.accumulate_grad_batches = 1
        self.max_epochs = 3
        self.model_name = "Salesforce/codegen-350M-mono"
        self.functional_dropout = True
        self.dropout_p = 0.1
        self.dropout_layers = 0
        self.warmup_steps = 500
        self.weight_decay = 0.01
        self.temperature = 1.0

ARGS = {
    "args": Args(),
    "num_nodes": 1
}
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
get_unwrapped_state_dict Not yet run
unverified (harvested, no recorded run)
amazon-science/contraclm/evaluation/code_search/model.py
code served (permissive licence) · get_code("751e6eadf409ba7f")
How it ran

no invocation recorded.

load_model_and_tokenizer Not yet run
unverified (harvested, no recorded run)
amazon-science/contraclm/utils.py
code served (permissive licence) · get_code("0770c863fd59b11f")
How it ran

no invocation recorded.

solve_tasks Not yet run
unverified (harvested, no recorded run)
amazon-science/contraclm/evaluation/code_generation/execution_utils.py
code served (permissive licence) · get_code("7edc50a43a8d82d3")
How it ran

no invocation recorded.

truncate_and_tokenize Not yet run
unverified (harvested, no recorded run)
amazon-science/contraclm/preprocess/preprocess_wikitext.py
code served (permissive licence) · get_code("58841a8b0179e38c")
How it ran

no invocation recorded.

Also present in other papers' code

Of 13 samples lifted from this paper's linked repositories, 13 carry a function identity and 0 do not. Of the 13 distinct functions with an identity, 0 are also present in other papers whose code we hold (0 with at least one paper dated earlier, 0 the same month, 0 later) and 13 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.

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

Despite exciting progress in causal language models, the expressiveness of the representations is largely limited due to poor discrimination ability. To remedy this issue, we present ContraCLM, a novel contrastive learning framework at both token-level and sequence-level. We assess ContraCLM on a variety of downstream tasks. We show that ContraCLM enhances discrimination of the representations and bridges the gap with the encoder-only models, which makes causal language models better suited for tasks beyond language generation. Specifically, we attain $44\%$ relative improvement on the Semantic Textual Similarity tasks and $34\%$ on Code-to-Code Search tasks. Furthermore, by improving the expressiveness of the representations, ContraCLM also boosts the source code generation capability with $9\%$ relative improvement on execution accuracy on the HumanEval benchmark.

For agents

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

get_harvested_code_for_paper("2210.01185")
get_code_for_paper("2210.01185")
have("2210.01185")

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

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

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

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

Connect an agent — have() is free.