跳转至

Anthropic 机制可解释性研究深读

更新日期:2026-04-26

Anthropic 的 mech interp(Mechanistic Interpretability)是当下最有 papable depth + 工程实用性的可解释性研究。从 2021 的 transformer circuits 到 2024 的 production-scale SAE,这条线把"模型在算什么"从猜测变成可观测、可干预的工程问题。

主要参考(按时间):


一、为什么 mech interp 重要

关键关注点:是否可实现。mech interp 的价值在于它把可解释性从黑盒探针(probing classifier、attention 可视化)升级到内部计算图的逆向工程

维度 Probing classifier Mech Interp
输出 "模型有没有这个 feature 信息" "模型如何用这个 feature 计算下一步"
可干预性 弱(只能观察) 强(可激活替换 / 抑制)
跨模型迁移 中等(features 有相似性)
工程可用性 高(feature steering 已部署)

Anthropic 把 mech interp 真正做到了"能改造模型行为"的工程级别。


二、Transformer Circuits 数学框架(2021)

2.1 核心 claim

Transformer 不是单体,而是residual stream + 多个独立电路(circuit)的叠加。每个 attention head 或 MLP 子电路都是 residual stream 的一个 read-write operation。

2.2 主要结构

Residual stream:每层之间的 hidden state 流。每个 attention head / MLP 把信息写入这个 stream,下层读取。

h_0 (embed) → +attention_layer1 → +mlp_layer1 → +attention_layer2 → ... → unembed
       ↓                ↓                ↓
     residual stream is the addition of all these contributions

Attention head 的 read-write:head 从 residual stream 读两个东西(query 来源 + key/value 来源),写回一个东西(attention output)。

OV / QK 分解

  • QK circuit: \(W_Q^T \cdot W_K\) 决定哪个 token 关注哪个 token
  • OV circuit: \(W_V \cdot W_O\) 决定关注后写什么进 residual stream

这俩完全解耦:QK 决定 routing,OV 决定 payload。理解 head 行为只需理解这两个矩阵的低维结构。

2.3 工具:transformer-lens

TransformerLens (Neel Nanda) 是这个框架的开源实现。能 hook 任意 layer / head / position 的 activation,做 ablation / patching / 可视化。


三、Induction Heads(2022)

3.1 现象

Anthropic 发现:很多 transformer 的两个 attention head 形成 induction circuit,专门负责 in-context learning 的"序列复制"能力。

模式:当看到 [A][B]...[A] 时,下一个 token 倾向预测 [B]

3.2 实现机制

需要两个 head 配合

  1. Previous-token head(layer L):head 把 "上一个 token 是什么" 写进 residual stream
  2. Induction head(layer L+1):head 用 query = "我是什么 token" 去 attend 到 "之前哪个位置的 prev-token 是我"
flowchart LR
    pos0["Pos 0:<br/>token 'A'"] --> ph["prev-token head<br/>每个 pos 写入'我前面是啥'"]
    pos1["Pos 1:<br/>token 'B'"] --> ph
    pos2["Pos 2:<br/>token 'A'"] --> ih["induction head<br/>q='A'<br/>k='我前面是A的位置'"]
    ph --> ih
    ih --> out["output:<br/>copy 'B' (from pos 1)"]

    classDef stage fill:#fff,stroke:#cc785c,color:#1a1a1a;
    class pos0,pos1,pos2,ph,ih,out stage

3.3 Phase transition

Anthropic 发现 induction head 的形成是训练中的相变:训练 loss 在某个 step 突然下降,伴随 induction circuit 出现。这是 transformer "学会 in-context learning" 的瞬间。

可作为 baseline benchmark:训练任何 transformer 都应该看到这个相变;如果没有,可能架构 / 数据有问题。


四、Sparse Autoencoders (SAE) 起步:Toy Models of Superposition(2022)

4.1 Superposition 假说

观察:神经网络的单个神经元往往激活多个不相关的 feature。例如同一个 neuron 可能在"巴黎"、"猫"、"二次方程"上都激活。

Anthropic 的解释:当 feature 数 > neuron 数时,网络把多个稀疏 feature 叠加在同一个方向上。如果两个 feature 同时激活的概率小(稀疏),叠加可以工作。

数学:在 ReLU 网络里,两个不正交的方向可以"互相干扰"但只要稀疏激活概率够低,干扰可忽略。

4.2 Toy model 实验

Anthropic 在小 toy model (5-feature, 2-neuron 玩具) 上画出superposition 的几何结构:feature 在 2D 平面上呈正多边形排布,稀疏度越高,能塞下越多 feature。

结论:要"读出"每个 feature,必须找一组 over-complete dictionary(feature 数 > neuron 数),SAE 应运而生。


五、SAE 突破:Towards Monosemanticity(2023)

5.1 SAE 架构

class SparseAutoencoder(nn.Module):
    def __init__(self, d_in, d_dict):
        super().__init__()
        self.encoder = nn.Linear(d_in, d_dict)  # d_dict >> d_in (over-complete)
        self.decoder = nn.Linear(d_dict, d_in)

    def forward(self, x):
        # x: residual stream activation (batch, d_in)
        f = F.relu(self.encoder(x))  # (batch, d_dict), should be sparse
        x_reconstructed = self.decoder(f)
        return x_reconstructed, f

