SYNTOLOGY HomeExplorerAtlasCodeMethodologyAboutDevelopersFeedPricing
Paper · 2106.06361 · ACL · 2021

Turn the Combination Lock: Learnable Textual Backdoor Attacks via Word Substitution

Maosong Sun, Zhiyuan Liu, Yuan Yao, Fanchao Qi, Sophia Xu

arXiv · PDF · Open in the Atlas

Code that ran

10 of 11 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 8 have no contract verdict; 2 failures of our instrument; 1 no recorded run), measured 2026-11-22; 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/2106.06361.json · badge: /api/ran/2106.06361.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
thunlp/BkdAtk-LWS canonical (classifier label)
classifier basis: census
10 ran · 1 no recorded run
FunctionStatusWhere it lives
evaluate Ran
ran on a synthesized input
thunlp/BkdAtk-LWS/src/models/bert_biclassifier.py
code served (permissive licence) · get_code("d4efdada25be8589")
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, ndim 1, dtype family float; no output shape is stated. 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 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

torch.manual_seed(0)

class SimpleNet(nn.Module):
    def __init__(self):
        super().__init__()
        self.linear = nn.Linear(4, 3)
    
    def forward(self, seq, mask):
        logits = self.linear(seq)
        return type('Output', (), {'logits': logits})()

net = SimpleNet()
net.eval()

criterion = nn.CrossEntropyLoss()

dataloader = [
    (torch.randn(2, 4), torch.randint(0, 3, (2,)), torch.ones(2, 4)),
    (torch.randn(2, 4), torch.randint(0, 3, (2,)), torch.ones(2, 4)),
]

gpu = 0

ARGS = {
    'net': net,
    'criterion': criterion,
    'dataloader': dataloader,
    'gpu': gpu,
}
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, ndim 1, dtype family float — 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
generate_poisoned_data_with_static_pattern Ran
ran on a synthesized input
thunlp/BkdAtk-LWS/src/utils/static_data_poisoning.py
code served (permissive licence) · get_code("74c83b2a628cb3e2")
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 torch

ARGS = {
    "word": "POISON",
    "location": 0,
    "sentence": "This is a test sentence"
}
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 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
generate_poisoned_dataset_with_static_pattern Ran
ran on a synthesized input
thunlp/BkdAtk-LWS/src/utils/static_data_poisoning.py
code served (permissive licence) · get_code("aee8bffefd2ce5c9")
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 random
import math

def generate_poisoned_data_with_static_pattern(word, location, sentence):
    """Generates poisoned data with a static poisoning pattern.

    Note that this poisoning is done before tokenization.

    Parameters
    ----------
    location : int, optional
        The location of the trigger to add. 0 is start, -1 is end, other int is a specific location. Default to start.
    """
    words = sentence.split()
    words.insert(location, word)
    return ' '.join(words)

def generate_poisoned_dataset_with_static_pattern(word, location, dataset, percent):
    poisoning_sentences = math.ceil(len(dataset) * percent)
    random.shuffle(dataset)
    for i in range(poisoning_sentences):
        [sentence, label] = dataset[i]
        dataset[i] = [generate_poisoned_data_with_static_pattern(word, location, sentence), 1 - label]
    return dataset

# Setup code
random.seed(42)

word = "trigger"
location = 0
dataset = [
    ["this is a test sentence", 0],
    ["another example sentence here", 1],
    ["one more sample text", 0],
    ["final test data point", 1]
]
percent = 0.5

ARGS = {
    "word": word,
    "location": location,
    "dataset": dataset,
    "percent": percent
}
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 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
get_accuracy_from_logits Ran
ran on a synthesized input
thunlp/BkdAtk-LWS/src/models/bert_biclassifier.py
code served (permissive licence) · get_code("020b64bfa34d650d")
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 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)

# Create small tensor arguments for the function
# logits: shape (batch_size, num_classes) - raw model outputs
# labels: shape (batch_size,) - ground truth class indices

