SYNTOLOGY HomeExplorerAtlasCodeMethodologyAboutDevelopersFeedPricing
Paper · 2009.07839 · ICLR · 2021

Text Generation by Learning from Demonstrations

Richard Pang, He He

arXiv · PDF · Open in the Atlas

Code that ran

4 of 5 samples (functions and classes) lifted from this paper's linked repositories executed on a synthesized input in Syntology's jail (2 of them constructed an object rather than computing a result; 0 honoured the contract we drafted, 0 violated it and 3 have no contract verdict; 1 failure 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/2009.07839.json · badge: /api/ran/2009.07839.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
clovaai/FocusSeq2Seq community
Papers with Code archive
4 ran · 1 no recorded run
FunctionStatusWhere it lives
GRUEncoder Ran
ran on a synthesized input · constructed an object; no result was computed
clovaai/FocusSeq2Seq/models.py
code served (permissive licence) · get_code("5b9354b55563c25f")
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 an instance of its own class, GRUEncoder: the run constructed the object and did not call it, so no result was computed. 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 torch.nn as nn
from torch.nn.utils.rnn import pack_padded_sequence, pad_packed_sequence

torch.manual_seed(0)

class GRUEncoder(nn.Module):

    def __init__(self, word_embed_size=300, answer_position_embed_size=16, ner_embed_size=16, pos_embed_size=16, case_embed_size=16, hidden_size=300, dropout_p=0.2, task='QG'):
        super().__init__()
        self.task = task
        if task == 'QG':
            input_size = word_embed_size + answer_position_embed_size + ner_embed_size + pos_embed_size + case_embed_size
        else:
            input_size = word_embed_size
        self.rnn = nn.GRU(input_size=input_size, hidden_size=hidden_size // 2, batch_first=True, num_layers=1, bidirectional=True)
        self.hidden_size = hidden_size
        self.dropout = nn.Dropout(dropout_p)
        
        if task == 'QG':
            self.word_embed = nn.Embedding(100, word_embed_size, padding_idx=0)
            self.answer_position_embed = nn.Embedding(50, answer_position_embed_size, padding_idx=0)
            self.ner_embed = nn.Embedding(50, ner_embed_size, padding_idx=0)
            self.pos_embed = nn.Embedding(50, pos_embed_size, padding_idx=0)
            self.case_embed = nn.Embedding(50, case_embed_size, padding_idx=0)
        else:
            self.word_embed = nn.Embedding(100, word_embed_size, padding_idx=0)

    def forward(self, source_WORD_encoding, answer_position_BIO_encoding=None, ner_encoding=None, pos_encoding=None, case_encoding=None, PAD_ID=0):
        pad_mask = source_WORD_encoding == PAD_ID
        source_len = (~pad_mask).long().sum(dim=1)
        source_len_sorted, idx_sorted = torch.sort(source_len, dim=0, descending=True)
        _, idx_unsort = torch.sort(idx_sorted, dim=0)
        if self.task == 'QG':
            source_WORD_encoding = source_WORD_encoding[idx_sorted]
            answer_position_BIO_encoding = answer_position_BIO_encoding[idx_sorted]
            ner_encoding = ner_encoding[idx_sorted]
            pos_encoding = pos_encoding[idx_sorted]
            case_encoding = case_encoding[idx_sorted]
            word_embedding = self.word_embed(source_WORD_encoding)
            answer_position_embedding = self.answer_position_embed(answer_position_BIO_encoding)
            ner_embedding = self.ner_embed(ner_encoding)
            pos_embedding = self.pos_embed(pos_encoding)
            case_embedding = self.case_embed(case_encoding)
            enc_input = torch.cat([word_embedding, answer_position_embedding, ner_embedding, pos_embedding, case_embedding], dim=2)
        else:
            source_WORD_encoding = source_WORD_encoding[idx_sorted]
            word_embedding = self.word_embed(source_WORD_encoding)
            enc_input = word_embedding
        enc_input = self.dropout(enc_input)
        enc_input = pack_padded_sequence(enc_input, source_len_sorted, batch_first=True)
        enc_outputs, h = self.rnn(enc_input)
        enc_outputs, _ = pad_packed_sequence(enc_outputs, batch_first=True)
        enc_outputs = enc_outputs[idx_unsort]
        h = h.index_select(1, idx_unsort)
        return (enc_outputs, h)

model = GRUEncoder(
    word_embed_size=32,
    answer_position_embed_size=8,
    ner_embed_size=8,
    pos_embed_size=8,
    case_embed_size=8,
    hidden_size=64,
    dropout_p=0.2,
    task='QG'
)

batch_size = 2
seq_len = 4

source_WORD_encoding = torch.randint(1, 50, (batch_size, seq_len))
answer_position_BIO_encoding = torch.randint(0, 30, (batch_size, seq_len))
ner_encoding = torch.randint(0, 30, (batch_size, seq_len))
pos_encoding = torch.randint(0, 30, (batch_size, seq_len))
case_encoding = torch.randint(0, 30, (batch_size, seq_len))

ARGS = {
    'word_embed_size': 32,
    'answer_position_embed_size': 8,
    'ner_embed_size': 8,
    'pos_embed_size': 8,
    'case_embed_size': 8,
    'hidden_size': 64,
    'dropout_p': 0.2,
    'task': 'QG'
}
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 GRUEncoder — the run constructed an instance of its own class and did not call it; no shape is stated — the instrument coerces any output to an array; for a GRUEncoder 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
ParallelDecoder Ran
ran on a synthesized input
clovaai/FocusSeq2Seq/models.py
code served (permissive licence) · get_code("8c86add14c1d23db")
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 Tensor, ndim 2, 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
import torch.nn as nn

# INIT_ARGS for ParallelDecoder.__init__
INIT_ARGS = {
    'embed_size': 8,
    'enc_hidden_size': 12,
    'dec_hidden_size': 10,
    'n_mixture': 3,
    'threshold': 0.15,
    'task': 'QG'
}

# ARGS for ParallelDecoder.forward
B = 2
max_source_len = 5

ARGS = {
    'enc_outputs': torch.randn(B, max_source_len, INIT_ARGS['enc_hidden_size']),
    's': torch.randn(B, INIT_ARGS['dec_hidden_size']),
    'source_WORD_encoding': torch.randint(0, 100, (B, max_source_len)),
    'mixture_id': torch.randint(0, INIT_ARGS['n_mixture'], (B,)),
    'focus_input': None,
    'train': True,
    'max_decoding_len': None
}
Setup block drafted by
a language model, class construct-then-call prompt, model not recorded
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 — no output shape is stated: observe_signature.py observed this class with its constructor sizes canonicalised where it could, which the node does not record, so its shape is not stated as this setup block's
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: torch and numpy seeded to 0 by the harness immediately before the class was constructed from INIT_ARGS (fixture_check.py)
ParallelSelector Ran
ran on a synthesized input · constructed an object; no result was computed
clovaai/FocusSeq2Seq/models.py
code served (permissive licence) · get_code("fbd0b841504c9ce7")
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 an instance of its own class, ParallelSelector: the run constructed the object and did not call it, so no result was computed. 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 torch.nn as nn
from torch.nn.utils.rnn import pack_padded_sequence, pad_packed_sequence

torch.manual_seed(0)

# Define the GRUEncoder class first
class GRUEncoder(nn.Module):
    def __init__(self, word_embed_size=300, answer_position_embed_size=16, ner_embed_size=16, pos_embed_size=16, case_embed_size=16, hidden_size=300, dropout_p=0.2, task='QG'):
        super().__init__()
        self.task = task
        if task == 'QG':
            input_size = word_embed_size + answer_position_embed_size + ner_embed_size + pos_embed_size + case_embed_size
        else:
            input_size = word_embed_size
        self.rnn = nn.GRU(input_size=input_size, hidden_size=hidden_size // 2, batch_first=True, num_layers=1, bidirectional=True)
        self.hidden_size = hidden_size
        self.dropout = nn.Dropout(dropout_p)
        self.word_embed = nn.Embedding(100, word_embed_size, padding_idx=0)
        if task == 'QG':
            self.answer_position_embed = nn.Embedding(10, answer_position_embed_size)
            self.ner_embed = nn.Embedding(10, ner_embed_size)
            self.pos_embed = nn.Embedding(10, pos_embed_size)
            self.case_embed = nn.Embedding(10, case_embed_size)

    def forward(self, source_WORD_encoding, answer_position_BIO_encoding=None, ner_encoding=None, pos_encoding=None, case_encoding=None, PAD_ID=0):
        pad_mask = source_WORD_encoding == PAD_ID
        source_len = (~pad_mask).long().sum(dim=1)
        source_len_sorted, idx_sorted = torch.sort(source_len, dim=0, descending=True)
        _, idx_unsort = torch.sort(idx_sorted, dim=0)
        if self.task == 'QG':
            source_WORD_encoding = source_WORD_encoding[idx_sorted]
            answer_position_BIO_encoding = answer_position_BIO_encoding[idx_sorted]
            ner_encoding = ner_encoding[idx_sorted]
            pos_encoding = pos_encoding[idx_sorted]
            case_encoding = case_encoding[idx_sorted]
            word_embedding = self.word_embed(source_WORD_encoding)
            answer_position_embedding = self.answer_position_embed(answer_position_BIO_encoding)
            ner_embedding = self.ner_embed(ner_encoding)
            pos_embedding = self.pos_embed(pos_encoding)
            case_embedding = self.case_embed(case_encoding)
            enc_input = torch.cat([word_embedding, answer_position_embedding, ner_embedding, pos_embedding, case_embedding], dim=2)
        else:
            source_WORD_encoding = source_WORD_encoding[idx_sorted]
            word_embedding = self.word_embed(source_WORD_encoding)
            enc_input = word_embedding
        enc_input = self.dropout(enc_input)
        enc_input = pack_padded_sequence(enc_input, source_len_sorted, batch_first=True)
        enc_outputs, h = self.rnn(enc_input)
        enc_outputs, _ = pad_packed_sequence(enc_outputs, batch_first=True)
        enc_outputs = enc_outputs[idx_unsort]
        h = h.index_select(1, idx_unsort)
        return (enc_outputs, h)

# Define ParallelSelector class
class ParallelSelector(nn.Module):
    def __init__(self, word_embed_size=300, answer_position_embed_size=16, ner_embed_size=16, pos_embed_size=16, case_embed_size=16, enc_hidden_size=300, dec_hidden_size=300, num_layers=1, dropout_p=0.2, n_mixture=5, task='QG', threshold=0.15):
        super().__init__()
        self.task = task
        self.enc_hidden_size = enc_hidden_size
        self.dec_hidden_size = dec_hidden_size
        self.n_mixture = n_mixture
        self.encoder = GRUEncoder(word_embed_size, answer_position_embed_size, ner_embed_size, pos_embed_size, case_embed_size, enc_hidden_size, task=task)

    def forward(self):
        pass

# Create arguments for ParallelSelector
ARGS = {
    'word_embed_size': 300,
    'answer_position_embed_size': 16,
    'ner_embed_size': 16,
    'pos_embed_size': 16,
    'case_embed_size': 16,
    'enc_hidden_size': 300,
    'dec_hidden_size': 300,
    'num_layers': 1,
    'dropout_p': 0.2,
    'n_mixture': 5,
    'task': 'QG',
    'threshold': 0.15
}
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 ParallelSelector — the run constructed an instance of its own class and did not call it; no shape is stated — the instrument coerces any output to an array; for a ParallelSelector 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
repeat Ran
ran; our contract draft was wrong, not the code
clovaai/FocusSeq2Seq/models.py
code served (permissive licence) · get_code("f0d5ad048814d336")
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 3, dtype family float, shape (6, 4, 3) 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

torch.manual_seed(0)

# Test case 1: torch.Tensor input
tensor_input = torch.randn(2, 4, 3)

# Test case 2: list input (list of numpy arrays or similar copyable objects)
class CopyableArray:
    def __init__(self, data):
        self.data = data
    
    def copy(self):
        return CopyableArray(self.data.copy())

list_input = [CopyableArray(__import__('numpy').array([1, 2, 3])), 
              CopyableArray(__import__('numpy').array([4, 5, 6]))]

# K parameter - repetition factor
K = 3

# Define arguments - test with tensor input
ARGS = {
    "tensor": tensor_input,
    "K": K
}
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 3, dtype family float, shape (6, 4, 3) — shape (6, 4, 3) 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
FocusSelector Not yet run
unverified (harvested, no recorded run)
clovaai/FocusSeq2Seq/models.py
code served (permissive licence) · get_code("710c6122db670130")
How it ran

no invocation recorded.

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

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

Current approaches to text generation largely rely on autoregressive models and maximum likelihood estimation. This paradigm leads to (i) diverse but low-quality samples due to mismatched learning objective and evaluation metric (likelihood vs. quality) and (ii) exposure bias due to mismatched history distributions (gold vs. model-generated). To alleviate these problems, we frame text generation as an offline reinforcement learning (RL) problem with expert demonstrations (i.e., the reference), where the goal is to maximize quality given model-generated histories. We propose GOLD (generation by off-policy learning from demonstrations): an easy-to-optimize algorithm that learns from the demonstrations by importance weighting. Intuitively, GOLD upweights confident tokens and downweights unconfident ones in the reference during training, avoiding optimization issues faced by prior RL approaches that rely on online data collection. According to both automatic and human evaluation, models trained by GOLD outperform those trained by MLE and policy gradient on summarization, question generation, and machine translation. Further, our models are less sensitive to decoding algorithms and alleviate exposure bias.

For agents

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

get_harvested_code_for_paper("2009.07839")
get_code_for_paper("2009.07839")
have("2009.07839")

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

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

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

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

Connect an agent — have() is free.