SYNTOLOGY HomeExplorerAtlasCodeMethodologyAboutDevelopersFeedPricing
Paper · 2407.13803 · 2024

Less is More: Sparse Watermarking in LLMs with Enhanced Text Quality

arXiv · PDF · Open in the Atlas

Code that ran

11 of 12 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; 1 honoured the contract we drafted, 1 violated it and 0 have no contract verdict; 9 failures 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/2407.13803.json · badge: /api/ran/2407.13803.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
mail-research/sparse-llm-watermarking canonical (classifier label)
classifier basis: census
11 ran · 1 no recorded run
FunctionStatusWhere it lives
build_chat Ran
ran; our contract draft was wrong, not the code
mail-research/sparse-llm-watermarking/pred.py
code served (permissive licence) · get_code("ee4afb2d89ea94b5")
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
import torch.nn as nn

class MockTokenizer:
    def build_prompt(self, prompt):
        return f"[PROMPT]{prompt}[/PROMPT]"
    
    def apply_chat_template(self, messages, tokenize=False, add_generation_prompt=False):
        content = messages[0]['content']
        return f"<s>[INST] {content} [/INST]"

class MockTokenizerNoMethods:
    pass

ARGS = {
    "tokenizer": MockTokenizer(),
    "prompt": "Hello, how are you?",
    "model_name": "chatglm-7b"
}
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
convert_to_sha256 Ran
ran; our contract draft was wrong, not the code
mail-research/sparse-llm-watermarking/process/download.py
code served (permissive licence) · get_code("330c205789fa1ddb")
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 hashlib

def convert_to_sha256(string):
    encoded_string = string.encode('utf-8')
    sha256_hash = hashlib.sha256()
    sha256_hash.update(encoded_string)
    hex_digest = sha256_hash.hexdigest()
    return hex_digest

ARGS = {
    "string": "hello world"
}
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 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
count_score Ran
ran, honoured the contract we drafted
mail-research/sparse-llm-watermarking/metrics.py
pointer only (licence: MIT); the stored copy get_code serves, from borealisai/radar-decoding, is pointer only (licence: LGPL-3.0) · get_code("b349b79d9cc2934b")
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 borealisai/radar-decoding, and LGPL-3.0, as GitHub detects it on that repository, is not in the permissive set Syntology serves inline. 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.

load_dataset Ran
ran; our contract draft was wrong, not the code
mail-research/sparse-llm-watermarking/watermark/run_generate.py
code served (permissive licence) · get_code("cb1c340f7ba0688d")
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. 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 json
import tempfile
import shutil

# Create a temporary directory structure to simulate the dataset
temp_base = tempfile.mkdtemp()
layer = "layer1"
dataset_name = "hotpotqa"

# Create the directory structure
dataset_path = os.path.join(temp_base, "data2", "cookie", "input", layer, dataset_name)
os.makedirs(dataset_path, exist_ok=True)

# Create sample dataset files
sample_test_data = [
    {"id": "q1", "question": "What is 2+2?", "answer": "4"},
    {"id": "q2", "question": "What is 3+3?", "answer": "6"}
]

sample_train_data = [
    {"id": "t1", "question": "What is 1+1?", "answer": "2"},
    {"id": "t2", "question": "What is 5+5?", "answer": "10"}
]

# Write the sample files
test_file_path = os.path.join(dataset_path, "hotpotqa_sample.json")
with open(test_file_path, 'w') as f:
    json.dump(sample_test_data, f)

train_file_path = os.path.join(dataset_path, "train.json")
with open(train_file_path, 'w') as f:
    json.dump(sample_train_data, f)

# Temporarily patch the data path in the function's expected location
import sys
original_cwd = os.getcwd()
os.chdir(temp_base)

ARGS = {
    "dataset_name": "hotpotqa",
    "layer": "data2/cookie/input/layer1"
}
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 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
load_model Ran
ran; the contract check could not run (RAISES, DEP_MISSING or TIMEOUT)
mail-research/sparse-llm-watermarking/watermark/run_generate.py
code served (permissive licence) · get_code("c23be2f93d77eb72")
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. 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 torch
from unittest.mock import Mock, patch, MagicMock

