SYNTOLOGY HomeExplorerAtlasCodeMethodologyAboutDevelopersFeedPricing
Paper · 2203.09101 · ACL Findings · 2022

RelationPrompt: Leveraging Prompts to Generate Synthetic Data for Zero-Shot Relation Triplet Extraction

Luo Si, Soujanya Poria, Lidong Bing, Yew Ken Chia

arXiv · PDF · Open in the Atlas

Code that ran

15 of 26 samples (functions and classes) lifted from this paper's linked repositories executed on a synthesized input in Syntology's jail (1 of them constructed an object rather than computing a result; 4 honoured the contract we drafted, 0 violated it and 3 have no contract verdict; 8 failures of our instrument; 11 no recorded run), measured 2026-11-21; 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/2203.09101.json · badge: /api/ran/2203.09101.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
declare-lab/hyperred community
Papers with Code archive
11 ran · 5 no recorded run
declare-lab/RelationPrompt community
Papers with Code archive
4 ran · 6 no recorded run
FunctionStatusWhere it lives
BertLayerNorm Ran
ran on a synthesized input
declare-lab/hyperred/modeling.py
pointer only (licence: NONE) · get_code("f24a08472067dcf7")
How it ran

The body of this sample is withheld: GitHub detected no licence in this paper's repository, declare-lab/hyperred 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.

BertLinear Ran
ran on a synthesized input
declare-lab/hyperred/modeling.py
pointer only (licence: NONE) · get_code("28a82cb66563a20d")
How it ran

The body of this sample is withheld: GitHub detected no licence in this paper's repository, declare-lab/hyperred 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.

RelationSentence Ran
ran on a synthesized input · constructed an object; no result was computed
declare-lab/RelationPrompt/generation.py
code served (permissive licence) · get_code("1bf96a550bc9db35")
How it ran

Ran in Syntology's sandbox on this synthesized input (drafted by a language model, class construct-then-call prompt, model not recorded) and returned RelationSentence: the class was constructed and called, and the call returned an instance of its own class. 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.

from typing import Dict, List, Optional, Tuple
from pydantic import BaseModel

def align_span_to_tokens(span: str, tokens: List[str]) -> Tuple[int, int]:
    char_word_map = {}
    num_chars = 0
    for i, w in enumerate(tokens):
        for _ in w:
            char_word_map[num_chars] = i
            num_chars += 1
    char_word_map[num_chars] = len(tokens)
    query = span.replace(' ', '')
    text = ''.join(tokens)
    assert query in text
    i = text.find(query)
    start = char_word_map[i]
    end = char_word_map[i + len(query) - 1]
    assert 0 <= start <= end
    return (start, end + 1)

def find_span(span: str, tokens: List[str]) -> List[int]:
    if span == '':
        return []
    start = find_sublist_index(tokens, span.split())
    if start >= 0:
        return [start + i for i in range(len(span.split()))]
    else:
        start, end = align_span_to_tokens(span, tokens)
        return list(range(start, end))

def find_sublist_index(items: list, query: list):
    length = len(query)
    for i in range(len(items) - length + 1):
        if items[i:i + length] == query:
            return i
    return -1

class RelationSentence(BaseModel):
    tokens: List[str]
    head: List[int]
    tail: List[int]
    label: str
    head_id: str = ''
    tail_id: str = ''
    label_id: str = ''
    error: str = ''
    raw: str = ''
    score: float = 0.0
    zerorc_included: bool = True

    def as_tuple(self) -> Tuple[str, str, str]:
        head = ' '.join([self.tokens[i] for i in self.head])
        tail = ' '.join([self.tokens[i] for i in self.tail])
        return (head, self.label, tail)

    def as_line(self) -> str:
        return self.json() + '\n'

    def is_valid(self) -> bool:
        for x in [self.tokens, self.head, self.tail, self.label]:
            if len(x) == 0:
                return False
        for x in [self.head, self.tail]:
            if -1 in x:
                return False
        return True

    @property
    def text(self) -> str:
        return ' '.join(self.tokens)

    @classmethod
    def from_spans(cls, text: str, head: str, tail: str, label: str, strict=True):
        tokens = text.split()
        sent = cls(tokens=tokens, head=find_span(head, tokens), tail=find_span(tail, tokens), label=label)
        if strict:
            assert sent.is_valid(), (head, label, tail, text)
        return sent

    def as_marked_text(self) -> str:
        tokens = list(self.tokens)
        for i, template in [(self.head[0], '[H {}'), (self.head[-1], '{} ]'), (self.tail[0], '[T {}'), (self.tail[-1], '{} ]')]:
            tokens[i] = template.format(tokens[i])
        return ' '.join(tokens)


