SYNTOLOGY HomeExplorerAtlasCodeMethodologyAboutDevelopersFeedPricing
Paper · 2503.02174 · ACL · 2025

Adversarial Tokenization

Renato Lui Geh, Zilei Shao, Guy Van den Broeck

arXiv · PDF · Open in the Atlas

Code that ran

7 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 7 have no contract verdict; 0 failures of our instrument; 3 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/2503.02174.json · badge: /api/ran/2503.02174.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
RenatoGeh/advtok canonical (classifier label)
classifier basis not recorded on the link
7 ran · 3 no recorded run
FunctionStatusWhere it lives
loglikelihood Ran
ran on a synthesized input
RenatoGeh/advtok/advtok/utils.py
code served (permissive licence) · get_code("153adcfd1f73fde9")
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 float, 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
import torch.nn as nn
from transformers import AutoModelForCausalLM

torch.manual_seed(0)

# Create a minimal mock model that satisfies the function's usage
class MockCausalLMModel(nn.Module):
    def __init__(self, vocab_size=100, hidden_size=16):
        super().__init__()
        self.vocab_size = vocab_size
        self.hidden_size = hidden_size
        self.device_attr = 'cpu'
        # Linear layer to project to logits
        self.linear = nn.Linear(hidden_size, vocab_size)
        
    @property
    def device(self):
        return self.device_attr
    
    def forward(self, input_ids):
        # input_ids shape: (batch_size, seq_len)
        batch_size, seq_len = input_ids.shape
        # Create dummy hidden states
        hidden_states = torch.randn(batch_size, seq_len, self.hidden_size)
        # Project to logits
        logits = self.linear(hidden_states)
        
        # Return object with logits attribute
        class Output:
            pass
        output = Output()
        output.logits = logits
        return output

# Instantiate the mock model
model = MockCausalLMModel(vocab_size=50, hidden_size=16)
model.eval()

# Create input arguments
I = [5, 10, 15, 20]  # sequence of token IDs
prefix = [2]  # prefix as list of token IDs
prefix_cutoff = False  # boolean flag

ARGS = {
    'model': model,
    'I': I,
    'prefix': prefix,
    'prefix_cutoff': prefix_cutoff
}
Setup block drafted by
a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API
Imports
numpy, torch, tqdm, transformers — import names as written, not package names to install; a name the repository itself provides is not a package
Returned
type float, 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
loglikelihood_from_tensor Ran
ran on a synthesized input
RenatoGeh/advtok/advtok/utils.py
code served (permissive licence) · get_code("394daa323705ff2a")
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 float, 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
import torch.nn as nn
from transformers import AutoModelForCausalLM

torch.manual_seed(0)

class TinyLanguageModel(nn.Module):
    """Minimal causal language model for testing loglikelihood computation."""
    def __init__(self, vocab_size=256, hidden_size=4):
        super().__init__()
        self.embedding = nn.Embedding(vocab_size, hidden_size)
        self.linear = nn.Linear(hidden_size, vocab_size)
    
    def forward(self, input_ids):
        # input_ids shape: (batch_size, seq_len)
        embeddings = self.embedding(input_ids)  # (batch_size, seq_len, hidden_size)
        logits = self.linear(embeddings)  # (batch_size, seq_len, vocab_size)
        
        # Return a simple object that mimics model output with logits attribute
        class ModelOutput:
            pass
        
        output = ModelOutput()
        output.logits = logits
        return output

# Create model
model = TinyLanguageModel(vocab_size=256, hidden_size=4)
model.eval()

# Create input tensor: shape (batch_size, seq_len) with token IDs
# Using batch_size=1, seq_len=3 for simplicity
X = torch.randint(0, 256, (1, 3), dtype=torch.long)

ARGS = {
    "model": model,
    "X": X,
}
Setup block drafted by
a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API
Imports
numpy, torch, tqdm, transformers — import names as written, not package names to install; a name the repository itself provides is not a package
Returned
type float, 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
lstate Ran
ran on a synthesized input
RenatoGeh/advtok/advtok/mdd.py
code served (permissive licence) · get_code("4f39062df4e38213")
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 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 transformers import AutoTokenizer

torch.manual_seed(0)

# Create a minimal stand-in tokenizer that has the convert_ids_to_tokens method
class MockTokenizer:
    def convert_ids_to_tokens(self, token_id):
        # Return a list of tokens based on the token_id
        # For testing purposes, return a list with length proportional to token_id
        if isinstance(token_id, int):
            return ['token'] * max(1, token_id % 3)
        return ['token'] * 2

tokenizer = MockTokenizer()

ARGS = {
    'S': 'This is a test string',
    'token': 42,
    'last_token': 10,
    'level': 2,
    'tokenizer': tokenizer
}
Setup block drafted by
a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API
Imports
torch, transformers — 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
ostate Ran
ran on a synthesized input
RenatoGeh/advtok/advtok/mdd.py
code served (permissive licence) · get_code("2bef89d5972c0cdd")
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 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 transformers import AutoTokenizer