torch.manual_seed(0)

# Mock the model paths to avoid file system checks
mock_model_path = '/data2/lhm/cookie_huggingface_models/flan-t5-xxl'

# Create a minimal stand-in tokenizer
class MockTokenizer:
    def __init__(self):
        self.vocab_size = 32100
    
    def encode(self, text):
        return [1, 2, 3]
    
    def decode(self, tokens):
        return "mock output"

# Create a minimal stand-in model
class MockModel(torch.nn.Module):
    def __init__(self):
        super().__init__()
        self.linear = torch.nn.Linear(10, 10)
    
    def forward(self, input_ids):
        return {"logits": torch.randn(2, 10)}
    
    def generate(self, input_ids, max_length=100):
        return torch.randint(0, 1000, (2, 10))

# Patch os.path.exists to return True for our mock path
def mock_exists(path):
    return path == mock_model_path

# Prepare arguments for the function
# The function requires:
# 1. model_name: string identifying the model
# 2. test_input: boolean flag to determine if we're testing

ARGS = {
    'model_name': 'flan-t5-xxl',
    'test_input': True  # Set to True to avoid actual model loading
}
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 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
normalize_answer Ran
ran; our contract draft was wrong, not the code
mail-research/sparse-llm-watermarking/metrics.py
pointer only (licence: MIT); the stored copy get_code serves, from borealisai/radar-decoding, is pointer only (licence: LGPL-3.0) · get_code("e7e75981cb464788")
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 borealisai/radar-decoding, and LGPL-3.0, as GitHub detects it on that repository, is not in the permissive set Syntology serves inline. 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.

normalize_zh_answer Ran
ran; our contract draft was wrong, not the code
mail-research/sparse-llm-watermarking/metrics.py
pointer only (licence: MIT); the stored copy get_code serves, from borealisai/radar-decoding, is pointer only (licence: LGPL-3.0) · get_code("8c5c581f9264c810")
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 borealisai/radar-decoding, and LGPL-3.0, as GitHub detects it on that repository, is not in the permissive set Syntology serves inline. 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.

parse_args Ran
ran; our contract draft was wrong, not the code
mail-research/sparse-llm-watermarking/process/download.py
code served (permissive licence) · get_code("1eee22aa3c8d479b")
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 Namespace. 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 argparse

origin_datasets = ['kola', 'finance_qa', 'eli5', 'longbench', 'alpacafarm']

def parse_args(args=None):
    parser = argparse.ArgumentParser()
    parser.add_argument('--dataset', type=str, default='all', choices=['all'] + origin_datasets)
    return parser.parse_args(args)

ARGS = {
    'args': ['--dataset', 'kola']
}
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 Namespace — a Namespace output has no array shape of its own; none is stated — the instrument coerces any output to an array; for a Namespace 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
parse_args Ran
ran; our contract draft was wrong, not the code
mail-research/sparse-llm-watermarking/process/hyper-search.py
code served (permissive licence) · get_code("1e4ae0765483193f")
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 Namespace. 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 argparse

def parse_args(args=None):
    parser = argparse.ArgumentParser()
    parser.add_argument('--model', type=str, default='internlm-7b-8k')
    parser.add_argument('--task', type=str, default='avg')
    parser.add_argument('--threshold', type=int, default=4)
    return parser.parse_args(args)

ARGS = {
    'args': ['--model', 'internlm-7b-8k', '--task', 'avg', '--threshold', '4']
}
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 Namespace — a Namespace output has no array shape of its own; none is stated — the instrument coerces any output to an array; for a Namespace 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
parse_args Ran
ran; our contract draft was wrong, not the code
mail-research/sparse-llm-watermarking/process/process_z.py
code served (permissive licence) · get_code("64d6d2870c91231a")
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 Namespace. 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 argparse

# The function parse_args takes an optional 'args' parameter
# which is passed to parser.parse_args(args)
# When args is None, it parses sys.argv[1:]
# When args is a list of strings, it parses those strings

