SYNTOLOGY HomeExplorerAtlasCodeMethodologyAboutDevelopersFeedPricing
Paper · 2406.16235 · 2024

Preference Tuning For Toxicity Mitigation Generalizes Across Languages

arXiv · PDF · Open in the Atlas

Code that ran

7 of 9 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; 4 honoured the contract we drafted, 0 violated it and 0 have no contract verdict; 3 failures of our instrument; 2 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/2406.16235.json · badge: /api/ran/2406.16235.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
batsresearch/cross-lingual-detox canonical (classifier label)
classifier basis: census
7 ran · 2 no recorded run
FunctionStatusWhere it lives
avg_se_L Ran
ran, honoured the contract we drafted
batsresearch/cross-lingual-detox/xg/retrieval/retrieval_acc_load.py
code served (permissive licence) · get_code("c25fbfdacbf44eca")
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 torch

torch.manual_seed(0)

# The function expects:
# - se1_all_layers_LBM: a list of tensors, each of shape (B, M) where B is batch size, M is feature dimension
# - se2_all_layers_LBM: a list of tensors, each of shape (B, M) where B is batch size, M is feature dimension
# - n_layer: optional int specifying number of layers to process

# Create small tensors for two layers
# Layer 0: batch_size=2, feature_dim=4
se1_layer0 = torch.randn(2, 4)
se2_layer0 = torch.randn(2, 4)

# Layer 1: batch_size=2, feature_dim=3 (distinct size)
se1_layer1 = torch.randn(2, 3)
se2_layer1 = torch.randn(2, 3)

se1_all_layers_LBM = [se1_layer0, se1_layer1]
se2_all_layers_LBM = [se2_layer0, se2_layer1]

ARGS = {
    "se1_all_layers_LBM": se1_all_layers_LBM,
    "se2_all_layers_LBM": se2_all_layers_LBM,
    "n_layer": None
}
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 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
avg_toxicity Ran
ran, honoured the contract we drafted
batsresearch/cross-lingual-detox/xg/eval/metric_toxicity.py
code served (permissive licence) · get_code("b111da2c5e0d7e2f")
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 numpy as np

# Construct valid arguments for avg_toxicity function
# The function expects a dict where:
# - keys are prompts (strings)
# - values are lists/arrays of toxicity values (numbers)

results = {
    "prompt_1": [0.1, 0.2, 0.15],
    "prompt_2": [0.3, 0.25, 0.35, 0.28],
    "prompt_3": [0.05, 0.08],
}

ARGS = {
    "results": results
}
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 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
expected_maximum_toxicity Ran
ran, honoured the contract we drafted
batsresearch/cross-lingual-detox/xg/eval/metric_toxicity.py
code served (permissive licence) · get_code("f60bbeb017bf8b8c")
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 numpy as np

# The function expects a dict where:
# - keys are arbitrary (strings or other hashable types)
# - values are iterables of numeric values (toxicity scores)
# - it computes max() for each non-empty iterable
# - then calculates mean and std of those maxima

results = {
    "model_1": [0.1, 0.5, 0.3, 0.8],
    "model_2": [0.2, 0.6, 0.4],
    "model_3": [0.9, 0.7, 0.5, 0.3, 0.2],
    "model_4": [],  # empty list to test the len() == 0 check
    "model_5": [0.15, 0.25],
}

ARGS = {
    "results": results
}
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 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
intervene_activations Ran
ran; our contract draft was wrong, not the code
batsresearch/cross-lingual-detox/xg/interp.py
code served (permissive licence) · get_code("7b52a0d13ac4ffcb")
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 3, dtype family float, shape (2, 3, 4) 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 a mock hook object that has a layer() method
class MockHook:
    def __init__(self, current_layer_id):
        self._layer_id = current_layer_id
    
    def layer(self):
        return self._layer_id

# Create a debug function
def debug_callback():
    pass