INIT_ARGS = {
    'tokens': ['The', 'cat', 'sat', 'on', 'the', 'mat'],
    'head': [0, 1],
    'tail': [3, 4, 5],
    'label': 'located_at',
    'head_id': 'e1',
    'tail_id': 'e2',
    'label_id': 'rel1',
    'error': '',
    'raw': 'The cat sat on the mat',
    'score': 0.95,
    'zerorc_included': True
}

ARGS = {
    'text': 'The cat sat on the mat',
    'head': 'The cat',
    'tail': 'on the mat',
    'label': 'located_at',
    'strict': False
}

METHOD = 'from_spans'

if __name__ == '__main__':
    instance = RelationSentence(**INIT_ARGS)
    print("Instance created:")
    print(f"  tokens: {instance.tokens}")
    print(f"  head: {instance.head}")
    print(f"  tail: {instance.tail}")
    print(f"  label: {instance.label}")
    print(f"  is_valid: {instance.is_valid()}")
    print(f"  text: {instance.text}")
    print(f"  as_tuple: {instance.as_tuple()}")
    print(f"  as_marked_text: {instance.as_marked_text()}")
    
    print("\nCalling from_spans method:")
    result = RelationSentence.from_spans(**ARGS)
    print(f"  Result tokens: {result.tokens}")
    print(f"  Result head: {result.head}")
    print(f"  Result tail: {result.tail}")
    print(f"  Result label: {result.label}")
    print(f"  Result is_valid: {result.is_valid()}")
    print(f"  Result as_tuple: {result.as_tuple()}")
Setup block drafted by
a language model, class construct-then-call prompt, model not recorded
Imports
pydantic — import names as written, not package names to install; a name the repository itself provides is not a package
Returned
type RelationSentence — the call returned an instance of its own class, which has no array shape; none is stated — the instrument coerces any output to an array; for a RelationSentence 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: torch and numpy seeded to 0 by the harness immediately before the class was constructed from INIT_ARGS (fixture_check.py)
align_span_to_tokens Ran
ran, honoured the contract we drafted
declare-lab/RelationPrompt/generation.py
code served (permissive licence) · get_code("46b3836cd0547e98")
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 tuple, ndim 1, dtype family int; 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 numpy as np

# Analyze the function:
# - span: str - a string to find in the concatenated tokens
# - tokens: List[str] - a list of token strings
# The function finds where 'span' (with spaces removed) appears in the concatenated tokens
# and returns the token indices (start, end+1) that cover that span

# Create test data
span = "helloworld"
tokens = ["hello", "world", "test"]

ARGS = {
    "span": span,
    "tokens": tokens,
}
Setup block drafted by
a language model, Claude Haiku 4.5, prompt python_fixture_v1
Imports
numpy, torch — 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 int — 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
batched_index_select Ran
ran; our contract draft was wrong, not the code
declare-lab/hyperred/modeling.py
pointer only (licence: NONE) · get_code("8e14a5ff3ee5597f")
How it ran

The body of this sample is withheld: GitHub detected no licence in this paper's repository, declare-lab/hyperred 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.

check_adjacent Ran
ran; the contract check could not run (RAISES, DEP_MISSING or TIMEOUT)
declare-lab/hyperred/modeling.py
pointer only (licence: NONE) · get_code("eb611ef75d9aa110")
How it ran

The body of this sample is withheld: GitHub detected no licence in this paper's repository, declare-lab/hyperred 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.

decode_nonzero_cuboids Ran
ran; the contract check could not run (RAISES, DEP_MISSING or TIMEOUT)
declare-lab/hyperred/modeling.py
pointer only (licence: NONE) · get_code("4c70a6becf27ff53")
How it ran

The body of this sample is withheld: GitHub detected no licence in this paper's repository, declare-lab/hyperred 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.

find_span Ran
ran, honoured the contract we drafted
declare-lab/RelationPrompt/generation.py
code served (permissive licence) · get_code("48a2b26807165ecf")
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 int; 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 numpy as np
from typing import Dict, List, Optional, Tuple

