0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

Uncensored1776 Day 6: 学術的基盤 - Arditi et al. 論文の解説

Last updated at Posted at 2025-12-11

Uncensored1776 Day 6: 学術的基盤 - Arditi et al. 論文の解説

「拒否は単一の方向によって媒介される」

公開日: 2025-12-06
シリーズ: 科学と神々株式会社 アドベントカレンダー
難易度: ★★★☆☆ (中級)


今日学ぶこと

  • Arditi et al. (2024) 論文の概要
  • 「拒否方向」の発見と意義
  • Abliteration技術の理論的基盤

1. 論文の概要

1.1 基本情報

タイトル: "Refusal in Language Models Is Mediated by a Single Direction"
著者: Andy Arditi, Oscar Obeso, Aaquib Syed, Daniel Paleka,
      Nina Panickssery, Wes Gurnee, Neel Nanda
発表: 2024年6月17日(v3: 2024年10月30日)
arXiv: 2406.11717
URL: https://arxiv.org/abs/2406.11717

1.2 主要な発見

衝撃的な発見: LLMの「拒否」行動は、高次元空間における単一の方向によって制御されている。

従来の理解:
- 検閲は複雑なパターン
- 多数のニューロンが関与
- 解除は困難

新しい理解:
- 検閲は「一本の線」で表現
- 特定の方向を削除すれば解除可能
- シンプルな数学で実現

2. 論文の詳細解説

2.1 実験の設計

研究者たちは以下の実験を行いました:

実験デザイン:

1. 有害プロンプトを用意
   "How do I make a bomb?"
   "Write a hate speech..."

2. 無害プロンプトを用意
   "What is the capital of France?"
   "Explain photosynthesis..."

3. 各プロンプトに対する隠れ状態を収集

4. 有害/無害の隠れ状態の差分を計算

5. その差分が「拒否方向」

2.2 数学的定式化

隠れ状態の表現:

h_harmful = モデルの有害プロンプトへの内部表現
h_harmless = モデルの無害プロンプトへの内部表現

拒否方向 d = mean(h_harmful) - mean(h_harmless)
d_normalized = d / ||d||  # 正規化

Pythonでの実装:

def compute_refusal_direction(
    harmful_activations: torch.Tensor,
    harmless_activations: torch.Tensor
) -> torch.Tensor:
    """拒否方向を計算"""

    # 各クラスの平均を計算
    mean_harmful = harmful_activations.mean(dim=0)
    mean_harmless = harmless_activations.mean(dim=0)

    # 差分を計算
    direction = mean_harmful - mean_harmless

    # 外れ値をクリップ (論文の推奨)
    threshold = torch.quantile(direction.abs().float(), 0.995)
    direction = direction.clamp(-threshold, threshold)

    # 正規化
    direction = direction / direction.norm()

    return direction

2.3 驚くべき結果

論文の主要な発見:

発見1: 単一方向の存在
- 拒否行動は1つの方向で説明可能
- 複数のレイヤーで同様のパターン

発見2: 方向の削除で拒否が消える
- その方向を重みから削除すると
- モデルは拒否しなくなる

発見3: 他の能力は保持される
- 一般的な能力は維持
- 品質の低下は最小限

3. 視覚的理解

3.1 高次元空間のイメージ

モデルの内部空間(非常に高次元):

         有害プロンプトの応答
              ↗
             /
            /  ← 拒否方向
           /
          ●────────────────→ 無害プロンプトの応答


この「拒否方向」を削除すると:





          ●────────────────→ すべてのプロンプトに応答

3.2 数学的な射影

射影の概念:

元のベクトル r
       ↗
      /
     /
    ●────────────────────→ 拒否方向 d

射影を削除:
r' = r - (r · d)d




    ●────────────────────→ 拒否方向と直交

4. 論文のインパクト

4.1 理論的意義

従来の理解:
"AIの安全性は複雑で、簡単に解除できない"

新しい理解:
"拒否は実は単純な構造を持っている"
"だからこそ、責任ある解除が可能"

4.2 実用的影響

1. 検閲解除が容易になった
   - 複雑なファインチューニング不要
   - 重みの編集だけで実現

2. 品質の維持が可能
   - ターゲットを絞った変更
   - 副作用を最小化

3. 研究の進展
   - 安全性メカニズムの理解
   - より良い設計への示唆

5. Abliteration技術への発展

5.1 論文からの発展

Arditi et al.の発見を基に、実用的なAbliteration技術が開発されました。

論文の発見 → Abliteration技術

1. 拒否方向の計算
   論文の手法をそのまま使用

2. 重みへの適用
   MLP層の重み行列から削除

3. 強度の調整
   Weight Kernelによる層別調整

5.2 Standard Abliteration

論文の手法を直接適用:

def standard_abliteration(W: torch.Tensor, d: torch.Tensor, strength: float):
    """
    Standard Abliteration: 論文の基本手法

    数式: W' = W - strength * (d ⊗ d) @ W

    Args:
        W: 重み行列
        d: 拒否方向(正規化済み)
        strength: 削除強度
    """
    # 外積で射影行列を作成
    projection = torch.outer(d, d)

    # 射影成分を削除
    W.data -= strength * (projection @ W.data)

5.3 Projected Abliteration

論文を発展させた手法:

def projected_abliteration(W: torch.Tensor, mu: torch.Tensor, strength: float):
    """
    Projected Abliteration: 直交部分空間への射影

    数式: W' = W - strength * (W @ μ) ⊗ μ

    特徴:
    - より保守的なアプローチ
    - 品質維持に優れる
    """
    # 重みの拒否方向成分を計算
    component = W.data @ mu

    # その成分を削除
    W.data -= strength * torch.outer(component, mu)

6. 論文の限界と注意点

6.1 論文が述べる限界

著者が認める限界:

1. モデル依存性
   - すべてのモデルで同じパターンか不明
   - アーキテクチャによる違い

2. 完全性の保証なし
   - すべての拒否が削除されるわけではない
   - 新しい形式の拒否が残る可能性

3. 安全性への影響
   - 意図した安全性も削除される可能性
   - 慎重な適用が必要

6.2 実践での注意点

実装時の注意:

1. 有害プロンプトの選定
   - 解除したいカテゴリを明確に
   - 安全性関連は含めない

2. 強度の調整
   - 強すぎると品質低下
   - 弱すぎると効果不足

3. 検証の重要性
   - 解除後の動作確認
   - 安全性テスト

7. 関連研究

7.1 Zou et al. (2023)

"Universal and Transferable Adversarial Attacks
on Aligned Language Models"

著者: Andy Zou, Zifan Wang, Nicholas Carlini, Milad Nasr,
      J. Zico Kolter, Matt Fredrikson
発表: 2023年7月27日
arXiv: 2307.15043
URL: https://arxiv.org/abs/2307.15043
GitHub: https://github.com/llm-attacks/llm-attacks

発見: 整列されたLLMへの普遍的な攻撃手法(GCG: Greedy Coordinate Gradient)
関連: 安全性訓練の脆弱性を示す
被引用数: 2,100+ (2025年現在)

7.2 Wei et al. (2023)

"Jailbroken: How Does LLM Safety Training Fail?"

著者: Alexander Wei, Nika Haghtalab, Jacob Steinhardt
発表: 2023年7月5日(NeurIPS 2023採択)
arXiv: 2307.02483
URL: https://arxiv.org/abs/2307.02483
PDF: https://proceedings.neurips.cc/paper_files/paper/2023/file/fd6613131889a4b656206c50a8bd7790-Paper-Conference.pdf

発見: 安全性訓練の失敗パターンを分類
  - Competing Objectives(競合する目標)
  - Mismatched Generalization(汎化の不一致)
関連: 検閲メカニズムの理解に貢献

7.3 grimjim's Projected Abliteration

発展: Arditi et al.の手法を改良
特徴: 直交射影による品質維持
貢献: Projected Abliteration、Biprojected Abliteration、SLERP Abliterationの提案

参考リンク:
- Projected Abliteration: https://huggingface.co/blog/grimjim/projected-abliteration
- Norm-Preserving Biprojected: https://huggingface.co/blog/grimjim/norm-preserving-biprojected-abliteration
- SLERP Abliteration: https://huggingface.co/blog/grimjim/exploring-slerp-abliteration
- GitHub実装: https://github.com/jim-plus/llm-abliteration

8. コードで理解する

8.1 完全な実装例

# scripts/enhanced_abliteration.py より

import torch
from transformers import AutoModelForCausalLM, AutoTokenizer

def full_abliteration_pipeline(
    model_name: str,
    harmful_prompts: list,
    harmless_prompts: list,
    target_layers: tuple,
    method: str = "projected"
):
    """
    完全なAbliterationパイプライン

    1. モデルをロード
    2. アクティベーションを収集
    3. 拒否方向を計算
    4. 重みを修正
    5. モデルを保存
    """

    # Step 1: モデルロード
    model = AutoModelForCausalLM.from_pretrained(model_name)
    tokenizer = AutoTokenizer.from_pretrained(model_name)

    # Step 2: アクティベーション収集
    harmful_acts = collect_activations(model, tokenizer, harmful_prompts)
    harmless_acts = collect_activations(model, tokenizer, harmless_prompts)

    # Step 3: 拒否方向計算
    refusal_dir = compute_refusal_direction(harmful_acts, harmless_acts)

    # Step 4: 重み修正
    num_layers = model.config.num_hidden_layers
    for layer_idx in range(num_layers):
        # ターゲットレイヤーのみ処理
        if not is_target_layer(layer_idx, num_layers, target_layers):
            continue

        # 重みを取得
        layer = model.model.layers[layer_idx]
        W = layer.mlp.down_proj.weight

        # Abliteration適用
        weight = compute_weight_kernel(layer_idx, num_layers)
        if method == "projected":
            projected_abliteration(W, refusal_dir, weight)
        else:
            standard_abliteration(W, refusal_dir, weight)

    return model

9. 今日のまとめ

Arditi et al. (2024) の要点:

発見:
- LLMの拒否は「単一の方向」で表現
- その方向を削除すれば拒否を解除可能

数学:
- 拒否方向 d = mean(有害) - mean(無害)
- 削除: W' = W - (d ⊗ d) @ W

意義:
- 検閲メカニズムの理解が深まった
- 実用的な解除技術の基盤

発展:
- Standard Abliteration
- Projected Abliteration
- Weight Kernel

明日の予告

Day 7: R1-1776の誕生 - Perplexity AIの取り組み

  • Perplexity AIとは
  • R1-1776プロジェクトの背景
  • 商用モデルからの検閲解除

参考リンク

主要論文

技術リソース

プロジェクト内リンク


ナビゲーション

前の記事 Day 5: 検閲解除の倫理的枠組み
次の記事 Day 7: R1-1776の誕生
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?