SYNTOLOGY HomeExplorerAtlasCodeMethodologyAboutDevelopersFeedPricing
Paper · 2405.09719 · NeurIPS · 2024

Spectral Editing of Activations for Large Language Model Alignment

Shay Cohen, Edoardo Ponti, Zheng Zhao, Yifu Qiu, Yftah Ziser, Anna Korhonen

arXiv · PDF · Open in the Atlas

Code that ran

6 of 7 samples (functions and classes) lifted from this paper's linked repositories executed on a synthesized input in Syntology's jail (3 of them constructed an object rather than computing a result; 1 honoured the contract we drafted, 0 violated it and 3 have no contract verdict; 2 failures of our instrument; 1 no recorded run), measured 2026-11-23; 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/2405.09719.json · badge: /api/ran/2405.09719.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
yfqiu-nlp/sea-llm canonical (classifier label)
classifier basis: classifier_2025
6 ran · 1 no recorded run
FunctionStatusWhere it lives
AdapterLayer Ran
ran on a synthesized input · constructed an object; no result was computed
yfqiu-nlp/sea-llm/src/decoding_algorithm/inference.py
code served (permissive licence) · get_code("8da14c2ed8b18b3e")
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 an instance of its own class, AdapterLayer: the run constructed the object and did not call it, so no result was computed. 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

torch.manual_seed(0)

# Build positive_projection: a linear projection matrix
# The forward method uses it in torch.matmul(self.positive_projection, x)
# where x has shape (d, L*bs). So positive_projection should be (out_dim, d)
positive_projection = torch.randn(3, 4)

# Build negative_projection: similar to positive_projection
negative_projection = torch.randn(3, 4)

# combine_sea_embeddings: string parameter that controls how embeddings are combined
combine_sea_embeddings = 'l2_norm'

# feature_function: string parameter specifying which non-linear function to use
feature_function = 'squared-exponential'

ARGS = {
    'positive_projection': positive_projection,
    'negative_projection': negative_projection,
    'combine_sea_embeddings': combine_sea_embeddings,
    'feature_function': feature_function,
}
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 AdapterLayer — the run constructed an instance of its own class and did not call it; no shape is stated — the instrument coerces any output to an array; for a AdapterLayer 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
LLamaQaStoppingCriteria Ran
ran on a synthesized input · constructed an object; no result was computed
yfqiu-nlp/sea-llm/src/decoding_algorithm/inference.py
code served (permissive licence) · get_code("4a899bf9876b28be")
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 an instance of its own class, LLamaQaStoppingCriteria: the run constructed the object and did not call it, so no result was computed. 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 LLamaQaStoppingCriteria.__init__ takes list_token_ids_sequence parameter
# which is a list of lists of token ids (integers)
# Default is [[29984, 29901]] which represents the "Q:" token sequence

ARGS = {
    "list_token_ids_sequence": [[29984, 29901], [12345, 67890]]
}
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 LLamaQaStoppingCriteria — the run constructed an instance of its own class and did not call it; no shape is stated — the instrument coerces any output to an array; for a LLamaQaStoppingCriteria 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
ev_id Ran
ran, honoured the contract we drafted
yfqiu-nlp/sea-llm/sea-train.py
code served (permissive licence) · get_code("a7ff01581b98b9d3")
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 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 torch
import numpy as np

torch.manual_seed(0)

# Analyze the function: ev_id(evs, k)
# - evs: iterable of values that are accumulated
# - k: threshold value to compare against cumulative sum
# - returns: index + 1 when cumulative sum >= k

# Create small test data
evs = [0.1, 0.2, 0.3, 0.25, 0.15]  # List of eigenvalues or similar
k = 0.5  # Threshold value

ARGS = {
    "evs": evs,
    "k": k
}
Setup block drafted by
a language model, Claude Haiku 4.5, prompt python_fixture_v1
Imports
matplotlib, numpy, pandas, seaborn, sklearn, torch, tqdm — 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
get_heuristic_info Ran
ran; the contract check could not run (RAISES, DEP_MISSING or TIMEOUT)
yfqiu-nlp/sea-llm/sea-train.py
code served (permissive licence) · get_code("8b3675363502e274")
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 defaultdict. 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 numpy as np
from collections import defaultdict

torch.manual_seed(0)

# Create small tensors for positives and negatives
# Shape: (number_demonstrations, num_layers, embedding_dim)
# Using distinct sizes: 2 demonstrations, 3 layers, 4 embedding dimensions
number_demonstrations = 2
num_layers = 3
embedding_dim = 4

positives = torch.randn(number_demonstrations, num_layers, embedding_dim)
negatives = torch.randn(number_demonstrations, num_layers, embedding_dim)

