SYNTOLOGY HomeExplorerAtlasCodeMethodologyAboutDevelopersFeedPricing
Paper · 2022.findings-naacl.188 · NAACL Findings · 2022

RCL: Relation Contrastive Learning for Zero-Shot Relation Extraction

Yajing Xu, Bo Xiao, Shusen Wang, Yanan Wu, Bosen Zhang

Open in the Atlas

Code that ran

5 of 5 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 4 have no contract verdict; 1 failure of our instrument; 0 no recorded run), measured 2026-11-24; 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/2022.findings-naacl.188.json · badge: /api/ran/2022.findings-naacl.188.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
ShusenWang/NAACL2022-RCL canonical (classifier label)
classifier basis: census
5 ran · 0 no recorded run
FunctionStatusWhere it lives
collate_fn Ran
ran on a synthesized input
ShusenWang/NAACL2022-RCL/dataset.py
code served (permissive licence) · get_code("46ddb71cf3bafbb3")
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

torch.manual_seed(0)

# Create sample batch data
batch = [
    {
        'input_ids': torch.tensor([[101, 2054, 2003, 102]]),
        'attention_mask': torch.tensor([[1, 1, 1, 1]]),
        'entity_idx': 2,
        'token_type_ids': torch.tensor([[0, 0, 1, 1]]),
        'label': 1,
    },
    {
        'input_ids': torch.tensor([[101, 2054, 2054, 102]]),
        'attention_mask': torch.tensor([[1, 1, 1, 1]]),
        'entity_idx': 1,
        'token_type_ids': torch.tensor([[0, 1, 1, 0]]),
        'label': 0,
    },
]

ARGS = {
    '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 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
format_time Ran
ran; our contract draft was wrong, not the code
ShusenWang/NAACL2022-RCL/utils.py
code served (permissive licence) · get_code("b37f7ffc7831d837")
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 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 datetime

def format_time(elapsed):
    """
    Takes a time in seconds and returns a string hh:mm:ss
    """
    elapsed_rounded = int(round(elapsed))
    return str(datetime.timedelta(seconds=elapsed_rounded))

ARGS = {
    "elapsed": 3661.5
}
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 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
read_data Ran
ran on a synthesized input
ShusenWang/NAACL2022-RCL/utils.py
code served (permissive licence) · get_code("38914ac4c8dd30f4")
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 tempfile
import csv
import os

# Create a temporary CSV file with test data
temp_dir = tempfile.mkdtemp()
data_file = os.path.join(temp_dir, 'test_data.csv')

with open(data_file, 'w', newline='', encoding='utf-8') as f:
    writer = csv.DictWriter(f, fieldnames=['sentences', 'label'])
    writer.writerow({'sentences': 'sentences', 'label': 'label'})  # header
    writer.writerow({'sentences': '<e1>entity1</e1> and <e2>entity2</e2>', 'label': 'relation_A'})
    writer.writerow({'sentences': '<e1>subject</e1> interacts <e2>object</e2>', 'label': 'relation_B'})
    writer.writerow({'sentences': '<e1>foo</e1> with <e2>bar</e2>', 'label': 'relation_A'})
    writer.writerow({'sentences': '<e1>x</e1> and <e2>y</e2>', 'label': 'other'})

labellist = ['relation_A', 'relation_B']

ARGS = {
    'data': data_file,
    'labellist': labellist,
    'use_mark': True
}
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
read_json Ran
ran on a synthesized input
ShusenWang/NAACL2022-RCL/utils.py
code served (permissive licence) · get_code("c10bf1ea56c58e14")
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 json
import tempfile
import os

# Create a temporary JSON file with some test data
temp_dir = tempfile.mkdtemp()
data_file = os.path.join(temp_dir, "test_data.json")

test_data = {
    "key1": "value1",
    "key2": [1, 2, 3],
    "key3": {"nested": "dict"}
}

with open(data_file, 'w') as f:
    json.dump(test_data, f)

ARGS = {
    "data_file": data_file
}
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 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
standard_metric_result Ran
ran on a synthesized input
ShusenWang/NAACL2022-RCL/evaluation.py
code served (permissive licence) · get_code("0897116d93e81989")
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 collections
from sklearn.metrics import classification_report

# Analyze the function to understand what it needs:
# - gt: a list/array of ground truth labels (strings or comparable)
# - cluster_result: a list/array of cluster assignments (integers)
# - labellist: a list of unique label strings that can be indexed

# Create small test data
gt = ['cat', 'dog', 'cat', 'bird', 'dog', 'cat']
cluster_result = [0, 1, 0, 2, 1, 0]
labellist = ['cat', 'dog', 'bird']

ARGS = {
    'gt': gt,
    'cluster_result': cluster_result,
    'labellist': labellist
}
Setup block drafted by
a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API
Imports
sklearn — 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

Also present in other papers' code

Of 5 samples lifted from this paper's linked repositories, 5 carry a function identity and 0 do not. Of the 5 distinct functions with an identity, 1 are also present in other papers whose code we hold (1 with at least one paper dated earlier, 0 the same month, 1 later) and 4 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
format_time 4 other papers
1 dated earlier, 3 later
2109.05897 (2021-09)
Question Answering over Electronic Devices: A New Benchmark Dataset and a Multi-Task Learning based QA Framework
2301.11796 (2023-01)
Call for Papers -- The BabyLM Challenge: Sample-efficient pretraining on a developmentally plausible corpus
2402.11235 (2024-02)
ZeroG: Investigating Cross-dataset Zero-shot Transferability in Graphs
and 1 more not named here

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

Repositories linked to this paper

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

Abstract

Zero-shot relation extraction aims to identify novel relations which cannot be observed at the training stage. However, it still faces some challenges since the unseen relations of instances are similar or the input sentences have similar entities, the unseen relation representations from different categories tend to overlap and lead to errors. In this paper, we propose a novel Relation Contrastive Learning framework (RCL) to mitigate above two types of similar problems: Similar Relations and Similar Entities. By jointly optimizing a contrastive instance loss with a relation classification loss on seen relations, RCL can learn subtle difference between instances and achieve better separation between different relation categories in the representation space simultaneously. Especially in contrastive instance learning, the dropout noise as data augmentation is adopted to amplify the semantic difference between similar instances without breaking relation representation, so as to promote model to learn more effective representations. Experiments conducted on two well-known datasets show that RCL can significantly outperform previous state-of-the-art methods. Moreover, if the seen relations are insufficient, RCL can also obtain comparable results with the model trained on the full training set, showing the robustness of our approach 1

For agents

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

get_harvested_code_for_paper("2022.findings-naacl.188")
get_code_for_paper("2022.findings-naacl.188")
have("2022.findings-naacl.188")

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

curl https://syntology.ai/api/ran/2022.findings-naacl.188.json

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

[![Syntology run record](https://syntology.ai/api/ran/2022.findings-naacl.188.svg)](https://syntology.ai/paper/2022.findings-naacl.188)

Connect an agent — have() is free.