ManimCode

ManimCodeLearning Visual Self-Correction for Educational Animation

Zhengyang Liang  ·  Lizi Liao

Singapore Management University

Paper (PDF) Code coming soon ManimData coming soon BibTeX

A video can render and still fail as teaching: a title covers a table, a label runs off the frame, a sum is wrong. ManimCode trains one small open model to see these defects in its own rendered frames and fix the program. Below is one such step, run by the 4B model alone.

Layout repaired CS algorithms

Request Display a table of transition rules for a simple machine, then highlight the row corresponding to the current state and scanned symbol, showing the next state and action.

Beforeversion 5

Reviewer 3.25 · Gemini 3.25

Feedback → edit

Reviewer critique (4B)

“The main title 'Transition Rules' overlaps with the top row of the table, making both the title and the 'Rule' column header partially illegible.”

Reviser edit (4B)

- table.scale(0.75).to_edge(UP, buff=0.5)
+ table.scale(0.75).to_edge(UP, buff=1.0)
- ….next_to(row_highlight, DOWN, buff=0.2)
+ current_label.next_to(table, DOWN, buff=0.5)
Afterversion 6

Reviewer 4.75 · Gemini 3.88 (+0.63)
kept as the final video

Render success
ManimData-test
96.6%52.6% for the untrained 4B model under the same inference setup
Render success
ManimBench
97.0%82.0% for the untrained 4B model under the same inference setup
Videos completed
Code2Video on MMMC
107/11719/117 when the untrained 4B model generates the scenes
Videos completed
TheoremExplainAgent on TEB
239/23953/239 when the untrained 4B model generates the scenes

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.

What a revision looks like

These steps come from our system's run on ManimData-test, with the 4B model in every role. The renderer reports crashes, our Reviewer critiques rendered frames, and the Reviser edits the program. Under each video are the Reviewer's own mean score and the score from Gemini 3.8 Flash, a judge that plays no part in the loop (both 1–5). Dashed boxes mark the defect and the repaired region.

We drew candidates automatically by edit type and kept steps whose defect shows in a sampled frame. They illustrate how the loop behaves, including when it fails. The rates are in the results.

Crash repaired Graph theory

Request Draw a graph with five vertices labeled A through E and connect them with directed edges. Next to the graph, display a vertical list of these vertices, each followed by an empty bracket placeholder.

Beforeversion 1

No video: the program crashes.

Feedback → edit

Renderer error

“NameError: name 'Braces' is not defined (line 33).”

Reviser edit (4B)

- bracket = Braces(label, color=YELLOW, …)
+ bracket = Brace(label, color=YELLOW, …)
Afterversion 2

Reviewer 4.00 · Gemini 3.62
renders

Layout repaired Number theory

Request Display the equation 2^x ≡ 3 (mod 13). Transform it step-by-step to show the calculation of the discrete log base 2 of 3, emphasizing the result x=4 and the modulo reduction of 16 to 3.

Beforeversion 3
overlap

Reviewer 3.75 · Gemini 3.38

Feedback → edit

Reviewer critique (4B)

“The final conclusion text overlaps with the 'x = 4' result, making both partially illegible.”

Reviser edit (4B)

- result.next_to(eq1, DOWN, buff=0.6)
- result.shift(RIGHT * 2.8)
+ result.next_to(powers, DOWN, buff=0.5)
Afterversion 4

Reviewer 4.75 · Gemini 3.88 (+0.50)

Content corrected CS algorithms

Request Display a weighted graph with five nodes, animate the selection of a maximum weight clique by sequentially highlighting the highest-weight connected subset, and show the sum of their weights.

Beforeversion 5
wrong sum

Reviewer 3.00 · Gemini 3.00

Feedback → edit

Reviewer critique (4B)

“The sum label is mathematically incorrect. The code calculates the sum of the clique {B, C, D} as 3+4+2=9, but the final explanation text claims the sum is 11.”

Reviser edit (4B)

- Text("… {B, C, D} with sum 11", …)
+ Text("… {B, C, D} with sum 9", …)
Afterversion 6

Reviewer 4.00 · Gemini 3.00 (+0.00)
kept as the final video

The sum is fixed, but the judge scores both versions 3.00. Among the steps in the paper's figures, this is the only one where the judge's score does not move with the Reviewer's.

Regression, not kept CS algorithms

Request Display a sample rule 'Bread => Butter' with a progress bar filling to 80% confidence, then highlight the transaction set where both items co-occur to demonstrate the rule's strength.

Beforeversion 8
cut off

Reviewer 3.50 · Gemini 3.00

Feedback → edit

Reviewer critique (4B)

“The transaction grid is positioned too low, causing the bottom-most box ('Cheese Bread') to be clipped by the bottom edge of the frame.”

Reviser edit (4B)