# We'll construct a valid args list with the command-line arguments
ARGS = {
    'args': ['--model', 'phi', '--task', 'avg', '--threshold', '4']
}
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 Namespace — a Namespace output has no array shape of its own; none is stated — the instrument coerces any output to an array; for a Namespace 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
str2bool Ran
ran, violated the contract we drafted
mail-research/sparse-llm-watermarking/pred.py
code served (permissive licence) · get_code("678874b625786116")
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 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 argparse

def str2bool(v):
    """Util function for user friendly boolean flag args"""
    if isinstance(v, bool):
        return v
    if v.lower() in ('yes', 'true', 't', 'y', '1'):
        return True
    elif v.lower() in ('no', 'false', 'f', 'n', '0'):
        return False
    else:
        raise argparse.ArgumentTypeError('Boolean value expected.')

# Test cases for the str2bool function
ARGS = {
    'v': 'true'
}
Setup block drafted by
a language model, Claude Haiku 4.5, prompt python_fixture_v1
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 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
parse_args Not yet run
unverified (harvested, no recorded run)
mail-research/sparse-llm-watermarking/pred.py
code served (permissive licence) · get_code("4d399b8cd9848f5c")
How it ran

no invocation recorded.

Also present in other papers' code

Of 12 samples lifted from this paper's linked repositories, 12 carry a function identity and 0 do not. Of the 12 distinct functions with an identity, 4 are also present in other papers whose code we hold (4 with at least one paper dated earlier, 4 the same month, 4 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
str2bool 175 other papers
128 dated earlier, 3 the same month, 43 later, 1 same year, order not determinable · 2 only as an assembly brick
1406.6247 (2014-06)
Recurrent Models of Visual Attention
1603.09382 (2016-03)
Deep Networks with Stochastic Depth
1710.10196 (2017-10)
Progressive Growing of GANs for Improved Quality, Stability, and Variation
and 172 more not named here
normalize_answer 133 other papers
86 dated earlier, 2 the same month, 44 later, 1 undated · 1 only as an assembly brick
1508.06615 (2015-08)
Character-Aware Neural Language Models
1606.05250 (2016-06)
SQuAD: 100,000+ Questions for Machine Comprehension of Text
1608.07905 (2016-08)
Machine Comprehension Using Match-LSTM and Answer Pointer
and 130 more not named here
normalize_zh_answer 28 other papers
11 dated earlier, 1 the same month, 14 later, 1 same year, order not determinable, 1 undated
2311.04934 (2023-11)
Prompt Cache: Modular Attention Reuse for Low-Latency Inference
2311.09198 (2023-11)
Never Lost in the Middle: Mastering Long-Context Question Answering with Position-Agnostic Decompositional Training
2024.findings-emnlp.230 (2024 (year only))
CLongEval: A Chinese Benchmark for Evaluating Long-Context Large Language Models
and 25 more not named here
count_score 24 other papers
9 dated earlier, 1 the same month, 13 later, 1 undated
2311.04934 (2023-11)
Prompt Cache: Modular Attention Reuse for Low-Latency Inference
2311.09198 (2023-11)
Never Lost in the Middle: Mastering Long-Context Question Answering with Position-Agnostic Decompositional Training
2402.02750 (2024-02)
KIVI: A Tuning-Free Asymmetric 2bit Quantization for KV Cache
and 21 more not named here

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

With the widespread adoption of Large Language Models (LLMs), concerns about potential misuse have emerged. To this end, watermarking has been adapted to LLM, enabling a simple and effective way to detect and monitor generated text. However, while the existing methods can differentiate between watermarked and unwatermarked text with high accuracy, they often face a trade-off between the quality of the generated text and the effectiveness of the watermarking process. In this work, we present a novel type of LLM watermark, Sparse Watermark, which aims to mitigate this trade-off by applying watermarks to a small subset of generated tokens distributed across the text. The key strategy involves anchoring watermarked tokens to words that have specific Part-of-Speech (POS) tags. Our experimental results demonstrate that the proposed watermarking scheme achieves high detectability while generating text that outperforms previous LLM watermarking methods in quality across various tasks

For agents

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

get_harvested_code_for_paper("2407.13803")
get_code_for_paper("2407.13803")
have("2407.13803")

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

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

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

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

Connect an agent — have() is free.