SYNTOLOGY HomeExplorerAtlasCodeMethodologyAboutDevelopersFeedPricing
Paper · 1910.07517 · 2019

Adversarial Examples for Models of Code

arXiv · PDF · Open in the Atlas

Code that ran

10 of 10 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; 6 failures of our instrument; 0 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/1910.07517.json · badge: /api/ran/1910.07517.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
tech-srl/code2seq canonical (classifier label)
classifier basis: census
5 ran · 0 no recorded run
copy not recorded community
not in the paper's declared repositories
4 ran · 0 no recorded run
ciselab/lampion extension (classifier label)
classifier basis: classifier_2025
1 ran · 0 no recorded run
FunctionStatusWhere it lives
adversary_by_prefix_random Ran
ran; the contract check could not run (RAISES, DEP_MISSING or TIMEOUT)
this paper's copy was not recorded; identical code first harvested from tech-srl/adversarial-examples
pointer only · get_code("9ab8f76e5ee9bc91")
How it ran

The body of this sample is withheld: this paper's copy of the code was not recorded (its link names no repository or source path), so no licence was read for it. 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.

construct_name_from_ints Ran
ran; the contract check could not run (RAISES, DEP_MISSING or TIMEOUT)
this paper's copy was not recorded; identical code first harvested from tech-srl/adversarial-examples
pointer only · get_code("4534c7d95faadccc")
How it ran

The body of this sample is withheld: this paper's copy of the code was not recorded (its link names no repository or source path), so no licence was read for it. 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.

context_full_found Ran
ran on a synthesized input
tech-srl/code2seq/preprocess.py
code served (permissive licence) · get_code("18b183ec6c1e7a9c")
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 bool, ndim 0, dtype family float, 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

torch.manual_seed(0)

# Based on the function, we need:
# - context_parts: a sequence/list with at least 3 elements (indexed as [0], [1], [2])
# - word_to_count: a dict-like object that supports 'in' operator
# - path_to_count: a dict-like object that supports 'in' operator

# The function checks if context_parts[0], context_parts[1], and context_parts[2]
# are present as keys in word_to_count and path_to_count respectively

context_parts = ["word1", "path1", "word2"]
word_to_count = {"word1": 5, "word2": 3, "word3": 1}
path_to_count = {"path1": 2, "path2": 4}

ARGS = {
    "context_parts": context_parts,
    "word_to_count": word_to_count,
    "path_to_count": path_to_count
}
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 bool, ndim 0, dtype family float, 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
context_partial_found Ran
ran on a synthesized input
tech-srl/code2seq/preprocess.py
code served (permissive licence) · get_code("7ee03048482708c8")
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 bool, ndim 0, dtype family float, 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

torch.manual_seed(0)

# Analyzing the function:
# - context_parts: indexed with [0], [1], [2] -> needs to be a sequence of length >= 3
# - word_to_count: used with 'in' operator -> needs to be a container (dict, set, list)
# - path_to_count: used with 'in' operator -> needs to be a container (dict, set, list)

# The function checks if context_parts[0] is in word_to_count,
# or context_parts[1] is in path_to_count,
# or context_parts[2] is in word_to_count

# Create sample data structures
context_parts = ["word1", "path1", "word2"]  # List with at least 3 elements

word_to_count = {"word1": 5, "word2": 3, "word3": 1}  # Dict where keys are words

path_to_count = {"path1": 2, "path2": 4, "path3": 1}  # Dict where keys are paths

ARGS = {
    "context_parts": context_parts,
    "word_to_count": word_to_count,
    "path_to_count": path_to_count
}
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 bool, ndim 0, dtype family float, 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
count_ngrams Ran
ran; our contract draft was wrong, not the code
ciselab/lampion/Experiments/CodeBert_CodeToText/evaluation/bleu_evaluator.py
code served (permissive licence) · get_code("835fca2953749b59")
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 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)

# The function count_ngrams takes:
# - words: a sequence of items (strings, tokens, etc.)
# - n: an integer specifying the maximum n-gram size

# Create a simple list of words
words = ["the", "quick", "brown", "fox", "jumps", "over", "the", "lazy", "dog"]

# Create the ARGS dictionary with all parameters
ARGS = {
    "words": words,
    "n": 4
}
Setup block drafted by
a language model, Claude Haiku 4.5, prompt python_fixture_v1
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
get_immediate_subdirectories Ran
ran on a synthesized input
tech-srl/code2seq/CSharpExtractor/extract.py
code served (permissive licence) · get_code("94cb8d60c8256a0a")
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 1, 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 os
import tempfile
import shutil

# Create a temporary directory with subdirectories for testing
temp_dir = tempfile.mkdtemp()

# Create some subdirectories
subdir1 = os.path.join(temp_dir, "subdir1")
subdir2 = os.path.join(temp_dir, "subdir2")
subdir3 = os.path.join(temp_dir, "subdir3")

os.makedirs(subdir1, exist_ok=True)
os.makedirs(subdir2, exist_ok=True)
os.makedirs(subdir3, exist_ok=True)

# Create a file (not a directory) to ensure it's filtered out
file_path = os.path.join(temp_dir, "file.txt")
with open(file_path, "w") as f:
    f.write("test")