torch.manual_seed(0)

# Test case 1: span matches exactly with token boundaries
span_1 = "hello world"
tokens_1 = ["hello", "world", "test"]

# Test case 2: span requires character-level alignment
span_2 = "lloworl"
tokens_2 = ["hello", "world", "test"]

# Test case 3: empty span
span_3 = ""
tokens_3 = ["hello", "world"]

# Test case 4: single token span
span_4 = "hello"
tokens_4 = ["hello", "world"]

# Test case 5: span with spaces that need to be removed for alignment
span_5 = "ell wor"
tokens_5 = ["hello", "world"]

ARGS = {
    "span": span_1,
    "tokens": tokens_1
}
Setup block drafted by
a language model, Claude Haiku 4.5, prompt python_fixture_v1
Imports
numpy, 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 int — 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
find_sublist_index Ran
ran; the contract check could not run (RAISES, DEP_MISSING or TIMEOUT)
declare-lab/RelationPrompt/generation.py
code served (permissive licence) · get_code("97a3eca137c3440e")
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 int, ndim 0, dtype family int, 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)

# The function find_sublist_index takes two parameters:
# - items: a list to search within
# - query: a list to search for as a sublist
# 
# The function iterates through items looking for a contiguous sublist
# that matches query exactly using list equality comparison.

ARGS = {
    "items": [1, 2, 3, 4, 5, 6, 7, 8],
    "query": [4, 5, 6]
}
Setup block drafted by
a language model, Claude Haiku 4.5, prompt python_fixture_v1
Imports
numpy, torch — import names as written, not package names to install; a name the repository itself provides is not a package
Returned
type int, ndim 0, dtype family int, 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
flatten_and_batch_shift_indices Ran
ran; our contract draft was wrong, not the code
declare-lab/hyperred/modeling.py
pointer only (licence: NONE) · get_code("27e54a4cbd7d001d")
How it ran

The body of this sample is withheld: GitHub detected no licence in this paper's repository, declare-lab/hyperred 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.

gelu Ran
ran, honoured the contract we drafted
declare-lab/hyperred/modeling.py
pointer only (licence: NONE) · get_code("e650dcdf9e8a559f")
How it ran

The body of this sample is withheld: GitHub detected no licence in this paper's repository, declare-lab/hyperred 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_device_of Ran
ran; our contract draft was wrong, not the code
declare-lab/hyperred/modeling.py
pointer only (licence: NONE) · get_code("5ea35802d5e71352")
How it ran

The body of this sample is withheld: GitHub detected no licence in this paper's repository, declare-lab/hyperred 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_range_vector Ran
ran, honoured the contract we drafted
declare-lab/hyperred/modeling.py
pointer only (licence: NONE) · get_code("2b70d9c14170a263")
How it ran

The body of this sample is withheld: GitHub detected no licence in this paper's repository, declare-lab/hyperred 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.

prune_matrix Ran
ran; the contract check could not run (RAISES, DEP_MISSING or TIMEOUT)
declare-lab/hyperred/modeling.py
pointer only (licence: NONE) · get_code("439cdde1774200fe")
How it ran

The body of this sample is withheld: GitHub detected no licence in this paper's repository, declare-lab/hyperred 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.

update_bounds Ran
ran; the contract check could not run (RAISES, DEP_MISSING or TIMEOUT)
declare-lab/hyperred/modeling.py
pointer only (licence: NONE) · get_code("d61d313e081aa624")
How it ran

The body of this sample is withheld: GitHub detected no licence in this paper's repository, declare-lab/hyperred 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.

BertEmbedModel Not yet run
unverified (harvested, no recorded run)
declare-lab/hyperred/modeling.py
pointer only (licence: NONE) · get_code("4534173317cad377")
How it ran

The body of this sample is withheld: GitHub detected no licence in this paper's repository, declare-lab/hyperred 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. No invocation recorded.

BertEncoder Not yet run
unverified (harvested, no recorded run)
declare-lab/hyperred/modeling.py
pointer only (licence: NONE) · get_code("e3af493846de2812")
How it ran

The body of this sample is withheld: GitHub detected no licence in this paper's repository, declare-lab/hyperred 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. No invocation recorded.