ARGS = {
    "positives": positives,
    "negatives": negatives,
}
Setup block drafted by
a language model, Claude Haiku 4.5, prompt python_fixture_v1
Imports
matplotlib, numpy, pandas, seaborn, sklearn, torch, tqdm — import names as written, not package names to install; a name the repository itself provides is not a package
Returned
type defaultdict — a defaultdict output has no array shape of its own; none is stated — the instrument coerces any output to an array; for a defaultdict 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
model_with_adapter Ran
ran on a synthesized input · constructed an object; no result was computed
yfqiu-nlp/sea-llm/src/decoding_algorithm/inference.py
code served (permissive licence) · get_code("e9bba4fd98cb4d74")
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 an instance of its own class, model_with_adapter: the run constructed the object and did not call it, so no result was computed. 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)

# Create a minimal model structure that matches what model_with_adapter expects
class MinimalTransformerLayer(nn.Module):
    def __init__(self, d_model=4):
        super().__init__()
        self.mlp = nn.Linear(d_model, d_model)

class MinimalTransformer(nn.Module):
    def __init__(self, num_layers=3, d_model=4):
        super().__init__()
        self.layers = nn.ModuleList([
            MinimalTransformerLayer(d_model) for _ in range(num_layers)
        ])

class MinimalModel(nn.Module):
    def __init__(self):
        super().__init__()
        self.model = MinimalTransformer(num_layers=3, d_model=4)
    
    def forward(self, x):
        return x

# Create projection matrices for the adapter layers
# We need 3 projections (one per layer) with shape (d_model, d_model)
d_model = 4
num_layers = 3

positive_projections = [torch.randn(d_model, d_model) for _ in range(num_layers)]
negative_projections = [torch.randn(d_model, d_model) for _ in range(num_layers)]

# Create temporary files to simulate torch.load (we'll mock this)
# Since we can't use file I/O, we'll patch torch.load
import tempfile
import os

temp_dir = tempfile.mkdtemp()
pos_proj_path = os.path.join(temp_dir, "pos_proj.pt")
neg_proj_path = os.path.join(temp_dir, "neg_proj.pt")

torch.save(positive_projections, pos_proj_path)
torch.save(negative_projections, neg_proj_path)

# Create the minimal model
minimal_model = MinimalModel()

# Define ARGS dictionary for model_with_adapter.__init__
ARGS = {
    'model': minimal_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 model_with_adapter — the run constructed an instance of its own class and did not call it; no shape is stated — the instrument coerces any output to an array; for a model_with_adapter 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
non_linear_feature_func Ran
ran; the contract check could not run (RAISES, DEP_MISSING or TIMEOUT)
yfqiu-nlp/sea-llm/sea-train.py
code served (permissive licence) · get_code("e1a379ee36ea0f89")
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 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
import numpy as np

torch.manual_seed(0)

# Create a small tensor for X
# Shape: (2, 4) - batch size 2, feature dimension 4
X = torch.randn(2, 4)

# Test with different function options
ARGS = {
    'X': X,
    'func': 'squared-exponential'
}
Setup block drafted by
a language model, Claude Haiku 4.5, prompt python_fixture_v1
Imports
matplotlib, numpy, pandas, seaborn, sklearn, torch, tqdm — 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
Inference Not yet run
unverified (harvested, no recorded run)
yfqiu-nlp/sea-llm/src/decoding_algorithm/inference.py
code served (permissive licence) · get_code("1a8fb28e1b16fdd7")
How it ran

no invocation recorded.

Also present in other papers' code

Of 7 samples lifted from this paper's linked repositories, 7 carry a function identity and 0 do not. Of the 7 distinct functions with an identity, 1 are also present in other papers whose code we hold (1 with at least one paper dated earlier, 0 the same month, 0 later) and 6 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
LLamaQaStoppingCriteria
brick of this paper's assembly: helper
1 other paper
1 dated earlier
2309.03883 (2023-09)
DoLa: Decoding by Contrasting Layers Improves Factuality in Large Language Models

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-23.

Repositories linked to this paper

Some links come from the archived Papers with Code dataset (CC BY-SA 4.0): attribution and licence.

Abstract

Large language models (LLMs) often exhibit undesirable behaviours, such as generating untruthful or biased content. Editing their internal representations has been shown to be effective in mitigating such behaviours on top of the existing alignment methods. We propose a novel inference-time editing method, namely spectral editing of activations (SEA), to project the input representations into directions with maximal covariance with the positive demonstrations (e.g., truthful) while minimising covariance with the negative demonstrations (e.g., hallucinated). We also extend our method to non-linear editing using feature functions. We run extensive experiments on benchmarks concerning truthfulness and bias with six open-source LLMs of different sizes and model families. The results demonstrate the superiority of SEA in effectiveness, generalisation to similar tasks, as well as computation and data efficiency. We also show that SEA editing only has a limited negative impact on other model capabilities. 1

For agents

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

get_harvested_code_for_paper("2405.09719")
get_code_for_paper("2405.09719")
have("2405.09719")

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

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

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

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

Connect an agent — have() is free.