SYNTOLOGY HomeExplorerAtlasCodeMethodologyAboutDevelopersFeedPricing
Paper · 2004.09015 · ACL · 2020

Incorporating External Knowledge through Pre-training for Natural Language to Code Generation

Graham Neubig, Frank Xu, Pengcheng Yin, Zhengbao Jiang, Bogdan Vasilescu

arXiv · PDF · 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 3 have no contract verdict; 2 failures of our instrument; 0 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/2004.09015.json · badge: /api/ran/2004.09015.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
neulab/external-knowledge-codegen canonical (classifier label)
classifier basis: census
5 ran · 0 no recorded run
FunctionStatusWhere it lives
decode Ran
ran on a synthesized input
neulab/external-knowledge-codegen/evaluation.py
code served (permissive licence) · get_code("0bf34988625f82d1")
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 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
from dataclasses import dataclass

torch.manual_seed(0)

# Stand-in classes for tree and hypothesis
class TreeNode:
    def __init__(self, value="root"):
        self.value = value
        self.children = []
    
    def to_string(self):
        return f"({self.value})"

class Hypothesis:
    def __init__(self, tree):
        self.tree = tree
        self.code = None

class Example:
    def __init__(self, idx, src_sent, tgt_code):
        self.idx = idx
        self.src_sent = src_sent
        self.tgt_code = tgt_code

class TransitionSystem:
    def ast_to_surface_code(self, tree):
        return f"code_for_{tree.value}"

# Minimal model that satisfies the function's usage
class DummyModel(nn.Module):
    def __init__(self):
        super().__init__()
        self.transition_system = TransitionSystem()
        self.linear = nn.Linear(4, 4)
    
    def parse(self, src_sent, context=None, beam_size=1):
        # Return list of hypotheses with trees
        hyps = []
        for i in range(beam_size):
            tree = TreeNode(f"tree_{i}")
            hyp = Hypothesis(tree)
            hyps.append(hyp)
        return hyps

# Create example data
examples = [
    Example(idx="ex_0", src_sent=["hello", "world"], tgt_code="code_0"),
    Example(idx="ex_1", src_sent=["foo", "bar"], tgt_code="code_1"),
]

# Create model
model = DummyModel()

# Create args namespace
@dataclass
class Args:
    beam_size: int = 2

args = Args()

# Define ARGS dict
ARGS = {
    'examples': examples,
    'model': model,
    'args': args,
    'verbose': False,
}
Setup block drafted by
a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API
Imports
torch, tqdm — import names as written, not package names to install; a name the repository itself provides is not a package
Returned
type list, ndim 2, 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
dot_prod_attention Ran
ran; our contract draft was wrong, not the code
neulab/external-knowledge-codegen/model/nn_utils.py
code served (permissive licence) · get_code("8a2b39c05ccc8ca0")
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 torch.nn.functional as F

torch.manual_seed(0)

batch_size = 2
hidden_size = 4
src_sent_len = 3

# h_t: (batch_size, hidden_size)
h_t = torch.randn(batch_size, hidden_size)

# src_encoding: (batch_size, src_sent_len, hidden_size * 2)
src_encoding = torch.randn(batch_size, src_sent_len, hidden_size * 2)

# src_encoding_att_linear: (batch_size, src_sent_len, hidden_size)
src_encoding_att_linear = torch.randn(batch_size, src_sent_len, hidden_size)

# mask: (batch_size, src_sent_len) - boolean mask where True values should be masked out
mask = torch.tensor([[False, True, False], [False, False, True]])

ARGS = {
    'h_t': h_t,
    'src_encoding': src_encoding,
    'src_encoding_att_linear': src_encoding_att_linear,
    'mask': mask
}
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 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
evaluate Ran
ran; our contract draft was wrong, not the code
neulab/external-knowledge-codegen/evaluation.py
code served (permissive licence) · get_code("3115c02671dad0f4")
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 torch.nn as nn
from dataclasses import dataclass

torch.manual_seed(0)

# Stand-in classes for the AST/tree structures
class Node:
    def __init__(self, value):
        self.value = value
        self.children = []
    
    def to_string(self):
        return f"Node({self.value})"

class Hypothesis:
    def __init__(self, tree):
        self.tree = tree
        self.code = None
        self.score = 0.0

class Example:
    def __init__(self, idx, src_sent, tgt_code):
        self.idx = idx
        self.src_sent = src_sent
        self.tgt_code = tgt_code

class TransitionSystem:
    def ast_to_surface_code(self, tree):
        return f"code_from_{tree.to_string()}"

