File size: 3,712 Bytes
db7bc06
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
#!/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));