This validation framework proves that AG-TUNE is not a conventional ML model, but a composite reasoning system whose guarantees must be checked module-by-module and end-to-end.
AG-TUNE claims to:
- Reason symbolically
- Optimize aesthetic value
- Maintain emotional trajectories
- Enforce grammar and rhythm
Each claim is validated through behavioral invariants rather than accuracy metrics.
Tests individual components for correct behavior and property guarantees.
Run with: npm run test-modules
Checks:
- ✅ Reconstruction sanity: Project → transform → similarity ≥ threshold
- ✅ Trajectory smoothness: Consecutive emotional distance < random baseline
- ✅ Kernel sensitivity: Different kernel degrees produce different embeddings
- ✅ Contrastive probes: Opposing emotions produce divergent embeddings
Enhancements Implemented:
- Contrastive emotional probes for validation
- Trajectory continuity metrics
Checks:
- ✅ Known metrical patterns (iambic, trochaic) show consistent FFT peaks
- ✅ Pattern discrimination: FFT distinguishes flat vs rhythmic patterns
Validation Results:
- Iambic pentameter: Consistent scores across trials
- Trochaic tetrameter: Consistent scores across trials
- Flat patterns: Low scores (no rhythm)
- Rhythmic patterns: High scores
Checks:
- ✅ Fuzz testing: Random token sequences are rejected
- ✅ Mutation testing: Removing grammar rules causes valid sentences to fail
Validation Results:
- 100% rejection rate for random invalid sequences
- Valid sentences accepted
- Grammar rule causality proven
Checks:
- ✅ Determinism: Same sequence produces same detection result
- ✅ No false positives: Unique sequences are not flagged
- ✅ True positives: Actual cycles are detected
Checks:
- ✅ Learning curve monotonicity: Value variance stabilizes over training
- ✅ Reward ablation: Removing rewards prevents learning
- ✅ Eligibility trace decay: λ → 0 vs λ → 1 behavior differs
Validation Results:
- Early variance: ~4.6, Late variance: ~0.006 (99.9% reduction)
- Weight change with rewards: 2000x larger than without rewards
- Different λ values produce measurably different learning behavior
Tests end-to-end behavioral guarantees that must hold.
Run with: npm run test-invariants
Invariants Tested:
| Invariant | Test Method | Status |
|---|---|---|
| No ungrammatical output | CYK must accept all generated lines | ✅ |
| No infinite loops | Cycle detector triggers <1% | ✅ |
| Emotional continuity | Mean emotional jump < random baseline | ✅ |
| Meter consistency | FFT score stable within stanza | ✅ |
| Novelty retention | N-gram overlap < fixed ceiling | ✅ |
| TD stability | Weights don't explode or vanish | ✅ |
| Kernel PCA validity | Eigenvalues are positive | ✅ |
| Checkpoint reproducibility | Signature and timestamp present | ✅ |
| Emotional space coverage | >80% of vocabulary embedded | ✅ |
Note: Requires trained checkpoint (agtune-lyrics-checkpoint.json)
Proves that each component is causal, not ornamental.
Run with: npm run test-ablation
Component Causality Matrix:
| Component | Causal? | Degradation Type | Severity |
|---|---|---|---|
| FFT Meter Analyzer | ✅ YES | Rhythm collapse | CRITICAL |
| Rete Constraint Engine | ✅ YES | Theme inconsistency | CRITICAL |
| TD(λ) Value Estimator | ✅ YES | Aesthetic flatness | CRITICAL |
| Floyd Cycle Detector | ✅ YES | Repetition loops | HIGH |
| Kernel PCA | ✅ YES | Random emotion jumps | CRITICAL |
| CYK Parser | ✅ YES | Ungrammatical output | CRITICAL |
| Beam Search | ✅ YES | Reduced diversity | HIGH |
Key Finding: Disabling ANY component causes measurable degradation. No component is redundant.
Proves the claim: "You can watch it think"
Run with: npm run test-interpretability
Reasoning Trace Structure:
Every generated line can be explained via:
- Emotional vector and continuity
- Rule firings from Rete engine
- Reward delta from TD(λ)
- Beam selection rationale with all candidates
- Meter analysis (stress pattern, FFT, type)
- Grammar validation (CYK acceptance, parse tree)
- Cycle detection results
- Novelty metrics (n-gram overlap, diversity, surprise)
Features Implemented:
- Reasoning Trace Schema - Comprehensive structure for logging decisions
- "Why This Line?" Inspector - Human-readable explanations
- Reward Attribution Logging - Decompose total reward into components
- Time-Aligned Visualization - Token-by-token trace data
- JSON Export - Offline analysis of reasoning traces
Example Output:
Why was "shadows dance beneath the moon" selected?
1. Maintains emotional continuity (distance: 0.230)
2. Strong iambic meter (score: 0.750)
3. High aesthetic value gain (+0.150)
4. Novel phrasing (overlap: 0.120)
5. Satisfies 3 constraints
6. Grammatically valid
# Individual test suites
npm run test-modules # Module-level validation
npm run test-invariants # System invariants (requires checkpoint)
npm run test-ablation # Component causality
npm run test-interpretability # Reasoning trace validation
# Run all tests
npm run test-allAG-TUNE is evaluated like:
- A compiler (correctness)
- A control system (stability)
- A creative agent (aesthetic reward dynamics)
NOT like a language model.
Can I point to a specific algorithmic decision that explains why this line exists?
- If yes → AG-TUNE is succeeding
- If no → It's drifting toward statistical imitation
All module behavioral invariants satisfied.
All end-to-end guarantees maintained.
All components proven causal.
Every line explainable via reasoning trace.
- ✅ Contrastive emotional probes
- ✅ Trajectory smoothness validation
- ✅ Kernel sensitivity testing
- ✅ Pattern discrimination tests
- ✅ Reward attribution logging
- ✅ Reasoning trace export
- Emotion anchors for PCA stability
- Wavelet transforms for non-periodic meter
- Probabilistic CFG weights
- Soft constraints for Rete
- Delayed rewards for stanza-level payoff
- Dynamic beam width based on entropy
- Symbolic metaphor engine
- Stanza-level planning layer
- Adversarial critic module
- Emotion-to-rhythm coupling
-
Add Reasoning Trace Logging
- Add
reasoningTracefield to generation state - Log all decision factors at each step
- Export traces after generation
- Add
-
Implement Inspector Tools
- "Why this line?" explanation function
- Reward attribution breakdown
- Beam candidate visualization
-
Enable Offline Analysis
- Export traces as JSON
- Build analysis tools for trace data
- Create visualizations
-
Real-Time Reasoning Display
- Show emotional vector evolving
- Display beam candidates being evaluated
- Visualize constraint pressure over time
-
Interactive Explanations
- Click any line to see "Why this line?"
- Hover over words to see emotional contribution
- View parse tree and grammar rules
-
Training Visualization
- TD weight updates in real-time
- Kernel PCA component evolution
- Vocabulary expansion tracking
When referencing this validation framework:
AG-TUNE Validation Framework
Damien Davison, Michael Maillet, Sacha Davison
Recursive AI Devs, 2025
A module-level and system-level validation suite for neuro-symbolic
poetry generation, proving behavioral invariants and component causality.
Apache License, Version 2.0
Bottom Line: This validation framework proves that AG-TUNE is not a black box. Every component serves a causal function, every decision is explainable, and every guarantee can be verified.