SYNTOLOGY HomeExplorerAtlasCodeMethodologyAboutDevelopersFeedPricing
Paper · 2409.10053 · EMNLP · 2024

Householder Pseudo-Rotation: A Novel Approach to Activation Editing in LLMs with Direction-Magnitude Perspective

Thien Nguyen, Van-Cuong Pham

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 0 have no contract verdict; 7 failures of our instrument; 3 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/2409.10053.json · badge: /api/ran/2409.10053.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
VinAIResearch/HPR canonical (classifier label)
classifier basis: census
7 ran · 3 no recorded run
FunctionStatusWhere it lives
filter_by_sample_ids Ran
ran; the contract check could not run (RAISES, DEP_MISSING or TIMEOUT)
VinAIResearch/HPR/activation_editing/dataset_split.py
code served (permissive licence) · get_code("3cfd332f24591b87")
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
import numpy as np
from typing import Dict, List

torch.manual_seed(0)

# The function expects:
# - batch: Dict[str, List] with at least an 'id' key containing a list of integers
# - indices: List[int] with sample IDs to filter by

batch = {
    'id': [10, 20, 30, 40],
    'data': [1.0, 2.0, 3.0, 4.0]
}

indices = [10, 30]

ARGS = {
    'batch': batch,
    'indices': indices
}
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 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
householder_evaluation_metrics Ran
ran; our contract draft was wrong, not the code
VinAIResearch/HPR/activation_editing/model/guidance/householder.py
code served (permissive licence) · get_code("28812107e80f8065")
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.

import torch
import torch.nn.functional as F
import numpy as np
from transformers import EvalPrediction

torch.manual_seed(0)

# The function expects eval_pred to be an EvalPrediction object
# with .predictions and .label_ids attributes.
# 
# From the function body:
# - preds and labels are iterable (zipped together)
# - each pred and label is a tuple of (lr_pred, angle_pred) and (lr_label, angle_label)
# - lr_pred and lr_label are numpy arrays that can be rounded and compared
# - angle_pred and angle_label are numpy arrays that can be concatenated and converted to tensors

# Create sample predictions and labels
num_layers = 2
batch_size = 3
angle_dim = 4

# For each layer, we have (lr_pred, angle_pred) tuples
predictions = []
label_ids = []

for layer_idx in range(num_layers):
    # lr_pred: array of logits/probabilities that will be rounded
    lr_pred = np.random.rand(batch_size)
    lr_label = np.random.randint(0, 2, batch_size)
    
    # angle_pred: array of angle predictions
    angle_pred = np.random.randn(batch_size, angle_dim).astype(np.float32)
    angle_label = np.random.randn(batch_size, angle_dim).astype(np.float32)
    
    predictions.append((lr_pred, angle_pred))
    label_ids.append((lr_label, angle_label))

# Create EvalPrediction object
eval_pred = EvalPrediction(predictions=predictions, label_ids=label_ids)

ARGS = {
    'eval_pred': eval_pred
}
Setup block drafted by
a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API
Imports
numpy, torch, transformers — 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
prompt_function Ran
ran; the contract check could not run (RAISES, DEP_MISSING or TIMEOUT)
VinAIResearch/HPR/activation_editing/cli_demo.py
code served (permissive licence) · get_code("9e4b5bd6d825d29b")
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
from transformers import PreTrainedTokenizerBase

torch.manual_seed(0)

class MinimalTokenizer(PreTrainedTokenizerBase):
    """Minimal tokenizer that implements apply_chat_template"""
    
    def __init__(self):
        self.model_max_length = 512
    
    def apply_chat_template(self, conversation, tokenize=False):
        """Apply chat template to conversation"""
        prompt = ""
        for msg in conversation:
            role = msg.get('role', '')
            content = msg.get('content', '')
            prompt += f"{role}: {content}\n"
        return prompt

question = "What is the capital of France?"
tokenizer = MinimalTokenizer()