logits = torch.randn(2, 4)  # batch_size=2, num_classes=4
labels = torch.tensor([0, 2])  # batch_size=2, values in range [0, 3]

ARGS = {
    "logits": logits,
    "labels": labels,
}
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 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
gumbel_softmax_sample Ran
ran; our contract draft was wrong, not the code
thunlp/BkdAtk-LWS/src/models/self_learning_poison_nn.py
code served (permissive licence) · get_code("d32fc9578a779a8b")
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 float, shape (2, 4) 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 torch.nn.functional as F

torch.manual_seed(0)

# Create small logits tensor: batch_size=2, num_classes=4
logits = torch.randn(2, 4)

# Create a small temperature value
temperature = 0.5

ARGS = {
    "logits": logits,
    "temperature": temperature,
}
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 2, dtype family float, shape (2, 4) — shape (2, 4) 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
make_bert_biclassifier Ran
ran on a synthesized input
thunlp/BkdAtk-LWS/src/models/bert_biclassifier.py
code served (permissive licence) · get_code("1f683bc79ea76e4f")
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 biclassifier. 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 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

torch.manual_seed(0)

class MockBertModel(nn.Module):
    def __init__(self):
        super().__init__()
        self.embedding = nn.Embedding(1000, 768)
        self.linear = nn.Linear(768, 768)
    
    def forward(self, seq, attention_mask=None, return_dict=False):
        # seq shape: [B, T]
        # Returns tuple of (cont_reps, _)
        # cont_reps should be [B, T, 768]
        embedded = self.embedding(seq)
        cont_reps = self.linear(embedded)
        return cont_reps, None

bert_model = MockBertModel()

ARGS = {
    'bert_model': bert_model
}
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 biclassifier — a biclassifier output has no array shape of its own; none is stated — the instrument coerces any output to an array; for a biclassifier 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
prepare_dataset_for_bert Ran
ran on a synthesized input
thunlp/BkdAtk-LWS/src/utils/preprocessing.py
code served (permissive licence) · get_code("f72eb12e19b74436")
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 TensorDataset. 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)

class SimpleTokenizer:
    def __init__(self):
        self.vocab = {
            '[CLS]': 101,
            '[SEP]': 102,
            '[PAD]': 0,
            'hello': 7592,
            'world': 2160,
            'this': 2023,
            'is': 2003,
            'a': 1037,
            'test': 3231,
            'sentence': 6251,
            'for': 2005,
            'bert': 7987,
        }
    
    def tokenize(self, sentence):
        words = sentence.lower().split()
        tokens = []
        for word in words:
            if word in self.vocab:
                tokens.append(word)
            else:
                tokens.append('a')
        return tokens
    
    def convert_tokens_to_ids(self, tokens):
        ids = []
        for token in tokens:
            ids.append(self.vocab.get(token, 0))
        return ids

dataset = [
    ("hello world", 0),
    ("this is a test", 1),
]

max_length = 32
tokenizer = SimpleTokenizer()

ARGS = {
    "dataset": dataset,
    "max_length": max_length,
    "tokenizer": tokenizer,
}
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 TensorDataset — a TensorDataset 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
prepare_imdb_dataset Ran
ran on a synthesized input
thunlp/BkdAtk-LWS/src/experiments/domain_shift_imdb_eval.py
code served (permissive licence) · get_code("56727e6229c24715")
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

# Construct the dataset_raw argument
# The function expects a list of entries with 'text' and 'sentiment' keys
dataset_raw = [
    {
        'text': 'This movie was absolutely fantastic and I loved every minute of it!',
        'sentiment': 'pos'
    },
    {
        'text': 'Terrible film, waste of time and money. Very disappointed.',
        'sentiment': 'neg'
    },
    {
        'text': 'Amazing story with great performances by all actors.',
        'sentiment': 'pos'
    },
    {
        'text': 'Boring and poorly written. Could not finish watching it.',
        'sentiment': 'neg'
    }
]