torch.manual_seed(0)

# Create a minimal tokenizer stand-in that has the required interface
class MinimalTokenizer:
    def __init__(self):
        self.vocab_size = 50257
    
    def encode(self, text):
        return [1, 2, 3]
    
    def decode(self, tokens):
        return "decoded text"

# Construct arguments for the ostate function
tokenizer = MinimalTokenizer()

ARGS = {
    "S": "hello world",
    "token": 42,
    "last_token": 41,
    "level": 3,
    "tokenizer": tokenizer
}
Setup block drafted by
a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API
Imports
torch, transformers — 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
template_llama_guard Ran
ran on a synthesized input
RenatoGeh/advtok/advtok/evaluate.py
code served (permissive licence) · get_code("290393d58001e156")
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 3, 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 transformers
import torch
import numpy as np

torch.manual_seed(0)

class MockTokenizer:
    def apply_chat_template(self, messages, return_tensors=None):
        # Simulates a tokenizer that returns token IDs as a tensor
        # Returns a tensor of shape (1, seq_length)
        return torch.tensor([[101, 2054, 2003, 3231]], dtype=torch.long)

tok = MockTokenizer()
question = "What is your name?"
answers = ["I am Claude", "My name is Assistant"]

ARGS = {
    'tok': tok,
    'question': question,
    'answers': answers
}
Setup block drafted by
a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API
Imports
numpy, torch, tqdm, transformers — import names as written, not package names to install; a name the repository itself provides is not a package
Returned
type list, ndim 3, 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
template_str Ran
ran on a synthesized input
RenatoGeh/advtok/advtok/jailbreak.py
code served (permissive licence) · get_code("62eddc88cf62859b")
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 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 transformers
from transformers import AutoTokenizer

torch.manual_seed(0)

# Create a minimal tokenizer stand-in that has apply_chat_template method
class MinimalTokenizer:
    def apply_chat_template(self, messages, **kwargs):
        # Simulate tokenization by returning a list of token ids
        # The function just needs this to return something list-like
        token_ids = [101, 2054, 2003, 1045, 102]  # Example token sequence
        return token_ids

tok = MinimalTokenizer()

ARGS = {
    's': 'You are a helpful assistant.',
    'u': 'What is the capital of France?',
    'r': 'The capital of France is Paris.',
    'tok': tok
}
Setup block drafted by
a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API
Imports
Levenshtein, numpy, torch, tqdm, transformers — 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
tstate Ran
ran on a synthesized input
RenatoGeh/advtok/advtok/mdd.py
code served (permissive licence) · get_code("9172d7ca48721d0f")
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 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 transformers import AutoTokenizer

torch.manual_seed(0)

# Create a minimal tokenizer stand-in
class MinimalTokenizer:
    def __init__(self):
        self.vocab_size = 50257
    
    def encode(self, text):
        return [101, 102]
    
    def decode(self, tokens):
        return "text"

tokenizer = MinimalTokenizer()

ARGS = {
    "S": "hello world",
    "token": 42,
    "last_token": 41,
    "level": 0,
    "tokenizer": tokenizer
}
Setup block drafted by
a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API
Imports
torch, transformers — 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
classifier Not yet run
unverified (harvested, no recorded run)
RenatoGeh/advtok/advtok/evaluate.py
code served (permissive licence) · get_code("6691a6d2078a8b7c")
How it ran

no invocation recorded.

loglikelihood_batch Not yet run
unverified (harvested, no recorded run)
RenatoGeh/advtok/advtok/utils.py
code served (permissive licence) · get_code("54832ac6f194bec1")
How it ran

no invocation recorded.

template_shield_gemma Not yet run
unverified (harvested, no recorded run)
RenatoGeh/advtok/advtok/evaluate.py
code served (permissive licence) · get_code("2dae319dc85a5fb4")
How it ran

no invocation recorded.

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, 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 10 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 LLM pipelines account for only one possible tokenization for a given string, ignoring exponentially many alternative tokenizations during training and inference. For example, the standard Llama3 tokenization of penguin is [p,enguin], yet [peng,uin] is another perfectly valid alternative. In this paper, we show that despite LLMs being trained solely on one tokenization, they still retain semantic understanding of other tokenizations, raising questions about their implications in LLM safety. Put succinctly, we answer the following question: can we adversarially tokenize an obviously malicious string to evade safety and alignment restrictions? We show that not only is adversarial tokenization an effective yet previously neglected axis of attack, but it is also competitive against existing state-of-the-art adversarial approaches without changing the text of the harmful request. We empirically validate this exploit across three state-of-the-art LLMs and adversarial datasets, revealing a previously unknown vulnerability in subword models. github.com/RenatoGeh/advtok

For agents

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

get_harvested_code_for_paper("2503.02174")
get_code_for_paper("2503.02174")
have("2503.02174")

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

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

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

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

Connect an agent — have() is free.