CubeRE Not yet run
unverified (harvested, no recorded run)
declare-lab/hyperred/modeling.py
pointer only (licence: NONE) · get_code("2e36d81e1a7ea466")
How it ran

The body of this sample is withheld: GitHub detected no licence in this paper's repository, declare-lab/hyperred 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. No invocation recorded.

DynamicModel Not yet run
unverified (harvested, no recorded run)
declare-lab/RelationPrompt/generation.py
code served (permissive licence) · get_code("1f6ddb84b665fb98")
How it ran

no invocation recorded.

Encoder Not yet run
unverified (harvested, no recorded run)
declare-lab/RelationPrompt/generation.py
code served (permissive licence) · get_code("b4e5d615275044cf")
How it ran

no invocation recorded.

ExtractEncoder Not yet run
unverified (harvested, no recorded run)
declare-lab/RelationPrompt/generation.py
code served (permissive licence) · get_code("43f13b65e230563d")
How it ran

no invocation recorded.

LabelConstraint Not yet run
unverified (harvested, no recorded run)
declare-lab/RelationPrompt/generation.py
code served (permissive licence) · get_code("ea519177ab88447d")
How it ran

no invocation recorded.

PretrainedEmbedModel Not yet run
unverified (harvested, no recorded run)
declare-lab/hyperred/modeling.py
pointer only (licence: NONE) · get_code("dc5e765561b30b13")
How it ran

The body of this sample is withheld: GitHub detected no licence in this paper's repository, declare-lab/hyperred 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. No invocation recorded.

PretrainedEncoder Not yet run
unverified (harvested, no recorded run)
declare-lab/hyperred/modeling.py
pointer only (licence: NONE) · get_code("ee228a910e7ecb91")
How it ran

The body of this sample is withheld: GitHub detected no licence in this paper's repository, declare-lab/hyperred 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. No invocation recorded.

TextGenerator Not yet run
unverified (harvested, no recorded run)
declare-lab/RelationPrompt/generation.py
code served (permissive licence) · get_code("c5312c4d166f9950")
How it ran

no invocation recorded.

TripletSearchDecoder Not yet run
unverified (harvested, no recorded run)
declare-lab/RelationPrompt/generation.py
code served (permissive licence) · get_code("1ad6a72afada7941")
How it ran

no invocation recorded.

Also present in other papers' code

Of 26 samples lifted from this paper's linked repositories, 26 carry a function identity and 0 do not. Of the 26 distinct functions with an identity, 2 are also present in other papers whose code we hold (1 with at least one paper dated earlier, 1 the same month, 2 later) and 24 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
gelu
brick of this paper's assembly: helper
198 other papers
101 dated earlier, 10 the same month, 83 later, 4 same year, order not determinable · 32 only as an assembly brick
1408.5882 (2014-08)
Convolutional Neural Networks for Sentence Classification
1810.04805 (2018-10)
BERT: Pre-training of Deep Bidirectional Transformers for Language Understanding
1901.10125 (2019-01)
Glyce: Glyph-vectors for Chinese Character Representations
and 195 more not named here
find_sublist_index
brick of this paper's assembly: helper
1 other paper
1 later
2210.10709 (2022-10)
Schema-aware Reference as Prompt Improves Data-Efficient Knowledge Graph Construction

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

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 the importance of relation extraction in building and representing knowledge, less research is focused on generalizing to unseen relations types. We introduce the task setting of Zero-Shot Relation Triplet Extraction (Ze-roRTE) to encourage further research in lowresource relation extraction methods. Given an input sentence, each extracted triplet consists of the head entity, relation label, and tail entity where the relation label is not seen at the training stage. To solve ZeroRTE, we propose to synthesize relation examples by prompting language models to generate structured texts. Concretely, we unify language model prompts and structured text approaches to design a structured prompt template for generating synthetic relation samples when conditioning on relation label prompts (RelationPrompt). To overcome the limitation for extracting multiple relation triplets in a sentence, we design a novel Triplet Search Decoding method. Experiments on FewRel and Wiki-ZSL datasets show the efficacy of RelationPrompt for the ZeroRTE task and zero-shot relation classification. Our code and data are available at github.com/declare-lab/RelationPrompt.

For agents

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

get_harvested_code_for_paper("2203.09101")
get_code_for_paper("2203.09101")
have("2203.09101")

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

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

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

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

Connect an agent — have() is free.