Purpose: Train the model on all lyrics from the lyrics/ folder
What it does:
- Loads 15 lyrics files (847+ lines)
- Builds vocabulary of 1,675+ unique words
- Computes co-occurrence embeddings
- Trains Kernel PCA for 8D emotional space
- Runs 100 epochs of TD-lambda learning
- Saves checkpoint to
agtune-lyrics-checkpoint.json
Output:
Vocabulary size: 1675 words
Training Kernel PCA...
Training TD value estimator for 100 epochs...
Average Reward: 4.8368
✓ Checkpoint saved
Duration: ~20-30 seconds
Purpose: Verify the model retains information indefinitely
What it does:
- Loads the trained checkpoint
- Runs 3 save/load cycles
- Verifies vectors are preserved exactly
- Tests vocabulary completeness (99%+)
- Validates data integrity checksums
Output:
✓ Cycle #1 passed - all data preserved
✓ Cycle #2 passed - all data preserved
✓ Cycle #3 passed - all data preserved
✓ Vocabulary coverage excellent (99.41%)
✓ Vocabulary integrity preserved
Duration: ~5-10 seconds
Purpose: Demonstrate continuous training across multiple sessions
What it does:
- Session 1: Trains on 3 lyrics files
- Saves checkpoint
- Session 2: Loads checkpoint, adds 3 more files
- Saves updated checkpoint
- Session 3: Loads checkpoint, adds 3 more files
- Verifies all original words retained
Output:
Session 1: 135 lines, 523 words
Session 2: 334 lines total, 1009 words
Session 3: 563 lines total, 1346 words
✓ "ghost" retained across 3 sessions
✓ "shadow" retained across 3 sessions
✓ "death" retained across 3 sessions
Duration: ~30-40 seconds
Purpose: Test core algorithm components
What it does:
- Tests Kernel PCA implementation
- Tests Floyd cycle detector
- Tests FFT meter analyzer
- Validates all algorithms work correctly
Output:
✓ Kernel PCA working
✓ Cycle detector working
✓ Meter analyzer working
All core algorithms functional! ✓
Duration: < 1 second
Purpose: Start the web UI development server
What it does:
- Starts Vite dev server
- Opens web interface at http://localhost:5173
- Enables training and poetry generation in browser
Features:
- Upload custom training corpus
- Train model with configurable epochs
- Generate poetry with trained model
- Visualize emotional space and weights
- Save/load checkpoints
Purpose: Build for production deployment
What it does:
- Bundles React app with Vite
- Optimizes for production
- Outputs to
dist/folder
# 1. Train on all lyrics
npm run train
# 2. Verify retention
npm run verify
# 3. Start web UI
npm run dev# 1. Initial training
npm run train
# 2. Test continuous training
npm run continuous
# 3. Verify everything works
npm run verify# 1. Test algorithms
npm run test-engine
# 2. Train model
npm run train
# 3. Start UI
npm run dev- Size: ~1.7 MB
- Contents: Vocabulary, embeddings, emotional space, PCA params, TD weights
- Use: Load in web UI or scripts to use trained model
- Persistence: Retains information indefinitely
temp-checkpoint-*.json: Used by verification script (auto-deleted)continuous-checkpoint.json: Used by continuous demo (auto-deleted)
Problem: Running verify before training
Solution: Run npm run train first
Problem: Corrupted or incorrect JSON
Solution: Delete checkpoint and run npm run train again
Problem: Some lyrics files missing or empty
Solution: Check lyrics/ folder has all .txt files
Problem: Large corpus or slow hardware
Solution: Reduce epochs in train-lyrics.js or use fewer files
| Script | Duration | Memory | CPU |
|---|---|---|---|
| train | 20-30s | ~100MB | High |
| verify | 5-10s | ~50MB | Medium |
| continuous | 30-40s | ~100MB | High |
| test-engine | <1s | ~20MB | Low |
Edit train-lyrics.js to modify:
const epochs = 100; // More epochs = better learning
const alpha = 0.01; // Learning rate
const gamma = 0.95; // Discount factor
const lambda = 0.8; // Eligibility trace decayCreate a custom script:
import { AGTuneEngine } from './train-lyrics.js';
const engine = new AGTuneEngine();
const customLyrics = ['verse 1', 'verse 2', ...];
engine.train(customLyrics, 50);
engine.saveCheckpoint('custom-checkpoint.json');Modify the training loop to log more frequently:
for (let epoch = 0; epoch < epochs; epoch++) {
const reward = engine.train(corpus, 1);
console.log(`Epoch ${epoch}: ${reward.toFixed(4)}`);
}- Run
npm run trainto create checkpoint - Start
npm run dev - Click "Load Checkpoint" button
- Upload
agtune-lyrics-checkpoint.json - Model is now trained and ready to generate
- In web UI, click "Upload Training Corpus"
- Select a .txt file with lyrics (one line per verse)
- Click "Train Model"
- Wait for training to complete
- Generate poetry with your custom style
Module not found errors:
- Ensure you're in the project root directory
- Run
npm installfirst
Permission denied errors:
- Make scripts executable:
chmod +x *.js - Or run with
nodeexplicitly:node train-lyrics.js
Out of memory errors:
- Reduce corpus size
- Lower number of epochs
- Close other applications
Missing words in vocabulary:
- Some words filtered as too short (<10 chars per line)
- Title lines ("icryafterikill") are intentionally filtered
- This is normal and expected
Checkpoint file corrupted:
- Delete and re-run training
- Check disk space
- Ensure write permissions
- Always verify after training: Run
npm run verifyto ensure quality - Save checkpoints frequently: During long training sessions
- Test incrementally: Use
npm run test-enginebefore full training - Monitor resources: Close unnecessary apps during training
- Backup checkpoints: Copy important checkpoints to safe location
- TRAINING.md - Comprehensive training documentation
- README.md - Project overview and setup
- DEMO_SCRIPT.md - Live demonstration guide
All scripts are production-ready and tested for correctness. ✓