class Parser(nn.Module):
    def __init__(self, transition_system):
        super().__init__()
        self.transition_system = transition_system
        self.linear = nn.Linear(4, 2)
    
    def parse(self, src_sent, context=None, beam_size=1):
        # Return a list of Hypothesis objects
        hyps = []
        for i in range(beam_size):
            tree = Node(f"tree_{i}")
            hyp = Hypothesis(tree)
            hyps.append(hyp)
        return hyps

class Evaluator:
    def evaluate_dataset(self, examples, decode_results, fast_mode=False, args=None):
        # Return a simple evaluation result dict
        return {
            'accuracy': 0.5,
            'bleu': 0.75,
            'total': len(examples)
        }

# Create minimal examples
examples = [
    Example(idx="ex1", src_sent=["hello", "world"], tgt_code="print('hello')"),
    Example(idx="ex2", src_sent=["foo", "bar"], tgt_code="x = 42"),
]

# Create transition system and parser
transition_system = TransitionSystem()
parser = Parser(transition_system)

# Create evaluator
evaluator = Evaluator()

# Create args
@dataclass
class Args:
    beam_size: int = 2

args = Args()

ARGS = {
    'examples': examples,
    'parser': parser,
    'evaluator': evaluator,
    'args': args,
    'verbose': False,
    'return_decode_result': False,
    'eval_top_pred_only': False,
}
Setup block drafted by
a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API
Imports
torch, 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
input_transpose Ran
ran on a synthesized input
neulab/external-knowledge-codegen/model/nn_utils.py
code served (permissive licence) · get_code("4d634e9ce2a4f738")
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 2, 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
from six.moves import xrange

# Define the arguments for input_transpose
# The function expects:
# - sents: List[sequence] of size (batch_size, max_sent_len)
# - pad_token: a token value to use for padding

# Create a small batch of sequences with different lengths
sents = [
    [1, 2, 3],           # sequence of length 3
    [4, 5]               # sequence of length 2
]

pad_token = 0  # Use 0 as the padding token

ARGS = {
    "sents": sents,
    "pad_token": pad_token
}
Setup block drafted by
a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API
Imports
six, torch — import names as written, not package names to install; a name the repository itself provides is not a package
Returned
type list, ndim 2, 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
length_array_to_mask_tensor Ran
ran on a synthesized input
neulab/external-knowledge-codegen/model/nn_utils.py
code served (permissive licence) · get_code("4f498904d7930e35")
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 2, dtype family int, shape (3, 5) as a later run recorded it. The image it ran in was not recorded. The code mentions cuda, and the harness aliases cuda to the CPU for every sample; whether this run needed that is 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)

ARGS = {
    "length_array": [3, 5, 2],
    "cuda": False,
    "valid_entry_has_mask_one": False,
}
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 Tensor, ndim 2, dtype family int, shape (3, 5) — shape (3, 5) 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

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, 4 are also present in other papers whose code we hold (4 with at least one paper dated earlier, 0 the same month, 2 later) and 1 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
dot_prod_attention 2 other papers
2 dated earlier
1810.02720 (2018-10)
TRANX: A Transition-based Neural Abstract Syntax Parser for Semantic Parsing and Code Generation
1905.08205 (2019-05)
Towards Complex Text-to-SQL in Cross-Domain Database with Intermediate Representation
input_transpose 2 other papers
1 dated earlier, 1 later
1810.02720 (2018-10)
TRANX: A Transition-based Neural Abstract Syntax Parser for Semantic Parsing and Code Generation
2105.14796 (2021-05)
Improving Tree-Structured Decoder Training for Code Generation via Mutual Learning
length_array_to_mask_tensor 2 other papers
1 dated earlier, 1 later
1810.02720 (2018-10)
TRANX: A Transition-based Neural Abstract Syntax Parser for Semantic Parsing and Code Generation
2105.14796 (2021-05)
Improving Tree-Structured Decoder Training for Code Generation via Mutual Learning
evaluate 1 other paper
1 dated earlier
1810.02720 (2018-10)
TRANX: A Transition-based Neural Abstract Syntax Parser for Semantic Parsing and Code 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-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

Open-domain code generation aims to generate code in a general-purpose programming language (such as Python) from natural language (NL) intents. Motivated by the intuition that developers usually retrieve resources on the web when writing code, we explore the effectiveness of incorporating two varieties of external knowledge into NL-to-code generation: automatically mined NL-code pairs from the online programming QA forum StackOverflow and programming language API documentation. Our evaluations show that combining the two sources with data augmentation and retrieval-based data re-sampling improves the current state-of-the-art by up to 2.2% absolute BLEU score on the code generation testbed CoNaLa.

For agents

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

get_harvested_code_for_paper("2004.09015")
get_code_for_paper("2004.09015")
have("2004.09015")

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

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

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

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

Connect an agent — have() is free.