ManimCode: Learning Visual Self-Correction for Educational Animation
Organizations: Singapore Management University
Abstract
Manim supports precise, programmatic video generation, but a successfully rendered educational animation can still have visual defects, missing explanations, or incorrect content. Rendering does not directly identify the code changes needed to correct these visual failures, so feedback-driven revision is needed. Existing agentic frameworks use iterative rendering and revision but typically rely on large models, often proprietary. Existing Manim datasets primarily contain final programs and often lack quality verification and the trajectories of feedback and revisions needed to learn this refinement process. We introduce ManimData and ManimCode, a data and training framework for feedback-driven educational animation generation. We construct ManimData through a render-guided pipeline that iteratively generates, executes, reviews, and revises Manim programs with retrieved API documentation. Its 24,034 render-verified, quality-filtered records preserve intermediate programs, execution errors, visual critiques, and corrective revisions. We use role-conditioned supervised fine-tuning on these trajectories to train ManimCode, a single 4B model, to write, review, and revise animation programs. To improve correction of errors that differ from those in the collected trajectories, we then train the Reviser with reinforcement learning on self-generated states, using rendering outcomes and reference-free quality feedback. ManimCode achieves 96.6% and 97.0% render success on ManimData-test and ManimBench, compared with 52.6% and 82.0% for the untrained 4B model under the same inference setup, while also improving video quality scores from 2.48 to 2.94 and from 3.00 to 3.44. Integrating ManimCode into two long-form educational video generation systems increases completed videos from 19/117 to 107/117 and from 53/239 to 239/239, alongside improvements in educational effectiveness and visual quality.
Figures & tables
| Dataset | Size | Purpose | Target Video | Render | Quality | Revision |
| Verified | Filtered | Trajectories | ||||
| ManimBench ( Rammuni Silva et al., 2026a ) | 416 | Train/Eval | Scene-level Animation | ✓ | ✗ | ✗ |
| JanusCode-800K (Manim) ( Sun et al., 2026 ) | 8,316 | Train | Scene-level Animation | ✗ | ✗ | ✗ |
| HF Community (7 datasets) | 20,976 | Train | Scene-level Animation | ✗ | ✗ | ✗ |
| MMMC (Code2Video) ( Chen et al., 2025b ) | 117 | Eval | Long-form Explanation | n/a | n/a | ✗ |
| TheoremExplainBench ( Ku et al., 2025 ) | 239 | Eval | Long-form Explanation | n/a | n/a | ✗ |
| ManimData-test | ManimBench | |||||
| Model | Size | RS | VQ | RS | VS | VQ |
| Large general-purpose models | ||||||
| GPT-4o | – | 60.2 | 2.87 | 79.0 | 71.0 | 3.34 |
| GLM-5.3 Flash | MoE | 57.2 | 3.18 | 83.0 | 73.7 | 3.51 |
| DeepSeek-V4 Flash | MoE | 62.4 | 3.05 | 81.0 | 72.9 | 3.33 |
| Small general-purpose models | ||||||
| Metric (higher is better) | Native | + Ours |
|---|---|---|
| Code2Video on MMMC | ||
| Videos completed | 19/117 | 107/117 |
| TeachQuiz gain ( 100) | 2.6 | 27.2 |
| Aesthetics (0–100) | 35.5 | 58.7 |
| TheoremExplainAgent on TEB | ||
| Videos completed | 53/239 | 239/239 |
Appendix figures & tables7 assets
Supplementary material from the paper’s appendix.
Appendix
| Setting | Value |
|---|---|
| Renderer | ManimCE v0.19.1 with eight domain plugins, 480p |
| Budget | 10 renders per input |
| Writer | Qwen3.8-27B; writes the full program from retrieved cards and feedback |
| Retrieval | 2–4 queries per step; Qwen3-Embedding-8B search, Qwen3-Reranker-8B reranking; top 10 cards |
| Layout checks | Objects outside the frame, overlapping text, labels too small to read, at animation pause points |
| Reviewer | Qwen3.8-27B; request, code, and 8 uniformly sampled frames; four dimensions scored 1–5 |
| Supervision | Input context | Target output | Examples |
|---|---|---|---|
| Writing | Request; retrieved API cards | Final program selected during construction | 24,034 |
| Execution repair | Request; failed code; execution error; API cards | Renderable repaired program | 14,587 |
| Quality revision | Request; code; scores and critique; layout diagnostics; API cards | Higher-rated revised program | 32,683 |
| Reviewing | Request; code; sampled video frames | Scores on the four review dimensions and a critique | 46,965 |
| Retrieval queries | Request; error or critique when present | Two to four API search queries | 187,183 |
| Total | 305,452 |
| Supervised fine-tuning | Revision RL | ||
|---|---|---|---|
| Base model | Qwen3.5-4B | Initialization | supervised model |
| LoRA | rank 32, , dropout 0.05 | LoRA | rank 32, |
| Target modules | all linear layers | Advantage | leave-one-out (RLOO) |
| Learning rate | , cosine | Learning rate | |
| Warm-up | 10 steps | Batch | 16 states samples |
| Batch size | 16 sequences | Policy updates | 2 per step (8 states each) |
| Gemini VQ gap | Pairs | Gemini’s higher | About the same | Gemini’s lower | Agreement (%) |
| 0 (equal scores) | 14 | – | 6 | – | – |
| 19 | 4 | 5 | 10 | 29 [7, 50] | |
| 26 | 15 | 5 | 6 | 71 [52, 90] | |
| 31 | 22 | 3 | 6 | 79 [61, 93] | |
| 8 | 5 | 2 | 1 | 83 [50, 100] | |
| All | 98 | 46 | 21 | 23 | 67 [55, 78] |
| Opponent | Benchmark | Pairs | Human W / T / L | Human win rate | Gemini W / T / L |
|---|---|---|---|---|---|
| GPT-4o | ManimData-test | 31 | 18 / 4 / 9 | 0.65 [0.48, 0.81] | 17 / 7 / 7 |
| GPT-4o | ManimBench | 17 | 7 / 7 / 3 | 0.62 [0.44, 0.79] | 9 / 3 / 5 |
| Qwen3.8-27B | ManimData-test | 36 | 11 / 2 / 23 | 0.33 [0.19, 0.49] | 14 / 3 / 19 |
| Qwen3.8-27B | ManimBench | 14 | 5 / 8 / 1 | 0.64 [0.50, 0.79] | 6 / 1 / 7 |
Video Generation
Video generation studies models that create and edit moving images from text, images, audio, and structured controls.
See all 376 papers