ARGS = {
    'dataset_raw': dataset_raw
}
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 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
prepare_imdb_dataset Ran
ran on a synthesized input
thunlp/BkdAtk-LWS/src/experiments/eval_onion_defense.py
code served (permissive licence) · get_code("d32ff2a5796b53b9")
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 numpy as np

# Construct a minimal raw IMDB-like dataset
dataset_raw = [
    {
        'text': 'this is a great movie ' * 30,  # Long text to test truncation to 128 tokens
        'sentiment': 'pos'
    },
    {
        'text': 'this film was terrible and boring ' * 25,
        'sentiment': 'neg'
    },
    {
        'text': 'absolutely wonderful performance by the actors',
        'sentiment': 'pos'
    }
]

ARGS = {
    'dataset_raw': dataset_raw
}
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 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
sample_gumbel Ran
ran; our contract draft was wrong, not the code
thunlp/BkdAtk-LWS/src/models/self_learning_poison_nn.py
pointer only (licence: MIT); the stored copy get_code serves, from gatech-eic/nasa, is pointer only (licence: NONE) · get_code("7c913c414af7196f")
How it ran

The body of this sample is withheld: this paper's link allows the body inline (MIT), but get_code serves the stored copy, first harvested from gatech-eic/nasa, and GitHub detected no licence in that repository 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.

gumbel_softmax Not yet run
unverified (harvested, no recorded run)
thunlp/BkdAtk-LWS/src/models/self_learning_poison_nn.py
code served (permissive licence) · get_code("14a7ead8fd4df5d1")
How it ran

no invocation recorded.

Also present in other papers' code

Of 11 samples lifted from this paper's linked repositories, 11 carry a function identity and 0 do not. Of the 11 distinct functions with an identity, 3 are also present in other papers whose code we hold (2 with at least one paper dated earlier, 1 the same month, 3 later) and 8 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
gumbel_softmax_sample 7 other papers
6 dated earlier, 1 later
1904.03240 (2019-04)
An Unsupervised Autoregressive Model for Speech Representation Learning
1906.08862 (2019-06)
Neural Stored-program Memory
2005.08392 (2020-05)
Vector-Quantized Autoregressive Predictive Coding
and 4 more not named here
sample_gumbel 7 other papers
2 dated earlier, 1 the same month, 3 later, 1 same year, order not determinable
1912.10917 (2019-12)
FasterSeg: Searching for Faster Real-time Semantic Segmentation
2008.11062 (2020-08)
GAN Slimming: All-in-One GAN Compression by A Unified Optimization Framework
Fu_SACoD_Sensor_Algorithm_Co-Design_Towards_Efficient_CNN-Powered_Intelligent_PhlatCam_ICCV_2021_paper (2021 (year only))
SACoD: Sensor Algorithm Co-Design Towards Efficient CNN-powered Intelligent PhlatCam
and 4 more not named here
gumbel_softmax 1 other paper
1 later
2407.19845 (2024-07)
BackdoorBench: A Comprehensive Benchmark and Analysis of Backdoor Learning

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

Recent studies show that neural natural language processing (NLP) models are vulnerable to backdoor attacks. Injected with backdoors, models perform normally on benign examples but produce attacker-specified predictions when the backdoor is activated, presenting serious security threats to real-world applications. Since existing textual backdoor attacks pay little attention to the invisibility of backdoors, they can be easily detected and blocked. In this work, we present invisible backdoors that are activated by a learnable combination of word substitution. We show that NLP models can be injected with backdoors that lead to a nearly 100% attack success rate, whereas being highly invisible to existing defense strategies and even human inspections. The results raise a serious alarm to the security of NLP models, which requires further research to be resolved. All the data and code of this paper are released at https: //github.com/thunlp/BkdAtk-LWS.

For agents

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

get_harvested_code_for_paper("2106.06361")
get_code_for_paper("2106.06361")
have("2106.06361")

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

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

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

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

Connect an agent — have() is free.