tianxuan / scripts /compare-checkpoints.js
masterofthestars's picture
Tianxuan: full project + data (checkpoints, world_model, data without raw) with correct directory structure
db7bc06
Raw History Blame Contribute Delete
3.71 kB
#!/usr/bin/env node
/**
* 天玄 TianXuan - 对比实验脚本
* 对比不同检查点的在线学习效果
*/
const fs = require('fs');
const path = require('path');
const { execSync } = require('child_process');
console.log('='.repeat(70));
console.log('天玄 TianXuan - 对比实验');
console.log('='.repeat(70));
console.log('');
const checkpoints = [
{ name: '旧检查点 (无STDP/STDA)', path: 'checkpoints' },
{ name: '新检查点 v2 (有STDP/STDA, 51步)', path: 'data/checkpoints_v2' },
{ name: '当前检查点 v3', path: 'data/checkpoints_v3' },
{ name: '最新检查点 v4', path: 'data/checkpoints_v4' },
];
const prompts = ['小明', '老王', '阿芳'];
console.log('【检查点信息】\n');
for (const ckpt of checkpoints) {
const metaPath = path.join(ckpt.path, 'meta.json');
if (fs.existsSync(metaPath)) {
const meta = JSON.parse(fs.readFileSync(metaPath, 'utf8'));
console.log(` ${ckpt.name}`);
console.log(` 路径: ${ckpt.path}`);
console.log(` 训练步数: ${meta.t} 步`);
console.log(` STDP: ${meta.stdp ? '✓' : '✗'}`);
console.log(` STDA: ${meta.stda ? '✓' : '✗'}`);
console.log(` 唯一字符 (平均): 待测试`);
console.log('');
} else {
console.log(` ⚠ ${ckpt.name} - 检查点不存在`);
console.log('');
}
}
console.log('【开始生成测试】\n');
const results = {};
for (const ckpt of checkpoints) {
const metaPath = path.join(ckpt.path, 'meta.json');
if (!fs.existsSync(metaPath)) continue;
console.log(`--- ${ckpt.name} ---`);
results[ckpt.path] = { uniqueChars: [], coherence: [] };
for (const prompt of prompts) {
try {
const cmd = `node sandbox/dist/ml/generate.js --checkpoint ${ckpt.path} --prompt "${prompt}" --len 100`;
const output = execSync(cmd, {
cwd: 'C:\\Users\\l1064\\Desktop\\tianxuan',
encoding: 'utf8',
stdio: ['pipe', 'pipe', 'pipe']
});
const lines = output.split('\n').filter(l => l.trim());
const textLine = lines.find(l => l.startsWith(prompt));
if (textLine) {
const uniqueChars = new Set(textLine.split('')).size;
const coherence = uniqueChars / textLine.length;
results[ckpt.path].uniqueChars.push(uniqueChars);
results[ckpt.path].coherence.push(coherence);
console.log(` "${prompt}" → 唯一字符: ${uniqueChars}, 连贯性: ${coherence.toFixed(3)}`);
}
} catch (e) {
console.error(` 错误: ${e.message.slice(0, 50)}`);
}
}
console.log('');
}
// 对比分析
console.log('='.repeat(70));
console.log('对比分析');
console.log('='.repeat(70));
console.log('');
const avgResults = {};
for (const [path, data] of Object.entries(results)) {
const avgUnique = data.uniqueChars.reduce((a, b) => a + b, 0) / data.uniqueChars.length;
const avgCoherence = data.coherence.reduce((a, b) => a + b, 0) / data.coherence.length;
avgResults[path] = { avgUnique, avgCoherence };
}
// 找出最佳
let bestPath = null;
let bestUnique = 0;
for (const [path, data] of Object.entries(avgResults)) {
if (data.avgUnique > bestUnique) {
bestUnique = data.avgUnique;
bestPath = path;
}
}
console.log('指标对比:');
for (const [path, data] of Object.entries(avgResults)) {
const ckptName = checkpoints.find(c => c.path === path)?.name || path;
const icon = path === bestPath ? '🏆' : ' ';
console.log(` ${icon} ${ckptName}: 唯一字符=${data.avgUnique.toFixed(1)}, 连贯性=${data.avgCoherence.toFixed(3)}`);
}
console.log('');
if (bestPath) {
console.log(`🏆 最佳检查点:${bestPath}`);
}
console.log('');
console.log('='.repeat(70));