- grid.move_to(DOWN * 2.5)
+ grid.move_to(DOWN * 1.5)
Afterversion 9
new overlap

Reviewer 2.00 · Gemini 2.58 (−0.42)
scored lower; the previous version is kept

Revisions can fail. Moving the list back up restores an overlap with the progress bar. The Reviewer scores this version lower, so the loop keeps version 8, even though its list is still cut off. Keeping the best candidate stops a regression from replacing a better version, but it cannot repair a defect the Reviser leaves behind.

Final videos

Six final videos from the same run, picked by hand to cover different subjects. Each scored 3.75 on the 1–5 video quality scale; the mean over all rendered ManimData-test videos is 2.94.

ManimData

ManimData pairs each request with a render-verified program, its video, and the trajectory of errors, critiques, and revisions that produced the program. Inputs come from two sources: requests derived from Wikipedia STEM topics, and public community programs from seven Hugging Face datasets, JanusCode-800K, and the ManimBench training split.

Every input enters the same render–review–revise loop. Qwen3.8-27B writes or revises the program with up to 10 renders per input, looking up APIs in a knowledge base of 2,219 cards that covers ManimCE v0.19.1 and eight domain plugins. A layout checker reports objects outside the frame, overlapping text, and labels too small to read, and the Reviewer scores eight sampled frames on request alignment, content completeness, visual clarity, and animation quality. An input is admitted only if its best version reaches a mean score of at least 3.75.

ManimData construction pipeline in three panels: request collection, render-guided generation, and curation.
ManimData construction: request collection, render-guided generation, and curation. Open the image for full resolution.
Construction by source
SourceInputsFinal records
Wikipedia22,05815,537
HF Community13,7684,284
JanusCode-800K6,3653,944
ManimBench train316269
Total42,50724,034

Mathematics, physics, and computer science account for 72% of the records. The median program has 88 lines and produces a 16.7-second video. The trajectories yield 305,452 role-conditioned training examples.

Domain shares of the 24,034 records, and distributions of program length, video length, and number of renders.
Domain shares of the records and per-record distributions of final program length, video length, and number of renders.

Compared with existing Manim data

DatasetSizePurposeTarget videoRender verifiedQuality filteredRevision trajectories
ManimBench416Train/EvalScene-level animation✓ yes✗ no✗ no
JanusCode-800K (Manim)8,316TrainScene-level animation✗ no✗ no✗ no
HF Community (7 datasets)20,976TrainScene-level animation✗ no✗ no✗ no
MMMC (Code2Video)117EvalLong-form explanationn/an/a✗ no
TheoremExplainBench239EvalLong-form explanationn/an/a✗ no
ManimData (ours)24,034TrainScene-level animation✓ yes✓ yes✓ yes

n/a marks a property that does not apply to the evaluation-only long-form benchmarks.

Method

ManimCode overview in three panels: trajectory supervision, revision reinforcement learning on self-generated states, and inference with the render, review, revise loop.
Overview of ManimCode. The two states in the middle panel are real training states; their revisions and scores are illustrative. Qwen3.8-27B is used only to build the data and to compute training rewards. Open the image for full resolution.

Role-conditioned trajectory supervision

Each trajectory supervises the writing, reviewing, and revision steps of one Qwen3.5-4B model, conditioned on its role. The Writer targets the record's final program, so it learns from the refinements made during construction. The Reviewer targets the recorded scores and critique. The Reviser targets complete revised programs from two kinds of successful transitions: execution repairs that turn a crash into a render, and quality revisions that raise the mean review score. We also supervise the retrieval queries so the model can look up API cards at inference.

Supervision extracted from ManimData
TaskTargetExamples
WritingFinal program24,034
Execution repairProgram that renders14,587
Quality revisionHigher-rated program32,683
ReviewingFour scores and a critique46,965
Retrieval queriesTwo to four API searches187,183
Total305,452

Revision RL on self-generated states

A stronger model collected the trajectories, so they may not capture the mistakes of the 4B model. We therefore let the supervised model write and review its own drafts on requests disjoint from the evaluation sets. Each crash becomes a repair state and each unsatisfactory review a critique state. The Reviser samples eight candidate revisions per state, and we render them all.

On a repair state, a candidate that fails to render earns zero, and one that renders earns a reward from Qwen3.8-27B's request alignment and content completeness scores. On a critique state, a successful candidate is compared with the input program in both presentation orders: it earns +1 if it wins both, −1 if it loses both, and 0 otherwise, while a candidate that fails to render earns −1. Near-duplicates earn zero. No reference program or target video is needed. We optimize with leave-one-out policy optimization (RLOO), using a clipped policy-gradient objective and a KL penalty toward the supervised policy.

Inference

