Без опису

caozheng 1110b56d06 Remove model/representations from git tracking 5 місяців тому
database e1b9827551 first commit 5 місяців тому
experiments e1b9827551 first commit 5 місяців тому
model 1110b56d06 Remove model/representations from git tracking 5 місяців тому
paper e1b9827551 first commit 5 місяців тому
.gitignore 1110b56d06 Remove model/representations from git tracking 5 місяців тому
README.md e1b9827551 first commit 5 місяців тому
requirements.txt e1b9827551 first commit 5 місяців тому

README.md

LLM 有效秩谱收敛验证实验

基于谱分析的 LLM 表示研究框架,用于检验 Platonic Representation Hypothesis


📌 核心结论

实验 发现 理论贡献
E1: 基础谱收敛 形式化任务收敛,开放任务发散 领域特异性分层
E2: 跨域谱分层 开放域 RS_cross 是形式化的 2.75 倍 谱分层 = 领域客观性度量
E3: 能力涌现 r_eff 单调变化,无突变点 涌现 = 渐进式演化
E4: 对齐机制 对齐 = 谱展开 + 域分化(跨模型普适) 新理论:对齐即谱工程
E5: 难度代理 RS_cross 与文本长度负相关 (ρ=-0.90) 短文本 = 高信息密度

核心贡献: 提出谱展开理论,证伪"谱压缩"假设,发现对齐使模型在指令域使用更多表示维度。


项目结构

effectiveRank/
├── model/                      # 模型核心模块
│   ├── spectrum.py             # 谱计算(r_eff、SPD、W1 距离)
│   ├── extractor.py            # 表示提取器
│   ├── downloadModel.py        # 模型下载
│   └── weights/                # 模型权重(git 忽略)
│
├── database/                   # 数据集模块
│   ├── corpus.py               # 语料加载器
│   ├── download_data.py        # 数据集下载
│   └── corpus/                 # 数据文件(git 忽略)
│
├── experiments/                # 实验脚本与报告
│   ├── run_direction9_experiments.py  # 实验运行器
│   ├── cross_model_convergence.py     # E1/E2: 跨模型谱收敛
│   ├── emergence_detection.py         # E3: 能力涌现检测
│   ├── alignment_spectrum.py          # E4: 对齐机制
│   ├── text_difficulty_proxy.py       # E5: 难度代理
│   ├── output/                 # 实验结果(JSON + 图表)
│   └── *.md                    # 实验报告
│
├── paper/                      # 相关论文索引
│   └── README.md
│
├── requirements.txt
└── README.md

核心指标

指标 公式 物理含义
r_eff $\exp(-\sum p_i \log p_i)$ 表示的"有效维度数"
RS_cross $\text{Var}M[r{\text{eff}}^{(M)}]$ 跨模型共识度(越低越收敛)
SPD $W_1(p_i, p_j)$ 谱 Platonic 距离(模型间差异)
STG $ r{\text{eff}}^{\text{instr}} - r{\text{eff}}^{\text{gen}}

收敛判断:

  • RS_cross < 1.0: 高度收敛
  • RS_cross > 5.0: 严重发散

快速开始

1. 安装依赖

cd /root/effectiveRank
pip install -r requirements.txt

2. 下载模型(从魔搭平台)

# Qwen2.5-7B 对
modelscope download --model Qwen/Qwen2.5-7B-Instruct --local_dir model/weights/Qwen2.5-7B-Instruct

# Mistral-7B 对
modelscope download --model AI-ModelScope/Mistral-7B-Instruct-v0.3 --local_dir model/weights/Mistral-7B-Instruct-v0.3

3. 运行实验

# 方向 9 完整实验
python experiments/run_direction9_experiments.py --all

# 单个实验
python experiments/run_direction9_experiments.py --e1   # 基础谱收敛
python experiments/run_direction9_experiments.py --e4   # 对齐机制

实验结果详情

E1: 基础谱收敛验证

数据集 RS_cross r_eff 范围 状态
humaneval 0.16 [2.46, 3.51] ✅ 高度收敛
flores200 1.28 [4.03, 7.01] ⚠️ 中度收敛
gsm8k 2.62 [4.31, 8.82] ⚠️ 中度发散
math 9.46 [3.98, 12.22] ❌ 发散
alpaca 11.21 [7.40, 16.79] ❌ 严重发散

结论: 谱收敛是领域特异的——形式化任务(代码)收敛好,开放任务(指令)分歧大。

E4: 对齐即谱工程(跨模型验证)

模型对 指令域 r_eff 变化 STG 提升 方向一致性
Qwen2.5-7B 3.01 → 12.14 (+303%) 0.36 → 8.11 (22.5x)
Mistral-7B 16.79 → 27.69 (+65%) 10.76 → 21.16 (2.0x)

核心发现:

  • 谱压缩假设被证伪: Instruct 版 r_eff 不降反升
  • 谱展开理论: 对齐使模型在指令域使用更多维度编码语义
  • 域分化效应: Instruct 版学会区分指令域和通用域

API 使用

计算有效秩

from model.spectrum import compute_gram_spectrum
import torch

H = torch.randn(4096, 1000)  # 表示矩阵 d×N
r_eff, eigenvalues = compute_gram_spectrum(H, return_eigvals=True)
print(f"有效秩:{r_eff}")

跨模型谱分析

from experiments.cross_model_convergence import CrossModelAnalyzer

analyzer = CrossModelAnalyzer(
    models=["llama3-8b", "mistral-7b", "qwen-7b"],
    datasets=["gsm8k", "alpaca"]
)

result = analyzer.compute_rs_cross("gsm8k")
print(f"RS_cross: {result['rs_cross']}")

输出文件

experiments/output/
├── cross_model/          # E1/E2 结果
│   ├── e1_result.json
│   └── e2_result.json
├── emergence/            # E3 结果
│   └── emergence_results.json
├── e4_qwen/              # E4 Qwen 对
│   ├── e4_result.json
│   └── e4_report.md
├── e4_mistral/           # E4 Mistral 对
│   ├── e4_result.json
│   └── e4_report.md
├── e5/                   # E5 结果
│   └── e5_summary.json
└── figures/              # 可视化图表
    ├── r_eff_comparison.png
    ├── rs_cross_heatmap.png
    └── emergence_curves.png

实验报告

报告 文件
E1 experiments/方向 9_E1 实验报告_20260314.md
E2 experiments/方向 9_E2 实验报告_跨域谱分层验证.md
E3 experiments/方向 9_E3 实验报告_20260314.md
E4 experiments/方向 9_E4 实验报告_对齐即谱工程.md
E5 experiments/方向 9_E5 实验报告_RS_cross 作为文本难度代理.md
总结 experiments/方向 9_五实验总结报告.md

依赖

torch>=2.0.0
transformers>=4.40.0
accelerate>=0.20.0
datasets>=2.14.0
scipy>=1.10.0
ruptures>=1.1.0
matplotlib>=3.7.0
seaborn>=0.12.0

参考文献

  1. Huh et al. The Platonic Representation Hypothesis. ICML 2024.
  2. Wei et al. Emergent Abilities of Large Language Models. TMLR 2022.
  3. Roy & Vetterli. The effective rank: A measure of effective dimensionality. EUSIPCO 2007.
  4. Raghu et al. SVCCA: Singular Vector Canonical Correlation Analysis. NeurIPS 2017.

最后更新: 2026-03-22 实验状态: E1-E5 全部完成 ✅