Langsung ke konten
Skillpedia
Machine learning33k Β· #8575

mechanistic-interpretability-saelens

Fungsinya

Skill ini memandu AI Anda menggunakan pustaka SAELens untuk memecah sinyal internal sebuah model menjadi fitur yang bisa dipahami satu per satu. Skill ini ditujukan bagi peneliti yang mempelajari cara model bahasa merepresentasikan konsep.

Kapan dipakai

  • βœ“Saat Anda ingin mengetahui konsep apa saja yang dipelajari sebuah model bahasa secara internal.
  • βœ“Saat Anda ingin melatih sparse autoencoder pada aktivasi sebuah model.
  • βœ“Saat Anda ingin mempelajari fitur yang terkait dengan topik keamanan, seperti penipuan atau konten berbahaya.

Link skill

https://github.com/davila7/claude-code-templates/blob/main/cli-tool/components/skills/ai-research/mechanistic-interpretability-saelens/SKILL.md

Salin lalu tempelkan ke AI Anda (Claude, ChatGPT, atau Cursor) dan minta AI mengikuti instruksinya.

Cara pakai

Cara paling mudah: salin pesan ini dan tempelkan ke AI Anda. AI akan membaca skill dan mengikuti instruksinya.

Pesan siap tempel

Gunakan skill ini untuk membantu saya: https://github.com/davila7/claude-code-templates/blob/main/cli-tool/components/skills/ai-research/mechanistic-interpretability-saelens/SKILL.md Baca file SKILL.md di link tersebut dan ikuti instruksinya untuk tugas saya.
Mau AI Anda menemukan skill seperti ini sendiri?Pasang MCP Skillpedia gratis: cukup satu baris, dan AI mencari di antara 15.000+ skill sebelum tiap tugas.Pasang dalam 1 menit β†’

Contoh permintaan ke AI

β€œBisakah Anda membantu saya menemukan fitur internal yang dipakai model bahasa untuk topik tertentu?”

5 skill baru setiap minggu. 1 menit baca.

Cara kerjanya

Skill ini menjelaskan cara melatih atau memuat sparse autoencoder. Autoencoder ini memecah aktivasi model menjadi sekumpulan kecil fitur, dan Anda kemudian bisa melihat input mana yang mengaktifkan setiap fitur.

Konten teknis (SKILL.md asli)

Teks asli dari pembuat, dalam bahasa Inggris, langsung dari GitHub.

SAELens: Sparse Autoencoders for Mechanistic Interpretability

SAELens is the primary library for training and analyzing Sparse Autoencoders (SAEs) - a technique for decomposing polysemantic neural network activations into sparse, interpretable features. Based on Anthropic's groundbreaking research on monosemanticity.

GitHub: jbloomAus/SAELens (1,100+ stars)

The Problem: Polysemanticity & Superposition

Individual neurons in neural networks are polysemantic - they activate in multiple, semantically distinct contexts. This happens because models use superposition to represent more features than they have neurons, making interpretability difficult.

SAEs solve this by decomposing dense activations into sparse, monosemantic features - typically only a small number of features activate for any given input, and each feature corresponds to an interpretable concept.

When to Use SAELens

Use SAELens when you need to:

  • Discover interpretable features in model activations
  • Understand what concepts a model has learned
  • Study superposition and feature geometry
  • Perform feature-based steering or ablation
  • Analyze safety-relevant features (deception, bias, harmful content)

Consider alternatives when:

  • You need basic activation analysis β†’ Use TransformerLens directly
  • You want causal intervention experiments β†’ Use pyvene or TransformerLens
  • You need production steering β†’ Consider direct activation engineering

Installation

pip install sae-lens

Requirements: Python 3.10+, transformer-lens>=2.0.0

Core Concepts

What SAEs Learn

SAEs are trained to reconstruct model activations through a sparse bottleneck:

Input Activation β†’ Encoder β†’ Sparse Features β†’ Decoder β†’ Reconstructed Activation
    (d_model)       ↓        (d_sae >> d_model)    ↓         (d_model)
                 sparsity                      reconstruction
                 penalty                          loss

Loss Function: MSE(original, reconstructed) + L1_coefficient Γ— L1(features)

Key Validation (Anthropic Research)

In "Towards Monosemanticity", human evaluators found 70% of SAE features genuinely interpretable. Features discovered include:

  • DNA sequences, legal language, HTTP requests
  • Hebrew text, nutrition statements, code syntax
  • Sentiment, named entities, grammatical structures

Workflow 1: Loading and Analyzing Pre-trained SAEs

Step-by-Step

from transformer_lens import HookedTransformer
from sae_lens import SAE

# 1. Load model and pre-trained SAE
model = HookedTransformer.from_pretrained("gpt2-small", device="cuda")
sae, cfg_dict, sparsity = SAE.from_pretrained(
    release="gpt2-small-res-jb",
    sae_id="blocks.8.hook_resid_pre",
    device="cuda"
)

# 2. Get model activations
tokens = model.to_tokens("The capital of France is Paris")
_, cache = model.run_with_cache(tokens)
activations = cache["resid_pre", 8]  # [batch, pos, d_model]

# 3. Encode to SAE features
sae_features = sae.encode(activations)  # [batch, pos, d_sae]
print(f"Active features: {(sae_features > 0).sum()}")

# 4. Find top features for each position
for pos in range(tokens.shape[1]):
    top_features = sae_features[0, pos].topk(5)
    token = model.to_str_tokens(tokens[0, pos:pos+1])[0]
    print(f"Token '{token}': features {top_features.indices.tolist()}")

# 5. Reconstruct activations
reconstructed = sae.decode(sae_features)
reconstruction_error = (activations - reconstructed).norm()

Available Pre-trained SAEs

Release Model Layers
gpt2-small-res-jb GPT-2 Small Multiple residual streams
gemma-2b-res Gemma 2B Residual streams
Various on HuggingFace Search tag saelens Various

Checklist

  • Load model with TransformerLens
  • Load matching SAE for target layer
  • Encode activations to sparse features
  • Identify top-activating features per token
  • Validate reconstruction quality

Workflow 2: Training a Custom SAE

Step-by-Step

from sae_lens import SAE, LanguageModelSAERunnerConfig, SAETrainingRunner

# 1. Configure training
cfg = LanguageModelSAERunnerConfig(
    # Model
    model_name="gpt2-small",
    hook_name="blocks.8.hook_resid_pre",
    hook_layer=8,
    d_in=768,  # Model dimension

    # SAE architecture
    architecture="standard",  # or "gated", "topk"
    d_sae=768 * 8,  # Expansion factor of 8
    activat
Pertanyaan umum

Apa itu sparse autoencoder di sini?

Ini adalah model kecil yang menulis ulang sinyal internal model bahasa sebagai kumpulan fitur yang jarang dan lebih mudah dibaca.

Apakah saya perlu melatih sendiri?

Tidak selalu. Skill ini mencakup pelatihan autoencoder baru maupun penggunaan autoencoder yang sudah ada.

Untuk siapa ini?

Ini untuk peneliti dan pengguna mahir yang sudah memahami dasar-dasar cara kerja internal model bahasa.

Detail

Deskripsi asli dari pembuat

Provides guidance for training and analyzing Sparse Autoencoders (SAEs) using SAELens to decompose neural network activations into interpretable features. Use when discovering interpretable features, analyzing superposition, or studying monosemantic representations in language models.

repo: davila7/claude-code-templates

Popularitas

Bintang GitHub
33k
Peringkat
#8575
Lisensi
MIT
Diperbarui
2/11/2026

Apakah skill ini berguna?

0

Masuk untuk memberi suara.

Komentar

  • …

Skill lain dari repositori ini

Skill serupa