A single 4B model runs the same render–review–revise loop used during data construction, without the larger model. Each request starts from a newly generated program, and the loop retains the best successfully rendered candidate within the budget.

Results

Scene-level generation

With a 4B generator, ManimCode reaches 96.6% and 97.0% render success on ManimData-test and ManimBench, ahead of the evaluated general-purpose models (at most 62.4% and 83.0%) and released Manim-specialized systems (at most 67.0% and 73.0%). Its video quality is comparable to GPT-4o and approaches recent mixture-of-experts models, particularly on ManimBench. The 4B rows separate the components: the loop alone lifts render success with only modest changes in video quality, trajectory SFT improves both, and Reviser RL mainly adds render success (8.0 and 5.0 points).

ModelSizeManimData-testManimBench
RS ↑VQ ↑RS ↑VS ↑VQ ↑
Large general-purpose models
GPT-4o–60.22.8779.071.03.34
GLM-5.3 FlashMoE57.23.1883.073.73.51
DeepSeek-V4 FlashMoE62.43.0581.072.93.33
Small general-purpose models
Qwen3.5-4B4B7.02.3431.027.63.01
Qwen3.5-9B9B15.42.6046.040.43.24
Qwen3.8-27B27B39.83.0959.052.63.37
Manim-specialized models
JanusCoder-8B†8B67.02.5571.064.83.21
ManimTrainer (Seed-Coder-8B)8B49.82.4167.059.93.10
Qwen3.5-4B + our loop4B52.62.4882.071.73.00
ManimTrainer (Seed-Coder-8B) + RITL-DOC8B56.62.3873.065.03.05
Our trained model
Ours (SFT, single pass)4B64.42.8281.069.73.29
Ours (SFT, loop)4B88.62.8992.079.03.45
Ours (SFT + RL, loop)4B96.62.9497.082.93.44

RS: render success (%), with a bar on a 0–100 scale. VS: visual similarity to the reference video (geometric mean of SSIM and CLIP similarity), ManimBench only. VQ: video quality from Gemini 3.8 Flash on a 1–5 scale, averaged over successfully rendered videos. †71 of the 100 ManimBench requests appear in JanusCoder's training data. See the paper for model versions and protocols.

Long-form video generation

We replace only the scene generator in Code2Video and TheoremExplainAgent. Both runs of a system share one lecture plan written by the untrained Qwen3.5-4B and the same rendering budget. On MMMC, that planner produces no valid plan for 10 of the 117 topics, so our 107 videos cover every topic that has a plan.

Metric (higher is better)Native+ Ours
Code2Video on MMMC
Videos completed19/117107/117
TeachQuiz gain (×100)−2.627.2
Aesthetics (0–100)35.558.7
TheoremExplainAgent on TEB
Videos completed53/239239/239
Visual score (1–5)2.353.16

Effect of training data

Training dataRequestsManimData-testManimBench
RS ↑VQ ↑RS ↑VS ↑VQ ↑
HF Community13,76876.02.7658.050.42.81
JanusCode-800K6,28923.22.3843.040.43.26
ManimBench train3152.02.1022.020.92.99
ManimData (ours)24,03464.42.8281.069.73.29

All models generate in a single pass.

Bar charts comparing a Writer fine-tuned on released community programs with one fine-tuned on curated programs, on render success and video quality on both benchmarks.
Effect of curation. On the same 8,416 community requests with identical inputs, a Qwen3.5-4B Writer fine-tuned on our curated programs (blue) scores higher in single-pass RS and VQ on both benchmarks than one fine-tuned on the released programs (gray).

How far to trust the judge

One member of our team, blind to which system produced which video, compared 98 pairs from ManimCode and GPT-4o or Qwen3.8-27B. For VQ gaps of at least 0.5, the annotator agreed with the judge on 79% of decided pairs, against 29% for gaps below 0.25, so small score differences should be read with care. At the system level, human preferences align with the judge's rankings in three of four comparisons, favoring ManimCode over GPT-4o overall but Qwen3.8-27B on ManimData-test.

Resources

Paper

The full paper, with appendices on data sources, the API knowledge base, construction settings, training hyperparameters, evaluation protocols, the human study, and more qualitative examples.

Code

Code for building ManimData, training the Writer, Reviewer, and Reviser, running the render–review–revise loop, and reproducing the evaluation.

ManimData

24,034 training records with request, final program, review scores, domain, and render count; the 500 ManimData-test requests; and the role-conditioned training samples, including reviews with their sampled frames. Rows derived from community datasets keep their source licenses.

Citation

@misc{liang2026manimcode,
  title  = {ManimCode: Learning Visual Self-Correction for Educational Animation},
  author = {Liang, Zhengyang and Liao, Lizi},
  year   = {2026},
  note   = {Project page: https://liang-zhengyang.github.io/manimcode/}
}

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