Licensed under the Apache License, Version 2.0
AG-TUNE (Aesthetic Gradient Tuning Engine) is a neuro-symbolic poetry generator that blends classical algorithmic reasoning with modern generative heuristics. It produces verses that follow emotional arcs, metrical rhythm, syntactic correctness, and aesthetic reward functions, rather than relying on large transformer-based text models.
Where traditional poetry generators imitate language statistically, AG-TUNE constructs poetry from first principles, guided by:
-
Mathematical embeddings
-
Rule-based structure
-
Reinforcement learning
-
Spectral rhythm analysis
-
Multi-objective heuristic search
-
linguistic constraint propagation
This engine doesn't just output text.
It thinks poetically.
Words are projected into an emotional-semantic space using a polynomial kernel.
This allows the model to track emotion trajectories across lines and stanzas.
AG-TUNE transforms candidate lines into stress patterns, applies FFT, and evaluates rhythmic coherence.
This forces lines to exhibit recognizable poetic meter without hardcoding specific forms.
A TD(Ξ») reinforcement learner assigns a value score to each line based on:
-
Emotional continuity
-
Surprise
-
Meter quality
-
Cohesion
-
Novelty
Poetry becomes a policy, not a guess.
Grammar rules, rhyming constraints, and thematic restrictions are encoded through a Rete-based forward chaining engine.
This ensures internal consistency without brute forcing.
Every candidate line must be syntactically valid according to a CFG.
Invalid structures are filtered immediately.
Token generation uses a custom beam search that weighs:
-
Emotional alignment
-
Meter score
-
Aesthetic reward
-
Rule satisfaction
-
Grammar validity
-
Novelty via cycle detection
It is essentially a cooperative committee of algorithms, all trying to agree on the next word.
Floydβs Tortoise-and-Hare algorithm prevents repetitive loops or stagnation.
A modern UI displays:
-
Emotional trajectory graphs
-
Beam search exploration trees
-
Rhythm spectral output
-
Rule activations
-
Aesthetic value gradients
The poet becomes something you can watch think.
+-----------------------------+
| Emotion Embedding (Kernel PCA)
+-----------------------------+
β
+-----------------------------+
| Rhythm Analyzer (FFT)
+-----------------------------+
β
+-----------------------------+
| Constraint Engine (Rete)
+-----------------------------+
β
+-----------------------------+
| Syntax Filter (CYK Parser)
+-----------------------------+
β
+-----------------------------+
| Aesthetic Value Model (TD(Ξ»))
+-----------------------------+
β
+-----------------------------+
| Multi-Objective Beam Search
+-----------------------------+
β
+-----------------------------+
| React Visualization Layer
+-----------------------------+
AG-TUNE is not one algorithm.
It is a coalition of reasoning systems negotiating the next word.
npm install
npm run dev
AG-TUNE is fully client-side and requires no server runtime.
AG-TUNE includes a comprehensive two-phase training system that learns from English pre-training data and lyrics:
# Train with English pre-training + lyrics fine-tuning
npm run train
# Verify the model retains information indefinitely
npm run verify
# Test core algorithms
npm run test-engine
# Validation Framework (comprehensive behavioral tests)
npm run test-modules # Module-level invariants
npm run test-invariants # System-level guarantees
npm run test-ablation # Component causality
npm run test-interpretability # Reasoning trace validation
npm run test-all # Run all validation testsSee VALIDATION.md and VALIDATION_GUIDE.md for comprehensive testing documentation.
The training process:
- Phase 1: Pre-training on 373 lines of English text (1,122 unique words)
- Builds foundational language comprehension
- Learns common vocabulary and grammatical patterns
- Phase 2: Fine-tuning on 847+ lines of lyrics (expanding to 2,329 unique words)
- Preserves English foundation while adding lyric-specific knowledge
- Builds co-occurrence word embeddings
- Trains Kernel PCA for emotional space mapping
- Optimizes TD-lambda value estimator (100 epochs)
- Saves checkpoint for indefinite reuse
The model retains all learned information and can be loaded anytime.
See TRAINING.md for training documentation and PRETRAINING.md for details on the pre-training system.
AG-TUNE includes a comprehensive validation framework that proves it's not a conventional ML model, but a composite reasoning system with verifiable guarantees.
Module-Level Invariants (15 tests)
- β Kernel PCA: Reconstruction sanity, trajectory smoothness, kernel sensitivity
- β FFT Analyzer: Metrical pattern detection, rhythm discrimination
- β CYK Parser: Grammar enforcement, mutation testing
- β Floyd Cycle Detector: Determinism, no false positives
- β TD(Ξ») Learner: Learning curve monotonicity, reward ablation
- β Rete Engine: Constraint satisfaction, conflict detection
System-Level Guarantees (10 tests)
- β No ungrammatical output
- β No infinite loops (cycle detection <1%)
- β Emotional continuity maintained
- β Meter consistency within stanzas
- β Novelty retention (n-gram overlap controlled)
Component Causality (Ablation Study)
- β All 7 components proven causal, not ornamental
- β Disabling ANY component causes measurable degradation
- β FFT removal β rhythm collapse
- β Rete removal β theme inconsistency
- β TD(Ξ») removal β aesthetic flatness
- β And more...
Interpretability ("You Can Watch It Think")
- β Every line explainable via reasoning trace
- β Reward attribution decomposition
- β Beam search candidate visualization
- β Time-aligned decision logging
- β JSON export for offline analysis
npm run test-modules # Module behavioral invariants
npm run test-invariants # System-level guarantees
npm run test-ablation # Component causality proofs
npm run test-interpretability # Reasoning trace validation
npm run test-all # Complete validation suiteAll tests pass at 100% - proving AG-TUNE maintains its guarantees.
See VALIDATION.md for the full validation framework documentation and VALIDATION_GUIDE.md for usage instructions and debugging help.
Key parameters include:
-
kernelDegree: degree of the polynomial kernel for emotional PCA -
beamWidth: number of candidate lines -
fftThreshold: sensitivity of rhythm detection -
lambda: eligibility trace decay for aesthetic learning -
constraintProfile: rule set passed to the Rete engine
Modify these in config.js to evolve the poet's personality.
AG-TUNE explores the question:
What if poetry were a computational process rather than a statistical artifact?
Instead of training on massive corpora, AG-TUNE reimagines poetry as:
-
An emotional manifold
-
A rhythmic signal
-
A logical structure
-
A reward-driven path
-
A symbolic negotiation
This model does not imitate poets.
It behaves like one.
AG-TUNE draws influence from:
-
Neural symbolic reasoning
-
Reinforcement learning with eligibility traces
-
Constraint programming
-
Formal grammar theory
-
Spectral audio analysis
-
Multi-objective optimization
If you build on this work, please cite the repository.
Contributing
Contributions are welcome, especially in the areas of:
-
New constraint rules
-
Alternative rhythm detectors
-
Additional emotional embedding models
-
Visualization components
-
Aesthetic reward shaping
Apache-2.0