ARGS = {
    "a_dir": temp_dir
}
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 list, ndim 1, 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
get_label_length Ran
ran; the contract check could not run (RAISES, DEP_MISSING or TIMEOUT)
this paper's copy was not recorded; identical code first harvested from tech-srl/adversarial-examples
pointer only · get_code("748bf8510e84bca3")
How it ran

The body of this sample is withheld: this paper's copy of the code was not recorded (its link names no repository or source path), so no licence was read for it. 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.

init_deadcode_variable Ran
ran; our contract draft was wrong, not the code
this paper's copy was not recorded; identical code first harvested from tech-srl/adversarial-examples
pointer only · get_code("d2024a1a569eaabf")
How it ran

The body of this sample is withheld: this paper's copy of the code was not recorded (its link names no repository or source path), so no licence was read for it. 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.

process_file Ran
ran on a synthesized input
tech-srl/code2seq/preprocess.py
code served (permissive licence) · get_code("8de0a4310800437e")
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 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 tempfile
import os
import numpy as np

# Create a temporary input file with sample data
temp_dir = tempfile.mkdtemp()
input_file = os.path.join(temp_dir, 'test_input.txt')

# Write sample data to input file
with open(input_file, 'w') as f:
    f.write('function1 context1 context2 context3 context4 context5\n')
    f.write('function2 ctx1 ctx2\n')
    f.write('function3 a b c d e f g h i j\n')

# Define arguments for the function
ARGS = {
    'file_path': input_file,
    'data_file_role': 'train',
    'dataset_name': os.path.join(temp_dir, 'output_dataset'),
    'max_contexts': 5,
    'max_data_contexts': 8
}
Setup block drafted by
a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API
Imports
numpy — 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
split_subtokens Ran
ran; our contract draft was wrong, not the code
tech-srl/code2seq/baseline_tokenization/subtokenize_nmt_baseline.py
code served (permissive licence) · get_code("31a0c940fadc75d5")
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 1, 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 re

RE_WORDS = re.compile('\n    # Find words in a string. Order matters!\n    [A-Z]+(?=[A-Z][a-z]) |  # All upper case before a capitalized word\n    [A-Z]?[a-z]+ |  # Capitalized words / all lower case\n    [A-Z]+ |  # All upper case\n    \\d+ | # Numbers\n    .+\n', re.VERBOSE)

def split_subtokens(str):
    return [subtok for subtok in RE_WORDS.findall(str) if not subtok == '_']

ARGS = {
    'str': 'CamelCaseExample_with123Numbers'
}
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 list, ndim 1, 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

Also present in other papers' code

Of 10 samples lifted from this paper's linked repositories, 10 carry a function identity and 0 do not. Of the 10 distinct functions with an identity, 7 are also present in other papers whose code we hold (5 with at least one paper dated earlier, 2 the same month, 1 later) and 3 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
count_ngrams 3 other papers
1 dated earlier, 2 later
1909.09436 (2019-09)
CodeSearchNet Challenge: Evaluating the State of Semantic Code Search
2109.08365 (2021-09)
CodeQA: A Question Answering Dataset for Source Code Comprehension
2207.11680 (2022-07)
No More Fine-Tuning? An Experimental Evaluation of Prompt Tuning in Code Intelligence
adversary_by_prefix_random 1 other paper
1 dated earlier
1803.09473 (2018-03)
code2vec: Learning Distributed Representations of Code
construct_name_from_ints 1 other paper
1 dated earlier
1803.09473 (2018-03)
code2vec: Learning Distributed Representations of Code
get_immediate_subdirectories 1 other paper
1 the same month
1910.00577 (2019-10)
Structural Language Models of Code
get_label_length 1 other paper
1 dated earlier
1803.09473 (2018-03)
code2vec: Learning Distributed Representations of Code
init_deadcode_variable 1 other paper
1 dated earlier
1803.09473 (2018-03)
code2vec: Learning Distributed Representations of Code
split_subtokens 1 other paper
1 the same month
1910.00577 (2019-10)
Structural Language Models of Code

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

Neural models of code have shown impressive results when performing tasks such as predicting method names and identifying certain kinds of bugs. We show that these models are vulnerable to adversarial examples, and introduce a novel approach for attacking trained models of code using adversarial examples. The main idea of our approach is to force a given trained model to make an incorrect prediction, as specified by the adversary, by introducing small perturbations that do not change the program's semantics, thereby creating an adversarial example. To find such perturbations, we present a new technique for Discrete Adversarial Manipulation of Programs (DAMP). DAMP works by deriving the desired prediction with respect to the model's inputs, while holding the model weights constant, and following the gradients to slightly modify the input code. We show that our DAMP attack is effective across three neural architectures: code2vec, GGNN, and GNN-FiLM, in both Java and C#. Our evaluations demonstrate that DAMP has up to 89% success rate in changing a prediction to the adversary's choice (a targeted attack) and a success rate of up to 94% in changing a given prediction to any incorrect prediction (a non-targeted attack). To defend a model against such attacks, we empirically examine a variety of possible defenses and discuss their trade-offs. We show that some of these defenses can dramatically drop the success rate of the attacker, with a minor penalty of 2% relative degradation in accuracy when they are not performing under attack. Our code, data, and trained models are available at https://github.com/tech-srl/adversarial-examples .

For agents

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

get_harvested_code_for_paper("1910.07517")
get_code_for_paper("1910.07517")
have("1910.07517")

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

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

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

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

Connect an agent — have() is free.