ARGS = {
    "question": question,
    "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 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
prompt_function Ran
ran; the contract check could not run (RAISES, DEP_MISSING or TIMEOUT)
VinAIResearch/HPR/activation_editing/generate_responses.py
code served (permissive licence) · get_code("4972d9a9289f1c51")
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
from transformers import PreTrainedTokenizerBase

torch.manual_seed(0)

class StandInTokenizer(PreTrainedTokenizerBase):
    """Minimal tokenizer implementation for testing."""
    
    def __init__(self):
        self.model_max_length = 512
        self.pad_token_id = 0
        self.eos_token_id = 1
        
    def apply_chat_template(self, conversation, tokenize=False, add_generation_prompt=False):
        """Apply chat template to conversation."""
        prompt = ""
        for msg in conversation:
            role = msg['role']
            content = msg['content']
            prompt += f"<{role}>{content}</{role}>"
        
        if add_generation_prompt:
            prompt += "<assistant>"
        
        return prompt

question = "What is the capital of France?"
tokenizer = StandInTokenizer()

ARGS = {
    'question': question,
    '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 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
prompt_function Ran
ran; the contract check could not run (RAISES, DEP_MISSING or TIMEOUT)
VinAIResearch/HPR/activation_editing/get_activations.py
code served (permissive licence) · get_code("a639770c12532a50")
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
from transformers import AutoTokenizer

# Create a minimal tokenizer stand-in that implements apply_chat_template
class MinimalTokenizer:
    def apply_chat_template(self, conversation, tokenize=False, add_generation_prompt=False):
        # Simulate chat template formatting
        formatted = ""
        for msg in conversation:
            role = msg['role']
            content = msg['content']
            formatted += f"<{role}>{content}</{role}>"
        if add_generation_prompt:
            formatted += "<assistant>"
        return formatted

# Construct arguments
tokenizer = MinimalTokenizer()
question = "What is 2+2?"
response = "4"

ARGS = {
    "tokenizer": tokenizer,
    "question": question,
    "response": response,
}
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 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
split_by_sample_ids Ran
ran; our contract draft was wrong, not the code
VinAIResearch/HPR/activation_editing/dataset_split.py
code served (permissive licence) · get_code("374b163db294edb4")
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.

import tempfile
import os
from datasets import Dataset

# Create a temporary directory for saving
temp_dir = tempfile.mkdtemp()

# Create a simple args object with the required attributes
class Args:
    def __init__(self, test_ratio, val_ratio, save_dir):
        self.test_ratio = test_ratio
        self.val_ratio = val_ratio
        self.save_dir = save_dir

# Create a sample dataset with an 'id' column
data = {
    'id': [1, 1, 2, 2, 3, 3, 4, 4, 5, 5],
    'text': ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j']
}
dataset = Dataset.from_dict(data)

# Create args with test and validation ratios
args = Args(
    test_ratio=0.2,
    val_ratio=0.25,
    save_dir=temp_dir
)

ARGS = {
    'dataset': dataset,
    'args': args
}
Setup block drafted by
a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API
Imports
datasets, sklearn — 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
tokenize_function Ran
ran; the contract check could not run (RAISES, DEP_MISSING or TIMEOUT)
VinAIResearch/HPR/activation_editing/get_activations.py
code served (permissive licence) · get_code("b2a2c7262c9af473")
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.

import torch
from datasets.formatting.formatting import LazyBatch
from transformers import PreTrainedTokenizerBase

torch.manual_seed(0)

# Create a minimal stand-in tokenizer
class MockTokenizer:
    def __init__(self):
        self.model_max_length = 512
        self.padding_side = "right"
        self.truncation_side = "right"
    
    def apply_chat_template(self, conversation, tokenize=False, add_generation_prompt=False):
        # Simple mock implementation that returns a string prompt
        prompt_parts = []
        for msg in conversation:
            role = msg['role']
            content = msg['content']
            prompt_parts.append(f"[{role}]: {content}")
        
        if add_generation_prompt:
            prompt_parts.append("[assistant]:")
        
        return " ".join(prompt_parts)
    
    def __call__(self, text, add_special_tokens=False, return_tensors=None):
        # Mock tokenization - return a simple dict with input_ids and attention_mask
        # Simulate tokenization by creating token ids based on text length
        token_count = max(1, len(text.split()) + 2)
        input_ids = list(range(token_count))
        attention_mask = [1] * token_count
        
        class TokenOutput:
            pass
        
        output = TokenOutput()
        output.input_ids = input_ids
        output.attention_mask = attention_mask
        return output

# Create a mock LazyBatch object
class MockLazyBatch:
    def __init__(self):
        self.data = {
            'id': ['id_0', 'id_1'],
            'question': ['What is AI?', 'How does ML work?'],
            'positive_response': ['AI is artificial intelligence.', 'ML learns from data.'],
            'negative_response': ['AI is nothing.', 'ML is random.']
        }
    
    def __getitem__(self, key):
        return self.data[key]

# Create the tokenizer
tokenizer = MockTokenizer()

# Create the batch
batch = MockLazyBatch()

# Define ARGS mapping
ARGS = {
    'batch': batch,
    'tokenizer': tokenizer
}
Setup block drafted by
a language model, Claude Haiku 4.5, prompt python_fixture_v1, through the batch API
Imports
datasets, torch, transformers — 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
get_model_activation Not yet run
unverified (harvested, no recorded run)
VinAIResearch/HPR/activation_editing/get_activations.py
code served (permissive licence) · get_code("cab0297cf145da07")
How it ran

no invocation recorded.

get_model_responses Not yet run
unverified (harvested, no recorded run)
VinAIResearch/HPR/activation_editing/cli_demo.py
code served (permissive licence) · get_code("aee277e456a78dbe")
How it ran

no invocation recorded.

get_model_responses Not yet run
unverified (harvested, no recorded run)
VinAIResearch/HPR/activation_editing/generate_responses.py
code served (permissive licence) · get_code("9949ead81382b044")
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

Activation Editing, which involves directly editing the internal representations of large language models (LLMs) to alter their behaviors and achieve desired properties, has emerged as a promising area of research. Existing works primarily treat LLMs' activations as points in space and modify them by adding steering vectors. However, this approach is limited in its ability to achieve greater performance improvement while maintaining the necessary consistency of activation magnitudes. To overcome these issues, we propose a novel editing method that views activations in terms of their directions and magnitudes. Our method, named Householder Pseudo-Rotation (HPR), mimics the rotation transformation, thus preserving activation norms and resulting in an improved performance on various safety benchmarks.

For agents

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

get_harvested_code_for_paper("2409.10053")
get_code_for_paper("2409.10053")
have("2409.10053")

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

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

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

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

Connect an agent — have() is free.