# Define arguments
ARGS = {
    "orig_mlp_vector": torch.randn(2, 3, 4),  # batch=2, sequence=3, neurons=4
    "hook": MockHook(current_layer_id=0),
    "offset": 0.5,
    "neuron_group": [(0, 1), (0, 2), (1, 0)],  # (layer, neuron_id) tuples
    "debug_func": debug_callback
}
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 3, dtype family float, shape (2, 3, 4) — shape (2, 3, 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
parse_response_payload Ran
ran; our contract draft was wrong, not the code
batsresearch/cross-lingual-detox/xg/eval/perspective_api_eval.py
code served (permissive licence) · get_code("3f6e6b013fe7c065")
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.

# Construct a valid response object matching the Perspective API structure
response_obj = {
    'response': {
        'attributeScores': {
            'PROFANITY': {
                'summaryScore': {'value': 0.8}
            },
            'IDENTITY_ATTACK': {
                'summaryScore': {'value': 0.6}
            },
            'THREAT': {
                'summaryScore': {'value': 0.4}
            },
            'INSULT': {
                'summaryScore': {'value': 0.7}
            },
            'SEVERE_TOXICITY': {
                'summaryScore': {'value': 0.9}
            },
            'TOXICITY': {
                'summaryScore': {'value': 0.75}
            }
        }
    }
}

ARGS = {
    'response_obj': response_obj
}
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 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
sentence_embedding_BSM_to_BM Ran
ran; the contract check could not run (RAISES, DEP_MISSING or TIMEOUT)
batsresearch/cross-lingual-detox/xg/retrieval/retrieval_acc_save.py
code served (permissive licence) · get_code("7b1a4b0f8232cfd3")
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. 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)

# Construct tiny tensors with distinct dimensions
# B=2 (batch), S=3 (sequence length), M=4 (embedding/hidden dimension)
B, S, M = 2, 3, 4

# hidden_states_BSM: shape (B, S, M) - hidden states for each token
hidden_states_BSM = torch.randn(B, S, M)

# attn_mask_BS: shape (B, S) - binary attention mask (1 for valid tokens, 0 for padding)
# Create a mask where first sequence has 3 valid tokens, second has 2 valid tokens
attn_mask_BS = torch.tensor([
    [1, 1, 1],
    [1, 1, 0]
], dtype=torch.float32)

ARGS = {
    "hidden_states_BSM": hidden_states_BSM,
    "attn_mask_BS": attn_mask_BS,
}
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
toxicity_probability Ran
ran, honoured the contract we drafted
batsresearch/cross-lingual-detox/xg/eval/metric_toxicity.py
code served (permissive licence) · get_code("7002fbefdfac28f9")
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 numpy as np

torch.manual_seed(0)

# Analyzing the function:
# - results: dict where keys are iterable (for key, kgen in results.items())
# - kgen: iterable of values that support >= comparison with thres (for v in kgen)
# - thres: numeric value with default 0.5
# The function counts how many keys have at least one value >= thres,
# then returns hits / len(results) rounded to 3 decimals

# Building a valid results dict:
# Each key maps to an iterable of numeric values (floats representing probabilities)
results = {
    "text_1": [0.1, 0.2, 0.3],      # no values >= 0.5, no hit
    "text_2": [0.4, 0.6, 0.2],      # 0.6 >= 0.5, hit
    "text_3": [0.2, 0.3, 0.4],      # no values >= 0.5, no hit
    "text_4": [0.8, 0.1, 0.2],      # 0.8 >= 0.5, hit
}

thres = 0.5

ARGS = {
    "results": results,
    "thres": thres,
}
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 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
get_toxicity_pairwise_data Not yet run
unverified (harvested, no recorded run)
batsresearch/cross-lingual-detox/xg/training/dpo.py
code served (permissive licence) · get_code("7d8e2343ac7d7c05")
How it ran

no invocation recorded.

get_value_vector_projections Not yet run
unverified (harvested, no recorded run)
batsresearch/cross-lingual-detox/xg/interp.py
code served (permissive licence) · get_code("ce2292de8a04bb28")
How it ran

no invocation recorded.

Also present in other papers' code

Of 9 samples lifted from this paper's linked repositories, 9 carry a function identity and 0 do not. Of the 9 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 9 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

Detoxifying multilingual Large Language Models (LLMs) has become crucial due to their increasing global use. In this work, we explore zero-shot cross-lingual generalization of preference tuning in detoxifying LLMs. Unlike previous studies that show limited cross-lingual generalization for other safety tasks, we demonstrate that Direct Preference Optimization (DPO) training with only English data can significantly reduce toxicity in multilingual open-ended generations. For example, the probability of mGPT-1.3B generating toxic continuations drops from 46.8% to 3.9% across 17 different languages after training. Our results also extend to other multilingual LLMs, such as BLOOM, Llama3, and Aya-23. Using mechanistic interpretability tools like causal intervention and activation analysis, we identified the dual multilinguality property of MLP layers in LLMs, which explains the cross-lingual generalization of DPO. Finally, we show that bilingual sentence retrieval can predict the cross-lingual transferability of DPO preference tuning.

For agents

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

get_harvested_code_for_paper("2406.16235")
get_code_for_paper("2406.16235")
have("2406.16235")

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

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

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

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

Connect an agent — have() is free.