# 稀疏自编码器

稀疏自编码器是一种自编码器，其训练准则在编码层上额外施加稀疏惩罚，使得对于任意给定输入，只有一小部分隐藏单元处于激活状态，此外还包括通常的重构误差 \( L(x, g(f(x))) + \Omega(h) \)。<sup>[1](https://www.deeplearningbook.org/contents/autoencoders.html)</sup> 该惩罚使得隐藏单元数多于输入维数的过完备表示成为良定问题，并支撑了两种不同的用途：经典的无监督特征学习，以及将大语言模型激活分解为可解释特征。<sup>[2](https://arxiv.org/pdf/2309.08600v3.pdf)</sup><sup> • </sup><sup>[3](https://transformer-circuits.pub/2023/monosemantic-features/index.html)</sup>

| 关键事实 | 数值 |
|---|---|
| 训练准则 | 重构损失加上编码层上的稀疏惩罚 \( \Omega(h) \)<sup>[1](https://www.deeplearningbook.org/contents/autoencoders.html)</sup> |
| 常用惩罚 | 朝向目标激活值 \( \rho = 0.05 \) 的KL散度，或L1项 \( \alpha \lVert c \rVert_1 \)<sup>[4](https://web.stanford.edu/class/cs294a/sparseAutoencoder_2011new.pdf)</sup><sup> • </sup><sup>[2](https://arxiv.org/pdf/2309.08600v3.pdf)</sup> |
| 字典大小 | 过完备；在一项Anthropic研究中，扩展因子从1×（512个特征）到256×（131,072个特征）<sup>[3](https://transformer-circuits.pub/2023/monosemantic-features/index.html)</sup> |
| 典型激活量 | 在Claude 3 Sonnet上训练的3400万特征SAE中，每个token的活跃特征少于300个<sup>[5](https://transformer-circuits.pub/2024/scaling-monosemanticity/index.html)</sup> |
| 重构质量 | 4,096个特征时恢复MLP层损失的79%；131,072个特征时恢复94.5%（L1系数0.004）<sup>[3](https://transformer-circuits.pub/2023/monosemantic-features/index.html)</sup> |
| 死亡单元 | 未经缓解时死亡潜变量高达90%；采用解码器转置初始化加辅助损失后降至7%<sup>[6](https://proceedings.iclr.cc/paper_files/paper/2025/file/42ef3308c230942d223c411adf182c88-Paper-Conference.pdf)</sup> |
| 现代训练规模 | 在GPT-4残差流激活上训练1600万潜变量SAE，训练400亿token<sup>[6](https://proceedings.iclr.cc/paper_files/paper/2025/file/42ef3308c230942d223c411adf182c88-Paper-Conference.pdf)</sup> |

## 工作原理

目标函数由两项组成。重构项衡量解码器将编码映射回输入的效果；稀疏项惩罚隐藏激活，使大多数单元输出接近零。在KL散度形式中，每个隐藏单元的平均激活 \( \hat{\rho}_j \) 被约束朝向稀疏参数 \( \rho \)，通常是一个接近零的小值，如 \( \rho = 0.05 \)，代价函数变为 \( J_{\mathrm{sparse}}(W, b) = J(W, b) + \beta \sum_{j} \mathrm{KL}(\rho \,\Vert\, \hat{\rho}_j) \)，其中 \( \beta \) 控制惩罚权重。<sup>[4](https://web.stanford.edu/class/cs294a/sparseAutoencoder_2011new.pdf)</sup> 当 \( \hat{\rho}_j = \rho \) 时KL项为零，当 \( \hat{\rho}_j \) 趋近0或1时则趋向无穷大。<sup>[7](http://ufldl.stanford.edu/tutorial/unsupervised/Autoencoders/)</sup>

在用于语言模型的L1形式中，损失为 \( L(x) = \lVert x - \hat{x} \rVert_2^2 + \alpha \lVert c \rVert_1 \)，其中 \( c \) 是特征激活向量，\( \alpha \) 设定稀疏性与重构之间的权衡。<sup>[2](https://arxiv.org/pdf/2309.08600v3.pdf)</sup><sup> • </sup><sup>[8](https://aclanthology.org/anthology-files/pdf/findings/2025.findings-emnlp.89.pdf)</sup> 稀疏性正是使过完备字典可学习的关键：当隐藏单元多于输入时，仅靠重构是退化的，而稀疏准则解决了这种退化。这与稀疏编码具有相同的结构——稀疏编码在过完备基上将输入 \( x \) 表示为 \( x = \sum_i a_i \cdot \phi_i \)，并在约束 \( \lVert \phi_i \rVert^2 \le C \) 下最小化 \( \sum_j \lVert x^{(j)} - \sum_i a_i^{(j)} \cdot \phi_i \rVert^2 + \lambda \sum_i S(a_i^{(j)}) \)，其中 \( S(a_i) = \lVert a_i \rVert_1 \) 或 \( \log(1 + a_i^2) \)。<sup>[9](http://ufldl.stanford.edu/tutorial/unsupervised/SparseCoding/)</sup> 自编码器的不同之处在于使用参数化前馈编码器，避免了稀疏编码对每个新样本所需的测试时优化。<sup>[9](http://ufldl.stanford.edu/tutorial/unsupervised/SparseCoding/)</sup>

## 实现方法

实践者选择输入维度、隐藏（字典）大小、惩罚形式和惩罚系数，然后通过反向传播进行训练。经典的斯坦福CS294A方案使用64个输入单元、25个隐藏单元和64个输出单元，在来自10张自然图像的10,000个随机采样的8×8图像块上训练，采用L-BFGS和sigmoid激活；目标函数包含三项：平方误差、权重衰减和稀疏惩罚。<sup>[10](https://web.stanford.edu/class/cs294a/cs294a_2011-assignment.pdf)</sup> 由于KL惩罚依赖于平均激活，必须在反向传播之前对所有训练样本进行一次前向传播，隐藏层的误差信号会增加一项 \( \beta(-\rho/\hat{\rho}_i + (1-\rho)/(1-\hat{\rho}_i)) \)。<sup>[7](http://ufldl.stanford.edu/tutorial/unsupervised/Autoencoders/)</sup>

对于语言模型SAE，Cunningham及其同事使用Adam优化器、学习率1e-3，在500万至5000万个激活向量上训练1至3轮，在单块A40 GPU上不到一小时即可完成；[残差流](https://www.edgepedia.org/zh/residual-stream)的L1系数 \( \alpha \) 为8.6e-4，MLP层为3.2e-4，稀疏性-准确率权衡曲线平滑，没有拐点。<sup>[2](https://arxiv.org/pdf/2309.08600v3.pdf)</sup> 质量通过 \( L_{0} \)（平均使用的特征数）和恢复损失（用重构替换激活时的归一化交叉熵）来监控。<sup>[11](https://www.proceedings.com/content/079/079017-0024open.pdf)</sup> SAEBench建议在 \( L_{0} \) 的[20, 200]范围内进行训练，因为许多指标与稀疏性强烈相关，并建议将解码器初始化为编码器的转置，这对于避免死亡潜变量很重要。<sup>[12](https://arxiv.org/pdf/2503.09532)</sup>

## 起源

数学根源是使用学习得到的过完备字典的稀疏编码。Olshausen和Field 1996年发表于《自然》的论文训练了一个模型来寻找自然图像的稀疏线性编码，学习到的基函数发展出类似于初级视觉皮层简单细胞的局部化、方向选择性和带通感受野。<sup>[13](https://doi.org/10.1038/381607a0)</sup><sup> • </sup><sup>[14](https://princetonuniversity.github.io/NEU-PSY-502/_static/pdf/Class%202/Olhausen96.pdf)</sup> 同一作者1997年发表于《视觉研究》的相关论文也常被文献引用。<sup>[2](https://arxiv.org/pdf/2309.08600v3.pdf)</sup>

编码器-解码器形式出现在深度学习时代：稀疏编码对称机（SESM）是一种无监督算法，产生稀疏过完备表示，其损失结合了重构误差和稀疏惩罚，如 \( \log(1 + \lVert z_i \rVert^2) \)，对应于因子化的学生t分布先验。<sup>[15](https://www.cs.toronto.edu/~ranzato/publications/ranzato-nips07.pdf)</sup> 《深度学习》教科书将稀疏自编码器的早期工作归功于Ranzato等人（2007a, 2008）。<sup>[1](https://www.deeplearningbook.org/contents/autoencoders.html)</sup> KL散度教程形式在斯坦福CS294A/UFLDL讲义中被标准化。<sup>[4](https://web.stanford.edu/class/cs294a/sparseAutoencoder_2011new.pdf)</sup> Makhzani和Frey于2013年在arXiv上提出了k-稀疏自编码器，使用TopK激活。<sup>[16](https://doi.org/10.48550/arxiv.1312.5663)</sup> 现代可解释性用途始于Cunningham及其同事2023年在arXiv上对Pythia残差流训练绑定权重ReLU SAE的工作。<sup>[17](https://doi.org/10.48550/arxiv.2309.08600)</sup>

## 变体

**KL散度SAE。** 使用sigmoid单元惩罚 \( \sum_j \mathrm{KL}(\rho \,\Vert\, \hat{\rho}_j) \)；经典的边缘检测器形式。<sup>[4](https://web.stanford.edu/class/cs294a/sparseAutoencoder_2011new.pdf)</sup>

**ReLU/L1 SAE。** 使用ReLU单元并对编码施加L1惩罚，在编码中产生真正的零。<sup>[1](https://www.deeplearningbook.org/contents/autoencoders.html)</sup>

**k-稀疏自编码器。** Makhzani和Frey 2013年的k-稀疏自编码器使用TopK激活，只保留k个最大的潜变量并将其余置零，直接控制活跃单元的数量。<sup>[16](https://doi.org/10.48550/arxiv.1312.5663)</sup>

**收缩自编码器和去噪自编码器。** 收缩自编码器惩罚编码器雅可比矩阵的弗罗贝尼乌斯范数的平方，\( \Omega(h) = \lambda \lVert \partial f(x)/\partial x \rVert_F^2 \)；Alain和Bengio（2013）证明，在小高斯输入噪声下，去噪重构误差等价于对重构函数的收缩惩罚。<sup>[1](https://www.deeplearningbook.org/contents/autoencoders.html)</sup>

**门控SAE。** 将特征选择与幅度估计分离，仅对门施加L1惩罚；这解决了激活收缩问题，并在可比重构保真度下只需一半的激活特征数。<sup>[11](https://www.proceedings.com/content/079/079017-0024open.pdf)</sup>

**JumpReLU SAE。** 由Rajamanoharan及其同事于2024年在arXiv上描述，在重构保真度上优于基线ReLU SAE。<sup>[18](https://doi.org/10.48550/arxiv.2407.14435)</sup>

**BatchTopK和Matryoshka SAE。** BatchTopK将TopK扩展到批次级别操作，允许每个样本的活跃潜变量数量灵活变化，同时保持期望的平均稀疏性。<sup>[19](https://proceedings.iclr.cc/paper_files/paper/2025/file/84ca3f2d9d9bfca13f69b48ea63eb4a5-Paper-Conference.pdf)</sup> Matryoshka BatchTopK SAE在SAEBench的概念检测和特征解耦任务中表现最佳。<sup>[12](https://arxiv.org/pdf/2503.09532)</sup>

## 应用

经典上，稀疏自编码器从无标签数据中学习特征：在白化自然图像块上训练的隐藏单元学习到不同位置和方向的边缘检测器。<sup>[4](https://web.stanford.edu/class/cs294a/sparseAutoencoder_2011new.pdf)</sup>

当前最主要的应用是语言模型的机制可解释性。Cunningham及其同事表明，Pythia残差流上的SAE特征比神经元、PCA和ICA更具可解释性，包括与K-活跃变体的受控比较，并能实现细粒度的回路检测。<sup>[2](https://arxiv.org/pdf/2309.08600v3.pdf)</sup> [Anthropic](https://www.edgepedia.org/zh/anthropic)在单层Transformer的512神经元MLP层上使用80亿数据点训练SAE，在1×到256×的扩展因子范围内发现了可解释特征。<sup>[3](https://transformer-circuits.pub/2023/monosemantic-features/index.html)</sup> 扩展到Claude 3 Sonnet后，多达3400万特征的SAE提取了多语言、多模态特征，通过将特征钳制到高值或低值进行特征引导，可以改变举止、偏好和所陈述的目标，并诱发错误，包括欺骗和谄媚等安全相关特征。<sup>[5](https://transformer-circuits.pub/2024/scaling-monosemanticity/index.html)</sup> OpenAI在GPT-4激活上训练了1600万特征的SAE，于2024年6月6日公布，并发布了代码和特征可视化。<sup>[20](https://openai.com/index/extracting-concepts-from-gpt-4/)</sup>

## 局限与替代方案

**死亡单元。** 未经缓解时，大型SAE中高达90%的潜变量可能死亡；将编码器初始化为解码器转置加上辅助top-k损失，在1600万潜变量模型中可将此降至7%。<sup>[6](https://proceedings.iclr.cc/paper_files/paper/2025/file/42ef3308c230942d223c411adf182c88-Paper-Conference.pdf)</sup> Anthropic通过重采样处理死亡神经元，定期重置未激活神经元的编码器权重以匹配表示不佳的数据点。<sup>[3](https://transformer-circuits.pub/2023/monosemantic-features/index.html)</sup>

**收缩与吸收。** L1惩罚使激活值向下偏移，门控SAE解决了这一问题。<sup>[11](https://www.proceedings.com/content/079/079017-0024open.pdf)</sup> 特征吸收发生在一个看似单义的潜变量未能激活、其特征被吸收到与token对齐的子潜变量中时；只要底层特征形成层次结构，稀疏惩罚就会导致这种情况，而增加吸收在保持完美重构的同时严格降低期望L1损失，因此仅改变SAE大小或稀疏性不足以解决该问题。<sup>[21](https://proceedings.neurips.cc/paper_files/paper/2025/file/764ff7477b8e24dbe01531f6791e8bdf-Paper-Conference.pdf)</sup>

**摊销差距。** 利用压缩感知理论，已证明标准的线性-非线性SAE编码器即使在可解情况下也本质上不足以进行准确的稀疏推断；将编码与解码解耦并使用更具表达力的稀疏推断可带来显著收益。<sup>[22](https://proceedings.mlr.press/v267/o-neill25a.html)</sup>

**非规范字典。** SAE拼接表明较小的SAE是不完整的，元SAE表明较大的SAE潜变量并非原子的；不存在一个单一的SAE宽度能使模型学到唯一且完整的原子特征字典，因此字典大小应根据任务选择。<sup>[19](https://proceedings.iclr.cc/paper_files/paper/2025/file/84ca3f2d9d9bfca13f69b48ea63eb4a5-Paper-Conference.pdf)</sup>

**某些用途中下游收益微弱。** 在跨数据稀缺、类别不平衡、标签噪声和协变量偏移的激活探测中，SAE偶尔在个别数据集上优于基线，但没有任何SAE加基线的集成能持续优于纯基线集成，且表面上的优势可被简单的非SAE基线所匹配。<sup>[23](https://proceedings.mlr.press/v267/kantamneni25a.html)</sup>

**比较。** PCA基线实现完美重构，但 \( L_{0} \) 约等于模型的隐藏维度，因此不提供稀疏分解。<sup>[12](https://arxiv.org/pdf/2503.09532)</sup> ICA是稀疏编码在方阵满秩 \( A \) 且无噪声时的特例。<sup>[24](https://redwood.berkeley.edu/wp-content/uploads/2018/08/sparse-coding-ICA.pdf)</sup> OpenAI指出，完全覆盖前沿模型的概念可能需要数十亿甚至数万亿个特征。<sup>[6](https://proceedings.iclr.cc/paper_files/paper/2025/file/42ef3308c230942d223c411adf182c88-Paper-Conference.pdf)</sup><sup> • </sup><sup>[20](https://openai.com/index/extracting-concepts-from-gpt-4/)</sup>

## References

1. [Deep Learning (Goodfellow, Bengio, Courville), Chapter 14: Autoencoders](https://www.deeplearningbook.org/contents/autoencoders.html)
2. [Sparse Autoencoders Find Highly Interpretable Features in Language Models (Cunningham et al., 2023)](https://arxiv.org/pdf/2309.08600v3.pdf)
3. [Towards Monosemanticity: Decomposing Language Models With Dictionary Learning (Bricken et al., Anthropic, 2023)](https://transformer-circuits.pub/2023/monosemantic-features/index.html)
4. [Sparse autoencoder, UFLDL/CS294A tutorial notes (Andrew Ng et al., 2011)](https://web.stanford.edu/class/cs294a/sparseAutoencoder_2011new.pdf)
5. [Scaling Monosemanticity: Extracting Interpretable Features from Claude 3 Sonnet (Templeton et al., Anthropic, 2024)](https://transformer-circuits.pub/2024/scaling-monosemanticity/index.html)
6. [Scaling and Evaluating Sparse Autoencoders (Gao et al., OpenAI, ICLR 2025)](https://proceedings.iclr.cc/paper_files/paper/2025/file/42ef3308c230942d223c411adf182c88-Paper-Conference.pdf)
7. [UFLDL Tutorial: Autoencoders (Stanford)](http://ufldl.stanford.edu/tutorial/unsupervised/Autoencoders/)
8. [A Survey on Sparse Autoencoders: Interpreting the Internal Mechanisms of Large Language Models (EMNLP 2025 Findings)](https://aclanthology.org/anthology-files/pdf/findings/2025.findings-emnlp.89.pdf)
9. [UFLDL Tutorial: Sparse Coding (Stanford)](http://ufldl.stanford.edu/tutorial/unsupervised/SparseCoding/)
10. [CS294A/W Winter 2011 Programming Assignment: Sparse Autoencoder](https://web.stanford.edu/class/cs294a/cs294a_2011-assignment.pdf)
11. [Improving Sparse Decomposition of Language Model Activations with Gated Sparse Autoencoders (Rajamanoharan et al., 2024)](https://www.proceedings.com/content/079/079017-0024open.pdf)
12. [SAEBench: A Comprehensive Benchmark for Sparse Autoencoders in Language Model Interpretability](https://arxiv.org/pdf/2503.09532)
13. [Bruno A. Olshausen, David J. Field (1996). Emergence of simple-cell receptive field properties by learning a sparse code for natural images. Nature.](https://doi.org/10.1038/381607a0)
14. [Emergence of simple-cell receptive field properties by learning a sparse code for natural images (Olshausen & Field, Nature 1996)](https://princetonuniversity.github.io/NEU-PSY-502/_static/pdf/Class%202/Olhausen96.pdf)
15. [Sparse Feature Learning for Deep Belief Networks (Ranzato et al., NIPS 2007)](https://www.cs.toronto.edu/~ranzato/publications/ranzato-nips07.pdf)
16. [Makhzani, Alireza, Frey, Brendan (2013). k-Sparse Autoencoders. arXiv (Cornell University).](https://doi.org/10.48550/arxiv.1312.5663)
17. [Cunningham, Hoagy and colleagues (2023). Sparse Autoencoders Find Highly Interpretable Features in Language Models. arXiv (Cornell University).](https://doi.org/10.48550/arxiv.2309.08600)
18. [Rajamanoharan, Senthooran and colleagues (2024). Jumping Ahead: Improving Reconstruction Fidelity with JumpReLU Sparse Autoencoders. arXiv (Cornell University).](https://doi.org/10.48550/arxiv.2407.14435)
19. [Sparse Autoencoders Do Not Find Canonical Units of Analysis (ICLR 2025)](https://proceedings.iclr.cc/paper_files/paper/2025/file/84ca3f2d9d9bfca13f69b48ea63eb4a5-Paper-Conference.pdf)
20. [Extracting Concepts from GPT-4 (OpenAI, June 6, 2024)](https://openai.com/index/extracting-concepts-from-gpt-4/)
21. [A is for Absorption: Studying Feature Splitting and Absorption in Sparse Autoencoders (NeurIPS 2025; Chanin et al.)](https://proceedings.neurips.cc/paper_files/paper/2025/file/764ff7477b8e24dbe01531f6791e8bdf-Paper-Conference.pdf)
22. [Compute Optimal Inference and Provable Amortisation Gap in Sparse Autoencoders (ICML 2025; arXiv 2411.13117)](https://proceedings.mlr.press/v267/o-neill25a.html)
23. [Are Sparse Autoencoders Useful? A Case Study in Sparse Probing (ICML 2025)](https://proceedings.mlr.press/v267/kantamneni25a.html)
24. [Sparse coding and 'ICA' (Olshausen, 2008 lecture notes)](https://redwood.berkeley.edu/wp-content/uploads/2018/08/sparse-coding-ICA.pdf)

---
*Initially written Sep 29, 2026 · Edited: Oct 15, 2026*

Topic: 技术与人造世界 › 计算技术与数字系统 › 人工智能与数据 › Machine learning and neural computation › Neural networks and deep learning › Titles I to Z

Copyright 2026 Edgepedia

License: Edgepedia Community License 1.0, https://www.edgepedia.org/edgepedia/license

Source: https://www.edgepedia.org/zh/sparse-autoencoder

English original: https://www.edgepedia.org/sparse-autoencoder