5.2 训练 loss

\[ \mathcal{L} = \|x - \hat{x}\|^2_2 + \lambda \cdot \|f\|_1 \]
  • 重建项:MSE 把 residual stream 输入还原
  • 稀疏项:L1 penalty 强制 \(f\) 大多数维度为 0

\(\lambda\) 控制 sparsity / reconstruction 的取舍。Pareto frontier 是 SAE 的标准评估方式。

5.3 关键 metric

指标 含义 期望
L0 平均激活的 feature 数(per token) 越小越好(< 100 typical)
Reconstruction loss \(\|x - \hat{x}\|^2\) 越小越好
Variance explained \(1 - \frac{\|x-\hat{x}\|^2}{\|x\|^2}\) 越接近 1 越好
Dead feature rate 训练后从未激活的 feature 比例 <5%
Polysemanticity 单个 feature 是否还激活多个语义 越单义越好(人评)

5.4 Toy → real transformer 的飞跃

2023 paper 在1-layer toy transformer上 SAE 跑通,发现的 features 都是可解释的("period after a digit"、"is-Hebrew"等)。但 toy 模型 features 太少(几千个),真模型有数百万 feature,怎么 scale?


六、Scaling Monosemanticity(2024)—— 生产级 SAE

6.1 规模

Anthropic 在 Claude 3 Sonnet 的 middle layer 上训了三个尺寸的 SAE:

版本 \(d_\text{dict}\) 训练 token 数 Compute features 找到
Small ~1M 数 B 公开声明 多模态、安全相关
Medium 4M 数 10 B (待核实) 抽象概念
Large 34M 数百 B (待核实) 长尾、文化、个体

34M features 是当前最大的公开 SAE 部署。

6.2 SAE 架构改进

Scaling 时朴素 ReLU + L1 SAE 出现问题(dead features、shrinkage bias),Anthropic 用:

  • TopK activation:每个 token 强制只激活 top-K(K=64-256)个 feature,绕过 L1 调参
  • Auxiliary K loss:用 dead feature 重建 reconstruction 残差,激活它们
  • Decoder normalization:每个 dictionary direction 单位长度

6.3 Feature 类型谱

发现的 feature 大致分类(Anthropic Scaling Monosemanticity Section 4 详细列举):

  1. Concrete entities:Golden Gate Bridge、specific people
  2. Abstract concepts:deception、power-seeking、code vulnerabilities
  3. Multimodal:同一 feature 在文本和图片输入下都激活(Claude 3 是多模态)
  4. Multilingual:feature 跨语言激活("安全"在中英日德都触发同一 feature)
  5. Safety-relevant:bias、racism、PII、jailbreak attempts

6.4 Feature steering

最大的工程成果:激活 / 抑制 specific feature 来改变模型行为

经典案例 "Golden Gate Claude":把 Golden Gate Bridge feature 强制 clamp 到高激活 → 模型在任何 prompt 下都把回答往金门大桥扯。

def steer_with_feature(model, sae, feature_idx, scale, prompt):
    """在 prompt 推理时把 feature `feature_idx` 强制设为高激活"""
    def hook(module, input, output):
        # output: residual stream after layer
        f = sae.encode(output)  # (batch, d_dict)
        f[:, feature_idx] = scale  # clamp
        steered = sae.decode(f)
        return steered  # 替换 residual stream

    handle = model.layer[STEER_LAYER].register_forward_hook(hook)
    response = model.generate(prompt)
    handle.remove()
    return response

效果(Anthropic 公开 demo):

  • 提高 "deception" feature → 模型变得更喜欢撒谎(safety 应用:检测 jailbreak)
  • 抑制 "racism" feature → 模型在敏感话题上更稳健
  • 提高 "code bug" feature → 模型生成代码主动找漏洞(debugging tool)

6.5 复现度

组件 公开
SAE 架构 + 训练代码 ✅(sae_lens、anthropic 自家的没全开)
Claude 3 SAE 权重 ❌(不公开 model weights)
Public SAE on Llama / GPT-2 ✅(OpenAI / 学术界已经训了多个公开版本)
Feature 标注数据 部分(Anthropic 给了一些 example 但不全)

实操路径:拿 Llama-3-8B(公开权重)→ 用 sae_lens 训 SAE → 自己探索 features。资源:1-2 张 H100,1-2 周。


七、Attribution Graphs(2025)—— On the Biology of LLM

7.1 出发点

SAE 给了 features,但features 之间怎么互动? 一个 reasoning chain 是 features 的因果链。Attribution Graphs 把这个链画出来。

7.2 方法

输入 prompt + 目标 token,构造一个图:

  • 节点:features(来自 SAE)+ tokens
  • :feature A 在 layer L 激活 → feature B 在 layer L+1 被它影响(用 gradient 估计或 ablation)

通过对图做 graph algorithm(最短路径、community detection),可以自动发现 reasoning steps

7.3 实例(paper Figure 案例)

