Manuscript Offprint

arXiv:2611.08294

ManimCode: Learning Visual Self-Correction for Educational Animation

Zhengyang Liang, Lizi Liao

Open access. PaperVantage converted this article to text, so layout and figures may differ from the original.

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.

Date: October 31, 2026

Email: zhengyang.l.2025@phdcs.smu.edu.sg

Homepage: https://liang-zhengyang.github.io/manimcode

SMU Research

1 Introduction

Educational animations help explain abstract STEM concepts by showing mathematical relationships, geometric constructions, and processes that unfold over time. Creating these animations by hand, however, requires both subject knowledge and programming expertise. Recent work uses language models to write programs for animation engines such as Manim, which render them into videos (Chen et al., 2025b; Ku et al., 2025). This approach offers precise control over formulas, text, and geometry, which are difficult to maintain with pixel-space video generation. A successful render can still produce a poor teaching video: labels may overlap, objects may fall outside the frame, or explanations may omit important steps. These defects are difficult to fix because the video does not directly identify the required code changes. Producing a usable animation therefore requires inspecting the output and revising the program based on the defects.

Agentic systems such as Code2Video (Chen et al., 2025b), TheoremExplainAgent (Ku et al., 2025), and ManimAgent (Jiang et al., 2026) use execution errors and, in some cases, visual feedback to revise generated programs. These systems typically rely on large models, often proprietary, and their refinement loops become much less reliable with smaller open alternatives. Specialized training is also limited by the available data. ManimBench (Rammuni Silva et al., 2026a) contains render-verified programs but is relatively small, while community datasets and JanusCode-800K (Sun et al., 2026) lack systematic rendering and quality checks. Of the 20,976 Hugging Face community programs we collected, roughly one-third fail to render as released. Even among the renderable Hugging Face programs, only 31% pass our quality criterion after revision. These datasets retain final programs but discard the errors, feedback, and edits that led to them. ManimTrainer (Rammuni Silva et al., 2026b) uses reference-based rewards during training and execution feedback at inference, but does not directly supervise models to interpret and correct visual defects. Existing data therefore offers little guidance on how a model should review and revise its own animations.

To make feedback-driven refinement learnable by small open models, we build ManimData through a render-guided pipeline that records how animation programs are corrected and improved. We collect Manim programs from public datasets and generate additional requests from Wikipedia STEM topics. A strong open multimodal model then writes or revises each program, executes it, and reviews the rendered frames. Execution errors, layout checks, and visual critiques guide subsequent revisions, with relevant API documentation retrieved from a knowledge base covering Manim and eight domain plugins. The pipeline keeps the best version and admits a record only when it meets the quality criterion. The resulting 24,034 render-verified, quality-filtered records contain the final program and video, intermediate versions, errors, rendered frames, reviews, and revisions, preserving the feedback and corrective actions missing from existing Manim corpora.

We use ManimData to train ManimCode, enabling a single 4B model to write, review, and revise animation programs. We first organize the recorded trajectories into role-conditioned supervised fine-tuning (SFT) tasks. The Writer generates programs from requests and retrieved API documentation, the Reviewer assesses rendered frames and identifies visual defects, and the Reviser corrects execution failures and improves programs based on visual critiques. Training on final programs and intermediate correction steps improves initial generation and feedback-driven revision. Because the trajectories come from a stronger model, they may not fully capture errors encountered by the smaller model. We address this gap by training the Reviser with reinforcement learning (RL) on self-generated repair and critique states, using rendering outcomes and reference-free quality feedback as rewards. At inference, a single 4B model runs the complete render-review-revise loop without the larger model.

We evaluate ManimCode on two scene-level animation benchmarks and integrate it as the scene generator in two long-form systems, Code2Video and TheoremExplainAgent. It achieves 96.6% and 97.0% render success on ManimData-test and ManimBench, compared with 52.6% and 82.0% for the untrained 4B backbone under the same inference setup. With the planning and rendering budgets held constant, completed videos increase from 19/117 to 107/117 and from 53/239 to 239/239, respectively, alongside improvements in learning-gain and visual-quality metrics.

Our contributions are:

  • We introduce ManimData, a dataset of 24,034 render-verified, quality-filtered animations. Alongside

SMU Research

final programs, its trajectories preserve execution errors, visual critiques, and corrective revisions, directly supervising models to identify and fix generation failures.

  • We propose ManimCode, a framework that trains a single 4B model to run the complete render-review-revise process. Role-conditioned trajectory SFT teaches it to generate, critique, and correct animation programs; reinforcement learning on self-generated failures improves correction of errors encountered at inference.

  • ManimCode achieves 96.6% and 97.0% render success on two scene-level benchmarks. When integrated into two existing long-form educational video generation systems, it increases video completion.

References (35)