prompt: "What state's capital is Austin?"

Attribution graph 显示:

  1. Token "Austin" → feature "capital city of Texas"
  2. feature "Texas" 激活
  3. layer L+5 → feature "US states"
  4. layer L+10 → output token "Texas"

每一步都是可观察、可干预的电路。

7.4 实操工具

Anthropic 没完全开源(attribution graph 代码内部用),但学术界(circuitsvis)有等价工具。


八、Influence Functions(2023)

8.1 问题

"模型为什么这样回答?是哪个训练样本导致的?"

经典 ML 工具是 Influence Functions(Koh & Liang 2017),但对 LLM 直接计算是 \(O(N^2)\) 不可行。

8.2 EK-FAC 近似

Grosse et al. 2023 用 Eigenvalue-corrected K-FAC 近似 Hessian inverse,把单个 query 的 influence 计算从 \(O(N^2)\) 降到 \(O(N)\)(with offline 预处理)。

8.3 规模

模型 论文实验 备注
8B Pythia ✅ 完整 学术公开
52B Anthropic 内部模型 不公开权重
Claude 3 / 4 部分 Anthropic 内部用

8.4 实用价值

Anthropic 用 influence functions 做:

  • Pretraining data attribution:模型某个能力是哪批数据贡献的
  • Generalization studies:模型 in-distribution vs out-of-distribution 行为
  • Safety auditing:检查不希望的行为是否来自特定 data poisoning

九、Constitutional AI 的机制视角

9.1 CAI 工作 vs 解释

Constitutional AI(Bai et al. 2022)是训练方法(见 alignment.md §一)。但模型遵守 constitution 的内部机制是 mech interp 关心的:

  • Refusal 是某个 feature 触发的吗?("refusal feature" SAE 实证)
  • 不同 constitutional principle 在 weight 里有不同的 circuits 吗?

9.2 Refusal feature

Scaling Monosemanticity paper 报告:在 Claude 3 Sonnet 找到了一个明显的 "refusal" feature。Steer 它能:

  • 提高激活 → 模型在不需要拒绝的 prompt 上拒绝(over-refusal)
  • 抑制激活 → 模型在该拒绝的 prompt 上响应(jailbreak)

这个 feature 的存在说明 constitutional 训练确实在 weight 里塑造了一个明确的拒绝机制,不是分散的。


十、产业落地:Constitutional Classifiers(2025)

Anthropic 2025 有论文 [Constitutional Classifiers (待核实标题,arXiv ID 待补)] 用 SAE / interp 工具做生产级 prompt 安全过滤:

  • 输入 prompt → encode 到 SAE features
  • 检查若干"red-flag features"(jailbreak、PII、weapons 等)的激活
  • 触发阈值则拦截或重写

跟传统 keyword filter / classifier 比的优势:

  • Concept-level:捕获语义而非表面词
  • Interpretable:每次拦截能给出原因("激活了 jailbreak feature")
  • 可调:阈值是连续的,便于 A/B 测试

总结

  1. mech interp 不再是研究玩具,是工程工具 —— SAE / steering 已经在 Claude 上做产品级 safety
  2. 关键 paper 顺序:Transformer Circuits → Induction Heads → Toy Superposition → Towards/Scaling Monosemanticity → Attribution Graphs。读这五篇能拿全 mech interp 工具箱
  3. 复现起点sae_lens 是最快路线,Llama-3-8B / Pythia / GPT-2 都有公开 SAE
  4. 跟 LLM playbook 关联:这些工具可以用来分析自己训的 LLM(Kimi、Qwen 等)—— SAE 不需要 model weights 公开(待核实,需 model API hook),分析自家模型的 reasoning circuits
  5. 未来方向:跨 checkpoint feature transfer、多模态 SAE、reasoning-specific SAE

参考文献

  1. Elhage et al. A Mathematical Framework for Transformer Circuits. 2021. transformer-circuits.pub/2021/framework
  2. Olsson et al. In-context Learning and Induction Heads. 2022. transformer-circuits.pub/2022/in-context-learning-and-induction-heads
  3. Elhage et al. Toy Models of Superposition. 2022. transformer-circuits.pub/2022/toy_model
  4. Bricken et al. Towards Monosemanticity: Decomposing Language Models with Dictionary Learning. 2023. transformer-circuits.pub/2023/monosemantic-features
  5. Templeton et al. Scaling Monosemanticity: Extracting Interpretable Features from Claude 3 Sonnet. 2024. transformer-circuits.pub/2024/scaling-monosemanticity
  6. Lindsey et al. On the Biology of a Large Language Model. 2025. transformer-circuits.pub/2025/attribution-graphs/biology
  7. Grosse et al. Studying Large Language Model Generalization with Influence Functions. 2023. arXiv:2308.03296
  8. Bai et al. Constitutional AI: Harmlessness from AI Feedback. 2022. arXiv:2212.08073
  9. TransformerLens — Neel Nanda's interpretability library
  10. SAELens — SAE training + analysis
  11. Koh & Liang. Understanding Black-box Predictions via Influence Functions. 2017. arXiv:1703.04730

上级 · Anthropic