diff --git "a/data/validation.jsonl" "b/data/validation.jsonl" new file mode 100644--- /dev/null +++ "b/data/validation.jsonl" @@ -0,0 +1,138 @@ +{"system": "You are an expert Manim Community Edition (ManimCE v0.19+) Python developer and mathematical animator. Given a user request, first plan the spatial layout, coordinate bounds, timing, and pedagogical flow inside ... tags (when reasoning is helpful), and then output a complete, runnable, self-contained ManimCE Python script using `from manim import *`. Never use deprecated ManimGL (`manimlib`) methods like `ShowCreation`, `TexMobject`, `TextMobject`, or `axes.get_graph`; always use modern ManimCE APIs (`Create`, `MathTex`, `Tex`, `Text`, `axes.plot`) and prevent visual overlap using `.to_edge()`, `.next_to()`, and `FadeOut`.", "prompt": "You are a Manim expert. Please convert the Markdown lecture notes into executable Manim CE v0.19.0 code that displays content in English. The page layout must be clear, with no overlapping elements, and you must not output any explanatory or descriptive text outside the code. Pay special attention to avoiding common errors such as LaTeX syntax issues and index out-of-range errors, and ensure the code can run directly. The Markdown lecture notes are as follows:\n\n### Understanding the Importance of FFT in Practical Applications\nRecognize the central role of FFT in real-time signal processing, communication systems, and image processing, and be able to select appropriate parameters based on engineering requirements.\n\n## Main Content\n### Definition of Discrete Fourier Transform (DFT)\n#### Mathematical Definition of DFT\n##### Forward Transform: $X[k] = \\sum x[n]W_N^{nk}$\nFor a finite-length sequence $x[n]$ of length $N$ ($0 \\le n \\le N-1$), its $N$-point discrete Fourier transform is defined as:\n$$ X[k] = \\sum_{n=0}^{N-1} x[n] W_N^{nk}, \\quad 0 \\le k \\le N-1 $$\nwhere $X[k]$ represents the $k$-th spectral line in the frequency domain.\n\n\nThe context of this section (from highest to current level):\n# Discrete Fourier Transform (DFT) and Fast Fourier Transform (FFT)\n## Course Objectives\n", "chosen": "```python\nfrom manim import *\nfrom manim import config\nText.set_default(font='SimHei')\n\nclass DFTLecture(Scene):\n\n def construct(self):\n title1 = Title('DFT and FFT: Course Objectives', font_size=40)\n subtitle1 = Text('Importance of FFT in Practical Applications', font_size=32, color=BLUE)\n bullet_points = VGroup(Text('• Central role in real-time signal processing', font_size=28), Text('• Fundamental to communication systems', font_size=28), Text('• Essential in image processing', font_size=28), Text('• Select appropriate parameters based on engineering requirements', font_size=28)).arrange(DOWN, aligned_edge=LEFT, buff=0.4)\n content_group1 = VGroup(subtitle1, bullet_points).arrange(DOWN, aligned_edge=LEFT, buff=0.6)\n content_group1.next_to(title1, DOWN, buff=0.8)\n self.play(Write(title1))\n self.play(FadeIn(subtitle1, shift=DOWN))\n self.play(Write(bullet_points), run_time=3)\n self.wait(2)\n self.play(FadeOut(title1), FadeOut(content_group1))\n title2 = Title('Definition of Discrete Fourier Transform (DFT)', font_size=40)\n subtitle2 = Text('Mathematical Definition: Forward Transform', font_size=32, color=BLUE)\n text_intro = Tex('For a finite-length sequence $x[n]$ of length $N$ ($0 \\\\le n \\\\le N-1$),\\\\\\\\', 'its $N$-point discrete Fourier transform is defined as:').scale(0.8)\n formula = MathTex('X[k] = \\\\sum_{n=0}^{N-1} x[n] W_N^{nk}, \\\\quad 0 \\\\le k \\\\le N-1').scale(1.2).set_color(YELLOW)\n text_outro = Tex('where $X[k]$ represents the $k$-th spectral line\\\\\\\\', 'in the frequency domain.').scale(0.8)\n content_group2 = VGroup(subtitle2, text_intro, formula, text_outro).arrange(DOWN, buff=0.6)\n content_group2.next_to(title2, DOWN, buff=0.5)\n self.play(Write(title2))\n self.play(FadeIn(subtitle2, shift=DOWN))\n self.play(Write(text_intro))\n self.play(Write(formula))\n self.play(Write(text_outro))\n self.wait(3)\n box = SurroundingRectangle(formula, color=RED, buff=0.2)\n self.play(Create(box))\n self.wait(2)\n self.play(FadeOut(title2), FadeOut(content_group2), FadeOut(box))\n```", "rejected": "```python\nfrom manim import *\nfrom manim import config\nText.set_default(font='SimHei')\n\nclass DFTLecture(Scene):\n\n def construct(self):\n title1 = Title('DFT and FFT: Course Objectives', font_size=40)\n subtitle1 = Text('Importance of FFT in Practical Applications', font_size=32, color=BLUE)\n bullet_points = VGroup(Text('• Central role in real-time signal processing', font_size=28), Text('• Fundamental to communication systems', font_size=28), Text('• Essential in image processing', font_size=28), Text('• Select appropriate parameters based on engineering requirements', font_size=28)).arrange(DOWN, aligned_edge=LEFT, buff=0.4)\n content_group1 = VGroup(subtitle1, bullet_points).arrange(DOWN, aligned_edge=LEFT, buff=0.6)\n content_group1.next_to(title1, DOWN, buff=0.8)\n self.play(Write(title1))\n self.play(FadeIn(subtitle1, shift=DOWN))\n self.play(Write(bullet_points), run_time=3)\n self.wait(2)\n self.play(FadeOut(title1), FadeOut(content_group1))\n title2 = Title('Definition of Discrete Fourier Transform (DFT)', font_size=40)\n subtitle2 = Text('Mathematical Definition: Forward Transform', font_size=32, color=BLUE)\n text_intro = Tex('For a finite-length sequence $x[n]$ of length $N$ ($0 \\\\le n \\\\le N-1$),\\\\\\\\', 'its $N$-point discrete Fourier transform is defined as:').scale(0.8)\n formula = TexMobject('X[k] = \\\\sum_{n=0}^{N-1} x[n] W_N^{nk}, \\\\quad 0 \\\\le k \\\\le N-1').scale(1.2).set_color(YELLOW)\n text_outro = Tex('where $X[k]$ represents the $k$-th spectral line\\\\\\\\', 'in the frequency domain.').scale(0.8)\n content_group2 = VGroup(subtitle2, text_intro, formula, text_outro).arrange(DOWN, buff=0.6)\n content_group2.next_to(title2, DOWN, buff=0.5)\n self.play(Write(title2))\n self.play(FadeIn(subtitle2, shift=DOWN))\n self.play(Write(text_intro))\n self.play(Write(formula))\n self.play(Write(text_outro))\n self.wait(3)\n box = SurroundingRectangle(formula, color=RED, buff=0.2)\n self.play(ShowCreation(box))\n self.wait(2)\n self.play(FadeOut(title2), FadeOut(content_group2), FadeOut(box))\n```", "category": "legacy_api_hallucination", "source": "synthetic_hard_neg:nabin2004/manim-sft-10k"} +{"system": "You are an expert Manim Community Edition (ManimCE v0.19+) Python developer and mathematical animator. Given a user request, first plan the spatial layout, coordinate bounds, timing, and pedagogical flow inside ... tags (when reasoning is helpful), and then output a complete, runnable, self-contained ManimCE Python script using `from manim import *`. Never use deprecated ManimGL (`manimlib`) methods like `ShowCreation`, `TexMobject`, `TextMobject`, or `axes.get_graph`; always use modern ManimCE APIs (`Create`, `MathTex`, `Tex`, `Text`, `axes.plot`) and prevent visual overlap using `.to_edge()`, `.next_to()`, and `FadeOut`.", "prompt": "Display a 3D coordinate system and render a colorful surface defined by the equation \\( z = 2\\sin(x) + 2\\cos(y) \\). The surface spans from \\(-3\\) to \\(3\\) along both the x- and y-axes and is colored using a gradient from blue to red. The camera is angled to provide a clear view of the surface’s undulating, wave-like shape.", "chosen": "```python\nfrom manim import *\n\nclass PlotSurfaceExample(ThreeDScene):\n def construct(self):\n resolution_fa = 16\n self.set_camera_orientation(phi=75 * DEGREES, theta=-60 * DEGREES)\n axes = ThreeDAxes(x_range=(-3, 3, 1), y_range=(-3, 3, 1), z_range=(-5, 5, 1))\n def param_trig(u, v):\n x = u\n y = v\n z = 2 * np.sin(x) + 2 * np.cos(y)\n return z\n trig_plane = axes.plot_surface(\n param_trig,\n resolution=(resolution_fa, resolution_fa),\n u_range = (-3, 3),\n v_range = (-3, 3),\n colorscale = [BLUE, GREEN, YELLOW, ORANGE, RED],\n )\n self.add(axes, trig_plane)\n```", "rejected": "```python\nfrom manim import *\n\nclass PlotSurfaceExample(Scene):\n def construct(self):\n resolution_fa = 16\n self.set_camera_orientation(phi=75 * DEGREES, theta=-60 * DEGREES)\n axes = ThreeDAxes(x_range=(-3, 3, 1), y_range=(-3, 3, 1), z_range=(-5, 5, 1))\n def param_trig(u, v):\n x = u\n y = v\n z = 2 * np.sin(x) + 2 * np.cos(y)\n return z\n trig_plane = axes.plot_surface(\n param_trig,\n resolution=(resolution_fa, resolution_fa),\n u_range = (-3, 3),\n v_range = (-3, 3),\n colorscale = [BLUE, GREEN, YELLOW, ORANGE, RED],\n )\n self.add(axes, trig_plane)\n```", "category": "wrong_3d_scene_base", "source": "synthetic_hard_neg:SuienR/ManimBench-v1"} +{"system": "You are an expert Manim Community Edition (ManimCE v0.19+) Python developer and mathematical animator. Given a user request, first plan the spatial layout, coordinate bounds, timing, and pedagogical flow inside ... tags (when reasoning is helpful), and then output a complete, runnable, self-contained ManimCE Python script using `from manim import *`. Never use deprecated ManimGL (`manimlib`) methods like `ShowCreation`, `TexMobject`, `TextMobject`, or `axes.get_graph`; always use modern ManimCE APIs (`Create`, `MathTex`, `Tex`, `Text`, `axes.plot`) and prevent visual overlap using `.to_edge()`, `.next_to()`, and `FadeOut`.", "prompt": "I'm learning about gradient flow and want a cascade of shrinking waterfall bars representing gradients passing through layers. Visualize a top-down stack of layers, each layer's bars shrinking as backprop reduces magnitude, with color cues for sign and a legend showing scale. Include transitions across epochs and a quick recap of stability when gradients vanish.", "chosen": "```python\nfrom manim import *\nfrom manim_voiceover import VoiceoverScene\nfrom manim_voiceover.services.gtts import GTTSService\nimport numpy as np\n\n\nclass GradientFlowVisualization(VoiceoverScene):\n def construct(self):\n self.set_speech_service(\n GTTSService(voice=\"alba\", cache_dir=\"voiceover_cache\")\n )\n \n # Title\n title = Text(\"Gradient Flow Visualization\", font_size=36, color=BLUE)\n title.to_edge(UP, buff=0.5)\n \n with self.voiceover(text=\"Imagine trying to find the lowest point in a bumpy landscape. How do you plot your path as you descend? In today's lecture, you will learn how to visualize gradient flow, the method that helps algorithms navigate these rough terrains in machine learning.\") as tracker:\n self.play(Write(title), run_time=tracker.duration)\n \n # Create axes\n axes = Axes(\n x_range=[-4, 4, 1],\n y_range=[-3, 3, 1],\n x_length=8,\n y_length=6,\n axis_config={\"include_tip\": True},\n )\n axes.shift(DOWN * 0.3)\n \n x_label = MathTex(r\"w_1\").next_to(axes.x_axis, RIGHT)\n y_label = MathTex(r\"w_2\").next_to(axes.y_axis, UP)\n \n with self.voiceover(text=\"Let's visualize a loss landscape. Think of it as a terrain where height represents loss, and we want to find the lowest point.\") as tracker:\n self.play(Create(axes), Write(x_label), Write(y_label), run_time=tracker.duration)\n \n # Gradient field for f(x,y) = x² + y²\n def gradient_field(point):\n x, y = point[:2]\n return np.array([-2*x, -2*y, 0])\n \n # Contour lines\n contours = VGroup()\n colors = [BLUE_E, BLUE_D, BLUE_C, TEAL, GREEN_C, YELLOW_C, ORANGE, RED_C]\n for i, r in enumerate([0.5, 1.0, 1.5, 2.0, 2.5, 3.0, 3.5]):\n circle = Circle(radius=r, color=colors[i % len(colors)], stroke_width=2, stroke_opacity=0.6)\n circle.move_to(axes.c2p(0, 0))\n contours.add(circle)\n \n loss_labels = VGroup()\n for i, r in enumerate([0.5, 1.5, 2.5, 3.5]):\n label = MathTex(rf\"L={r**2:.1f}\", font_size=16, color=colors[i*2])\n label.move_to(axes.c2p(r*0.7, r*0.7))\n loss_labels.add(label)\n \n with self.voiceover(text=\"These concentric circles represent level sets of our loss function. Inner circles have lower loss, with the global minimum at the center.\") as tracker:\n self.play(FadeIn(contours), FadeIn(loss_labels), run_time=tracker.duration)\n \n # Stream lines\n stream_lines = StreamLines(\n gradient_field,\n x_range=[-3.5, 3.5, 0.5],\n y_range=[-2.5, 2.5, 0.5],\n stroke_width=1.5,\n opacity=0.7,\n colors=[BLUE, TEAL, GREEN],\n virtual_time=2,\n )\n stream_lines.scale(0.8)\n stream_lines.move_to(axes.c2p(0, 0))\n \n with self.voiceover(text=\"These stream lines show the gradient flow. At every point, the flow follows the direction of steepest descent toward the minimum.\") as tracker:\n self.play(FadeIn(stream_lines), run_time=tracker.duration)\n self.wait(1)\n \n # Gradient descent demo\n start_point = np.array([3.0, 2.0])\n learning_rate = 0.15\n \n dot = Dot(axes.c2p(start_point[0], start_point[1]), color=RED, radius=0.12)\n dot_label = MathTex(r\"\\theta_0\", font_size=24, color=RED)\n dot_label.next_to(dot, UR, buff=0.1)\n \n with self.voiceover(text=\"Now let's watch gradient descent in action. We start at this red point, and follow the negative gradient step by step.\") as tracker:\n self.play(FadeIn(dot), Write(dot_label), run_time=tracker.duration)\n \n # Pre-calculate path\n current_pos = start_point.copy()\n positions = [current_pos.copy()]\n for step in range(12):\n grad = np.array([2*current_pos[0], 2*current_pos[1]])\n new_pos = current_pos - learning_rate * grad\n positions.append(new_pos.copy())\n current_pos = new_pos\n if np.linalg.norm(grad) < 0.1:\n break\n \n screen_points = [axes.c2p(p[0], p[1]) for p in positions]\n \n # Build path gradually\n with self.voiceover(text=\"At each step, we compute the gradient and move in the opposite direction. The size of each step is controlled by the learning rate.\") as tracker:\n for i in range(1, len(screen_points)):\n line = Line(screen_points[i-1], screen_points[i], color=RED, stroke_width=3)\n self.play(dot.animate.move_to(screen_points[i]), Create(line), run_time=0.4)\n \n new_label = MathTex(r\"\\theta^*\", font_size=24, color=GREEN)\n new_label.next_to(dot, UR, buff=0.1)\n \n with self.voiceover(text=\"Notice how the steps get smaller as we approach the minimum. This is because the gradient magnitude decreases near the optimum.\") as tracker:\n self.play(Transform(dot_label, new_label), run_time=tracker.duration)\n \n min_dot = Dot(axes.c2p(0, 0), color=GREEN, radius=0.15)\n min_label = Text(\"Minimum\", font_size=20, color=GREEN)\n min_label.next_to(min_dot, DOWN, buff=0.2)\n \n with self.voiceover(text=\"We've reached the global minimum. The gradient flow visualization helps us understand how optimization algorithms navigate toward this point.\") as tracker:\n self.play(FadeIn(min_dot), Write(min_label), run_time=tracker.duration)\n \n with self.voiceover(text=\"Let's compare different learning rates. A larger learning rate means bigger steps, but can cause overshooting.\") as tracker:\n self.wait(tracker.duration)\n \n # Fade out first demo\n self.play(FadeOut(dot), FadeOut(dot_label), FadeOut(min_dot), FadeOut(min_label))\n \n # Compare three learning rates\n start_point = np.array([2.5, 1.5])\n learning_rates = [0.05, 0.2, 0.45]\n colors_lr = [BLUE, GREEN, ORANGE]\n labels_lr = [\"Small LR\", \"Medium LR\", \"Large LR\"]\n \n dot1 = Dot(axes.c2p(start_point[0], start_point[1]), color=colors_lr[0], radius=0.1)\n dot2 = Dot(axes.c2p(start_point[0], start_point[1]), color=colors_lr[1], radius=0.1)\n dot3 = Dot(axes.c2p(start_point[0], start_point[1]), color=colors_lr[2], radius=0.1)\n \n label1 = Text(labels_lr[0], font_size=18, color=colors_lr[0])\n label2 = Text(labels_lr[1], font_size=18, color=colors_lr[1])\n label3 = Text(labels_lr[2], font_size=18, color=colors_lr[2])\n label1.next_to(axes.c2p(start_point[0], start_point[1]), UP, buff=0.5).shift(LEFT * 1.5)\n label2.next_to(axes.c2p(start_point[0], start_point[1]), UP, buff=0.5)\n label3.next_to(axes.c2p(start_point[0], start_point[1]), UP, buff=0.5).shift(RIGHT * 1.5)\n \n with self.voiceover(text=\"Here are three starting points with different learning rates. Watch how each one converges.\") as tracker:\n self.play(FadeIn(dot1), FadeIn(dot2), FadeIn(dot3), run_time=tracker.duration/2)\n self.play(FadeIn(label1), FadeIn(label2), FadeIn(label3), run_time=tracker.duration/2)\n \n # Pre-calculate all paths\n all_positions = []\n for lr in learning_rates:\n positions = [start_point.copy()]\n current = start_point.copy()\n for step in range(15):\n grad = np.array([2*current[0], 2*current[1]])\n new_pos = current - lr * grad\n positions.append(new_pos.copy())\n current = new_pos\n all_positions.append(positions)\n \n dots_list = [dot1, dot2, dot3]\n \n with self.voiceover(text=\"The blue path with small learning rate takes many small steps. The green path with medium learning rate converges smoothly. The orange path with large learning rate overshoots and oscillates.\") as tracker:\n for step in range(15):\n for i in range(3):\n if step + 1 < len(all_positions[i]):\n prev_pos = all_positions[i][step]\n curr_pos = all_positions[i][step + 1]\n self.play(\n dots_list[i].animate.move_to(axes.c2p(curr_pos[0], curr_pos[1])),\n run_time=0.15\n )\n line = Line(\n axes.c2p(prev_pos[0], prev_pos[1]),\n axes.c2p(curr_pos[0], curr_pos[1]),\n color=colors_lr[i],\n stroke_width=2.5\n )\n self.add(line)\n \n # Summary\n with self.voiceover(text=\"To summarize: Gradient flow visualizes how optimizers navigate toward minima. The learning rate is crucial. Too large causes oscillation, too small causes slow convergence. Choose wisely for smooth gradient flow.\") as tracker:\n self.play(FadeOut(title), FadeOut(stream_lines), FadeOut(contours), FadeOut(loss_labels))\n self.play(FadeOut(axes), FadeOut(x_label), FadeOut(y_label))\n self.play(FadeOut(dot1), FadeOut(dot2), FadeOut(dot3))\n self.play(FadeOut(label1), FadeOut(label2), FadeOut(label3))\n \n # Summary screen\n summary_title = Text(\"Key Takeaways:\", font_size=28, color=YELLOW)\n summary_title.to_edge(UP, buff=0.5)\n \n t1 = Text(\"1. Gradient flow follows steepest descent\", font_size=22)\n t2 = Text(\"2. Learning rate controls step size\", font_size=22)\n t3 = Text(\"3. Too large: oscillation; Too small: slow\", font_size=22)\n t4 = Text(\"4. Visualize to understand optimizer behavior\", font_size=22)\n \n t1.next_to(summary_title, DOWN, buff=0.5)\n t2.next_to(t1, DOWN, buff=0.3)\n t3.next_to(t2, DOWN, buff=0.3)\n t4.next_to(t3, DOWN, buff=0.3)\n \n self.play(Write(summary_title))\n self.play(Write(t1))\n self.play(Write(t2))\n self.play(Write(t3))\n self.play(Write(t4))\n \n self.wait(1)\n```", "rejected": "```python\nfrom manim import *\nimport numpy as np\n\nclass GradientFlowVisualization(Scene):\n\n def construct(self):\n title = Text('Gradient Flow Visualization', font_size=36, color=BLUE)\n title.to_edge(UP, buff=0.5)\n self.play(Write(title), run_time=2.0)\n axes = Axes(x_range=[-4, 4, 1], y_range=[-3, 3, 1], x_length=8, y_length=6, axis_config={'include_tip': True})\n axes.shift(DOWN * 0.3)\n x_label = MathTex('w_1').next_to(axes.x_axis, RIGHT)\n y_label = MathTex('w_2').next_to(axes.y_axis, UP)\n self.play(Create(axes), Write(x_label), Write(y_label), run_time=2.0)\n\n def gradient_field(point):\n x, y = point[:2]\n return np.array([-2 * x, -2 * y, 0])\n contours = VGroup()\n colors = [BLUE_E, BLUE_D, BLUE_C, TEAL, GREEN_C, YELLOW_C, ORANGE, RED_C]\n for i, r in enumerate([0.5, 1.0, 1.5, 2.0, 2.5, 3.0, 3.5]):\n circle = Circle(radius=r, color=colors[i % len(colors)], stroke_width=2, stroke_opacity=0.6)\n circle.move_to(axes.c2p(0, 0))\n contours.add(circle)\n loss_labels = VGroup()\n for i, r in enumerate([0.5, 1.5, 2.5, 3.5]):\n label = MathTex(f'L={r ** 2:.1f}', font_size=16, color=colors[i * 2])\n label.move_to(axes.c2p(r * 0.7, r * 0.7))\n loss_labels.add(label)\n self.play(FadeIn(contours), FadeIn(loss_labels), run_time=2.0)\n stream_lines = StreamLines(gradient_field, x_range=[-3.5, 3.5, 0.5], y_range=[-2.5, 2.5, 0.5], stroke_width=1.5, opacity=0.7, colors=[BLUE, TEAL, GREEN], virtual_time=2)\n stream_lines.scale(0.8)\n stream_lines.move_to(axes.c2p(0, 0))\n self.play(FadeIn(stream_lines), run_time=2.0)\n self.wait(1)\n start_point = np.array([3.0, 2.0])\n learning_rate = 0.15\n dot = Dot(axes.c2p(start_point[0], start_point[1]), color=RED, radius=0.12)\n dot_label = MathTex('\\\\theta_0', font_size=24, color=RED)\n dot_label.next_to(dot, UR, buff=0.1)\n self.play(FadeIn(dot), Write(dot_label), run_time=2.0)\n current_pos = start_point.copy()\n positions = [current_pos.copy()]\n for step in range(12):\n grad = np.array([2 * current_pos[0], 2 * current_pos[1]])\n new_pos = current_pos - learning_rate * grad\n positions.append(new_pos.copy())\n current_pos = new_pos\n if np.linalg.norm(grad) < 0.1:\n break\n screen_points = [axes.c2p(p[0], p[1]) for p in positions]\n for i in range(1, len(screen_points)):\n line = Line(screen_points[i - 1], screen_points[i], color=RED, stroke_width=3)\n self.play(dot.animate.move_to(screen_points[i]), Create(line), run_time=0.4)\n new_label = MathTex('\\\\theta^*', font_size=24, color=GREEN)\n new_label.next_to(dot, UR, buff=0.1)\n self.play(Transform(dot_label, new_label), run_time=2.0)\n min_dot = Dot(axes.c2p(0, 0), color=GREEN, radius=0.15)\n min_label = Text('Minimum', font_size=20, color=GREEN)\n min_label.next_to(min_dot, DOWN, buff=0.2)\n self.play(FadeIn(min_dot), Write(min_label), run_time=2.0)\n self.wait(2.0)\n self.play(FadeOut(dot), FadeOut(dot_label), FadeOut(min_dot), FadeOut(min_label))\n start_point = np.array([2.5, 1.5])\n learning_rates = [0.05, 0.2, 0.45]\n colors_lr = [BLUE, GREEN, ORANGE]\n labels_lr = ['Small LR', 'Medium LR', 'Large LR']\n dot1 = Dot(axes.c2p(start_point[0], start_point[1]), color=colors_lr[0], radius=0.1)\n dot2 = Dot(axes.c2p(start_point[0], start_point[1]), color=colors_lr[1], radius=0.1)\n dot3 = Dot(axes.c2p(start_point[0], start_point[1]), color=colors_lr[2], radius=0.1)\n label1 = Text(labels_lr[0], font_size=18, color=colors_lr[0])\n label2 = Text(labels_lr[1], font_size=18, color=colors_lr[1])\n label3 = Text(labels_lr[2], font_size=18, color=colors_lr[2])\n label1.next_to(axes.c2p(start_point[0], start_point[1]), UP, buff=0.5).shift(LEFT * 1.5)\n label2.next_to(axes.c2p(start_point[0], start_point[1]), UP, buff=0.5)\n label3.next_to(axes.c2p(start_point[0], start_point[1]), UP, buff=0.5).shift(RIGHT * 1.5)\n self.play(FadeIn(dot1), FadeIn(dot2), FadeIn(dot3), run_time=2.0 / 2)\n self.play(FadeIn(label1), FadeIn(label2), FadeIn(label3), run_time=2.0 / 2)\n all_positions = []\n for lr in learning_rates:\n positions = [start_point.copy()]\n current = start_point.copy()\n for step in range(15):\n grad = np.array([2 * current[0], 2 * current[1]])\n new_pos = current - lr * grad\n positions.append(new_pos.copy())\n current = new_pos\n all_positions.append(positions)\n dots_list = [dot1, dot2, dot3]\n for step in range(15):\n for i in range(3):\n if step + 1 < len(all_positions[i]):\n prev_pos = all_positions[i][step]\n curr_pos = all_positions[i][step + 1]\n self.play(dots_list[i].animate.move_to(axes.c2p(curr_pos[0], curr_pos[1])), run_time=0.15)\n line = Line(axes.c2p(prev_pos[0], prev_pos[1]), axes.c2p(curr_pos[0], curr_pos[1]), color=colors_lr[i], stroke_width=2.5)\n self.add(line)\n self.play(FadeOut(title), FadeOut(stream_lines), FadeOut(contours), FadeOut(loss_labels))\n self.play(FadeOut(axes), FadeOut(x_label), FadeOut(y_label))\n self.play(FadeOut(dot1), FadeOut(dot2), FadeOut(dot3))\n self.play(FadeOut(label1), FadeOut(label2), FadeOut(label3))\n summary_title = Text('Key Takeaways:', font_size=28, color=YELLOW)\n summary_title.to_edge(UP, buff=0.5)\n t1 = Text('1. Gradient flow follows steepest descent', font_size=22)\n t2 = Text('2. Learning rate controls step size', font_size=22)\n t3 = Text('3. Too large: oscillation; Too small: slow', font_size=22)\n t4 = Text('4. Visualize to understand optimizer behavior', font_size=22)\n t1.next_to(summary_title, DOWN, buff=0.5)\n t2.next_to(t1, DOWN, buff=0.3)\n t3.next_to(t2, DOWN, buff=0.3)\n t4.next_to(t3, DOWN, buff=0.3)\n self.play(Write(summary_title))\n self.play(Write(t1))\n self.play(Write(t2))\n self.play(Write(t3))\n self.play(Write(t4))\n self.wait(1)\n```", "category": "narrated_pedagogical_preference", "source": "nabin2004/manim-narrated-dpo-400"} +{"system": "You are an expert Manim Community Edition (ManimCE v0.19+) Python developer and mathematical animator. Given a user request, first plan the spatial layout, coordinate bounds, timing, and pedagogical flow inside ... tags (when reasoning is helpful), and then output a complete, runnable, self-contained ManimCE Python script using `from manim import *`. Never use deprecated ManimGL (`manimlib`) methods like `ShowCreation`, `TexMobject`, `TextMobject`, or `axes.get_graph`; always use modern ManimCE APIs (`Create`, `MathTex`, `Tex`, `Text`, `axes.plot`) and prevent visual overlap using `.to_edge()`, `.next_to()`, and `FadeOut`.", "prompt": "I'm teaching undergrads a course on computational graphs and want a vivid visualization of a topological sort. Show a DAG of operations from inputs to output, with each operation numbered in the exact execution order. Animate the dependency sweep so nodes activate in sequence and the final order is highlighted. Include multiple scenes with sequential numbering and a legend explaining what each number means.", "chosen": "```python\nfrom manim import *\nfrom manim_voiceover import VoiceoverScene\nfrom manim_voiceover.services.gtts import GTTSService\n\nclass TopologicalSortVisualization(VoiceoverScene):\n def construct(self):\n self.set_speech_service(\n GTTSService(voice=\"alba\", cache_dir=\"voiceover_cache\")\n )\n \n # Title\n title = Text(\"Topological Sort Visualization\", font_size=48)\n title.to_edge(UP, buff=0.5)\n \n with self.voiceover(text=\"Imagine you have a set of tasks to complete, and each task depends on others. How do you determine the order in which to perform them? This process is called topological sorting.\") as tracker:\n self.play(Write(title), run_time=tracker.duration)\n \n self.wait(0.3)\n \n # Create a directed graph representing tasks and dependencies\n # A -> B -> D\n # A -> C -> D\n \n nodes = {\n \"A\": Circle(radius=0.4, color=BLUE, fill_opacity=0.3),\n \"B\": Circle(radius=0.4, color=GREEN, fill_opacity=0.3),\n \"C\": Circle(radius=0.4, color=GREEN, fill_opacity=0.3),\n \"D\": Circle(radius=0.4, color=RED, fill_opacity=0.3),\n }\n \n # Position nodes in a diamond pattern\n nodes[\"A\"].move_to(UP * 2)\n nodes[\"B\"].move_to(LEFT * 2 + DOWN * 0.5)\n nodes[\"C\"].move_to(RIGHT * 2 + DOWN * 0.5)\n nodes[\"D\"].move_to(DOWN * 3)\n \n # Node labels\n labels = {\n \"A\": Text(\"A\", font_size=32).move_to(nodes[\"A\"].get_center()),\n \"B\": Text(\"B\", font_size=32).move_to(nodes[\"B\"].get_center()),\n \"C\": Text(\"C\", font_size=32).move_to(nodes[\"C\"].get_center()),\n \"D\": Text(\"D\", font_size=32).move_to(nodes[\"D\"].get_center()),\n }\n \n # Task descriptions\n task_desc = VGroup(\n Text(\"A: Wake up\", font_size=20),\n Text(\"B: Brush teeth\", font_size=20),\n Text(\"C: Eat breakfast\", font_size=20),\n Text(\"D: Leave house\", font_size=20),\n ).arrange(DOWN, aligned_edge=LEFT, buff=0.2)\n task_desc.to_edge(RIGHT, buff=0.5)\n task_desc.shift(UP * 0.5)\n \n with self.voiceover(text=\"Here we have four daily tasks. You must wake up before brushing teeth or eating breakfast. And you must brush teeth and eat breakfast before leaving the house.\") as tracker:\n self.play(\n *[Create(nodes[n]) for n in nodes],\n *[Write(labels[n]) for n in labels],\n run_time=tracker.duration * 0.6\n )\n self.play(Write(task_desc), run_time=tracker.duration * 0.4)\n \n self.wait(0.3)\n \n # Create edges with arrows\n edges = {\n \"AB\": Arrow(nodes[\"A\"].get_bottom() + LEFT*0.1, nodes[\"B\"].get_top() + UP*0.1, buff=0.1, color=WHITE),\n \"AC\": Arrow(nodes[\"A\"].get_bottom() + RIGHT*0.1, nodes[\"C\"].get_top() + UP*0.1, buff=0.1, color=WHITE),\n \"BD\": Arrow(nodes[\"B\"].get_bottom(), nodes[\"D\"].get_top() + LEFT*0.1, buff=0.1, color=WHITE),\n \"CD\": Arrow(nodes[\"C\"].get_bottom(), nodes[\"D\"].get_top() + RIGHT*0.1, buff=0.1, color=WHITE),\n }\n \n with self.voiceover(text=\"These arrows represent dependencies. An arrow from A to B means task A must be completed before task B.\") as tracker:\n self.play(*[Create(edges[e]) for e in edges], run_time=tracker.duration)\n \n self.wait(0.3)\n \n # Show in-degrees\n in_degree_title = Text(\"In-Degree (incoming arrows):\", font_size=24, color=YELLOW)\n in_degree_title.to_edge(LEFT, buff=0.3)\n in_degree_title.shift(UP * 1.5)\n \n in_degrees = VGroup(\n Text(\"A: 0\", font_size=22, color=YELLOW),\n Text(\"B: 1\", font_size=22, color=YELLOW),\n Text(\"C: 1\", font_size=22, color=YELLOW),\n Text(\"D: 2\", font_size=22, color=YELLOW),\n ).arrange(DOWN, aligned_edge=LEFT, buff=0.2)\n in_degrees.next_to(in_degree_title, DOWN, buff=0.2)\n \n with self.voiceover(text=\"To find a valid order, we use in-degrees — the count of incoming arrows. Task A has zero, so it can start immediately. Tasks B and C each need one prerequisite. Task D needs both B and C.\") as tracker:\n self.play(Write(in_degree_title), run_time=tracker.duration * 0.3)\n self.play(Write(in_degrees), run_time=tracker.duration * 0.7)\n \n self.wait(0.3)\n \n # Start topological sort visualization\n sort_title = Text(\"Topological Sort:\", font_size=28, color=ORANGE)\n sort_title.to_edge(DOWN, buff=1.5)\n \n sorted_order = []\n order_display = Text(\"\", font_size=24, color=ORANGE)\n order_display.next_to(sort_title, DOWN, buff=0.2)\n \n with self.voiceover(text=\"Now let's perform the topological sort. We repeatedly pick nodes with zero in-degree.\") as tracker:\n self.play(Write(sort_title), run_time=tracker.duration)\n \n self.wait(0.3)\n \n # Step 1: Pick A\n with self.voiceover(text=\"Task A has zero in-degree. We add it to our sorted order.\") as tracker:\n sorted_order.append(\"A\")\n order_display.become(Text(\"Order: [A]\", font_size=24, color=ORANGE).next_to(sort_title, DOWN, buff=0.2))\n self.play(\n nodes[\"A\"].animate.set_fill(YELLOW, opacity=0.8),\n FadeIn(order_display),\n run_time=tracker.duration * 0.5\n )\n # Remove outgoing edges from A\n self.play(\n edges[\"AB\"].animate.set_color(YELLOW),\n edges[\"AC\"].animate.set_color(YELLOW),\n run_time=tracker.duration * 0.3\n )\n self.play(\n FadeOut(edges[\"AB\"]),\n FadeOut(edges[\"AC\"]),\n run_time=tracker.duration * 0.2\n )\n \n self.wait(0.2)\n \n # Update in-degrees: B and C now have 0\n new_in_degrees = VGroup(\n Text(\"A: done\", font_size=22, color=GRAY),\n Text(\"B: 0\", font_size=22, color=YELLOW),\n Text(\"C: 0\", font_size=22, color=YELLOW),\n Text(\"D: 2\", font_size=22, color=YELLOW),\n ).arrange(DOWN, aligned_edge=LEFT, buff=0.2)\n new_in_degrees.next_to(in_degree_title, DOWN, buff=0.2)\n \n with self.voiceover(text=\"Removing A reduces B and C to zero in-degrees. Now either can come next.\") as tracker:\n self.play(Transform(in_degrees, new_in_degrees), run_time=tracker.duration)\n \n self.wait(0.2)\n \n # Step 2: Pick B\n with self.voiceover(text=\"Let's pick B. We add it to our order.\") as tracker:\n sorted_order.append(\"B\")\n order_display.become(Text(\"Order: [A, B]\", font_size=24, color=ORANGE).next_to(sort_title, DOWN, buff=0.2))\n self.play(\n nodes[\"B\"].animate.set_fill(YELLOW, opacity=0.8),\n FadeOut(order_display),\n run_time=tracker.duration * 0.3\n )\n order_display = Text(\"Order: [A, B]\", font_size=24, color=ORANGE).next_to(sort_title, DOWN, buff=0.2)\n self.play(FadeIn(order_display), run_time=tracker.duration * 0.2)\n # Remove edge B->D\n self.play(edges[\"BD\"].animate.set_color(YELLOW), run_time=tracker.duration * 0.3)\n self.play(FadeOut(edges[\"BD\"]), run_time=tracker.duration * 0.2)\n \n self.wait(0.2)\n \n # Update in-degrees\n new_in_degrees2 = VGroup(\n Text(\"A: done\", font_size=22, color=GRAY),\n Text(\"B: done\", font_size=22, color=GRAY),\n Text(\"C: 0\", font_size=22, color=YELLOW),\n Text(\"D: 1\", font_size=22, color=YELLOW),\n ).arrange(DOWN, aligned_edge=LEFT, buff=0.2)\n new_in_degrees2.next_to(in_degree_title, DOWN, buff=0.2)\n \n with self.voiceover(text=\"B is done. D's in-degree drops to one, but D still needs C.\") as tracker:\n self.play(Transform(in_degrees, new_in_degrees2), run_time=tracker.duration)\n \n self.wait(0.2)\n \n # Step 3: Pick C\n with self.voiceover(text=\"C now has zero in-degree, so we add it next.\") as tracker:\n sorted_order.append(\"C\")\n order_display.become(Text(\"Order: [A, B, C]\", font_size=24, color=ORANGE).next_to(sort_title, DOWN, buff=0.2))\n self.play(\n nodes[\"C\"].animate.set_fill(YELLOW, opacity=0.8),\n FadeOut(order_display),\n run_time=tracker.duration * 0.3\n )\n order_display = Text(\"Order: [A, B, C]\", font_size=24, color=ORANGE).next_to(sort_title, DOWN, buff=0.2)\n self.play(FadeIn(order_display), run_time=tracker.duration * 0.2)\n # Remove edge C->D\n self.play(edges[\"CD\"].animate.set_color(YELLOW), run_time=tracker.duration * 0.3)\n self.play(FadeOut(edges[\"CD\"]), run_time=tracker.duration * 0.2)\n \n self.wait(0.2)\n \n # Update in-degrees\n new_in_degrees3 = VGroup(\n Text(\"A: done\", font_size=22, color=GRAY),\n Text(\"B: done\", font_size=22, color=GRAY),\n Text(\"C: done\", font_size=22, color=GRAY),\n Text(\"D: 0\", font_size=22, color=YELLOW),\n ).arrange(DOWN, aligned_edge=LEFT, buff=0.2)\n new_in_degrees3.next_to(in_degree_title, DOWN, buff=0.2)\n \n with self.voiceover(text=\"C is done. D's in-degree is now zero.\") as tracker:\n self.play(Transform(in_degrees, new_in_degrees3), run_time=tracker.duration)\n \n self.wait(0.2)\n \n # Step 4: Pick D\n with self.voiceover(text=\"Finally, we add D to complete the topological sort.\") as tracker:\n sorted_order.append(\"D\")\n order_display.become(Text(\"Order: [A, B, C, D]\", font_size=24, color=ORANGE).next_to(sort_title, DOWN, buff=0.2))\n self.play(\n nodes[\"D\"].animate.set_fill(YELLOW, opacity=0.8),\n FadeOut(order_display),\n run_time=tracker.duration * 0.5\n )\n order_display = Text(\"Order: [A, B, C, D]\", font_size=24, color=ORANGE).next_to(sort_title, DOWN, buff=0.2)\n self.play(FadeIn(order_display), run_time=tracker.duration * 0.5)\n \n self.wait(0.3)\n \n # Show alternative valid sort\n alt_text = Text(\"Alternative valid order: [A, C, B, D]\", font_size=22, color=GREEN)\n alt_text.next_to(order_display, DOWN, buff=0.3)\n \n with self.voiceover(text=\"This gives us the order: wake up, brush teeth, eat breakfast, leave house. Note that A, C, B, D is also valid because B and C have no dependencies between them.\") as tracker:\n self.play(Write(alt_text), run_time=tracker.duration)\n \n self.wait(0.3)\n \n # Highlight what makes a sort invalid\n invalid_text = Text(\"Invalid: [B, A, ...] — B depends on A!\", font_size=22, color=RED)\n invalid_text.next_to(alt_text, DOWN, buff=0.3)\n \n with self.voiceover(text=\"However, starting with B would be invalid because B depends on A. A topological sort must respect all dependencies.\") as tracker:\n self.play(Write(invalid_text), run_time=tracker.duration)\n \n self.wait(0.5)\n \n # Final summary\n self.play(\n FadeOut(invalid_text),\n FadeOut(alt_text),\n FadeOut(in_degree_title),\n FadeOut(in_degrees),\n FadeOut(task_desc),\n )\n \n summary = VGroup(\n Text(\"Key Takeaways:\", font_size=28, color=BLUE),\n Text(\"• Topological sort orders tasks by dependencies\", font_size=22),\n Text(\"• Use in-degrees to find starting nodes\", font_size=22),\n Text(\"• Remove edges as nodes are processed\", font_size=22),\n Text(\"• Multiple valid orders may exist\", font_size=22),\n ).arrange(DOWN, aligned_edge=LEFT, buff=0.3)\n summary.move_to(ORIGIN)\n summary.shift(UP * 0.5)\n \n with self.voiceover(text=\"To summarize: topological sort organizes tasks based on dependencies. We use in-degrees to find starting points, remove edges as we process nodes, and understand that multiple valid orderings can exist.\") as tracker:\n self.play(\n FadeOut(title),\n *[FadeOut(nodes[n]) for n in nodes],\n *[FadeOut(labels[n]) for n in labels],\n FadeOut(sort_title),\n FadeOut(order_display),\n run_time=tracker.duration * 0.3\n )\n self.play(Write(summary), run_time=tracker.duration * 0.7)\n \n self.wait(1)\n```", "rejected": "```python\nfrom manim import *\nfrom manim_voiceover import VoiceoverScene\nfrom manim_voiceover.services.gtts import GTTSService\n\nclass TopologicalSortVisualization(VoiceoverScene):\n def construct(self):\n self.set_speech_service(\n GTTSService(voice=\"alba\", cache_dir=\"voiceover_cache\")\n )\n \n # Title\n title = Text(\"Topological Sort Visualization\", font_size=48)\n title\n \n with self.voiceover(text=\"Imagine you have a set of tasks to complete, and each task depends on others. How do you determine the order in which to perform them? This process is called topological sorting.\") as tracker:\n self.play(Write(title), run_time=tracker.duration)\n \n self.wait(0.3)\n \n # Create a directed graph representing tasks and dependencies\n # A -> B -> D\n # A -> C -> D\n \n nodes = {\n \"A\": Circle(radius=0.4, color=BLUE, fill_opacity=0.3),\n \"B\": Circle(radius=0.4, color=GREEN, fill_opacity=0.3),\n \"C\": Circle(radius=0.4, color=GREEN, fill_opacity=0.3),\n \"D\": Circle(radius=0.4, color=RED, fill_opacity=0.3),\n }\n \n # Position nodes in a diamond pattern\n nodes[\"A\"].move_to(UP * 2)\n nodes[\"B\"].move_to(LEFT * 2 + DOWN * 0.5)\n nodes[\"C\"].move_to(RIGHT * 2 + DOWN * 0.5)\n nodes[\"D\"].move_to(DOWN * 3)\n \n # Node labels\n labels = {\n \"A\": Text(\"A\", font_size=32).move_to(nodes[\"A\"].get_center()),\n \"B\": Text(\"B\", font_size=32).move_to(nodes[\"B\"].get_center()),\n \"C\": Text(\"C\", font_size=32).move_to(nodes[\"C\"].get_center()),\n \"D\": Text(\"D\", font_size=32).move_to(nodes[\"D\"].get_center()),\n }\n \n # Task descriptions\n task_desc = VGroup(\n Text(\"A: Wake up\", font_size=20),\n Text(\"B: Brush teeth\", font_size=20),\n Text(\"C: Eat breakfast\", font_size=20),\n Text(\"D: Leave house\", font_size=20),\n ).arrange(DOWN, aligned_edge=LEFT, buff=0.2)\n task_desc\n task_desc\n \n with self.voiceover(text=\"Here we have four daily tasks. You must wake up before brushing teeth or eating breakfast. And you must brush teeth and eat breakfast before leaving the house.\") as tracker:\n self.play(\n *[Create(nodes[n]) for n in nodes],\n *[Write(labels[n]) for n in labels],\n run_time=tracker.duration * 0.6\n )\n self.play(Write(task_desc), run_time=tracker.duration * 0.4)\n \n self.wait(0.3)\n \n # Create edges with arrows\n edges = {\n \"AB\": Arrow(nodes[\"A\"].get_bottom() + LEFT*0.1, nodes[\"B\"].get_top() + UP*0.1, buff=0.1, color=WHITE),\n \"AC\": Arrow(nodes[\"A\"].get_bottom() + RIGHT*0.1, nodes[\"C\"].get_top() + UP*0.1, buff=0.1, color=WHITE),\n \"BD\": Arrow(nodes[\"B\"].get_bottom(), nodes[\"D\"].get_top() + LEFT*0.1, buff=0.1, color=WHITE),\n \"CD\": Arrow(nodes[\"C\"].get_bottom(), nodes[\"D\"].get_top() + RIGHT*0.1, buff=0.1, color=WHITE),\n }\n \n with self.voiceover(text=\"These arrows represent dependencies. An arrow from A to B means task A must be completed before task B.\") as tracker:\n self.play(*[Create(edges[e]) for e in edges], run_time=tracker.duration)\n \n self.wait(0.3)\n \n # Show in-degrees\n in_degree_title = Text(\"In-Degree (incoming arrows):\", font_size=24, color=YELLOW)\n in_degree_title.to_edge(LEFT, buff=0.3)\n in_degree_title.shift(UP * 1.5)\n \n in_degrees = VGroup(\n Text(\"A: 0\", font_size=22, color=YELLOW),\n Text(\"B: 1\", font_size=22, color=YELLOW),\n Text(\"C: 1\", font_size=22, color=YELLOW),\n Text(\"D: 2\", font_size=22, color=YELLOW),\n ).arrange(DOWN, aligned_edge=LEFT, buff=0.2)\n in_degrees.next_to(in_degree_title, DOWN, buff=0.2)\n \n with self.voiceover(text=\"To find a valid order, we use in-degrees — the count of incoming arrows. Task A has zero, so it can start immediately. Tasks B and C each need one prerequisite. Task D needs both B and C.\") as tracker:\n self.play(Write(in_degree_title), run_time=tracker.duration * 0.3)\n self.play(Write(in_degrees), run_time=tracker.duration * 0.7)\n \n self.wait(0.3)\n \n # Start topological sort visualization\n sort_title = Text(\"Topological Sort:\", font_size=28, color=ORANGE)\n sort_title.to_edge(DOWN, buff=1.5)\n \n sorted_order = []\n order_display = Text(\"\", font_size=24, color=ORANGE)\n order_display.next_to(sort_title, DOWN, buff=0.2)\n \n with self.voiceover(text=\"Now let's perform the topological sort. We repeatedly pick nodes with zero in-degree.\") as tracker:\n self.play(Write(sort_title), run_time=tracker.duration)\n \n self.wait(0.3)\n \n # Step 1: Pick A\n with self.voiceover(text=\"Task A has zero in-degree. We add it to our sorted order.\") as tracker:\n sorted_order.append(\"A\")\n order_display.become(Text(\"Order: [A]\", font_size=24, color=ORANGE).next_to(sort_title, DOWN, buff=0.2))\n self.play(\n nodes[\"A\"].animate.set_fill(YELLOW, opacity=0.8),\n FadeIn(order_display),\n run_time=tracker.duration * 0.5\n )\n # Remove outgoing edges from A\n self.play(\n edges[\"AB\"].animate.set_color(YELLOW),\n edges[\"AC\"].animate.set_color(YELLOW),\n run_time=tracker.duration * 0.3\n )\n self.play(\n FadeOut(edges[\"AB\"]),\n FadeOut(edges[\"AC\"]),\n run_time=tracker.duration * 0.2\n )\n \n self.wait(0.2)\n \n # Update in-degrees: B and C now have 0\n new_in_degrees = VGroup(\n Text(\"A: done\", font_size=22, color=GRAY),\n Text(\"B: 0\", font_size=22, color=YELLOW),\n Text(\"C: 0\", font_size=22, color=YELLOW),\n Text(\"D: 2\", font_size=22, color=YELLOW),\n ).arrange(DOWN, aligned_edge=LEFT, buff=0.2)\n new_in_degrees.next_to(in_degree_title, DOWN, buff=0.2)\n \n with self.voiceover(text=\"Removing A reduces B and C to zero in-degrees. Now either can come next.\") as tracker:\n self.play(Transform(in_degrees, new_in_degrees), run_time=tracker.duration)\n \n self.wait(0.2)\n \n # Step 2: Pick B\n with self.voiceover(text=\"Let's pick B. We add it to our order.\") as tracker:\n sorted_order.append(\"B\")\n order_display.become(Text(\"Order: [A, B]\", font_size=24, color=ORANGE).next_to(sort_title, DOWN, buff=0.2))\n self.play(\n nodes[\"B\"].animate.set_fill(YELLOW, opacity=0.8),\n FadeOut(order_display),\n run_time=tracker.duration * 0.3\n )\n order_display = Text(\"Order: [A, B]\", font_size=24, color=ORANGE).next_to(sort_title, DOWN, buff=0.2)\n self.play(FadeIn(order_display), run_time=tracker.duration * 0.2)\n # Remove edge B->D\n self.play(edges[\"BD\"].animate.set_color(YELLOW), run_time=tracker.duration * 0.3)\n self.play(FadeOut(edges[\"BD\"]), run_time=tracker.duration * 0.2)\n \n self.wait(0.2)\n \n # Update in-degrees\n new_in_degrees2 = VGroup(\n Text(\"A: done\", font_size=22, color=GRAY),\n Text(\"B: done\", font_size=22, color=GRAY),\n Text(\"C: 0\", font_size=22, color=YELLOW),\n Text(\"D: 1\", font_size=22, color=YELLOW),\n ).arrange(DOWN, aligned_edge=LEFT, buff=0.2)\n new_in_degrees2.next_to(in_degree_title, DOWN, buff=0.2)\n \n with self.voiceover(text=\"B is done. D's in-degree drops to one, but D still needs C.\") as tracker:\n self.play(Transform(in_degrees, new_in_degrees2), run_time=tracker.duration)\n \n self.wait(0.2)\n \n # Step 3: Pick C\n with self.voiceover(text=\"C now has zero in-degree, so we add it next.\") as tracker:\n sorted_order.append(\"C\")\n order_display.become(Text(\"Order: [A, B, C]\", font_size=24, color=ORANGE).next_to(sort_title, DOWN, buff=0.2))\n self.play(\n nodes[\"C\"].animate.set_fill(YELLOW, opacity=0.8),\n FadeOut(order_display),\n run_time=tracker.duration * 0.3\n )\n order_display = Text(\"Order: [A, B, C]\", font_size=24, color=ORANGE).next_to(sort_title, DOWN, buff=0.2)\n self.play(FadeIn(order_display), run_time=tracker.duration * 0.2)\n # Remove edge C->D\n self.play(edges[\"CD\"].animate.set_color(YELLOW), run_time=tracker.duration * 0.3)\n self.play(FadeOut(edges[\"CD\"]), run_time=tracker.duration * 0.2)\n \n self.wait(0.2)\n \n # Update in-degrees\n new_in_degrees3 = VGroup(\n Text(\"A: done\", font_size=22, color=GRAY),\n Text(\"B: done\", font_size=22, color=GRAY),\n Text(\"C: done\", font_size=22, color=GRAY),\n Text(\"D: 0\", font_size=22, color=YELLOW),\n ).arrange(DOWN, aligned_edge=LEFT, buff=0.2)\n new_in_degrees3.next_to(in_degree_title, DOWN, buff=0.2)\n \n with self.voiceover(text=\"C is done. D's in-degree is now zero.\") as tracker:\n self.play(Transform(in_degrees, new_in_degrees3), run_time=tracker.duration)\n \n self.wait(0.2)\n \n # Step 4: Pick D\n with self.voiceover(text=\"Finally, we add D to complete the topological sort.\") as tracker:\n sorted_order.append(\"D\")\n order_display.become(Text(\"Order: [A, B, C, D]\", font_size=24, color=ORANGE).next_to(sort_title, DOWN, buff=0.2))\n self.play(\n nodes[\"D\"].animate.set_fill(YELLOW, opacity=0.8),\n FadeOut(order_display),\n run_time=tracker.duration * 0.5\n )\n order_display = Text(\"Order: [A, B, C, D]\", font_size=24, color=ORANGE).next_to(sort_title, DOWN, buff=0.2)\n self.play(FadeIn(order_display), run_time=tracker.duration * 0.5)\n \n self.wait(0.3)\n \n # Show alternative valid sort\n alt_text = Text(\"Alternative valid order: [A, C, B, D]\", font_size=22, color=GREEN)\n alt_text.next_to(order_display, DOWN, buff=0.3)\n \n with self.voiceover(text=\"This gives us the order: wake up, brush teeth, eat breakfast, leave house. Note that A, C, B, D is also valid because B and C have no dependencies between them.\") as tracker:\n self.play(Write(alt_text), run_time=tracker.duration)\n \n self.wait(0.3)\n \n # Highlight what makes a sort invalid\n invalid_text = Text(\"Invalid: [B, A, ...] — B depends on A!\", font_size=22, color=RED)\n invalid_text.next_to(alt_text, DOWN, buff=0.3)\n \n with self.voiceover(text=\"However, starting with B would be invalid because B depends on A. A topological sort must respect all dependencies.\") as tracker:\n self.play(Write(invalid_text), run_time=tracker.duration)\n \n self.wait(0.5)\n \n # Final summary\n self.play(\n FadeOut(invalid_text),\n FadeOut(alt_text),\n FadeOut(in_degree_title),\n FadeOut(in_degrees),\n FadeOut(task_desc),\n )\n \n summary = VGroup(\n Text(\"Key Takeaways:\", font_size=28, color=BLUE),\n Text(\"• Topological sort orders tasks by dependencies\", font_size=22),\n Text(\"• Use in-degrees to find starting nodes\", font_size=22),\n Text(\"• Remove edges as nodes are processed\", font_size=22),\n Text(\"• Multiple valid orders may exist\", font_size=22),\n ).arrange(DOWN, aligned_edge=LEFT, buff=0.3)\n summary.move_to(ORIGIN)\n summary.shift(UP * 0.5)\n \n with self.voiceover(text=\"To summarize: topological sort organizes tasks based on dependencies. We use in-degrees to find starting points, remove edges as we process nodes, and understand that multiple valid orderings can exist.\") as tracker:\n self.play(\n FadeOut(title),\n *[FadeOut(nodes[n]) for n in nodes],\n *[FadeOut(labels[n]) for n in labels],\n FadeOut(sort_title),\n FadeOut(order_display),\n run_time=tracker.duration * 0.3\n )\n self.play(Write(summary), run_time=tracker.duration * 0.7)\n \n self.wait(1)\n```", "category": "spatial_layout_overlap", "source": "synthetic_hard_neg:nabin2004/AOS-Narrated-Manim-400"} +{"system": "You are an expert Manim Community Edition (ManimCE v0.19+) Python developer and mathematical animator. Given a user request, first plan the spatial layout, coordinate bounds, timing, and pedagogical flow inside ... tags (when reasoning is helpful), and then output a complete, runnable, self-contained ManimCE Python script using `from manim import *`. Never use deprecated ManimGL (`manimlib`) methods like `ShowCreation`, `TexMobject`, `TextMobject`, or `axes.get_graph`; always use modern ManimCE APIs (`Create`, `MathTex`, `Tex`, `Text`, `axes.plot`) and prevent visual overlap using `.to_edge()`, `.next_to()`, and `FadeOut`.", "prompt": "Create an interactive Manim CE animation demonstrating: Orbital mechanics simulation using add_updater with dt. Use updaters and ValueTracker.\n\n```python\nfrom manim import *\nimport numpy as np\n\nclass DynamicScene923(Scene):\n def construct(self):\n sun = Dot(ORIGIN, radius=0.25, color=GOLD)\n planet = Dot(RIGHT * 2.5, radius=0.12, color=BLUE)\n trail = TracedPath(planet.get_center, stroke_color=BLUE_A, stroke_width=2, stroke_opacity=0.8)\n \n angle = [0.0]\n omega = 1.5 # rad/s\n \n def update_planet(mob, dt):\n angle[0] += omega * dt\n mob.move_to(np.array([2.5 * np.cos(angle[0]), 1.8 * np.sin(angle[0]), 0]))\n \n planet.add_updater(update_planet)\n self.add(sun, trail, planet)\n self.wait(4)\n planet.clear_updaters()\n```", "chosen": "```python\nfrom manim import *\nfrom manim_voiceover import VoiceoverScene\nfrom manim_voiceover.services.gtts import GTTSService\nimport numpy as np\n\nMARGIN = 0.5\n\nclass DynamicScene923(VoiceoverScene):\n def fit_in_frame(self, mob: Mobject, w_frac=0.9, h_frac=0.9) -> Mobject:\n max_w = config.frame_width * w_frac\n max_h = config.frame_height * h_frac\n if mob.width > max_w: mob.width = max_w\n if mob.height > max_h: mob.height = max_h\n return mob\n\n def construct(self):\n self.set_speech_service(GTTSService(transcription_model=\"base\"))\n \n # [SETUP]\n sun = Dot(ORIGIN, radius=0.25, color=GOLD)\n planet = Dot(RIGHT * 2.5, radius=0.12, color=BLUE)\n trail = TracedPath(planet.get_center, stroke_color=BLUE_A, stroke_width=2, stroke_opacity=0.8)\n \n angle = [0.0]\n omega = 1.5\n time_tracker = ValueTracker(0.0)\n \n # [LAYOUT]\n title = MathTex(r\"\\text{Orbital Mechanics}\").to_edge(UP, buff=MARGIN)\n self.fit_in_frame(title)\n \n # [UPDATER]\n def update_planet(mob, dt):\n angle[0] += omega * dt\n time_tracker.set_value(angle[0])\n mob.move_to(np.array([2.5 * np.cos(angle[0]), 1.8 * np.sin(angle[0]), 0]))\n \n planet.add_updater(update_planet)\n angle_label = DecimalNumber(0, num_decimal_places=2, color=BLUE).to_corner(UR)\n angle_label.add_updater(lambda m: m.set_value(time_tracker.get_value()))\n \n self.add(title, sun, trail, planet, angle_label)\n \n # [BEAT 1 | sync: b1]\n with self.voiceover(text=\"The planet orbits the sun in an elliptical path, driven by a time-based updater. \") as t:\n self.wait_until_bookmark(\"b1\")\n self.wait(4)\n \n planet.clear_updaters()\n self.wait(1)\n```", "rejected": "```python\nfrom manim import *\nfrom manim_voiceover import VoiceoverScene\nfrom manim_voiceover.services.gtts import GTTSService\nimport numpy as np\n\nMARGIN = 0.5\n\nclass DynamicScene923(VoiceoverScene):\n def fit_in_frame(self, mob: Mobject, w_frac=0.9, h_frac=0.9) -> Mobject:\n max_w = config.frame_width * w_frac\n max_h = config.frame_height * h_frac\n if mob.width > max_w: mob.width = max_w\n if mob.height > max_h: mob.height = max_h\n return mob\n\n def construct(self):\n self.set_speech_service(GTTSService(transcription_model=\"base\"))\n \n # [SETUP]\n sun = Dot(ORIGIN, radius=0.25, color=GOLD)\n planet = Dot(RIGHT * 2.5, radius=0.12, color=BLUE)\n trail = TracedPath(planet.get_center, stroke_color=BLUE_A, stroke_width=2, stroke_opacity=0.8)\n \n angle = [0.0]\n omega = 1.5\n time_tracker = ValueTracker(0.0)\n \n # [LAYOUT]\n title = TexMobject(r\"\\text{Orbital Mechanics}\").to_edge(UP, buff=MARGIN)\n self.fit_in_frame(title)\n \n # [UPDATER]\n def update_planet(mob, dt):\n angle[0] += omega * dt\n time_tracker.set_value(angle[0])\n mob.move_to(np.array([2.5 * np.cos(angle[0]), 1.8 * np.sin(angle[0]), 0]))\n \n planet.add_updater(update_planet)\n angle_label = DecimalNumber(0, num_decimal_places=2, color=BLUE).to_corner(UR)\n angle_label.add_updater(lambda m: m.set_value(time_tracker.get_value()))\n \n self.add(title, sun, trail, planet, angle_label)\n \n # [BEAT 1 | sync: b1]\n with self.voiceover(text=\"The planet orbits the sun in an elliptical path, driven by a time-based updater. \") as t:\n self.wait_until_bookmark(\"b1\")\n self.wait(4)\n \n planet.clear_updaters()\n self.wait(1)\n```", "category": "legacy_api_hallucination", "source": "synthetic_hard_neg:nabin2004/qwen3-8b-manimator-gold-sft"} +{"system": "You are an expert Manim Community Edition (ManimCE v0.19+) Python developer and mathematical animator. Given a user request, first plan the spatial layout, coordinate bounds, timing, and pedagogical flow inside ... tags (when reasoning is helpful), and then output a complete, runnable, self-contained ManimCE Python script using `from manim import *`. Never use deprecated ManimGL (`manimlib`) methods like `ShowCreation`, `TexMobject`, `TextMobject`, or `axes.get_graph`; always use modern ManimCE APIs (`Create`, `MathTex`, `Tex`, `Text`, `axes.plot`) and prevent visual overlap using `.to_edge()`, `.next_to()`, and `FadeOut`.", "prompt": "Here is the enhanced animation instruction that builds upon the original while adding significant new features:\n\nThe enhanced animation begins by displaying the function f(x) = x² with a smooth fade-in effect, then introduces a labeled coordinate plane that appears beneath it with axes from 0 to 2 on the x-axis and 0 to 4 on the y-axis. As the explanation text about calculating the area under the curve appears at the top, the curve x² is plotted point-by-point with a moving dot tracer, leaving a glowing trail. The definite integral formula then transforms from the function while simultaneously, the area under the curve begins filling with a gradient that starts at the left boundary and smoothly expands rightward, synchronized with the integral's evaluation. During the solution steps, each mathematical transformation is accompanied by corresponding visual changes: when showing the antiderivative (1/3)x³, the filled area pulses to emphasize its connection to the formula, and when evaluating at the bounds, vertical lines appear at x=0 and x=2 with animated height adjustments to show the evaluation points. The final result 8/3 appears while the filled area pulses gold, and as a new feature, a Riemann sum visualization emerges beside it - first as rectangles that approximate the area, then morphing into the exact integral area, with a text explanation comparing the two methods. The scene concludes by highlighting both the exact solution and the Riemann sum approximation together, demonstrating the fundamental theorem of calculus visually. Throughout the animation, all text and formulas are rendered with LaTeX for clarity, and smooth transitions connect each conceptual step.", "chosen": "```python\nfrom manim import *\n\nclass EnhancedIntegralVisualization(Scene):\n def construct(self):\n # Create axes\n axes = Axes(\n x_range=[0, 2.2, 0.5],\n y_range=[0, 4.2, 1],\n x_length=6,\n y_length=5,\n axis_config={\"color\": BLUE},\n x_axis_config={\n \"numbers_to_include\": [0, 1, 2],\n \"numbers_with_elongated_ticks\": [0, 1, 2],\n },\n y_axis_config={\n \"numbers_to_include\": [0, 1, 2, 3, 4],\n \"numbers_with_elongated_ticks\": [0, 1, 2, 3, 4],\n },\n )\n axes_labels = axes.get_axis_labels(x_label=\"x\", y_label=\"f(x)\")\n\n # Create function curve\n func = axes.plot(lambda x: x**2, color=YELLOW)\n func_label = MathTex(\"f(x) = x^2\", color=YELLOW).next_to(func, UR, buff=0.2)\n\n # Introduction animation\n self.play(FadeIn(axes), FadeIn(axes_labels))\n self.play(Create(func), Write(func_label))\n self.wait(0.5)\n\n # Add explanation text\n explanation = Text(\"Area under the curve from x=0 to x=2\", font_size=24).to_edge(UP)\n self.play(Write(explanation))\n self.wait()\n\n # Animate plotting the curve with a moving dot\n dot = Dot(color=RED).move_to(axes.c2p(0, 0))\n self.play(FadeIn(dot))\n self.play(\n MoveAlongPath(dot, func, rate_func=linear),\n run_time=2\n )\n self.play(FadeOut(dot))\n\n # Show integral formula\n integral = MathTex(r\"\\int_{0}^{2} x^2 \\,dx\").next_to(explanation, DOWN)\n self.play(Write(integral))\n self.wait()\n\n # Fill area under curve\n area = axes.get_area(func, x_range=[0, 2], color=[BLUE, GREEN])\n self.play(FadeIn(area))\n self.wait()\n\n # Show antiderivative\n antiderivative = MathTex(r\"\\frac{1}{3}x^3 \\Big|_{0}^{2}\").next_to(integral, DOWN)\n self.play(Transform(integral.copy(), antiderivative))\n self.play(Flash(area, color=YELLOW, line_length=0.3))\n self.wait()\n\n # Evaluate at bounds\n eval_text = MathTex(r\"\\frac{1}{3}(2)^3 - \\frac{1}{3}(0)^3\").next_to(antiderivative, DOWN)\n self.play(Transform(antiderivative.copy(), eval_text))\n \n # Show vertical lines at bounds\n line1 = DashedLine(\n start=axes.c2p(0, 0),\n end=axes.c2p(0, 4),\n color=RED\n )\n line2 = DashedLine(\n start=axes.c2p(2, 0),\n end=axes.c2p(2, 4),\n color=RED\n )\n self.play(Create(line1), Create(line2))\n self.wait()\n\n # Final calculation\n result = MathTex(r\"\\frac{8}{3}\").next_to(eval_text, DOWN)\n self.play(Transform(eval_text.copy(), result))\n self.play(Flash(area, color=GOLD, line_length=0.5))\n self.wait()\n\n # Riemann sum visualization\n riemann_group = VGroup()\n riemann_axes = axes.copy().shift(RIGHT*3.5)\n riemann_func = riemann_axes.plot(lambda x: x**2, color=YELLOW)\n riemann_area = riemann_axes.get_riemann_rectangles(\n riemann_func, x_range=[0, 2], dx=0.5, color=[BLUE, GREEN], fill_opacity=0.6\n )\n riemann_text = Text(\"Riemann Sum Approximation\", font_size=20).next_to(riemann_axes, UP)\n riemann_group.add(riemann_axes, riemann_func, riemann_area, riemann_text)\n\n self.play(\n FadeIn(riemann_axes),\n FadeIn(riemann_func),\n Write(riemann_text)\n )\n self.play(Create(riemann_area))\n self.wait()\n\n # Morph Riemann sum to exact area\n exact_area = riemann_axes.get_area(riemann_func, x_range=[0, 2], color=[BLUE, GREEN])\n comparison_text = Text(\"Approach to Exact Area\", font_size=20).move_to(riemann_text)\n \n self.play(\n ReplacementTransform(riemann_area, exact_area),\n Transform(riemann_text, comparison_text)\n )\n self.wait()\n\n # Highlight both methods\n ftc_text = Text(\"Fundamental Theorem of Calculus\", font_size=24).to_edge(DOWN)\n self.play(Write(ftc_text))\n self.play(\n Flash(area, color=YELLOW),\n Flash(exact_area, color=YELLOW)\n )\n self.wait(2)\n```", "rejected": "```python\nfrom manim import *\n\nclass EnhancedIntegralVisualization(Scene):\n def construct(self):\n # Create axes\n axes = Axes(axis_color=BLUE, \n x_range=[0, 2.2, 0.5],\n y_range=[0, 4.2, 1],\n x_length=6,\n y_length=5,\n axis_config={\"color\": BLUE},\n x_axis_config={\n \"numbers_to_include\": [0, 1, 2],\n \"numbers_with_elongated_ticks\": [0, 1, 2],\n },\n y_axis_config={\n \"numbers_to_include\": [0, 1, 2, 3, 4],\n \"numbers_with_elongated_ticks\": [0, 1, 2, 3, 4],\n },\n )\n axes_labels = axes.get_axis_labels(x_label=\"x\", y_label=\"f(x)\")\n\n # Create function curve\n func = axes.plot(lambda x: x**2, color=YELLOW)\n func_label = MathTex(\"f(x) = x^2\", color=YELLOW).next_to(func, UR, buff=0.2)\n\n # Introduction animation\n self.play(FadeIn(axes), FadeIn(axes_labels))\n self.play(Create(func), Write(func_label))\n self.wait(0.5)\n\n # Add explanation text\n explanation = Text(\"Area under the curve from x=0 to x=2\", font_size=24).to_edge(UP)\n self.play(Write(explanation))\n self.wait()\n\n # Animate plotting the curve with a moving dot\n dot = Dot(color=RED).move_to(axes.c2p(0, 0))\n self.play(FadeIn(dot))\n self.play(\n MoveAlongPath(dot, func, rate_func=linear),\n run_time=2\n )\n self.play(FadeOut(dot))\n\n # Show integral formula\n integral = MathTex(r\"\\int_{0}^{2} x^2 \\,dx\").next_to(explanation, DOWN)\n self.play(Write(integral))\n self.wait()\n\n # Fill area under curve\n area = axes.get_area(func, x_range=[0, 2], color=[BLUE, GREEN])\n self.play(FadeIn(area))\n self.wait()\n\n # Show antiderivative\n antiderivative = MathTex(r\"\\frac{1}{3}x^3 \\Big|_{0}^{2}\").next_to(integral, DOWN)\n self.play(Transform(integral.copy(), antiderivative))\n self.play(Flash(area, color=YELLOW, line_length=0.3))\n self.wait()\n\n # Evaluate at bounds\n eval_text = MathTex(r\"\\frac{1}{3}(2)^3 - \\frac{1}{3}(0)^3\").next_to(antiderivative, DOWN)\n self.play(Transform(antiderivative.copy(), eval_text))\n \n # Show vertical lines at bounds\n line1 = DashedLine(\n start=axes.c2p(0, 0),\n end=axes.c2p(0, 4),\n color=RED\n )\n line2 = DashedLine(\n start=axes.c2p(2, 0),\n end=axes.c2p(2, 4),\n color=RED\n )\n self.play(Create(line1), Create(line2))\n self.wait()\n\n # Final calculation\n result = MathTex(r\"\\frac{8}{3}\").next_to(eval_text, DOWN)\n self.play(Transform(eval_text.copy(), result))\n self.play(Flash(area, color=GOLD, line_length=0.5))\n self.wait()\n\n # Riemann sum visualization\n riemann_group = VGroup()\n riemann_axes = axes.copy().shift(RIGHT*3.5)\n riemann_func = riemann_axes.plot(lambda x: x**2, color=YELLOW)\n riemann_area = riemann_axes.get_riemann_rectangles(\n riemann_func, x_range=[0, 2], dx=0.5, color=[BLUE, GREEN], fill_opacity=0.6\n )\n riemann_text = Text(\"Riemann Sum Approximation\", font_size=20).next_to(riemann_axes, UP)\n riemann_group.add(riemann_axes, riemann_func, riemann_area, riemann_text)\n\n self.play(\n FadeIn(riemann_axes),\n FadeIn(riemann_func),\n Write(riemann_text)\n )\n self.play(Create(riemann_area))\n self.wait()\n\n # Morph Riemann sum to exact area\n exact_area = riemann_axes.get_area(riemann_func, x_range=[0, 2], color=[BLUE, GREEN])\n comparison_text = Text(\"Approach to Exact Area\", font_size=20).move_to(riemann_text)\n \n self.play(\n ReplacementTransform(riemann_area, exact_area),\n Transform(riemann_text, comparison_text)\n )\n self.wait()\n\n # Highlight both methods\n ftc_text = Text(\"Fundamental Theorem of Calculus\", font_size=24).to_edge(DOWN)\n self.play(Write(ftc_text))\n self.play(\n Flash(area, color=YELLOW),\n Flash(exact_area, color=YELLOW)\n )\n self.wait(2)\n```", "category": "invalid_axes_kwarg", "source": "synthetic_hard_neg:nabin2004/manim-sft-10k"} +{"system": "You are an expert Manim Community Edition (ManimCE v0.19+) Python developer and mathematical animator. Given a user request, first plan the spatial layout, coordinate bounds, timing, and pedagogical flow inside ... tags (when reasoning is helpful), and then output a complete, runnable, self-contained ManimCE Python script using `from manim import *`. Never use deprecated ManimGL (`manimlib`) methods like `ShowCreation`, `TexMobject`, `TextMobject`, or `axes.get_graph`; always use modern ManimCE APIs (`Create`, `MathTex`, `Tex`, `Text`, `axes.plot`) and prevent visual overlap using `.to_edge()`, `.next_to()`, and `FadeOut`.", "prompt": "I'm an instructor designing a Manim video for a sophomore linear algebra class; prerequisite: vectors, matrix multiplication, and basic eigen/SVD ideas. Create a visual that builds intuition for singular value decomposition: A = U Σ V^T with singular values as scaling along principal axes. Show multiple scenes: a 2D/3D linear map acting on shapes (unit circle to ellipse), then reconstruction with rank-k approximations, and a tiny data cloud compressed into lower dimensions. I want intuition first, then equations on screen, with smooth scene transitions and camera moves; include a plot of the singular value spectrum and discuss truncation error and PCA intuition. End with a brief note on real-world applications and when SVD is especially useful.", "chosen": "```python\nfrom manim import *\nfrom manim_voiceover import VoiceoverScene\nfrom manim_voiceover.services.gtts import GTTSService\n\nclass SVDExplanationSophomore(VoiceoverScene):\n def construct(self):\n # [SETUP]\n # [LAYOUT]\n self.set_speech_service(GTTSService(transcription_model=\"base\"))\n\n # [BEAT 1 | sync: FORMULA]\n with self.voiceover(text=\"Singular Value Decomposition reveals the hidden structure of data. Any matrix A can be factored into U, Sigma, and V transpose.\") as tracker:\n title = Text(\"Singular Value Decomposition\", font_size=42)\n self.fit_in_frame(title)\n eq = MathTex(\"A\", \"=\", \"U\", \"\\\\Sigma\", \"V^T\")\n eq[2].set_color(BLUE)\n eq[3].set_color(YELLOW)\n eq[4].set_color(GREEN)\n group = VGroup(title, eq).arrange(DOWN)\n self.wait_until_bookmark(\"FORMULA\")\n self.play(Write(group), run_time=tracker.duration)\n self.play(group.animate.scale(0.6).to_edge(UP), run_time=0.5)\n\n with self.voiceover(text=\"Geometrically, a matrix transforms a unit circle into an ellipse. The axes of this ellipse are the singular vectors, and their lengths are the singular values.\") as tracker:\n circle = Circle(radius=1.2, color=GREEN)\n self.wait_until_bookmark(\"CIRCLE\")\n self.play(Create(circle), run_time=tracker.duration * 0.4)\n \n ellipse = Ellipse(width=3.0, height=1.2, color=YELLOW)\n self.wait_until_bookmark(\"ELLIPSE\")\n self.play(Transform(circle, ellipse), run_time=tracker.duration * 0.6)\n \n major = Line(ellipse.get_center() + LEFT * 1.5, ellipse.get_center() + RIGHT * 1.5, color=RED)\n self.play(Create(major), run_time=1)\n\n with self.voiceover(text=\"By keeping only the largest singular values, we can compress data, discarding noise while preserving the essential structure.\") as tracker:\n self.wait_until_bookmark(\"RANK\")\n approximation = Text(\"Rank-k Approximation: A ≈ U_k Σ_k V_k^T\", font_size=28, color=BLUE)\n self.play(Write(approximation), run_time=tracker.duration)\n self.wait(1)\n\n def fit_in_frame(self, mob: Mobject, w_frac: float = 0.9, h_frac: float = 0.9) -> Mobject:\n max_w = config.frame_width * w_frac\n max_h = config.frame_height * h_frac\n if mob.width > max_w:\n mob.width = max_w\n if mob.height > max_h:\n mob.height = max_h\n return mob\n```", "rejected": "```python\nfrom manim import *\nfrom manim_voiceover import VoiceoverScene\nfrom manim_voiceover.services.gtts import GTTSService\n\nclass SVDExplanationSophomore(VoiceoverScene):\n def construct(self):\n # [SETUP]\n # [LAYOUT]\n self.set_speech_service(GTTSService(transcription_model=\"base\"))\n\n # [BEAT 1 | sync: FORMULA]\n with self.voiceover(text=\"Singular Value Decomposition reveals the hidden structure of data. Any matrix A can be factored into U, Sigma, and V transpose.\") as tracker:\n title = Text(\"Singular Value Decomposition\", font_size=42)\n self.fit_in_frame(title)\n eq = TexMobject(\"A\", \"=\", \"U\", \"\\\\Sigma\", \"V^T\")\n eq[2].set_color(BLUE)\n eq[3].set_color(YELLOW)\n eq[4].set_color(GREEN)\n group = VGroup(title, eq).arrange(DOWN)\n self.wait_until_bookmark(\"FORMULA\")\n self.play(Write(group), run_time=tracker.duration)\n self.play(group.animate.scale(0.6).to_edge(UP), run_time=0.5)\n\n with self.voiceover(text=\"Geometrically, a matrix transforms a unit circle into an ellipse. The axes of this ellipse are the singular vectors, and their lengths are the singular values.\") as tracker:\n circle = Circle(radius=1.2, color=GREEN)\n self.wait_until_bookmark(\"CIRCLE\")\n self.play(ShowCreation(circle), run_time=tracker.duration * 0.4)\n \n ellipse = Ellipse(width=3.0, height=1.2, color=YELLOW)\n self.wait_until_bookmark(\"ELLIPSE\")\n self.play(Transform(circle, ellipse), run_time=tracker.duration * 0.6)\n \n major = Line(ellipse.get_center() + LEFT * 1.5, ellipse.get_center() + RIGHT * 1.5, color=RED)\n self.play(Create(major), run_time=1)\n\n with self.voiceover(text=\"By keeping only the largest singular values, we can compress data, discarding noise while preserving the essential structure.\") as tracker:\n self.wait_until_bookmark(\"RANK\")\n approximation = Text(\"Rank-k Approximation: A ≈ U_k Σ_k V_k^T\", font_size=28, color=BLUE)\n self.play(Write(approximation), run_time=tracker.duration)\n self.wait(1)\n\n def fit_in_frame(self, mob: Mobject, w_frac: float = 0.9, h_frac: float = 0.9) -> Mobject:\n max_w = config.frame_width * w_frac\n max_h = config.frame_height * h_frac\n if mob.width > max_w:\n mob.width = max_w\n if mob.height > max_h:\n mob.height = max_h\n return mob\n```", "category": "legacy_api_hallucination", "source": "synthetic_hard_neg:nabin2004/qwen3-8b-manimator-gold-sft"} +{"system": "You are an expert Manim Community Edition (ManimCE v0.19+) Python developer and mathematical animator. Given a user request, first plan the spatial layout, coordinate bounds, timing, and pedagogical flow inside ... tags (when reasoning is helpful), and then output a complete, runnable, self-contained ManimCE Python script using `from manim import *`. Never use deprecated ManimGL (`manimlib`) methods like `ShowCreation`, `TexMobject`, `TextMobject`, or `axes.get_graph`; always use modern ManimCE APIs (`Create`, `MathTex`, `Tex`, `Text`, `axes.plot`) and prevent visual overlap using `.to_edge()`, `.next_to()`, and `FadeOut`.", "prompt": "I'm teaching an advanced ML course and want a visualization of Bayesian optimization for RL where model-based planning is guided by neuroevolution.\nShow a population of neural policies evolving, with Bayesian optimization selecting promising candidates under model-based rollouts and constraints.\nDepict the surrogate updates, model-based simulations, and a multi-fidelity budget showing sample efficiency and robustness.\nInclude transitions illustrating policy improvement over generations and a side plot comparing sample efficiency against purely gradient-based methods.", "chosen": "```python\nfrom manim import *\nfrom manim_voiceover import VoiceoverScene\nfrom manim_voiceover.services.gtts import GTTSService\n\nclass BONeuroevolutionScene(VoiceoverScene):\n def construct(self):\n # [SETUP]\n # [LAYOUT]\n self.set_speech_service(GTTSService(transcription_model=\"base\"))\n\n # [BEAT 1 | sync: POP]\n with self.voiceover(text=\"Bayesian Optimization can guide neuroevolution in reinforcement learning. We start with a population of neural policies, each representing a different set of hyperparameters or architecture choices.\") as tracker:\n title = Text(\"BO-Guided Neuroevolution\", font_size=36, color=BLUE)\n self.fit_in_frame(title)\n title.to_edge(UP)\n \n policies = VGroup(*[\n VGroup(\n Circle(radius=0.3, color=BLUE, fill_opacity=0.5),\n Text(f\"P{i+1}\", font_size=14)\n ).arrange(ORIGIN) for i in range(6)\n ]).arrange(RIGHT, buff=0.8).shift(UP)\n \n self.wait_until_bookmark(\"POP\")\n self.play(Write(title), Create(policies), run_time=tracker.duration)\n\n with self.voiceover(text=\"We evaluate these policies using model-based rollouts. A Gaussian Process surrogate models the reward landscape, capturing both the expected performance and the uncertainty of each candidate.\") as tracker:\n axes = Axes(x_range=[0, 6, 1], y_range=[0, 5, 1], x_length=8, y_length=3)\n axes.shift(DOWN * 1.5)\n \n gp_mean = axes.plot(lambda x: 2 + np.sin(x), color=BLUE, stroke_width=2)\n band = VGroup(*[\n Line(\n axes.c2p(x, 2 + np.sin(x) - 0.8), \n axes.c2p(x, 2 + np.sin(x) + 0.8), \n stroke_width=1, color=BLUE\n ).set_opacity(0.15) for x in np.linspace(0, 6, 40)\n ])\n \n self.wait_until_bookmark(\"GP\")\n self.play(Create(axes), Create(band), Create(gp_mean), run_time=tracker.duration)\n\n with self.voiceover(text=\"Finally, the acquisition function balances exploration and exploitation. It selects the most promising policy to evaluate next, efficiently navigating the multi-fidelity budget to find a robust, high-performing agent.\") as tracker:\n acq_peak = Dot(axes.c2p(4.5, 4.2), color=YELLOW)\n acq_arrow = Arrow(axes.c2p(4.5, 4.8), acq_peak, color=YELLOW, buff=0.1)\n \n self.wait_until_bookmark(\"ACQ\")\n self.play(Create(acq_peak), GrowArrow(acq_arrow), run_time=tracker.duration)\n self.wait(1)\n\n def fit_in_frame(self, mob: Mobject, w_frac: float = 0.9, h_frac: float = 0.9) -> Mobject:\n max_w = config.frame_width * w_frac\n max_h = config.frame_height * h_frac\n if mob.width > max_w:\n mob.width = max_w\n if mob.height > max_h:\n mob.height = max_h\n return mob\n```", "rejected": "```python\nfrom manim import *\nfrom manim_voiceover import VoiceoverScene\nfrom manim_voiceover.services.gtts import GTTSService\n\nclass BONeuroevolutionScene(VoiceoverScene):\n def construct(self):\n # [SETUP]\n # [LAYOUT]\n self.set_speech_service(GTTSService(transcription_model=\"base\"))\n\n # [BEAT 1 | sync: POP]\n with self.voiceover(text=\"Bayesian Optimization can guide neuroevolution in reinforcement learning. We start with a population of neural policies, each representing a different set of hyperparameters or architecture choices.\") as tracker:\n title = Text(\"BO-Guided Neuroevolution\", font_size=36, color=BLUE)\n self.fit_in_frame(title)\n title.to_edge(UP)\n \n policies = VGroup(*[\n VGroup(\n Circle(radius=0.3, color=BLUE, fill_opacity=0.5),\n Text(f\"P{i+1}\", font_size=14)\n ).arrange(ORIGIN) for i in range(6)\n ]).arrange(RIGHT, buff=0.8).shift(UP)\n \n self.wait_until_bookmark(\"POP\")\n self.play(Write(title), Create(policies), run_time=tracker.duration)\n\n with self.voiceover(text=\"We evaluate these policies using model-based rollouts. A Gaussian Process surrogate models the reward landscape, capturing both the expected performance and the uncertainty of each candidate.\") as tracker:\n axes = Axes(axis_color=BLUE, x_range=[0, 6, 1], y_range=[0, 5, 1], x_length=8, y_length=3)\n axes.shift(DOWN * 1.5)\n \n gp_mean = axes.plot(lambda x: 2 + np.sin(x), color=BLUE, stroke_width=2)\n band = VGroup(*[\n Line(\n axes.c2p(x, 2 + np.sin(x) - 0.8), \n axes.c2p(x, 2 + np.sin(x) + 0.8), \n stroke_width=1, color=BLUE\n ).set_opacity(0.15) for x in np.linspace(0, 6, 40)\n ])\n \n self.wait_until_bookmark(\"GP\")\n self.play(Create(axes), Create(band), Create(gp_mean), run_time=tracker.duration)\n\n with self.voiceover(text=\"Finally, the acquisition function balances exploration and exploitation. It selects the most promising policy to evaluate next, efficiently navigating the multi-fidelity budget to find a robust, high-performing agent.\") as tracker:\n acq_peak = Dot(axes.c2p(4.5, 4.2), color=YELLOW)\n acq_arrow = Arrow(axes.c2p(4.5, 4.8), acq_peak, color=YELLOW, buff=0.1)\n \n self.wait_until_bookmark(\"ACQ\")\n self.play(Create(acq_peak), GrowArrow(acq_arrow), run_time=tracker.duration)\n self.wait(1)\n\n def fit_in_frame(self, mob: Mobject, w_frac: float = 0.9, h_frac: float = 0.9) -> Mobject:\n max_w = config.frame_width * w_frac\n max_h = config.frame_height * h_frac\n if mob.width > max_w:\n mob.width = max_w\n if mob.height > max_h:\n mob.height = max_h\n return mob\n```", "category": "invalid_axes_kwarg", "source": "synthetic_hard_neg:nabin2004/qwen3-8b-manimator-gold-sft"} +{"system": "You are an expert Manim Community Edition (ManimCE v0.19+) Python developer and mathematical animator. Given a user request, first plan the spatial layout, coordinate bounds, timing, and pedagogical flow inside ... tags (when reasoning is helpful), and then output a complete, runnable, self-contained ManimCE Python script using `from manim import *`. Never use deprecated ManimGL (`manimlib`) methods like `ShowCreation`, `TexMobject`, `TextMobject`, or `axes.get_graph`; always use modern ManimCE APIs (`Create`, `MathTex`, `Tex`, `Text`, `axes.plot`) and prevent visual overlap using `.to_edge()`, `.next_to()`, and `FadeOut`.", "prompt": "I'm studying optimization and want to visualize Adam's momentum term as an exponentially decaying average of past gradients.\nAnimate a sequence of gradient vectors with color representing decay, and show the velocity update as a moving average that smooths the path.\nInclude a brief note on bias-correction and a side-by-side view of how different betas affect the momentum tail.\nLet students adjust beta values and watch how the trajectory of parameter updates changes.", "chosen": "```python\nfrom manim import *\nfrom manim_voiceover import VoiceoverScene\nfrom manim_voiceover.services.gtts import GTTSService\n\nclass MomentumOptimizationScene(VoiceoverScene):\n def construct(self):\n self.set_speech_service(\n GTTSService(voice=\"alba\", cache_dir=\"voiceover_cache\")\n )\n \n # Title\n with self.voiceover(text=\"Momentum Term in Optimization\") as tracker:\n title = Text(\"Momentum in Optimization\", font_size=48, color=BLUE)\n self.play(Write(title), run_time=tracker.duration)\n self.wait(0.5)\n self.play(title.animate.to_edge(UP), run_time=1)\n \n # Opener with ball analogy\n with self.voiceover(text=\"Have you ever wondered why some optimization algorithms converge faster than others? Imagine a ball rolling down a hill. It gains speed as it rolls. In a similar way, we use momentum to enhance our optimization processes. Today, you'll discover how this physics concept speeds up your machine learning models.\") as tracker:\n ball = Circle(radius=0.3, color=RED, fill_opacity=1)\n ball.set_fill(RED)\n ball.move_to(LEFT * 4 + UP * 2)\n \n hill = FunctionGraph(\n lambda x: 0.3 * x**2 - 0.5,\n x_range=[-4, 4],\n color=GREEN\n )\n \n self.play(Create(hill), run_time=1)\n self.play(FadeIn(ball), run_time=0.5)\n \n # Animate ball rolling down\n path = [ball.get_center()]\n for t in range(1, 11):\n new_pos = LEFT * (4 - 0.8 * t) + UP * (0.3 * (4 - 0.8 * t)**2 - 0.5)\n path.append(new_pos)\n \n for i in range(len(path) - 1):\n speed = 0.3 + i * 0.08\n self.play(ball.animate.move_to(path[i+1]), run_time=speed)\n \n self.wait(0.5)\n self.play(FadeOut(ball), FadeOut(hill), run_time=0.5)\n \n # Clear for next section\n self.play(FadeOut(title))\n \n # The Problem: Vanilla Gradient Descent\n with self.voiceover(text=\"Let's first look at vanilla gradient descent. It updates parameters directly using the current gradient. But this can lead to slow convergence and oscillations in ravines.\") as tracker:\n problem_title = Text(\"The Problem: Vanilla Gradient Descent\", font_size=36, color=YELLOW)\n problem_title.to_edge(UP)\n self.play(Write(problem_title), run_time=1.5)\n \n # Draw a ravine function\n ravine = FunctionGraph(\n lambda x: 0.1 * x**2,\n x_range=[-3, 3],\n color=GRAY\n )\n ravine.move_to(DOWN * 0.5)\n \n self.play(Create(ravine), run_time=1)\n \n # Show zigzag path of vanilla GD\n zigzag_points = [\n LEFT * 2.5 + UP * 0.5,\n LEFT * 2 + DOWN * 0.5,\n LEFT * 1.5 + UP * 0.3,\n LEFT * 1 + DOWN * 0.3,\n LEFT * 0.5 + UP * 0.2,\n DOWN * 0.2,\n RIGHT * 0.5 + UP * 0.15,\n RIGHT * 1 + DOWN * 0.15,\n ]\n \n gd_path = VMobject(color=RED)\n gd_path.set_points_as_corners([zigzag_points[0], zigzag_points[0]])\n self.play(Create(gd_path), run_time=0.3)\n \n for i in range(len(zigzag_points) - 1):\n new_path = VMobject(color=RED)\n new_path.set_points_as_corners(zigzag_points[:i+2])\n self.play(Transform(gd_path, new_path), run_time=0.4)\n \n self.wait(0.5)\n \n slow_label = Text(\"Slow, Oscillating\", font_size=24, color=RED)\n slow_label.next_to(gd_path, UP)\n self.play(Write(slow_label), run_time=0.5)\n \n self.wait(0.5)\n self.play(\n FadeOut(problem_title), FadeOut(ravine), \n FadeOut(gd_path), FadeOut(slow_label), run_time=0.5\n )\n \n # Momentum Concept\n with self.voiceover(text=\"Momentum solves this by accumulating velocity. Like the rolling ball, we keep track of past gradients to maintain direction and speed.\") as tracker:\n concept_title = Text(\"Momentum Concept\", font_size=36, color=BLUE)\n concept_title.to_edge(UP)\n self.play(Write(concept_title), run_time=1)\n \n # Show velocity accumulation\n vel_text = Text(\"Velocity accumulates past gradients\", font_size=28)\n vel_text.move_to(UP * 1.5)\n self.play(Write(vel_text), run_time=1)\n \n # Visual arrows showing accumulation\n arrows = VGroup()\n for i in range(4):\n arrow = Arrow(\n start=LEFT * 2 + UP * (0.5 - i * 0.8),\n end=RIGHT * 2 + UP * (0.5 - i * 0.8),\n color=BLUE,\n buff=0\n )\n arrow.scale(0.3 + i * 0.2)\n arrows.add(arrow)\n \n for arrow in arrows:\n self.play(GrowArrow(arrow), run_time=0.4)\n \n accumulate_text = Text(\"Past gradients -> Velocity -> Faster convergence\", font_size=24, color=GREEN)\n accumulate_text.move_to(DOWN * 2)\n self.play(Write(accumulate_text), run_time=1)\n \n self.wait(0.5)\n self.play(\n FadeOut(concept_title), FadeOut(vel_text),\n FadeOut(arrows), FadeOut(accumulate_text), run_time=0.5\n )\n \n # The Equations\n with self.voiceover(text=\"Here are the momentum update equations. First, we compute the velocity as a weighted average of the previous velocity and the current gradient. Then we update the parameters using this velocity.\") as tracker:\n eq_title = Text(\"Momentum Update Equations\", font_size=36, color=YELLOW)\n eq_title.to_edge(UP)\n self.play(Write(eq_title), run_time=1)\n \n # Equation 1: Velocity update - using Text instead of MathTex to avoid LaTeX issues\n eq1_group = VGroup()\n eq1_text = Text(\"v_t = beta * v_{t-1} + (1-beta) * g_t\", font_size=36, color=WHITE)\n eq1_group.add(eq1_text)\n eq1_group.move_to(UP * 1)\n \n with self.voiceover(text=\"The velocity term combines the previous velocity scaled by beta, plus the current gradient.\") as tracker2:\n self.play(Write(eq1_text), run_time=tracker2.duration)\n \n # Equation 2: Parameter update\n eq2_text = Text(\"theta_t = theta_{t-1} - alpha * v_t\", font_size=36, color=WHITE)\n eq2_text.move_to(DOWN * 0.5)\n \n with self.voiceover(text=\"Then we update parameters by subtracting the learning rate times velocity.\") as tracker3:\n self.play(Write(eq2_text), run_time=tracker3.duration)\n \n # Labels for terms\n beta_label = Text(\"beta: momentum coefficient\", font_size=20, color=BLUE)\n beta_label.next_to(eq1_text, DOWN, buff=0.5)\n \n g_label = Text(\"g_t: current gradient\", font_size=20, color=GREEN)\n g_label.next_to(beta_label, DOWN, buff=0.2)\n \n alpha_label = Text(\"alpha: learning rate\", font_size=20, color=ORANGE)\n alpha_label.next_to(eq2_text, DOWN, buff=0.5)\n \n self.play(Write(beta_label), Write(g_label), Write(alpha_label), run_time=1)\n \n self.wait(1)\n self.play(\n FadeOut(eq_title), FadeOut(eq1_text), FadeOut(eq2_text),\n FadeOut(beta_label), FadeOut(g_label), FadeOut(alpha_label), run_time=0.5\n )\n \n # Visual Comparison\n with self.voiceover(text=\"Now let's compare. Watch how momentum takes a smoother, faster path to the minimum compared to vanilla gradient descent.\") as tracker:\n comp_title = Text(\"Gradient Descent vs Momentum\", font_size=32, color=WHITE)\n comp_title.to_edge(UP)\n self.play(Write(comp_title), run_time=1)\n \n # Draw contour plot representation\n contours = VGroup()\n for r in [2.5, 2, 1.5, 1, 0.5]:\n ellipse = Ellipse(width=r*3, height=r*1.2, color=GRAY, fill_opacity=0.1)\n contours.add(ellipse)\n \n self.play(Create(contours), run_time=1)\n \n # Vanilla GD path - zigzag\n gd_dots = VGroup()\n gd_path_points = [\n LEFT * 3 + UP * 1.5,\n LEFT * 2.5 + DOWN * 1,\n LEFT * 2 + UP * 0.8,\n LEFT * 1.5 + DOWN * 0.6,\n LEFT * 1 + UP * 0.4,\n LEFT * 0.5 + DOWN * 0.3,\n DOWN * 0.2,\n ]\n \n gd_label = Text(\"Vanilla GD\", font_size=20, color=RED)\n gd_label.move_to(LEFT * 3.5 + UP * 2)\n self.play(Write(gd_label), run_time=0.5)\n \n for i, pos in enumerate(gd_path_points):\n dot = Dot(pos, color=RED, radius=0.1)\n gd_dots.add(dot)\n if i == 0:\n self.play(FadeIn(dot), run_time=0.3)\n else:\n line = Line(gd_path_points[i-1], pos, color=RED, stroke_width=2)\n self.play(Create(line), FadeIn(dot), run_time=0.3)\n \n # Momentum path - smooth curve\n momentum_dots = VGroup()\n momentum_path_points = [\n LEFT * 3 + UP * 1.5,\n LEFT * 2.3 + UP * 0.5,\n LEFT * 1.6 + DOWN * 0.2,\n LEFT * 0.9 + DOWN * 0.3,\n LEFT * 0.4 + DOWN * 0.2,\n DOWN * 0.1,\n ]\n \n mom_label = Text(\"With Momentum\", font_size=20, color=BLUE)\n mom_label.move_to(RIGHT * 3 + UP * 2)\n self.play(Write(mom_label), run_time=0.5)\n \n for i, pos in enumerate(momentum_path_points):\n dot = Dot(pos, color=BLUE, radius=0.1)\n momentum_dots.add(dot)\n if i == 0:\n self.play(FadeIn(dot), run_time=0.3)\n else:\n line = Line(momentum_path_points[i-1], pos, color=BLUE, stroke_width=2)\n self.play(Create(line), FadeIn(dot), run_time=0.4)\n \n self.wait(0.5)\n \n # Highlight benefits\n benefit1 = Text(\"Faster convergence\", font_size=22, color=GREEN)\n benefit1.move_to(DOWN * 2.5 + LEFT * 2)\n \n benefit2 = Text(\"Smoother path\", font_size=22, color=GREEN)\n benefit2.move_to(DOWN * 2.5)\n \n self.play(Write(benefit1), Write(benefit2), run_time=1)\n \n self.wait(0.5)\n self.play(\n FadeOut(comp_title), FadeOut(contours), FadeOut(gd_dots),\n FadeOut(momentum_dots), FadeOut(gd_label), FadeOut(mom_label),\n FadeOut(benefit1), FadeOut(benefit2), run_time=0.5\n )\n \n # Escaping Local Minima\n with self.voiceover(text=\"Momentum also helps escape shallow local minima. The accumulated velocity can carry the optimizer over small bumps to reach better solutions.\") as tracker:\n local_title = Text(\"Escaping Local Minima\", font_size=36, color=YELLOW)\n local_title.to_edge(UP)\n self.play(Write(local_title), run_time=1)\n \n # Draw function with local minimum\n local_min_func = FunctionGraph(\n lambda x: 0.15 * (x + 2)**2 + 0.3 if x < -0.5 else 0.5 * (x - 1)**2 + 0.1,\n x_range=[-3.5, 3],\n color=GRAY\n )\n \n self.play(Create(local_min_func), run_time=1)\n \n # Show momentum carrying over the bump\n ball = Dot(LEFT * 3 + UP * 1, color=BLUE, radius=0.15)\n self.play(FadeIn(ball), run_time=0.5)\n \n # Animate through local min and over to global\n path_points = [\n LEFT * 3 + UP * 1,\n LEFT * 2 + UP * 0.3,\n LEFT * 1 + DOWN * 0.1,\n LEFT * 0.3 + UP * 0.2,\n RIGHT * 1 + UP * 0.1,\n RIGHT * 2 + DOWN * 0.05,\n ]\n \n for pos in path_points:\n self.play(ball.animate.move_to(pos), run_time=0.4)\n \n escape_text = Text(\"Momentum carries us to better minima!\", font_size=24, color=GREEN)\n escape_text.move_to(DOWN * 2)\n self.play(Write(escape_text), run_time=0.8)\n \n self.wait(0.5)\n self.play(\n FadeOut(local_title), FadeOut(local_min_func),\n FadeOut(ball), FadeOut(escape_text), run_time=0.5\n )\n \n # Summary\n with self.voiceover(text=\"To summarize: Momentum accelerates optimization by accumulating velocity from past gradients. This leads to faster convergence, smoother updates, and helps escape local minima. The key hyperparameter is beta, typically set around 0.9.\") as tracker:\n summary_title = Text(\"Key Takeaways\", font_size=40, color=BLUE)\n summary_title.to_edge(UP)\n self.play(Write(summary_title), run_time=1)\n \n takeaways = VGroup(\n Text(\"- Momentum accumulates past gradients as velocity\", font_size=26),\n Text(\"- Results in faster, smoother convergence\", font_size=26),\n Text(\"- Helps escape shallow local minima\", font_size=26),\n Text(\"- Typical beta value: 0.9\", font_size=26),\n Text(\"- Essential for deep learning optimization\", font_size=26),\n )\n takeaways.arrange(DOWN, aligned_edge=LEFT, buff=0.5)\n takeaways.move_to(ORIGIN) # Fixed: use ORIGIN instead of CENTER\n \n for takeaway in takeaways:\n self.play(Write(takeaway), run_time=0.6)\n \n self.wait(1)\n \n # Outro\n with self.voiceover(text=\"Now you understand momentum in optimization. Apply it in your neural networks and watch your models train faster!\") as tracker:\n self.play(\n FadeOut(summary_title), FadeOut(takeaways), run_time=1\n )\n \n outro = Text(\"Happy Optimizing!\", font_size=48, color=GREEN)\n self.play(Write(outro), run_time=1.5)\n self.wait(0.5)\n```", "rejected": "```python\nfrom manim import *\n\nclass MomentumOptimizationScene(Scene):\n\n def construct(self):\n title = Text('Momentum in Optimization', font_size=48, color=BLUE)\n self.play(Write(title), run_time=2.0)\n self.wait(0.5)\n self.play(title.animate.to_edge(UP), run_time=1)\n ball = Circle(radius=0.3, color=RED, fill_opacity=1)\n ball.set_fill(RED)\n ball.move_to(LEFT * 4 + UP * 2)\n hill = FunctionGraph(lambda x: 0.3 * x ** 2 - 0.5, x_range=[-4, 4], color=GREEN)\n self.play(Create(hill), run_time=1)\n self.play(FadeIn(ball), run_time=0.5)\n path = [ball.get_center()]\n for t in range(1, 11):\n new_pos = LEFT * (4 - 0.8 * t) + UP * (0.3 * (4 - 0.8 * t) ** 2 - 0.5)\n path.append(new_pos)\n for i in range(len(path) - 1):\n speed = 0.3 + i * 0.08\n self.play(ball.animate.move_to(path[i + 1]), run_time=speed)\n self.wait(0.5)\n self.play(FadeOut(ball), FadeOut(hill), run_time=0.5)\n self.play(FadeOut(title))\n problem_title = Text('The Problem: Vanilla Gradient Descent', font_size=36, color=YELLOW)\n problem_title.to_edge(UP)\n self.play(Write(problem_title), run_time=1.5)\n ravine = FunctionGraph(lambda x: 0.1 * x ** 2, x_range=[-3, 3], color=GRAY)\n ravine.move_to(DOWN * 0.5)\n self.play(Create(ravine), run_time=1)\n zigzag_points = [LEFT * 2.5 + UP * 0.5, LEFT * 2 + DOWN * 0.5, LEFT * 1.5 + UP * 0.3, LEFT * 1 + DOWN * 0.3, LEFT * 0.5 + UP * 0.2, DOWN * 0.2, RIGHT * 0.5 + UP * 0.15, RIGHT * 1 + DOWN * 0.15]\n gd_path = VMobject(color=RED)\n gd_path.set_points_as_corners([zigzag_points[0], zigzag_points[0]])\n self.play(Create(gd_path), run_time=0.3)\n for i in range(len(zigzag_points) - 1):\n new_path = VMobject(color=RED)\n new_path.set_points_as_corners(zigzag_points[:i + 2])\n self.play(Transform(gd_path, new_path), run_time=0.4)\n self.wait(0.5)\n slow_label = Text('Slow, Oscillating', font_size=24, color=RED)\n slow_label.next_to(gd_path, UP)\n self.play(Write(slow_label), run_time=0.5)\n self.wait(0.5)\n self.play(FadeOut(problem_title), FadeOut(ravine), FadeOut(gd_path), FadeOut(slow_label), run_time=0.5)\n concept_title = Text('Momentum Concept', font_size=36, color=BLUE)\n concept_title.to_edge(UP)\n self.play(Write(concept_title), run_time=1)\n vel_text = Text('Velocity accumulates past gradients', font_size=28)\n vel_text.move_to(UP * 1.5)\n self.play(Write(vel_text), run_time=1)\n arrows = VGroup()\n for i in range(4):\n arrow = Arrow(start=LEFT * 2 + UP * (0.5 - i * 0.8), end=RIGHT * 2 + UP * (0.5 - i * 0.8), color=BLUE, buff=0)\n arrow.scale(0.3 + i * 0.2)\n arrows.add(arrow)\n for arrow in arrows:\n self.play(GrowArrow(arrow), run_time=0.4)\n accumulate_text = Text('Past gradients -> Velocity -> Faster convergence', font_size=24, color=GREEN)\n accumulate_text.move_to(DOWN * 2)\n self.play(Write(accumulate_text), run_time=1)\n self.wait(0.5)\n self.play(FadeOut(concept_title), FadeOut(vel_text), FadeOut(arrows), FadeOut(accumulate_text), run_time=0.5)\n eq_title = Text('Momentum Update Equations', font_size=36, color=YELLOW)\n eq_title.to_edge(UP)\n self.play(Write(eq_title), run_time=1)\n eq1_group = VGroup()\n eq1_text = Text('v_t = beta * v_{t-1} + (1-beta) * g_t', font_size=36, color=WHITE)\n eq1_group.add(eq1_text)\n eq1_group.move_to(UP * 1)\n self.play(Write(eq1_text), run_time=tracker2.duration)\n eq2_text = Text('theta_t = theta_{t-1} - alpha * v_t', font_size=36, color=WHITE)\n eq2_text.move_to(DOWN * 0.5)\n self.play(Write(eq2_text), run_time=tracker3.duration)\n beta_label = Text('beta: momentum coefficient', font_size=20, color=BLUE)\n beta_label.next_to(eq1_text, DOWN, buff=0.5)\n g_label = Text('g_t: current gradient', font_size=20, color=GREEN)\n g_label.next_to(beta_label, DOWN, buff=0.2)\n alpha_label = Text('alpha: learning rate', font_size=20, color=ORANGE)\n alpha_label.next_to(eq2_text, DOWN, buff=0.5)\n self.play(Write(beta_label), Write(g_label), Write(alpha_label), run_time=1)\n self.wait(1)\n self.play(FadeOut(eq_title), FadeOut(eq1_text), FadeOut(eq2_text), FadeOut(beta_label), FadeOut(g_label), FadeOut(alpha_label), run_time=0.5)\n comp_title = Text('Gradient Descent vs Momentum', font_size=32, color=WHITE)\n comp_title.to_edge(UP)\n self.play(Write(comp_title), run_time=1)\n contours = VGroup()\n for r in [2.5, 2, 1.5, 1, 0.5]:\n ellipse = Ellipse(width=r * 3, height=r * 1.2, color=GRAY, fill_opacity=0.1)\n contours.add(ellipse)\n self.play(Create(contours), run_time=1)\n gd_dots = VGroup()\n gd_path_points = [LEFT * 3 + UP * 1.5, LEFT * 2.5 + DOWN * 1, LEFT * 2 + UP * 0.8, LEFT * 1.5 + DOWN * 0.6, LEFT * 1 + UP * 0.4, LEFT * 0.5 + DOWN * 0.3, DOWN * 0.2]\n gd_label = Text('Vanilla GD', font_size=20, color=RED)\n gd_label.move_to(LEFT * 3.5 + UP * 2)\n self.play(Write(gd_label), run_time=0.5)\n for i, pos in enumerate(gd_path_points):\n dot = Dot(pos, color=RED, radius=0.1)\n gd_dots.add(dot)\n if i == 0:\n self.play(FadeIn(dot), run_time=0.3)\n else:\n line = Line(gd_path_points[i - 1], pos, color=RED, stroke_width=2)\n self.play(Create(line), FadeIn(dot), run_time=0.3)\n momentum_dots = VGroup()\n momentum_path_points = [LEFT * 3 + UP * 1.5, LEFT * 2.3 + UP * 0.5, LEFT * 1.6 + DOWN * 0.2, LEFT * 0.9 + DOWN * 0.3, LEFT * 0.4 + DOWN * 0.2, DOWN * 0.1]\n mom_label = Text('With Momentum', font_size=20, color=BLUE)\n mom_label.move_to(RIGHT * 3 + UP * 2)\n self.play(Write(mom_label), run_time=0.5)\n for i, pos in enumerate(momentum_path_points):\n dot = Dot(pos, color=BLUE, radius=0.1)\n momentum_dots.add(dot)\n if i == 0:\n self.play(FadeIn(dot), run_time=0.3)\n else:\n line = Line(momentum_path_points[i - 1], pos, color=BLUE, stroke_width=2)\n self.play(Create(line), FadeIn(dot), run_time=0.4)\n self.wait(0.5)\n benefit1 = Text('Faster convergence', font_size=22, color=GREEN)\n benefit1.move_to(DOWN * 2.5 + LEFT * 2)\n benefit2 = Text('Smoother path', font_size=22, color=GREEN)\n benefit2.move_to(DOWN * 2.5)\n self.play(Write(benefit1), Write(benefit2), run_time=1)\n self.wait(0.5)\n self.play(FadeOut(comp_title), FadeOut(contours), FadeOut(gd_dots), FadeOut(momentum_dots), FadeOut(gd_label), FadeOut(mom_label), FadeOut(benefit1), FadeOut(benefit2), run_time=0.5)\n local_title = Text('Escaping Local Minima', font_size=36, color=YELLOW)\n local_title.to_edge(UP)\n self.play(Write(local_title), run_time=1)\n local_min_func = FunctionGraph(lambda x: 0.15 * (x + 2) ** 2 + 0.3 if x < -0.5 else 0.5 * (x - 1) ** 2 + 0.1, x_range=[-3.5, 3], color=GRAY)\n self.play(Create(local_min_func), run_time=1)\n ball = Dot(LEFT * 3 + UP * 1, color=BLUE, radius=0.15)\n self.play(FadeIn(ball), run_time=0.5)\n path_points = [LEFT * 3 + UP * 1, LEFT * 2 + UP * 0.3, LEFT * 1 + DOWN * 0.1, LEFT * 0.3 + UP * 0.2, RIGHT * 1 + UP * 0.1, RIGHT * 2 + DOWN * 0.05]\n for pos in path_points:\n self.play(ball.animate.move_to(pos), run_time=0.4)\n escape_text = Text('Momentum carries us to better minima!', font_size=24, color=GREEN)\n escape_text.move_to(DOWN * 2)\n self.play(Write(escape_text), run_time=0.8)\n self.wait(0.5)\n self.play(FadeOut(local_title), FadeOut(local_min_func), FadeOut(ball), FadeOut(escape_text), run_time=0.5)\n summary_title = Text('Key Takeaways', font_size=40, color=BLUE)\n summary_title.to_edge(UP)\n self.play(Write(summary_title), run_time=1)\n takeaways = VGroup(Text('- Momentum accumulates past gradients as velocity', font_size=26), Text('- Results in faster, smoother convergence', font_size=26), Text('- Helps escape shallow local minima', font_size=26), Text('- Typical beta value: 0.9', font_size=26), Text('- Essential for deep learning optimization', font_size=26))\n takeaways.arrange(DOWN, aligned_edge=LEFT, buff=0.5)\n takeaways.move_to(ORIGIN)\n for takeaway in takeaways:\n self.play(Write(takeaway), run_time=0.6)\n self.wait(1)\n self.play(FadeOut(summary_title), FadeOut(takeaways), run_time=1)\n outro = Text('Happy Optimizing!', font_size=48, color=GREEN)\n self.play(Write(outro), run_time=1.5)\n self.wait(0.5)\n```", "category": "narrated_pedagogical_preference", "source": "nabin2004/manim-narrated-dpo-400"} +{"system": "You are an expert Manim Community Edition (ManimCE v0.19+) Python developer and mathematical animator. Given a user request, first plan the spatial layout, coordinate bounds, timing, and pedagogical flow inside ... tags (when reasoning is helpful), and then output a complete, runnable, self-contained ManimCE Python script using `from manim import *`. Never use deprecated ManimGL (`manimlib`) methods like `ShowCreation`, `TexMobject`, `TextMobject`, or `axes.get_graph`; always use modern ManimCE APIs (`Create`, `MathTex`, `Tex`, `Text`, `axes.plot`) and prevent visual overlap using `.to_edge()`, `.next_to()`, and `FadeOut`.", "prompt": "Construct a clean Manim CE scene initializing Axes with verified keyword arguments. Ensure no deprecated ManimGL arguments (like element_color, max_value, or max_magnitude) are used.\n\n```python\nfrom manim import *\nimport numpy as np\n\nclass ApiValidAxes398(Scene):\n def construct(self):\n obj = Axes(x_range=[-3, 3, 1], y_range=[-2, 4, 1], x_length=6, y_length=4, tips=True)\n obj.set_color(GREEN)\n self.play(Create(obj))\n self.wait(1)\n```", "chosen": "```python\nfrom manim import *\nfrom manim_voiceover import VoiceoverScene\nfrom manim_voiceover.services.gtts import GTTSService\nimport numpy as np\n\nMARGIN = 0.5\n\nclass ApiValidAxes398(VoiceoverScene):\n def fit_in_frame(self, mob: Mobject, w_frac=0.9, h_frac=0.9) -> Mobject:\n max_w = config.frame_width * w_frac\n max_h = config.frame_height * h_frac\n if mob.width > max_w: mob.width = max_w\n if mob.height > max_h: mob.height = max_h\n return mob\n\n def construct(self):\n self.set_speech_service(GTTSService(transcription_model=\"base\"))\n \n # [SETUP]\n obj = Axes(x_range=[-3, 3, 1], y_range=[-2, 4, 1], x_length=6, y_length=4, tips=True)\n obj.set_color(GREEN)\n \n # [LAYOUT]\n title = MathTex(r\"\\text{Valid Axes}\").to_edge(UP, buff=MARGIN)\n self.fit_in_frame(title)\n self.add(title, obj)\n \n # [UPDATER]\n # none\n \n # [BEAT 1 | sync: b1]\n with self.voiceover(text=\"Here is a properly initialized Axes object, avoiding deprecated arguments like element color or max value. \") as t:\n self.wait_until_bookmark(\"b1\")\n self.play(Create(obj))\n \n self.wait(1)\n```", "rejected": "```python\nfrom manim import *\nfrom manim_voiceover import VoiceoverScene\nfrom manim_voiceover.services.gtts import GTTSService\nimport numpy as np\n\nMARGIN = 0.5\n\nclass ApiValidAxes398(VoiceoverScene):\n def fit_in_frame(self, mob: Mobject, w_frac=0.9, h_frac=0.9) -> Mobject:\n max_w = config.frame_width * w_frac\n max_h = config.frame_height * h_frac\n if mob.width > max_w: mob.width = max_w\n if mob.height > max_h: mob.height = max_h\n return mob\n\n def construct(self):\n self.set_speech_service(GTTSService(transcription_model=\"base\"))\n \n # [SETUP]\n obj = Axes(axis_color=BLUE, x_range=[-3, 3, 1], y_range=[-2, 4, 1], x_length=6, y_length=4, tips=True)\n obj.set_color(GREEN)\n \n # [LAYOUT]\n title = MathTex(r\"\\text{Valid Axes}\").to_edge(UP, buff=MARGIN)\n self.fit_in_frame(title)\n self.add(title, obj)\n \n # [UPDATER]\n # none\n \n # [BEAT 1 | sync: b1]\n with self.voiceover(text=\"Here is a properly initialized Axes object, avoiding deprecated arguments like element color or max value. \") as t:\n self.wait_until_bookmark(\"b1\")\n self.play(Create(obj))\n \n self.wait(1)\n```", "category": "invalid_axes_kwarg", "source": "synthetic_hard_neg:nabin2004/qwen3-8b-manimator-gold-sft"} +{"system": "You are an expert Manim Community Edition (ManimCE v0.19+) Python developer and mathematical animator. Given a user request, first plan the spatial layout, coordinate bounds, timing, and pedagogical flow inside ... tags (when reasoning is helpful), and then output a complete, runnable, self-contained ManimCE Python script using `from manim import *`. Never use deprecated ManimGL (`manimlib`) methods like `ShowCreation`, `TexMobject`, `TextMobject`, or `axes.get_graph`; always use modern ManimCE APIs (`Create`, `MathTex`, `Tex`, `Text`, `axes.plot`) and prevent visual overlap using `.to_edge()`, `.next_to()`, and `FadeOut`.", "prompt": "I'm teaching undergrads about language models and want a trie (prefix tree) of character sequences, highlighting the depth-2 branches for the bigram model. Build a character trie from a small corpus, animate insertion of sequences, and emphasize depth-2 branches with bold colors and bigram probabilities annotated on branches.", "chosen": "```python\nfrom manim import *\n\nclass CharacterTrieScene(Scene):\n\n def construct(self):\n title = Text('Character Trie for Language Models', font_size=40, color=BLUE)\n subtitle = Text('Efficient String Storage & Retrieval', font_size=24, color=GRAY)\n title_group = VGroup(title, subtitle).arrange(DOWN, buff=0.3)\n self.play(Write(title), run_time=2.0 * 0.6)\n self.play(FadeIn(subtitle), run_time=2.0 * 0.4)\n self.wait(0.5)\n self.play(FadeOut(title_group))\n what_is = Text('What is a Trie?', font_size=36, color=YELLOW)\n what_is.to_edge(UP)\n self.play(Write(what_is), run_time=2.0)\n points = VGroup(Text('• Tree-based data structure', font_size=24), Text('• Stores characters at each node', font_size=24), Text('• Paths from root form strings', font_size=24), Text(\"• Also known as 'prefix tree'\", font_size=24)).arrange(DOWN, aligned_edge=LEFT, buff=0.4)\n points.next_to(what_is, DOWN, buff=0.5)\n for point in points:\n self.play(FadeIn(point), run_time=2.0 * 0.25)\n self.wait(0.5)\n self.play(FadeOut(what_is), FadeOut(points))\n structure_title = Text('Trie Structure', font_size=32, color=GREEN)\n structure_title.to_edge(UP)\n self.play(Write(structure_title), run_time=2.0)\n root = Circle(radius=0.3, color=BLUE, fill_opacity=0.3)\n root_text = Text('∅', font_size=20, color=WHITE)\n root_node = VGroup(root, root_text)\n root_node.move_to(UP * 2)\n self.play(Create(root), Write(root_text), run_time=2.0)\n c_node_circ = Circle(radius=0.3, color=YELLOW, fill_opacity=0.3)\n c_text = Text('c', font_size=20, color=WHITE)\n c_node = VGroup(c_node_circ, c_text)\n c_node.move_to(UP * 0.5 + LEFT * 2)\n d_node_circ = Circle(radius=0.3, color=YELLOW, fill_opacity=0.3)\n d_text = Text('d', font_size=20, color=WHITE)\n d_node = VGroup(d_node_circ, d_text)\n d_node.move_to(UP * 0.5 + RIGHT * 2)\n edge_c = Line(root_node.get_bottom(), c_node.get_top(), color=GRAY)\n edge_d = Line(root_node.get_bottom(), d_node.get_top(), color=GRAY)\n self.play(Create(edge_c), Create(edge_d), Create(c_node_circ), Write(c_text), Create(d_node_circ), Write(d_text), run_time=2.0)\n ca_node_circ = Circle(radius=0.3, color=ORANGE, fill_opacity=0.3)\n ca_text = Text('a', font_size=20, color=WHITE)\n ca_node = VGroup(ca_node_circ, ca_text)\n ca_node.move_to(DOWN * 1 + LEFT * 3)\n co_node_circ = Circle(radius=0.3, color=ORANGE, fill_opacity=0.3)\n co_text = Text('o', font_size=20, color=WHITE)\n co_node = VGroup(co_node_circ, co_text)\n co_node.move_to(DOWN * 1 + LEFT * 1)\n edge_ca = Line(c_node.get_bottom(), ca_node.get_top(), color=GRAY)\n edge_co = Line(c_node.get_bottom(), co_node.get_top(), color=GRAY)\n self.play(Create(edge_ca), Create(edge_co), Create(ca_node_circ), Write(ca_text), Create(co_node_circ), Write(co_text), run_time=2.0)\n cat_t_circ = Circle(radius=0.3, color=GREEN, fill_opacity=0.5)\n cat_t_text = Text('t', font_size=20, color=WHITE)\n cat_t_node = VGroup(cat_t_circ, cat_t_text)\n cat_t_node.move_to(DOWN * 2.5 + LEFT * 3)\n edge_cat = Line(ca_node.get_bottom(), cat_t_node.get_top(), color=GRAY)\n end_marker = Star(n=5, outer_radius=0.15, inner_radius=0.07, color=RED, fill_opacity=1)\n end_marker.next_to(cat_t_node, RIGHT, buff=0.1)\n self.play(Create(edge_cat), Create(cat_t_circ), Write(cat_t_text), run_time=2.0 * 0.7)\n self.play(Create(end_marker), run_time=2.0 * 0.3)\n cat_label = Text('\"cat\"', font_size=20, color=GREEN)\n cat_label.next_to(cat_t_node, DOWN, buff=0.3)\n self.play(Write(cat_label), run_time=2.0)\n self.wait(0.5)\n trie_structure = VGroup(root_node, c_node, d_node, ca_node, co_node, cat_t_node, edge_c, edge_d, edge_ca, edge_co, edge_cat, end_marker, cat_label, structure_title)\n self.play(FadeOut(trie_structure))\n insert_title = Text('Insertion Operation', font_size=32, color=BLUE)\n insert_title.to_edge(UP)\n self.play(Write(insert_title), run_time=2.0)\n word_to_insert = Text('Insert: \"car\"', font_size=28, color=YELLOW)\n word_to_insert.next_to(insert_title, DOWN, buff=0.5)\n self.play(Write(word_to_insert), run_time=2.0)\n step1 = Text('1. Start at root', font_size=22, color=WHITE)\n step1.to_edge(LEFT).shift(UP * 0.5)\n self.play(Write(step1), run_time=2.0)\n step2 = Text(\"2. 'c' exists? Yes → traverse\", font_size=22, color=WHITE)\n step2.next_to(step1, DOWN, buff=0.3)\n self.play(Write(step2), run_time=2.0)\n step3 = Text(\"3. 'a' exists? Yes → traverse\", font_size=22, color=WHITE)\n step3.next_to(step2, DOWN, buff=0.3)\n self.play(Write(step3), run_time=2.0)\n step4 = Text(\"4. 'r' exists? No → create node\", font_size=22, color=GREEN)\n step4.next_to(step3, DOWN, buff=0.3)\n self.play(Write(step4), run_time=2.0)\n step5 = Text('5. Mark as end-of-word', font_size=22, color=RED)\n step5.next_to(step4, DOWN, buff=0.3)\n self.play(Write(step5), run_time=2.0)\n self.wait(0.5)\n self.play(FadeOut(insert_title), FadeOut(word_to_insert), FadeOut(step1), FadeOut(step2), FadeOut(step3), FadeOut(step4), FadeOut(step5))\n search_title = Text('Search Operation', font_size=32, color=PURPLE)\n search_title.to_edge(UP)\n self.play(Write(search_title), run_time=2.0)\n search_word = Text('Search: \"cat\"', font_size=28, color=YELLOW)\n search_word.next_to(search_title, DOWN, buff=0.5)\n self.play(Write(search_word), run_time=2.0)\n s_step1 = Text(\"1. Check 'c' → found ✓\", font_size=22, color=GREEN)\n s_step1.to_edge(LEFT).shift(UP * 0.5)\n self.play(Write(s_step1), run_time=2.0)\n s_step2 = Text(\"2. Check 'a' → found ✓\", font_size=22, color=GREEN)\n s_step2.next_to(s_step1, DOWN, buff=0.3)\n self.play(Write(s_step2), run_time=2.0)\n s_step3 = Text(\"3. Check 't' → found ✓\", font_size=22, color=GREEN)\n s_step3.next_to(s_step2, DOWN, buff=0.3)\n self.play(Write(s_step3), run_time=2.0)\n s_step4 = Text('4. End marker? → Yes ✓', font_size=22, color=GREEN)\n s_step4.next_to(s_step3, DOWN, buff=0.3)\n result = Text('Result: FOUND!', font_size=26, color=GREEN)\n result.next_to(s_step4, DOWN, buff=0.5)\n self.play(Write(s_step4), run_time=2.0 * 0.5)\n self.play(Write(result), run_time=2.0 * 0.5)\n self.wait(0.5)\n self.play(FadeOut(search_title), FadeOut(search_word), FadeOut(s_step1), FadeOut(s_step2), FadeOut(s_step3), FadeOut(s_step4), FadeOut(result))\n benefits_title = Text('Benefits for Language Models', font_size=32, color=BLUE)\n benefits_title.to_edge(UP)\n self.play(Write(benefits_title), run_time=2.0)\n left_col = VGroup(Text('• O(m) lookup time', font_size=22, color=YELLOW), Text(' m = word length', font_size=18, color=GRAY), Text('• Prefix matching', font_size=22, color=YELLOW), Text('• Space efficient', font_size=22, color=YELLOW)).arrange(DOWN, aligned_edge=LEFT, buff=0.3)\n right_col = VGroup(Text('• Fast autocomplete', font_size=22, color=YELLOW), Text('• Spell checking', font_size=22, color=YELLOW), Text('• Dictionary storage', font_size=22, color=YELLOW), Text('• Token prediction', font_size=22, color=YELLOW)).arrange(DOWN, aligned_edge=LEFT, buff=0.3)\n left_col.to_edge(LEFT, buff=1).shift(DOWN * 0.5)\n right_col.to_edge(RIGHT, buff=1).shift(DOWN * 0.5)\n self.play(FadeIn(left_col), run_time=2.0 * 0.5)\n self.play(FadeIn(right_col), run_time=2.0 * 0.5)\n self.wait(0.5)\n self.play(FadeOut(left_col), FadeOut(right_col), FadeOut(benefits_title))\n summary_title = Text('Summary', font_size=36, color=GREEN)\n summary_title.to_edge(UP)\n self.play(Write(summary_title), run_time=2.0)\n summary_points = VGroup(Text('1. A Trie is a tree for storing strings', font_size=24), Text('2. Each path represents a prefix', font_size=24), Text('3. Insertion and search are O(m)', font_size=24), Text('4. Perfect for language model tasks', font_size=24)).arrange(DOWN, aligned_edge=LEFT, buff=0.4)\n summary_points.next_to(summary_title, DOWN, buff=0.6)\n for point in summary_points:\n self.play(FadeIn(point), run_time=2.0 * 0.25)\n self.wait(0.5)\n final_text = Text('Build smarter AI with Tries!', font_size=32, color=BLUE)\n final_text.next_to(summary_points, DOWN, buff=0.8)\n self.play(Write(final_text), run_time=2.0)\n self.wait(1)\n```", "rejected": "```python\nfrom manim import *\n\nclass CharacterTrieScene(Scene):\n\n def construct(self):\n title = Text('Character Trie for Language Models', font_size=40, color=BLUE)\n subtitle = Text('Efficient String Storage & Retrieval', font_size=24, color=GRAY)\n title_group = VGroup(title, subtitle).arrange(DOWN, buff=0.3)\n self.play(Write(title), run_time=2.0 * 0.6)\n self.play(FadeIn(subtitle), run_time=2.0 * 0.4)\n self.wait(0.5)\n self.play(FadeOut(title_group))\n what_is = Text('What is a Trie?', font_size=36, color=YELLOW)\n what_is\n self.play(Write(what_is), run_time=2.0)\n points = VGroup(Text('• Tree-based data structure', font_size=24), Text('• Stores characters at each node', font_size=24), Text('• Paths from root form strings', font_size=24), Text(\"• Also known as 'prefix tree'\", font_size=24)).arrange(DOWN, aligned_edge=LEFT, buff=0.4)\n points\n for point in points:\n self.play(FadeIn(point), run_time=2.0 * 0.25)\n self.wait(0.5)\n self.play(FadeOut(what_is), FadeOut(points))\n structure_title = Text('Trie Structure', font_size=32, color=GREEN)\n structure_title\n self.play(Write(structure_title), run_time=2.0)\n root = Circle(radius=0.3, color=BLUE, fill_opacity=0.3)\n root_text = Text('∅', font_size=20, color=WHITE)\n root_node = VGroup(root, root_text)\n root_node.move_to(UP * 2)\n self.play(Create(root), Write(root_text), run_time=2.0)\n c_node_circ = Circle(radius=0.3, color=YELLOW, fill_opacity=0.3)\n c_text = Text('c', font_size=20, color=WHITE)\n c_node = VGroup(c_node_circ, c_text)\n c_node.move_to(UP * 0.5 + LEFT * 2)\n d_node_circ = Circle(radius=0.3, color=YELLOW, fill_opacity=0.3)\n d_text = Text('d', font_size=20, color=WHITE)\n d_node = VGroup(d_node_circ, d_text)\n d_node.move_to(UP * 0.5 + RIGHT * 2)\n edge_c = Line(root_node.get_bottom(), c_node.get_top(), color=GRAY)\n edge_d = Line(root_node.get_bottom(), d_node.get_top(), color=GRAY)\n self.play(Create(edge_c), Create(edge_d), Create(c_node_circ), Write(c_text), Create(d_node_circ), Write(d_text), run_time=2.0)\n ca_node_circ = Circle(radius=0.3, color=ORANGE, fill_opacity=0.3)\n ca_text = Text('a', font_size=20, color=WHITE)\n ca_node = VGroup(ca_node_circ, ca_text)\n ca_node.move_to(DOWN * 1 + LEFT * 3)\n co_node_circ = Circle(radius=0.3, color=ORANGE, fill_opacity=0.3)\n co_text = Text('o', font_size=20, color=WHITE)\n co_node = VGroup(co_node_circ, co_text)\n co_node.move_to(DOWN * 1 + LEFT * 1)\n edge_ca = Line(c_node.get_bottom(), ca_node.get_top(), color=GRAY)\n edge_co = Line(c_node.get_bottom(), co_node.get_top(), color=GRAY)\n self.play(Create(edge_ca), Create(edge_co), Create(ca_node_circ), Write(ca_text), Create(co_node_circ), Write(co_text), run_time=2.0)\n cat_t_circ = Circle(radius=0.3, color=GREEN, fill_opacity=0.5)\n cat_t_text = Text('t', font_size=20, color=WHITE)\n cat_t_node = VGroup(cat_t_circ, cat_t_text)\n cat_t_node.move_to(DOWN * 2.5 + LEFT * 3)\n edge_cat = Line(ca_node.get_bottom(), cat_t_node.get_top(), color=GRAY)\n end_marker = Star(n=5, outer_radius=0.15, inner_radius=0.07, color=RED, fill_opacity=1)\n end_marker.next_to(cat_t_node, RIGHT, buff=0.1)\n self.play(Create(edge_cat), Create(cat_t_circ), Write(cat_t_text), run_time=2.0 * 0.7)\n self.play(Create(end_marker), run_time=2.0 * 0.3)\n cat_label = Text('\"cat\"', font_size=20, color=GREEN)\n cat_label.next_to(cat_t_node, DOWN, buff=0.3)\n self.play(Write(cat_label), run_time=2.0)\n self.wait(0.5)\n trie_structure = VGroup(root_node, c_node, d_node, ca_node, co_node, cat_t_node, edge_c, edge_d, edge_ca, edge_co, edge_cat, end_marker, cat_label, structure_title)\n self.play(FadeOut(trie_structure))\n insert_title = Text('Insertion Operation', font_size=32, color=BLUE)\n insert_title.to_edge(UP)\n self.play(Write(insert_title), run_time=2.0)\n word_to_insert = Text('Insert: \"car\"', font_size=28, color=YELLOW)\n word_to_insert.next_to(insert_title, DOWN, buff=0.5)\n self.play(Write(word_to_insert), run_time=2.0)\n step1 = Text('1. Start at root', font_size=22, color=WHITE)\n step1.to_edge(LEFT).shift(UP * 0.5)\n self.play(Write(step1), run_time=2.0)\n step2 = Text(\"2. 'c' exists? Yes → traverse\", font_size=22, color=WHITE)\n step2.next_to(step1, DOWN, buff=0.3)\n self.play(Write(step2), run_time=2.0)\n step3 = Text(\"3. 'a' exists? Yes → traverse\", font_size=22, color=WHITE)\n step3.next_to(step2, DOWN, buff=0.3)\n self.play(Write(step3), run_time=2.0)\n step4 = Text(\"4. 'r' exists? No → create node\", font_size=22, color=GREEN)\n step4.next_to(step3, DOWN, buff=0.3)\n self.play(Write(step4), run_time=2.0)\n step5 = Text('5. Mark as end-of-word', font_size=22, color=RED)\n step5.next_to(step4, DOWN, buff=0.3)\n self.play(Write(step5), run_time=2.0)\n self.wait(0.5)\n self.play(FadeOut(insert_title), FadeOut(word_to_insert), FadeOut(step1), FadeOut(step2), FadeOut(step3), FadeOut(step4), FadeOut(step5))\n search_title = Text('Search Operation', font_size=32, color=PURPLE)\n search_title.to_edge(UP)\n self.play(Write(search_title), run_time=2.0)\n search_word = Text('Search: \"cat\"', font_size=28, color=YELLOW)\n search_word.next_to(search_title, DOWN, buff=0.5)\n self.play(Write(search_word), run_time=2.0)\n s_step1 = Text(\"1. Check 'c' → found ✓\", font_size=22, color=GREEN)\n s_step1.to_edge(LEFT).shift(UP * 0.5)\n self.play(Write(s_step1), run_time=2.0)\n s_step2 = Text(\"2. Check 'a' → found ✓\", font_size=22, color=GREEN)\n s_step2.next_to(s_step1, DOWN, buff=0.3)\n self.play(Write(s_step2), run_time=2.0)\n s_step3 = Text(\"3. Check 't' → found ✓\", font_size=22, color=GREEN)\n s_step3.next_to(s_step2, DOWN, buff=0.3)\n self.play(Write(s_step3), run_time=2.0)\n s_step4 = Text('4. End marker? → Yes ✓', font_size=22, color=GREEN)\n s_step4.next_to(s_step3, DOWN, buff=0.3)\n result = Text('Result: FOUND!', font_size=26, color=GREEN)\n result.next_to(s_step4, DOWN, buff=0.5)\n self.play(Write(s_step4), run_time=2.0 * 0.5)\n self.play(Write(result), run_time=2.0 * 0.5)\n self.wait(0.5)\n self.play(FadeOut(search_title), FadeOut(search_word), FadeOut(s_step1), FadeOut(s_step2), FadeOut(s_step3), FadeOut(s_step4), FadeOut(result))\n benefits_title = Text('Benefits for Language Models', font_size=32, color=BLUE)\n benefits_title.to_edge(UP)\n self.play(Write(benefits_title), run_time=2.0)\n left_col = VGroup(Text('• O(m) lookup time', font_size=22, color=YELLOW), Text(' m = word length', font_size=18, color=GRAY), Text('• Prefix matching', font_size=22, color=YELLOW), Text('• Space efficient', font_size=22, color=YELLOW)).arrange(DOWN, aligned_edge=LEFT, buff=0.3)\n right_col = VGroup(Text('• Fast autocomplete', font_size=22, color=YELLOW), Text('• Spell checking', font_size=22, color=YELLOW), Text('• Dictionary storage', font_size=22, color=YELLOW), Text('• Token prediction', font_size=22, color=YELLOW)).arrange(DOWN, aligned_edge=LEFT, buff=0.3)\n left_col.to_edge(LEFT, buff=1).shift(DOWN * 0.5)\n right_col.to_edge(RIGHT, buff=1).shift(DOWN * 0.5)\n self.play(FadeIn(left_col), run_time=2.0 * 0.5)\n self.play(FadeIn(right_col), run_time=2.0 * 0.5)\n self.wait(0.5)\n self.play(FadeOut(left_col), FadeOut(right_col), FadeOut(benefits_title))\n summary_title = Text('Summary', font_size=36, color=GREEN)\n summary_title.to_edge(UP)\n self.play(Write(summary_title), run_time=2.0)\n summary_points = VGroup(Text('1. A Trie is a tree for storing strings', font_size=24), Text('2. Each path represents a prefix', font_size=24), Text('3. Insertion and search are O(m)', font_size=24), Text('4. Perfect for language model tasks', font_size=24)).arrange(DOWN, aligned_edge=LEFT, buff=0.4)\n summary_points.next_to(summary_title, DOWN, buff=0.6)\n for point in summary_points:\n self.play(FadeIn(point), run_time=2.0 * 0.25)\n self.wait(0.5)\n final_text = Text('Build smarter AI with Tries!', font_size=32, color=BLUE)\n final_text.next_to(summary_points, DOWN, buff=0.8)\n self.play(Write(final_text), run_time=2.0)\n self.wait(1)\n```", "category": "spatial_layout_overlap", "source": "synthetic_hard_neg:nabin2004/AOS-Manim-SFT"} +{"system": "You are an expert Manim Community Edition (ManimCE v0.19+) Python developer and mathematical animator. Given a user request, first plan the spatial layout, coordinate bounds, timing, and pedagogical flow inside ... tags (when reasoning is helpful), and then output a complete, runnable, self-contained ManimCE Python script using `from manim import *`. Never use deprecated ManimGL (`manimlib`) methods like `ShowCreation`, `TexMobject`, `TextMobject`, or `axes.get_graph`; always use modern ManimCE APIs (`Create`, `MathTex`, `Tex`, `Text`, `axes.plot`) and prevent visual overlap using `.to_edge()`, `.next_to()`, and `FadeOut`.", "prompt": "I'm teaching undergrads ML and want a vivid visualization of the tanh activation curve. Show logits ranging from -∞ to ∞ mapped to -1 to 1, with saturation regions colored red. Include a moving input slider and an annotation of the slope decay, plus a side plot of the derivative magnitude.", "chosen": "```python\nfrom manim import *\nfrom manim_voiceover import VoiceoverScene\nfrom manim_voiceover.services.gtts import GTTSService\nimport numpy as np\n\nclass TanhFunctionScene(VoiceoverScene):\n def construct(self):\n self.set_speech_service(\n GTTSService(voice=\"alba\", cache_dir=\"voiceover_cache\")\n )\n \n # Title\n title = Text(\"Tanh Activation Function\", font_size=48, color=BLUE)\n title.to_edge(UP, buff=0.5)\n \n with self.voiceover(text=\"Have you ever wondered how neural networks make decisions?\") as tracker:\n self.play(Write(title), run_time=tracker.duration)\n \n with self.voiceover(text=\"A crucial part of this process involves activation functions, like the hyperbolic tangent or Tanh function.\") as tracker:\n self.wait(tracker.duration)\n \n with self.voiceover(text=\"Today, you're going to uncover the secrets behind this vital mathematical tool!\") as tracker:\n self.wait(tracker.duration)\n \n # Create axes\n axes = Axes(\n x_range=[-4, 4, 1],\n y_range=[-1.5, 1.5, 0.5],\n axis_config={\"include_tip\": True, \"include_numbers\": True},\n x_axis_config={\"numbers_to_include\": [-4, -2, 0, 2, 4]},\n y_axis_config={\"numbers_to_include\": [-1, 0, 1]},\n )\n axes.scale(0.8)\n axes.to_edge(DOWN, buff=0.8)\n \n # Labels\n x_label = axes.get_x_axis_label(\"x\")\n y_label = axes.get_y_axis_label(\"f(x)\")\n \n with self.voiceover(text=\"Let's start by looking at the mathematical definition of Tanh.\") as tracker:\n self.play(FadeOut(title), run_time=0.5)\n \n # Formula\n formula = MathTex(r\"f(x) = \\tanh(x) = \\frac{e^x - e^{-x}}{e^x + e^{-x}}\")\n formula.to_edge(UP, buff=0.8)\n \n with self.voiceover(text=\"The Tanh function is defined as e to the x, minus e to the negative x, divided by e to the x, plus e to the negative x.\") as tracker:\n self.play(Write(formula), run_time=tracker.duration)\n \n # Show axes\n with self.voiceover(text=\"Now, let's visualize this function on a coordinate plane.\") as tracker:\n self.play(Create(axes), Write(x_label), Write(y_label), run_time=tracker.duration)\n \n # Plot the tanh function\n tanh_graph = axes.plot(lambda x: np.tanh(x), x_range=[-4, 4], color=BLUE, stroke_width=3)\n \n with self.voiceover(text=\"Watch as we plot the hyperbolic tangent curve.\") as tracker:\n self.play(Create(tanh_graph), run_time=tracker.duration)\n \n # Highlight asymptotes\n asymptote_top = DashedLine(\n axes.c2p(-4, 1), axes.c2p(4, 1),\n color=YELLOW, stroke_width=2, dash_length=0.1\n )\n asymptote_bottom = DashedLine(\n axes.c2p(-4, -1), axes.c2p(4, -1),\n color=YELLOW, stroke_width=2, dash_length=0.1\n )\n \n with self.voiceover(text=\"Notice how the curve approaches but never crosses the horizontal lines at y equals 1 and y equals negative 1.\") as tracker:\n self.play(Create(asymptote_top), Create(asymptote_bottom), run_time=tracker.duration)\n \n # Range annotation\n range_text = MathTex(r\"\\text{Range: } (-1, 1)\")\n range_text.next_to(formula, DOWN, buff=0.5)\n range_text.set_color(GREEN)\n \n with self.voiceover(text=\"This means the range of Tanh is between negative 1 and 1, not including the endpoints.\") as tracker:\n self.play(Write(range_text), run_time=tracker.duration)\n \n # Highlight zero-centered\n origin_dot = Dot(axes.c2p(0, 0), color=RED, radius=0.1)\n zero_label = MathTex(r\"f(0) = 0\")\n zero_label.next_to(origin_dot, UR, buff=0.2)\n zero_label.scale(0.8)\n \n with self.voiceover(text=\"Another key property: Tanh is zero-centered. When x equals 0, the output is exactly 0.\") as tracker:\n self.play(FadeIn(origin_dot), Write(zero_label), run_time=tracker.duration)\n \n # S-shape highlight\n s_shape_rect = SurroundingRectangle(tanh_graph, color=ORANGE, buff=0.2)\n \n with self.voiceover(text=\"The distinctive S-shape of Tanh makes it ideal for neural networks.\") as tracker:\n self.play(Create(s_shape_rect), run_time=tracker.duration)\n \n # Key properties list\n properties_title = Text(\"Key Properties:\", font_size=32, color=WHITE)\n properties_title.to_edge(LEFT, buff=0.5)\n properties_title.shift(UP * 1.5)\n \n prop1 = Text(\"• Zero-centered output\", font_size=24)\n prop2 = Text(\"• Range: (-1, 1)\", font_size=24)\n prop3 = Text(\"• Smooth gradients\", font_size=24)\n prop4 = Text(\"• Sigmoid-like but better\", font_size=24)\n \n props = VGroup(prop1, prop2, prop3, prop4)\n props.arrange(DOWN, aligned_edge=LEFT, buff=0.3)\n props.next_to(properties_title, DOWN, aligned_edge=LEFT, buff=0.3)\n props.shift(RIGHT * 0.3)\n \n with self.voiceover(text=\"Let's summarize the key properties of Tanh. It's zero-centered, which helps with training. It outputs values between negative 1 and 1. It has smooth gradients for backpropagation. And it's similar to sigmoid, but with better properties for deep learning.\") as tracker:\n self.play(\n FadeOut(formula), FadeOut(range_text), FadeOut(zero_label),\n FadeOut(s_shape_rect), FadeOut(origin_dot),\n FadeOut(asymptote_top), FadeOut(asymptote_bottom),\n run_time=0.5\n )\n self.play(Write(properties_title), run_time=0.5)\n self.play(Write(props), run_time=tracker.duration - 1)\n \n # Final summary\n with self.voiceover(text=\"Today, you've seen how the Tanh function behaves graphically, grasped its significance in neural networks, and learned about its key properties and applications.\") as tracker:\n self.wait(tracker.duration)\n \n with self.voiceover(text=\"Tanh remains a powerful tool in your deep learning toolkit!\") as tracker:\n self.wait(tracker.duration)\n \n self.wait(1)\n```", "rejected": "```python\nfrom manim import *\nimport numpy as np\n\nclass TanhFunctionScene(Scene):\n\n def construct(self):\n title = Text('Tanh Activation Function', font_size=48, color=BLUE)\n title.to_edge(UP, buff=0.5)\n self.play(Write(title), run_time=2.0)\n self.wait(2.0)\n self.wait(2.0)\n axes = Axes(x_range=[-4, 4, 1], y_range=[-1.5, 1.5, 0.5], axis_config={'include_tip': True, 'include_numbers': True}, x_axis_config={'numbers_to_include': [-4, -2, 0, 2, 4]}, y_axis_config={'numbers_to_include': [-1, 0, 1]})\n axes.scale(0.8)\n axes.to_edge(DOWN, buff=0.8)\n x_label = axes.get_x_axis_label('x')\n y_label = axes.get_y_axis_label('f(x)')\n self.play(FadeOut(title), run_time=0.5)\n formula = MathTex('f(x) = \\\\tanh(x) = \\\\frac{e^x - e^{-x}}{e^x + e^{-x}}')\n formula.to_edge(UP, buff=0.8)\n self.play(Write(formula), run_time=2.0)\n self.play(Create(axes), Write(x_label), Write(y_label), run_time=2.0)\n tanh_graph = axes.plot(lambda x: np.tanh(x), x_range=[-4, 4], color=BLUE, stroke_width=3)\n self.play(Create(tanh_graph), run_time=2.0)\n asymptote_top = DashedLine(axes.c2p(-4, 1), axes.c2p(4, 1), color=YELLOW, stroke_width=2, dash_length=0.1)\n asymptote_bottom = DashedLine(axes.c2p(-4, -1), axes.c2p(4, -1), color=YELLOW, stroke_width=2, dash_length=0.1)\n self.play(Create(asymptote_top), Create(asymptote_bottom), run_time=2.0)\n range_text = MathTex('\\\\text{Range: } (-1, 1)')\n range_text.next_to(formula, DOWN, buff=0.5)\n range_text.set_color(GREEN)\n self.play(Write(range_text), run_time=2.0)\n origin_dot = Dot(axes.c2p(0, 0), color=RED, radius=0.1)\n zero_label = MathTex('f(0) = 0')\n zero_label.next_to(origin_dot, UR, buff=0.2)\n zero_label.scale(0.8)\n self.play(FadeIn(origin_dot), Write(zero_label), run_time=2.0)\n s_shape_rect = SurroundingRectangle(tanh_graph, color=ORANGE, buff=0.2)\n self.play(Create(s_shape_rect), run_time=2.0)\n properties_title = Text('Key Properties:', font_size=32, color=WHITE)\n properties_title.to_edge(LEFT, buff=0.5)\n properties_title.shift(UP * 1.5)\n prop1 = Text('• Zero-centered output', font_size=24)\n prop2 = Text('• Range: (-1, 1)', font_size=24)\n prop3 = Text('• Smooth gradients', font_size=24)\n prop4 = Text('• Sigmoid-like but better', font_size=24)\n props = VGroup(prop1, prop2, prop3, prop4)\n props.arrange(DOWN, aligned_edge=LEFT, buff=0.3)\n props.next_to(properties_title, DOWN, aligned_edge=LEFT, buff=0.3)\n props.shift(RIGHT * 0.3)\n self.play(FadeOut(formula), FadeOut(range_text), FadeOut(zero_label), FadeOut(s_shape_rect), FadeOut(origin_dot), FadeOut(asymptote_top), FadeOut(asymptote_bottom), run_time=0.5)\n self.play(Write(properties_title), run_time=0.5)\n self.play(Write(props), run_time=2.0 - 1)\n self.wait(2.0)\n self.wait(2.0)\n self.wait(1)\n```", "category": "narrated_pedagogical_preference", "source": "nabin2004/manim-narrated-dpo-400"} +{"system": "You are an expert Manim Community Edition (ManimCE v0.19+) Python developer and mathematical animator. Given a user request, first plan the spatial layout, coordinate bounds, timing, and pedagogical flow inside ... tags (when reasoning is helpful), and then output a complete, runnable, self-contained ManimCE Python script using `from manim import *`. Never use deprecated ManimGL (`manimlib`) methods like `ShowCreation`, `TexMobject`, `TextMobject`, or `axes.get_graph`; always use modern ManimCE APIs (`Create`, `MathTex`, `Tex`, `Text`, `axes.plot`) and prevent visual overlap using `.to_edge()`, `.next_to()`, and `FadeOut`.", "prompt": "The following Manim CE script crashed with this traceback:\n\n```text\nTypeError: Text.__init__() got an unexpected keyword argument 'size'\n```\n\nFix the bug and provide the corrected, fully compilable Manim CE code:\n\n```python\nfrom manim import *\nimport numpy as np\n\nclass ApiValidNumberPlane243(Scene):\n def construct(self):\n txt = Text('Test', size=24)\n obj = NumberPlane(x_range=[-4, 4, 1], y_range=[-3, 3, 1], background_line_style={'stroke_opacity': 0.4})\n obj.set_color(BLUE)\n self.play(Create(obj))\n self.wait(1)\n```", "chosen": "```python\nfrom manim import *\nfrom manim_voiceover import VoiceoverScene\nfrom manim_voiceover.services.gtts import GTTSService\nimport numpy as np\n\nMARGIN = 0.5\n\nclass ApiValidNumberPlaneScene(VoiceoverScene):\n def fit_in_frame(self, mob: Mobject, w_frac=0.9, h_frac=0.9) -> Mobject:\n max_w = config.frame_width * w_frac\n max_h = config.frame_height * h_frac\n if mob.width > max_w:\n mob.width = max_w\n if mob.height > max_h:\n mob.height = max_h\n return mob\n\n def construct(self):\n self.set_speech_service(GTTSService(transcription_model=\"base\"))\n \n # [SETUP]\n title = Title(\"Text Initialization\", buff=MARGIN)\n \n # [LAYOUT]\n main_group = self.fit_in_frame(VGroup(title))\n self.add(main_group)\n \n # [UPDATER]\n # None\n \n # [BEAT 1 | sync: b1]\n with self.voiceover(text=\"This scene demonstrates the correct initialization of a Text object. \") as t_voice:\n self.wait_until_bookmark(\"b1\")\n self.play(Write(title), run_time=1.5)\n \n # [BEAT 2 | sync: b2]\n with self.voiceover(text=\"We use font_size instead of the deprecated size argument to prevent initialization errors. The resulting text is displayed cleanly over a subtle number plane.\") as t_voice:\n self.wait_until_bookmark(\"b2\")\n txt = Text('Test', font_size=24)\n obj = NumberPlane(x_range=[-4, 4, 1], y_range=[-3, 3, 1], background_line_style={'stroke_opacity': 0.4})\n obj.set_color(BLUE)\n self.play(Create(obj), Write(txt), run_time=2)\n self.wait(1)\n```", "rejected": "```python\nfrom manim import *\nfrom manim_voiceover import VoiceoverScene\nfrom manim_voiceover.services.gtts import GTTSService\nimport numpy as np\n\nMARGIN = 0.5\n\nclass ApiValidNumberPlaneScene(VoiceoverScene):\n def fit_in_frame(self, mob: Mobject, w_frac=0.9, h_frac=0.9) -> Mobject:\n max_w = config.frame_width * w_frac\n max_h = config.frame_height * h_frac\n if mob.width > max_w:\n mob.width = max_w\n if mob.height > max_h:\n mob.height = max_h\n return mob\n\n def construct(self):\n self.set_speech_service(GTTSService(transcription_model=\"base\"))\n \n # [SETUP]\n title = Title(\"Text Initialization\", buff=MARGIN)\n \n # [LAYOUT]\n main_group = self.fit_in_frame(VGroup(title))\n self.add(main_group)\n \n # [UPDATER]\n # None\n \n # [BEAT 1 | sync: b1]\n with self.voiceover(text=\"This scene demonstrates the correct initialization of a Text object. \") as t_voice:\n self.wait_until_bookmark(\"b1\")\n self.play(Write(title), run_time=1.5)\n \n # [BEAT 2 | sync: b2]\n with self.voiceover(text=\"We use font_size instead of the deprecated size argument to prevent initialization errors. The resulting text is displayed cleanly over a subtle number plane.\") as t_voice:\n self.wait_until_bookmark(\"b2\")\n txt = Text('Test', font_size=24)\n obj = NumberPlane(x_range=[-4, 4, 1], y_range=[-3, 3, 1], background_line_style={'stroke_opacity': 0.4})\n obj.set_color(BLUE)\n self.play(ShowCreation(obj), Write(txt), run_time=2)\n self.wait(1)\n```", "category": "legacy_api_hallucination", "source": "synthetic_hard_neg:nabin2004/qwen3-8b-manimator-gold-sft"} +{"system": "You are an expert Manim Community Edition (ManimCE v0.19+) Python developer and mathematical animator. Given a user request, first plan the spatial layout, coordinate bounds, timing, and pedagogical flow inside ... tags (when reasoning is helpful), and then output a complete, runnable, self-contained ManimCE Python script using `from manim import *`. Never use deprecated ManimGL (`manimlib`) methods like `ShowCreation`, `TexMobject`, `TextMobject`, or `axes.get_graph`; always use modern ManimCE APIs (`Create`, `MathTex`, `Tex`, `Text`, `axes.plot`) and prevent visual overlap using `.to_edge()`, `.next_to()`, and `FadeOut`.", "prompt": "Create a step-by-step educational Manim CE lecture scene explaining: Taylor Series Expansion of exp(x).\n\n```python\nfrom manim import *\nimport numpy as np\n\nclass PedagogicalScene56(Scene):\n def construct(self):\n title = Title(r\"Taylor Series of $f(x) = e^x$ around $x=0$\")\n ax = Axes(x_range=[-3, 3, 1], y_range=[-1, 8, 2], x_length=6, y_length=4)\n exp_curve = ax.plot(lambda x: np.exp(x), color=WHITE)\n exp_label = MathTex(r\"e^x\").next_to(ax.c2p(2, np.exp(2)), RIGHT)\n \n t1 = ax.plot(lambda x: 1 + x, color=BLUE)\n t2 = ax.plot(lambda x: 1 + x + 0.5 * x**2, color=GREEN)\n t3 = ax.plot(lambda x: 1 + x + 0.5 * x**2 + (1/6) * x**3, color=YELLOW)\n \n self.play(Write(title), Create(ax), Create(exp_curve), Write(exp_label))\n self.play(Create(t1), run_time=1.5)\n self.wait(0.5)\n self.play(Transform(t1, t2), run_time=1.5)\n self.wait(0.5)\n self.play(Transform(t1, t3), run_time=1.5)\n self.wait(2)\n```", "chosen": "```python\nfrom manim import *\nfrom manim_voiceover import VoiceoverScene\nfrom manim_voiceover.services.gtts import GTTSService\nimport numpy as np\n\nMARGIN = 0.5\n\nclass TaylorSeriesExpScene(VoiceoverScene):\n def fit_in_frame(self, mob: Mobject, w_frac=0.9, h_frac=0.9) -> Mobject:\n max_w = config.frame_width * w_frac\n max_h = config.frame_height * h_frac\n if mob.width > max_w: mob.width = max_w\n if mob.height > max_h: mob.height = max_h\n return mob\n\n def construct(self):\n self.set_speech_service(GTTSService(transcription_model=\"base\"))\n\n # [SETUP]\n title = Title(r\"Taylor Series of $f(x) = e^x$\", buff=MARGIN)\n ax = Axes(x_range=[-3, 3, 1], y_range=[-1, 8, 2], x_length=6, y_length=4)\n exp_curve = ax.plot(lambda x: np.exp(x), color=WHITE)\n exp_label = MathTex(r\"e^x\").next_to(ax.c2p(2, np.exp(2)), RIGHT)\n t1 = ax.plot(lambda x: 1 + x, color=BLUE)\n t2 = ax.plot(lambda x: 1 + x + 0.5 * x**2, color=GREEN)\n t3 = ax.plot(lambda x: 1 + x + 0.5 * x**2 + (1/6) * x**3, color=YELLOW)\n\n # [LAYOUT]\n main_group = self.fit_in_frame(VGroup(title, ax, exp_curve, exp_label))\n self.add(main_group)\n\n # [UPDATER]\n # None\n\n # [BEAT 1 | sync: b1]\n with self.voiceover(text=\"The Taylor series builds a polynomial approximation around the origin. \") as t_voice:\n self.wait_until_bookmark(\"b1\")\n self.play(Create(t1), run_time=1.5)\n\n # [BEAT 2 | sync: b2]\n with self.voiceover(text=\"Higher-order terms extend the region where the polynomial closely matches the exponential. \") as t_voice:\n self.wait_until_bookmark(\"b2\")\n self.play(Transform(t1, t2), run_time=1.5)\n self.play(Transform(t1, t3), run_time=1.5)\n self.wait(1)\n```", "rejected": "```python\nfrom manim import *\nfrom manim_voiceover import VoiceoverScene\nfrom manim_voiceover.services.gtts import GTTSService\nimport numpy as np\n\nMARGIN = 0.5\n\nclass TaylorSeriesExpScene(VoiceoverScene):\n def fit_in_frame(self, mob: Mobject, w_frac=0.9, h_frac=0.9) -> Mobject:\n max_w = config.frame_width * w_frac\n max_h = config.frame_height * h_frac\n if mob.width > max_w: mob.width = max_w\n if mob.height > max_h: mob.height = max_h\n return mob\n\n def construct(self):\n self.set_speech_service(GTTSService(transcription_model=\"base\"))\n\n # [SETUP]\n title = Title(r\"Taylor Series of $f(x) = e^x$\", buff=MARGIN)\n ax = Axes(x_range=[-3, 3, 1], y_range=[-1, 8, 2], x_length=6, y_length=4)\n exp_curve = ax.get_graph(lambda x: np.exp(x), color=WHITE)\n exp_label = TexMobject(r\"e^x\").next_to(ax.c2p(2, np.exp(2)), RIGHT)\n t1 = ax.plot(lambda x: 1 + x, color=BLUE)\n t2 = ax.plot(lambda x: 1 + x + 0.5 * x**2, color=GREEN)\n t3 = ax.plot(lambda x: 1 + x + 0.5 * x**2 + (1/6) * x**3, color=YELLOW)\n\n # [LAYOUT]\n main_group = self.fit_in_frame(VGroup(title, ax, exp_curve, exp_label))\n self.add(main_group)\n\n # [UPDATER]\n # None\n\n # [BEAT 1 | sync: b1]\n with self.voiceover(text=\"The Taylor series builds a polynomial approximation around the origin. \") as t_voice:\n self.wait_until_bookmark(\"b1\")\n self.play(ShowCreation(t1), run_time=1.5)\n\n # [BEAT 2 | sync: b2]\n with self.voiceover(text=\"Higher-order terms extend the region where the polynomial closely matches the exponential. \") as t_voice:\n self.wait_until_bookmark(\"b2\")\n self.play(Transform(t1, t2), run_time=1.5)\n self.play(Transform(t1, t3), run_time=1.5)\n self.wait(1)\n```", "category": "legacy_api_hallucination", "source": "synthetic_hard_neg:nabin2004/qwen3-8b-manimator-gold-sft"} +{"system": "You are an expert Manim Community Edition (ManimCE v0.19+) Python developer and mathematical animator. Given a user request, first plan the spatial layout, coordinate bounds, timing, and pedagogical flow inside ... tags (when reasoning is helpful), and then output a complete, runnable, self-contained ManimCE Python script using `from manim import *`. Never use deprecated ManimGL (`manimlib`) methods like `ShowCreation`, `TexMobject`, `TextMobject`, or `axes.get_graph`; always use modern ManimCE APIs (`Create`, `MathTex`, `Tex`, `Text`, `axes.plot`) and prevent visual overlap using `.to_edge()`, `.next_to()`, and `FadeOut`.", "prompt": "I'm learning why exploding gradients crash training.\nAnimate massive parameter updates that push the loss skyward, showing how gradient norms explode, then show a remedy like gradient clipping.\nInclude a side-by-side comparison of a stable run vs with clipping, and visualize the loss trajectory as a vertical spike followed by stabilization.", "chosen": "```python\nfrom manim import *\nfrom manim_voiceover import VoiceoverScene\nfrom manim_voiceover.services.gtts import GTTSService\n\nclass ExplodingGradientsAndClipping(VoiceoverScene):\n def construct(self):\n self.set_speech_service(\n GTTSService(voice=\"alba\", cache_dir=\"voiceover_cache\")\n )\n \n # Title\n title = Text(\"Exploding Gradients & Clipping\", font_size=36, color=BLUE)\n title.to_edge(UP, buff=0.5)\n \n with self.voiceover(text=\"Have you ever trained a neural network and noticed that the loss just skyrockets unexpectedly?\") as tracker:\n self.play(Write(title), run_time=tracker.duration)\n \n with self.voiceover(text=\"This common issue, known as exploding gradients, can derail your training process. Curious about why this happens and how to fix it? Let's dive in!\") as tracker:\n self.wait(tracker.duration)\n \n self.play(FadeOut(title))\n \n # Section 1: What are exploding gradients?\n section1_title = Text(\"What are Exploding Gradients?\", font_size=30, color=YELLOW)\n section1_title.to_edge(UP, buff=0.5)\n \n with self.voiceover(text=\"Exploding gradients occur when the gradients in a neural network become extremely large during backpropagation.\") as tracker:\n self.play(Write(section1_title), run_time=tracker.duration * 0.6)\n \n # Visual representation of gradient explosion\n neuron_layers = VGroup()\n \n # Create a simple 4-layer network representation\n layer_positions = [-4, -1.5, 1, 3.5]\n colors = [BLUE, GREEN, ORANGE, RED]\n \n for i, x in enumerate(layer_positions):\n neurons = VGroup(*[Circle(radius=0.25, color=colors[i], fill_opacity=0.3) for _ in range(3)])\n neurons.arrange(DOWN, buff=0.4)\n neurons.shift(RIGHT * x)\n neuron_layers.add(neurons)\n \n with self.voiceover(text=\"In deep networks, gradients are multiplied through many layers.\") as tracker:\n self.play(FadeIn(neuron_layers), run_time=tracker.duration)\n \n # Show gradient flow arrows growing\n grad_arrows = VGroup()\n \n for i in range(3):\n start = neuron_layers[i][1].get_right()\n end = neuron_layers[i+1][1].get_left()\n arrow = Arrow(start, end, buff=0.1, color=WHITE)\n grad_arrows.add(arrow)\n \n with self.voiceover(text=\"When weights are large, these multiplications compound, causing gradients to explode exponentially.\") as tracker:\n self.play(Create(grad_arrows[0]), run_time=0.5)\n self.play(Create(grad_arrows[1]), run_time=0.5)\n self.play(Create(grad_arrows[2]), run_time=0.5)\n \n # Show gradient values exploding\n grad_values = VGroup()\n val1 = MathTex(r\"0.5\").set_color(GREEN)\n val2 = MathTex(r\"2.5\").set_color(ORANGE)\n val3 = MathTex(r\"12.5\").set_color(RED)\n grad_values.add(val1, val2, val3)\n \n for i, (arrow, val) in enumerate(zip(grad_arrows, grad_values)):\n val.next_to(arrow, UP, buff=0.2)\n \n with self.voiceover(text=\"Watch as the gradient grows from 0 point 5, to 2 point 5, to 12 point 5 — getting larger with each layer!\") as tracker:\n for val in grad_values:\n self.play(Write(val), run_time=0.4)\n \n # Show explosion symbol\n explosion = Text(\"BOOM!\", font_size=48, color=RED)\n explosion.move_to(neuron_layers[-1])\n \n with self.voiceover(text=\"This explosion causes unstable training and massive weight updates.\") as tracker:\n self.play(Transform(grad_values[2].copy(), explosion), run_time=tracker.duration)\n \n self.play(FadeOut(section1_title), FadeOut(neuron_layers), FadeOut(grad_arrows), \n FadeOut(grad_values), FadeOut(explosion))\n \n # Section 2: Impact on training\n section2_title = Text(\"Impact on Training\", font_size=30, color=YELLOW)\n section2_title.to_edge(UP, buff=0.5)\n \n with self.voiceover(text=\"What happens when gradients explode? Let's look at the consequences.\") as tracker:\n self.play(Write(section2_title), run_time=tracker.duration)\n \n # Create a simple graph showing loss explosion\n axes = Axes(\n x_range=[0, 10, 1],\n y_range=[0, 50, 10],\n axis_config={\"color\": WHITE},\n x_length=8,\n y_length=4,\n )\n axes.to_edge(DOWN, buff=1)\n axes_labels = axes.get_axis_labels(x_label=\"Epochs\", y_label=\"Loss\")\n \n # Normal training curve (initial part)\n normal_curve = axes.plot(\n lambda x: 20 * (0.9 ** x) + 2,\n x_range=[0, 5],\n color=GREEN,\n )\n \n # Exploding curve\n explode_curve = axes.plot(\n lambda x: 2 * (1.8 ** (x - 5)) + 5,\n x_range=[5, 7.5],\n color=RED,\n )\n \n with self.voiceover(text=\"First, the loss might decrease normally.\") as tracker:\n self.play(Create(axes), Write(axes_labels), run_time=tracker.duration * 0.5)\n self.play(Create(normal_curve), run_time=tracker.duration * 0.5)\n \n with self.voiceover(text=\"But suddenly, it spikes dramatically!\") as tracker:\n self.play(Create(explode_curve), run_time=tracker.duration)\n \n # Add annotations\n stable_text = Text(\"Stable Training\", font_size=18, color=GREEN)\n stable_text.next_to(normal_curve, LEFT, buff=0.3)\n \n explode_text = Text(\"Explosion!\", font_size=20, color=RED)\n explode_text.next_to(explode_curve, RIGHT, buff=0.3)\n \n with self.voiceover(text=\"The exploding gradients cause weight updates so large that the model diverges completely.\") as tracker:\n self.play(Write(stable_text), Write(explode_text), run_time=tracker.duration)\n \n # Show NaN result\n nan_text = Text(\"Loss = NaN\", font_size=36, color=RED)\n nan_text.next_to(axes, RIGHT, buff=0.5)\n \n with self.voiceover(text=\"Eventually, you might see NaN values — not a number — meaning training has failed.\") as tracker:\n self.play(Write(nan_text), run_time=tracker.duration)\n \n self.play(FadeOut(section2_title), FadeOut(axes), FadeOut(axes_labels),\n FadeOut(normal_curve), FadeOut(explode_curve), FadeOut(stable_text),\n FadeOut(explode_text), FadeOut(nan_text))\n \n # Section 3: Gradient Clipping Solution\n section3_title = Text(\"Solution: Gradient Clipping\", font_size=30, color=YELLOW)\n section3_title.to_edge(UP, buff=0.5)\n \n with self.voiceover(text=\"Now for the solution: gradient clipping. This technique limits how large gradients can get.\") as tracker:\n self.play(Write(section3_title), run_time=tracker.duration)\n \n # Visual comparison\n unclipped_label = Text(\"Unclipped\", font_size=20, color=RED)\n clipped_label = Text(\"Clipped\", font_size=20, color=GREEN)\n \n unclipped_label.to_edge(LEFT, buff=1).shift(UP * 1)\n clipped_label.to_edge(RIGHT, buff=1).shift(UP * 1)\n \n with self.voiceover(text=\"Here's the difference between unclipped and clipped gradients.\") as tracker:\n self.play(Write(unclipped_label), Write(clipped_label), run_time=tracker.duration)\n \n # Unclipped bars (growing)\n unclipped_bars = VGroup()\n heights = [0.5, 1.2, 2.5, 4.8, 8.0]\n for i, h in enumerate(heights):\n bar = Rectangle(width=0.6, height=h, fill_color=RED, fill_opacity=0.7, stroke_color=WHITE)\n bar.shift(LEFT * 3 + DOWN * 1.5 + RIGHT * i * 0.8 + UP * h/2)\n unclipped_bars.add(bar)\n \n # Clipped bars (capped)\n clipped_bars = VGroup()\n max_height = 2.0\n for i, h in enumerate(heights):\n capped_h = min(h, max_height)\n bar = Rectangle(width=0.6, height=capped_h, fill_color=GREEN, fill_opacity=0.7, stroke_color=WHITE)\n bar.shift(RIGHT * 1 + DOWN * 1.5 + RIGHT * i * 0.8 + UP * capped_h/2)\n clipped_bars.add(bar)\n \n with self.voiceover(text=\"Without clipping, gradients grow unchecked. With clipping, they stay within a safe threshold.\") as tracker:\n self.play(Create(unclipped_bars), Create(clipped_bars), run_time=tracker.duration)\n \n # Add threshold line\n threshold_line = DashedLine(\n start=RIGHT * 0.5 + UP * 0.5,\n end=RIGHT * 4.5 + UP * 0.5,\n color=YELLOW\n )\n threshold_label = Text(\"Threshold\", font_size=16, color=YELLOW)\n threshold_label.next_to(threshold_line, RIGHT)\n \n with self.voiceover(text=\"We set a threshold. Any gradient exceeding it gets scaled down to this limit.\") as tracker:\n self.play(Create(threshold_line), Write(threshold_label), run_time=tracker.duration)\n \n # Formula - simplified\n formula = MathTex(r\"g \\leftarrow \\tau \\cdot \\frac{g}{||g||}\")\n formula.scale(0.9)\n formula.next_to(section3_title, DOWN, buff=0.5)\n \n with self.voiceover(text=\"Mathematically, if the gradient norm exceeds threshold tau, we rescale it to have norm tau.\") as tracker:\n self.play(Write(formula), run_time=tracker.duration)\n \n self.play(FadeOut(section3_title), FadeOut(unclipped_label), FadeOut(clipped_label),\n FadeOut(unclipped_bars), FadeOut(clipped_bars), FadeOut(threshold_line),\n FadeOut(threshold_label), FadeOut(formula))\n \n # Summary\n summary_title = Text(\"Key Takeaways\", font_size=32, color=BLUE)\n summary_title.to_edge(UP, buff=0.5)\n \n takeaways = VGroup(\n Text(\"1. Exploding gradients occur in deep networks\", font_size=22),\n Text(\"2. They cause unstable training and NaN losses\", font_size=22),\n Text(\"3. Gradient clipping limits gradient magnitude\", font_size=22),\n Text(\"4. Set an appropriate threshold for your model\", font_size=22),\n )\n takeaways.arrange(DOWN, aligned_edge=LEFT, buff=0.5)\n takeaways.next_to(summary_title, DOWN, buff=0.8)\n \n with self.voiceover(text=\"To summarize: exploding gradients occur in deep networks when gradient magnitudes compound through layers.\") as tracker:\n self.play(Write(summary_title), run_time=tracker.duration * 0.5)\n self.play(Write(takeaways[0]), run_time=tracker.duration * 0.25)\n \n with self.voiceover(text=\"They cause unstable training and can lead to NaN losses.\") as tracker:\n self.play(Write(takeaways[1]), run_time=tracker.duration)\n \n with self.voiceover(text=\"Gradient clipping is a simple but effective solution that limits gradient magnitudes to a threshold.\") as tracker:\n self.play(Write(takeaways[2]), run_time=tracker.duration)\n \n with self.voiceover(text=\"Remember to choose an appropriate threshold for your specific model and problem. Happy training!\") as tracker:\n self.play(Write(takeaways[3]), run_time=tracker.duration)\n \n self.wait(1)\n```", "rejected": "```python\nfrom manim import *\nfrom manim_voiceover import VoiceoverScene\nfrom manim_voiceover.services.gtts import GTTSService\n\nclass ExplodingGradientsAndClipping(VoiceoverScene):\n def construct(self):\n self.set_speech_service(\n GTTSService(voice=\"alba\", cache_dir=\"voiceover_cache\")\n )\n \n # Title\n title = Text(\"Exploding Gradients & Clipping\", font_size=36, color=BLUE)\n title.to_edge(UP, buff=0.5)\n \n with self.voiceover(text=\"Have you ever trained a neural network and noticed that the loss just skyrockets unexpectedly?\") as tracker:\n self.play(Write(title), run_time=tracker.duration)\n \n with self.voiceover(text=\"This common issue, known as exploding gradients, can derail your training process. Curious about why this happens and how to fix it? Let's dive in!\") as tracker:\n self.wait(tracker.duration)\n \n self.play(FadeOut(title))\n \n # Section 1: What are exploding gradients?\n section1_title = Text(\"What are Exploding Gradients?\", font_size=30, color=YELLOW)\n section1_title.to_edge(UP, buff=0.5)\n \n with self.voiceover(text=\"Exploding gradients occur when the gradients in a neural network become extremely large during backpropagation.\") as tracker:\n self.play(Write(section1_title), run_time=tracker.duration * 0.6)\n \n # Visual representation of gradient explosion\n neuron_layers = VGroup()\n \n # Create a simple 4-layer network representation\n layer_positions = [-4, -1.5, 1, 3.5]\n colors = [BLUE, GREEN, ORANGE, RED]\n \n for i, x in enumerate(layer_positions):\n neurons = VGroup(*[Circle(radius=0.25, color=colors[i], fill_opacity=0.3) for _ in range(3)])\n neurons.arrange(DOWN, buff=0.4)\n neurons.shift(RIGHT * x)\n neuron_layers.add(neurons)\n \n with self.voiceover(text=\"In deep networks, gradients are multiplied through many layers.\") as tracker:\n self.play(FadeIn(neuron_layers), run_time=tracker.duration)\n \n # Show gradient flow arrows growing\n grad_arrows = VGroup()\n \n for i in range(3):\n start = neuron_layers[i][1].get_right()\n end = neuron_layers[i+1][1].get_left()\n arrow = Arrow(start, end, buff=0.1, color=WHITE)\n grad_arrows.add(arrow)\n \n with self.voiceover(text=\"When weights are large, these multiplications compound, causing gradients to explode exponentially.\") as tracker:\n self.play(Create(grad_arrows[0]), run_time=0.5)\n self.play(Create(grad_arrows[1]), run_time=0.5)\n self.play(Create(grad_arrows[2]), run_time=0.5)\n \n # Show gradient values exploding\n grad_values = VGroup()\n val1 = MathTex(r\"0.5\").set_color(GREEN)\n val2 = MathTex(r\"2.5\").set_color(ORANGE)\n val3 = MathTex(r\"12.5\").set_color(RED)\n grad_values.add(val1, val2, val3)\n \n for i, (arrow, val) in enumerate(zip(grad_arrows, grad_values)):\n val.next_to(arrow, UP, buff=0.2)\n \n with self.voiceover(text=\"Watch as the gradient grows from 0 point 5, to 2 point 5, to 12 point 5 — getting larger with each layer!\") as tracker:\n for val in grad_values:\n self.play(Write(val), run_time=0.4)\n \n # Show explosion symbol\n explosion = Text(\"BOOM!\", font_size=48, color=RED)\n explosion.move_to(neuron_layers[-1])\n \n with self.voiceover(text=\"This explosion causes unstable training and massive weight updates.\") as tracker:\n self.play(Transform(grad_values[2].copy(), explosion), run_time=tracker.duration)\n \n self.play(FadeOut(section1_title), FadeOut(neuron_layers), FadeOut(grad_arrows), \n FadeOut(grad_values), FadeOut(explosion))\n \n # Section 2: Impact on training\n section2_title = Text(\"Impact on Training\", font_size=30, color=YELLOW)\n section2_title.to_edge(UP, buff=0.5)\n \n with self.voiceover(text=\"What happens when gradients explode? Let's look at the consequences.\") as tracker:\n self.play(Write(section2_title), run_time=tracker.duration)\n \n # Create a simple graph showing loss explosion\n axes = Axes(axis_color=BLUE, \n x_range=[0, 10, 1],\n y_range=[0, 50, 10],\n axis_config={\"color\": WHITE},\n x_length=8,\n y_length=4,\n )\n axes.to_edge(DOWN, buff=1)\n axes_labels = axes.get_axis_labels(x_label=\"Epochs\", y_label=\"Loss\")\n \n # Normal training curve (initial part)\n normal_curve = axes.plot(\n lambda x: 20 * (0.9 ** x) + 2,\n x_range=[0, 5],\n color=GREEN,\n )\n \n # Exploding curve\n explode_curve = axes.plot(\n lambda x: 2 * (1.8 ** (x - 5)) + 5,\n x_range=[5, 7.5],\n color=RED,\n )\n \n with self.voiceover(text=\"First, the loss might decrease normally.\") as tracker:\n self.play(Create(axes), Write(axes_labels), run_time=tracker.duration * 0.5)\n self.play(Create(normal_curve), run_time=tracker.duration * 0.5)\n \n with self.voiceover(text=\"But suddenly, it spikes dramatically!\") as tracker:\n self.play(Create(explode_curve), run_time=tracker.duration)\n \n # Add annotations\n stable_text = Text(\"Stable Training\", font_size=18, color=GREEN)\n stable_text.next_to(normal_curve, LEFT, buff=0.3)\n \n explode_text = Text(\"Explosion!\", font_size=20, color=RED)\n explode_text.next_to(explode_curve, RIGHT, buff=0.3)\n \n with self.voiceover(text=\"The exploding gradients cause weight updates so large that the model diverges completely.\") as tracker:\n self.play(Write(stable_text), Write(explode_text), run_time=tracker.duration)\n \n # Show NaN result\n nan_text = Text(\"Loss = NaN\", font_size=36, color=RED)\n nan_text.next_to(axes, RIGHT, buff=0.5)\n \n with self.voiceover(text=\"Eventually, you might see NaN values — not a number — meaning training has failed.\") as tracker:\n self.play(Write(nan_text), run_time=tracker.duration)\n \n self.play(FadeOut(section2_title), FadeOut(axes), FadeOut(axes_labels),\n FadeOut(normal_curve), FadeOut(explode_curve), FadeOut(stable_text),\n FadeOut(explode_text), FadeOut(nan_text))\n \n # Section 3: Gradient Clipping Solution\n section3_title = Text(\"Solution: Gradient Clipping\", font_size=30, color=YELLOW)\n section3_title.to_edge(UP, buff=0.5)\n \n with self.voiceover(text=\"Now for the solution: gradient clipping. This technique limits how large gradients can get.\") as tracker:\n self.play(Write(section3_title), run_time=tracker.duration)\n \n # Visual comparison\n unclipped_label = Text(\"Unclipped\", font_size=20, color=RED)\n clipped_label = Text(\"Clipped\", font_size=20, color=GREEN)\n \n unclipped_label.to_edge(LEFT, buff=1).shift(UP * 1)\n clipped_label.to_edge(RIGHT, buff=1).shift(UP * 1)\n \n with self.voiceover(text=\"Here's the difference between unclipped and clipped gradients.\") as tracker:\n self.play(Write(unclipped_label), Write(clipped_label), run_time=tracker.duration)\n \n # Unclipped bars (growing)\n unclipped_bars = VGroup()\n heights = [0.5, 1.2, 2.5, 4.8, 8.0]\n for i, h in enumerate(heights):\n bar = Rectangle(width=0.6, height=h, fill_color=RED, fill_opacity=0.7, stroke_color=WHITE)\n bar.shift(LEFT * 3 + DOWN * 1.5 + RIGHT * i * 0.8 + UP * h/2)\n unclipped_bars.add(bar)\n \n # Clipped bars (capped)\n clipped_bars = VGroup()\n max_height = 2.0\n for i, h in enumerate(heights):\n capped_h = min(h, max_height)\n bar = Rectangle(width=0.6, height=capped_h, fill_color=GREEN, fill_opacity=0.7, stroke_color=WHITE)\n bar.shift(RIGHT * 1 + DOWN * 1.5 + RIGHT * i * 0.8 + UP * capped_h/2)\n clipped_bars.add(bar)\n \n with self.voiceover(text=\"Without clipping, gradients grow unchecked. With clipping, they stay within a safe threshold.\") as tracker:\n self.play(Create(unclipped_bars), Create(clipped_bars), run_time=tracker.duration)\n \n # Add threshold line\n threshold_line = DashedLine(\n start=RIGHT * 0.5 + UP * 0.5,\n end=RIGHT * 4.5 + UP * 0.5,\n color=YELLOW\n )\n threshold_label = Text(\"Threshold\", font_size=16, color=YELLOW)\n threshold_label.next_to(threshold_line, RIGHT)\n \n with self.voiceover(text=\"We set a threshold. Any gradient exceeding it gets scaled down to this limit.\") as tracker:\n self.play(Create(threshold_line), Write(threshold_label), run_time=tracker.duration)\n \n # Formula - simplified\n formula = MathTex(r\"g \\leftarrow \\tau \\cdot \\frac{g}{||g||}\")\n formula.scale(0.9)\n formula.next_to(section3_title, DOWN, buff=0.5)\n \n with self.voiceover(text=\"Mathematically, if the gradient norm exceeds threshold tau, we rescale it to have norm tau.\") as tracker:\n self.play(Write(formula), run_time=tracker.duration)\n \n self.play(FadeOut(section3_title), FadeOut(unclipped_label), FadeOut(clipped_label),\n FadeOut(unclipped_bars), FadeOut(clipped_bars), FadeOut(threshold_line),\n FadeOut(threshold_label), FadeOut(formula))\n \n # Summary\n summary_title = Text(\"Key Takeaways\", font_size=32, color=BLUE)\n summary_title.to_edge(UP, buff=0.5)\n \n takeaways = VGroup(\n Text(\"1. Exploding gradients occur in deep networks\", font_size=22),\n Text(\"2. They cause unstable training and NaN losses\", font_size=22),\n Text(\"3. Gradient clipping limits gradient magnitude\", font_size=22),\n Text(\"4. Set an appropriate threshold for your model\", font_size=22),\n )\n takeaways.arrange(DOWN, aligned_edge=LEFT, buff=0.5)\n takeaways.next_to(summary_title, DOWN, buff=0.8)\n \n with self.voiceover(text=\"To summarize: exploding gradients occur in deep networks when gradient magnitudes compound through layers.\") as tracker:\n self.play(Write(summary_title), run_time=tracker.duration * 0.5)\n self.play(Write(takeaways[0]), run_time=tracker.duration * 0.25)\n \n with self.voiceover(text=\"They cause unstable training and can lead to NaN losses.\") as tracker:\n self.play(Write(takeaways[1]), run_time=tracker.duration)\n \n with self.voiceover(text=\"Gradient clipping is a simple but effective solution that limits gradient magnitudes to a threshold.\") as tracker:\n self.play(Write(takeaways[2]), run_time=tracker.duration)\n \n with self.voiceover(text=\"Remember to choose an appropriate threshold for your specific model and problem. Happy training!\") as tracker:\n self.play(Write(takeaways[3]), run_time=tracker.duration)\n \n self.wait(1)\n```", "category": "invalid_axes_kwarg", "source": "synthetic_hard_neg:nabin2004/AOS-Narrated-Manim-400"} +{"system": "You are an expert Manim Community Edition (ManimCE v0.19+) Python developer and mathematical animator. Given a user request, first plan the spatial layout, coordinate bounds, timing, and pedagogical flow inside ... tags (when reasoning is helpful), and then output a complete, runnable, self-contained ManimCE Python script using `from manim import *`. Never use deprecated ManimGL (`manimlib`) methods like `ShowCreation`, `TexMobject`, `TextMobject`, or `axes.get_graph`; always use modern ManimCE APIs (`Create`, `MathTex`, `Tex`, `Text`, `axes.plot`) and prevent visual overlap using `.to_edge()`, `.next_to()`, and `FadeOut`.", "prompt": "I'm learning about gradient computation in normalization layers and want a manual derivation of gradients with respect to gamma and beta using summations over the batch. Show the algebra visually, then animate the corresponding gradient vectors flowing from the batch statistics through the gamma/beta parameters, with a final numeric example.", "chosen": "```python\nfrom manim import *\nfrom manim_voiceover import VoiceoverScene\nfrom manim_voiceover.services.gtts import GTTSService\n\nclass GradientComputationScene(VoiceoverScene):\n def construct(self):\n self.set_speech_service(\n GTTSService(voice=\"alba\", cache_dir=\"voiceover_cache\")\n )\n\n # Title\n title = Tex(\"Gradient Computation in Normalization Layers\", font_size=40)\n title.to_edge(UP, buff=0.3)\n\n with self.voiceover(text=\"Welcome! Today, let us explore gradient computation in normalization layers, an essential piece of modern deep learning training.\") as tracker:\n self.play(Write(title), run_time=tracker.duration)\n\n # Introduction\n intro = Tex(\"Normalization stabilizes activations and speeds up training.\", font_size=32)\n intro.next_to(title, DOWN, buff=0.5)\n\n with self.voiceover(text=\"Normalization layers stabilize activations across different data scales, making models learn faster and more reliably.\") as tracker:\n self.play(Write(intro), run_time=tracker.duration)\n\n self.wait(0.3)\n\n # Normalization formulas\n bn = MathTex(r\"\\mathrm{Batch\\ Norm:}\\ \\hat{x} = \\frac{x-\\mu_B}{\\sqrt{\\sigma_B^2+\\epsilon}}\", font_size=24)\n ln = MathTex(r\"\\mathrm{Layer\\ Norm:}\\ \\hat{x} = \\frac{x-\\mu_L}{\\sqrt{\\sigma_L^2+\\epsilon}}\", font_size=24)\n norm_group = VGroup(bn, ln)\n norm_group.arrange(DOWN, buff=0.4, aligned_edge=LEFT)\n norm_group.move_to(ORIGIN)\n\n with self.voiceover(text=\"Two popular variants are batch normalization and layer normalization. Each centers and scales its inputs using local mean and variance.\") as tracker:\n self.play(FadeOut(intro), run_time=tracker.duration * 0.3)\n self.play(Write(norm_group), run_time=tracker.duration * 0.7)\n\n self.wait(0.3)\n\n # Chain rule section\n chain_label = Tex(\"Backpropagation uses the chain rule:\", font_size=30)\n eq1 = MathTex(r\"\\frac{\\partial L}{\\partial W} = \\frac{\\partial L}{\\partial \\mathrm{BN}} \\cdot \\frac{\\partial \\mathrm{BN}}{\\partial W}\", font_size=24)\n eq2 = MathTex(r\"\\frac{\\partial L}{\\partial X} = \\frac{\\partial L}{\\partial \\mathrm{BN}} \\cdot \\frac{\\partial \\mathrm{BN}}{\\partial X}\", font_size=24)\n chain_group = VGroup(chain_label, eq1, eq2)\n chain_group.arrange(DOWN, buff=0.35, aligned_edge=LEFT)\n chain_group.move_to(ORIGIN)\n\n with self.voiceover(text=\"To update weights, we need gradients. The chain rule tells us how loss flows backward through a normalization layer.\") as tracker:\n self.play(FadeOut(norm_group), run_time=tracker.duration * 0.3)\n self.play(Write(chain_group), run_time=tracker.duration * 0.7)\n\n self.wait(0.3)\n\n # Loss equation\n loss_eq = MathTex(r\"L = C + \\lambda R\", font_size=32)\n loss_eq.next_to(chain_group, DOWN, buff=0.5)\n\n with self.voiceover(text=\"Remember, total loss is the sum of cost plus a regularization term scaled by lambda.\") as tracker:\n self.play(Write(loss_eq), run_time=tracker.duration)\n\n self.wait(0.3)\n\n # Takeaway\n takeaway = Tex(r\"Key Takeaway: Proper gradient flow through normalization layers\\\\improves convergence and training efficiency.\", font_size=24)\n takeaway.to_edge(DOWN, buff=0.4)\n\n with self.voiceover(text=\"By computing these gradients correctly, you ensure stable gradient flow, leading to faster convergence and better models.\") as tracker:\n self.play(FadeIn(takeaway), run_time=tracker.duration)\n\n self.wait(1)\n```", "rejected": "```python\nfrom manim import *\n\nclass GradientComputationScene(Scene):\n\n def construct(self):\n title = Tex('Gradient Computation in Normalization Layers', font_size=40)\n title.to_edge(UP, buff=0.3)\n self.play(Write(title), run_time=2.0)\n intro = Tex('Normalization stabilizes activations and speeds up training.', font_size=32)\n intro.next_to(title, DOWN, buff=0.5)\n self.play(Write(intro), run_time=2.0)\n self.wait(0.3)\n bn = MathTex('\\\\mathrm{Batch\\\\ Norm:}\\\\ \\\\hat{x} = \\\\frac{x-\\\\mu_B}{\\\\sqrt{\\\\sigma_B^2+\\\\epsilon}}', font_size=24)\n ln = MathTex('\\\\mathrm{Layer\\\\ Norm:}\\\\ \\\\hat{x} = \\\\frac{x-\\\\mu_L}{\\\\sqrt{\\\\sigma_L^2+\\\\epsilon}}', font_size=24)\n norm_group = VGroup(bn, ln)\n norm_group.arrange(DOWN, buff=0.4, aligned_edge=LEFT)\n norm_group.move_to(ORIGIN)\n self.play(FadeOut(intro), run_time=2.0 * 0.3)\n self.play(Write(norm_group), run_time=2.0 * 0.7)\n self.wait(0.3)\n chain_label = Tex('Backpropagation uses the chain rule:', font_size=30)\n eq1 = MathTex('\\\\frac{\\\\partial L}{\\\\partial W} = \\\\frac{\\\\partial L}{\\\\partial \\\\mathrm{BN}} \\\\cdot \\\\frac{\\\\partial \\\\mathrm{BN}}{\\\\partial W}', font_size=24)\n eq2 = MathTex('\\\\frac{\\\\partial L}{\\\\partial X} = \\\\frac{\\\\partial L}{\\\\partial \\\\mathrm{BN}} \\\\cdot \\\\frac{\\\\partial \\\\mathrm{BN}}{\\\\partial X}', font_size=24)\n chain_group = VGroup(chain_label, eq1, eq2)\n chain_group.arrange(DOWN, buff=0.35, aligned_edge=LEFT)\n chain_group.move_to(ORIGIN)\n self.play(FadeOut(norm_group), run_time=2.0 * 0.3)\n self.play(Write(chain_group), run_time=2.0 * 0.7)\n self.wait(0.3)\n loss_eq = MathTex('L = C + \\\\lambda R', font_size=32)\n loss_eq.next_to(chain_group, DOWN, buff=0.5)\n self.play(Write(loss_eq), run_time=2.0)\n self.wait(0.3)\n takeaway = Tex('Key Takeaway: Proper gradient flow through normalization layers\\\\\\\\improves convergence and training efficiency.', font_size=24)\n takeaway.to_edge(DOWN, buff=0.4)\n self.play(FadeIn(takeaway), run_time=2.0)\n self.wait(1)\n```", "category": "narrated_pedagogical_preference", "source": "nabin2004/manim-narrated-dpo-400"} +{"system": "You are an expert Manim Community Edition (ManimCE v0.19+) Python developer and mathematical animator. Given a user request, first plan the spatial layout, coordinate bounds, timing, and pedagogical flow inside ... tags (when reasoning is helpful), and then output a complete, runnable, self-contained ManimCE Python script using `from manim import *`. Never use deprecated ManimGL (`manimlib`) methods like `ShowCreation`, `TexMobject`, `TextMobject`, or `axes.get_graph`; always use modern ManimCE APIs (`Create`, `MathTex`, `Tex`, `Text`, `axes.plot`) and prevent visual overlap using `.to_edge()`, `.next_to()`, and `FadeOut`.", "prompt": "Create an interactive Manim CE animation demonstrating: Cycloid Generation with TracedPath and rolling circle. Use updaters and ValueTracker.\n\n```python\nfrom manim import *\nimport numpy as np\n\nclass DynamicScene40(Scene):\n def construct(self):\n ground = Line(LEFT * 4 + DOWN * 1.5, RIGHT * 4 + DOWN * 1.5, color=GREY)\n r = 0.8\n theta = ValueTracker(0.0)\n \n wheel = always_redraw(lambda: Circle(radius=r, color=WHITE).move_to(\n LEFT * 3 + RIGHT * (r * theta.get_value()) + DOWN * (1.5 - r)\n ))\n dot = always_redraw(lambda: Dot(\n wheel.get_center() + np.array([-r * np.sin(theta.get_value()), -r * np.cos(theta.get_value()), 0]),\n color=RED, radius=0.08\n ))\n trail = TracedPath(dot.get_center, stroke_color=YELLOW, stroke_width=3)\n \n self.add(ground, trail, wheel, dot)\n self.play(theta.animate.set_value(2 * PI * 1.2), run_time=4, rate_func=linear)\n self.wait(1)\n```", "chosen": "```python\nfrom manim import *\nfrom manim_voiceover import VoiceoverScene\nfrom manim_voiceover.services.gtts import GTTSService\nimport numpy as np\n\nclass DynamicScene40(VoiceoverScene):\n MARGIN = 0.5\n\n def fit_in_frame(self, mob: Mobject, w_frac=0.9, h_frac=0.9) -> Mobject:\n max_w = config.frame_width * w_frac\n max_h = config.frame_height * h_frac\n if mob.width > max_w:\n mob.width = max_w\n if mob.height > max_h:\n mob.height = max_h\n return mob\n\n def construct(self):\n self.set_speech_service(GTTSService(transcription_model=\"base\"))\n \n # [SETUP]\n title = Title(\"Cycloid Generation\")\n self.fit_in_frame(title)\n \n # [LAYOUT]\n ground = Line(LEFT * 4 + DOWN * 1.5, RIGHT * 4 + DOWN * 1.5, color=GREY)\n r = 0.8\n theta = ValueTracker(0.0)\n \n # [UPDATER]\n wheel = always_redraw(lambda: Circle(radius=r, color=WHITE).move_to(\n LEFT * 3 + RIGHT * (r * theta.get_value()) + DOWN * (1.5 - r)\n ))\n dot = always_redraw(lambda: Dot(\n wheel.get_center() + np.array([-r * np.sin(theta.get_value()), -r * np.cos(theta.get_value()), 0]),\n color=RED, radius=0.08\n ))\n trail = TracedPath(dot.get_center, stroke_color=YELLOW, stroke_width=3)\n \n self.fit_in_frame(VGroup(ground, trail, wheel, dot))\n \n # [BEAT 1 | sync: b1]\n with self.voiceover(text=\"A cycloid is the curve traced by a point on the rim of a circular wheel. \") as t:\n self.wait_until_bookmark(\"b1\")\n self.play(Write(title), Create(ground), Create(wheel), Create(dot))\n \n # [BEAT 2 | sync: b2]\n with self.voiceover(text=\"As the wheel rolls along a straight line without slipping, the point traces the cycloid path.\") as t:\n self.add(trail)\n self.play(theta.animate.set_value(2 * PI * 1.2), run_time=4, rate_func=linear)\n self.wait(1)\n```", "rejected": "```python\nfrom manim import *\nfrom manim_voiceover import VoiceoverScene\nfrom manim_voiceover.services.gtts import GTTSService\nimport numpy as np\n\nclass DynamicScene40(VoiceoverScene):\n MARGIN = 0.5\n\n def fit_in_frame(self, mob: Mobject, w_frac=0.9, h_frac=0.9) -> Mobject:\n max_w = config.frame_width * w_frac\n max_h = config.frame_height * h_frac\n if mob.width > max_w:\n mob.width = max_w\n if mob.height > max_h:\n mob.height = max_h\n return mob\n\n def construct(self):\n self.set_speech_service(GTTSService(transcription_model=\"base\"))\n \n # [SETUP]\n title = Title(\"Cycloid Generation\")\n self.fit_in_frame(title)\n \n # [LAYOUT]\n ground = Line(LEFT * 4 + DOWN * 1.5, RIGHT * 4 + DOWN * 1.5, color=GREY)\n r = 0.8\n theta = ValueTracker(0.0)\n \n # [UPDATER]\n wheel = always_redraw(lambda: Circle(radius=r, color=WHITE).move_to(\n LEFT * 3 + RIGHT * (r * theta.get_value()) + DOWN * (1.5 - r)\n ))\n dot = always_redraw(lambda: Dot(\n wheel.get_center() + np.array([-r * np.sin(theta.get_value()), -r * np.cos(theta.get_value()), 0]),\n color=RED, radius=0.08\n ))\n trail = TracedPath(dot.get_center, stroke_color=YELLOW, stroke_width=3)\n \n self.fit_in_frame(VGroup(ground, trail, wheel, dot))\n \n # [BEAT 1 | sync: b1]\n with self.voiceover(text=\"A cycloid is the curve traced by a point on the rim of a circular wheel. \") as t:\n self.wait_until_bookmark(\"b1\")\n self.play(Write(title), ShowCreation(ground), Create(wheel), Create(dot))\n \n # [BEAT 2 | sync: b2]\n with self.voiceover(text=\"As the wheel rolls along a straight line without slipping, the point traces the cycloid path.\") as t:\n self.add(trail)\n self.play(theta.animate.set_value(2 * PI * 1.2), run_time=4, rate_func=linear)\n self.wait(1)\n```", "category": "legacy_api_hallucination", "source": "synthetic_hard_neg:nabin2004/qwen3-8b-manimator-gold-sft"} +{"system": "You are an expert Manim Community Edition (ManimCE v0.19+) Python developer and mathematical animator. Given a user request, first plan the spatial layout, coordinate bounds, timing, and pedagogical flow inside ... tags (when reasoning is helpful), and then output a complete, runnable, self-contained ManimCE Python script using `from manim import *`. Never use deprecated ManimGL (`manimlib`) methods like `ShowCreation`, `TexMobject`, `TextMobject`, or `axes.get_graph`; always use modern ManimCE APIs (`Create`, `MathTex`, `Tex`, `Text`, `axes.plot`) and prevent visual overlap using `.to_edge()`, `.next_to()`, and `FadeOut`.", "prompt": "I'm teaching undergrads about activation functions and want a vivid visualization of the derivative of tanh. Show tanh(x) and plot its derivative sech^2(x) as a bell-shaped curve, highlighting saturation where gradients vanish for large |x|. Include an interactive slider for x and color-code the regions where derivative is near zero versus near peak, with a label explaining vanishing gradients in deep nets.\n\n```python\nfrom manim import *\nimport numpy as np\n\nclass AOSTrajectoryScene89(Scene):\n def construct(self):\n # Visualize the derivative of the tanh function as a bell-shaped curve, highlighting regions of saturation (vanishing gradients).\n title = Title(\"Visualize the derivative of the tanh fun\")\n ax = Axes(x_range=[-3, 3, 1], y_range=[-1, 5, 1], x_length=6, y_length=4)\n curve = ax.plot(lambda x: 1 / (1 + np.exp(-x)), color=BLUE)\n label = MathTex(r'\\sigma(x) = \\frac{1}{1 + e^{-x}}').to_corner(UR)\n dot = Dot(ax.c2p(0, 0.5), color=RED)\n self.play(Write(title), Create(ax), Create(curve), Write(label), FadeIn(dot))\n self.play(dot.animate.move_to(ax.c2p(2, 1 / (1 + np.exp(-2)))), run_time=2)\n self.wait(1)\n```", "chosen": "```python\nfrom manim import *\nfrom manim_voiceover import VoiceoverScene\nfrom manim_voiceover.services.gtts import GTTSService\nimport numpy as np\n\nMARGIN = 0.5\n\nclass AOSTrajectoryScene89(VoiceoverScene):\n def fit_in_frame(self, mob: Mobject, w_frac=0.9, h_frac=0.9) -> Mobject:\n max_w = config.frame_width * w_frac\n max_h = config.frame_height * h_frac\n if mob.width > max_w:\n mob.width = max_w\n if mob.height > max_h:\n mob.height = max_h\n return mob\n\n def construct(self):\n self.set_speech_service(GTTSService(transcription_model=\"base\"))\n \n # [SETUP]\n ax = Axes(x_range=[-4, 4, 1], y_range=[-1.5, 1.5, 0.5], x_length=7, y_length=4)\n tanh_c = ax.plot(lambda x: np.tanh(x), color=BLUE)\n sech2_c = ax.plot(lambda x: 1.0 - np.tanh(x)**2, color=RED)\n \n x_val = ValueTracker(0.0)\n \n # [LAYOUT]\n dot_tanh = always_redraw(lambda: Dot(ax.c2p(x_val.get_value(), np.tanh(x_val.get_value())), color=BLUE, radius=0.08))\n dot_sech2 = always_redraw(lambda: Dot(ax.c2p(x_val.get_value(), 1.0 - np.tanh(x_val.get_value())**2), color=RED, radius=0.08))\n \n label_sat_left = Text(\"Saturation\", font_size=24, color=GREY).move_to(ax.c2p(-3, 1.2))\n label_sat_right = Text(\"Saturation\", font_size=24, color=GREY).move_to(ax.c2p(3, 1.2))\n label_peak = Text(\"Peak Gradient\", font_size=24, color=RED).next_to(ax.c2p(0, 1), UP)\n \n group = VGroup(ax, tanh_c, sech2_c, dot_tanh, dot_sech2, label_sat_left, label_sat_right, label_peak)\n group = self.fit_in_frame(group)\n self.add(ax, tanh_c, sech2_c, dot_tanh, dot_sech2, label_sat_left, label_sat_right, label_peak)\n \n # [UPDATER]\n # [BEAT 1 | sync: b1]\n with self.voiceover(text=\"We plot the tanh activation function in blue and its derivative, sech squared x, in red. \") as t:\n self.wait_until_bookmark(\"b1\")\n self.play(x_val.animate.set_value(2.5), run_time=2)\n \n # [BEAT 2 | sync: b2]\n with self.voiceover(text=\"Notice how the derivative approaches zero for large absolute values of x, illustrating the vanishing gradient problem in deep networks. \") as t:\n self.wait_until_bookmark(\"b2\")\n self.play(x_val.animate.set_value(-3.5), run_time=3)\n self.play(x_val.animate.set_value(3.5), run_time=3)\n```", "rejected": "```python\nfrom manim import *\nfrom manim_voiceover import VoiceoverScene\nfrom manim_voiceover.services.gtts import GTTSService\nimport numpy as np\n\nMARGIN = 0.5\n\nclass AOSTrajectoryScene89(VoiceoverScene):\n def fit_in_frame(self, mob: Mobject, w_frac=0.9, h_frac=0.9) -> Mobject:\n max_w = config.frame_width * w_frac\n max_h = config.frame_height * h_frac\n if mob.width > max_w:\n mob.width = max_w\n if mob.height > max_h:\n mob.height = max_h\n return mob\n\n def construct(self):\n self.set_speech_service(GTTSService(transcription_model=\"base\"))\n \n # [SETUP]\n ax = Axes(axis_color=BLUE, x_range=[-4, 4, 1], y_range=[-1.5, 1.5, 0.5], x_length=7, y_length=4)\n tanh_c = ax.plot(lambda x: np.tanh(x), color=BLUE)\n sech2_c = ax.plot(lambda x: 1.0 - np.tanh(x)**2, color=RED)\n \n x_val = ValueTracker(0.0)\n \n # [LAYOUT]\n dot_tanh = always_redraw(lambda: Dot(ax.c2p(x_val.get_value(), np.tanh(x_val.get_value())), color=BLUE, radius=0.08))\n dot_sech2 = always_redraw(lambda: Dot(ax.c2p(x_val.get_value(), 1.0 - np.tanh(x_val.get_value())**2), color=RED, radius=0.08))\n \n label_sat_left = Text(\"Saturation\", font_size=24, color=GREY).move_to(ax.c2p(-3, 1.2))\n label_sat_right = Text(\"Saturation\", font_size=24, color=GREY).move_to(ax.c2p(3, 1.2))\n label_peak = Text(\"Peak Gradient\", font_size=24, color=RED).next_to(ax.c2p(0, 1), UP)\n \n group = VGroup(ax, tanh_c, sech2_c, dot_tanh, dot_sech2, label_sat_left, label_sat_right, label_peak)\n group = self.fit_in_frame(group)\n self.add(ax, tanh_c, sech2_c, dot_tanh, dot_sech2, label_sat_left, label_sat_right, label_peak)\n \n # [UPDATER]\n # [BEAT 1 | sync: b1]\n with self.voiceover(text=\"We plot the tanh activation function in blue and its derivative, sech squared x, in red. \") as t:\n self.wait_until_bookmark(\"b1\")\n self.play(x_val.animate.set_value(2.5), run_time=2)\n \n # [BEAT 2 | sync: b2]\n with self.voiceover(text=\"Notice how the derivative approaches zero for large absolute values of x, illustrating the vanishing gradient problem in deep networks. \") as t:\n self.wait_until_bookmark(\"b2\")\n self.play(x_val.animate.set_value(-3.5), run_time=3)\n self.play(x_val.animate.set_value(3.5), run_time=3)\n```", "category": "invalid_axes_kwarg", "source": "synthetic_hard_neg:nabin2004/qwen3-8b-manimator-gold-sft"} +{"system": "You are an expert Manim Community Edition (ManimCE v0.19+) Python developer and mathematical animator. Given a user request, first plan the spatial layout, coordinate bounds, timing, and pedagogical flow inside ... tags (when reasoning is helpful), and then output a complete, runnable, self-contained ManimCE Python script using `from manim import *`. Never use deprecated ManimGL (`manimlib`) methods like `ShowCreation`, `TexMobject`, `TextMobject`, or `axes.get_graph`; always use modern ManimCE APIs (`Create`, `MathTex`, `Tex`, `Text`, `axes.plot`) and prevent visual overlap using `.to_edge()`, `.next_to()`, and `FadeOut`.", "prompt": "I'm learning robustness to misspecification and want to animate sensitivity analysis: perturb priors/likelihoods, display how outputs shift, and plot robustness measures across a parameter grid with quick scenario comparisons.", "chosen": "```python\nfrom manim import *\n\nclass RobustnessToMisspecification(Scene):\n\n def construct(self):\n title = Text('Robustness To Misspecification', font_size=40, color=BLUE)\n subtitle = Text(\"When Models Don't Match Reality\", font_size=24, color=GRAY)\n title_group = VGroup(title, subtitle).arrange(DOWN, buff=0.4)\n self.play(Write(title), FadeIn(subtitle), run_time=2.0)\n self.wait(0.3)\n self.play(FadeOut(title_group))\n ax = Axes(x_range=[-3, 3, 1], y_range=[-1, 10, 2], x_length=5, y_length=3.5, axis_config={'include_tip': False}).shift(LEFT * 2.5)\n data_coords = [(-2.5, 6.2), (-2, 4.3), (-1.5, 2.8), (-1, 1.2), (-0.5, 0.3), (0, 0.1), (0.5, 0.4), (1, 1.3), (1.5, 2.9), (2, 4.1), (2.5, 6.3)]\n dots = VGroup(*[Dot(ax.c2p(x, y), radius=0.06, color=BLUE) for x, y in data_coords])\n linear_line = Line(ax.c2p(-3, -1), ax.c2p(3, 7), color=RED, stroke_width=3)\n linear_label = Text('Linear Model', font_size=20, color=RED).next_to(linear_line.get_end(), RIGHT, buff=0.2)\n true_curve = ax.plot(lambda x: x ** 2, x_range=[-2.5, 2.5], color=GREEN, stroke_width=2)\n true_label = Text('True Pattern', font_size=20, color=GREEN).next_to(ax.c2p(1.8, 3.2), RIGHT, buff=0.2)\n right_panel = VGroup(Text('Reality: Complex', font_size=20, color=GREEN), Text('Model: Linear', font_size=20, color=RED), Text('Result: Misspecified', font_size=20, color=YELLOW)).arrange(DOWN, buff=0.3, aligned_edge=LEFT)\n right_panel.next_to(ax, RIGHT, buff=0.5).shift(UP * 0.5)\n scene1 = VGroup(ax, dots, linear_line, linear_label, true_curve, true_label, right_panel)\n self.play(Create(ax), run_time=2.0 * 0.25)\n self.play(FadeIn(dots), run_time=2.0 * 0.25)\n self.play(Create(linear_line), FadeIn(linear_label), run_time=2.0 * 0.25)\n self.play(FadeIn(right_panel), run_time=2.0 * 0.25)\n residuals = VGroup()\n for x, y in data_coords:\n y_model = 4.0 / 3.0 * x + 3\n line = DashedLine(ax.c2p(x, y), ax.c2p(x, y_model), color=YELLOW, stroke_width=1)\n residuals.add(line)\n self.play(Create(residuals), run_time=2.0 * 0.5)\n self.play(Create(true_curve), FadeIn(true_label), run_time=2.0 * 0.5)\n self.wait(0.3)\n methods_title = Text('Building Robust Models', font_size=34, color=BLUE).to_edge(UP, buff=0.5)\n left_col = VGroup(Text('• Robust Loss Functions', font_size=22), Text('• Regularization', font_size=22), Text('• Ensemble Methods', font_size=22)).arrange(DOWN, buff=0.4, aligned_edge=LEFT)\n right_col = VGroup(Text('• Cross-Validation', font_size=22), Text('• Adversarial Training', font_size=22), Text('• Distributional Tests', font_size=22)).arrange(DOWN, buff=0.4, aligned_edge=LEFT)\n columns = VGroup(left_col, right_col).arrange(RIGHT, buff=1.5).next_to(methods_title, DOWN, buff=0.6)\n box = SurroundingRectangle(columns, buff=0.3, color=GRAY)\n self.play(FadeOut(scene1), FadeOut(residuals), run_time=0.5)\n self.play(Write(methods_title), run_time=2.0 * 0.3)\n self.play(FadeIn(left_col), FadeIn(right_col), Create(box), run_time=2.0 * 0.7)\n self.wait(0.3)\n testing_title = Text('Testing Under Varying Assumptions', font_size=32, color=BLUE).to_edge(UP, buff=0.5)\n test_items = VGroup(Text('• Sensitivity Analysis', font_size=22), Text('• Distribution Shift Detection', font_size=22), Text('• Bootstrap & Stress Tests', font_size=22), Text('• Out-of-Domain Evaluation', font_size=22)).arrange(DOWN, buff=0.4, aligned_edge=LEFT)\n test_items.next_to(testing_title, DOWN, buff=0.6)\n test_box = SurroundingRectangle(test_items, buff=0.3, color=GRAY)\n methods_scene = VGroup(methods_title, left_col, right_col, box)\n self.play(FadeOut(methods_scene), run_time=0.5)\n self.play(Write(testing_title), run_time=2.0 * 0.3)\n self.play(FadeIn(test_items), Create(test_box), run_time=2.0 * 0.7)\n self.wait(0.3)\n takeaways_title = Text('Key Takeaways', font_size=34, color=BLUE).to_edge(UP, buff=0.5)\n takeaways = VGroup(Text('1. Misspecification is common and detectable', font_size=22), Text('2. Robust methods protect against wrong assumptions', font_size=22), Text('3. Always test under varied, realistic conditions', font_size=22)).arrange(DOWN, buff=0.4, aligned_edge=LEFT)\n takeaways.next_to(takeaways_title, DOWN, buff=0.6)\n tw_box = SurroundingRectangle(takeaways, buff=0.3, color=GRAY)\n testing_scene = VGroup(testing_title, test_items, test_box)\n self.play(FadeOut(testing_scene), run_time=0.5)\n self.play(Write(takeaways_title), run_time=2.0 * 0.3)\n self.play(FadeIn(takeaways), Create(tw_box), run_time=2.0 * 0.7)\n self.wait(1)\n```", "rejected": "```python\nfrom manim import *\n\nclass RobustnessToMisspecification(Scene):\n\n def construct(self):\n title = Text('Robustness To Misspecification', font_size=40, color=BLUE)\n subtitle = Text(\"When Models Don't Match Reality\", font_size=24, color=GRAY)\n title_group = VGroup(title, subtitle).arrange(DOWN, buff=0.4)\n self.play(Write(title), FadeIn(subtitle), run_time=2.0)\n self.wait(0.3)\n self.play(FadeOut(title_group))\n ax = Axes(x_range=[-3, 3, 1], y_range=[-1, 10, 2], x_length=5, y_length=3.5, axis_config={'include_tip': False}).shift(LEFT * 2.5)\n data_coords = [(-2.5, 6.2), (-2, 4.3), (-1.5, 2.8), (-1, 1.2), (-0.5, 0.3), (0, 0.1), (0.5, 0.4), (1, 1.3), (1.5, 2.9), (2, 4.1), (2.5, 6.3)]\n dots = VGroup(*[Dot(ax.c2p(x, y), radius=0.06, color=BLUE) for x, y in data_coords])\n linear_line = Line(ax.c2p(-3, -1), ax.c2p(3, 7), color=RED, stroke_width=3)\n linear_label = Text('Linear Model', font_size=20, color=RED).next_to(linear_line.get_end(), RIGHT, buff=0.2)\n true_curve = ax.get_graph(lambda x: x ** 2, x_range=[-2.5, 2.5], color=GREEN, stroke_width=2)\n true_label = Text('True Pattern', font_size=20, color=GREEN).next_to(ax.c2p(1.8, 3.2), RIGHT, buff=0.2)\n right_panel = VGroup(Text('Reality: Complex', font_size=20, color=GREEN), Text('Model: Linear', font_size=20, color=RED), Text('Result: Misspecified', font_size=20, color=YELLOW)).arrange(DOWN, buff=0.3, aligned_edge=LEFT)\n right_panel.next_to(ax, RIGHT, buff=0.5).shift(UP * 0.5)\n scene1 = VGroup(ax, dots, linear_line, linear_label, true_curve, true_label, right_panel)\n self.play(ShowCreation(ax), run_time=2.0 * 0.25)\n self.play(FadeIn(dots), run_time=2.0 * 0.25)\n self.play(Create(linear_line), FadeIn(linear_label), run_time=2.0 * 0.25)\n self.play(FadeIn(right_panel), run_time=2.0 * 0.25)\n residuals = VGroup()\n for x, y in data_coords:\n y_model = 4.0 / 3.0 * x + 3\n line = DashedLine(ax.c2p(x, y), ax.c2p(x, y_model), color=YELLOW, stroke_width=1)\n residuals.add(line)\n self.play(Create(residuals), run_time=2.0 * 0.5)\n self.play(Create(true_curve), FadeIn(true_label), run_time=2.0 * 0.5)\n self.wait(0.3)\n methods_title = Text('Building Robust Models', font_size=34, color=BLUE).to_edge(UP, buff=0.5)\n left_col = VGroup(Text('• Robust Loss Functions', font_size=22), Text('• Regularization', font_size=22), Text('• Ensemble Methods', font_size=22)).arrange(DOWN, buff=0.4, aligned_edge=LEFT)\n right_col = VGroup(Text('• Cross-Validation', font_size=22), Text('• Adversarial Training', font_size=22), Text('• Distributional Tests', font_size=22)).arrange(DOWN, buff=0.4, aligned_edge=LEFT)\n columns = VGroup(left_col, right_col).arrange(RIGHT, buff=1.5).next_to(methods_title, DOWN, buff=0.6)\n box = SurroundingRectangle(columns, buff=0.3, color=GRAY)\n self.play(FadeOut(scene1), FadeOut(residuals), run_time=0.5)\n self.play(Write(methods_title), run_time=2.0 * 0.3)\n self.play(FadeIn(left_col), FadeIn(right_col), Create(box), run_time=2.0 * 0.7)\n self.wait(0.3)\n testing_title = Text('Testing Under Varying Assumptions', font_size=32, color=BLUE).to_edge(UP, buff=0.5)\n test_items = VGroup(Text('• Sensitivity Analysis', font_size=22), Text('• Distribution Shift Detection', font_size=22), Text('• Bootstrap & Stress Tests', font_size=22), Text('• Out-of-Domain Evaluation', font_size=22)).arrange(DOWN, buff=0.4, aligned_edge=LEFT)\n test_items.next_to(testing_title, DOWN, buff=0.6)\n test_box = SurroundingRectangle(test_items, buff=0.3, color=GRAY)\n methods_scene = VGroup(methods_title, left_col, right_col, box)\n self.play(FadeOut(methods_scene), run_time=0.5)\n self.play(Write(testing_title), run_time=2.0 * 0.3)\n self.play(FadeIn(test_items), Create(test_box), run_time=2.0 * 0.7)\n self.wait(0.3)\n takeaways_title = Text('Key Takeaways', font_size=34, color=BLUE).to_edge(UP, buff=0.5)\n takeaways = VGroup(Text('1. Misspecification is common and detectable', font_size=22), Text('2. Robust methods protect against wrong assumptions', font_size=22), Text('3. Always test under varied, realistic conditions', font_size=22)).arrange(DOWN, buff=0.4, aligned_edge=LEFT)\n takeaways.next_to(takeaways_title, DOWN, buff=0.6)\n tw_box = SurroundingRectangle(takeaways, buff=0.3, color=GRAY)\n testing_scene = VGroup(testing_title, test_items, test_box)\n self.play(FadeOut(testing_scene), run_time=0.5)\n self.play(Write(takeaways_title), run_time=2.0 * 0.3)\n self.play(FadeIn(takeaways), Create(tw_box), run_time=2.0 * 0.7)\n self.wait(1)\n```", "category": "legacy_api_hallucination", "source": "synthetic_hard_neg:nabin2004/AOS-Manim-SFT"} +{"system": "You are an expert Manim Community Edition (ManimCE v0.19+) Python developer and mathematical animator. Given a user request, first plan the spatial layout, coordinate bounds, timing, and pedagogical flow inside ... tags (when reasoning is helpful), and then output a complete, runnable, self-contained ManimCE Python script using `from manim import *`. Never use deprecated ManimGL (`manimlib`) methods like `ShowCreation`, `TexMobject`, `TextMobject`, or `axes.get_graph`; always use modern ManimCE APIs (`Create`, `MathTex`, `Tex`, `Text`, `axes.plot`) and prevent visual overlap using `.to_edge()`, `.next_to()`, and `FadeOut`.", "prompt": "I'm learning linear algebra for ML and want to visualize the first principal component of a weight matrix evolving over time. Animate the principal direction drifting in the weight space, with an accompanying plot of the corresponding eigenvalue and a 2D/3D visualization of the weight vectors' trajectory.", "chosen": "```python\nfrom manim import *\nfrom manim_voiceover import VoiceoverScene\nfrom manim_voiceover.services.gtts import GTTSService\nimport math\n\nclass PCAExplanation(VoiceoverScene):\n def construct(self):\n self.set_speech_service(\n GTTSService(voice=\"alba\", cache_dir=\"voiceover_cache\")\n )\n\n # --- Title ---\n title = Text(\"Principal Component Analysis\", font_size=44)\n subtitle = Text(\"PCA\", font_size=32)\n subtitle.next_to(title, DOWN)\n t_grp = VGroup(title, subtitle)\n\n with self.voiceover(text=\"Have you ever wondered how Google Photos can group similar pictures together? It’s all thanks to a powerful technique called Principal Component Analysis, or PCA!\") as tracker:\n self.play(FadeIn(title), run_time=tracker.duration/2)\n self.play(FadeIn(subtitle), run_time=tracker.duration/2)\n\n with self.voiceover(text=\"In today's lecture, you will unlock the secrets behind this method that simplifies data while preserving its essential characteristics.\") as tracker:\n self.wait(tracker.duration)\n\n self.play(FadeOut(t_grp))\n\n # --- Data & Math ---\n raw_points = [\n (2.0, 1.8), (-2.0, -1.8),\n (1.0, 0.9), (-1.0, -0.9),\n (0.5, 0.4), (-0.5, -0.4),\n (1.5, 1.4), (-1.5, -1.4),\n (0.0, 0.1), (-0.2, -0.1)\n ]\n n = len(raw_points)\n mean_x = sum(p[0] for p in raw_points) / n\n mean_y = sum(p[1] for p in raw_points) / n\n centered = [(p[0]-mean_x, p[1]-mean_y) for p in raw_points]\n\n # covariance entries\n sxx = sum(x*x for x,y in centered)\n sxy = sum(x*y for x,y in centered)\n syy = sum(y*y for x,y in centered)\n a = sxx/(n-1)\n b = sxy/(n-1)\n c = syy/(n-1)\n trace = a + c\n det = a*c - b*b\n lam1 = (trace + math.sqrt(trace*trace - 4*det))/2\n lam2 = (trace - math.sqrt(trace*trace - 4*det))/2\n v1x, v1y = b, lam1 - a\n norm1 = math.sqrt(v1x*v1x + v1y*v1y)\n v1x, v1y = v1x/norm1, v1y/norm1\n v2x, v2y = -v1y, v1x\n\n # --- Axes & Points ---\n axes = Axes(\n x_range=[-3, 3, 1],\n y_range=[-2, 2, 1],\n x_length=6,\n y_length=4,\n axis_config={\"include_tip\": False, \"numbers_to_exclude\": [0]},\n )\n axes.shift(DOWN*0.5)\n\n dots = VGroup(*[Dot(axes.c2p(x,y), radius=0.06, color=BLUE) for x,y in raw_points])\n\n with self.voiceover(text=\"Here is a cloud of data points in two dimensions. Real-world data often has many features, making it hard to visualize.\") as tracker:\n self.play(Create(axes), run_time=tracker.duration/2)\n self.play(FadeIn(dots, lag_ratio=0.1), run_time=tracker.duration/2)\n\n # --- Centering ---\n mean_dot = Dot(axes.c2p(mean_x, mean_y), color=YELLOW, radius=0.08)\n mean_label = MathTex(r\"\\bar{X}\").next_to(mean_dot, UR, buff=0.1).scale(0.8)\n centered_dots = VGroup(*[Dot(axes.c2p(x,y), radius=0.06, color=GREEN) for x,y in centered])\n\n with self.voiceover(text=\"The first step is to center the data by subtracting the mean from each point.\") as tracker:\n self.play(FadeIn(mean_dot), FadeIn(mean_label), run_time=tracker.duration/2)\n self.wait(tracker.duration/2)\n\n with self.voiceover(text=\"Now the origin represents the average of our dataset.\") as tracker:\n self.play(Transform(dots, centered_dots), FadeOut(mean_dot), FadeOut(mean_label), run_time=tracker.duration)\n\n # --- Covariance Matrix ---\n group_data = VGroup(axes, dots)\n cov_formula = MathTex(r\"\\text{Cov}(X) = \\frac{1}{n-1} (X - \\bar{X})^T (X - \\bar{X})\")\n cov_formula.scale(0.75).next_to(group_data, RIGHT, buff=0.4)\n\n with self.voiceover(text=\"Next, we compute the covariance matrix.\") as tracker:\n self.play(group_data.animate.scale(0.65).to_edge(LEFT, buff=0.4), run_time=tracker.duration)\n\n with self.voiceover(text=\"This square matrix tells us how features vary together. Notice the formula uses the centered data transposed multiplied by itself, scaled by one over n minus one.\") as tracker:\n self.play(Write(cov_formula), run_time=tracker.duration)\n\n # --- Eigenvectors ---\n origin = axes.c2p(0,0)\n scale_arrow = 1.8\n arrow1 = Arrow(origin, axes.c2p(v1x*scale_arrow, v1y*scale_arrow), buff=0, color=RED)\n arrow2 = Arrow(origin, axes.c2p(v2x*scale_arrow, v2y*scale_arrow), buff=0, color=ORANGE)\n pc1_lbl = MathTex(r\"\\mathbf{w}_1\").next_to(arrow1.get_end(), UR, buff=0.1).scale(0.7)\n pc2_lbl = MathTex(r\"\\mathbf{w}_2\").next_to(arrow2.get_end(), DL, buff=0.1).scale(0.7)\n\n with self.voiceover(text=\"Then we find the eigenvectors and eigenvalues of the covariance matrix.\") as tracker:\n self.play(FadeOut(cov_formula), group_data.animate.scale(1/0.65).move_to(ORIGIN), run_time=tracker.duration)\n\n with self.voiceover(text=\"The eigenvectors point in the directions of maximum variance, and the eigenvalues tell us how much variance each direction captures.\") as tracker:\n self.play(GrowArrow(arrow1), GrowArrow(arrow2), run_time=tracker.duration/2)\n self.play(FadeIn(pc1_lbl), FadeIn(pc2_lbl), run_time=tracker.duration/2)\n\n # --- Projection Formula ---\n proj_formula = MathTex(r\"X' = X \\, W\")\n proj_formula.scale(0.9).to_edge(UP)\n\n with self.voiceover(text=\"To reduce dimensions, we project the data onto these new axes. We multiply the data matrix X by the eigenvector matrix W to get the transformed data X prime.\") as tracker:\n self.play(Write(proj_formula), run_time=tracker.duration)\n\n # --- Animate Projection ---\n proj_pts = VGroup()\n proj_lines = VGroup()\n for x,y in centered:\n t = x*v1x + y*v1y\n px, py = t*v1x, t*v1y\n proj_pts.add(Dot(axes.c2p(px, py), radius=0.06, color=RED))\n proj_lines.add(DashedLine(axes.c2p(x,y), axes.c2p(px,py), color=GRAY, stroke_width=1.5))\n\n with self.voiceover(text=\"Watch as each point is projected onto the first principal component.\") as tracker:\n self.play(Create(proj_lines), FadeIn(proj_pts, lag_ratio=0.1), run_time=tracker.duration)\n\n # --- Variance Formula ---\n var_formula = MathTex(r\"\\text{Var}(X') = W^T \\, \\text{Cov}(X) \\, W\")\n var_formula.scale(0.8).next_to(proj_formula, DOWN, buff=0.3)\n\n with self.voiceover(text=\"The variance of the projected data is given by W transpose times the covariance matrix times W. This confirms that projecting onto the top eigenvectors preserves the most variance.\") as tracker:\n self.play(Write(var_formula), run_time=tracker.duration)\n\n # --- Results ---\n original_panel = VGroup(axes.copy(), dots.copy())\n original_panel.scale(0.6).to_edge(LEFT, buff=0.5)\n\n new_axes = Axes(\n x_range=[-3, 3, 1],\n y_range=[-2, 2, 1],\n x_length=5,\n y_length=3.5,\n axis_config={\"include_tip\": False, \"numbers_to_exclude\": [0]},\n )\n new_axes.scale(0.6).to_edge(RIGHT, buff=0.5)\n\n trans_points = [(x*v1x + y*v1y, x*v2x + y*v2y) for x,y in centered]\n trans_dots = VGroup(*[Dot(new_axes.c2p(x,y), radius=0.06, color=RED) for x,y in trans_points])\n\n pc1_text = MathTex(r\"\\text{PC}_1\").next_to(new_axes.x_axis.get_end(), DOWN, buff=0.1).scale(0.6)\n pc2_text = MathTex(r\"\\text{PC}_2\").next_to(new_axes.y_axis.get_end(), LEFT, buff=0.1).scale(0.6)\n\n with self.voiceover(text=\"Here is the result. PCA rotates the data so the first axis captures the most information. We can now drop the second axis and still keep the essential shape.\") as tracker:\n self.play(\n FadeOut(proj_lines), FadeOut(proj_pts), FadeOut(var_formula),\n FadeOut(proj_formula), FadeOut(arrow1), FadeOut(arrow2),\n FadeOut(pc1_lbl), FadeOut(pc2_lbl), FadeOut(group_data),\n run_time=tracker.duration/3\n )\n self.play(FadeIn(original_panel), run_time=tracker.duration/3)\n self.play(Create(new_axes), FadeIn(trans_dots), FadeIn(pc1_text), FadeIn(pc2_text), run_time=tracker.duration/3)\n\n # --- Summary ---\n summary_title = Text(\"Learning Outcomes\", font_size=40).to_edge(UP)\n outcomes = VGroup(\n Text(\"• Recognize the significance of PCA\", font_size=28),\n Text(\"• Calculate covariance matrices\", font_size=28),\n Text(\"• Apply PCA to transform data\", font_size=28),\n ).arrange(DOWN, aligned_edge=LEFT, buff=0.3).next_to(summary_title, DOWN, buff=0.5)\n\n with self.voiceover(text=\"Today you learned why PCA matters, how to compute the covariance matrix, and how to transform data into a lower-dimensional space while preserving its key characteristics.\") as tracker:\n self.play(\n FadeOut(original_panel), FadeOut(new_axes),\n FadeOut(trans_dots), FadeOut(pc1_text), FadeOut(pc2_text),\n run_time=tracker.duration/3\n )\n self.play(Write(summary_title), run_time=tracker.duration/3)\n self.play(FadeIn(outcomes, lag_ratio=0.15), run_time=tracker.duration/3)\n\n self.wait(1)\n```", "rejected": "```python\nfrom manim import *\nimport math\n\nclass PCAExplanation(Scene):\n\n def construct(self):\n title = Text('Principal Component Analysis', font_size=44)\n subtitle = Text('PCA', font_size=32)\n subtitle.next_to(title, DOWN)\n t_grp = VGroup(title, subtitle)\n self.play(FadeIn(title), run_time=2.0 / 2)\n self.play(FadeIn(subtitle), run_time=2.0 / 2)\n self.wait(2.0)\n self.play(FadeOut(t_grp))\n raw_points = [(2.0, 1.8), (-2.0, -1.8), (1.0, 0.9), (-1.0, -0.9), (0.5, 0.4), (-0.5, -0.4), (1.5, 1.4), (-1.5, -1.4), (0.0, 0.1), (-0.2, -0.1)]\n n = len(raw_points)\n mean_x = sum((p[0] for p in raw_points)) / n\n mean_y = sum((p[1] for p in raw_points)) / n\n centered = [(p[0] - mean_x, p[1] - mean_y) for p in raw_points]\n sxx = sum((x * x for x, y in centered))\n sxy = sum((x * y for x, y in centered))\n syy = sum((y * y for x, y in centered))\n a = sxx / (n - 1)\n b = sxy / (n - 1)\n c = syy / (n - 1)\n trace = a + c\n det = a * c - b * b\n lam1 = (trace + math.sqrt(trace * trace - 4 * det)) / 2\n lam2 = (trace - math.sqrt(trace * trace - 4 * det)) / 2\n v1x, v1y = (b, lam1 - a)\n norm1 = math.sqrt(v1x * v1x + v1y * v1y)\n v1x, v1y = (v1x / norm1, v1y / norm1)\n v2x, v2y = (-v1y, v1x)\n axes = Axes(x_range=[-3, 3, 1], y_range=[-2, 2, 1], x_length=6, y_length=4, axis_config={'include_tip': False, 'numbers_to_exclude': [0]})\n axes.shift(DOWN * 0.5)\n dots = VGroup(*[Dot(axes.c2p(x, y), radius=0.06, color=BLUE) for x, y in raw_points])\n self.play(Create(axes), run_time=2.0 / 2)\n self.play(FadeIn(dots, lag_ratio=0.1), run_time=2.0 / 2)\n mean_dot = Dot(axes.c2p(mean_x, mean_y), color=YELLOW, radius=0.08)\n mean_label = MathTex('\\\\bar{X}').next_to(mean_dot, UR, buff=0.1).scale(0.8)\n centered_dots = VGroup(*[Dot(axes.c2p(x, y), radius=0.06, color=GREEN) for x, y in centered])\n self.play(FadeIn(mean_dot), FadeIn(mean_label), run_time=2.0 / 2)\n self.wait(2.0 / 2)\n self.play(Transform(dots, centered_dots), FadeOut(mean_dot), FadeOut(mean_label), run_time=2.0)\n group_data = VGroup(axes, dots)\n cov_formula = MathTex('\\\\text{Cov}(X) = \\\\frac{1}{n-1} (X - \\\\bar{X})^T (X - \\\\bar{X})')\n cov_formula.scale(0.75).next_to(group_data, RIGHT, buff=0.4)\n self.play(group_data.animate.scale(0.65).to_edge(LEFT, buff=0.4), run_time=2.0)\n self.play(Write(cov_formula), run_time=2.0)\n origin = axes.c2p(0, 0)\n scale_arrow = 1.8\n arrow1 = Arrow(origin, axes.c2p(v1x * scale_arrow, v1y * scale_arrow), buff=0, color=RED)\n arrow2 = Arrow(origin, axes.c2p(v2x * scale_arrow, v2y * scale_arrow), buff=0, color=ORANGE)\n pc1_lbl = MathTex('\\\\mathbf{w}_1').next_to(arrow1.get_end(), UR, buff=0.1).scale(0.7)\n pc2_lbl = MathTex('\\\\mathbf{w}_2').next_to(arrow2.get_end(), DL, buff=0.1).scale(0.7)\n self.play(FadeOut(cov_formula), group_data.animate.scale(1 / 0.65).move_to(ORIGIN), run_time=2.0)\n self.play(GrowArrow(arrow1), GrowArrow(arrow2), run_time=2.0 / 2)\n self.play(FadeIn(pc1_lbl), FadeIn(pc2_lbl), run_time=2.0 / 2)\n proj_formula = MathTex(\"X' = X \\\\, W\")\n proj_formula.scale(0.9).to_edge(UP)\n self.play(Write(proj_formula), run_time=2.0)\n proj_pts = VGroup()\n proj_lines = VGroup()\n for x, y in centered:\n t = x * v1x + y * v1y\n px, py = (t * v1x, t * v1y)\n proj_pts.add(Dot(axes.c2p(px, py), radius=0.06, color=RED))\n proj_lines.add(DashedLine(axes.c2p(x, y), axes.c2p(px, py), color=GRAY, stroke_width=1.5))\n self.play(Create(proj_lines), FadeIn(proj_pts, lag_ratio=0.1), run_time=2.0)\n var_formula = MathTex(\"\\\\text{Var}(X') = W^T \\\\, \\\\text{Cov}(X) \\\\, W\")\n var_formula.scale(0.8).next_to(proj_formula, DOWN, buff=0.3)\n self.play(Write(var_formula), run_time=2.0)\n original_panel = VGroup(axes.copy(), dots.copy())\n original_panel.scale(0.6).to_edge(LEFT, buff=0.5)\n new_axes = Axes(x_range=[-3, 3, 1], y_range=[-2, 2, 1], x_length=5, y_length=3.5, axis_config={'include_tip': False, 'numbers_to_exclude': [0]})\n new_axes.scale(0.6).to_edge(RIGHT, buff=0.5)\n trans_points = [(x * v1x + y * v1y, x * v2x + y * v2y) for x, y in centered]\n trans_dots = VGroup(*[Dot(new_axes.c2p(x, y), radius=0.06, color=RED) for x, y in trans_points])\n pc1_text = MathTex('\\\\text{PC}_1').next_to(new_axes.x_axis.get_end(), DOWN, buff=0.1).scale(0.6)\n pc2_text = MathTex('\\\\text{PC}_2').next_to(new_axes.y_axis.get_end(), LEFT, buff=0.1).scale(0.6)\n self.play(FadeOut(proj_lines), FadeOut(proj_pts), FadeOut(var_formula), FadeOut(proj_formula), FadeOut(arrow1), FadeOut(arrow2), FadeOut(pc1_lbl), FadeOut(pc2_lbl), FadeOut(group_data), run_time=2.0 / 3)\n self.play(FadeIn(original_panel), run_time=2.0 / 3)\n self.play(Create(new_axes), FadeIn(trans_dots), FadeIn(pc1_text), FadeIn(pc2_text), run_time=2.0 / 3)\n summary_title = Text('Learning Outcomes', font_size=40).to_edge(UP)\n outcomes = VGroup(Text('• Recognize the significance of PCA', font_size=28), Text('• Calculate covariance matrices', font_size=28), Text('• Apply PCA to transform data', font_size=28)).arrange(DOWN, aligned_edge=LEFT, buff=0.3).next_to(summary_title, DOWN, buff=0.5)\n self.play(FadeOut(original_panel), FadeOut(new_axes), FadeOut(trans_dots), FadeOut(pc1_text), FadeOut(pc2_text), run_time=2.0 / 3)\n self.play(Write(summary_title), run_time=2.0 / 3)\n self.play(FadeIn(outcomes, lag_ratio=0.15), run_time=2.0 / 3)\n self.wait(1)\n```", "category": "narrated_pedagogical_preference", "source": "nabin2004/manim-narrated-dpo-400"} +{"system": "You are an expert Manim Community Edition (ManimCE v0.19+) Python developer and mathematical animator. Given a user request, first plan the spatial layout, coordinate bounds, timing, and pedagogical flow inside ... tags (when reasoning is helpful), and then output a complete, runnable, self-contained ManimCE Python script using `from manim import *`. Never use deprecated ManimGL (`manimlib`) methods like `ShowCreation`, `TexMobject`, `TextMobject`, or `axes.get_graph`; always use modern ManimCE APIs (`Create`, `MathTex`, `Tex`, `Text`, `axes.plot`) and prevent visual overlap using `.to_edge()`, `.next_to()`, and `FadeOut`.", "prompt": "I'm learning undergrad numerical analysis. Create a visual demonstration of Newton's method for root finding on a non-linear function. Show the 2D plot of f(x), its tangent at the current iterate, and the sequence of iterates from several starting points; highlight basins of attraction. Include a short error-progress plot and a side-by-side animation of the update rule x_{n+1}=x_n - f(x_n)/f'(x_n). Use multiple scenes with zooms into the curve near roots, and switch to a 3D view that overlays the surface z=f(x) with the tangent plane along the path. Compare a well-behaved polynomial and a problematic function to illustrate convergence vs divergence.", "chosen": "```python\nfrom manim import *\n\nclass NewtonMethodScene(Scene):\n\n def construct(self):\n title = Text(\"Newton's Method\", font_size=48, color=BLUE)\n subtitle = Text('Finding Roots Numerically', font_size=28, color=GRAY)\n title_group = VGroup(title, subtitle).arrange(DOWN, buff=0.3)\n self.play(Write(title), run_time=2.0 * 0.5)\n self.play(FadeIn(subtitle), run_time=2.0 * 0.5)\n self.wait(0.5)\n self.play(FadeOut(title_group))\n axes = Axes(x_range=[-0.5, 3.5, 0.5], y_range=[-1.5, 3.5, 0.5], x_length=7, y_length=5, axis_config={'include_tip': False, 'numbers_to_include': [0, 1, 2, 3]}).shift(DOWN * 0.3)\n\n def func(x):\n return x ** 2 - 2\n\n def deriv(x):\n return 2 * x\n graph = axes.plot(func, color=BLUE, x_range=[0.2, 3.2])\n graph_label = MathTex('f(x) = x^2 - 2', font_size=28, color=BLUE)\n graph_label.next_to(graph.get_end(), RIGHT, buff=0.2)\n self.play(Create(axes), run_time=2.0 * 0.4)\n self.play(Create(graph), FadeIn(graph_label), run_time=2.0 * 0.6)\n formula = MathTex(\"x_{n+1} = x_n - \\\\frac{f(x_n)}{f'(x_n)}\", font_size=36, color=YELLOW)\n formula.to_edge(UP, buff=0.3)\n formula_box = SurroundingRectangle(formula, color=YELLOW, buff=0.15, corner_radius=0.1)\n self.play(Write(formula), run_time=2.0 * 0.6)\n self.play(Create(formula_box), run_time=2.0 * 0.4)\n x0 = 2.5\n x_vals = [x0]\n for i in range(3):\n xn = x_vals[-1]\n fx = func(xn)\n dfx = deriv(xn)\n x_next = xn - fx / dfx\n x_vals.append(x_next)\n point_zero = Dot(axes.c2p(x_vals[0], func(x_vals[0])), color=RED, radius=0.08)\n label_x0 = MathTex('x_0', font_size=24, color=RED)\n label_x0.next_to(point_zero, UP, buff=0.15)\n self.play(FadeIn(point_zero, label_x0), run_time=2.0)\n colors = [ORANGE, GREEN, PURPLE]\n prev_point = point_zero\n prev_label = label_x0\n for i in range(3):\n xn = x_vals[i]\n fxn = func(xn)\n dfxn = deriv(xn)\n x_next = x_vals[i + 1]\n fx_next = func(x_next)\n tangent_point = axes.c2p(xn, fxn)\n tangent_slope = dfxn\n tangent_left_x = xn - 0.8\n tangent_right_x = xn + 0.8\n tangent_left_y = fxn + tangent_slope * (tangent_left_x - xn)\n tangent_right_y = fxn + tangent_slope * (tangent_right_x - xn)\n tangent_line = Line(axes.c2p(tangent_left_x, tangent_left_y), axes.c2p(tangent_right_x, tangent_right_y), color=YELLOW)\n x_axis_point = axes.c2p(xn, 0)\n vertical_line = DashedLine(tangent_point, x_axis_point, color=WHITE, dash_length=0.1)\n x_next_axis_point = axes.c2p(x_next, 0)\n horizontal_line = DashedLine(x_axis_point, x_next_axis_point, color=WHITE, dash_length=0.1)\n new_point = Dot(axes.c2p(x_next, fx_next), color=colors[i], radius=0.08)\n new_label = MathTex('x_' + str(i + 1), font_size=24, color=colors[i])\n new_label.next_to(new_point, UP if fx_next >= 0 else DOWN, buff=0.15)\n new_x_label = MathTex('x_' + str(i + 1), font_size=22, color=colors[i])\n new_x_label.next_to(x_next_axis_point, DOWN, buff=0.1)\n narrate_text = f'At x sub {i}, which is about {xn:.3f}, we draw the tangent line. The function value is {fxn:.3f}, and the slope is {dfxn:.3f}. The tangent crosses the x-axis at x sub {i + 1}, which is about {x_next:.4f}.'\n self.play(Create(tangent_line), run_time=2.0 * 0.25)\n self.play(Create(vertical_line), run_time=2.0 * 0.15)\n self.play(Create(horizontal_line), run_time=2.0 * 0.15)\n self.play(FadeIn(new_point, new_label, new_x_label), run_time=2.0 * 0.25)\n if i == 0:\n self.play(FadeOut(prev_label), run_time=2.0 * 0.1)\n else:\n self.play(FadeOut(prev_label), run_time=2.0 * 0.1)\n self.play(FadeOut(tangent_line), FadeOut(vertical_line), FadeOut(horizontal_line), FadeOut(new_x_label), run_time=0.5)\n prev_point = new_point\n prev_label = new_label\n root_label = MathTex('\\\\sqrt{2} \\\\approx 1.4142', font_size=28, color=GREEN)\n root_label.next_to(prev_point, RIGHT, buff=0.2)\n root_line = DashedLine(axes.c2p(1.4142, -0.1), axes.c2p(1.4142, 0.1), color=GREEN)\n self.play(FadeIn(root_label, root_line), run_time=2.0)\n self.play(FadeOut(formula), FadeOut(formula_box), FadeOut(graph_label), run_time=0.5)\n takeaway_title = Text('Key Takeaways', font_size=32, color=BLUE).to_edge(UP, buff=0.3)\n takeaways = VGroup(MathTex('\\\\bullet\\\\ \\\\text{Start with an initial guess } x_0', font_size=24), MathTex(\"\\\\bullet\\\\ \\\\text{Iterate: } x_{n+1} = x_n - \\\\frac{f(x_n)}{f'(x_n)}\", font_size=24), MathTex('\\\\bullet\\\\ \\\\text{Converges quickly near the root}', font_size=24), MathTex(\"\\\\bullet\\\\ \\\\text{Requires } f'(x) \\\\neq 0 \\\\text{ at the guess}\", font_size=24)).arrange(DOWN, aligned_edge=LEFT, buff=0.3)\n takeaways.next_to(takeaway_title, DOWN, buff=0.4)\n takeaway_box = SurroundingRectangle(takeaways, color=BLUE, buff=0.2, corner_radius=0.1)\n self.play(Write(takeaway_title), run_time=2.0 * 0.2)\n self.play(Write(takeaways), run_time=2.0 * 0.5)\n self.play(Create(takeaway_box), run_time=2.0 * 0.3)\n self.wait(2)\n```", "rejected": "```python\nfrom manim import *\n\nclass NewtonMethodScene(Scene):\n\n def construct(self):\n title = Text(\"Newton's Method\", font_size=48, color=BLUE)\n subtitle = Text('Finding Roots Numerically', font_size=28, color=GRAY)\n title_group = VGroup(title, subtitle).arrange(DOWN, buff=0.3)\n self.play(Write(title), run_time=2.0 * 0.5)\n self.play(FadeIn(subtitle), run_time=2.0 * 0.5)\n self.wait(0.5)\n self.play(FadeOut(title_group))\n axes = Axes(x_range=[-0.5, 3.5, 0.5], y_range=[-1.5, 3.5, 0.5], x_length=7, y_length=5, axis_config={'include_tip': False, 'numbers_to_include': [0, 1, 2, 3]})\n\n def func(x):\n return x ** 2 - 2\n\n def deriv(x):\n return 2 * x\n graph = axes.plot(func, color=BLUE, x_range=[0.2, 3.2])\n graph_label = MathTex('f(x) = x^2 - 2', font_size=28, color=BLUE)\n graph_label.next_to(graph.get_end(), RIGHT, buff=0.2)\n self.play(Create(axes), run_time=2.0 * 0.4)\n self.play(Create(graph), FadeIn(graph_label), run_time=2.0 * 0.6)\n formula = MathTex(\"x_{n+1} = x_n - \\\\frac{f(x_n)}{f'(x_n)}\", font_size=36, color=YELLOW)\n formula\n formula_box = SurroundingRectangle(formula, color=YELLOW, buff=0.15, corner_radius=0.1)\n self.play(Write(formula), run_time=2.0 * 0.6)\n self.play(Create(formula_box), run_time=2.0 * 0.4)\n x0 = 2.5\n x_vals = [x0]\n for i in range(3):\n xn = x_vals[-1]\n fx = func(xn)\n dfx = deriv(xn)\n x_next = xn - fx / dfx\n x_vals.append(x_next)\n point_zero = Dot(axes.c2p(x_vals[0], func(x_vals[0])), color=RED, radius=0.08)\n label_x0 = MathTex('x_0', font_size=24, color=RED)\n label_x0\n self.play(FadeIn(point_zero, label_x0), run_time=2.0)\n colors = [ORANGE, GREEN, PURPLE]\n prev_point = point_zero\n prev_label = label_x0\n for i in range(3):\n xn = x_vals[i]\n fxn = func(xn)\n dfxn = deriv(xn)\n x_next = x_vals[i + 1]\n fx_next = func(x_next)\n tangent_point = axes.c2p(xn, fxn)\n tangent_slope = dfxn\n tangent_left_x = xn - 0.8\n tangent_right_x = xn + 0.8\n tangent_left_y = fxn + tangent_slope * (tangent_left_x - xn)\n tangent_right_y = fxn + tangent_slope * (tangent_right_x - xn)\n tangent_line = Line(axes.c2p(tangent_left_x, tangent_left_y), axes.c2p(tangent_right_x, tangent_right_y), color=YELLOW)\n x_axis_point = axes.c2p(xn, 0)\n vertical_line = DashedLine(tangent_point, x_axis_point, color=WHITE, dash_length=0.1)\n x_next_axis_point = axes.c2p(x_next, 0)\n horizontal_line = DashedLine(x_axis_point, x_next_axis_point, color=WHITE, dash_length=0.1)\n new_point = Dot(axes.c2p(x_next, fx_next), color=colors[i], radius=0.08)\n new_label = MathTex('x_' + str(i + 1), font_size=24, color=colors[i])\n new_label.next_to(new_point, UP if fx_next >= 0 else DOWN, buff=0.15)\n new_x_label = MathTex('x_' + str(i + 1), font_size=22, color=colors[i])\n new_x_label.next_to(x_next_axis_point, DOWN, buff=0.1)\n narrate_text = f'At x sub {i}, which is about {xn:.3f}, we draw the tangent line. The function value is {fxn:.3f}, and the slope is {dfxn:.3f}. The tangent crosses the x-axis at x sub {i + 1}, which is about {x_next:.4f}.'\n self.play(Create(tangent_line), run_time=2.0 * 0.25)\n self.play(Create(vertical_line), run_time=2.0 * 0.15)\n self.play(Create(horizontal_line), run_time=2.0 * 0.15)\n self.play(FadeIn(new_point, new_label, new_x_label), run_time=2.0 * 0.25)\n if i == 0:\n self.play(FadeOut(prev_label), run_time=2.0 * 0.1)\n else:\n self.play(FadeOut(prev_label), run_time=2.0 * 0.1)\n self.play(FadeOut(tangent_line), FadeOut(vertical_line), FadeOut(horizontal_line), FadeOut(new_x_label), run_time=0.5)\n prev_point = new_point\n prev_label = new_label\n root_label = MathTex('\\\\sqrt{2} \\\\approx 1.4142', font_size=28, color=GREEN)\n root_label.next_to(prev_point, RIGHT, buff=0.2)\n root_line = DashedLine(axes.c2p(1.4142, -0.1), axes.c2p(1.4142, 0.1), color=GREEN)\n self.play(FadeIn(root_label, root_line), run_time=2.0)\n self.play(FadeOut(formula), FadeOut(formula_box), FadeOut(graph_label), run_time=0.5)\n takeaway_title = Text('Key Takeaways', font_size=32, color=BLUE).to_edge(UP, buff=0.3)\n takeaways = VGroup(MathTex('\\\\bullet\\\\ \\\\text{Start with an initial guess } x_0', font_size=24), MathTex(\"\\\\bullet\\\\ \\\\text{Iterate: } x_{n+1} = x_n - \\\\frac{f(x_n)}{f'(x_n)}\", font_size=24), MathTex('\\\\bullet\\\\ \\\\text{Converges quickly near the root}', font_size=24), MathTex(\"\\\\bullet\\\\ \\\\text{Requires } f'(x) \\\\neq 0 \\\\text{ at the guess}\", font_size=24)).arrange(DOWN, aligned_edge=LEFT, buff=0.3)\n takeaways.next_to(takeaway_title, DOWN, buff=0.4)\n takeaway_box = SurroundingRectangle(takeaways, color=BLUE, buff=0.2, corner_radius=0.1)\n self.play(Write(takeaway_title), run_time=2.0 * 0.2)\n self.play(Write(takeaways), run_time=2.0 * 0.5)\n self.play(Create(takeaway_box), run_time=2.0 * 0.3)\n self.wait(2)\n```", "category": "spatial_layout_overlap", "source": "synthetic_hard_neg:nabin2004/AOS-Manim-SFT"} +{"system": "You are an expert Manim Community Edition (ManimCE v0.19+) Python developer and mathematical animator. Given a user request, first plan the spatial layout, coordinate bounds, timing, and pedagogical flow inside ... tags (when reasoning is helpful), and then output a complete, runnable, self-contained ManimCE Python script using `from manim import *`. Never use deprecated ManimGL (`manimlib`) methods like `ShowCreation`, `TexMobject`, `TextMobject`, or `axes.get_graph`; always use modern ManimCE APIs (`Create`, `MathTex`, `Tex`, `Text`, `axes.plot`) and prevent visual overlap using `.to_edge()`, `.next_to()`, and `FadeOut`.", "prompt": "Display five different types of tables arranged in two groups:\n\n- **Top Group (scaled down and aligned at the top):**\n - A labeled table with two rows and two columns, including row and column headers and a top-left label. The cell at row 2, column 2 is highlighted in green.\n - A decimal table showing values of \\(x\\) and \\(f(x) = e^x\\) for five evenly spaced \\(x\\)-values from -2 to 2. The cell at row 2, column 2 is highlighted in red.\n\n- **Bottom Group (scaled down and aligned at the bottom):**\n - A math table with addition values, where the first row and column act as headers. The first three horizontal and vertical grid lines are colored blue and layered above the table.\n - A table of geometric objects (circles and crosses), arranged in a 3×3 grid. A red diagonal line crosses the table from bottom-left to top-right. It is a completed Tic-tac-toe game, 'O' has won.\n - An integer table filled with numbers from 1 to 20 arranged in a 5×4 grid, with outer lines included.\n\nAll tables are neatly arranged with spacing between them and displayed together on the screen.", "chosen": "```python\nfrom manim import *\n\nclass TableExamples(Scene):\n def construct(self):\n t0 = Table(\n [[\"First\", \"Second\"],\n [\"Third\",\"Fourth\"]],\n row_labels=[Text(\"R1\"), Text(\"R2\")],\n col_labels=[Text(\"C1\"), Text(\"C2\")],\n top_left_entry=Text(\"TOP\"))\n t0.add_highlighted_cell((2,2), color=GREEN)\n x_vals = np.linspace(-2,2,5)\n y_vals = np.exp(x_vals)\n t1 = DecimalTable(\n [x_vals, y_vals],\n row_labels=[MathTex(\"x\"), MathTex(\"f(x)\")],\n include_outer_lines=True)\n t1.add(t1.get_cell((2,2), color=RED))\n t2 = MathTable(\n [[\"+\", 0, 5, 10],\n [0, 0, 5, 10],\n [2, 2, 7, 12],\n [4, 4, 9, 14]],\n include_outer_lines=True)\n t2.get_horizontal_lines()[:3].set_color(BLUE)\n t2.get_vertical_lines()[:3].set_color(BLUE)\n t2.get_horizontal_lines()[:3].set_z_index(1)\n cross = VGroup(\n Line(UP + LEFT, DOWN + RIGHT),\n Line(UP + RIGHT, DOWN + LEFT))\n a = Circle().set_color(RED).scale(0.5)\n b = cross.set_color(BLUE).scale(0.5)\n t3 = MobjectTable(\n [[a.copy(),b.copy(),a.copy()],\n [b.copy(),a.copy(),a.copy()],\n [a.copy(),b.copy(),b.copy()]])\n t3.add(Line(\n t3.get_corner(DL), t3.get_corner(UR)\n ).set_color(RED))\n vals = np.arange(1,21).reshape(5,4)\n t4 = IntegerTable(\n vals,\n include_outer_lines=True\n )\n g1 = Group(t0, t1).scale(0.5).arrange(buff=1).to_edge(UP, buff=1)\n g2 = Group(t2, t3, t4).scale(0.5).arrange(buff=1).to_edge(DOWN, buff=1)\n self.add(g1, g2)\n```", "rejected": "```python\nfrom manim import *\n\nclass TableExamples(Scene):\n def construct(self):\n t0 = Table(\n [[\"First\", \"Second\"],\n [\"Third\",\"Fourth\"]],\n row_labels=[Text(\"R1\"), Text(\"R2\")],\n col_labels=[Text(\"C1\"), Text(\"C2\")],\n top_left_entry=Text(\"TOP\"))\n t0.add_highlighted_cell((2,2), color=GREEN)\n x_vals = np.linspace(-2,2,5)\n y_vals = np.exp(x_vals)\n t1 = DecimalTable(\n [x_vals, y_vals],\n row_labels=[TexMobject(\"x\"), MathTex(\"f(x)\")],\n include_outer_lines=True)\n t1.add(t1.get_cell((2,2), color=RED))\n t2 = MathTable(\n [[\"+\", 0, 5, 10],\n [0, 0, 5, 10],\n [2, 2, 7, 12],\n [4, 4, 9, 14]],\n include_outer_lines=True)\n t2.get_horizontal_lines()[:3].set_color(BLUE)\n t2.get_vertical_lines()[:3].set_color(BLUE)\n t2.get_horizontal_lines()[:3].set_z_index(1)\n cross = VGroup(\n Line(UP + LEFT, DOWN + RIGHT),\n Line(UP + RIGHT, DOWN + LEFT))\n a = Circle().set_color(RED).scale(0.5)\n b = cross.set_color(BLUE).scale(0.5)\n t3 = MobjectTable(\n [[a.copy(),b.copy(),a.copy()],\n [b.copy(),a.copy(),a.copy()],\n [a.copy(),b.copy(),b.copy()]])\n t3.add(Line(\n t3.get_corner(DL), t3.get_corner(UR)\n ).set_color(RED))\n vals = np.arange(1,21).reshape(5,4)\n t4 = IntegerTable(\n vals,\n include_outer_lines=True\n )\n g1 = Group(t0, t1).scale(0.5).arrange(buff=1).to_edge(UP, buff=1)\n g2 = Group(t2, t3, t4).scale(0.5).arrange(buff=1).to_edge(DOWN, buff=1)\n self.add(g1, g2)\n```", "category": "legacy_api_hallucination", "source": "synthetic_hard_neg:SuienR/ManimBench-v1"} +{"system": "You are an expert Manim Community Edition (ManimCE v0.19+) Python developer and mathematical animator. Given a user request, first plan the spatial layout, coordinate bounds, timing, and pedagogical flow inside ... tags (when reasoning is helpful), and then output a complete, runnable, self-contained ManimCE Python script using `from manim import *`. Never use deprecated ManimGL (`manimlib`) methods like `ShowCreation`, `TexMobject`, `TextMobject`, or `axes.get_graph`; always use modern ManimCE APIs (`Create`, `MathTex`, `Tex`, `Text`, `axes.plot`) and prevent visual overlap using `.to_edge()`, `.next_to()`, and `FadeOut`.", "prompt": "I'm learning about pruning and quantization to compress RNNs and want a practical visual.\nDemonstrate pruning by gradually removing weights with magnitude thresholds while showing impact on accuracy and activation patterns.\nShow quantization as lowering precision per layer and visualize how quantized weights approximate full-precision behavior.\nInclude a live trade-off curve of size vs. error and a recovery demonstration after fine-tuning, plus a quick note on deployment considerations.", "chosen": "```python\nfrom manim import *\nfrom manim_voiceover import VoiceoverScene\nfrom manim_voiceover.services.gtts import GTTSService\n\nclass PruningQuantizationRNNs(VoiceoverScene):\n def construct(self):\n self.set_speech_service(\n GTTSService(voice=\"alba\", cache_dir=\"voiceover_cache\")\n )\n \n # ==================== TITLE SLIDE ====================\n title = Text(\"Pruning and Quantization for RNNs\", font_size=48, color=BLUE)\n subtitle = Text(\"Optimizing Neural Networks for Efficiency\", font_size=28, color=GRAY)\n title_group = VGroup(title, subtitle).arrange(DOWN, buff=0.5)\n \n with self.voiceover(text=\"Imagine a world where neural networks can perform astonishing tasks while consuming minimal resources. This is the potential of pruning and quantization, techniques that optimize recurrent neural networks for efficiency without sacrificing performance. Let's dive into this fascinating topic.\") as tracker:\n self.play(Write(title), run_time=tracker.duration * 0.6)\n self.play(FadeIn(subtitle), run_time=tracker.duration * 0.4)\n \n self.wait(0.5)\n self.play(FadeOut(title_group))\n \n # ==================== RNN ARCHITECTURE OVERVIEW ====================\n self.next_section(\"RNN Overview\")\n \n rnn_title = Text(\"Recurrent Neural Networks\", font_size=36, color=BLUE).to_edge(UP, buff=0.8)\n \n # Simple RNN cell visualization\n cell = Circle(radius=0.8, color=BLUE, fill_opacity=0.2)\n cell_label = MathTex(r\"h_t\", font_size=32).move_to(cell.get_center())\n \n # Input and output arrows\n input_arrow = Arrow(LEFT * 3, LEFT * 0.8, buff=0.1, color=GREEN)\n input_label = MathTex(r\"x_t\", font_size=28, color=GREEN).next_to(input_arrow, DOWN, buff=0.2)\n \n output_arrow = Arrow(RIGHT * 0.8, RIGHT * 3, buff=0.1, color=YELLOW)\n output_label = MathTex(r\"y_t\", font_size=28, color=YELLOW).next_to(output_arrow, DOWN, buff=0.2)\n \n # Recurrent connection\n recurrent_arrow = CurvedArrow(UP * 0.8, UP * 2.5, angle=PI, color=RED)\n recurrent_label = MathTex(r\"h_{t-1}\", font_size=28, color=RED).next_to(recurrent_arrow, UP, buff=0.1)\n \n rnn_group = VGroup(cell, cell_label, input_arrow, input_label, \n output_arrow, output_label, recurrent_arrow, recurrent_label)\n \n with self.voiceover(text=\"Recurrent Neural Networks, or RNNs, are powerful for sequential data. But they can be computationally expensive. That's where optimization techniques come in.\") as tracker:\n self.play(Write(rnn_title), run_time=tracker.duration * 0.2)\n self.play(Create(cell), Write(cell_label), run_time=tracker.duration * 0.2)\n self.play(GrowArrow(input_arrow), Write(input_label), run_time=tracker.duration * 0.15)\n self.play(GrowArrow(output_arrow), Write(output_label), run_time=tracker.duration * 0.15)\n self.play(Create(recurrent_arrow), Write(recurrent_label), run_time=tracker.duration * 0.3)\n \n self.wait(0.3)\n self.play(FadeOut(rnn_group), FadeOut(rnn_title))\n \n # ==================== WHAT IS PRUNING ====================\n self.next_section(\"What is Pruning\")\n \n pruning_title = Text(\"What is Pruning?\", font_size=40, color=BLUE).to_edge(UP, buff=0.8)\n \n # Weight matrix visualization - before pruning\n matrix_before = VGroup()\n matrix_size = 6\n cell_size = 0.35\n values_before = []\n \n import random\n random.seed(42)\n \n for i in range(matrix_size):\n row = []\n for j in range(matrix_size):\n # Random weights with varying magnitudes\n val = random.uniform(-1, 1)\n color = interpolate_color(BLACK, BLUE, abs(val))\n square = Square(side_length=cell_size, fill_color=color, fill_opacity=0.8, stroke_width=1)\n square.shift(RIGHT * j * cell_size + DOWN * i * cell_size)\n row.append((square, val))\n values_before.append(row)\n \n for row in values_before:\n for square, _ in row:\n matrix_before.add(square)\n \n matrix_before.move_to(LEFT * 2.5)\n label_before = Text(\"Before Pruning\", font_size=24, color=WHITE).next_to(matrix_before, DOWN, buff=0.4)\n \n # Explanation text\n pruning_def = BulletedList(\n \"Removing unnecessary weights\",\n \"Reducing model size\",\n \"Improving inference speed\",\n font_size=24\n ).to_edge(RIGHT, buff=0.8)\n \n with self.voiceover(text=\"Pruning is the process of removing unnecessary weights from a neural network. Think of it like trimming dead branches from a tree. We reduce model size and improve inference speed.\") as tracker:\n self.play(Write(pruning_title), run_time=tracker.duration * 0.15)\n self.play(FadeIn(matrix_before), run_time=tracker.duration * 0.3)\n self.play(Write(label_before), run_time=tracker.duration * 0.1)\n self.play(FadeIn(pruning_def), run_time=tracker.duration * 0.45)\n \n self.wait(0.3)\n \n # After pruning visualization\n matrix_after = VGroup()\n threshold = 0.4\n pruned_count = 0\n \n for i, row in enumerate(values_before):\n for j, (square, val) in enumerate(row):\n if abs(val) < threshold:\n # Pruned - white/empty\n new_square = Square(side_length=cell_size, fill_color=WHITE, fill_opacity=0.1, stroke_width=1)\n pruned_count += 1\n else:\n # Keep - original color\n color = interpolate_color(BLACK, BLUE, abs(val))\n new_square = Square(side_length=cell_size, fill_color=color, fill_opacity=0.8, stroke_width=1)\n new_square.shift(RIGHT * j * cell_size + DOWN * i * cell_size)\n matrix_after.add(new_square)\n \n matrix_after.move_to(LEFT * 2.5)\n label_after = Text(\"After Pruning\", font_size=24, color=WHITE).next_to(matrix_after, DOWN, buff=0.4)\n \n sparsity_text = Text(f\"Sparsity: {pruned_count/(matrix_size*matrix_size)*100:.0f}%\", \n font_size=22, color=YELLOW).next_to(label_after, DOWN, buff=0.2)\n \n with self.voiceover(text=\"Small magnitude weights are set to zero. This creates sparse matrices, reducing storage and computation needs.\") as tracker:\n self.play(Transform(matrix_before, matrix_after),\n Transform(label_before, label_after),\n run_time=tracker.duration * 0.7)\n self.play(Write(sparsity_text), run_time=tracker.duration * 0.3)\n \n self.wait(0.3)\n self.play(FadeOut(matrix_before), FadeOut(label_before), FadeOut(sparsity_text), \n FadeOut(pruning_def), FadeOut(pruning_title))\n \n # ==================== TYPES OF PRUNING ====================\n self.next_section(\"Types of Pruning\")\n \n types_title = Text(\"Types of Pruning\", font_size=40, color=BLUE).to_edge(UP, buff=0.8)\n \n # Weight pruning (unstructured)\n unstructured_title = Text(\"Weight Pruning\", font_size=28, color=GREEN).to_edge(UP, buff=2)\n unstructured_title.shift(LEFT * 3.5)\n \n # Small matrix showing unstructured pattern\n small_matrix1 = VGroup()\n pattern = [\n [1, 0, 1, 1],\n [0, 1, 0, 1],\n [1, 1, 0, 0],\n [0, 1, 1, 0]\n ]\n for i, row in enumerate(pattern):\n for j, val in enumerate(row):\n color = BLUE if val == 1 else WHITE\n opacity = 0.8 if val == 1 else 0.1\n sq = Square(side_length=0.4, fill_color=color, fill_opacity=opacity, stroke_width=1)\n sq.shift(RIGHT * j * 0.4 + DOWN * i * 0.4)\n small_matrix1.add(sq)\n small_matrix1.next_to(unstructured_title, DOWN, buff=0.4)\n \n unstruct_desc = Text(\"Unstructured\\nIndividual weights\", font_size=20, color=GRAY)\n unstruct_desc.next_to(small_matrix1, DOWN, buff=0.3)\n \n unstructured_group = VGroup(unstructured_title, small_matrix1, unstruct_desc)\n \n # Structured pruning\n structured_title = Text(\"Structured Pruning\", font_size=28, color=RED).to_edge(UP, buff=2)\n structured_title.shift(RIGHT * 3.5)\n \n small_matrix2 = VGroup()\n pattern2 = [\n [1, 1, 0, 0],\n [1, 1, 0, 0],\n [1, 1, 0, 0],\n [1, 1, 0, 0]\n ]\n for i, row in enumerate(pattern2):\n for j, val in enumerate(row):\n color = RED if val == 1 else WHITE\n opacity = 0.8 if val == 1 else 0.1\n sq = Square(side_length=0.4, fill_color=color, fill_opacity=opacity, stroke_width=1)\n sq.shift(RIGHT * j * 0.4 + DOWN * i * 0.4)\n small_matrix2.add(sq)\n small_matrix2.next_to(structured_title, DOWN, buff=0.4)\n \n struct_desc = Text(\"Structured\\nEntire rows/columns\", font_size=20, color=GRAY)\n struct_desc.next_to(small_matrix2, DOWN, buff=0.3)\n \n structured_group = VGroup(structured_title, small_matrix2, struct_desc)\n \n with self.voiceover(text=\"There are two main types of pruning. Weight pruning removes individual weights, creating unstructured sparsity. Structured pruning removes entire rows or columns, which is more hardware-friendly.\") as tracker:\n self.play(Write(types_title), run_time=tracker.duration * 0.15)\n self.play(FadeIn(unstructured_group), run_time=tracker.duration * 0.4)\n self.play(FadeIn(structured_group), run_time=tracker.duration * 0.45)\n \n self.wait(0.3)\n \n # Pros and cons\n pros_cons = VGroup(\n Text(\"Weight: Higher compression, but needs special hardware\", font_size=20, color=GRAY),\n Text(\"Structured: Better hardware support, slightly less compression\", font_size=20, color=GRAY)\n ).arrange(DOWN, buff=0.3).to_edge(DOWN, buff=0.8)\n \n with self.voiceover(text=\"Weight pruning achieves higher compression but needs specialized hardware. Structured pruning works better with standard hardware but may have slightly less compression.\") as tracker:\n self.play(FadeIn(pros_cons), run_time=tracker.duration)\n \n self.wait(0.3)\n self.play(FadeOut(types_title), FadeOut(unstructured_group), FadeOut(structured_group), FadeOut(pros_cons))\n \n # ==================== WHAT IS QUANTIZATION ====================\n self.next_section(\"What is Quantization\")\n \n quant_title = Text(\"What is Quantization?\", font_size=40, color=BLUE).to_edge(UP, buff=0.8)\n \n # Float vs Integer representation\n float_title = Text(\"32-bit Float\", font_size=26, color=BLUE).shift(LEFT * 3 + UP * 1)\n \n # Visual representation of float bits\n float_bits = VGroup()\n bit_labels = [\"S\"] + [\"E\"] * 8 + [\"M\"] * 23\n colors = [RED] + [GREEN] * 8 + [BLUE] * 23\n for i, (label, color) in enumerate(zip(bit_labels, colors)):\n rect = Rectangle(width=0.25, height=0.5, fill_color=color, fill_opacity=0.5, stroke_width=1)\n rect.shift(RIGHT * i * 0.25 + LEFT * 4)\n txt = Text(label, font_size=12).move_to(rect.get_center())\n float_bits.add(VGroup(rect, txt))\n \n float_bits.next_to(float_title, DOWN, buff=0.3)\n float_val = MathTex(r\"3.14159...\", font_size=24, color=BLUE).next_to(float_bits, DOWN, buff=0.3)\n float_box = VGroup(float_title, float_bits, float_val)\n \n # Arrow showing conversion\n arrow_down = Arrow(UP * 0.5, DOWN * 1.5, color=YELLOW)\n arrow_label = Text(\"Quantize\", font_size=20, color=YELLOW).next_to(arrow_down, RIGHT, buff=0.2)\n \n # Int8 representation\n int_title = Text(\"8-bit Integer\", font_size=26, color=GREEN).shift(LEFT * 3 + DOWN * 2)\n \n int_bits = VGroup()\n for i in range(8):\n rect = Rectangle(width=0.4, height=0.5, fill_color=GREEN, fill_opacity=0.5, stroke_width=1)\n rect.shift(RIGHT * i * 0.4 + LEFT * 1.4)\n int_bits.add(rect)\n \n int_bits.next_to(int_title, DOWN, buff=0.3)\n int_val = MathTex(r\"3\", font_size=24, color=GREEN).next_to(int_bits, DOWN, buff=0.3)\n int_box = VGroup(int_title, int_bits, int_val)\n \n quantization_group = VGroup(float_box, arrow_down, arrow_label, int_box)\n quantization_group.move_to(LEFT * 2)\n \n # Benefits\n benefits = BulletedList(\n \"Reduce memory by 4x (32-bit to 8-bit)\",\n \"Faster integer arithmetic\",\n \"Lower power consumption\",\n \"Enable edge deployment\",\n font_size=22\n ).to_edge(RIGHT, buff=0.8)\n \n with self.voiceover(text=\"Quantization reduces the precision of weights. We convert 32-bit floating point numbers to 8-bit integers. This reduces memory by four times, enables faster integer arithmetic, and lowers power consumption.\") as tracker:\n self.play(Write(quant_title), run_time=tracker.duration * 0.1)\n self.play(FadeIn(float_box), run_time=tracker.duration * 0.25)\n self.play(GrowArrow(arrow_down), Write(arrow_label), run_time=tracker.duration * 0.2)\n self.play(FadeIn(int_box), run_time=tracker.duration * 0.2)\n self.play(FadeIn(benefits), run_time=tracker.duration * 0.25)\n \n self.wait(0.3)\n self.play(FadeOut(quantization_group), FadeOut(benefits), FadeOut(quant_title))\n \n # ==================== QUANTIZATION TECHNIQUES ====================\n self.next_section(\"Quantization Techniques\")\n \n tech_title = Text(\"Quantization Techniques\", font_size=40, color=BLUE).to_edge(UP, buff=0.8)\n \n # Fixed-point quantization\n fixed_point = VGroup(\n Text(\"Fixed-Point Quantization\", font_size=26, color=BLUE),\n Text(\"Pre-defined scale factor\", font_size=20, color=GRAY),\n MathTex(r\"w_{quant} = round(w \\times scale)\", font_size=22),\n Text(\"Simple, but may lose precision\", font_size=18, color=RED)\n ).arrange(DOWN, buff=0.3).shift(LEFT * 3.5 + UP * 0.5)\n \n # Dynamic quantization\n dynamic = VGroup(\n Text(\"Dynamic Quantization\", font_size=26, color=GREEN),\n Text(\"Scale computed at runtime\", font_size=20, color=GRAY),\n MathTex(r\"scale = \\frac{max - min}{255}\", font_size=22),\n Text(\"Better accuracy, more computation\", font_size=18, color=YELLOW)\n ).arrange(DOWN, buff=0.3).shift(RIGHT * 3.5 + UP * 0.5)\n \n with self.voiceover(text=\"There are different quantization techniques. Fixed-point uses a pre-defined scale factor. It's simple but may lose precision. Dynamic quantization computes scales at runtime for better accuracy, though it requires more computation.\") as tracker:\n self.play(Write(tech_title), run_time=tracker.duration * 0.1)\n self.play(FadeIn(fixed_point), run_time=tracker.duration * 0.45)\n self.play(FadeIn(dynamic), run_time=tracker.duration * 0.45)\n \n self.wait(0.3)\n \n # Comparison note\n note = Text(\"For RNNs: Dynamic quantization often preferred due to varying activation ranges\", \n font_size=20, color=YELLOW).to_edge(DOWN, buff=0.8)\n \n with self.voiceover(text=\"For RNNs, dynamic quantization is often preferred because activation ranges vary across time steps.\") as tracker:\n self.play(FadeIn(note), run_time=tracker.duration)\n \n self.wait(0.3)\n self.play(FadeOut(tech_title), FadeOut(fixed_point), FadeOut(dynamic), FadeOut(note))\n \n # ==================== TRADE-OFFS ====================\n self.next_section(\"Trade-offs\")\n \n trade_title = Text(\"Trade-offs and Considerations\", font_size=40, color=BLUE).to_edge(UP, buff=0.8)\n \n # Two column layout\n left_col = VGroup(\n Text(\"Benefits\", font_size=28, color=GREEN),\n BulletedList(\n \"Smaller model size\",\n \"Faster inference\",\n \"Lower energy usage\",\n \"Edge deployment\",\n font_size=22\n )\n ).arrange(DOWN, buff=0.4).shift(LEFT * 3.5)\n \n right_col = VGroup(\n Text(\"Challenges\", font_size=28, color=RED),\n BulletedList(\n \"Potential accuracy loss\",\n \"Requires fine-tuning\",\n \"Hardware dependencies\",\n \"Not always straightforward\",\n font_size=22\n )\n ).arrange(DOWN, buff=0.4).shift(RIGHT * 3.5)\n \n with self.voiceover(text=\"These techniques offer significant benefits: smaller models, faster inference, and lower energy. But they come with challenges. There may be accuracy loss, and fine-tuning is often required. Hardware dependencies must also be considered.\") as tracker:\n self.play(Write(trade_title), run_time=tracker.duration * 0.15)\n self.play(FadeIn(left_col), run_time=tracker.duration * 0.4)\n self.play(FadeIn(right_col), run_time=tracker.duration * 0.45)\n \n self.wait(0.3)\n self.play(FadeOut(left_col), FadeOut(right_col), FadeOut(trade_title))\n \n # ==================== SUMMARY ====================\n self.next_section(\"Summary\")\n \n summary_title = Text(\"Key Takeaways\", font_size=40, color=BLUE).to_edge(UP, buff=0.8)\n \n takeaways = VGroup(\n Text(\"1. Pruning removes unnecessary weights\", font_size=24),\n Text(\"2. Quantization reduces precision (32-bit → 8-bit)\", font_size=24),\n Text(\"3. Both techniques optimize RNNs for efficiency\", font_size=24),\n Text(\"4. Trade-offs exist between size, speed, and accuracy\", font_size=24),\n Text(\"5. Essential for deploying RNNs on resource-constrained devices\", font_size=24)\n ).arrange(DOWN, buff=0.5, aligned_edge=LEFT)\n \n with self.voiceover(text=\"To summarize: Pruning removes unnecessary weights. Quantization reduces precision. Both optimize RNNs for efficiency. Trade-offs exist between size, speed, and accuracy. These techniques are essential for deploying RNNs on resource-constrained devices.\") as tracker:\n self.play(Write(summary_title), run_time=tracker.duration * 0.1)\n for i, takeaway in enumerate(takeaways):\n self.play(FadeIn(takeaway), run_time=tracker.duration * 0.18)\n \n self.wait(0.5)\n \n # Final message\n final = Text(\"Ready to optimize your RNNs?\", font_size=32, color=GREEN)\n \n with self.voiceover(text=\"Are you ready to optimize your RNNs?\") as tracker:\n self.play(FadeOut(takeaways), Transform(summary_title, final), run_time=tracker.duration)\n \n self.wait(1)\n self.play(FadeOut(summary_title))\n```", "rejected": "```python\nfrom manim import *\n\nclass PruningQuantizationRNNs(Scene):\n\n def construct(self):\n title = Text('Pruning and Quantization for RNNs', font_size=48, color=BLUE)\n subtitle = Text('Optimizing Neural Networks for Efficiency', font_size=28, color=GRAY)\n title_group = VGroup(title, subtitle).arrange(DOWN, buff=0.5)\n self.play(Write(title), run_time=2.0 * 0.6)\n self.play(FadeIn(subtitle), run_time=2.0 * 0.4)\n self.wait(0.5)\n self.play(FadeOut(title_group))\n self.next_section('RNN Overview')\n rnn_title = Text('Recurrent Neural Networks', font_size=36, color=BLUE).to_edge(UP, buff=0.8)\n cell = Circle(radius=0.8, color=BLUE, fill_opacity=0.2)\n cell_label = MathTex('h_t', font_size=32).move_to(cell.get_center())\n input_arrow = Arrow(LEFT * 3, LEFT * 0.8, buff=0.1, color=GREEN)\n input_label = MathTex('x_t', font_size=28, color=GREEN).next_to(input_arrow, DOWN, buff=0.2)\n output_arrow = Arrow(RIGHT * 0.8, RIGHT * 3, buff=0.1, color=YELLOW)\n output_label = MathTex('y_t', font_size=28, color=YELLOW).next_to(output_arrow, DOWN, buff=0.2)\n recurrent_arrow = CurvedArrow(UP * 0.8, UP * 2.5, angle=PI, color=RED)\n recurrent_label = MathTex('h_{t-1}', font_size=28, color=RED).next_to(recurrent_arrow, UP, buff=0.1)\n rnn_group = VGroup(cell, cell_label, input_arrow, input_label, output_arrow, output_label, recurrent_arrow, recurrent_label)\n self.play(Write(rnn_title), run_time=2.0 * 0.2)\n self.play(Create(cell), Write(cell_label), run_time=2.0 * 0.2)\n self.play(GrowArrow(input_arrow), Write(input_label), run_time=2.0 * 0.15)\n self.play(GrowArrow(output_arrow), Write(output_label), run_time=2.0 * 0.15)\n self.play(Create(recurrent_arrow), Write(recurrent_label), run_time=2.0 * 0.3)\n self.wait(0.3)\n self.play(FadeOut(rnn_group), FadeOut(rnn_title))\n self.next_section('What is Pruning')\n pruning_title = Text('What is Pruning?', font_size=40, color=BLUE).to_edge(UP, buff=0.8)\n matrix_before = VGroup()\n matrix_size = 6\n cell_size = 0.35\n values_before = []\n import random\n random.seed(42)\n for i in range(matrix_size):\n row = []\n for j in range(matrix_size):\n val = random.uniform(-1, 1)\n color = interpolate_color(BLACK, BLUE, abs(val))\n square = Square(side_length=cell_size, fill_color=color, fill_opacity=0.8, stroke_width=1)\n square.shift(RIGHT * j * cell_size + DOWN * i * cell_size)\n row.append((square, val))\n values_before.append(row)\n for row in values_before:\n for square, _ in row:\n matrix_before.add(square)\n matrix_before.move_to(LEFT * 2.5)\n label_before = Text('Before Pruning', font_size=24, color=WHITE).next_to(matrix_before, DOWN, buff=0.4)\n pruning_def = BulletedList('Removing unnecessary weights', 'Reducing model size', 'Improving inference speed', font_size=24).to_edge(RIGHT, buff=0.8)\n self.play(Write(pruning_title), run_time=2.0 * 0.15)\n self.play(FadeIn(matrix_before), run_time=2.0 * 0.3)\n self.play(Write(label_before), run_time=2.0 * 0.1)\n self.play(FadeIn(pruning_def), run_time=2.0 * 0.45)\n self.wait(0.3)\n matrix_after = VGroup()\n threshold = 0.4\n pruned_count = 0\n for i, row in enumerate(values_before):\n for j, (square, val) in enumerate(row):\n if abs(val) < threshold:\n new_square = Square(side_length=cell_size, fill_color=WHITE, fill_opacity=0.1, stroke_width=1)\n pruned_count += 1\n else:\n color = interpolate_color(BLACK, BLUE, abs(val))\n new_square = Square(side_length=cell_size, fill_color=color, fill_opacity=0.8, stroke_width=1)\n new_square.shift(RIGHT * j * cell_size + DOWN * i * cell_size)\n matrix_after.add(new_square)\n matrix_after.move_to(LEFT * 2.5)\n label_after = Text('After Pruning', font_size=24, color=WHITE).next_to(matrix_after, DOWN, buff=0.4)\n sparsity_text = Text(f'Sparsity: {pruned_count / (matrix_size * matrix_size) * 100:.0f}%', font_size=22, color=YELLOW).next_to(label_after, DOWN, buff=0.2)\n self.play(Transform(matrix_before, matrix_after), Transform(label_before, label_after), run_time=2.0 * 0.7)\n self.play(Write(sparsity_text), run_time=2.0 * 0.3)\n self.wait(0.3)\n self.play(FadeOut(matrix_before), FadeOut(label_before), FadeOut(sparsity_text), FadeOut(pruning_def), FadeOut(pruning_title))\n self.next_section('Types of Pruning')\n types_title = Text('Types of Pruning', font_size=40, color=BLUE).to_edge(UP, buff=0.8)\n unstructured_title = Text('Weight Pruning', font_size=28, color=GREEN).to_edge(UP, buff=2)\n unstructured_title.shift(LEFT * 3.5)\n small_matrix1 = VGroup()\n pattern = [[1, 0, 1, 1], [0, 1, 0, 1], [1, 1, 0, 0], [0, 1, 1, 0]]\n for i, row in enumerate(pattern):\n for j, val in enumerate(row):\n color = BLUE if val == 1 else WHITE\n opacity = 0.8 if val == 1 else 0.1\n sq = Square(side_length=0.4, fill_color=color, fill_opacity=opacity, stroke_width=1)\n sq.shift(RIGHT * j * 0.4 + DOWN * i * 0.4)\n small_matrix1.add(sq)\n small_matrix1.next_to(unstructured_title, DOWN, buff=0.4)\n unstruct_desc = Text('Unstructured\\nIndividual weights', font_size=20, color=GRAY)\n unstruct_desc.next_to(small_matrix1, DOWN, buff=0.3)\n unstructured_group = VGroup(unstructured_title, small_matrix1, unstruct_desc)\n structured_title = Text('Structured Pruning', font_size=28, color=RED).to_edge(UP, buff=2)\n structured_title.shift(RIGHT * 3.5)\n small_matrix2 = VGroup()\n pattern2 = [[1, 1, 0, 0], [1, 1, 0, 0], [1, 1, 0, 0], [1, 1, 0, 0]]\n for i, row in enumerate(pattern2):\n for j, val in enumerate(row):\n color = RED if val == 1 else WHITE\n opacity = 0.8 if val == 1 else 0.1\n sq = Square(side_length=0.4, fill_color=color, fill_opacity=opacity, stroke_width=1)\n sq.shift(RIGHT * j * 0.4 + DOWN * i * 0.4)\n small_matrix2.add(sq)\n small_matrix2.next_to(structured_title, DOWN, buff=0.4)\n struct_desc = Text('Structured\\nEntire rows/columns', font_size=20, color=GRAY)\n struct_desc.next_to(small_matrix2, DOWN, buff=0.3)\n structured_group = VGroup(structured_title, small_matrix2, struct_desc)\n self.play(Write(types_title), run_time=2.0 * 0.15)\n self.play(FadeIn(unstructured_group), run_time=2.0 * 0.4)\n self.play(FadeIn(structured_group), run_time=2.0 * 0.45)\n self.wait(0.3)\n pros_cons = VGroup(Text('Weight: Higher compression, but needs special hardware', font_size=20, color=GRAY), Text('Structured: Better hardware support, slightly less compression', font_size=20, color=GRAY)).arrange(DOWN, buff=0.3).to_edge(DOWN, buff=0.8)\n self.play(FadeIn(pros_cons), run_time=2.0)\n self.wait(0.3)\n self.play(FadeOut(types_title), FadeOut(unstructured_group), FadeOut(structured_group), FadeOut(pros_cons))\n self.next_section('What is Quantization')\n quant_title = Text('What is Quantization?', font_size=40, color=BLUE).to_edge(UP, buff=0.8)\n float_title = Text('32-bit Float', font_size=26, color=BLUE).shift(LEFT * 3 + UP * 1)\n float_bits = VGroup()\n bit_labels = ['S'] + ['E'] * 8 + ['M'] * 23\n colors = [RED] + [GREEN] * 8 + [BLUE] * 23\n for i, (label, color) in enumerate(zip(bit_labels, colors)):\n rect = Rectangle(width=0.25, height=0.5, fill_color=color, fill_opacity=0.5, stroke_width=1)\n rect.shift(RIGHT * i * 0.25 + LEFT * 4)\n txt = Text(label, font_size=12).move_to(rect.get_center())\n float_bits.add(VGroup(rect, txt))\n float_bits.next_to(float_title, DOWN, buff=0.3)\n float_val = MathTex('3.14159...', font_size=24, color=BLUE).next_to(float_bits, DOWN, buff=0.3)\n float_box = VGroup(float_title, float_bits, float_val)\n arrow_down = Arrow(UP * 0.5, DOWN * 1.5, color=YELLOW)\n arrow_label = Text('Quantize', font_size=20, color=YELLOW).next_to(arrow_down, RIGHT, buff=0.2)\n int_title = Text('8-bit Integer', font_size=26, color=GREEN).shift(LEFT * 3 + DOWN * 2)\n int_bits = VGroup()\n for i in range(8):\n rect = Rectangle(width=0.4, height=0.5, fill_color=GREEN, fill_opacity=0.5, stroke_width=1)\n rect.shift(RIGHT * i * 0.4 + LEFT * 1.4)\n int_bits.add(rect)\n int_bits.next_to(int_title, DOWN, buff=0.3)\n int_val = MathTex('3', font_size=24, color=GREEN).next_to(int_bits, DOWN, buff=0.3)\n int_box = VGroup(int_title, int_bits, int_val)\n quantization_group = VGroup(float_box, arrow_down, arrow_label, int_box)\n quantization_group.move_to(LEFT * 2)\n benefits = BulletedList('Reduce memory by 4x (32-bit to 8-bit)', 'Faster integer arithmetic', 'Lower power consumption', 'Enable edge deployment', font_size=22).to_edge(RIGHT, buff=0.8)\n self.play(Write(quant_title), run_time=2.0 * 0.1)\n self.play(FadeIn(float_box), run_time=2.0 * 0.25)\n self.play(GrowArrow(arrow_down), Write(arrow_label), run_time=2.0 * 0.2)\n self.play(FadeIn(int_box), run_time=2.0 * 0.2)\n self.play(FadeIn(benefits), run_time=2.0 * 0.25)\n self.wait(0.3)\n self.play(FadeOut(quantization_group), FadeOut(benefits), FadeOut(quant_title))\n self.next_section('Quantization Techniques')\n tech_title = Text('Quantization Techniques', font_size=40, color=BLUE).to_edge(UP, buff=0.8)\n fixed_point = VGroup(Text('Fixed-Point Quantization', font_size=26, color=BLUE), Text('Pre-defined scale factor', font_size=20, color=GRAY), MathTex('w_{quant} = round(w \\\\times scale)', font_size=22), Text('Simple, but may lose precision', font_size=18, color=RED)).arrange(DOWN, buff=0.3).shift(LEFT * 3.5 + UP * 0.5)\n dynamic = VGroup(Text('Dynamic Quantization', font_size=26, color=GREEN), Text('Scale computed at runtime', font_size=20, color=GRAY), MathTex('scale = \\\\frac{max - min}{255}', font_size=22), Text('Better accuracy, more computation', font_size=18, color=YELLOW)).arrange(DOWN, buff=0.3).shift(RIGHT * 3.5 + UP * 0.5)\n self.play(Write(tech_title), run_time=2.0 * 0.1)\n self.play(FadeIn(fixed_point), run_time=2.0 * 0.45)\n self.play(FadeIn(dynamic), run_time=2.0 * 0.45)\n self.wait(0.3)\n note = Text('For RNNs: Dynamic quantization often preferred due to varying activation ranges', font_size=20, color=YELLOW).to_edge(DOWN, buff=0.8)\n self.play(FadeIn(note), run_time=2.0)\n self.wait(0.3)\n self.play(FadeOut(tech_title), FadeOut(fixed_point), FadeOut(dynamic), FadeOut(note))\n self.next_section('Trade-offs')\n trade_title = Text('Trade-offs and Considerations', font_size=40, color=BLUE).to_edge(UP, buff=0.8)\n left_col = VGroup(Text('Benefits', font_size=28, color=GREEN), BulletedList('Smaller model size', 'Faster inference', 'Lower energy usage', 'Edge deployment', font_size=22)).arrange(DOWN, buff=0.4).shift(LEFT * 3.5)\n right_col = VGroup(Text('Challenges', font_size=28, color=RED), BulletedList('Potential accuracy loss', 'Requires fine-tuning', 'Hardware dependencies', 'Not always straightforward', font_size=22)).arrange(DOWN, buff=0.4).shift(RIGHT * 3.5)\n self.play(Write(trade_title), run_time=2.0 * 0.15)\n self.play(FadeIn(left_col), run_time=2.0 * 0.4)\n self.play(FadeIn(right_col), run_time=2.0 * 0.45)\n self.wait(0.3)\n self.play(FadeOut(left_col), FadeOut(right_col), FadeOut(trade_title))\n self.next_section('Summary')\n summary_title = Text('Key Takeaways', font_size=40, color=BLUE).to_edge(UP, buff=0.8)\n takeaways = VGroup(Text('1. Pruning removes unnecessary weights', font_size=24), Text('2. Quantization reduces precision (32-bit → 8-bit)', font_size=24), Text('3. Both techniques optimize RNNs for efficiency', font_size=24), Text('4. Trade-offs exist between size, speed, and accuracy', font_size=24), Text('5. Essential for deploying RNNs on resource-constrained devices', font_size=24)).arrange(DOWN, buff=0.5, aligned_edge=LEFT)\n self.play(Write(summary_title), run_time=2.0 * 0.1)\n for i, takeaway in enumerate(takeaways):\n self.play(FadeIn(takeaway), run_time=2.0 * 0.18)\n self.wait(0.5)\n final = Text('Ready to optimize your RNNs?', font_size=32, color=GREEN)\n self.play(FadeOut(takeaways), Transform(summary_title, final), run_time=2.0)\n self.wait(1)\n self.play(FadeOut(summary_title))\n```", "category": "narrated_pedagogical_preference", "source": "nabin2004/manim-narrated-dpo-400"} +{"system": "You are an expert Manim Community Edition (ManimCE v0.19+) Python developer and mathematical animator. Given a user request, first plan the spatial layout, coordinate bounds, timing, and pedagogical flow inside ... tags (when reasoning is helpful), and then output a complete, runnable, self-contained ManimCE Python script using `from manim import *`. Never use deprecated ManimGL (`manimlib`) methods like `ShowCreation`, `TexMobject`, `TextMobject`, or `axes.get_graph`; always use modern ManimCE APIs (`Create`, `MathTex`, `Tex`, `Text`, `axes.plot`) and prevent visual overlap using `.to_edge()`, `.next_to()`, and `FadeOut`.", "prompt": "The following Manim CE scene failed to compile. Truncated traceback:\n\nValueError: latex error converting to dvi. Unicode character ₁ (U+2081)\n\nFix the code. Return a complete working scene. Do not keep the invalid constructor kwargs or Unicode subscripts.\n\n```python\nBACKGROUND_COLOR = \"#faf4e1\"\nTEXT_COLOR = \"#434343\"\nLIGHT_RED_COLOR = \"#f55e61\"\nLIGHT_GREEN_COLOR = \"#5fcb50\"\nLIGHT_BLUE_COLOR = \"#408ef5\"\nLIGHT_ORANGE_COLOR = \"#e3883d\"\nLIGHT_PURPLE_COLOR = \"#a346eb\"\nAQUA_GREEN_COLOR = \"#0dc786\"\nGREEN_COLOR = \"#34a853\"\nDARK_RED_COLOR = \"#bf2626\"\nDARK_BLUE_COLOR = \"#3333FF\"\nSAND_COLOR = \"#b3a77d\"\nBROWN_COLOR = \"#b85842\"\n\n\nfrom manim import *\nfrom utils import *\n\nconfig.frame_size = 1080, 1920 \nconfig.frame_width = 9\nconfig.frame_height = 16\n\ndef Division(numerator, denominator):\n result = numerator // denominator\n integerPart = int(result * denominator)\n remainder = numerator - integerPart\n \n gp = VGroup(\n VGroup(\n MathTex(str(numerator), color=LIGHT_PURPLE_COLOR),\n VGroup(\n Line((0, 0, 0), (0, 0.6, 0), color=LIGHT_PURPLE_COLOR),\n Line((0, 0, 0), (0.6, 0, 0), color=LIGHT_PURPLE_COLOR),\n MathTex(str(denominator), color=LIGHT_PURPLE_COLOR).shift(0.3 * UP + 0.32 * RIGHT)\n ) \n ).arrange(RIGHT),\n VGroup(\n MathTex(\"-\", color=SAND_COLOR),\n MathTex(r\"\\frac{\" + str(integerPart) + \"}{\" + str(remainder) + \"}\", color=SAND_COLOR),\n MathTex(str(result), color=SAND_COLOR)\n ).arrange(RIGHT)\n )\n\n gp[1].shift(0.5 * LEFT + 0.9 * DOWN)\n gp[1][0].shift(0.3 * UP)\n gp[1][1][0][1].scale(2).shift(0.03 * UP)\n gp[1][2].shift(0.3 * UP + 0.22 * RIGHT)\n\n return gp\n\nclass FiveDivision(Scene):\n def construct(self):\n bad = MathTex(\"w₁\")\n self.camera.background_color = BACKGROUND_COLOR\n\n by_one = Division(5, 1)\n by_one.scale(1.4)\n by_two = Division(5, 2)\n by_two.scale(1.4)\n by_three = Division(5, 3)\n by_three.scale(1.4)\n by_four = Division(5, 4)\n by_four.scale(1.4)\n by_five = Division(5, 5)\n by_five.scale(1.4)\n divisions = VGroup(\n VGroup(\n by_one,\n by_two\n ).arrange(RIGHT, buff=1),\n VGroup(\n by_three,\n by_four,\n ).arrange(RIGHT, buff=1),\n by_five\n )\n divisions.arrange(DOWN, buff=1)\n square1 = SurroundingRectangle(by_one, color=LIGHT_RED_COLOR)\n square2 = SurroundingRectangle(by_five, color=LIGHT_RED_COLOR)\n\n self.play(LaggedStart(\n FadeIn(by_one), \n FadeIn(by_two),\n FadeIn(by_three),\n FadeIn(by_four),\n FadeIn(by_five),\n lag_ratio=0.3, \n run_time=1.5\n ))\n self.wait(1)\n self.play(LaggedStart(\n Create(square1),\n Create(square2),\n lag_ratio=0.3,\n run_time=1.5\n ))\n self.wait(2)\n self.play(\n FadeOut(square1), \n FadeOut(square2), \n FadeOut(divisions), \n run_time=0.5\n )\n self.wait(0.5)\n```", "chosen": "```python\nBACKGROUND_COLOR = \"#faf4e1\"\nTEXT_COLOR = \"#434343\"\nLIGHT_RED_COLOR = \"#f55e61\"\nLIGHT_GREEN_COLOR = \"#5fcb50\"\nLIGHT_BLUE_COLOR = \"#408ef5\"\nLIGHT_ORANGE_COLOR = \"#e3883d\"\nLIGHT_PURPLE_COLOR = \"#a346eb\"\nAQUA_GREEN_COLOR = \"#0dc786\"\nGREEN_COLOR = \"#34a853\"\nDARK_RED_COLOR = \"#bf2626\"\nDARK_BLUE_COLOR = \"#3333FF\"\nSAND_COLOR = \"#b3a77d\"\nBROWN_COLOR = \"#b85842\"\n\n\nfrom manim import *\nfrom utils import *\n\nconfig.frame_size = 1080, 1920 \nconfig.frame_width = 9\nconfig.frame_height = 16\n\ndef Division(numerator, denominator):\n result = numerator // denominator\n integerPart = int(result * denominator)\n remainder = numerator - integerPart\n \n gp = VGroup(\n VGroup(\n MathTex(str(numerator), color=LIGHT_PURPLE_COLOR),\n VGroup(\n Line((0, 0, 0), (0, 0.6, 0), color=LIGHT_PURPLE_COLOR),\n Line((0, 0, 0), (0.6, 0, 0), color=LIGHT_PURPLE_COLOR),\n MathTex(str(denominator), color=LIGHT_PURPLE_COLOR).shift(0.3 * UP + 0.32 * RIGHT)\n ) \n ).arrange(RIGHT),\n VGroup(\n MathTex(\"-\", color=SAND_COLOR),\n MathTex(r\"\\frac{\" + str(integerPart) + \"}{\" + str(remainder) + \"}\", color=SAND_COLOR),\n MathTex(str(result), color=SAND_COLOR)\n ).arrange(RIGHT)\n )\n\n gp[1].shift(0.5 * LEFT + 0.9 * DOWN)\n gp[1][0].shift(0.3 * UP)\n gp[1][1][0][1].scale(2).shift(0.03 * UP)\n gp[1][2].shift(0.3 * UP + 0.22 * RIGHT)\n\n return gp\n\nclass FiveDivision(Scene):\n def construct(self):\n self.camera.background_color = BACKGROUND_COLOR\n\n by_one = Division(5, 1)\n by_one.scale(1.4)\n by_two = Division(5, 2)\n by_two.scale(1.4)\n by_three = Division(5, 3)\n by_three.scale(1.4)\n by_four = Division(5, 4)\n by_four.scale(1.4)\n by_five = Division(5, 5)\n by_five.scale(1.4)\n divisions = VGroup(\n VGroup(\n by_one,\n by_two\n ).arrange(RIGHT, buff=1),\n VGroup(\n by_three,\n by_four,\n ).arrange(RIGHT, buff=1),\n by_five\n )\n divisions.arrange(DOWN, buff=1)\n square1 = SurroundingRectangle(by_one, color=LIGHT_RED_COLOR)\n square2 = SurroundingRectangle(by_five, color=LIGHT_RED_COLOR)\n\n self.play(LaggedStart(\n FadeIn(by_one), \n FadeIn(by_two),\n FadeIn(by_three),\n FadeIn(by_four),\n FadeIn(by_five),\n lag_ratio=0.3, \n run_time=1.5\n ))\n self.wait(1)\n self.play(LaggedStart(\n Create(square1),\n Create(square2),\n lag_ratio=0.3,\n run_time=1.5\n ))\n self.wait(2)\n self.play(\n FadeOut(square1), \n FadeOut(square2), \n FadeOut(divisions), \n run_time=0.5\n )\n self.wait(0.5)\n```", "rejected": "```python\nBACKGROUND_COLOR = \"#faf4e1\"\nTEXT_COLOR = \"#434343\"\nLIGHT_RED_COLOR = \"#f55e61\"\nLIGHT_GREEN_COLOR = \"#5fcb50\"\nLIGHT_BLUE_COLOR = \"#408ef5\"\nLIGHT_ORANGE_COLOR = \"#e3883d\"\nLIGHT_PURPLE_COLOR = \"#a346eb\"\nAQUA_GREEN_COLOR = \"#0dc786\"\nGREEN_COLOR = \"#34a853\"\nDARK_RED_COLOR = \"#bf2626\"\nDARK_BLUE_COLOR = \"#3333FF\"\nSAND_COLOR = \"#b3a77d\"\nBROWN_COLOR = \"#b85842\"\n\n\nfrom manim import *\nfrom utils import *\n\nconfig.frame_size = 1080, 1920 \nconfig.frame_width = 9\nconfig.frame_height = 16\n\ndef Division(numerator, denominator):\n result = numerator // denominator\n integerPart = int(result * denominator)\n remainder = numerator - integerPart\n \n gp = VGroup(\n VGroup(\n TexMobject(str(numerator), color=LIGHT_PURPLE_COLOR),\n VGroup(\n Line((0, 0, 0), (0, 0.6, 0), color=LIGHT_PURPLE_COLOR),\n Line((0, 0, 0), (0.6, 0, 0), color=LIGHT_PURPLE_COLOR),\n MathTex(str(denominator), color=LIGHT_PURPLE_COLOR).shift(0.3 * UP + 0.32 * RIGHT)\n ) \n ).arrange(RIGHT),\n VGroup(\n MathTex(\"-\", color=SAND_COLOR),\n MathTex(r\"\\frac{\" + str(integerPart) + \"}{\" + str(remainder) + \"}\", color=SAND_COLOR),\n MathTex(str(result), color=SAND_COLOR)\n ).arrange(RIGHT)\n )\n\n gp[1].shift(0.5 * LEFT + 0.9 * DOWN)\n gp[1][0].shift(0.3 * UP)\n gp[1][1][0][1].scale(2).shift(0.03 * UP)\n gp[1][2].shift(0.3 * UP + 0.22 * RIGHT)\n\n return gp\n\nclass FiveDivision(Scene):\n def construct(self):\n self.camera.background_color = BACKGROUND_COLOR\n\n by_one = Division(5, 1)\n by_one.scale(1.4)\n by_two = Division(5, 2)\n by_two.scale(1.4)\n by_three = Division(5, 3)\n by_three.scale(1.4)\n by_four = Division(5, 4)\n by_four.scale(1.4)\n by_five = Division(5, 5)\n by_five.scale(1.4)\n divisions = VGroup(\n VGroup(\n by_one,\n by_two\n ).arrange(RIGHT, buff=1),\n VGroup(\n by_three,\n by_four,\n ).arrange(RIGHT, buff=1),\n by_five\n )\n divisions.arrange(DOWN, buff=1)\n square1 = SurroundingRectangle(by_one, color=LIGHT_RED_COLOR)\n square2 = SurroundingRectangle(by_five, color=LIGHT_RED_COLOR)\n\n self.play(LaggedStart(\n FadeIn(by_one), \n FadeIn(by_two),\n FadeIn(by_three),\n FadeIn(by_four),\n FadeIn(by_five),\n lag_ratio=0.3, \n run_time=1.5\n ))\n self.wait(1)\n self.play(LaggedStart(\n ShowCreation(square1),\n Create(square2),\n lag_ratio=0.3,\n run_time=1.5\n ))\n self.wait(2)\n self.play(\n FadeOut(square1), \n FadeOut(square2), \n FadeOut(divisions), \n run_time=0.5\n )\n self.wait(0.5)\n```", "category": "legacy_api_hallucination", "source": "synthetic_hard_neg:nabin2004/manim-sft-10k"} +{"system": "You are an expert Manim Community Edition (ManimCE v0.19+) Python developer and mathematical animator. Given a user request, first plan the spatial layout, coordinate bounds, timing, and pedagogical flow inside ... tags (when reasoning is helpful), and then output a complete, runnable, self-contained ManimCE Python script using `from manim import *`. Never use deprecated ManimGL (`manimlib`) methods like `ShowCreation`, `TexMobject`, `TextMobject`, or `axes.get_graph`; always use modern ManimCE APIs (`Create`, `MathTex`, `Tex`, `Text`, `axes.plot`) and prevent visual overlap using `.to_edge()`, `.next_to()`, and `FadeOut`.", "prompt": "I'm teaching an undergrad course on PyTorch architectures and want an animated nn.Module tree visualization.\nStart from a root module and recursively unfold into child modules, showing names, shapes, and parent-child relations.\nAdd a zoomed-in view of a selected submodule’s internals and a high-level summary of the overall module hierarchy.", "chosen": "```python\nfrom manim import *\nfrom manim_voiceover import VoiceoverScene\nfrom manim_voiceover.services.gtts import GTTSService\n\n\nclass VisualizingPyTorchModuleArchitectures(VoiceoverScene):\n def construct(self):\n self.set_speech_service(\n GTTSService(voice=\"alba\", cache_dir=\"voiceover_cache\")\n )\n\n # Title\n with self.voiceover(text=\"Welcome to our session on Visualizing PyTorch Module Architectures.\") as tracker:\n title = Text(\"Visualizing PyTorch Module Architectures\", font_size=36)\n title.to_edge(UP, buff=0.5)\n self.play(Write(title), run_time=tracker.duration)\n\n # Opener question\n with self.voiceover(text=\"Have you ever wondered how deep learning models are built and structured in PyTorch? Visualizing the architecture can really illuminate the design of these networks and help you understand how they function.\") as tracker:\n question = Text(\"How are PyTorch models structured?\", font_size=28, color=BLUE)\n question.next_to(title, DOWN, buff=0.8)\n self.play(Write(question), run_time=tracker.duration)\n\n self.wait(0.5)\n\n # Clear for architecture demo\n self.play(FadeOut(question))\n\n # Build a simple neural network visualization\n with self.voiceover(text=\"Let's visualize a simple neural network. We'll start with an input layer.\") as tracker:\n # Input layer\n input_layer = VGroup()\n input_nodes = []\n for i in range(3):\n node = Circle(radius=0.25, color=BLUE, fill_opacity=0.8)\n node.shift(LEFT * 4 + UP * (1 - i))\n input_layer.add(node)\n input_nodes.append(node)\n input_label = Text(\"Input\\nLayer\", font_size=20).next_to(input_layer, LEFT, buff=0.5)\n self.play(Create(input_layer), Write(input_label), run_time=tracker.duration)\n\n # Hidden layer\n with self.voiceover(text=\"Next, we add a hidden layer with multiple neurons.\") as tracker:\n hidden_layer = VGroup()\n hidden_nodes = []\n for i in range(4):\n node = Circle(radius=0.25, color=GREEN, fill_opacity=0.8)\n node.shift(LEFT * 0.5 + UP * (1.5 - i * 0.8))\n hidden_layer.add(node)\n hidden_nodes.append(node)\n hidden_label = Text(\"Hidden\\nLayer\", font_size=20).next_to(hidden_layer, UP, buff=0.3)\n self.play(Create(hidden_layer), Write(hidden_label), run_time=tracker.duration)\n\n # Output layer\n with self.voiceover(text=\"Finally, the output layer produces our predictions.\") as tracker:\n output_layer = VGroup()\n output_nodes = []\n for i in range(2):\n node = Circle(radius=0.25, color=RED, fill_opacity=0.8)\n node.shift(RIGHT * 3 + UP * (0.5 - i))\n output_layer.add(node)\n output_nodes.append(node)\n output_label = Text(\"Output\\nLayer\", font_size=20).next_to(output_layer, RIGHT, buff=0.5)\n self.play(Create(output_layer), Write(output_label), run_time=tracker.duration)\n\n # Connections - Input to Hidden\n with self.voiceover(text=\"Each connection represents a weight parameter in our model.\") as tracker:\n connections_ih = VGroup()\n for in_node in input_nodes:\n for hid_node in hidden_nodes:\n line = Line(in_node.get_center(), hid_node.get_center(), stroke_width=1, color=GRAY)\n connections_ih.add(line)\n self.play(Create(connections_ih), run_time=tracker.duration)\n\n # Connections - Hidden to Output\n with self.voiceover(text=\"These connections carry information forward through the network.\") as tracker:\n connections_ho = VGroup()\n for hid_node in hidden_nodes:\n for out_node in output_nodes:\n line = Line(hid_node.get_center(), out_node.get_center(), stroke_width=1, color=GRAY)\n connections_ho.add(line)\n self.play(Create(connections_ho), run_time=tracker.duration)\n\n self.wait(0.5)\n\n # Show PyTorch code representation\n with self.voiceover(text=\"In PyTorch, this architecture is defined using the Module class.\") as tracker:\n # Fade out the network slightly\n network_group = VGroup(input_layer, hidden_layer, output_layer, \n connections_ih, connections_ho, \n input_label, hidden_label, output_label)\n self.play(network_group.animate.scale(0.6).to_edge(LEFT, buff=0.5).shift(DOWN * 0.5), run_time=1)\n\n with self.voiceover(text=\"Here's how we code this network. The linear layers define our connections, and ReLU adds non-linearity.\") as tracker:\n # Create code visualization using Text with monospace styling\n code_lines = VGroup()\n code_content = [\n \"import torch.nn as nn\",\n \"\",\n \"class SimpleNet(nn.Module):\",\n \" def __init__(self):\",\n \" super().__init__()\",\n \" self.fc1 = nn.Linear(3, 4)\",\n \" self.relu = nn.ReLU()\",\n \" self.fc2 = nn.Linear(4, 2)\",\n \" \",\n \" def forward(self, x):\",\n \" x = self.fc1(x)\",\n \" x = self.relu(x)\",\n \" x = self.fc2(x)\",\n \" return x\"\n ]\n for i, line in enumerate(code_content):\n line_text = Text(line, font_size=14, font=\"monospace\")\n line_text.shift(RIGHT * 2.5 + UP * (2.5 - i * 0.3))\n code_lines.add(line_text)\n \n # Add a background rectangle\n bg = SurroundingRectangle(code_lines, buff=0.3, color=WHITE, fill_color=BLACK, fill_opacity=0.9)\n self.play(Create(bg), LaggedStart(*[Write(line) for line in code_lines], lag_ratio=0.1), run_time=tracker.duration)\n\n self.wait(0.5)\n\n # Learning outcomes\n self.play(FadeOut(network_group), FadeOut(bg), FadeOut(code_lines), FadeOut(title))\n\n with self.voiceover(text=\"By the end of this session, you'll be able to identify components of PyTorch module architectures, and create visual representations of neural network structures using Manim.\") as tracker:\n outcomes_title = Text(\"Learning Outcomes\", font_size=32, color=YELLOW)\n outcomes_title.to_edge(UP, buff=0.5)\n \n outcome1 = Text(\"• Identify components of PyTorch module architectures\", font_size=24)\n outcome2 = Text(\"• Create visual representations using Manim\", font_size=24)\n \n outcome1.next_to(outcomes_title, DOWN, buff=0.8)\n outcome2.next_to(outcome1, DOWN, buff=0.5)\n \n self.play(Write(outcomes_title), run_time=1)\n self.play(Write(outcome1), run_time=1)\n self.play(Write(outcome2), run_time=tracker.duration - 2)\n\n self.wait(1)\n self.play(FadeOut(outcomes_title), FadeOut(outcome1), FadeOut(outcome2))\n\n # Closing\n with self.voiceover(text=\"Thank you for joining. Happy visualizing!\") as tracker:\n closing = Text(\"Happy Visualizing!\", font_size=40, color=BLUE)\n self.play(Write(closing), run_time=tracker.duration)\n\n self.wait(1)\n```", "rejected": "```python\nfrom manim import *\nfrom manim_voiceover import VoiceoverScene\nfrom manim_voiceover.services.gtts import GTTSService\n\n\nclass VisualizingPyTorchModuleArchitectures(VoiceoverScene):\n def construct(self):\n self.set_speech_service(\n GTTSService(voice=\"alba\", cache_dir=\"voiceover_cache\")\n )\n\n # Title\n with self.voiceover(text=\"Welcome to our session on Visualizing PyTorch Module Architectures.\") as tracker:\n title = Text(\"Visualizing PyTorch Module Architectures\", font_size=36)\n title.to_edge(UP, buff=0.5)\n self.play(Write(title), run_time=tracker.duration)\n\n # Opener question\n with self.voiceover(text=\"Have you ever wondered how deep learning models are built and structured in PyTorch? Visualizing the architecture can really illuminate the design of these networks and help you understand how they function.\") as tracker:\n question = Text(\"How are PyTorch models structured?\", font_size=28, color=BLUE)\n question.next_to(title, DOWN, buff=0.8)\n self.play(Write(question), run_time=tracker.duration)\n\n self.wait(0.5)\n\n # Clear for architecture demo\n self.play(FadeOut(question))\n\n # Build a simple neural network visualization\n with self.voiceover(text=\"Let's visualize a simple neural network. We'll start with an input layer.\") as tracker:\n # Input layer\n input_layer = VGroup()\n input_nodes = []\n for i in range(3):\n node = Circle(radius=0.25, color=BLUE, fill_opacity=0.8)\n node.shift(LEFT * 4 + UP * (1 - i))\n input_layer.add(node)\n input_nodes.append(node)\n input_label = Text(\"Input\\nLayer\", font_size=20).next_to(input_layer, LEFT, buff=0.5)\n self.play(ShowCreation(input_layer), Write(input_label), run_time=tracker.duration)\n\n # Hidden layer\n with self.voiceover(text=\"Next, we add a hidden layer with multiple neurons.\") as tracker:\n hidden_layer = VGroup()\n hidden_nodes = []\n for i in range(4):\n node = Circle(radius=0.25, color=GREEN, fill_opacity=0.8)\n node.shift(LEFT * 0.5 + UP * (1.5 - i * 0.8))\n hidden_layer.add(node)\n hidden_nodes.append(node)\n hidden_label = Text(\"Hidden\\nLayer\", font_size=20).next_to(hidden_layer, UP, buff=0.3)\n self.play(Create(hidden_layer), Write(hidden_label), run_time=tracker.duration)\n\n # Output layer\n with self.voiceover(text=\"Finally, the output layer produces our predictions.\") as tracker:\n output_layer = VGroup()\n output_nodes = []\n for i in range(2):\n node = Circle(radius=0.25, color=RED, fill_opacity=0.8)\n node.shift(RIGHT * 3 + UP * (0.5 - i))\n output_layer.add(node)\n output_nodes.append(node)\n output_label = Text(\"Output\\nLayer\", font_size=20).next_to(output_layer, RIGHT, buff=0.5)\n self.play(Create(output_layer), Write(output_label), run_time=tracker.duration)\n\n # Connections - Input to Hidden\n with self.voiceover(text=\"Each connection represents a weight parameter in our model.\") as tracker:\n connections_ih = VGroup()\n for in_node in input_nodes:\n for hid_node in hidden_nodes:\n line = Line(in_node.get_center(), hid_node.get_center(), stroke_width=1, color=GRAY)\n connections_ih.add(line)\n self.play(Create(connections_ih), run_time=tracker.duration)\n\n # Connections - Hidden to Output\n with self.voiceover(text=\"These connections carry information forward through the network.\") as tracker:\n connections_ho = VGroup()\n for hid_node in hidden_nodes:\n for out_node in output_nodes:\n line = Line(hid_node.get_center(), out_node.get_center(), stroke_width=1, color=GRAY)\n connections_ho.add(line)\n self.play(Create(connections_ho), run_time=tracker.duration)\n\n self.wait(0.5)\n\n # Show PyTorch code representation\n with self.voiceover(text=\"In PyTorch, this architecture is defined using the Module class.\") as tracker:\n # Fade out the network slightly\n network_group = VGroup(input_layer, hidden_layer, output_layer, \n connections_ih, connections_ho, \n input_label, hidden_label, output_label)\n self.play(network_group.animate.scale(0.6).to_edge(LEFT, buff=0.5).shift(DOWN * 0.5), run_time=1)\n\n with self.voiceover(text=\"Here's how we code this network. The linear layers define our connections, and ReLU adds non-linearity.\") as tracker:\n # Create code visualization using Text with monospace styling\n code_lines = VGroup()\n code_content = [\n \"import torch.nn as nn\",\n \"\",\n \"class SimpleNet(nn.Module):\",\n \" def __init__(self):\",\n \" super().__init__()\",\n \" self.fc1 = nn.Linear(3, 4)\",\n \" self.relu = nn.ReLU()\",\n \" self.fc2 = nn.Linear(4, 2)\",\n \" \",\n \" def forward(self, x):\",\n \" x = self.fc1(x)\",\n \" x = self.relu(x)\",\n \" x = self.fc2(x)\",\n \" return x\"\n ]\n for i, line in enumerate(code_content):\n line_text = Text(line, font_size=14, font=\"monospace\")\n line_text.shift(RIGHT * 2.5 + UP * (2.5 - i * 0.3))\n code_lines.add(line_text)\n \n # Add a background rectangle\n bg = SurroundingRectangle(code_lines, buff=0.3, color=WHITE, fill_color=BLACK, fill_opacity=0.9)\n self.play(Create(bg), LaggedStart(*[Write(line) for line in code_lines], lag_ratio=0.1), run_time=tracker.duration)\n\n self.wait(0.5)\n\n # Learning outcomes\n self.play(FadeOut(network_group), FadeOut(bg), FadeOut(code_lines), FadeOut(title))\n\n with self.voiceover(text=\"By the end of this session, you'll be able to identify components of PyTorch module architectures, and create visual representations of neural network structures using Manim.\") as tracker:\n outcomes_title = Text(\"Learning Outcomes\", font_size=32, color=YELLOW)\n outcomes_title.to_edge(UP, buff=0.5)\n \n outcome1 = Text(\"• Identify components of PyTorch module architectures\", font_size=24)\n outcome2 = Text(\"• Create visual representations using Manim\", font_size=24)\n \n outcome1.next_to(outcomes_title, DOWN, buff=0.8)\n outcome2.next_to(outcome1, DOWN, buff=0.5)\n \n self.play(Write(outcomes_title), run_time=1)\n self.play(Write(outcome1), run_time=1)\n self.play(Write(outcome2), run_time=tracker.duration - 2)\n\n self.wait(1)\n self.play(FadeOut(outcomes_title), FadeOut(outcome1), FadeOut(outcome2))\n\n # Closing\n with self.voiceover(text=\"Thank you for joining. Happy visualizing!\") as tracker:\n closing = Text(\"Happy Visualizing!\", font_size=40, color=BLUE)\n self.play(Write(closing), run_time=tracker.duration)\n\n self.wait(1)\n```", "category": "legacy_api_hallucination", "source": "synthetic_hard_neg:nabin2004/AOS-Narrated-Manim-400"} +{"system": "You are an expert Manim Community Edition (ManimCE v0.19+) Python developer and mathematical animator. Given a user request, first plan the spatial layout, coordinate bounds, timing, and pedagogical flow inside ... tags (when reasoning is helpful), and then output a complete, runnable, self-contained ManimCE Python script using `from manim import *`. Never use deprecated ManimGL (`manimlib`) methods like `ShowCreation`, `TexMobject`, `TextMobject`, or `axes.get_graph`; always use modern ManimCE APIs (`Create`, `MathTex`, `Tex`, `Text`, `axes.plot`) and prevent visual overlap using `.to_edge()`, `.next_to()`, and `FadeOut`.", "prompt": "Create a 16:9 Manim animation for a Grade 12 Business Studies class on \"Policies and Strategies in Marketing\" following this structure:\n\n1. Title slide: Display \"Policies and Strategies in Marketing\" with a subtle business-themed background.\n\n2. Question presentation: Show the question \"Describe the role of policies in interpreting marketing strategies?\" centered on screen, allowing time for students to read and think.\n\n3. Visual hierarchy diagram: Create a flowchart showing:\n - \"Marketing Strategies\" at the top (broad, general statements)\n - Arrow pointing downward\n - \"Policies\" in the middle (general guidelines and frameworks)\n - Arrow pointing downward\n - \"Managerial Actions & Decisions\" at the bottom (specific execution)\n\n4. Key concept boxes: Display three connected boxes showing:\n Box 1: \"Strategies (Broad Plans)\" - examples like pricing, distribution, advertising\n Box 2: \"Policies (Guidelines)\" - emphasizing framework and consistency\n Box 3: \"Execution (Effective Implementation)\" - how strategies become reality\n\n5. Answer summary: Present the answer text clearly: \"Policies provide a basis for interpreting strategies by serving as guides to managerial action, ensuring effective and consistent execution.\"\n\n6. Reinforcement: Show how policies bridge the gap between abstract strategies and concrete business decisions with simple real-world marketing examples.\n\nMaintain clear, readable fonts throughout. Use professional colors and smooth transitions between sections. Total animation time should be approximately 90 seconds.", "chosen": "```python\nfrom manim import *\nimport numpy as np\nimport random\nimport math\n\nclass MarketingStrategies(Scene):\n def construct(self):\n # Setup Theme\n self.camera.background_color = \"#0f0f0f\"\n \n # Color Palette\n BLUE_ACCENT = \"#4a9eff\"\n GREEN_ACCENT = \"#6ba76e\"\n ORANGE_ACCENT = \"#e8945e\"\n TEXT_COLOR = \"#d4d4d4\"\n \n # --- SECTION 1: TITLE SLIDE (0-8s) ---\n title = Text(\"Policies and Strategies\", font_size=54, color=BLUE_ACCENT, weight=BOLD)\n subtitle = Text(\"in Marketing\", font_size=42, color=TEXT_COLOR)\n grade = Text(\"Grade 12 Business Studies\", font_size=24, color=GRAY)\n \n header_group = VGroup(title, subtitle, grade).arrange(DOWN, buff=0.3)\n \n # Decorative elements for title\n line_top = Line(LEFT*4, RIGHT*4, color=BLUE_ACCENT).next_to(header_group, UP, buff=0.5)\n line_bottom = Line(LEFT*4, RIGHT*4, color=BLUE_ACCENT).next_to(header_group, DOWN, buff=0.5)\n \n self.play(\n Create(line_top),\n Create(line_bottom),\n Write(header_group),\n run_time=3.0\n )\n self.wait(5.0) # Total 8s\n \n # --- SECTION 2: QUESTION PRESENTATION (8-20s) ---\n self.play(\n FadeOut(header_group),\n FadeOut(line_top),\n FadeOut(line_bottom),\n run_time=1.0\n )\n \n question_text = Text(\n \"Describe the role of policies in\\ninterpreting marketing strategies?\",\n font_size=36,\n line_spacing=1.2,\n t2c={\"policies\": GREEN_ACCENT, \"marketing strategies\": BLUE_ACCENT}\n )\n question_text.move_to(ORIGIN)\n \n self.play(Write(question_text), run_time=3.0)\n self.wait(8.0) # Allow reading time. Total 12s segment.\n \n # --- SECTION 3: VISUAL HIERARCHY DIAGRAM (20-45s) ---\n self.play(FadeOut(question_text), run_time=1.0)\n \n # Define shapes for vertical hierarchy\n box_width = 6.0\n box_height = 1.2\n \n # Level 1: Strategies\n strat_box = RoundedRectangle(width=box_width, height=box_height, corner_radius=0.2, color=BLUE_ACCENT)\n strat_txt = Text(\"Marketing Strategies\", font_size=32).move_to(strat_box.get_top() + DOWN*0.3)\n strat_sub = Text(\"(Broad, General Statements)\", font_size=24, color=GRAY_B).next_to(strat_txt, DOWN, buff=0.1)\n strat_group = VGroup(strat_box, strat_txt, strat_sub)\n \n # Level 2: Policies\n pol_box = RoundedRectangle(width=box_width, height=box_height, corner_radius=0.2, color=GREEN_ACCENT)\n pol_txt = Text(\"Policies\", font_size=32).move_to(pol_box.get_top() + DOWN*0.3)\n pol_sub = Text(\"(General Guidelines & Frameworks)\", font_size=24, color=GRAY_B).next_to(pol_txt, DOWN, buff=0.1)\n pol_group = VGroup(pol_box, pol_txt, pol_sub)\n \n # Level 3: Actions\n act_box = RoundedRectangle(width=box_width, height=box_height, corner_radius=0.2, color=ORANGE_ACCENT)\n act_txt = Text(\"Managerial Actions\", font_size=32).move_to(act_box.get_top() + DOWN*0.3)\n act_sub = Text(\"(Specific Execution)\", font_size=24, color=GRAY_B).next_to(act_txt, DOWN, buff=0.1)\n act_group = VGroup(act_box, act_txt, act_sub)\n \n # Arrangement\n hierarchy = VGroup(strat_group, pol_group, act_group).arrange(DOWN, buff=1.0)\n hierarchy.move_to(ORIGIN)\n \n # Arrows\n arrow1 = Arrow(start=strat_box.get_bottom(), end=pol_box.get_top(), buff=0.1, color=TEXT_COLOR)\n arrow2 = Arrow(start=pol_box.get_bottom(), end=act_box.get_top(), buff=0.1, color=TEXT_COLOR)\n \n # Animation sequence\n self.play(FadeIn(strat_group, shift=DOWN), run_time=2.0)\n self.wait(1.0)\n self.play(GrowArrow(arrow1), run_time=1.0)\n self.play(FadeIn(pol_group, shift=DOWN), run_time=2.0)\n self.wait(1.0)\n self.play(GrowArrow(arrow2), run_time=1.0)\n self.play(FadeIn(act_group, shift=DOWN), run_time=2.0)\n self.wait(14.0) # Explanation time. Total 25s segment.\n \n # --- SECTION 4: KEY CONCEPT BOXES (45-65s) ---\n # Transition: Shrink and move or just clear and show detailed view\n self.play(\n FadeOut(hierarchy),\n FadeOut(arrow1),\n FadeOut(arrow2),\n run_time=1.0\n )\n \n # Detailed Concept Boxes (Horizontal)\n # We need to fit 3 boxes horizontally\n \n def create_concept_card(title_str, sub_str, color, pos):\n card = VGroup()\n rect = RoundedRectangle(width=3.8, height=4.5, corner_radius=0.2, color=color)\n rect.set_fill(color, opacity=0.1)\n \n t_title = Text(title_str, font_size=28, weight=BOLD, color=color)\n t_title.move_to(rect.get_top() + DOWN*0.6)\n \n # Using paragraph for body text to wrap\n t_body = Text(sub_str, font_size=22, line_spacing=1.2, color=TEXT_COLOR)\n # Ensure text fits width\n if t_body.get_width() > 3.4:\n t_body.scale_to_fit_width(3.4)\n t_body.next_to(t_title, DOWN, buff=0.5)\n \n card.add(rect, t_title, t_body)\n card.move_to(pos)\n return card\n\n card1 = create_concept_card(\"Strategies\", \"Broad Plans\\n\\nExamples:\\n- Pricing\\n- Distribution\\n- Advertising\", BLUE_ACCENT, LEFT*4.2)\n card2 = create_concept_card(\"Policies\", \"Guidelines\\n\\n- Frameworks\\n- Consistency\\n- Interpretation\", GREEN_ACCENT, ORIGIN)\n card3 = create_concept_card(\"Execution\", \"Implementation\\n\\n- Daily Actions\\n- Decisions\\n- Reality\", ORANGE_ACCENT, RIGHT*4.2)\n \n self.play(LaggedStart(\n FadeIn(card1, shift=UP),\n FadeIn(card2, shift=UP),\n FadeIn(card3, shift=UP),\n lag_ratio=0.5\n ), run_time=3.0)\n \n # Highlight connection (Policies connects Strategy to Execution)\n conn1 = Arrow(card1.get_right(), card2.get_left(), color=TEXT_COLOR, buff=0.1)\n conn2 = Arrow(card2.get_right(), card3.get_left(), color=TEXT_COLOR, buff=0.1)\n \n self.play(GrowArrow(conn1), GrowArrow(conn2), run_time=2.0)\n self.wait(14.0) # Total 20s segment\n \n # --- SECTION 5: ANSWER SUMMARY (65-80s) ---\n self.play(\n FadeOut(card1), FadeOut(card2), FadeOut(card3), \n FadeOut(conn1), FadeOut(conn2),\n run_time=1.0\n )\n \n answer_text = Text(\n \"Policies provide a basis for interpreting\\nstrategies by serving as guides to\\nmanagerial action, ensuring effective\\nand consistent execution.\",\n font_size=32,\n line_spacing=1.5,\n t2c={\n \"interpreting\": BLUE_ACCENT, \n \"guides\": GREEN_ACCENT, \n \"action\": ORANGE_ACCENT,\n \"consistent\": GREEN_ACCENT\n }\n )\n answer_text.move_to(ORIGIN)\n \n # Draw a box around the answer\n answer_box = SurroundingRectangle(answer_text, color=TEXT_COLOR, buff=0.5, corner_radius=0.2)\n \n self.play(Write(answer_text), run_time=4.0)\n self.play(Create(answer_box), run_time=1.0)\n self.wait(9.0) # Total 15s segment\n \n # --- SECTION 6: REINFORCEMENT / BRIDGE (80-90s) ---\n self.play(\n FadeOut(answer_text),\n FadeOut(answer_box),\n run_time=1.0\n )\n \n # Create a visual bridge metaphor\n # Left side: Abstract (Cloud)\n abstract_label = Text(\"Abstract Strategy\", font_size=24, color=BLUE_ACCENT).to_edge(LEFT, buff=1.5).shift(UP)\n cloud = Cloud(color=BLUE_ACCENT, fill_opacity=0.2).scale(0.8).next_to(abstract_label, DOWN)\n \n # Right side: Concrete (Cube/Square)\n concrete_label = Text(\"Concrete Action\", font_size=24, color=ORANGE_ACCENT).to_edge(RIGHT, buff=1.5).shift(UP)\n brick = Square(side_length=1.5, color=ORANGE_ACCENT, fill_opacity=0.2).next_to(concrete_label, DOWN)\n \n # Middle: Bridge (Policies)\n bridge = Rectangle(width=4, height=0.5, color=GREEN_ACCENT, fill_opacity=0.5)\n bridge.move_to(ORIGIN + DOWN*0.5)\n bridge_label = Text(\"POLICY BRIDGE\", font_size=20, color=BLACK).move_to(bridge.get_center())\n \n self.play(\n FadeIn(abstract_label), FadeIn(cloud),\n FadeIn(concrete_label), FadeIn(brick),\n run_time=2.0\n )\n \n self.play(\n GrowFromCenter(bridge),\n FadeIn(bridge_label),\n run_time=2.0\n )\n \n final_arrow = Arrow(cloud.get_right(), brick.get_left(), color=WHITE, buff=0.1).set_stroke(width=2)\n # Ensure arrow goes OVER the bridge visually\n self.bring_to_front(bridge, bridge_label)\n \n self.play(Create(final_arrow), run_time=2.0)\n self.wait(3.0) # Total 10s segment -> Total 90s roughly\n \n # Cleanup\n self.play(FadeOut(Group(*self.mobjects)), run_time=1.0)\n\n# Helper class for the cloud shape since it's not a standard primitive\nclass Cloud(VGroup):\n def __init__(self, color=WHITE, **kwargs):\n super().__init__(**kwargs)\n circles = VGroup()\n centers = [ORIGIN, UP*0.5, UP*0.5+RIGHT*0.5, RIGHT*0.8, RIGHT*0.4+DOWN*0.3, LEFT*0.4+DOWN*0.3, LEFT*0.8, LEFT*0.5+UP*0.5]\n radii = [0.8, 0.6, 0.7, 0.6, 0.7, 0.6, 0.7, 0.6]\n \n for center, radius in zip(centers, radii):\n circles.add(Circle(radius=radius, color=color, fill_opacity=0.5, stroke_opacity=0).move_to(center))\n \n self.add(circles)\n # Merge visually by adding an outline if needed, but simple group of circles works for metaphor\n```", "rejected": "```python\nfrom manim import *\nimport numpy as np\nimport random\nimport math\n\nclass MarketingStrategies(Scene):\n def construct(self):\n # Setup Theme\n self.camera.background_color = \"#0f0f0f\"\n \n # Color Palette\n BLUE_ACCENT = \"#4a9eff\"\n GREEN_ACCENT = \"#6ba76e\"\n ORANGE_ACCENT = \"#e8945e\"\n TEXT_COLOR = \"#d4d4d4\"\n \n # --- SECTION 1: TITLE SLIDE (0-8s) ---\n title = Text(\"Policies and Strategies\", font_size=54, color=BLUE_ACCENT, weight=BOLD)\n subtitle = Text(\"in Marketing\", font_size=42, color=TEXT_COLOR)\n grade = Text(\"Grade 12 Business Studies\", font_size=24, color=GRAY)\n \n header_group = VGroup(title, subtitle, grade).arrange(DOWN, buff=0.3)\n \n # Decorative elements for title\n line_top = Line(LEFT*4, RIGHT*4, color=BLUE_ACCENT).next_to(header_group, UP, buff=0.5)\n line_bottom = Line(LEFT*4, RIGHT*4, color=BLUE_ACCENT).next_to(header_group, DOWN, buff=0.5)\n \n self.play(\n ShowCreation(line_top),\n Create(line_bottom),\n Write(header_group),\n run_time=3.0\n )\n self.wait(5.0) # Total 8s\n \n # --- SECTION 2: QUESTION PRESENTATION (8-20s) ---\n self.play(\n FadeOut(header_group),\n FadeOut(line_top),\n FadeOut(line_bottom),\n run_time=1.0\n )\n \n question_text = Text(\n \"Describe the role of policies in\\ninterpreting marketing strategies?\",\n font_size=36,\n line_spacing=1.2,\n t2c={\"policies\": GREEN_ACCENT, \"marketing strategies\": BLUE_ACCENT}\n )\n question_text.move_to(ORIGIN)\n \n self.play(Write(question_text), run_time=3.0)\n self.wait(8.0) # Allow reading time. Total 12s segment.\n \n # --- SECTION 3: VISUAL HIERARCHY DIAGRAM (20-45s) ---\n self.play(FadeOut(question_text), run_time=1.0)\n \n # Define shapes for vertical hierarchy\n box_width = 6.0\n box_height = 1.2\n \n # Level 1: Strategies\n strat_box = RoundedRectangle(width=box_width, height=box_height, corner_radius=0.2, color=BLUE_ACCENT)\n strat_txt = Text(\"Marketing Strategies\", font_size=32).move_to(strat_box.get_top() + DOWN*0.3)\n strat_sub = Text(\"(Broad, General Statements)\", font_size=24, color=GRAY_B).next_to(strat_txt, DOWN, buff=0.1)\n strat_group = VGroup(strat_box, strat_txt, strat_sub)\n \n # Level 2: Policies\n pol_box = RoundedRectangle(width=box_width, height=box_height, corner_radius=0.2, color=GREEN_ACCENT)\n pol_txt = Text(\"Policies\", font_size=32).move_to(pol_box.get_top() + DOWN*0.3)\n pol_sub = Text(\"(General Guidelines & Frameworks)\", font_size=24, color=GRAY_B).next_to(pol_txt, DOWN, buff=0.1)\n pol_group = VGroup(pol_box, pol_txt, pol_sub)\n \n # Level 3: Actions\n act_box = RoundedRectangle(width=box_width, height=box_height, corner_radius=0.2, color=ORANGE_ACCENT)\n act_txt = Text(\"Managerial Actions\", font_size=32).move_to(act_box.get_top() + DOWN*0.3)\n act_sub = Text(\"(Specific Execution)\", font_size=24, color=GRAY_B).next_to(act_txt, DOWN, buff=0.1)\n act_group = VGroup(act_box, act_txt, act_sub)\n \n # Arrangement\n hierarchy = VGroup(strat_group, pol_group, act_group).arrange(DOWN, buff=1.0)\n hierarchy.move_to(ORIGIN)\n \n # Arrows\n arrow1 = Arrow(start=strat_box.get_bottom(), end=pol_box.get_top(), buff=0.1, color=TEXT_COLOR)\n arrow2 = Arrow(start=pol_box.get_bottom(), end=act_box.get_top(), buff=0.1, color=TEXT_COLOR)\n \n # Animation sequence\n self.play(FadeIn(strat_group, shift=DOWN), run_time=2.0)\n self.wait(1.0)\n self.play(GrowArrow(arrow1), run_time=1.0)\n self.play(FadeIn(pol_group, shift=DOWN), run_time=2.0)\n self.wait(1.0)\n self.play(GrowArrow(arrow2), run_time=1.0)\n self.play(FadeIn(act_group, shift=DOWN), run_time=2.0)\n self.wait(14.0) # Explanation time. Total 25s segment.\n \n # --- SECTION 4: KEY CONCEPT BOXES (45-65s) ---\n # Transition: Shrink and move or just clear and show detailed view\n self.play(\n FadeOut(hierarchy),\n FadeOut(arrow1),\n FadeOut(arrow2),\n run_time=1.0\n )\n \n # Detailed Concept Boxes (Horizontal)\n # We need to fit 3 boxes horizontally\n \n def create_concept_card(title_str, sub_str, color, pos):\n card = VGroup()\n rect = RoundedRectangle(width=3.8, height=4.5, corner_radius=0.2, color=color)\n rect.set_fill(color, opacity=0.1)\n \n t_title = Text(title_str, font_size=28, weight=BOLD, color=color)\n t_title.move_to(rect.get_top() + DOWN*0.6)\n \n # Using paragraph for body text to wrap\n t_body = Text(sub_str, font_size=22, line_spacing=1.2, color=TEXT_COLOR)\n # Ensure text fits width\n if t_body.get_width() > 3.4:\n t_body.scale_to_fit_width(3.4)\n t_body.next_to(t_title, DOWN, buff=0.5)\n \n card.add(rect, t_title, t_body)\n card.move_to(pos)\n return card\n\n card1 = create_concept_card(\"Strategies\", \"Broad Plans\\n\\nExamples:\\n- Pricing\\n- Distribution\\n- Advertising\", BLUE_ACCENT, LEFT*4.2)\n card2 = create_concept_card(\"Policies\", \"Guidelines\\n\\n- Frameworks\\n- Consistency\\n- Interpretation\", GREEN_ACCENT, ORIGIN)\n card3 = create_concept_card(\"Execution\", \"Implementation\\n\\n- Daily Actions\\n- Decisions\\n- Reality\", ORANGE_ACCENT, RIGHT*4.2)\n \n self.play(LaggedStart(\n FadeIn(card1, shift=UP),\n FadeIn(card2, shift=UP),\n FadeIn(card3, shift=UP),\n lag_ratio=0.5\n ), run_time=3.0)\n \n # Highlight connection (Policies connects Strategy to Execution)\n conn1 = Arrow(card1.get_right(), card2.get_left(), color=TEXT_COLOR, buff=0.1)\n conn2 = Arrow(card2.get_right(), card3.get_left(), color=TEXT_COLOR, buff=0.1)\n \n self.play(GrowArrow(conn1), GrowArrow(conn2), run_time=2.0)\n self.wait(14.0) # Total 20s segment\n \n # --- SECTION 5: ANSWER SUMMARY (65-80s) ---\n self.play(\n FadeOut(card1), FadeOut(card2), FadeOut(card3), \n FadeOut(conn1), FadeOut(conn2),\n run_time=1.0\n )\n \n answer_text = Text(\n \"Policies provide a basis for interpreting\\nstrategies by serving as guides to\\nmanagerial action, ensuring effective\\nand consistent execution.\",\n font_size=32,\n line_spacing=1.5,\n t2c={\n \"interpreting\": BLUE_ACCENT, \n \"guides\": GREEN_ACCENT, \n \"action\": ORANGE_ACCENT,\n \"consistent\": GREEN_ACCENT\n }\n )\n answer_text.move_to(ORIGIN)\n \n # Draw a box around the answer\n answer_box = SurroundingRectangle(answer_text, color=TEXT_COLOR, buff=0.5, corner_radius=0.2)\n \n self.play(Write(answer_text), run_time=4.0)\n self.play(Create(answer_box), run_time=1.0)\n self.wait(9.0) # Total 15s segment\n \n # --- SECTION 6: REINFORCEMENT / BRIDGE (80-90s) ---\n self.play(\n FadeOut(answer_text),\n FadeOut(answer_box),\n run_time=1.0\n )\n \n # Create a visual bridge metaphor\n # Left side: Abstract (Cloud)\n abstract_label = Text(\"Abstract Strategy\", font_size=24, color=BLUE_ACCENT).to_edge(LEFT, buff=1.5).shift(UP)\n cloud = Cloud(color=BLUE_ACCENT, fill_opacity=0.2).scale(0.8).next_to(abstract_label, DOWN)\n \n # Right side: Concrete (Cube/Square)\n concrete_label = Text(\"Concrete Action\", font_size=24, color=ORANGE_ACCENT).to_edge(RIGHT, buff=1.5).shift(UP)\n brick = Square(side_length=1.5, color=ORANGE_ACCENT, fill_opacity=0.2).next_to(concrete_label, DOWN)\n \n # Middle: Bridge (Policies)\n bridge = Rectangle(width=4, height=0.5, color=GREEN_ACCENT, fill_opacity=0.5)\n bridge.move_to(ORIGIN + DOWN*0.5)\n bridge_label = Text(\"POLICY BRIDGE\", font_size=20, color=BLACK).move_to(bridge.get_center())\n \n self.play(\n FadeIn(abstract_label), FadeIn(cloud),\n FadeIn(concrete_label), FadeIn(brick),\n run_time=2.0\n )\n \n self.play(\n GrowFromCenter(bridge),\n FadeIn(bridge_label),\n run_time=2.0\n )\n \n final_arrow = Arrow(cloud.get_right(), brick.get_left(), color=WHITE, buff=0.1).set_stroke(width=2)\n # Ensure arrow goes OVER the bridge visually\n self.bring_to_front(bridge, bridge_label)\n \n self.play(Create(final_arrow), run_time=2.0)\n self.wait(3.0) # Total 10s segment -> Total 90s roughly\n \n # Cleanup\n self.play(FadeOut(Group(*self.mobjects)), run_time=1.0)\n\n# Helper class for the cloud shape since it's not a standard primitive\nclass Cloud(VGroup):\n def __init__(self, color=WHITE, **kwargs):\n super().__init__(**kwargs)\n circles = VGroup()\n centers = [ORIGIN, UP*0.5, UP*0.5+RIGHT*0.5, RIGHT*0.8, RIGHT*0.4+DOWN*0.3, LEFT*0.4+DOWN*0.3, LEFT*0.8, LEFT*0.5+UP*0.5]\n radii = [0.8, 0.6, 0.7, 0.6, 0.7, 0.6, 0.7, 0.6]\n \n for center, radius in zip(centers, radii):\n circles.add(Circle(radius=radius, color=color, fill_opacity=0.5, stroke_opacity=0).move_to(center))\n \n self.add(circles)\n # Merge visually by adding an outline if needed, but simple group of circles works for metaphor\n```", "category": "legacy_api_hallucination", "source": "synthetic_hard_neg:nabin2004/manim-sft-10k"} +{"system": "You are an expert Manim Community Edition (ManimCE v0.19+) Python developer and mathematical animator. Given a user request, first plan the spatial layout, coordinate bounds, timing, and pedagogical flow inside ... tags (when reasoning is helpful), and then output a complete, runnable, self-contained ManimCE Python script using `from manim import *`. Never use deprecated ManimGL (`manimlib`) methods like `ShowCreation`, `TexMobject`, `TextMobject`, or `axes.get_graph`; always use modern ManimCE APIs (`Create`, `MathTex`, `Tex`, `Text`, `axes.plot`) and prevent visual overlap using `.to_edge()`, `.next_to()`, and `FadeOut`.", "prompt": "I'm teaching an undergraduate ML class and need a clean line chart of training and validation loss across epochs. Show two lines, with a clear marker and annotation where validation starts to diverge (overfitting). Add shading for the gap, and a zoomed inset around the overfitting point to inspect the slope, plus a small caption explaining the switch.", "chosen": "```python\nfrom manim import *\n\nclass TrainingValidationLossChart(Scene):\n\n def construct(self):\n title = Text('Training and Validation Loss', font_size=40)\n title.to_edge(UP, buff=0.3)\n axes = Axes(x_range=[0, 10, 1], y_range=[0, 1.0, 0.2], x_length=10, y_length=5, x_axis_config={'include_numbers': True, 'font_size': 20}, y_axis_config={'include_numbers': False}, tips=False)\n axes.center()\n axis_labels = axes.get_axis_labels(x_label='Epoch', y_label='Loss')\n epochs = list(range(11))\n train_loss = [0.9, 0.72, 0.58, 0.48, 0.41, 0.36, 0.33, 0.31, 0.29, 0.28, 0.27]\n val_loss = [0.9, 0.76, 0.64, 0.55, 0.5, 0.48, 0.49, 0.53, 0.58, 0.64, 0.71]\n train_points = [axes.c2p(x, y) for x, y in zip(epochs, train_loss)]\n val_points = [axes.c2p(x, y) for x, y in zip(epochs, val_loss)]\n train_path = VMobject(color=BLUE, stroke_width=3)\n train_path.set_points_as_corners(train_points)\n val_path = VMobject(color=ORANGE, stroke_width=3)\n val_path.set_points_as_corners(val_points)\n train_dots = VGroup(*[Dot(p, color=BLUE, radius=0.04) for p in train_points])\n val_dots = VGroup(*[Dot(p, color=ORANGE, radius=0.04) for p in val_points])\n\n def legend_item(color, label):\n line = Line(ORIGIN, RIGHT * 0.4, color=color, stroke_width=3)\n text = Text(label, font_size=20)\n text.next_to(line, RIGHT, buff=0.15)\n return VGroup(line, text)\n legend = VGroup(legend_item(BLUE, 'Training'), legend_item(ORANGE, 'Validation'))\n legend.arrange(DOWN, aligned_edge=LEFT, buff=0.2)\n legend.to_corner(UR, buff=0.3)\n under_arrow = Arrow(axes.c2p(1.5, 1.05), axes.c2p(1, 0.72), color=RED, buff=0.05)\n under_text = Text('Underfitting', font_size=22, color=RED)\n under_text.next_to(under_arrow.get_start(), UP, buff=0.1)\n good_arrow = Arrow(axes.c2p(5, 0.22), axes.c2p(5, 0.48), color=GREEN, buff=0.05)\n good_text = Text('Good fit', font_size=22, color=GREEN)\n good_text.next_to(good_arrow.get_end(), UP, buff=0.1)\n over_arrow = Arrow(axes.c2p(8.5, 1.05), axes.c2p(8, 0.72), color=RED, buff=0.05)\n over_text = Text('Overfitting', font_size=22, color=RED)\n over_text.next_to(over_arrow.get_start(), UP, buff=0.1)\n stop_line = DashedLine(axes.c2p(5.5, 0), axes.c2p(5.5, 0.95), color=YELLOW)\n stop_label = Text('Optimal stopping', font_size=22, color=YELLOW)\n stop_label.next_to(stop_line.get_end(), RIGHT, buff=0.15)\n self.play(Write(title), run_time=2.0)\n self.play(Create(axes), Write(axis_labels), run_time=2.0)\n self.play(Create(train_path), FadeIn(train_dots), run_time=2.0)\n self.play(Create(val_path), FadeIn(val_dots), run_time=2.0)\n self.play(FadeIn(legend), run_time=2.0)\n self.play(Create(under_arrow), FadeIn(under_text), run_time=2.0)\n self.play(Create(stop_line), FadeIn(stop_label), Create(good_arrow), FadeIn(good_text), run_time=2.0)\n self.play(Create(over_arrow), FadeIn(over_text), run_time=2.0)\n self.wait(2.0)\n```", "rejected": "```python\nfrom manim import *\n\nclass TrainingValidationLossChart(Scene):\n\n def construct(self):\n title = Text('Training and Validation Loss', font_size=40)\n title\n axes = Axes(x_range=[0, 10, 1], y_range=[0, 1.0, 0.2], x_length=10, y_length=5, x_axis_config={'include_numbers': True, 'font_size': 20}, y_axis_config={'include_numbers': False}, tips=False)\n axes.center()\n axis_labels = axes.get_axis_labels(x_label='Epoch', y_label='Loss')\n epochs = list(range(11))\n train_loss = [0.9, 0.72, 0.58, 0.48, 0.41, 0.36, 0.33, 0.31, 0.29, 0.28, 0.27]\n val_loss = [0.9, 0.76, 0.64, 0.55, 0.5, 0.48, 0.49, 0.53, 0.58, 0.64, 0.71]\n train_points = [axes.c2p(x, y) for x, y in zip(epochs, train_loss)]\n val_points = [axes.c2p(x, y) for x, y in zip(epochs, val_loss)]\n train_path = VMobject(color=BLUE, stroke_width=3)\n train_path.set_points_as_corners(train_points)\n val_path = VMobject(color=ORANGE, stroke_width=3)\n val_path.set_points_as_corners(val_points)\n train_dots = VGroup(*[Dot(p, color=BLUE, radius=0.04) for p in train_points])\n val_dots = VGroup(*[Dot(p, color=ORANGE, radius=0.04) for p in val_points])\n\n def legend_item(color, label):\n line = Line(ORIGIN, RIGHT * 0.4, color=color, stroke_width=3)\n text = Text(label, font_size=20)\n text\n return VGroup(line, text)\n legend = VGroup(legend_item(BLUE, 'Training'), legend_item(ORANGE, 'Validation'))\n legend.arrange(DOWN, aligned_edge=LEFT, buff=0.2)\n legend\n under_arrow = Arrow(axes.c2p(1.5, 1.05), axes.c2p(1, 0.72), color=RED, buff=0.05)\n under_text = Text('Underfitting', font_size=22, color=RED)\n under_text.next_to(under_arrow.get_start(), UP, buff=0.1)\n good_arrow = Arrow(axes.c2p(5, 0.22), axes.c2p(5, 0.48), color=GREEN, buff=0.05)\n good_text = Text('Good fit', font_size=22, color=GREEN)\n good_text.next_to(good_arrow.get_end(), UP, buff=0.1)\n over_arrow = Arrow(axes.c2p(8.5, 1.05), axes.c2p(8, 0.72), color=RED, buff=0.05)\n over_text = Text('Overfitting', font_size=22, color=RED)\n over_text.next_to(over_arrow.get_start(), UP, buff=0.1)\n stop_line = DashedLine(axes.c2p(5.5, 0), axes.c2p(5.5, 0.95), color=YELLOW)\n stop_label = Text('Optimal stopping', font_size=22, color=YELLOW)\n stop_label.next_to(stop_line.get_end(), RIGHT, buff=0.15)\n self.play(Write(title), run_time=2.0)\n self.play(Create(axes), Write(axis_labels), run_time=2.0)\n self.play(Create(train_path), FadeIn(train_dots), run_time=2.0)\n self.play(Create(val_path), FadeIn(val_dots), run_time=2.0)\n self.play(FadeIn(legend), run_time=2.0)\n self.play(Create(under_arrow), FadeIn(under_text), run_time=2.0)\n self.play(Create(stop_line), FadeIn(stop_label), Create(good_arrow), FadeIn(good_text), run_time=2.0)\n self.play(Create(over_arrow), FadeIn(over_text), run_time=2.0)\n self.wait(2.0)\n```", "category": "spatial_layout_overlap", "source": "synthetic_hard_neg:nabin2004/AOS-Manim-SFT"} +{"system": "You are an expert Manim Community Edition (ManimCE v0.19+) Python developer and mathematical animator. Given a user request, first plan the spatial layout, coordinate bounds, timing, and pedagogical flow inside ... tags (when reasoning is helpful), and then output a complete, runnable, self-contained ManimCE Python script using `from manim import *`. Never use deprecated ManimGL (`manimlib`) methods like `ShowCreation`, `TexMobject`, `TextMobject`, or `axes.get_graph`; always use modern ManimCE APIs (`Create`, `MathTex`, `Tex`, `Text`, `axes.plot`) and prevent visual overlap using `.to_edge()`, `.next_to()`, and `FadeOut`.", "prompt": "I’m teaching a tensor operations visualization and want to animate a 2D slicing operation. Show a matrix and highlight a specific row and/or column being extracted, then display the resulting slice with its new shape. Include indexing notation visual cues and a quick comparison of before/after shapes. End with a note on practical uses of slicing in data pipelines.", "chosen": "```python\nfrom manim import *\nfrom manim_voiceover import VoiceoverScene\nfrom manim_voiceover.services.gtts import GTTSService\n\nclass MatrixSlicingScene(VoiceoverScene):\n def construct(self):\n # [SETUP]\n # [LAYOUT]\n self.set_speech_service(GTTSService(transcription_model=\"base\"))\n \n # [BEAT 1 | sync: MATRIX]\n with self.voiceover(text=\"In tensor operations, slicing allows us to extract specific parts of a matrix efficiently. Let's start with a standard four by four matrix, A.\") as tracker:\n title = Text(\"Tensor Slicing Operations\", font_size=36, color=BLUE)\n self.fit_in_frame(title)\n title.to_edge(UP)\n \n matrix_data = [[10, 20, 30, 40], [50, 60, 70, 80], [90, 100, 110, 120], [130, 140, 150, 160]]\n A = Matrix(matrix_data, h_buff=0.8, v_buff=0.6).scale(0.7)\n A_label = MathTex(\"A =\").scale(0.9)\n A_group = VGroup(A_label, A).arrange(RIGHT, buff=0.2)\n \n self.wait_until_bookmark(\"MATRIX\")\n self.play(Write(title), Create(A_group), run_time=tracker.duration)\n \n with self.voiceover(text=\"We can extract a specific row, column, or sub-matrix. For example, A bracket one, colon extracts the entire second row, changing the shape from four by four to one by four.\") as tracker:\n row_code = MathTex(\"A[1, :]\").scale(0.9)\n row_code.next_to(A_group, UP, buff=0.5)\n \n rows = A.get_rows()\n row_rect = SurroundingRectangle(rows[1], color=YELLOW, buff=0.1)\n \n row_data = [[50, 60, 70, 80]]\n A_row = Matrix(row_data, h_buff=0.8, v_buff=0.6).scale(0.7)\n A_row.next_to(A_group, RIGHT, buff=1.5)\n arrow = Arrow(A.get_right(), A_row.get_left(), buff=0.2, color=WHITE)\n \n self.wait_until_bookmark(\"SLICE\")\n self.play(Write(row_code), Create(row_rect), run_time=tracker.duration * 0.5)\n self.play(GrowArrow(arrow), Create(A_row), run_time=tracker.duration * 0.5)\n \n with self.voiceover(text=\"Slicing is a fundamental operation in data pipelines, allowing models to process batches, features, or sequences without copying the underlying data.\") as tracker:\n summary = VGroup(\n Text(\"• Extract rows: A[i, :]\", font_size=20, color=GREEN),\n Text(\"• Extract columns: A[:, j]\", font_size=20, color=GREEN),\n Text(\"• Sub-matrices: A[start:end, start:end]\", font_size=20, color=GREEN),\n Text(\"• Memory efficient: avoids data copying\", font_size=20, color=GREEN)\n ).arrange(DOWN, aligned_edge=LEFT, buff=0.3).to_edge(DOWN)\n \n self.wait_until_bookmark(\"SUMMARY\")\n self.play(FadeOut(row_code), FadeOut(row_rect), FadeOut(arrow), FadeOut(A_row))\n self.play(Write(summary), run_time=tracker.duration)\n self.wait(1)\n\n def fit_in_frame(self, mob: Mobject, w_frac: float = 0.9, h_frac: float = 0.9) -> Mobject:\n max_w = config.frame_width * w_frac\n max_h = config.frame_height * h_frac\n if mob.width > max_w:\n mob.width = max_w\n if mob.height > max_h:\n mob.height = max_h\n return mob\n```", "rejected": "```python\nfrom manim import *\nfrom manim_voiceover import VoiceoverScene\nfrom manim_voiceover.services.gtts import GTTSService\n\nclass MatrixSlicingScene(VoiceoverScene):\n def construct(self):\n # [SETUP]\n # [LAYOUT]\n self.set_speech_service(GTTSService(transcription_model=\"base\"))\n \n # [BEAT 1 | sync: MATRIX]\n with self.voiceover(text=\"In tensor operations, slicing allows us to extract specific parts of a matrix efficiently. Let's start with a standard four by four matrix, A.\") as tracker:\n title = Text(\"Tensor Slicing Operations\", font_size=36, color=BLUE)\n self.fit_in_frame(title)\n title.to_edge(UP)\n \n matrix_data = [[10, 20, 30, 40], [50, 60, 70, 80], [90, 100, 110, 120], [130, 140, 150, 160]]\n A = Matrix(matrix_data, h_buff=0.8, v_buff=0.6).scale(0.7)\n A_label = TexMobject(\"A =\").scale(0.9)\n A_group = VGroup(A_label, A).arrange(RIGHT, buff=0.2)\n \n self.wait_until_bookmark(\"MATRIX\")\n self.play(Write(title), ShowCreation(A_group), run_time=tracker.duration)\n \n with self.voiceover(text=\"We can extract a specific row, column, or sub-matrix. For example, A bracket one, colon extracts the entire second row, changing the shape from four by four to one by four.\") as tracker:\n row_code = MathTex(\"A[1, :]\").scale(0.9)\n row_code.next_to(A_group, UP, buff=0.5)\n \n rows = A.get_rows()\n row_rect = SurroundingRectangle(rows[1], color=YELLOW, buff=0.1)\n \n row_data = [[50, 60, 70, 80]]\n A_row = Matrix(row_data, h_buff=0.8, v_buff=0.6).scale(0.7)\n A_row.next_to(A_group, RIGHT, buff=1.5)\n arrow = Arrow(A.get_right(), A_row.get_left(), buff=0.2, color=WHITE)\n \n self.wait_until_bookmark(\"SLICE\")\n self.play(Write(row_code), Create(row_rect), run_time=tracker.duration * 0.5)\n self.play(GrowArrow(arrow), Create(A_row), run_time=tracker.duration * 0.5)\n \n with self.voiceover(text=\"Slicing is a fundamental operation in data pipelines, allowing models to process batches, features, or sequences without copying the underlying data.\") as tracker:\n summary = VGroup(\n Text(\"• Extract rows: A[i, :]\", font_size=20, color=GREEN),\n Text(\"• Extract columns: A[:, j]\", font_size=20, color=GREEN),\n Text(\"• Sub-matrices: A[start:end, start:end]\", font_size=20, color=GREEN),\n Text(\"• Memory efficient: avoids data copying\", font_size=20, color=GREEN)\n ).arrange(DOWN, aligned_edge=LEFT, buff=0.3).to_edge(DOWN)\n \n self.wait_until_bookmark(\"SUMMARY\")\n self.play(FadeOut(row_code), FadeOut(row_rect), FadeOut(arrow), FadeOut(A_row))\n self.play(Write(summary), run_time=tracker.duration)\n self.wait(1)\n\n def fit_in_frame(self, mob: Mobject, w_frac: float = 0.9, h_frac: float = 0.9) -> Mobject:\n max_w = config.frame_width * w_frac\n max_h = config.frame_height * h_frac\n if mob.width > max_w:\n mob.width = max_w\n if mob.height > max_h:\n mob.height = max_h\n return mob\n```", "category": "legacy_api_hallucination", "source": "synthetic_hard_neg:nabin2004/qwen3-8b-manimator-gold-sft"} +{"system": "You are an expert Manim Community Edition (ManimCE v0.19+) Python developer and mathematical animator. Given a user request, first plan the spatial layout, coordinate bounds, timing, and pedagogical flow inside ... tags (when reasoning is helpful), and then output a complete, runnable, self-contained ManimCE Python script using `from manim import *`. Never use deprecated ManimGL (`manimlib`) methods like `ShowCreation`, `TexMobject`, `TextMobject`, or `axes.get_graph`; always use modern ManimCE APIs (`Create`, `MathTex`, `Tex`, `Text`, `axes.plot`) and prevent visual overlap using `.to_edge()`, `.next_to()`, and `FadeOut`.", "prompt": "Explain the spectral theorem for real symmetric matrices with visual intuition.\nVisualize 2D and 3D transformations: show a unit circle mapped to an ellipse along eigen-directions, then decompose A = Q Λ Q^T and animate alignment with eigenvectors.\nAdd a slider to vary A's entries, display eigenvalues/eigenvectors, and demonstrate A^k converging to the dominant eigenvector.\nTarget undergraduate students; balance intuition and rigor with multiple scenes, 3D axes, color coding, and smooth transitions.", "chosen": "```python\nfrom manim import *\nfrom manim_voiceover import VoiceoverScene\nfrom manim_voiceover.services.gtts import GTTSService\nimport numpy as np\n\nclass SpectralTheorem(VoiceoverScene):\n def construct(self):\n # [SETUP]\n # [LAYOUT]\n self.set_speech_service(GTTSService(transcription_model=\"base\"))\n \n # [BEAT 1 | sync: THEOREM]\n with self.voiceover(text=\"The Spectral Theorem states that every real symmetric matrix can be diagonalized by an orthogonal matrix. This means we can decompose A into P D P transpose, where P contains the orthogonal eigenvectors.\") as tracker:\n self.wait_until_bookmark(\"THEOREM\")\n title = Text(\"The Spectral Theorem\", font_size=36)\n self.fit_in_frame(title)\n title.to_edge(UP)\n eq = MathTex(\"A = P D P^T\", font_size=48)\n eq.next_to(title, DOWN)\n self.play(Write(title), Write(eq), run_time=tracker.duration)\n \n with self.voiceover(text=\"Geometrically, this means the transformation stretches space along the orthogonal eigen-directions. If we repeatedly apply the matrix, any vector will eventually align with the dominant eigenvector, corresponding to the largest eigenvalue.\") as tracker:\n self.wait_until_bookmark(\"CONVERGE\")\n plane = NumberPlane()\n self.add(plane)\n \n v = Arrow(ORIGIN, [1, 1, 0], color=GREEN, stroke_width=5)\n self.add(v)\n \n A = np.array([[2, 1], [1, 2]])\n for _ in range(5):\n self.play(ApplyMatrix(A, v), run_time=0.5)\n self.wait(max(0.1, tracker.duration - 2.5))\n\n def fit_in_frame(self, mob: Mobject, w_frac: float = 0.9, h_frac: float = 0.9) -> Mobject:\n max_w = config.frame_width * w_frac\n max_h = config.frame_height * h_frac\n if mob.width > max_w:\n mob.width = max_w\n if mob.height > max_h:\n mob.height = max_h\n return mob\n```", "rejected": "```python\nfrom manim import *\nfrom manim_voiceover import VoiceoverScene\nfrom manim_voiceover.services.gtts import GTTSService\nimport numpy as np\n\nclass SpectralTheorem(VoiceoverScene):\n def construct(self):\n # [SETUP]\n # [LAYOUT]\n self.set_speech_service(GTTSService(transcription_model=\"base\"))\n \n # [BEAT 1 | sync: THEOREM]\n with self.voiceover(text=\"The Spectral Theorem states that every real symmetric matrix can be diagonalized by an orthogonal matrix. This means we can decompose A into P D P transpose, where P contains the orthogonal eigenvectors.\") as tracker:\n self.wait_until_bookmark(\"THEOREM\")\n title = Text(\"The Spectral Theorem\", font_size=36)\n self.fit_in_frame(title)\n title.to_edge(UP)\n eq = TexMobject(\"A = P D P^T\", font_size=48)\n eq.next_to(title, DOWN)\n self.play(Write(title), Write(eq), run_time=tracker.duration)\n \n with self.voiceover(text=\"Geometrically, this means the transformation stretches space along the orthogonal eigen-directions. If we repeatedly apply the matrix, any vector will eventually align with the dominant eigenvector, corresponding to the largest eigenvalue.\") as tracker:\n self.wait_until_bookmark(\"CONVERGE\")\n plane = NumberPlane()\n self.add(plane)\n \n v = Arrow(ORIGIN, [1, 1, 0], color=GREEN, stroke_width=5)\n self.add(v)\n \n A = np.array([[2, 1], [1, 2]])\n for _ in range(5):\n self.play(ApplyMatrix(A, v), run_time=0.5)\n self.wait(max(0.1, tracker.duration - 2.5))\n\n def fit_in_frame(self, mob: Mobject, w_frac: float = 0.9, h_frac: float = 0.9) -> Mobject:\n max_w = config.frame_width * w_frac\n max_h = config.frame_height * h_frac\n if mob.width > max_w:\n mob.width = max_w\n if mob.height > max_h:\n mob.height = max_h\n return mob\n```", "category": "legacy_api_hallucination", "source": "synthetic_hard_neg:nabin2004/qwen3-8b-manimator-gold-sft"} +{"system": "You are an expert Manim Community Edition (ManimCE v0.19+) Python developer and mathematical animator. Given a user request, first plan the spatial layout, coordinate bounds, timing, and pedagogical flow inside ... tags (when reasoning is helpful), and then output a complete, runnable, self-contained ManimCE Python script using `from manim import *`. Never use deprecated ManimGL (`manimlib`) methods like `ShowCreation`, `TexMobject`, `TextMobject`, or `axes.get_graph`; always use modern ManimCE APIs (`Create`, `MathTex`, `Tex`, `Text`, `axes.plot`) and prevent visual overlap using `.to_edge()`, `.next_to()`, and `FadeOut`.", "prompt": "I’m teaching an undergrad ML course and want a side-by-side animation of optimization on a saddle point.\nShow SGD oscillating along the saddle and Adam progressively escaping, with velocity vectors and learning-rate indicators.\nUse a 2D surface, plot the trajectories, and annotate which terms drive the escape in Adam.\nConclude with a crisp intuition about when adaptive methods help and when they may not.", "chosen": "```python\nfrom manim import *\nfrom manim_voiceover import VoiceoverScene\nfrom manim_voiceover.services.gtts import GTTSService\n\nclass SaddlePointScene(VoiceoverScene):\n def construct(self):\n self.set_speech_service(\n GTTSService(voice=\"alba\", cache_dir=\"voiceover_cache\")\n )\n \n # ===== INTRODUCTION =====\n with self.voiceover(text=\"Imagine you're at a mountain range with peaks and valleys. But what if I told you there are points called saddle points that can lead you to the best solutions in optimization problems?\") as tracker:\n title = Text(\"Optimization on Saddle Points\", font_size=40, color=BLUE)\n title.to_edge(UP, buff=0.5)\n self.play(Write(title), run_time=tracker.duration)\n \n self.wait(0.5)\n \n # ===== WHAT IS A SADDLE POINT =====\n with self.voiceover(text=\"A saddle point is a special point on a surface that is neither a local minimum nor a local maximum, but rather a minimum along one direction and a maximum along another.\") as tracker:\n self.play(title.animate.scale(0.6).to_corner(UL, buff=0.3), run_time=1)\n \n # Create contour representation of saddle function: f(x,y) = x² - y²\n axes = Axes(\n x_range=[-3, 3, 1],\n y_range=[-3, 3, 1],\n x_length=6,\n y_length=6,\n axis_config={\"include_tip\": False, \"include_numbers\": False},\n )\n axes.shift(LEFT * 2)\n \n # Add labels\n x_label = MathTex(\"x\").next_to(axes.x_axis, RIGHT)\n y_label = MathTex(\"y\").next_to(axes.y_axis, UP)\n \n self.play(Create(axes), Write(x_label), Write(y_label), run_time=tracker.duration * 0.7)\n \n # Draw contour lines for f(x,y) = x² - y²\n with self.voiceover(text=\"Mathematically, a common saddle function is f of x comma y equals x squared minus y squared.\") as tracker:\n func_label = MathTex(r\"f(x,y) = x^2 - y^2\", font_size=28)\n func_label.to_corner(UR, buff=0.5)\n self.play(Write(func_label), run_time=tracker.duration * 0.5)\n \n # Draw hyperbolic contour lines\n contours = VGroup()\n for c in [-2, -1, -0.5, 0.5, 1, 2]:\n if abs(c) < 0.1:\n continue\n # x² - y² = c => y = ±sqrt(x² - c)\n points = []\n if c > 0:\n for x in np.linspace(-3, -np.sqrt(c)+0.01, 20):\n y = np.sqrt(x**2 - c)\n points.append(axes.c2p(x, y))\n curve1 = VMobject()\n curve1.set_points_as_corners(points)\n curve1.set_stroke(color=BLUE, width=2, opacity=0.7)\n \n points2 = []\n for x in np.linspace(np.sqrt(c)+0.01, 3, 20):\n y = np.sqrt(x**2 - c)\n points2.append(axes.c2p(x, y))\n curve2 = VMobject()\n curve2.set_points_as_corners(points2)\n curve2.set_stroke(color=BLUE, width=2, opacity=0.7)\n \n points3 = []\n for x in np.linspace(-3, -np.sqrt(c)+0.01, 20):\n y = -np.sqrt(x**2 - c)\n points3.append(axes.c2p(x, y))\n curve3 = VMobject()\n curve3.set_points_as_corners(points3)\n curve3.set_stroke(color=BLUE, width=2, opacity=0.7)\n \n points4 = []\n for x in np.linspace(np.sqrt(c)+0.01, 3, 20):\n y = -np.sqrt(x**2 - c)\n points4.append(axes.c2p(x, y))\n curve4 = VMobject()\n curve4.set_points_as_corners(points4)\n curve4.set_stroke(color=BLUE, width=2, opacity=0.7)\n \n contours.add(curve1, curve2, curve3, curve4)\n else:\n # For negative c, vertical hyperbolas\n for y_val in [-2, 2]:\n points = []\n for y in np.linspace(-2.5, 2.5, 30):\n if y**2 + c >= 0:\n x = np.sqrt(y**2 + c)\n points.append(axes.c2p(x, y))\n if len(points) > 1:\n curve = VMobject()\n curve.set_points_as_corners(points)\n curve.set_stroke(color=GREEN, width=2, opacity=0.7)\n contours.add(curve)\n \n points2 = []\n for y in np.linspace(-2.5, 2.5, 30):\n if y**2 + c >= 0:\n x = -np.sqrt(y**2 + c)\n points2.append(axes.c2p(x, y))\n if len(points2) > 1:\n curve2 = VMobject()\n curve2.set_points_as_corners(points2)\n curve2.set_stroke(color=GREEN, width=2, opacity=0.7)\n contours.add(curve2)\n \n # Add diagonal lines for zero contour\n diag1 = Line(axes.c2p(-2.5, -2.5), axes.c2p(2.5, 2.5), color=YELLOW, stroke_width=3)\n diag2 = Line(axes.c2p(-2.5, 2.5), axes.c2p(2.5, -2.5), color=YELLOW, stroke_width=3)\n \n self.play(Create(diag1), Create(diag2), run_time=tracker.duration * 0.3)\n self.play(*[Create(c) for c in contours], run_time=tracker.duration * 0.2)\n \n # Mark the saddle point\n with self.voiceover(text=\"At the origin, we have our saddle point. Along the x direction, it's a minimum. But along the y direction, it's a maximum.\") as tracker:\n saddle_dot = Dot(axes.c2p(0, 0), color=RED, radius=0.12)\n saddle_label = MathTex(r\"(0,0)\", font_size=24, color=RED)\n saddle_label.next_to(saddle_dot, UR, buff=0.1)\n \n self.play(Create(saddle_dot), Write(saddle_label), run_time=tracker.duration * 0.5)\n \n # Add arrows showing directions\n arrow_x1 = Arrow(axes.c2p(-1.5, 0), axes.c2p(-0.2, 0), buff=0.1, color=GREEN)\n arrow_x2 = Arrow(axes.c2p(1.5, 0), axes.c2p(0.2, 0), buff=0.1, color=GREEN)\n arrow_y1 = Arrow(axes.c2p(0, -1.5), axes.c2p(0, -0.2), buff=0.1, color=ORANGE)\n arrow_y2 = Arrow(axes.c2p(0, 1.5), axes.c2p(0, 0.2), buff=0.1, color=ORANGE)\n \n self.play(\n Create(arrow_x1), Create(arrow_x2),\n Create(arrow_y1), Create(arrow_y2),\n run_time=tracker.duration * 0.5\n )\n \n # ===== IDENTIFYING SADDLE POINTS =====\n with self.voiceover(text=\"How do we identify a saddle point mathematically? We use the gradient and the Hessian matrix.\") as tracker:\n self.play(\n FadeOut(diag1), FadeOut(diag2), FadeOut(contours),\n FadeOut(arrow_x1), FadeOut(arrow_x2), FadeOut(arrow_y1), FadeOut(arrow_y2),\n FadeOut(saddle_label), FadeOut(saddle_dot),\n run_time=0.5\n )\n \n # Gradient explanation - fixed string\n grad_text = MathTex(r\"\\nabla f = \\begin{bmatrix} 2x \\\\ -2y \\end{bmatrix}\", font_size=28)\n grad_text.next_to(axes, RIGHT, buff=1)\n \n self.play(Write(grad_text), run_time=tracker.duration * 0.5)\n \n with self.voiceover(text=\"At the saddle point, the gradient equals zero. This is also true for minima and maxima, so we need more information.\") as tracker:\n grad_zero = MathTex(r\"\\nabla f = \\mathbf{0} \\text{ at } (0,0)\", font_size=26)\n grad_zero.next_to(grad_text, DOWN, buff=0.3)\n \n self.play(Write(grad_zero), run_time=tracker.duration * 0.6)\n \n # Show gradient arrows at various points\n grad_arrows = VGroup()\n for x in [-2, -1, 1, 2]:\n for y in [-2, -1, 1, 2]:\n start = axes.c2p(x, y)\n # Gradient is (2x, -2y)\n end = axes.c2p(x + 0.3 * x, y - 0.3 * y)\n if np.abs(x) > 0.5 or np.abs(y) > 0.5:\n arrow = Arrow(start, end, buff=0.05, color=BLUE, stroke_width=2)\n grad_arrows.add(arrow)\n \n self.play(*[Create(a) for a in grad_arrows], run_time=tracker.duration * 0.4)\n \n # Hessian explanation\n with self.voiceover(text=\"The Hessian matrix tells us the curvature. For our function, it has one positive and one negative eigenvalue at the saddle point.\") as tracker:\n self.play(FadeOut(grad_arrows), FadeOut(func_label), run_time=0.3)\n \n hessian = MathTex(r\"H = \\begin{bmatrix} 2 & 0 \\\\ 0 & -2 \\end{bmatrix}\", font_size=28)\n hessian.next_to(grad_zero, DOWN, buff=0.4)\n \n eigen = MathTex(r\"\\lambda_1 = 2, \\lambda_2 = -2\", font_size=26, color=YELLOW)\n eigen.next_to(hessian, DOWN, buff=0.3)\n \n self.play(Write(hessian), run_time=tracker.duration * 0.5)\n self.play(Write(eigen), run_time=tracker.duration * 0.5)\n \n with self.voiceover(text=\"When eigenvalues have opposite signs, we have a saddle point. This is the key test.\") as tracker:\n test_box = SurroundingRectangle(VGroup(hessian, eigen), buff=0.2, color=YELLOW)\n self.play(Create(test_box), run_time=tracker.duration * 0.6)\n self.wait(tracker.duration * 0.4)\n \n # ===== IMPLICATIONS IN MACHINE LEARNING =====\n with self.voiceover(text=\"In machine learning, saddle points are common in high-dimensional loss landscapes. They can trap optimization algorithms.\") as tracker:\n self.play(\n FadeOut(axes), FadeOut(x_label), FadeOut(y_label),\n FadeOut(grad_text), FadeOut(grad_zero), FadeOut(hessian), \n FadeOut(eigen), FadeOut(test_box),\n run_time=0.5\n )\n \n # Create loss landscape visualization\n loss_title = Text(\"Loss Landscape in Neural Networks\", font_size=30, color=BLUE)\n loss_title.to_edge(UP, buff=0.5)\n \n # Simple 2D representation of optimization path\n opt_axes = Axes(\n x_range=[-3, 3, 1],\n y_range=[-2, 2, 1],\n x_length=8,\n y_length=4,\n axis_config={\"include_tip\": False},\n )\n \n self.play(Write(loss_title), Create(opt_axes), run_time=tracker.duration * 0.6)\n \n with self.voiceover(text=\"Gradient descent might get stuck or slow down significantly near saddle points, because the gradient becomes very small.\") as tracker:\n # Draw optimization path that slows near saddle\n path_points = []\n t_vals = np.linspace(-2.5, 2.5, 100)\n for t in t_vals:\n # Path that goes through a saddle-like region\n x = t\n y = 0.5 * np.sin(2 * t) * np.exp(-t**2/4)\n path_points.append(opt_axes.c2p(x, y))\n \n path = VMobject()\n path.set_points_as_corners(path_points)\n path.set_stroke(color=GREEN, width=3)\n \n # Moving dot\n tracker_dot = Dot(path_points[0], color=RED, radius=0.1)\n \n self.play(Create(path), run_time=tracker.duration * 0.4)\n \n # Animate dot moving along path with varying speed\n for i in range(1, len(path_points), 3):\n alpha = i / len(path_points)\n # Slow down near center (saddle point)\n if 0.4 < alpha < 0.6:\n speed_factor = 0.3\n else:\n speed_factor = 1.0\n self.play(tracker_dot.animate.move_to(path_points[i]), run_time=0.03/speed_factor)\n \n with self.voiceover(text=\"To escape saddle points, we use techniques like momentum, which helps the optimizer push through flat regions.\") as tracker:\n # Show momentum arrows\n momentum_arrows = VGroup()\n for i in [20, 40, 60, 80]:\n if i < len(path_points) - 5:\n direction = path_points[i+5] - path_points[i]\n arrow = Arrow(path_points[i], path_points[i] + direction*2, \n buff=0.05, color=ORANGE, stroke_width=2)\n momentum_arrows.add(arrow)\n \n momentum_label = Text(\"Momentum\", font_size=24, color=ORANGE)\n momentum_label.to_corner(DR, buff=0.5)\n \n self.play(*[Create(a) for a in momentum_arrows], Write(momentum_label), run_time=tracker.duration * 0.7)\n \n # ===== SUMMARY =====\n with self.voiceover(text=\"To summarize: Saddle points are critical points with mixed curvature. They can be identified by the Hessian having both positive and negative eigenvalues. And in machine learning, escaping them is crucial for finding good solutions.\") as tracker:\n self.play(\n FadeOut(opt_axes), FadeOut(path), FadeOut(tracker_dot),\n FadeOut(momentum_arrows), FadeOut(momentum_label),\n FadeOut(loss_title),\n run_time=0.5\n )\n \n # Create summary boxes in two columns\n col1 = VGroup()\n col2 = VGroup()\n \n # Left column - identification\n id_title = Text(\"Identification\", font_size=26, color=BLUE, weight=BOLD)\n id_bullet1 = Text(\"• Gradient = 0\", font_size=22)\n id_bullet2 = Text(\"• Hessian eigenvalues\", font_size=22)\n id_bullet3 = Text(\" have opposite signs\", font_size=22)\n id_group = VGroup(id_title, id_bullet1, id_bullet2, id_bullet3)\n id_group.arrange(DOWN, aligned_edge=LEFT, buff=0.2)\n \n # Right column - implications\n impl_title = Text(\"ML Implications\", font_size=26, color=GREEN, weight=BOLD)\n impl_bullet1 = Text(\"• Common in high-D\", font_size=22)\n impl_bullet2 = Text(\"• Can trap optimizers\", font_size=22)\n impl_bullet3 = Text(\"• Use momentum to escape\", font_size=22)\n impl_group = VGroup(impl_title, impl_bullet1, impl_bullet2, impl_bullet3)\n impl_group.arrange(DOWN, aligned_edge=LEFT, buff=0.2)\n \n col1.add(id_group)\n col2.add(impl_group)\n \n columns = VGroup(col1, col2)\n columns.arrange(RIGHT, buff=1.5)\n columns.center()\n columns.shift(UP * 0.5)\n \n # Formula at bottom\n formula = MathTex(r\"f(x,y) = x^2 - y^2 \\text{ at } (0,0)\", font_size=28)\n formula.to_edge(DOWN, buff=1)\n \n self.play(\n Write(id_title), Write(impl_title),\n run_time=tracker.duration * 0.3\n )\n self.play(\n Write(id_bullet1), Write(id_bullet2), Write(id_bullet3),\n Write(impl_bullet1), Write(impl_bullet2), Write(impl_bullet3),\n run_time=tracker.duration * 0.4\n )\n self.play(Write(formula), run_time=tracker.duration * 0.3)\n \n # Final takeaway box\n with self.voiceover(text=\"Understanding saddle points helps us design better optimization algorithms for training AI models.\") as tracker:\n takeaway = Text(\"Key Takeaway: Saddle points are not local minima!\", \n font_size=28, color=YELLOW, weight=BOLD)\n takeaway.move_to(ORIGIN)\n takeaway_box = SurroundingRectangle(takeaway, buff=0.3, color=YELLOW, stroke_width=3)\n \n self.play(\n FadeOut(columns), FadeOut(formula),\n run_time=0.3\n )\n self.play(\n Write(takeaway), Create(takeaway_box),\n run_time=tracker.duration * 0.7\n )\n \n self.wait(1)\n```", "rejected": "```python\nfrom manim import *\n\nclass SaddlePointScene(Scene):\n\n def construct(self):\n title = Text('Optimization on Saddle Points', font_size=40, color=BLUE)\n title.to_edge(UP, buff=0.5)\n self.play(Write(title), run_time=2.0)\n self.wait(0.5)\n self.play(title.animate.scale(0.6).to_corner(UL, buff=0.3), run_time=1)\n axes = Axes(x_range=[-3, 3, 1], y_range=[-3, 3, 1], x_length=6, y_length=6, axis_config={'include_tip': False, 'include_numbers': False})\n axes.shift(LEFT * 2)\n x_label = MathTex('x').next_to(axes.x_axis, RIGHT)\n y_label = MathTex('y').next_to(axes.y_axis, UP)\n self.play(Create(axes), Write(x_label), Write(y_label), run_time=2.0 * 0.7)\n func_label = MathTex('f(x,y) = x^2 - y^2', font_size=28)\n func_label.to_corner(UR, buff=0.5)\n self.play(Write(func_label), run_time=2.0 * 0.5)\n contours = VGroup()\n for c in [-2, -1, -0.5, 0.5, 1, 2]:\n if abs(c) < 0.1:\n continue\n points = []\n if c > 0:\n for x in np.linspace(-3, -np.sqrt(c) + 0.01, 20):\n y = np.sqrt(x ** 2 - c)\n points.append(axes.c2p(x, y))\n curve1 = VMobject()\n curve1.set_points_as_corners(points)\n curve1.set_stroke(color=BLUE, width=2, opacity=0.7)\n points2 = []\n for x in np.linspace(np.sqrt(c) + 0.01, 3, 20):\n y = np.sqrt(x ** 2 - c)\n points2.append(axes.c2p(x, y))\n curve2 = VMobject()\n curve2.set_points_as_corners(points2)\n curve2.set_stroke(color=BLUE, width=2, opacity=0.7)\n points3 = []\n for x in np.linspace(-3, -np.sqrt(c) + 0.01, 20):\n y = -np.sqrt(x ** 2 - c)\n points3.append(axes.c2p(x, y))\n curve3 = VMobject()\n curve3.set_points_as_corners(points3)\n curve3.set_stroke(color=BLUE, width=2, opacity=0.7)\n points4 = []\n for x in np.linspace(np.sqrt(c) + 0.01, 3, 20):\n y = -np.sqrt(x ** 2 - c)\n points4.append(axes.c2p(x, y))\n curve4 = VMobject()\n curve4.set_points_as_corners(points4)\n curve4.set_stroke(color=BLUE, width=2, opacity=0.7)\n contours.add(curve1, curve2, curve3, curve4)\n else:\n for y_val in [-2, 2]:\n points = []\n for y in np.linspace(-2.5, 2.5, 30):\n if y ** 2 + c >= 0:\n x = np.sqrt(y ** 2 + c)\n points.append(axes.c2p(x, y))\n if len(points) > 1:\n curve = VMobject()\n curve.set_points_as_corners(points)\n curve.set_stroke(color=GREEN, width=2, opacity=0.7)\n contours.add(curve)\n points2 = []\n for y in np.linspace(-2.5, 2.5, 30):\n if y ** 2 + c >= 0:\n x = -np.sqrt(y ** 2 + c)\n points2.append(axes.c2p(x, y))\n if len(points2) > 1:\n curve2 = VMobject()\n curve2.set_points_as_corners(points2)\n curve2.set_stroke(color=GREEN, width=2, opacity=0.7)\n contours.add(curve2)\n diag1 = Line(axes.c2p(-2.5, -2.5), axes.c2p(2.5, 2.5), color=YELLOW, stroke_width=3)\n diag2 = Line(axes.c2p(-2.5, 2.5), axes.c2p(2.5, -2.5), color=YELLOW, stroke_width=3)\n self.play(Create(diag1), Create(diag2), run_time=2.0 * 0.3)\n self.play(*[Create(c) for c in contours], run_time=2.0 * 0.2)\n saddle_dot = Dot(axes.c2p(0, 0), color=RED, radius=0.12)\n saddle_label = MathTex('(0,0)', font_size=24, color=RED)\n saddle_label.next_to(saddle_dot, UR, buff=0.1)\n self.play(Create(saddle_dot), Write(saddle_label), run_time=2.0 * 0.5)\n arrow_x1 = Arrow(axes.c2p(-1.5, 0), axes.c2p(-0.2, 0), buff=0.1, color=GREEN)\n arrow_x2 = Arrow(axes.c2p(1.5, 0), axes.c2p(0.2, 0), buff=0.1, color=GREEN)\n arrow_y1 = Arrow(axes.c2p(0, -1.5), axes.c2p(0, -0.2), buff=0.1, color=ORANGE)\n arrow_y2 = Arrow(axes.c2p(0, 1.5), axes.c2p(0, 0.2), buff=0.1, color=ORANGE)\n self.play(Create(arrow_x1), Create(arrow_x2), Create(arrow_y1), Create(arrow_y2), run_time=2.0 * 0.5)\n self.play(FadeOut(diag1), FadeOut(diag2), FadeOut(contours), FadeOut(arrow_x1), FadeOut(arrow_x2), FadeOut(arrow_y1), FadeOut(arrow_y2), FadeOut(saddle_label), FadeOut(saddle_dot), run_time=0.5)\n grad_text = MathTex('\\\\nabla f = \\\\begin{bmatrix} 2x \\\\\\\\ -2y \\\\end{bmatrix}', font_size=28)\n grad_text.next_to(axes, RIGHT, buff=1)\n self.play(Write(grad_text), run_time=2.0 * 0.5)\n grad_zero = MathTex('\\\\nabla f = \\\\mathbf{0} \\\\text{ at } (0,0)', font_size=26)\n grad_zero.next_to(grad_text, DOWN, buff=0.3)\n self.play(Write(grad_zero), run_time=2.0 * 0.6)\n grad_arrows = VGroup()\n for x in [-2, -1, 1, 2]:\n for y in [-2, -1, 1, 2]:\n start = axes.c2p(x, y)\n end = axes.c2p(x + 0.3 * x, y - 0.3 * y)\n if np.abs(x) > 0.5 or np.abs(y) > 0.5:\n arrow = Arrow(start, end, buff=0.05, color=BLUE, stroke_width=2)\n grad_arrows.add(arrow)\n self.play(*[Create(a) for a in grad_arrows], run_time=2.0 * 0.4)\n self.play(FadeOut(grad_arrows), FadeOut(func_label), run_time=0.3)\n hessian = MathTex('H = \\\\begin{bmatrix} 2 & 0 \\\\\\\\ 0 & -2 \\\\end{bmatrix}', font_size=28)\n hessian.next_to(grad_zero, DOWN, buff=0.4)\n eigen = MathTex('\\\\lambda_1 = 2, \\\\lambda_2 = -2', font_size=26, color=YELLOW)\n eigen.next_to(hessian, DOWN, buff=0.3)\n self.play(Write(hessian), run_time=2.0 * 0.5)\n self.play(Write(eigen), run_time=2.0 * 0.5)\n test_box = SurroundingRectangle(VGroup(hessian, eigen), buff=0.2, color=YELLOW)\n self.play(Create(test_box), run_time=2.0 * 0.6)\n self.wait(2.0 * 0.4)\n self.play(FadeOut(axes), FadeOut(x_label), FadeOut(y_label), FadeOut(grad_text), FadeOut(grad_zero), FadeOut(hessian), FadeOut(eigen), FadeOut(test_box), run_time=0.5)\n loss_title = Text('Loss Landscape in Neural Networks', font_size=30, color=BLUE)\n loss_title.to_edge(UP, buff=0.5)\n opt_axes = Axes(x_range=[-3, 3, 1], y_range=[-2, 2, 1], x_length=8, y_length=4, axis_config={'include_tip': False})\n self.play(Write(loss_title), Create(opt_axes), run_time=2.0 * 0.6)\n path_points = []\n t_vals = np.linspace(-2.5, 2.5, 100)\n for t in t_vals:\n x = t\n y = 0.5 * np.sin(2 * t) * np.exp(-t ** 2 / 4)\n path_points.append(opt_axes.c2p(x, y))\n path = VMobject()\n path.set_points_as_corners(path_points)\n path.set_stroke(color=GREEN, width=3)\n tracker_dot = Dot(path_points[0], color=RED, radius=0.1)\n self.play(Create(path), run_time=2.0 * 0.4)\n for i in range(1, len(path_points), 3):\n alpha = i / len(path_points)\n if 0.4 < alpha < 0.6:\n speed_factor = 0.3\n else:\n speed_factor = 1.0\n self.play(tracker_dot.animate.move_to(path_points[i]), run_time=0.03 / speed_factor)\n momentum_arrows = VGroup()\n for i in [20, 40, 60, 80]:\n if i < len(path_points) - 5:\n direction = path_points[i + 5] - path_points[i]\n arrow = Arrow(path_points[i], path_points[i] + direction * 2, buff=0.05, color=ORANGE, stroke_width=2)\n momentum_arrows.add(arrow)\n momentum_label = Text('Momentum', font_size=24, color=ORANGE)\n momentum_label.to_corner(DR, buff=0.5)\n self.play(*[Create(a) for a in momentum_arrows], Write(momentum_label), run_time=2.0 * 0.7)\n self.play(FadeOut(opt_axes), FadeOut(path), FadeOut(tracker_dot), FadeOut(momentum_arrows), FadeOut(momentum_label), FadeOut(loss_title), run_time=0.5)\n col1 = VGroup()\n col2 = VGroup()\n id_title = Text('Identification', font_size=26, color=BLUE, weight=BOLD)\n id_bullet1 = Text('• Gradient = 0', font_size=22)\n id_bullet2 = Text('• Hessian eigenvalues', font_size=22)\n id_bullet3 = Text(' have opposite signs', font_size=22)\n id_group = VGroup(id_title, id_bullet1, id_bullet2, id_bullet3)\n id_group.arrange(DOWN, aligned_edge=LEFT, buff=0.2)\n impl_title = Text('ML Implications', font_size=26, color=GREEN, weight=BOLD)\n impl_bullet1 = Text('• Common in high-D', font_size=22)\n impl_bullet2 = Text('• Can trap optimizers', font_size=22)\n impl_bullet3 = Text('• Use momentum to escape', font_size=22)\n impl_group = VGroup(impl_title, impl_bullet1, impl_bullet2, impl_bullet3)\n impl_group.arrange(DOWN, aligned_edge=LEFT, buff=0.2)\n col1.add(id_group)\n col2.add(impl_group)\n columns = VGroup(col1, col2)\n columns.arrange(RIGHT, buff=1.5)\n columns.center()\n columns.shift(UP * 0.5)\n formula = MathTex('f(x,y) = x^2 - y^2 \\\\text{ at } (0,0)', font_size=28)\n formula.to_edge(DOWN, buff=1)\n self.play(Write(id_title), Write(impl_title), run_time=2.0 * 0.3)\n self.play(Write(id_bullet1), Write(id_bullet2), Write(id_bullet3), Write(impl_bullet1), Write(impl_bullet2), Write(impl_bullet3), run_time=2.0 * 0.4)\n self.play(Write(formula), run_time=2.0 * 0.3)\n takeaway = Text('Key Takeaway: Saddle points are not local minima!', font_size=28, color=YELLOW, weight=BOLD)\n takeaway.move_to(ORIGIN)\n takeaway_box = SurroundingRectangle(takeaway, buff=0.3, color=YELLOW, stroke_width=3)\n self.play(FadeOut(columns), FadeOut(formula), run_time=0.3)\n self.play(Write(takeaway), Create(takeaway_box), run_time=2.0 * 0.7)\n self.wait(1)\n```", "category": "narrated_pedagogical_preference", "source": "nabin2004/manim-narrated-dpo-400"} +{"system": "You are an expert Manim Community Edition (ManimCE v0.19+) Python developer and mathematical animator. Given a user request, first plan the spatial layout, coordinate bounds, timing, and pedagogical flow inside ... tags (when reasoning is helpful), and then output a complete, runnable, self-contained ManimCE Python script using `from manim import *`. Never use deprecated ManimGL (`manimlib`) methods like `ShowCreation`, `TexMobject`, `TextMobject`, or `axes.get_graph`; always use modern ManimCE APIs (`Create`, `MathTex`, `Tex`, `Text`, `axes.plot`) and prevent visual overlap using `.to_edge()`, `.next_to()`, and `FadeOut`.", "prompt": "I'm learning linear algebra to undergraduates and want a visual that unpacks singular value decomposition.\nShow how a 2D/3D linear map stretches and rotates vectors into principal axes, with animated ellipsoids and a moving camera.\nInclude step-by-step intuition, then derive A = U Σ V^T visually, plus a numeric example with a 3x3 matrix and a dynamic plot of singular values as you tweak A.\nI want multiple scenes: initial grid under transformation, decomposition stage, and a comparison with eigen decomposition for symmetric cases.\nPacing should be moderate; use 3D axes, TracedPath of a chosen vector, and a small interactive prompt asking viewers to guess the effect of changing a singular value.", "chosen": "```python\nfrom manim import *\nfrom manim_voiceover import VoiceoverScene\nfrom manim_voiceover.services.gtts import GTTSService\nimport math\n\nclass SVDGeometricInterpretationScene(VoiceoverScene):\n def construct(self):\n self.set_speech_service(\n GTTSService(voice=\"alba\", cache_dir=\"voiceover_cache\")\n )\n \n # --- INTRO ---\n title = Text(\"Singular Value Decomposition\", font_size=38)\n subtitle = Text(\"Visualizing Matrix Decomposition\", font_size=22, color=BLUE_B)\n header = VGroup(title, subtitle).arrange(DOWN, buff=0.15)\n \n with self.voiceover(\n text=\"Have you ever wondered how we can break down complex matrices into simpler, more interpretable forms? Singular Value Decomposition, or SVD, allows us to do just that! It's a powerful technique that reveals the hidden structure of data and helps us with tasks like dimensionality reduction. Let's dive into this fascinating concept together!\"\n ) as tracker:\n self.play(Write(header), run_time=tracker.duration)\n \n self.wait(0.3)\n \n # --- FORMULA ---\n formula = MathTex(r\"A\", r\"=\", r\"U\", r\"\\Sigma\", r\"V^T\", font_size=38)\n formula.next_to(header, DOWN, buff=0.3)\n \n label_a = Text(\"Data\", font_size=16, color=WHITE).next_to(formula[0], DOWN, buff=0.3)\n label_u = Text(\"Rotate\", font_size=16, color=BLUE).next_to(formula[2], DOWN, buff=0.3)\n label_s = Text(\"Scale\", font_size=16, color=GREEN).next_to(formula[3], DOWN, buff=0.3)\n label_v = Text(\"Rotate\", font_size=16, color=RED).next_to(formula[4], DOWN, buff=0.3)\n labels = VGroup(label_a, label_u, label_s, label_v)\n \n with self.voiceover(\n text=\"At its heart, SVD says any matrix A can be written as U times Sigma times V transpose. U and V transpose are orthogonal matrices that rotate or reflect space, while Sigma is a diagonal matrix that scales along the principal axes.\"\n ) as tracker:\n self.play(FadeOut(subtitle), run_time=0.3)\n self.play(Write(formula), run_time=tracker.duration * 0.55)\n self.play(FadeIn(labels, shift=UP*0.2), run_time=tracker.duration * 0.45)\n \n self.wait(0.3)\n \n # --- GEOMETRY SETUP ---\n c30 = math.sqrt(3) / 2\n s30 = 0.5\n VT = [[c30, -s30], [s30, c30]]\n SIGMA = [[2.0, 0.0], [0.0, 0.5]]\n c45 = math.sqrt(2) / 2\n s45 = math.sqrt(2) / 2\n U = [[c45, -s45], [s45, c45]]\n \n circle = Circle(radius=1.2, color=YELLOW, stroke_width=3)\n center_dot = Dot(color=YELLOW)\n geo_group = VGroup(circle, center_dot)\n \n step1 = Text(\"Step 1: V^T\", font_size=20, color=RED).move_to(RIGHT*3.5 + UP*1.0)\n step2 = Text(\"Step 2: Σ\", font_size=20, color=GREEN).move_to(RIGHT*3.5)\n step3 = Text(\"Step 3: U\", font_size=20, color=BLUE).move_to(RIGHT*3.5 + DOWN*1.0)\n \n note = Text(\"Any matrix A maps the unit circle to an ellipse\", font_size=18, color=GRAY)\n note.to_edge(DOWN, buff=0.25)\n \n with self.voiceover(\n text=\"Now let's see this geometrically. Any matrix maps the unit circle to an ellipse. We begin with a unit circle centered at the origin.\"\n ) as tracker:\n # Compact header/formula to top\n title_small = title.copy().scale(0.7)\n formula_small = formula.copy().scale(0.7)\n labels_small = labels.copy().scale(0.7)\n mini_group = VGroup(title_small, formula_small, labels_small).arrange(DOWN, buff=0.1)\n mini_group.to_edge(UP, buff=0.2)\n \n self.play(\n Transform(title, title_small),\n Transform(formula, formula_small),\n Transform(labels, labels_small),\n run_time=0.4\n )\n self.play(\n Create(circle),\n FadeIn(center_dot),\n run_time=tracker.duration * 0.7\n )\n self.play(Write(note), run_time=tracker.duration * 0.3)\n \n self.wait(0.3)\n \n # --- STEP 1: V^T ---\n with self.voiceover(\n text=\"First, V transpose applies a rotation to the input space.\"\n ) as tracker:\n self.play(\n ApplyMatrix(VT, geo_group),\n FadeIn(step1),\n run_time=tracker.duration\n )\n \n self.wait(0.3)\n \n # --- STEP 2: Sigma ---\n with self.voiceover(\n text=\"Next, Sigma stretches space along the new coordinate axes, turning the circle into an ellipse.\"\n ) as tracker:\n self.play(\n ApplyMatrix(SIGMA, geo_group),\n FadeIn(step2),\n run_time=tracker.duration\n )\n \n self.wait(0.3)\n \n # --- STEP 3: U ---\n with self.voiceover(\n text=\"Finally, U rotates the ellipse to its final orientation. The combined effect is exactly the linear transformation described by the original matrix A.\"\n ) as tracker:\n self.play(\n ApplyMatrix(U, geo_group),\n FadeIn(step3),\n run_time=tracker.duration\n )\n \n self.wait(0.5)\n \n # --- CONCLUSION ---\n conclusion = VGroup(\n Text(\"Key Takeaways\", font_size=24, color=BLUE),\n Text(\"• SVD = Rotate → Scale → Rotate\", font_size=18),\n Text(\"• Reveals principal axes of data\", font_size=18),\n Text(\"• Powers PCA, compression, & denoising\", font_size=18),\n ).arrange(DOWN, aligned_edge=LEFT, buff=0.15)\n conclusion.to_edge(DOWN, buff=0.2).to_edge(RIGHT, buff=0.4)\n \n with self.voiceover(\n text=\"SVD decomposes any matrix into simple geometric actions: rotations and scalings. This reveals the principal axes of your data and powers applications like principal component analysis, image compression, and noise reduction.\"\n ) as tracker:\n self.play(\n FadeOut(note),\n Write(conclusion),\n run_time=tracker.duration\n )\n \n self.wait(1)\n```", "rejected": "```python\nfrom manim import *\nimport math\n\nclass SVDGeometricInterpretationScene(Scene):\n\n def construct(self):\n title = Text('Singular Value Decomposition', font_size=38)\n subtitle = Text('Visualizing Matrix Decomposition', font_size=22, color=BLUE_B)\n header = VGroup(title, subtitle).arrange(DOWN, buff=0.15)\n self.play(Write(header), run_time=2.0)\n self.wait(0.3)\n formula = MathTex('A', '=', 'U', '\\\\Sigma', 'V^T', font_size=38)\n formula.next_to(header, DOWN, buff=0.3)\n label_a = Text('Data', font_size=16, color=WHITE).next_to(formula[0], DOWN, buff=0.3)\n label_u = Text('Rotate', font_size=16, color=BLUE).next_to(formula[2], DOWN, buff=0.3)\n label_s = Text('Scale', font_size=16, color=GREEN).next_to(formula[3], DOWN, buff=0.3)\n label_v = Text('Rotate', font_size=16, color=RED).next_to(formula[4], DOWN, buff=0.3)\n labels = VGroup(label_a, label_u, label_s, label_v)\n self.play(FadeOut(subtitle), run_time=0.3)\n self.play(Write(formula), run_time=2.0 * 0.55)\n self.play(FadeIn(labels, shift=UP * 0.2), run_time=2.0 * 0.45)\n self.wait(0.3)\n c30 = math.sqrt(3) / 2\n s30 = 0.5\n VT = [[c30, -s30], [s30, c30]]\n SIGMA = [[2.0, 0.0], [0.0, 0.5]]\n c45 = math.sqrt(2) / 2\n s45 = math.sqrt(2) / 2\n U = [[c45, -s45], [s45, c45]]\n circle = Circle(radius=1.2, color=YELLOW, stroke_width=3)\n center_dot = Dot(color=YELLOW)\n geo_group = VGroup(circle, center_dot)\n step1 = Text('Step 1: V^T', font_size=20, color=RED).move_to(RIGHT * 3.5 + UP * 1.0)\n step2 = Text('Step 2: Σ', font_size=20, color=GREEN).move_to(RIGHT * 3.5)\n step3 = Text('Step 3: U', font_size=20, color=BLUE).move_to(RIGHT * 3.5 + DOWN * 1.0)\n note = Text('Any matrix A maps the unit circle to an ellipse', font_size=18, color=GRAY)\n note.to_edge(DOWN, buff=0.25)\n title_small = title.copy().scale(0.7)\n formula_small = formula.copy().scale(0.7)\n labels_small = labels.copy().scale(0.7)\n mini_group = VGroup(title_small, formula_small, labels_small).arrange(DOWN, buff=0.1)\n mini_group.to_edge(UP, buff=0.2)\n self.play(Transform(title, title_small), Transform(formula, formula_small), Transform(labels, labels_small), run_time=0.4)\n self.play(Create(circle), FadeIn(center_dot), run_time=2.0 * 0.7)\n self.play(Write(note), run_time=2.0 * 0.3)\n self.wait(0.3)\n self.play(ApplyMatrix(VT, geo_group), FadeIn(step1), run_time=2.0)\n self.wait(0.3)\n self.play(ApplyMatrix(SIGMA, geo_group), FadeIn(step2), run_time=2.0)\n self.wait(0.3)\n self.play(ApplyMatrix(U, geo_group), FadeIn(step3), run_time=2.0)\n self.wait(0.5)\n conclusion = VGroup(Text('Key Takeaways', font_size=24, color=BLUE), Text('• SVD = Rotate → Scale → Rotate', font_size=18), Text('• Reveals principal axes of data', font_size=18), Text('• Powers PCA, compression, & denoising', font_size=18)).arrange(DOWN, aligned_edge=LEFT, buff=0.15)\n conclusion.to_edge(DOWN, buff=0.2).to_edge(RIGHT, buff=0.4)\n self.play(FadeOut(note), Write(conclusion), run_time=2.0)\n self.wait(1)\n```", "category": "narrated_pedagogical_preference", "source": "nabin2004/manim-narrated-dpo-400"} +{"system": "You are an expert Manim Community Edition (ManimCE v0.19+) Python developer and mathematical animator. Given a user request, first plan the spatial layout, coordinate bounds, timing, and pedagogical flow inside ... tags (when reasoning is helpful), and then output a complete, runnable, self-contained ManimCE Python script using `from manim import *`. Never use deprecated ManimGL (`manimlib`) methods like `ShowCreation`, `TexMobject`, `TextMobject`, or `axes.get_graph`; always use modern ManimCE APIs (`Create`, `MathTex`, `Tex`, `Text`, `axes.plot`) and prevent visual overlap using `.to_edge()`, `.next_to()`, and `FadeOut`.", "prompt": "I'm learning tensor shapes and want to trace shapes by hand on a visible scratchpad.\nAnimate a pen-and-paper style derivation that shows how shapes transform through each operation, with dimension labels and broadcasting notes.\nInclude arrows tracing axes and a live log of the resulting shape after each step.\nFinish with a summary table of original vs final shapes and a short recap of common broadcasting pitfalls.", "chosen": "```python\nfrom manim import *\nfrom manim_voiceover import VoiceoverScene\nfrom manim_voiceover.services.gtts import GTTSService\n\nclass TensorShapesAndBroadcasting(VoiceoverScene):\n def construct(self):\n self.set_speech_service(\n GTTSService(voice=\"alba\", cache_dir=\"voiceover_cache\")\n )\n \n # Title slide\n with self.voiceover(text=\"Hello everyone! Have you ever wondered why deep learning frameworks like TensorFlow or PyTorch are so efficient with array operations? It's all thanks to tensor shapes and broadcasting!\") as tracker:\n title = Text(\"Tensor Shapes and Broadcasting\", font_size=48, color=BLUE)\n subtitle = Text(\"The Magic Behind Efficient AI Computations\", font_size=28, color=GRAY)\n subtitle.next_to(title, DOWN, buff=0.5)\n self.play(Write(title), Write(subtitle), run_time=tracker.duration)\n \n self.wait(0.5)\n self.play(FadeOut(title), FadeOut(subtitle))\n \n # Section 1: Understanding Tensor Shapes\n with self.voiceover(text=\"Let's start with the basics. A tensor's shape describes its dimensions. Here's a one-dimensional tensor, which we call a vector.\") as tracker:\n section_title = Text(\"1. Understanding Tensor Shapes\", font_size=36, color=BLUE)\n section_title.to_edge(UP)\n self.play(Write(section_title), run_time=tracker.duration * 0.3)\n \n # Show 1D tensor (vector)\n with self.voiceover(text=\"This vector has shape four, meaning it has four elements.\") as tracker:\n vector_cells = VGroup(*[Square(side_length=0.6, fill_color=BLUE, fill_opacity=0.7) for _ in range(4)])\n vector_cells.arrange(RIGHT, buff=0.1)\n vector_cells.move_to(UP * 1.5)\n \n labels = VGroup(*[Text(str(i+1), font_size=20).move_to(cell.get_center()) for i, cell in enumerate(vector_cells)])\n \n shape_label = MathTex(r\"\text{Shape: } (4,)\", font_size=28)\n shape_label.next_to(vector_cells, DOWN, buff=0.5)\n \n self.play(Create(vector_cells), run_time=tracker.duration * 0.4)\n self.play(Write(labels), run_time=tracker.duration * 0.3)\n self.play(Write(shape_label), run_time=tracker.duration * 0.3)\n \n self.wait(0.5)\n \n # Show 2D tensor (matrix)\n with self.voiceover(text=\"Now, a two-dimensional tensor is a matrix. This one has shape two by three, two rows and three columns.\") as tracker:\n matrix_cells = VGroup()\n matrix_labels = VGroup()\n val = 1\n for row in range(2):\n for col in range(3):\n cell = Square(side_length=0.6, fill_color=GREEN, fill_opacity=0.7)\n cell.move_to(np.array([col * 0.7 - 0.7, -row * 0.7, 0]))\n matrix_cells.add(cell)\n label = Text(str(val), font_size=18)\n label.move_to(cell.get_center())\n matrix_labels.add(label)\n val += 1\n \n matrix_group = VGroup(matrix_cells, matrix_labels)\n matrix_group.move_to(UP * 0.5)\n \n matrix_shape = MathTex(r\"\text{Shape: } (2, 3)\", font_size=28)\n matrix_shape.next_to(matrix_group, DOWN, buff=0.5)\n \n self.play(FadeOut(vector_cells), FadeOut(labels), FadeOut(shape_label))\n self.play(Create(matrix_cells), Write(matrix_labels), run_time=tracker.duration * 0.6)\n self.play(Write(matrix_shape), run_time=tracker.duration * 0.4)\n \n self.wait(0.5)\n \n # Show 3D tensor\n with self.voiceover(text=\"Three-dimensional tensors are common in images. Think of them as stacks of matrices. This one has shape two by three by two.\") as tracker:\n self.play(FadeOut(matrix_cells), FadeOut(matrix_labels), FadeOut(matrix_shape))\n \n tensor_3d = VGroup()\n colors = [RED, BLUE]\n for layer in range(2):\n layer_group = VGroup()\n for row in range(2):\n for col in range(3):\n cell = Square(side_length=0.5, fill_color=colors[layer], fill_opacity=0.6, stroke_width=1)\n cell.move_to(np.array([col * 0.55 - 0.55, -row * 0.55, 0]))\n layer_group.add(cell)\n layer_group.shift(RIGHT * layer * 2.5 + DOWN * 0.5)\n tensor_3d.add(layer_group)\n \n tensor_shape = MathTex(r\"\text{Shape: } (2, 2, 3)\", font_size=28)\n tensor_shape.next_to(tensor_3d, DOWN, buff=0.5)\n \n dim_labels = VGroup(\n Text(\"Layer 1\", font_size=16, color=colors[0]).next_to(tensor_3d[0], UP, buff=0.2),\n Text(\"Layer 2\", font_size=16, color=colors[1]).next_to(tensor_3d[1], UP, buff=0.2)\n )\n \n self.play(Create(tensor_3d), Write(dim_labels), run_time=tracker.duration * 0.6)\n self.play(Write(tensor_shape), run_time=tracker.duration * 0.4)\n \n self.wait(0.5)\n self.play(FadeOut(tensor_3d), FadeOut(dim_labels), FadeOut(tensor_shape), FadeOut(section_title))\n \n # Section 2: What is Broadcasting?\n with self.voiceover(text=\"Now let's explore broadcasting. Broadcasting allows tensors with different shapes to be used in arithmetic operations.\") as tracker:\n section_title2 = Text(\"2. What is Broadcasting?\", font_size=36, color=BLUE)\n section_title2.to_edge(UP)\n self.play(Write(section_title2), run_time=tracker.duration)\n \n # Example 1: Scalar broadcasting\n with self.voiceover(text=\"Here's a simple example. A scalar, which is a zero-dimensional tensor, can be added to any tensor.\") as tracker:\n scalar = Circle(radius=0.4, fill_color=YELLOW, fill_opacity=0.8)\n scalar_text = Text(\"5\", font_size=24).move_to(scalar.get_center())\n scalar_group = VGroup(scalar, scalar_text)\n scalar_group.move_to(LEFT * 4 + UP * 1)\n \n scalar_shape = MathTex(r\"\text{Shape: } ()\", font_size=24)\n scalar_shape.next_to(scalar_group, DOWN, buff=0.3)\n \n vector_bc = VGroup(*[Square(side_length=0.5, fill_color=BLUE, fill_opacity=0.7) for _ in range(3)])\n vector_bc.arrange(RIGHT, buff=0.1)\n vector_bc.move_to(RIGHT * 2 + UP * 1)\n \n vector_labels_bc = VGroup(*[Text(str(i+1), font_size=18).move_to(cell.get_center()) for i, cell in enumerate(vector_bc)])\n vector_shape_bc = MathTex(r\"\text{Shape: } (3,)\", font_size=24)\n vector_shape_bc.next_to(vector_bc, DOWN, buff=0.3)\n \n plus_sign = Text(\"+\", font_size=36).move_to((scalar_group.get_center() + vector_bc.get_center()) / 2)\n \n self.play(Create(scalar_group), Write(scalar_shape), run_time=tracker.duration * 0.3)\n self.play(Write(plus_sign), run_time=tracker.duration * 0.1)\n self.play(Create(vector_bc), Write(vector_labels_bc), Write(vector_shape_bc), run_time=tracker.duration * 0.3)\n \n with self.voiceover(text=\"The scalar gets virtually expanded to match the vector's shape. So five is added to each element.\") as tracker:\n arrow = Arrow(vector_bc.get_bottom() + DOWN * 0.3, vector_bc.get_bottom() + DOWN * 1.2, buff=0.1)\n \n result = VGroup(*[Square(side_length=0.5, fill_color=GREEN, fill_opacity=0.7) for _ in range(3)])\n result.arrange(RIGHT, buff=0.1)\n result.move_to(vector_bc.get_center() + DOWN * 1.5)\n \n result_labels = VGroup(\n Text(\"6\", font_size=18).move_to(result[0].get_center()),\n Text(\"7\", font_size=18).move_to(result[1].get_center()),\n Text(\"8\", font_size=18).move_to(result[2].get_center())\n )\n \n result_shape = MathTex(r\"\text{Shape: } (3,)\", font_size=24)\n result_shape.next_to(result, DOWN, buff=0.3)\n \n self.play(Create(arrow), Create(result), Write(result_labels), run_time=tracker.duration * 0.6)\n self.play(Write(result_shape), run_time=tracker.duration * 0.4)\n \n self.wait(0.5)\n self.play(FadeOut(scalar_group), FadeOut(scalar_shape), FadeOut(plus_sign), \n FadeOut(vector_bc), FadeOut(vector_labels_bc), FadeOut(vector_shape_bc),\n FadeOut(arrow), FadeOut(result), FadeOut(result_labels), FadeOut(result_shape))\n \n # Section 3: Broadcasting Rules\n with self.voiceover(text=\"Broadcasting follows specific rules. Let me show you how different shapes can work together.\") as tracker:\n section_title3 = Text(\"3. Broadcasting Rules\", font_size=36, color=BLUE)\n section_title3.to_edge(UP)\n self.play(Transform(section_title2, section_title3))\n \n # Example 2: Row vector + Column vector\n with self.voiceover(text=\"Consider a row vector with shape one by three, and a column vector with shape two by one.\") as tracker:\n row_vec = VGroup(*[Square(side_length=0.5, fill_color=BLUE, fill_opacity=0.7) for _ in range(3)])\n row_vec.arrange(RIGHT, buff=0.1)\n row_vec.move_to(LEFT * 3 + UP * 0.5)\n row_labels = VGroup(*[Text(str(i+1), font_size=16).move_to(cell.get_center()) for i, cell in enumerate(row_vec)])\n row_shape = MathTex(r\"(1, 3)\", font_size=22)\n row_shape.next_to(row_vec, DOWN, buff=0.2)\n \n col_vec = VGroup(*[Square(side_length=0.5, fill_color=RED, fill_opacity=0.7) for _ in range(2)])\n col_vec.arrange(DOWN, buff=0.1)\n col_vec.move_to(LEFT * 3 + DOWN * 1.5)\n col_labels = VGroup(*[Text(str(i+10), font_size=16).move_to(cell.get_center()) for i, cell in enumerate(col_vec)])\n col_shape = MathTex(r\"(2, 1)\", font_size=22)\n col_shape.next_to(col_vec, LEFT, buff=0.2)\n \n self.play(Create(row_vec), Write(row_labels), Write(row_shape), run_time=tracker.duration * 0.4)\n self.play(Create(col_vec), Write(col_labels), Write(col_shape), run_time=tracker.duration * 0.4)\n \n with self.voiceover(text=\"When we add them, broadcasting expands both to create a two by three result. The row stretches downward, and the column stretches rightward.\") as tracker:\n plus = Text(\"+\", font_size=32).move_to((row_vec.get_right() + col_vec.get_right()) / 2 + RIGHT * 0.5)\n \n result_grid = VGroup()\n for row in range(2):\n for col in range(3):\n cell = Square(side_length=0.5, fill_color=GREEN, fill_opacity=0.7)\n cell.move_to(np.array([col * 0.55 + 1, -row * 0.55 + 0.5, 0]))\n result_grid.add(cell)\n \n result_vals = VGroup(\n Text(\"11\", font_size=14).move_to(result_grid[0]),\n Text(\"12\", font_size=14).move_to(result_grid[1]),\n Text(\"13\", font_size=14).move_to(result_grid[2]),\n Text(\"12\", font_size=14).move_to(result_grid[3]),\n Text(\"13\", font_size=14).move_to(result_grid[4]),\n Text(\"14\", font_size=14).move_to(result_grid[5])\n )\n \n result_sh = MathTex(r\"(2, 3)\", font_size=22)\n result_sh.next_to(result_grid, DOWN, buff=0.2)\n \n arrow1 = Arrow(row_vec.get_right(), result_grid.get_left(), buff=0.2, color=BLUE)\n arrow2 = Arrow(col_vec.get_right(), result_grid.get_left() + DOWN * 0.3, buff=0.2, color=RED)\n \n self.play(Write(plus), run_time=tracker.duration * 0.1)\n self.play(Create(arrow1), Create(arrow2), run_time=tracker.duration * 0.3)\n self.play(Create(result_grid), Write(result_vals), run_time=tracker.duration * 0.4)\n self.play(Write(result_sh), run_time=tracker.duration * 0.2)\n \n self.wait(0.5)\n self.play(FadeOut(row_vec), FadeOut(row_labels), FadeOut(row_shape),\n FadeOut(col_vec), FadeOut(col_labels), FadeOut(col_shape),\n FadeOut(plus), FadeOut(arrow1), FadeOut(arrow2),\n FadeOut(result_grid), FadeOut(result_vals), FadeOut(result_sh))\n \n # Section 4: Practical Examples\n with self.voiceover(text=\"In AI, broadcasting is everywhere. Here are two practical examples.\") as tracker:\n section_title4 = Text(\"4. Practical Examples in AI\", font_size=36, color=BLUE)\n section_title4.to_edge(UP)\n self.play(Transform(section_title2, section_title4))\n \n with self.voiceover(text=\"First, batch processing. You have a batch of images with shape batch size by height by width by channels. You can add a bias vector to all images at once.\") as tracker:\n batch_text = Text(\"Batch Images: (32, 64, 64, 3)\", font_size=24, color=BLUE)\n bias_text = Text(\"Bias: (3,)\", font_size=24, color=RED)\n output_text = Text(\"Output: (32, 64, 64, 3)\", font_size=24, color=GREEN)\n \n batch_text.move_to(UP * 1.5)\n bias_text.next_to(batch_text, DOWN, buff=0.5)\n output_text.next_to(bias_text, DOWN, buff=0.5)\n \n arrow_down = Arrow(batch_text.get_bottom(), bias_text.get_top(), buff=0.1)\n arrow_down2 = Arrow(bias_text.get_bottom(), output_text.get_top(), buff=0.1)\n \n self.play(Write(batch_text), run_time=tracker.duration * 0.3)\n self.play(Create(arrow_down), Write(bias_text), run_time=tracker.duration * 0.3)\n self.play(Create(arrow_down2), Write(output_text), run_time=tracker.duration * 0.4)\n \n self.wait(0.5)\n self.play(FadeOut(batch_text), FadeOut(bias_text), FadeOut(output_text), \n FadeOut(arrow_down), FadeOut(arrow_down2))\n \n with self.voiceover(text=\"Second, normalization. You compute the mean across the batch dimension and subtract it from each sample. Broadcasting handles the shape mismatch automatically.\") as tracker:\n norm_text1 = Text(\"Features: (100, 512)\", font_size=24, color=BLUE)\n norm_text2 = Text(\"Mean: (512,)\", font_size=24, color=RED)\n norm_text3 = Text(\"Normalized: (100, 512)\", font_size=24, color=GREEN)\n \n norm_text1.move_to(UP * 1.5)\n norm_text2.next_to(norm_text1, DOWN, buff=0.5)\n norm_text3.next_to(norm_text2, DOWN, buff=0.5)\n \n arrow_n1 = Arrow(norm_text1.get_bottom(), norm_text2.get_top(), buff=0.1)\n arrow_n2 = Arrow(norm_text2.get_bottom(), norm_text3.get_top(), buff=0.1)\n \n self.play(Write(norm_text1), run_time=tracker.duration * 0.25)\n self.play(Create(arrow_n1), Write(norm_text2), run_time=tracker.duration * 0.35)\n self.play(Create(arrow_n2), Write(norm_text3), run_time=tracker.duration * 0.4)\n \n self.wait(0.5)\n self.play(FadeOut(norm_text1), FadeOut(norm_text2), FadeOut(norm_text3),\n FadeOut(arrow_n1), FadeOut(arrow_n2), FadeOut(section_title2))\n \n # Summary\n with self.voiceover(text=\"To summarize: you now understand tensor shapes and their dimensions, you know how broadcasting allows operations on different shapes, and you've seen practical AI applications. Broadcasting is the secret sauce that makes tensor operations efficient and elegant!\") as tracker:\n summary_title = Text(\"Summary\", font_size=40, color=BLUE)\n summary_title.to_edge(UP)\n \n points = VGroup(\n Text(\"• Tensor shapes define dimensions\", font_size=24),\n Text(\"• Broadcasting enables cross-shape operations\", font_size=24),\n Text(\"• Essential for efficient AI computations\", font_size=24),\n Text(\"• Used in batching and normalization\", font_size=24)\n )\n points.arrange(DOWN, buff=0.4, aligned_edge=LEFT)\n points.move_to(DOWN * 0.5)\n \n self.play(Write(summary_title), run_time=tracker.duration * 0.2)\n for point in points:\n self.play(Write(point), run_time=tracker.duration * 0.2)\n \n self.wait(1)\n self.play(FadeOut(summary_title), FadeOut(points))\n \n # Closing\n with self.voiceover(text=\"Thanks for watching! Now go forth and broadcast with confidence!\") as tracker:\n closing = Text(\"Happy Broadcasting! 🚀\", font_size=40, color=BLUE)\n self.play(Write(closing), run_time=tracker.duration)\n \n self.wait(1)\n```", "rejected": "```python\nfrom manim import *\nfrom manim_voiceover import VoiceoverScene\nfrom manim_voiceover.services.gtts import GTTSService\n\nclass TensorShapesAndBroadcasting(VoiceoverScene):\n def construct(self):\n self.set_speech_service(\n GTTSService(voice=\"alba\", cache_dir=\"voiceover_cache\")\n )\n \n # Title slide\n with self.voiceover(text=\"Hello everyone! Have you ever wondered why deep learning frameworks like TensorFlow or PyTorch are so efficient with array operations? It's all thanks to tensor shapes and broadcasting!\") as tracker:\n title = Text(\"Tensor Shapes and Broadcasting\", font_size=48, color=BLUE)\n subtitle = Text(\"The Magic Behind Efficient AI Computations\", font_size=28, color=GRAY)\n subtitle.next_to(title, DOWN, buff=0.5)\n self.play(Write(title), Write(subtitle), run_time=tracker.duration)\n \n self.wait(0.5)\n self.play(FadeOut(title), FadeOut(subtitle))\n \n # Section 1: Understanding Tensor Shapes\n with self.voiceover(text=\"Let's start with the basics. A tensor's shape describes its dimensions. Here's a one-dimensional tensor, which we call a vector.\") as tracker:\n section_title = Text(\"1. Understanding Tensor Shapes\", font_size=36, color=BLUE)\n section_title.to_edge(UP)\n self.play(Write(section_title), run_time=tracker.duration * 0.3)\n \n # Show 1D tensor (vector)\n with self.voiceover(text=\"This vector has shape four, meaning it has four elements.\") as tracker:\n vector_cells = VGroup(*[Square(side_length=0.6, fill_color=BLUE, fill_opacity=0.7) for _ in range(4)])\n vector_cells.arrange(RIGHT, buff=0.1)\n vector_cells.move_to(UP * 1.5)\n \n labels = VGroup(*[Text(str(i+1), font_size=20).move_to(cell.get_center()) for i, cell in enumerate(vector_cells)])\n \n shape_label = TexMobject(r\"\text{Shape: } (4,)\", font_size=28)\n shape_label.next_to(vector_cells, DOWN, buff=0.5)\n \n self.play(ShowCreation(vector_cells), run_time=tracker.duration * 0.4)\n self.play(Write(labels), run_time=tracker.duration * 0.3)\n self.play(Write(shape_label), run_time=tracker.duration * 0.3)\n \n self.wait(0.5)\n \n # Show 2D tensor (matrix)\n with self.voiceover(text=\"Now, a two-dimensional tensor is a matrix. This one has shape two by three, two rows and three columns.\") as tracker:\n matrix_cells = VGroup()\n matrix_labels = VGroup()\n val = 1\n for row in range(2):\n for col in range(3):\n cell = Square(side_length=0.6, fill_color=GREEN, fill_opacity=0.7)\n cell.move_to(np.array([col * 0.7 - 0.7, -row * 0.7, 0]))\n matrix_cells.add(cell)\n label = Text(str(val), font_size=18)\n label.move_to(cell.get_center())\n matrix_labels.add(label)\n val += 1\n \n matrix_group = VGroup(matrix_cells, matrix_labels)\n matrix_group.move_to(UP * 0.5)\n \n matrix_shape = MathTex(r\"\text{Shape: } (2, 3)\", font_size=28)\n matrix_shape.next_to(matrix_group, DOWN, buff=0.5)\n \n self.play(FadeOut(vector_cells), FadeOut(labels), FadeOut(shape_label))\n self.play(Create(matrix_cells), Write(matrix_labels), run_time=tracker.duration * 0.6)\n self.play(Write(matrix_shape), run_time=tracker.duration * 0.4)\n \n self.wait(0.5)\n \n # Show 3D tensor\n with self.voiceover(text=\"Three-dimensional tensors are common in images. Think of them as stacks of matrices. This one has shape two by three by two.\") as tracker:\n self.play(FadeOut(matrix_cells), FadeOut(matrix_labels), FadeOut(matrix_shape))\n \n tensor_3d = VGroup()\n colors = [RED, BLUE]\n for layer in range(2):\n layer_group = VGroup()\n for row in range(2):\n for col in range(3):\n cell = Square(side_length=0.5, fill_color=colors[layer], fill_opacity=0.6, stroke_width=1)\n cell.move_to(np.array([col * 0.55 - 0.55, -row * 0.55, 0]))\n layer_group.add(cell)\n layer_group.shift(RIGHT * layer * 2.5 + DOWN * 0.5)\n tensor_3d.add(layer_group)\n \n tensor_shape = MathTex(r\"\text{Shape: } (2, 2, 3)\", font_size=28)\n tensor_shape.next_to(tensor_3d, DOWN, buff=0.5)\n \n dim_labels = VGroup(\n Text(\"Layer 1\", font_size=16, color=colors[0]).next_to(tensor_3d[0], UP, buff=0.2),\n Text(\"Layer 2\", font_size=16, color=colors[1]).next_to(tensor_3d[1], UP, buff=0.2)\n )\n \n self.play(Create(tensor_3d), Write(dim_labels), run_time=tracker.duration * 0.6)\n self.play(Write(tensor_shape), run_time=tracker.duration * 0.4)\n \n self.wait(0.5)\n self.play(FadeOut(tensor_3d), FadeOut(dim_labels), FadeOut(tensor_shape), FadeOut(section_title))\n \n # Section 2: What is Broadcasting?\n with self.voiceover(text=\"Now let's explore broadcasting. Broadcasting allows tensors with different shapes to be used in arithmetic operations.\") as tracker:\n section_title2 = Text(\"2. What is Broadcasting?\", font_size=36, color=BLUE)\n section_title2.to_edge(UP)\n self.play(Write(section_title2), run_time=tracker.duration)\n \n # Example 1: Scalar broadcasting\n with self.voiceover(text=\"Here's a simple example. A scalar, which is a zero-dimensional tensor, can be added to any tensor.\") as tracker:\n scalar = Circle(radius=0.4, fill_color=YELLOW, fill_opacity=0.8)\n scalar_text = Text(\"5\", font_size=24).move_to(scalar.get_center())\n scalar_group = VGroup(scalar, scalar_text)\n scalar_group.move_to(LEFT * 4 + UP * 1)\n \n scalar_shape = MathTex(r\"\text{Shape: } ()\", font_size=24)\n scalar_shape.next_to(scalar_group, DOWN, buff=0.3)\n \n vector_bc = VGroup(*[Square(side_length=0.5, fill_color=BLUE, fill_opacity=0.7) for _ in range(3)])\n vector_bc.arrange(RIGHT, buff=0.1)\n vector_bc.move_to(RIGHT * 2 + UP * 1)\n \n vector_labels_bc = VGroup(*[Text(str(i+1), font_size=18).move_to(cell.get_center()) for i, cell in enumerate(vector_bc)])\n vector_shape_bc = MathTex(r\"\text{Shape: } (3,)\", font_size=24)\n vector_shape_bc.next_to(vector_bc, DOWN, buff=0.3)\n \n plus_sign = Text(\"+\", font_size=36).move_to((scalar_group.get_center() + vector_bc.get_center()) / 2)\n \n self.play(Create(scalar_group), Write(scalar_shape), run_time=tracker.duration * 0.3)\n self.play(Write(plus_sign), run_time=tracker.duration * 0.1)\n self.play(Create(vector_bc), Write(vector_labels_bc), Write(vector_shape_bc), run_time=tracker.duration * 0.3)\n \n with self.voiceover(text=\"The scalar gets virtually expanded to match the vector's shape. So five is added to each element.\") as tracker:\n arrow = Arrow(vector_bc.get_bottom() + DOWN * 0.3, vector_bc.get_bottom() + DOWN * 1.2, buff=0.1)\n \n result = VGroup(*[Square(side_length=0.5, fill_color=GREEN, fill_opacity=0.7) for _ in range(3)])\n result.arrange(RIGHT, buff=0.1)\n result.move_to(vector_bc.get_center() + DOWN * 1.5)\n \n result_labels = VGroup(\n Text(\"6\", font_size=18).move_to(result[0].get_center()),\n Text(\"7\", font_size=18).move_to(result[1].get_center()),\n Text(\"8\", font_size=18).move_to(result[2].get_center())\n )\n \n result_shape = MathTex(r\"\text{Shape: } (3,)\", font_size=24)\n result_shape.next_to(result, DOWN, buff=0.3)\n \n self.play(Create(arrow), Create(result), Write(result_labels), run_time=tracker.duration * 0.6)\n self.play(Write(result_shape), run_time=tracker.duration * 0.4)\n \n self.wait(0.5)\n self.play(FadeOut(scalar_group), FadeOut(scalar_shape), FadeOut(plus_sign), \n FadeOut(vector_bc), FadeOut(vector_labels_bc), FadeOut(vector_shape_bc),\n FadeOut(arrow), FadeOut(result), FadeOut(result_labels), FadeOut(result_shape))\n \n # Section 3: Broadcasting Rules\n with self.voiceover(text=\"Broadcasting follows specific rules. Let me show you how different shapes can work together.\") as tracker:\n section_title3 = Text(\"3. Broadcasting Rules\", font_size=36, color=BLUE)\n section_title3.to_edge(UP)\n self.play(Transform(section_title2, section_title3))\n \n # Example 2: Row vector + Column vector\n with self.voiceover(text=\"Consider a row vector with shape one by three, and a column vector with shape two by one.\") as tracker:\n row_vec = VGroup(*[Square(side_length=0.5, fill_color=BLUE, fill_opacity=0.7) for _ in range(3)])\n row_vec.arrange(RIGHT, buff=0.1)\n row_vec.move_to(LEFT * 3 + UP * 0.5)\n row_labels = VGroup(*[Text(str(i+1), font_size=16).move_to(cell.get_center()) for i, cell in enumerate(row_vec)])\n row_shape = MathTex(r\"(1, 3)\", font_size=22)\n row_shape.next_to(row_vec, DOWN, buff=0.2)\n \n col_vec = VGroup(*[Square(side_length=0.5, fill_color=RED, fill_opacity=0.7) for _ in range(2)])\n col_vec.arrange(DOWN, buff=0.1)\n col_vec.move_to(LEFT * 3 + DOWN * 1.5)\n col_labels = VGroup(*[Text(str(i+10), font_size=16).move_to(cell.get_center()) for i, cell in enumerate(col_vec)])\n col_shape = MathTex(r\"(2, 1)\", font_size=22)\n col_shape.next_to(col_vec, LEFT, buff=0.2)\n \n self.play(Create(row_vec), Write(row_labels), Write(row_shape), run_time=tracker.duration * 0.4)\n self.play(Create(col_vec), Write(col_labels), Write(col_shape), run_time=tracker.duration * 0.4)\n \n with self.voiceover(text=\"When we add them, broadcasting expands both to create a two by three result. The row stretches downward, and the column stretches rightward.\") as tracker:\n plus = Text(\"+\", font_size=32).move_to((row_vec.get_right() + col_vec.get_right()) / 2 + RIGHT * 0.5)\n \n result_grid = VGroup()\n for row in range(2):\n for col in range(3):\n cell = Square(side_length=0.5, fill_color=GREEN, fill_opacity=0.7)\n cell.move_to(np.array([col * 0.55 + 1, -row * 0.55 + 0.5, 0]))\n result_grid.add(cell)\n \n result_vals = VGroup(\n Text(\"11\", font_size=14).move_to(result_grid[0]),\n Text(\"12\", font_size=14).move_to(result_grid[1]),\n Text(\"13\", font_size=14).move_to(result_grid[2]),\n Text(\"12\", font_size=14).move_to(result_grid[3]),\n Text(\"13\", font_size=14).move_to(result_grid[4]),\n Text(\"14\", font_size=14).move_to(result_grid[5])\n )\n \n result_sh = MathTex(r\"(2, 3)\", font_size=22)\n result_sh.next_to(result_grid, DOWN, buff=0.2)\n \n arrow1 = Arrow(row_vec.get_right(), result_grid.get_left(), buff=0.2, color=BLUE)\n arrow2 = Arrow(col_vec.get_right(), result_grid.get_left() + DOWN * 0.3, buff=0.2, color=RED)\n \n self.play(Write(plus), run_time=tracker.duration * 0.1)\n self.play(Create(arrow1), Create(arrow2), run_time=tracker.duration * 0.3)\n self.play(Create(result_grid), Write(result_vals), run_time=tracker.duration * 0.4)\n self.play(Write(result_sh), run_time=tracker.duration * 0.2)\n \n self.wait(0.5)\n self.play(FadeOut(row_vec), FadeOut(row_labels), FadeOut(row_shape),\n FadeOut(col_vec), FadeOut(col_labels), FadeOut(col_shape),\n FadeOut(plus), FadeOut(arrow1), FadeOut(arrow2),\n FadeOut(result_grid), FadeOut(result_vals), FadeOut(result_sh))\n \n # Section 4: Practical Examples\n with self.voiceover(text=\"In AI, broadcasting is everywhere. Here are two practical examples.\") as tracker:\n section_title4 = Text(\"4. Practical Examples in AI\", font_size=36, color=BLUE)\n section_title4.to_edge(UP)\n self.play(Transform(section_title2, section_title4))\n \n with self.voiceover(text=\"First, batch processing. You have a batch of images with shape batch size by height by width by channels. You can add a bias vector to all images at once.\") as tracker:\n batch_text = Text(\"Batch Images: (32, 64, 64, 3)\", font_size=24, color=BLUE)\n bias_text = Text(\"Bias: (3,)\", font_size=24, color=RED)\n output_text = Text(\"Output: (32, 64, 64, 3)\", font_size=24, color=GREEN)\n \n batch_text.move_to(UP * 1.5)\n bias_text.next_to(batch_text, DOWN, buff=0.5)\n output_text.next_to(bias_text, DOWN, buff=0.5)\n \n arrow_down = Arrow(batch_text.get_bottom(), bias_text.get_top(), buff=0.1)\n arrow_down2 = Arrow(bias_text.get_bottom(), output_text.get_top(), buff=0.1)\n \n self.play(Write(batch_text), run_time=tracker.duration * 0.3)\n self.play(Create(arrow_down), Write(bias_text), run_time=tracker.duration * 0.3)\n self.play(Create(arrow_down2), Write(output_text), run_time=tracker.duration * 0.4)\n \n self.wait(0.5)\n self.play(FadeOut(batch_text), FadeOut(bias_text), FadeOut(output_text), \n FadeOut(arrow_down), FadeOut(arrow_down2))\n \n with self.voiceover(text=\"Second, normalization. You compute the mean across the batch dimension and subtract it from each sample. Broadcasting handles the shape mismatch automatically.\") as tracker:\n norm_text1 = Text(\"Features: (100, 512)\", font_size=24, color=BLUE)\n norm_text2 = Text(\"Mean: (512,)\", font_size=24, color=RED)\n norm_text3 = Text(\"Normalized: (100, 512)\", font_size=24, color=GREEN)\n \n norm_text1.move_to(UP * 1.5)\n norm_text2.next_to(norm_text1, DOWN, buff=0.5)\n norm_text3.next_to(norm_text2, DOWN, buff=0.5)\n \n arrow_n1 = Arrow(norm_text1.get_bottom(), norm_text2.get_top(), buff=0.1)\n arrow_n2 = Arrow(norm_text2.get_bottom(), norm_text3.get_top(), buff=0.1)\n \n self.play(Write(norm_text1), run_time=tracker.duration * 0.25)\n self.play(Create(arrow_n1), Write(norm_text2), run_time=tracker.duration * 0.35)\n self.play(Create(arrow_n2), Write(norm_text3), run_time=tracker.duration * 0.4)\n \n self.wait(0.5)\n self.play(FadeOut(norm_text1), FadeOut(norm_text2), FadeOut(norm_text3),\n FadeOut(arrow_n1), FadeOut(arrow_n2), FadeOut(section_title2))\n \n # Summary\n with self.voiceover(text=\"To summarize: you now understand tensor shapes and their dimensions, you know how broadcasting allows operations on different shapes, and you've seen practical AI applications. Broadcasting is the secret sauce that makes tensor operations efficient and elegant!\") as tracker:\n summary_title = Text(\"Summary\", font_size=40, color=BLUE)\n summary_title.to_edge(UP)\n \n points = VGroup(\n Text(\"• Tensor shapes define dimensions\", font_size=24),\n Text(\"• Broadcasting enables cross-shape operations\", font_size=24),\n Text(\"• Essential for efficient AI computations\", font_size=24),\n Text(\"• Used in batching and normalization\", font_size=24)\n )\n points.arrange(DOWN, buff=0.4, aligned_edge=LEFT)\n points.move_to(DOWN * 0.5)\n \n self.play(Write(summary_title), run_time=tracker.duration * 0.2)\n for point in points:\n self.play(Write(point), run_time=tracker.duration * 0.2)\n \n self.wait(1)\n self.play(FadeOut(summary_title), FadeOut(points))\n \n # Closing\n with self.voiceover(text=\"Thanks for watching! Now go forth and broadcast with confidence!\") as tracker:\n closing = Text(\"Happy Broadcasting! 🚀\", font_size=40, color=BLUE)\n self.play(Write(closing), run_time=tracker.duration)\n \n self.wait(1)\n```", "category": "legacy_api_hallucination", "source": "synthetic_hard_neg:nabin2004/AOS-Narrated-Manim-400"} +{"system": "You are an expert Manim Community Edition (ManimCE v0.19+) Python developer and mathematical animator. Given a user request, first plan the spatial layout, coordinate bounds, timing, and pedagogical flow inside ... tags (when reasoning is helpful), and then output a complete, runnable, self-contained ManimCE Python script using `from manim import *`. Never use deprecated ManimGL (`manimlib`) methods like `ShowCreation`, `TexMobject`, `TextMobject`, or `axes.get_graph`; always use modern ManimCE APIs (`Create`, `MathTex`, `Tex`, `Text`, `axes.plot`) and prevent visual overlap using `.to_edge()`, `.next_to()`, and `FadeOut`.", "prompt": "I'm learning about attention-like mechanisms and want a concrete visualization of the dot product between an embedding vector and a weight row. Show the embedding and a specific weight row, compute their dot product, and label it as the compatibility score. Animate the alignment as you rotate vectors or slide the embedding to maximize the score. Include a small schematic of subsequent softmax over scores to complete the intuition.", "chosen": "```python\nfrom manim import *\nfrom manim_voiceover import VoiceoverScene\nfrom manim_voiceover.services.gtts import GTTSService\n\nclass AttentionMechanismScene(VoiceoverScene):\n def construct(self):\n self.set_speech_service(\n GTTSService(voice=\"alba\", cache_dir=\"voiceover_cache\")\n )\n\n # --- Title ---\n title = Text(\"Attention Mechanisms & Dot Product\", font_size=40)\n title.to_edge(UP, buff=0.5)\n with self.voiceover(text=\"Let's explore Attention Mechanisms and the Dot Product in AI.\") as tracker:\n self.play(Write(title), run_time=tracker.duration)\n\n # --- Book Analogy ---\n with self.voiceover(text=\"Imagine you're reading a book and you want to remember certain details. How do you focus your attention on the most important parts? This is similar to how attention mechanisms in AI work!\") as tracker:\n self.wait(tracker.duration)\n\n book_rect = RoundedRectangle(width=4, height=2.5, corner_radius=0.2, color=BLUE)\n book_rect.shift(LEFT * 2.5)\n words = VGroup(\n Text(\"The cat sat...\", font_size=20),\n Text(\"...on the mat...\", font_size=20),\n Text(\"...and looked outside.\", font_size=20)\n )\n words.arrange(DOWN, aligned_edge=LEFT, buff=0.2)\n words.move_to(book_rect.get_center())\n book_group = VGroup(book_rect, words)\n\n with self.voiceover(text=\"When reading, your brain highlights the most relevant words based on what you are looking for.\") as tracker:\n self.play(Create(book_rect), run_time=0.5)\n self.play(Write(words), run_time=0.5)\n self.wait(0.5)\n\n # Highlight important word\n highlight = SurroundingRectangle(words[1], color=YELLOW, buff=0.1)\n with self.voiceover(text=\"Attention does the same: it scores every word's importance.\") as tracker:\n self.play(Create(highlight), run_time=tracker.duration)\n\n # --- Q, K, V Introduction ---\n qkv_group = VGroup(\n MathTex(r\"\\mathbf{Q}\", color=RED, font_size=48),\n MathTex(r\"\\mathbf{K}\", color=GREEN, font_size=48),\n MathTex(r\"\\mathbf{V}\", color=BLUE, font_size=48)\n )\n qkv_group.arrange(RIGHT, buff=1.5)\n qkv_group.shift(RIGHT * 2.5)\n\n labels = VGroup(\n Text(\"Query\", font_size=24, color=RED).next_to(qkv_group[0], DOWN),\n Text(\"Key\", font_size=24, color=GREEN).next_to(qkv_group[1], DOWN),\n Text(\"Value\", font_size=24, color=BLUE).next_to(qkv_group[2], DOWN)\n )\n\n with self.voiceover(text=\"In attention, every input has three roles: Query, Key, and Value.\") as tracker:\n self.play(FadeOut(book_group, highlight), run_time=0.5)\n self.play(Write(qkv_group), Write(labels), run_time=tracker.duration - 0.5)\n\n # --- Attention Score Formula ---\n self.play(FadeOut(qkv_group, labels), run_time=0.3)\n score_formula = MathTex(\n r\"\\text{Score}(Q, K) = \\frac{Q \\cdot K}{\\sqrt{d_k}}\",\n font_size=44\n )\n score_formula.move_to(ORIGIN)\n with self.voiceover(text=\"The attention score is computed using the dot product between Query and Key, scaled by the square root of the key dimension.\") as tracker:\n self.play(Write(score_formula), run_time=tracker.duration)\n\n # --- Concrete Example ---\n with self.voiceover(text=\"Let's see a concrete example with numbers.\") as tracker:\n self.wait(tracker.duration)\n\n self.play(FadeOut(score_formula), run_time=0.3)\n\n q_vec = Matrix([[1], [2], [3]], left_bracket=\"[\", right_bracket=\"]\")\n k_vec = Matrix([[4], [5], [6]], left_bracket=\"[\", right_bracket=\"]\")\n q_vec.set_color(RED)\n k_vec.set_color(GREEN)\n q_vec.scale(0.6)\n k_vec.scale(0.6)\n q_vec.to_edge(LEFT, buff=1)\n k_vec.to_edge(RIGHT, buff=1)\n q_label = Text(\"Query\", font_size=24, color=RED).next_to(q_vec, UP)\n k_label = Text(\"Key\", font_size=24, color=GREEN).next_to(k_vec, UP)\n\n with self.voiceover(text=\"Here is a Query vector and a Key vector.\") as tracker:\n self.play(Write(q_label), Write(q_vec), Write(k_label), Write(k_vec), run_time=tracker.duration)\n\n # Dot product step\n dot_step = MathTex(r\"1 \\cdot 4 + 2 \\cdot 5 + 3 \\cdot 6 = 32\", font_size=40)\n dot_step.move_to(ORIGIN)\n with self.voiceover(text=\"The dot product equals one times four, plus two times five, plus three times six, which gives thirty-two.\") as tracker:\n self.play(Write(dot_step), run_time=tracker.duration)\n\n # Scale step\n scale_step = MathTex(r\"\\frac{32}{\\sqrt{3}} \\approx 18.48\", font_size=40)\n scale_step.move_to(ORIGIN)\n with self.voiceover(text=\"Then we scale by the square root of the dimension, giving approximately eighteen point four eight.\") as tracker:\n self.play(ReplacementTransform(dot_step, scale_step), run_time=tracker.duration)\n\n # Softmax note\n softmax_note = Text(\"(Pass through Softmax for probabilities)\", font_size=24, color=YELLOW)\n softmax_note.next_to(scale_step, DOWN, buff=0.5)\n with self.voiceover(text=\"These scores are usually passed through softmax to turn them into probabilities.\") as tracker:\n self.play(Write(softmax_note), run_time=tracker.duration)\n\n # --- Output Formula ---\n self.play(FadeOut(scale_step, q_vec, k_vec, q_label, k_label, softmax_note), run_time=0.3)\n output_formula = MathTex(\n r\"\\text{Output} = \\text{Attention}(Q, K, V) = \\text{softmax}\\left(\\frac{Q K^T}{\\sqrt{d_k}}\\right) V\",\n font_size=40\n )\n output_formula.move_to(ORIGIN)\n with self.voiceover(text=\"Finally, the output is the weighted sum of Values, where the weights are the attention scores. This is the core of self-attention.\") as tracker:\n self.play(Write(output_formula), run_time=tracker.duration)\n\n # --- Takeaways ---\n self.play(FadeOut(output_formula), run_time=0.3)\n takeaway_title = Text(\"Key Takeaways\", font_size=36, color=BLUE)\n takeaway_title.to_edge(UP, buff=0.5)\n takeaways = VGroup(\n Text(\"1. Attention scores importance using Query and Key.\", font_size=26),\n Text(\"2. Dot product measures similarity.\", font_size=26),\n Text(\"3. Scaling prevents extremely large values.\", font_size=26),\n Text(\"4. Output is a weighted sum of Values.\", font_size=26)\n )\n takeaways.arrange(DOWN, aligned_edge=LEFT, buff=0.3)\n takeaways.next_to(takeaway_title, DOWN, buff=0.6)\n\n with self.voiceover(text=\"To summarize: attention scores importance using Query and Key. The dot product measures similarity. Scaling keeps values stable. And the output is a weighted sum of Values.\") as tracker:\n self.play(Write(takeaway_title), run_time=0.5)\n self.play(Write(takeaways), run_time=tracker.duration - 0.5)\n\n self.wait(1)\n```", "rejected": "```python\nfrom manim import *\nfrom manim_voiceover import VoiceoverScene\nfrom manim_voiceover.services.gtts import GTTSService\n\nclass AttentionMechanismScene(VoiceoverScene):\n def construct(self):\n self.set_speech_service(\n GTTSService(voice=\"alba\", cache_dir=\"voiceover_cache\")\n )\n\n # --- Title ---\n title = Text(\"Attention Mechanisms & Dot Product\", font_size=40)\n title\n with self.voiceover(text=\"Let's explore Attention Mechanisms and the Dot Product in AI.\") as tracker:\n self.play(Write(title), run_time=tracker.duration)\n\n # --- Book Analogy ---\n with self.voiceover(text=\"Imagine you're reading a book and you want to remember certain details. How do you focus your attention on the most important parts? This is similar to how attention mechanisms in AI work!\") as tracker:\n self.wait(tracker.duration)\n\n book_rect = RoundedRectangle(width=4, height=2.5, corner_radius=0.2, color=BLUE)\n book_rect\n words = VGroup(\n Text(\"The cat sat...\", font_size=20),\n Text(\"...on the mat...\", font_size=20),\n Text(\"...and looked outside.\", font_size=20)\n )\n words.arrange(DOWN, aligned_edge=LEFT, buff=0.2)\n words.move_to(book_rect.get_center())\n book_group = VGroup(book_rect, words)\n\n with self.voiceover(text=\"When reading, your brain highlights the most relevant words based on what you are looking for.\") as tracker:\n self.play(Create(book_rect), run_time=0.5)\n self.play(Write(words), run_time=0.5)\n self.wait(0.5)\n\n # Highlight important word\n highlight = SurroundingRectangle(words[1], color=YELLOW, buff=0.1)\n with self.voiceover(text=\"Attention does the same: it scores every word's importance.\") as tracker:\n self.play(Create(highlight), run_time=tracker.duration)\n\n # --- Q, K, V Introduction ---\n qkv_group = VGroup(\n MathTex(r\"\\mathbf{Q}\", color=RED, font_size=48),\n MathTex(r\"\\mathbf{K}\", color=GREEN, font_size=48),\n MathTex(r\"\\mathbf{V}\", color=BLUE, font_size=48)\n )\n qkv_group.arrange(RIGHT, buff=1.5)\n qkv_group\n\n labels = VGroup(\n Text(\"Query\", font_size=24, color=RED).next_to(qkv_group[0], DOWN),\n Text(\"Key\", font_size=24, color=GREEN).next_to(qkv_group[1], DOWN),\n Text(\"Value\", font_size=24, color=BLUE).next_to(qkv_group[2], DOWN)\n )\n\n with self.voiceover(text=\"In attention, every input has three roles: Query, Key, and Value.\") as tracker:\n self.play(FadeOut(book_group, highlight), run_time=0.5)\n self.play(Write(qkv_group), Write(labels), run_time=tracker.duration - 0.5)\n\n # --- Attention Score Formula ---\n self.play(FadeOut(qkv_group, labels), run_time=0.3)\n score_formula = MathTex(\n r\"\\text{Score}(Q, K) = \\frac{Q \\cdot K}{\\sqrt{d_k}}\",\n font_size=44\n )\n score_formula.move_to(ORIGIN)\n with self.voiceover(text=\"The attention score is computed using the dot product between Query and Key, scaled by the square root of the key dimension.\") as tracker:\n self.play(Write(score_formula), run_time=tracker.duration)\n\n # --- Concrete Example ---\n with self.voiceover(text=\"Let's see a concrete example with numbers.\") as tracker:\n self.wait(tracker.duration)\n\n self.play(FadeOut(score_formula), run_time=0.3)\n\n q_vec = Matrix([[1], [2], [3]], left_bracket=\"[\", right_bracket=\"]\")\n k_vec = Matrix([[4], [5], [6]], left_bracket=\"[\", right_bracket=\"]\")\n q_vec.set_color(RED)\n k_vec.set_color(GREEN)\n q_vec.scale(0.6)\n k_vec.scale(0.6)\n q_vec.to_edge(LEFT, buff=1)\n k_vec.to_edge(RIGHT, buff=1)\n q_label = Text(\"Query\", font_size=24, color=RED).next_to(q_vec, UP)\n k_label = Text(\"Key\", font_size=24, color=GREEN).next_to(k_vec, UP)\n\n with self.voiceover(text=\"Here is a Query vector and a Key vector.\") as tracker:\n self.play(Write(q_label), Write(q_vec), Write(k_label), Write(k_vec), run_time=tracker.duration)\n\n # Dot product step\n dot_step = MathTex(r\"1 \\cdot 4 + 2 \\cdot 5 + 3 \\cdot 6 = 32\", font_size=40)\n dot_step.move_to(ORIGIN)\n with self.voiceover(text=\"The dot product equals one times four, plus two times five, plus three times six, which gives thirty-two.\") as tracker:\n self.play(Write(dot_step), run_time=tracker.duration)\n\n # Scale step\n scale_step = MathTex(r\"\\frac{32}{\\sqrt{3}} \\approx 18.48\", font_size=40)\n scale_step.move_to(ORIGIN)\n with self.voiceover(text=\"Then we scale by the square root of the dimension, giving approximately eighteen point four eight.\") as tracker:\n self.play(ReplacementTransform(dot_step, scale_step), run_time=tracker.duration)\n\n # Softmax note\n softmax_note = Text(\"(Pass through Softmax for probabilities)\", font_size=24, color=YELLOW)\n softmax_note.next_to(scale_step, DOWN, buff=0.5)\n with self.voiceover(text=\"These scores are usually passed through softmax to turn them into probabilities.\") as tracker:\n self.play(Write(softmax_note), run_time=tracker.duration)\n\n # --- Output Formula ---\n self.play(FadeOut(scale_step, q_vec, k_vec, q_label, k_label, softmax_note), run_time=0.3)\n output_formula = MathTex(\n r\"\\text{Output} = \\text{Attention}(Q, K, V) = \\text{softmax}\\left(\\frac{Q K^T}{\\sqrt{d_k}}\\right) V\",\n font_size=40\n )\n output_formula.move_to(ORIGIN)\n with self.voiceover(text=\"Finally, the output is the weighted sum of Values, where the weights are the attention scores. This is the core of self-attention.\") as tracker:\n self.play(Write(output_formula), run_time=tracker.duration)\n\n # --- Takeaways ---\n self.play(FadeOut(output_formula), run_time=0.3)\n takeaway_title = Text(\"Key Takeaways\", font_size=36, color=BLUE)\n takeaway_title.to_edge(UP, buff=0.5)\n takeaways = VGroup(\n Text(\"1. Attention scores importance using Query and Key.\", font_size=26),\n Text(\"2. Dot product measures similarity.\", font_size=26),\n Text(\"3. Scaling prevents extremely large values.\", font_size=26),\n Text(\"4. Output is a weighted sum of Values.\", font_size=26)\n )\n takeaways.arrange(DOWN, aligned_edge=LEFT, buff=0.3)\n takeaways.next_to(takeaway_title, DOWN, buff=0.6)\n\n with self.voiceover(text=\"To summarize: attention scores importance using Query and Key. The dot product measures similarity. Scaling keeps values stable. And the output is a weighted sum of Values.\") as tracker:\n self.play(Write(takeaway_title), run_time=0.5)\n self.play(Write(takeaways), run_time=tracker.duration - 0.5)\n\n self.wait(1)\n```", "category": "spatial_layout_overlap", "source": "synthetic_hard_neg:nabin2004/AOS-Narrated-Manim-400"} +{"system": "You are an expert Manim Community Edition (ManimCE v0.19+) Python developer and mathematical animator. Given a user request, first plan the spatial layout, coordinate bounds, timing, and pedagogical flow inside ... tags (when reasoning is helpful), and then output a complete, runnable, self-contained ManimCE Python script using `from manim import *`. Never use deprecated ManimGL (`manimlib`) methods like `ShowCreation`, `TexMobject`, `TextMobject`, or `axes.get_graph`; always use modern ManimCE APIs (`Create`, `MathTex`, `Tex`, `Text`, `axes.plot`) and prevent visual overlap using `.to_edge()`, `.next_to()`, and `FadeOut`.", "prompt": "I'm teaching undergrads and want a vivid visualization of receptive field growth when increasing filter size vs. increasing dilation rate. Show two parallel paths: a growing kernel vs. a fixed kernel with dilation, over a 2D input, highlighting the covered area. Include side-by-side comparisons, zoom-ins on the receptive field, and captions explaining which settings expand the field most efficiently.", "chosen": "```python\nfrom manim import *\nfrom manim_voiceover import VoiceoverScene\nfrom manim_voiceover.services.gtts import GTTSService\n\n\nclass ReceptiveFieldGrowthScene(VoiceoverScene):\n def construct(self):\n self.set_speech_service(\n GTTSService(voice=\"alba\", cache_dir=\"voiceover_cache\")\n )\n \n # Color scheme\n INPUT_COLOR = \"#4ECDC4\"\n LAYER1_COLOR = \"#45B7D1\"\n LAYER2_COLOR = \"#96CEB4\"\n LAYER3_COLOR = \"#FFEAA7\"\n NEURON_COLOR = \"#DDA0DD\"\n RF_COLOR = \"#FF6B6B\"\n HIGHLIGHT_COLOR = \"#FFD93D\"\n \n # ============================================\n # TITLE AND INTRODUCTION\n # ============================================\n with self.voiceover(\n text=\"Have you ever wondered how neural networks process visual information efficiently?\"\n ) as tracker:\n title = Text(\"Receptive Field Growth\", font_size=48, color=WHITE)\n subtitle = Text(\"in Neural Networks\", font_size=32, color=GRAY)\n subtitle.next_to(title, DOWN, buff=0.3)\n title_group = VGroup(title, subtitle)\n title_group.center()\n self.play(Write(title), run_time=tracker.duration * 0.6)\n self.play(FadeIn(subtitle), run_time=tracker.duration * 0.4)\n \n self.wait(0.5)\n \n with self.voiceover(\n text=\"Receptive fields play a crucial role in how neurons respond to stimuli, growing and adapting across layers.\"\n ) as tracker:\n self.play(FadeOut(title_group), run_time=tracker.duration)\n \n # ============================================\n # PART 1: SINGLE NEURON WITH SMALL RECEPTIVE FIELD\n # ============================================\n with self.voiceover(\n text=\"Let's start with the basics. A single neuron in a neural network doesn't see the entire input image.\"\n ) as tracker:\n # Create input grid representing an image\n input_grid = VGroup()\n for i in range(7):\n for j in range(7):\n cell = Square(side_length=0.35, stroke_width=1, fill_opacity=0.1, fill_color=INPUT_COLOR)\n cell.move_to([i * 0.36 - 1.26, j * 0.36 - 1.26, 0])\n input_grid.add(cell)\n input_label = Text(\"Input Image\", font_size=20, color=INPUT_COLOR)\n input_label.next_to(input_grid, DOWN, buff=0.3)\n input_group = VGroup(input_grid, input_label)\n input_group.move_to(LEFT * 4)\n \n self.play(Create(input_grid), Write(input_label), run_time=tracker.duration)\n \n with self.voiceover(\n text=\"Instead, it has a receptive field, a specific region of the input it responds to.\"\n ) as tracker:\n # Highlight a small 3x3 receptive field\n rf_cells = VGroup()\n for i in range(2, 5):\n for j in range(2, 5):\n idx = i * 7 + j\n rf_cells.add(input_grid[idx])\n \n # Create surrounding rectangle for receptive field\n rf_box = SurroundingRectangle(rf_cells, color=RF_COLOR, buff=0.02, corner_radius=0.05)\n rf_box.set_stroke_width(3)\n \n rf_label = Text(\"Receptive Field (3x3)\", font_size=16, color=RF_COLOR)\n rf_label.next_to(rf_box, UP, buff=0.15)\n \n self.play(Create(rf_box), Write(rf_label), run_time=tracker.duration * 0.6)\n self.play(\n rf_cells.animate.set_fill(RF_COLOR, opacity=0.4),\n run_time=tracker.duration * 0.4\n )\n \n with self.voiceover(\n text=\"In early layers, this field is small. The neuron only processes local features like edges or corners.\"\n ) as tracker:\n # Add a neuron\n neuron = Circle(radius=0.3, color=NEURON_COLOR, fill_opacity=0.3, fill_color=NEURON_COLOR)\n neuron.move_to(RIGHT * 2)\n neuron_label = Text(\"Neuron\", font_size=18, color=NEURON_COLOR)\n neuron_label.next_to(neuron, DOWN, buff=0.2)\n \n # Arrow from RF to neuron\n arrow = Arrow(rf_box.get_right(), neuron.get_left(), color=WHITE, buff=0.2)\n \n self.play(Create(neuron), Write(neuron_label), run_time=tracker.duration * 0.5)\n self.play(Create(arrow), run_time=tracker.duration * 0.5)\n \n self.wait(0.5)\n \n # ============================================\n # PART 2: RECEPTIVE FIELD GROWS ACROSS LAYERS\n # ============================================\n with self.voiceover(\n text=\"But here's where it gets interesting. As we move deeper into the network, receptive fields grow.\"\n ) as tracker:\n # Fade out current elements\n self.play(\n FadeOut(arrow),\n FadeOut(neuron),\n FadeOut(neuron_label),\n FadeOut(rf_label),\n FadeOut(rf_box),\n input_grid.animate.set_fill(opacity=0.1),\n run_time=tracker.duration\n )\n \n with self.voiceover(\n text=\"Let's visualize this growth across three layers.\"\n ) as tracker:\n # Show layer labels\n layer1_label = Text(\"Layer 1\", font_size=20, color=LAYER1_COLOR)\n layer2_label = Text(\"Layer 2\", font_size=20, color=LAYER2_COLOR)\n layer3_label = Text(\"Layer 3\", font_size=20, color=LAYER3_COLOR)\n \n layer1_label.move_to(RIGHT * 1 + UP * 2.5)\n layer2_label.move_to(RIGHT * 2.5 + UP * 2.5)\n layer3_label.move_to(RIGHT * 4 + UP * 2.5)\n \n self.play(\n Write(layer1_label),\n Write(layer2_label),\n Write(layer3_label),\n run_time=tracker.duration\n )\n \n # Layer 1: Small RF (3x3)\n with self.voiceover(\n text=\"In layer one, each neuron sees a 3 by 3 patch of the input.\"\n ) as tracker:\n # Create small neurons for layer 1\n layer1_neurons = VGroup()\n rf1_boxes = VGroup()\n \n for idx, pos in enumerate([(0.5, 0.5), (0.5, -0.5), (-0.5, 0.5)]):\n n = Circle(radius=0.15, color=LAYER1_COLOR, fill_opacity=0.5)\n n.move_to([1 + pos[0], pos[1], 0])\n layer1_neurons.add(n)\n \n # Show corresponding RF\n rf_center_x = 3 + pos[0] * 2\n rf_center_y = 3 + pos[1] * 2\n rf_indices = []\n for dx in [-1, 0, 1]:\n for dy in [-1, 0, 1]:\n rf_i = int(rf_center_x + dx)\n rf_j = int(rf_center_y + dy)\n if 0 <= rf_i < 7 and 0 <= rf_j < 7:\n rf_indices.append(rf_i * 7 + rf_j)\n \n rf_cells = VGroup(*[input_grid[i] for i in rf_indices])\n rf_box = SurroundingRectangle(rf_cells, color=LAYER1_COLOR, buff=0.02, corner_radius=0.03)\n rf_box.set_stroke_width(2)\n rf1_boxes.add(rf_box)\n \n arrow = Arrow(rf_box.get_right(), n.get_left(), color=LAYER1_COLOR, buff=0.1, stroke_width=2)\n layer1_neurons.add(arrow)\n \n self.play(\n Create(layer1_neurons),\n Create(rf1_boxes),\n run_time=tracker.duration\n )\n \n # Layer 2: Medium RF (5x5 effective)\n with self.voiceover(\n text=\"In layer two, each neuron combines information from multiple layer one neurons.\"\n ) as tracker:\n layer2_neurons = VGroup()\n rf2_highlights = VGroup()\n \n n2_1 = Circle(radius=0.15, color=LAYER2_COLOR, fill_opacity=0.5)\n n2_1.move_to([2.5, 0.3, 0])\n layer2_neurons.add(n2_1)\n \n # Arrows from layer 1 to layer 2\n for n1 in layer1_neurons:\n if isinstance(n1, Circle):\n arrow = Arrow(n1.get_right(), n2_1.get_left(), color=LAYER2_COLOR, buff=0.1, stroke_width=1.5)\n layer2_neurons.add(arrow)\n \n # Show larger effective RF\n rf2_indices = []\n for i in range(2, 7):\n for j in range(1, 6):\n rf2_indices.append(i * 7 + j)\n rf2_cells = VGroup(*[input_grid[i] for i in rf2_indices])\n rf2_box = SurroundingRectangle(rf2_cells, color=LAYER2_COLOR, buff=0.02, corner_radius=0.03)\n rf2_box.set_stroke_width(2)\n rf2_highlights.add(rf2_box)\n \n self.play(\n Create(layer2_neurons),\n Create(rf2_highlights),\n run_time=tracker.duration * 0.7\n )\n self.play(\n rf2_cells.animate.set_fill(LAYER2_COLOR, opacity=0.3),\n run_time=tracker.duration * 0.3\n )\n \n with self.voiceover(\n text=\"Now the effective receptive field is larger, about 5 by 5 pixels.\"\n ) as tracker:\n rf2_label = Text(\"5x5 RF\", font_size=14, color=LAYER2_COLOR)\n rf2_label.next_to(rf2_box, UP, buff=0.1)\n self.play(Write(rf2_label), run_time=tracker.duration)\n \n # Layer 3: Large RF (7x7 - full image)\n with self.voiceover(\n text=\"By layer three, the receptive field has grown even more.\"\n ) as tracker:\n layer3_neurons = VGroup()\n \n n3_1 = Circle(radius=0.15, color=LAYER3_COLOR, fill_opacity=0.5)\n n3_1.move_to([4, 0, 0])\n layer3_neurons.add(n3_1)\n \n # Arrows from layer 2 to layer 3\n arrow = Arrow(n2_1.get_right(), n3_1.get_left(), color=LAYER3_COLOR, buff=0.1, stroke_width=1.5)\n layer3_neurons.add(arrow)\n \n self.play(Create(layer3_neurons), run_time=tracker.duration * 0.6)\n \n # Full image RF\n rf3_box = SurroundingRectangle(input_grid, color=LAYER3_COLOR, buff=0.02, corner_radius=0.05)\n rf3_box.set_stroke_width(3)\n \n self.play(\n Create(rf3_box),\n input_grid.animate.set_fill(LAYER3_COLOR, opacity=0.2),\n run_time=tracker.duration * 0.4\n )\n \n with self.voiceover(\n text=\"Now this neuron can see the entire 7 by 7 image! It processes global features and patterns.\"\n ) as tracker:\n rf3_label = Text(\"Full Image RF (7x7)\", font_size=14, color=LAYER3_COLOR)\n rf3_label.next_to(rf3_box, UP, buff=0.1)\n self.play(Write(rf3_label), run_time=tracker.duration)\n \n self.wait(0.5)\n \n # ============================================\n # PART 3: WHY THIS MATTERS\n # ============================================\n with self.voiceover(\n text=\"This hierarchical growth is powerful. Early layers detect simple features.\"\n ) as tracker:\n # Clear and show feature examples\n self.play(\n FadeOut(layer1_neurons),\n FadeOut(layer2_neurons),\n FadeOut(layer3_neurons),\n FadeOut(rf1_boxes),\n FadeOut(rf2_highlights),\n FadeOut(rf2_label),\n FadeOut(rf3_label),\n FadeOut(rf3_box),\n FadeOut(layer1_label),\n FadeOut(layer2_label),\n FadeOut(layer3_label),\n input_grid.animate.set_fill(opacity=0.1),\n run_time=tracker.duration\n )\n \n with self.voiceover(\n text=\"Edges, colors, and basic textures.\"\n ) as tracker:\n # Simple features visualization\n edge_line = Line(LEFT * 0.5, RIGHT * 0.5, color=YELLOW, stroke_width=4)\n edge_line.move_to([2, 1.5, 0])\n edge_label = Text(\"Edges\", font_size=16, color=YELLOW)\n edge_label.next_to(edge_line, DOWN, buff=0.1)\n \n self.play(Create(edge_line), Write(edge_label), run_time=tracker.duration)\n \n with self.voiceover(\n text=\"Deeper layers combine these into complex patterns, like shapes and objects.\"\n ) as tracker:\n # Complex features\n shape = Polygon(\n [2.5, 0.8, 0],\n [3, 0, 0],\n [2.5, -0.8, 0],\n [2, 0, 0],\n color=HIGHLIGHT_COLOR,\n fill_opacity=0.3\n )\n shape_label = Text(\"Shapes\", font_size=16, color=HIGHLIGHT_COLOR)\n shape_label.next_to(shape, DOWN, buff=0.3)\n \n self.play(Create(shape), Write(shape_label), run_time=tracker.duration)\n \n with self.voiceover(\n text=\"And the deepest layers understand entire objects and scenes.\"\n ) as tracker:\n # Scene understanding\n scene_rect = RoundedRectangle(corner_radius=0.2, height=1.2, width=1.5, color=RF_COLOR, fill_opacity=0.2)\n scene_rect.move_to([2, -1.5, 0])\n scene_label = Text(\"Objects & Scenes\", font_size=16, color=RF_COLOR)\n scene_label.next_to(scene_rect, DOWN, buff=0.1)\n \n # Simple cat-like shape\n cat_head = Circle(radius=0.25, color=WHITE, fill_opacity=0.5)\n cat_head.move_to([2, -1.4, 0])\n ear1 = Polygon([1.85, -1.25, 0], [1.9, -1.05, 0], [1.95, -1.25, 0], color=WHITE, fill_opacity=0.5)\n ear2 = Polygon([2.05, -1.25, 0], [2.1, -1.05, 0], [2.15, -1.25, 0], color=WHITE, fill_opacity=0.5)\n \n self.play(\n Create(scene_rect),\n Create(cat_head),\n Create(ear1),\n Create(ear2),\n Write(scene_label),\n run_time=tracker.duration\n )\n \n self.wait(0.5)\n \n # ============================================\n # PART 4: TAKEAWAYS\n # ============================================\n with self.voiceover(\n text=\"Let's summarize the key takeaways about receptive field growth.\"\n ) as tracker:\n # Clear screen\n self.play(\n FadeOut(input_grid),\n FadeOut(input_label),\n FadeOut(edge_line),\n FadeOut(edge_label),\n FadeOut(shape),\n FadeOut(shape_label),\n FadeOut(scene_rect),\n FadeOut(cat_head),\n FadeOut(ear1),\n FadeOut(ear2),\n FadeOut(scene_label),\n run_time=tracker.duration\n )\n \n with self.voiceover(\n text=\"First, receptive fields start small in early layers, processing local information.\"\n ) as tracker:\n takeaway1 = Text(\"1. Early layers: Small receptive fields\", font_size=22, color=LAYER1_COLOR)\n takeaway1.move_to(UP * 1.5)\n self.play(Write(takeaway1), run_time=tracker.duration)\n \n with self.voiceover(\n text=\"Second, they grow progressively larger as we go deeper.\"\n ) as tracker:\n takeaway2 = Text(\"2. Deeper layers: Larger receptive fields\", font_size=22, color=LAYER3_COLOR)\n takeaway2.move_to(UP * 0.5)\n self.play(Write(takeaway2), run_time=tracker.duration)\n \n with self.voiceover(\n text=\"Third, this enables hierarchical feature learning from simple to complex.\"\n ) as tracker:\n takeaway3 = Text(\"3. Hierarchical feature learning\", font_size=22, color=HIGHLIGHT_COLOR)\n takeaway3.move_to(DOWN * 0.5)\n self.play(Write(takeaway3), run_time=tracker.duration)\n \n with self.voiceover(\n text=\"And finally, larger receptive fields help AI models understand global context better.\"\n ) as tracker:\n takeaway4 = Text(\"4. Better global context understanding\", font_size=22, color=RF_COLOR)\n takeaway4.move_to(DOWN * 1.5)\n self.play(Write(takeaway4), run_time=tracker.duration)\n \n # Box all takeaways\n takeaways = VGroup(takeaway1, takeaway2, takeaway3, takeaway4)\n box = SurroundingRectangle(takeaways, color=WHITE, buff=0.3, corner_radius=0.1)\n \n with self.voiceover(\n text=\"Understanding receptive field growth helps us design better neural network architectures.\"\n ) as tracker:\n self.play(Create(box), run_time=tracker.duration)\n \n self.wait(0.5)\n \n with self.voiceover(\n text=\"Thanks for watching!\"\n ) as tracker:\n self.play(FadeOut(takeaways), FadeOut(box), run_time=tracker.duration)\n```", "rejected": "```python\nfrom manim import *\nfrom manim_voiceover import VoiceoverScene\nfrom manim_voiceover.services.gtts import GTTSService\n\n\nclass ReceptiveFieldGrowthScene(VoiceoverScene):\n def construct(self):\n self.set_speech_service(\n GTTSService(voice=\"alba\", cache_dir=\"voiceover_cache\")\n )\n \n # Color scheme\n INPUT_COLOR = \"#4ECDC4\"\n LAYER1_COLOR = \"#45B7D1\"\n LAYER2_COLOR = \"#96CEB4\"\n LAYER3_COLOR = \"#FFEAA7\"\n NEURON_COLOR = \"#DDA0DD\"\n RF_COLOR = \"#FF6B6B\"\n HIGHLIGHT_COLOR = \"#FFD93D\"\n \n # ============================================\n # TITLE AND INTRODUCTION\n # ============================================\n with self.voiceover(\n text=\"Have you ever wondered how neural networks process visual information efficiently?\"\n ) as tracker:\n title = Text(\"Receptive Field Growth\", font_size=48, color=WHITE)\n subtitle = Text(\"in Neural Networks\", font_size=32, color=GRAY)\n subtitle.next_to(title, DOWN, buff=0.3)\n title_group = VGroup(title, subtitle)\n title_group.center()\n self.play(Write(title), run_time=tracker.duration * 0.6)\n self.play(FadeIn(subtitle), run_time=tracker.duration * 0.4)\n \n self.wait(0.5)\n \n with self.voiceover(\n text=\"Receptive fields play a crucial role in how neurons respond to stimuli, growing and adapting across layers.\"\n ) as tracker:\n self.play(FadeOut(title_group), run_time=tracker.duration)\n \n # ============================================\n # PART 1: SINGLE NEURON WITH SMALL RECEPTIVE FIELD\n # ============================================\n with self.voiceover(\n text=\"Let's start with the basics. A single neuron in a neural network doesn't see the entire input image.\"\n ) as tracker:\n # Create input grid representing an image\n input_grid = VGroup()\n for i in range(7):\n for j in range(7):\n cell = Square(side_length=0.35, stroke_width=1, fill_opacity=0.1, fill_color=INPUT_COLOR)\n cell.move_to([i * 0.36 - 1.26, j * 0.36 - 1.26, 0])\n input_grid.add(cell)\n input_label = Text(\"Input Image\", font_size=20, color=INPUT_COLOR)\n input_label.next_to(input_grid, DOWN, buff=0.3)\n input_group = VGroup(input_grid, input_label)\n input_group.move_to(LEFT * 4)\n \n self.play(ShowCreation(input_grid), Write(input_label), run_time=tracker.duration)\n \n with self.voiceover(\n text=\"Instead, it has a receptive field, a specific region of the input it responds to.\"\n ) as tracker:\n # Highlight a small 3x3 receptive field\n rf_cells = VGroup()\n for i in range(2, 5):\n for j in range(2, 5):\n idx = i * 7 + j\n rf_cells.add(input_grid[idx])\n \n # Create surrounding rectangle for receptive field\n rf_box = SurroundingRectangle(rf_cells, color=RF_COLOR, buff=0.02, corner_radius=0.05)\n rf_box.set_stroke_width(3)\n \n rf_label = Text(\"Receptive Field (3x3)\", font_size=16, color=RF_COLOR)\n rf_label.next_to(rf_box, UP, buff=0.15)\n \n self.play(Create(rf_box), Write(rf_label), run_time=tracker.duration * 0.6)\n self.play(\n rf_cells.animate.set_fill(RF_COLOR, opacity=0.4),\n run_time=tracker.duration * 0.4\n )\n \n with self.voiceover(\n text=\"In early layers, this field is small. The neuron only processes local features like edges or corners.\"\n ) as tracker:\n # Add a neuron\n neuron = Circle(radius=0.3, color=NEURON_COLOR, fill_opacity=0.3, fill_color=NEURON_COLOR)\n neuron.move_to(RIGHT * 2)\n neuron_label = Text(\"Neuron\", font_size=18, color=NEURON_COLOR)\n neuron_label.next_to(neuron, DOWN, buff=0.2)\n \n # Arrow from RF to neuron\n arrow = Arrow(rf_box.get_right(), neuron.get_left(), color=WHITE, buff=0.2)\n \n self.play(Create(neuron), Write(neuron_label), run_time=tracker.duration * 0.5)\n self.play(Create(arrow), run_time=tracker.duration * 0.5)\n \n self.wait(0.5)\n \n # ============================================\n # PART 2: RECEPTIVE FIELD GROWS ACROSS LAYERS\n # ============================================\n with self.voiceover(\n text=\"But here's where it gets interesting. As we move deeper into the network, receptive fields grow.\"\n ) as tracker:\n # Fade out current elements\n self.play(\n FadeOut(arrow),\n FadeOut(neuron),\n FadeOut(neuron_label),\n FadeOut(rf_label),\n FadeOut(rf_box),\n input_grid.animate.set_fill(opacity=0.1),\n run_time=tracker.duration\n )\n \n with self.voiceover(\n text=\"Let's visualize this growth across three layers.\"\n ) as tracker:\n # Show layer labels\n layer1_label = Text(\"Layer 1\", font_size=20, color=LAYER1_COLOR)\n layer2_label = Text(\"Layer 2\", font_size=20, color=LAYER2_COLOR)\n layer3_label = Text(\"Layer 3\", font_size=20, color=LAYER3_COLOR)\n \n layer1_label.move_to(RIGHT * 1 + UP * 2.5)\n layer2_label.move_to(RIGHT * 2.5 + UP * 2.5)\n layer3_label.move_to(RIGHT * 4 + UP * 2.5)\n \n self.play(\n Write(layer1_label),\n Write(layer2_label),\n Write(layer3_label),\n run_time=tracker.duration\n )\n \n # Layer 1: Small RF (3x3)\n with self.voiceover(\n text=\"In layer one, each neuron sees a 3 by 3 patch of the input.\"\n ) as tracker:\n # Create small neurons for layer 1\n layer1_neurons = VGroup()\n rf1_boxes = VGroup()\n \n for idx, pos in enumerate([(0.5, 0.5), (0.5, -0.5), (-0.5, 0.5)]):\n n = Circle(radius=0.15, color=LAYER1_COLOR, fill_opacity=0.5)\n n.move_to([1 + pos[0], pos[1], 0])\n layer1_neurons.add(n)\n \n # Show corresponding RF\n rf_center_x = 3 + pos[0] * 2\n rf_center_y = 3 + pos[1] * 2\n rf_indices = []\n for dx in [-1, 0, 1]:\n for dy in [-1, 0, 1]:\n rf_i = int(rf_center_x + dx)\n rf_j = int(rf_center_y + dy)\n if 0 <= rf_i < 7 and 0 <= rf_j < 7:\n rf_indices.append(rf_i * 7 + rf_j)\n \n rf_cells = VGroup(*[input_grid[i] for i in rf_indices])\n rf_box = SurroundingRectangle(rf_cells, color=LAYER1_COLOR, buff=0.02, corner_radius=0.03)\n rf_box.set_stroke_width(2)\n rf1_boxes.add(rf_box)\n \n arrow = Arrow(rf_box.get_right(), n.get_left(), color=LAYER1_COLOR, buff=0.1, stroke_width=2)\n layer1_neurons.add(arrow)\n \n self.play(\n Create(layer1_neurons),\n Create(rf1_boxes),\n run_time=tracker.duration\n )\n \n # Layer 2: Medium RF (5x5 effective)\n with self.voiceover(\n text=\"In layer two, each neuron combines information from multiple layer one neurons.\"\n ) as tracker:\n layer2_neurons = VGroup()\n rf2_highlights = VGroup()\n \n n2_1 = Circle(radius=0.15, color=LAYER2_COLOR, fill_opacity=0.5)\n n2_1.move_to([2.5, 0.3, 0])\n layer2_neurons.add(n2_1)\n \n # Arrows from layer 1 to layer 2\n for n1 in layer1_neurons:\n if isinstance(n1, Circle):\n arrow = Arrow(n1.get_right(), n2_1.get_left(), color=LAYER2_COLOR, buff=0.1, stroke_width=1.5)\n layer2_neurons.add(arrow)\n \n # Show larger effective RF\n rf2_indices = []\n for i in range(2, 7):\n for j in range(1, 6):\n rf2_indices.append(i * 7 + j)\n rf2_cells = VGroup(*[input_grid[i] for i in rf2_indices])\n rf2_box = SurroundingRectangle(rf2_cells, color=LAYER2_COLOR, buff=0.02, corner_radius=0.03)\n rf2_box.set_stroke_width(2)\n rf2_highlights.add(rf2_box)\n \n self.play(\n Create(layer2_neurons),\n Create(rf2_highlights),\n run_time=tracker.duration * 0.7\n )\n self.play(\n rf2_cells.animate.set_fill(LAYER2_COLOR, opacity=0.3),\n run_time=tracker.duration * 0.3\n )\n \n with self.voiceover(\n text=\"Now the effective receptive field is larger, about 5 by 5 pixels.\"\n ) as tracker:\n rf2_label = Text(\"5x5 RF\", font_size=14, color=LAYER2_COLOR)\n rf2_label.next_to(rf2_box, UP, buff=0.1)\n self.play(Write(rf2_label), run_time=tracker.duration)\n \n # Layer 3: Large RF (7x7 - full image)\n with self.voiceover(\n text=\"By layer three, the receptive field has grown even more.\"\n ) as tracker:\n layer3_neurons = VGroup()\n \n n3_1 = Circle(radius=0.15, color=LAYER3_COLOR, fill_opacity=0.5)\n n3_1.move_to([4, 0, 0])\n layer3_neurons.add(n3_1)\n \n # Arrows from layer 2 to layer 3\n arrow = Arrow(n2_1.get_right(), n3_1.get_left(), color=LAYER3_COLOR, buff=0.1, stroke_width=1.5)\n layer3_neurons.add(arrow)\n \n self.play(Create(layer3_neurons), run_time=tracker.duration * 0.6)\n \n # Full image RF\n rf3_box = SurroundingRectangle(input_grid, color=LAYER3_COLOR, buff=0.02, corner_radius=0.05)\n rf3_box.set_stroke_width(3)\n \n self.play(\n Create(rf3_box),\n input_grid.animate.set_fill(LAYER3_COLOR, opacity=0.2),\n run_time=tracker.duration * 0.4\n )\n \n with self.voiceover(\n text=\"Now this neuron can see the entire 7 by 7 image! It processes global features and patterns.\"\n ) as tracker:\n rf3_label = Text(\"Full Image RF (7x7)\", font_size=14, color=LAYER3_COLOR)\n rf3_label.next_to(rf3_box, UP, buff=0.1)\n self.play(Write(rf3_label), run_time=tracker.duration)\n \n self.wait(0.5)\n \n # ============================================\n # PART 3: WHY THIS MATTERS\n # ============================================\n with self.voiceover(\n text=\"This hierarchical growth is powerful. Early layers detect simple features.\"\n ) as tracker:\n # Clear and show feature examples\n self.play(\n FadeOut(layer1_neurons),\n FadeOut(layer2_neurons),\n FadeOut(layer3_neurons),\n FadeOut(rf1_boxes),\n FadeOut(rf2_highlights),\n FadeOut(rf2_label),\n FadeOut(rf3_label),\n FadeOut(rf3_box),\n FadeOut(layer1_label),\n FadeOut(layer2_label),\n FadeOut(layer3_label),\n input_grid.animate.set_fill(opacity=0.1),\n run_time=tracker.duration\n )\n \n with self.voiceover(\n text=\"Edges, colors, and basic textures.\"\n ) as tracker:\n # Simple features visualization\n edge_line = Line(LEFT * 0.5, RIGHT * 0.5, color=YELLOW, stroke_width=4)\n edge_line.move_to([2, 1.5, 0])\n edge_label = Text(\"Edges\", font_size=16, color=YELLOW)\n edge_label.next_to(edge_line, DOWN, buff=0.1)\n \n self.play(Create(edge_line), Write(edge_label), run_time=tracker.duration)\n \n with self.voiceover(\n text=\"Deeper layers combine these into complex patterns, like shapes and objects.\"\n ) as tracker:\n # Complex features\n shape = Polygon(\n [2.5, 0.8, 0],\n [3, 0, 0],\n [2.5, -0.8, 0],\n [2, 0, 0],\n color=HIGHLIGHT_COLOR,\n fill_opacity=0.3\n )\n shape_label = Text(\"Shapes\", font_size=16, color=HIGHLIGHT_COLOR)\n shape_label.next_to(shape, DOWN, buff=0.3)\n \n self.play(Create(shape), Write(shape_label), run_time=tracker.duration)\n \n with self.voiceover(\n text=\"And the deepest layers understand entire objects and scenes.\"\n ) as tracker:\n # Scene understanding\n scene_rect = RoundedRectangle(corner_radius=0.2, height=1.2, width=1.5, color=RF_COLOR, fill_opacity=0.2)\n scene_rect.move_to([2, -1.5, 0])\n scene_label = Text(\"Objects & Scenes\", font_size=16, color=RF_COLOR)\n scene_label.next_to(scene_rect, DOWN, buff=0.1)\n \n # Simple cat-like shape\n cat_head = Circle(radius=0.25, color=WHITE, fill_opacity=0.5)\n cat_head.move_to([2, -1.4, 0])\n ear1 = Polygon([1.85, -1.25, 0], [1.9, -1.05, 0], [1.95, -1.25, 0], color=WHITE, fill_opacity=0.5)\n ear2 = Polygon([2.05, -1.25, 0], [2.1, -1.05, 0], [2.15, -1.25, 0], color=WHITE, fill_opacity=0.5)\n \n self.play(\n Create(scene_rect),\n Create(cat_head),\n Create(ear1),\n Create(ear2),\n Write(scene_label),\n run_time=tracker.duration\n )\n \n self.wait(0.5)\n \n # ============================================\n # PART 4: TAKEAWAYS\n # ============================================\n with self.voiceover(\n text=\"Let's summarize the key takeaways about receptive field growth.\"\n ) as tracker:\n # Clear screen\n self.play(\n FadeOut(input_grid),\n FadeOut(input_label),\n FadeOut(edge_line),\n FadeOut(edge_label),\n FadeOut(shape),\n FadeOut(shape_label),\n FadeOut(scene_rect),\n FadeOut(cat_head),\n FadeOut(ear1),\n FadeOut(ear2),\n FadeOut(scene_label),\n run_time=tracker.duration\n )\n \n with self.voiceover(\n text=\"First, receptive fields start small in early layers, processing local information.\"\n ) as tracker:\n takeaway1 = Text(\"1. Early layers: Small receptive fields\", font_size=22, color=LAYER1_COLOR)\n takeaway1.move_to(UP * 1.5)\n self.play(Write(takeaway1), run_time=tracker.duration)\n \n with self.voiceover(\n text=\"Second, they grow progressively larger as we go deeper.\"\n ) as tracker:\n takeaway2 = Text(\"2. Deeper layers: Larger receptive fields\", font_size=22, color=LAYER3_COLOR)\n takeaway2.move_to(UP * 0.5)\n self.play(Write(takeaway2), run_time=tracker.duration)\n \n with self.voiceover(\n text=\"Third, this enables hierarchical feature learning from simple to complex.\"\n ) as tracker:\n takeaway3 = Text(\"3. Hierarchical feature learning\", font_size=22, color=HIGHLIGHT_COLOR)\n takeaway3.move_to(DOWN * 0.5)\n self.play(Write(takeaway3), run_time=tracker.duration)\n \n with self.voiceover(\n text=\"And finally, larger receptive fields help AI models understand global context better.\"\n ) as tracker:\n takeaway4 = Text(\"4. Better global context understanding\", font_size=22, color=RF_COLOR)\n takeaway4.move_to(DOWN * 1.5)\n self.play(Write(takeaway4), run_time=tracker.duration)\n \n # Box all takeaways\n takeaways = VGroup(takeaway1, takeaway2, takeaway3, takeaway4)\n box = SurroundingRectangle(takeaways, color=WHITE, buff=0.3, corner_radius=0.1)\n \n with self.voiceover(\n text=\"Understanding receptive field growth helps us design better neural network architectures.\"\n ) as tracker:\n self.play(Create(box), run_time=tracker.duration)\n \n self.wait(0.5)\n \n with self.voiceover(\n text=\"Thanks for watching!\"\n ) as tracker:\n self.play(FadeOut(takeaways), FadeOut(box), run_time=tracker.duration)\n```", "category": "legacy_api_hallucination", "source": "synthetic_hard_neg:nabin2004/AOS-Narrated-Manim-400"} +{"system": "You are an expert Manim Community Edition (ManimCE v0.19+) Python developer and mathematical animator. Given a user request, first plan the spatial layout, coordinate bounds, timing, and pedagogical flow inside ... tags (when reasoning is helpful), and then output a complete, runnable, self-contained ManimCE Python script using `from manim import *`. Never use deprecated ManimGL (`manimlib`) methods like `ShowCreation`, `TexMobject`, `TextMobject`, or `axes.get_graph`; always use modern ManimCE APIs (`Create`, `MathTex`, `Tex`, `Text`, `axes.plot`) and prevent visual overlap using `.to_edge()`, `.next_to()`, and `FadeOut`.", "prompt": "I'm teaching undergrad NLP and want to visualize embedding dimension effects.\nShow two training runs: small embedding dimension (underfit) and large dimension (overfit), plotting the training and validation losses over epochs.\nAdd a geometric view of embedding space scatter to illustrate representational capacity differences.", "chosen": "```python\nfrom manim import *\nfrom manim_voiceover import VoiceoverScene\nfrom manim_voiceover.services.gtts import GTTSService\n\n\nclass EmbeddingImpactScene(VoiceoverScene):\n def construct(self):\n self.set_speech_service(\n GTTSService(voice=\"alba\", cache_dir=\"voiceover_cache\")\n )\n \n # Title\n title = Text(\"NLP Embedding Dimension Effects\", font_size=40, color=BLUE)\n title.to_edge(UP, buff=0.5)\n \n with self.voiceover(text=\"Have you ever wondered how the size of an embedding can influence the performance of a natural language processing model?\") as tracker:\n self.play(Write(title), run_time=tracker.duration)\n \n with self.voiceover(text=\"It is fascinating how the right dimension can enhance understanding, while the wrong choice can lead to confusion.\") as tracker:\n self.wait(tracker.duration)\n \n with self.voiceover(text=\"Today, we will dive into the impact of embedding dimensions on NLP model performance!\") as tracker:\n self.wait(tracker.duration)\n \n # Clear title for next section\n self.play(FadeOut(title))\n \n # Section: What are Embeddings?\n section_title = Text(\"What are Word Embeddings?\", font_size=36, color=YELLOW)\n section_title.to_edge(UP, buff=0.5)\n \n with self.voiceover(text=\"Word embeddings are numerical representations of words in a continuous vector space.\") as tracker:\n self.play(Write(section_title), run_time=tracker.duration)\n \n # Create a visual representation of word embeddings\n words = [\"king\", \"queen\", \"man\", \"woman\"]\n word_group = VGroup()\n \n for word in words:\n word_text = Text(f'\"{word}\"', font_size=24)\n word_group.add(word_text)\n \n word_group.arrange(DOWN, buff=0.5)\n word_group.shift(LEFT * 3)\n \n with self.voiceover(text=\"Words like king, queen, man, and woman are converted into dense vectors.\") as tracker:\n self.play(Write(word_group), run_time=tracker.duration)\n \n # Show embedding vectors of different dimensions\n low_dim_box = Rectangle(width=2, height=0.5, color=GREEN)\n low_dim_box.shift(RIGHT * 2 + UP * 1.5)\n low_dim_label = Text(\"Low Dim (50D)\", font_size=20, color=GREEN)\n low_dim_label.next_to(low_dim_box, UP, buff=0.2)\n \n mid_dim_box = Rectangle(width=3, height=0.5, color=YELLOW)\n mid_dim_box.shift(RIGHT * 2.5)\n mid_dim_label = Text(\"Medium Dim (300D)\", font_size=20, color=YELLOW)\n mid_dim_label.next_to(mid_dim_box, UP, buff=0.2)\n \n high_dim_box = Rectangle(width=4.5, height=0.5, color=RED)\n high_dim_box.shift(RIGHT * 3.25 + DOWN * 1.5)\n high_dim_label = Text(\"High Dim (1000D+)\", font_size=20, color=RED)\n high_dim_label.next_to(high_dim_box, UP, buff=0.2)\n \n arrow_low = Arrow(word_group.get_right(), low_dim_box.get_left(), color=WHITE)\n arrow_mid = Arrow(word_group.get_right(), mid_dim_box.get_left(), color=WHITE)\n arrow_high = Arrow(word_group.get_right(), high_dim_box.get_left(), color=WHITE)\n \n with self.voiceover(text=\"Embeddings can have different dimensions, from low dimensional like 50, to medium like 300, to very high dimensions over 1000.\") as tracker:\n self.play(\n Create(low_dim_box), Write(low_dim_label),\n Create(mid_dim_box), Write(mid_dim_label),\n Create(high_dim_box), Write(high_dim_label),\n Create(arrow_low), Create(arrow_mid), Create(arrow_high),\n run_time=tracker.duration\n )\n \n self.wait(0.5)\n self.play(\n FadeOut(section_title), FadeOut(word_group),\n FadeOut(low_dim_box), FadeOut(low_dim_label),\n FadeOut(mid_dim_box), FadeOut(mid_dim_label),\n FadeOut(high_dim_box), FadeOut(high_dim_label),\n FadeOut(arrow_low), FadeOut(arrow_mid), FadeOut(arrow_high)\n )\n \n # Section: Accuracy Formula\n acc_title = Text(\"Model Accuracy\", font_size=36, color=GREEN)\n acc_title.to_edge(UP, buff=0.5)\n \n with self.voiceover(text=\"Let us look at how we measure model performance. Accuracy is a key metric.\") as tracker:\n self.play(Write(acc_title), run_time=tracker.duration)\n \n # Use Text instead of MathTex to avoid LaTeX issues\n accuracy_formula = Text(\"Accuracy = TP / (TP + FN)\", font_size=36, color=WHITE)\n accuracy_formula.move_to(UP * 0.5)\n \n with self.voiceover(text=\"Accuracy equals true positives divided by the sum of true positives and false negatives.\") as tracker:\n self.play(Write(accuracy_formula), run_time=tracker.duration)\n \n tp_explanation = Text(\"TP = True Positives (correct predictions)\", font_size=22, color=GREEN)\n tp_explanation.next_to(accuracy_formula, DOWN, buff=0.8)\n \n fn_explanation = Text(\"FN = False Negatives (missed correct answers)\", font_size=22, color=RED)\n fn_explanation.next_to(tp_explanation, DOWN, buff=0.3)\n \n with self.voiceover(text=\"True positives are correct predictions, while false negatives are answers we missed.\") as tracker:\n self.play(Write(tp_explanation), Write(fn_explanation), run_time=tracker.duration)\n \n self.wait(0.5)\n self.play(\n FadeOut(acc_title), FadeOut(accuracy_formula),\n FadeOut(tp_explanation), FadeOut(fn_explanation)\n )\n \n # Section: Error Rate Formula\n err_title = Text(\"Error Rate\", font_size=36, color=RED)\n err_title.to_edge(UP, buff=0.5)\n \n with self.voiceover(text=\"Another important metric is the error rate.\") as tracker:\n self.play(Write(err_title), run_time=tracker.duration)\n \n # Use Text instead of MathTex\n error_formula = Text(\"Error Rate = (FP + FN) / Total\", font_size=36, color=WHITE)\n error_formula.move_to(UP * 0.5)\n \n with self.voiceover(text=\"Error rate equals false positives plus false negatives, divided by the total number of predictions.\") as tracker:\n self.play(Write(error_formula), run_time=tracker.duration)\n \n fp_explanation = Text(\"FP = False Positives (incorrect positive predictions)\", font_size=22, color=ORANGE)\n fp_explanation.next_to(error_formula, DOWN, buff=0.8)\n \n total_explanation = Text(\"Total = Total number of samples\", font_size=22, color=BLUE)\n total_explanation.next_to(fp_explanation, DOWN, buff=0.3)\n \n with self.voiceover(text=\"False positives are incorrect positive predictions, and we divide by the total sample count.\") as tracker:\n self.play(Write(fp_explanation), Write(total_explanation), run_time=tracker.duration)\n \n self.wait(0.5)\n self.play(\n FadeOut(err_title), FadeOut(error_formula),\n FadeOut(fp_explanation), FadeOut(total_explanation)\n )\n \n # Section: Dimension Trade-offs\n trade_title = Text(\"Dimension Trade-offs\", font_size=36, color=PURPLE)\n trade_title.to_edge(UP, buff=0.5)\n \n with self.voiceover(text=\"Now, let us explore the trade-offs between different embedding dimensions.\") as tracker:\n self.play(Write(trade_title), run_time=tracker.duration)\n \n # Create comparison table - using two columns layout\n low_dim_title = Text(\"Low Dimension (50-100)\", font_size=22, color=GREEN)\n low_dim_title.shift(LEFT * 3.5 + UP * 1.5)\n \n low_pros = VGroup(\n Text(\"✓ Fast training\", font_size=18, color=GREEN),\n Text(\"✓ Less memory\", font_size=18, color=GREEN),\n Text(\"✗ Less expressive\", font_size=18, color=RED),\n Text(\"✗ Lower accuracy\", font_size=18, color=RED)\n ).arrange(DOWN, buff=0.2)\n low_pros.next_to(low_dim_title, DOWN, buff=0.3)\n low_pros.shift(LEFT * 3.5)\n \n high_dim_title = Text(\"High Dimension (500+)\", font_size=22, color=BLUE)\n high_dim_title.shift(RIGHT * 3.5 + UP * 1.5)\n \n high_pros = VGroup(\n Text(\"✓ Highly expressive\", font_size=18, color=GREEN),\n Text(\"✓ Better accuracy\", font_size=18, color=GREEN),\n Text(\"✗ Slow training\", font_size=18, color=RED),\n Text(\"✗ More memory\", font_size=18, color=RED)\n ).arrange(DOWN, buff=0.2)\n high_pros.next_to(high_dim_title, DOWN, buff=0.3)\n high_pros.shift(RIGHT * 3.5)\n \n with self.voiceover(text=\"Low dimensions offer fast training and less memory usage, but they are less expressive and may yield lower accuracy.\") as tracker:\n self.play(Write(low_dim_title), Write(low_pros), run_time=tracker.duration)\n \n with self.voiceover(text=\"High dimensions are highly expressive and can achieve better accuracy, but require more memory and training time.\") as tracker:\n self.play(Write(high_dim_title), Write(high_pros), run_time=tracker.duration)\n \n self.wait(0.5)\n \n # Show optimal point\n optimal_text = Text(\"Optimal: 100-300 dimensions\", font_size=24, color=YELLOW)\n optimal_text.move_to(DOWN * 2)\n \n with self.voiceover(text=\"Research suggests that 100 to 300 dimensions often provides the best balance for many NLP tasks.\") as tracker:\n self.play(Write(optimal_text), run_time=tracker.duration)\n \n self.wait(0.5)\n self.play(\n FadeOut(trade_title),\n FadeOut(low_dim_title), FadeOut(low_pros),\n FadeOut(high_dim_title), FadeOut(high_pros),\n FadeOut(optimal_text)\n )\n \n # Learning Outcomes Summary\n outcomes_title = Text(\"Learning Outcomes\", font_size=36, color=BLUE)\n outcomes_title.to_edge(UP, buff=0.5)\n \n with self.voiceover(text=\"Let us summarize what we have learned today.\") as tracker:\n self.play(Write(outcomes_title), run_time=tracker.duration)\n \n outcomes = VGroup(\n Text(\"1. Identify optimal embedding dimensions\", font_size=24),\n Text(\"2. Evaluate high vs low dimensional effects\", font_size=24),\n Text(\"3. Apply knowledge to improve your models\", font_size=24)\n ).arrange(DOWN, buff=0.5)\n outcomes.move_to(DOWN * 0.5)\n \n with self.voiceover(text=\"You can now identify optimal embedding dimensions for specific applications.\") as tracker:\n self.play(Write(outcomes[0]), run_time=tracker.duration * 0.4)\n \n with self.voiceover(text=\"You can evaluate the effects of high versus low dimensional embeddings on accuracy.\") as tracker:\n self.play(Write(outcomes[1]), run_time=tracker.duration * 0.4)\n \n with self.voiceover(text=\"And you can apply this knowledge of embedding dimensions to improve your NLP models.\") as tracker:\n self.play(Write(outcomes[2]), run_time=tracker.duration * 0.4)\n \n self.wait(1)\n \n # Closing\n closing = Text(\"Thank you for learning with us!\", font_size=32, color=GREEN)\n closing.move_to(DOWN * 2.5)\n \n with self.voiceover(text=\"Thank you for learning with us today!\") as tracker:\n self.play(Write(closing), run_time=tracker.duration)\n \n self.wait(2)\n```", "rejected": "```python\nfrom manim import *\nfrom manim_voiceover import VoiceoverScene\nfrom manim_voiceover.services.gtts import GTTSService\n\n\nclass EmbeddingImpactScene(VoiceoverScene):\n def construct(self):\n self.set_speech_service(\n GTTSService(voice=\"alba\", cache_dir=\"voiceover_cache\")\n )\n \n # Title\n title = Text(\"NLP Embedding Dimension Effects\", font_size=40, color=BLUE)\n title.to_edge(UP, buff=0.5)\n \n with self.voiceover(text=\"Have you ever wondered how the size of an embedding can influence the performance of a natural language processing model?\") as tracker:\n self.play(Write(title), run_time=tracker.duration)\n \n with self.voiceover(text=\"It is fascinating how the right dimension can enhance understanding, while the wrong choice can lead to confusion.\") as tracker:\n self.wait(tracker.duration)\n \n with self.voiceover(text=\"Today, we will dive into the impact of embedding dimensions on NLP model performance!\") as tracker:\n self.wait(tracker.duration)\n \n # Clear title for next section\n self.play(FadeOut(title))\n \n # Section: What are Embeddings?\n section_title = Text(\"What are Word Embeddings?\", font_size=36, color=YELLOW)\n section_title.to_edge(UP, buff=0.5)\n \n with self.voiceover(text=\"Word embeddings are numerical representations of words in a continuous vector space.\") as tracker:\n self.play(Write(section_title), run_time=tracker.duration)\n \n # Create a visual representation of word embeddings\n words = [\"king\", \"queen\", \"man\", \"woman\"]\n word_group = VGroup()\n \n for word in words:\n word_text = Text(f'\"{word}\"', font_size=24)\n word_group.add(word_text)\n \n word_group.arrange(DOWN, buff=0.5)\n word_group.shift(LEFT * 3)\n \n with self.voiceover(text=\"Words like king, queen, man, and woman are converted into dense vectors.\") as tracker:\n self.play(Write(word_group), run_time=tracker.duration)\n \n # Show embedding vectors of different dimensions\n low_dim_box = Rectangle(width=2, height=0.5, color=GREEN)\n low_dim_box.shift(RIGHT * 2 + UP * 1.5)\n low_dim_label = Text(\"Low Dim (50D)\", font_size=20, color=GREEN)\n low_dim_label.next_to(low_dim_box, UP, buff=0.2)\n \n mid_dim_box = Rectangle(width=3, height=0.5, color=YELLOW)\n mid_dim_box.shift(RIGHT * 2.5)\n mid_dim_label = Text(\"Medium Dim (300D)\", font_size=20, color=YELLOW)\n mid_dim_label.next_to(mid_dim_box, UP, buff=0.2)\n \n high_dim_box = Rectangle(width=4.5, height=0.5, color=RED)\n high_dim_box.shift(RIGHT * 3.25 + DOWN * 1.5)\n high_dim_label = Text(\"High Dim (1000D+)\", font_size=20, color=RED)\n high_dim_label.next_to(high_dim_box, UP, buff=0.2)\n \n arrow_low = Arrow(word_group.get_right(), low_dim_box.get_left(), color=WHITE)\n arrow_mid = Arrow(word_group.get_right(), mid_dim_box.get_left(), color=WHITE)\n arrow_high = Arrow(word_group.get_right(), high_dim_box.get_left(), color=WHITE)\n \n with self.voiceover(text=\"Embeddings can have different dimensions, from low dimensional like 50, to medium like 300, to very high dimensions over 1000.\") as tracker:\n self.play(\n ShowCreation(low_dim_box), Write(low_dim_label),\n Create(mid_dim_box), Write(mid_dim_label),\n Create(high_dim_box), Write(high_dim_label),\n Create(arrow_low), Create(arrow_mid), Create(arrow_high),\n run_time=tracker.duration\n )\n \n self.wait(0.5)\n self.play(\n FadeOut(section_title), FadeOut(word_group),\n FadeOut(low_dim_box), FadeOut(low_dim_label),\n FadeOut(mid_dim_box), FadeOut(mid_dim_label),\n FadeOut(high_dim_box), FadeOut(high_dim_label),\n FadeOut(arrow_low), FadeOut(arrow_mid), FadeOut(arrow_high)\n )\n \n # Section: Accuracy Formula\n acc_title = Text(\"Model Accuracy\", font_size=36, color=GREEN)\n acc_title.to_edge(UP, buff=0.5)\n \n with self.voiceover(text=\"Let us look at how we measure model performance. Accuracy is a key metric.\") as tracker:\n self.play(Write(acc_title), run_time=tracker.duration)\n \n # Use Text instead of MathTex to avoid LaTeX issues\n accuracy_formula = Text(\"Accuracy = TP / (TP + FN)\", font_size=36, color=WHITE)\n accuracy_formula.move_to(UP * 0.5)\n \n with self.voiceover(text=\"Accuracy equals true positives divided by the sum of true positives and false negatives.\") as tracker:\n self.play(Write(accuracy_formula), run_time=tracker.duration)\n \n tp_explanation = Text(\"TP = True Positives (correct predictions)\", font_size=22, color=GREEN)\n tp_explanation.next_to(accuracy_formula, DOWN, buff=0.8)\n \n fn_explanation = Text(\"FN = False Negatives (missed correct answers)\", font_size=22, color=RED)\n fn_explanation.next_to(tp_explanation, DOWN, buff=0.3)\n \n with self.voiceover(text=\"True positives are correct predictions, while false negatives are answers we missed.\") as tracker:\n self.play(Write(tp_explanation), Write(fn_explanation), run_time=tracker.duration)\n \n self.wait(0.5)\n self.play(\n FadeOut(acc_title), FadeOut(accuracy_formula),\n FadeOut(tp_explanation), FadeOut(fn_explanation)\n )\n \n # Section: Error Rate Formula\n err_title = Text(\"Error Rate\", font_size=36, color=RED)\n err_title.to_edge(UP, buff=0.5)\n \n with self.voiceover(text=\"Another important metric is the error rate.\") as tracker:\n self.play(Write(err_title), run_time=tracker.duration)\n \n # Use Text instead of MathTex\n error_formula = Text(\"Error Rate = (FP + FN) / Total\", font_size=36, color=WHITE)\n error_formula.move_to(UP * 0.5)\n \n with self.voiceover(text=\"Error rate equals false positives plus false negatives, divided by the total number of predictions.\") as tracker:\n self.play(Write(error_formula), run_time=tracker.duration)\n \n fp_explanation = Text(\"FP = False Positives (incorrect positive predictions)\", font_size=22, color=ORANGE)\n fp_explanation.next_to(error_formula, DOWN, buff=0.8)\n \n total_explanation = Text(\"Total = Total number of samples\", font_size=22, color=BLUE)\n total_explanation.next_to(fp_explanation, DOWN, buff=0.3)\n \n with self.voiceover(text=\"False positives are incorrect positive predictions, and we divide by the total sample count.\") as tracker:\n self.play(Write(fp_explanation), Write(total_explanation), run_time=tracker.duration)\n \n self.wait(0.5)\n self.play(\n FadeOut(err_title), FadeOut(error_formula),\n FadeOut(fp_explanation), FadeOut(total_explanation)\n )\n \n # Section: Dimension Trade-offs\n trade_title = Text(\"Dimension Trade-offs\", font_size=36, color=PURPLE)\n trade_title.to_edge(UP, buff=0.5)\n \n with self.voiceover(text=\"Now, let us explore the trade-offs between different embedding dimensions.\") as tracker:\n self.play(Write(trade_title), run_time=tracker.duration)\n \n # Create comparison table - using two columns layout\n low_dim_title = Text(\"Low Dimension (50-100)\", font_size=22, color=GREEN)\n low_dim_title.shift(LEFT * 3.5 + UP * 1.5)\n \n low_pros = VGroup(\n Text(\"✓ Fast training\", font_size=18, color=GREEN),\n Text(\"✓ Less memory\", font_size=18, color=GREEN),\n Text(\"✗ Less expressive\", font_size=18, color=RED),\n Text(\"✗ Lower accuracy\", font_size=18, color=RED)\n ).arrange(DOWN, buff=0.2)\n low_pros.next_to(low_dim_title, DOWN, buff=0.3)\n low_pros.shift(LEFT * 3.5)\n \n high_dim_title = Text(\"High Dimension (500+)\", font_size=22, color=BLUE)\n high_dim_title.shift(RIGHT * 3.5 + UP * 1.5)\n \n high_pros = VGroup(\n Text(\"✓ Highly expressive\", font_size=18, color=GREEN),\n Text(\"✓ Better accuracy\", font_size=18, color=GREEN),\n Text(\"✗ Slow training\", font_size=18, color=RED),\n Text(\"✗ More memory\", font_size=18, color=RED)\n ).arrange(DOWN, buff=0.2)\n high_pros.next_to(high_dim_title, DOWN, buff=0.3)\n high_pros.shift(RIGHT * 3.5)\n \n with self.voiceover(text=\"Low dimensions offer fast training and less memory usage, but they are less expressive and may yield lower accuracy.\") as tracker:\n self.play(Write(low_dim_title), Write(low_pros), run_time=tracker.duration)\n \n with self.voiceover(text=\"High dimensions are highly expressive and can achieve better accuracy, but require more memory and training time.\") as tracker:\n self.play(Write(high_dim_title), Write(high_pros), run_time=tracker.duration)\n \n self.wait(0.5)\n \n # Show optimal point\n optimal_text = Text(\"Optimal: 100-300 dimensions\", font_size=24, color=YELLOW)\n optimal_text.move_to(DOWN * 2)\n \n with self.voiceover(text=\"Research suggests that 100 to 300 dimensions often provides the best balance for many NLP tasks.\") as tracker:\n self.play(Write(optimal_text), run_time=tracker.duration)\n \n self.wait(0.5)\n self.play(\n FadeOut(trade_title),\n FadeOut(low_dim_title), FadeOut(low_pros),\n FadeOut(high_dim_title), FadeOut(high_pros),\n FadeOut(optimal_text)\n )\n \n # Learning Outcomes Summary\n outcomes_title = Text(\"Learning Outcomes\", font_size=36, color=BLUE)\n outcomes_title.to_edge(UP, buff=0.5)\n \n with self.voiceover(text=\"Let us summarize what we have learned today.\") as tracker:\n self.play(Write(outcomes_title), run_time=tracker.duration)\n \n outcomes = VGroup(\n Text(\"1. Identify optimal embedding dimensions\", font_size=24),\n Text(\"2. Evaluate high vs low dimensional effects\", font_size=24),\n Text(\"3. Apply knowledge to improve your models\", font_size=24)\n ).arrange(DOWN, buff=0.5)\n outcomes.move_to(DOWN * 0.5)\n \n with self.voiceover(text=\"You can now identify optimal embedding dimensions for specific applications.\") as tracker:\n self.play(Write(outcomes[0]), run_time=tracker.duration * 0.4)\n \n with self.voiceover(text=\"You can evaluate the effects of high versus low dimensional embeddings on accuracy.\") as tracker:\n self.play(Write(outcomes[1]), run_time=tracker.duration * 0.4)\n \n with self.voiceover(text=\"And you can apply this knowledge of embedding dimensions to improve your NLP models.\") as tracker:\n self.play(Write(outcomes[2]), run_time=tracker.duration * 0.4)\n \n self.wait(1)\n \n # Closing\n closing = Text(\"Thank you for learning with us!\", font_size=32, color=GREEN)\n closing.move_to(DOWN * 2.5)\n \n with self.voiceover(text=\"Thank you for learning with us today!\") as tracker:\n self.play(Write(closing), run_time=tracker.duration)\n \n self.wait(2)\n```", "category": "legacy_api_hallucination", "source": "synthetic_hard_neg:nabin2004/AOS-Narrated-Manim-400"} +{"system": "You are an expert Manim Community Edition (ManimCE v0.19+) Python developer and mathematical animator. Given a user request, first plan the spatial layout, coordinate bounds, timing, and pedagogical flow inside ... tags (when reasoning is helpful), and then output a complete, runnable, self-contained ManimCE Python script using `from manim import *`. Never use deprecated ManimGL (`manimlib`) methods like `ShowCreation`, `TexMobject`, `TextMobject`, or `axes.get_graph`; always use modern ManimCE APIs (`Create`, `MathTex`, `Tex`, `Text`, `axes.plot`) and prevent visual overlap using `.to_edge()`, `.next_to()`, and `FadeOut`.", "prompt": "The following Manim CE script crashed with this traceback:\n\n```text\nTypeError: Mobject.__init__() got an unexpected keyword argument 'element_color'\n```\n\nFix the bug and provide the corrected, fully compilable Manim CE code:\n\n```python\nfrom manim import *\nimport numpy as np\n\nclass ApiValidBarChart306(Scene):\n def construct(self):\n m = Matrix([[1, 2]], element_color=RED)\n obj = BarChart(values=[2, 4, 3, 5], bar_names=['A', 'B', 'C', 'D'], y_range=[0, 6, 2], y_length=4, x_length=6)\n obj.set_color(BLUE)\n self.play(Create(obj))\n self.wait(1)\n```", "chosen": "```python\nfrom manim import *\nfrom manim_voiceover import VoiceoverScene\nfrom manim_voiceover.services.gtts import GTTSService\nimport numpy as np\n\nMARGIN = 0.5\n\nclass ApiValidBarChart306(VoiceoverScene):\n def fit_in_frame(self, mob: Mobject, w_frac=0.9, h_frac=0.9) -> Mobject:\n max_w = config.frame_width * w_frac\n max_h = config.frame_height * h_frac\n if mob.width > max_w:\n mob.width = max_w\n if mob.height > max_h:\n mob.height = max_h\n return mob\n\n def construct(self):\n self.set_speech_service(GTTSService(transcription_model=\"base\"))\n \n # [SETUP]\n # [LAYOUT]\n m = Matrix([[1, 2]], left_bracket='[', right_bracket=']').to_edge(UP)\n m.set_color(RED)\n obj = BarChart(values=[2, 4, 3, 5], bar_names=['A', 'B', 'C', 'D'], y_range=[0, 6, 2], y_length=4, x_length=6)\n obj.set_color(BLUE)\n \n group = VGroup(m, obj)\n group = self.fit_in_frame(group)\n self.add(m)\n \n # [UPDATER]\n # [BEAT 1 | sync: b1]\n with self.voiceover(text=\"We initialize a matrix and a bar chart. \") as t:\n self.wait_until_bookmark(\"b1\")\n self.play(Create(obj))\n self.wait(1)\n \n # [BEAT 2 | sync: b2]\n with self.voiceover(text=\"Notice the clean setup without deprecated arguments. \") as t:\n self.wait_until_bookmark(\"b2\")\n self.wait(1)\n```", "rejected": "```python\nfrom manim import *\nfrom manim_voiceover import VoiceoverScene\nfrom manim_voiceover.services.gtts import GTTSService\nimport numpy as np\n\nMARGIN = 0.5\n\nclass ApiValidBarChart306(VoiceoverScene):\n def fit_in_frame(self, mob: Mobject, w_frac=0.9, h_frac=0.9) -> Mobject:\n max_w = config.frame_width * w_frac\n max_h = config.frame_height * h_frac\n if mob.width > max_w:\n mob.width = max_w\n if mob.height > max_h:\n mob.height = max_h\n return mob\n\n def construct(self):\n self.set_speech_service(GTTSService(transcription_model=\"base\"))\n \n # [SETUP]\n # [LAYOUT]\n m = Matrix([[1, 2]], left_bracket='[', right_bracket=']').to_edge(UP)\n m.set_color(RED)\n obj = BarChart(values=[2, 4, 3, 5], bar_names=['A', 'B', 'C', 'D'], y_range=[0, 6, 2], y_length=4, x_length=6)\n obj.set_color(BLUE)\n \n group = VGroup(m, obj)\n group = self.fit_in_frame(group)\n self.add(m)\n \n # [UPDATER]\n # [BEAT 1 | sync: b1]\n with self.voiceover(text=\"We initialize a matrix and a bar chart. \") as t:\n self.wait_until_bookmark(\"b1\")\n self.play(ShowCreation(obj))\n self.wait(1)\n \n # [BEAT 2 | sync: b2]\n with self.voiceover(text=\"Notice the clean setup without deprecated arguments. \") as t:\n self.wait_until_bookmark(\"b2\")\n self.wait(1)\n```", "category": "legacy_api_hallucination", "source": "synthetic_hard_neg:nabin2004/qwen3-8b-manimator-gold-sft"} +{"system": "You are an expert Manim Community Edition (ManimCE v0.19+) Python developer and mathematical animator. Given a user request, first plan the spatial layout, coordinate bounds, timing, and pedagogical flow inside ... tags (when reasoning is helpful), and then output a complete, runnable, self-contained ManimCE Python script using `from manim import *`. Never use deprecated ManimGL (`manimlib`) methods like `ShowCreation`, `TexMobject`, `TextMobject`, or `axes.get_graph`; always use modern ManimCE APIs (`Create`, `MathTex`, `Tex`, `Text`, `axes.plot`) and prevent visual overlap using `.to_edge()`, `.next_to()`, and `FadeOut`.", "prompt": "Curious about eigenvalues and eigenvectors? I want a geometric visualization for a 2x2 matrix: animate the plane under the linear map, highlight eigen-directions and their scaling, and compare with non-eigen directions. Then visualize the quadratic form x^T A x as a 3D surface and contours to show how eigenvalues shape the ridges. I'd like a quick intuition before the equations, and a brief discussion of diagonalizable vs non-diagonalizable cases with a real-world analogy.", "chosen": "```python\nfrom manim import *\nfrom manim_voiceover import VoiceoverScene\nfrom manim_voiceover.services.gtts import GTTSService\n\nclass EigenvalueVisualization(VoiceoverScene):\n def construct(self):\n self.set_speech_service(\n GTTSService(voice=\"alba\", cache_dir=\"voiceover_cache\")\n )\n \n # Title - use Text instead of MathTex\n title = Text(\"Eigenvalues & Eigenvectors\", font_size=40)\n subtitle = Text(\"Geometric Meaning\", font_size=28, color=BLUE_B)\n title_group = VGroup(title, subtitle).arrange(DOWN, buff=0.3)\n title_group.to_edge(UP, buff=0.5)\n \n with self.voiceover(text=\"Have you ever wondered how certain matrices can stretch or flip vectors in space, while keeping their direction intact? Let's unlock this geometric mystery together!\") as tracker:\n self.play(Write(title), run_time=1.5)\n self.play(FadeIn(subtitle), run_time=1)\n self.wait(tracker.duration - 2.5)\n \n self.play(FadeOut(title_group))\n \n # Set up the coordinate system\n plane = NumberPlane(\n x_range=[-6, 6, 1],\n y_range=[-4, 4, 1],\n background_line_style={\n \"stroke_color\": BLUE_D,\n \"stroke_width\": 1,\n \"stroke_opacity\": 0.3,\n },\n )\n axes = Axes(\n x_range=[-6, 6, 1],\n y_range=[-4, 4, 1],\n axis_config={\"include_tip\": True, \"numbers_to_exclude\": [0]},\n )\n \n with self.voiceover(text=\"We begin with our coordinate plane, ready to explore how vectors transform.\") as tracker:\n self.play(Create(plane), run_time=1.5)\n self.play(Create(axes), run_time=1.5)\n \n # Define our transformation matrix using plain text\n matrix_A = [[2, 1], [0, 3]]\n matrix_tex = Text(\"A = [[2, 1], [0, 3]]\", font_size=24, font=\"Courier New\")\n matrix_tex.to_corner(UL, buff=0.5)\n \n with self.voiceover(text=\"Consider this transformation matrix A. It contains the recipe for stretching and rotating space.\") as tracker:\n self.play(Write(matrix_tex), run_time=1.5)\n \n # First, show a random vector being transformed\n random_vec_start = np.array([2, 1, 0])\n random_vec_end = np.array([2*2 + 1, 1*3, 0]) # [5, 3]\n \n vector_v = Arrow(ORIGIN, random_vec_start, buff=0, color=YELLOW, stroke_width=3)\n label_v = Text(\"v\", color=YELLOW, font_size=24).next_to(vector_v.get_end(), UR, buff=0.1)\n \n with self.voiceover(text=\"When we apply this transformation to any ordinary vector, both its length and direction change.\") as tracker:\n self.play(GrowArrow(vector_v), FadeIn(label_v), run_time=2)\n self.wait(0.5)\n \n # Show transformed vector\n vector_v2 = Arrow(ORIGIN, random_vec_end, buff=0, color=ORANGE, stroke_width=3)\n label_v2 = Text(\"A·v\", color=ORANGE, font_size=24).next_to(vector_v2.get_end(), UR, buff=0.1)\n \n with self.voiceover(text=\"The orange vector shows the result. Notice how it rotated and stretched.\") as tracker:\n self.play(Transform(vector_v, vector_v2), Transform(label_v, label_v2), run_time=2)\n \n self.play(FadeOut(vector_v), FadeOut(label_v))\n \n # Now show eigenvector 1: [1, 0] with eigenvalue 2\n ev1 = np.array([3, 0, 0])\n eigenvec1 = Arrow(ORIGIN, ev1, buff=0, color=GREEN, stroke_width=4)\n label_e1 = Text(\"v1\", color=GREEN, font_size=24).next_to(eigenvec1.get_end(), DOWN, buff=0.15)\n \n with self.voiceover(text=\"But watch this special vector. Its direction is along the x-axis.\") as tracker:\n self.play(GrowArrow(eigenvec1), FadeIn(label_e1), run_time=2)\n \n # After transformation: [1, 0] -> [2, 0], scaled by 2\n ev1_transformed = np.array([6, 0, 0])\n eigenvec1_t = Arrow(ORIGIN, ev1_transformed, buff=0, color=RED, stroke_width=4)\n label_e1_t = Text(\"A·v1 = 2·v1\", color=RED, font_size=22).next_to(eigenvec1_t.get_end(), DOWN, buff=0.15)\n \n with self.voiceover(text=\"After transformation, it stretches by a factor of two, but stays on the horizontal line. The direction is preserved!\") as tracker:\n self.play(Transform(eigenvec1, eigenvec1_t), Transform(label_e1, label_e1_t), run_time=2)\n \n self.wait(0.5)\n \n # Show eigenvalue formula for first one - using text\n eq1 = Text(\"A·v = λ·v\", font_size=24, color=WHITE)\n eq1.to_corner(UR, buff=0.5)\n \n with self.voiceover(text=\"This is the defining equation. The vector v is an eigenvector, and the scaling factor, lambda equals 2, is the eigenvalue.\") as tracker:\n self.play(Write(eq1), run_time=1.5)\n \n self.play(FadeOut(eigenvec1), FadeOut(label_e1))\n \n # Now show eigenvector 2: [1, 1] with eigenvalue 3\n ev2 = np.array([2, 2, 0])\n eigenvec2 = Arrow(ORIGIN, ev2, buff=0, color=GREEN, stroke_width=4)\n label_e2 = Text(\"v2\", color=GREEN, font_size=24).next_to(eigenvec2.get_end(), UR, buff=0.1)\n \n with self.voiceover(text=\"Here's another special vector, pointing along the diagonal. Watch what happens to it.\") as tracker:\n self.play(GrowArrow(eigenvec2), FadeIn(label_e2), run_time=2)\n \n # After transformation: [1, 1] -> [3, 3], scaled by 3\n ev2_transformed = np.array([2.5, 2.5, 0])\n eigenvec2_t = Arrow(ORIGIN, ev2_transformed, buff=0, color=PURPLE, stroke_width=4)\n label_e2_t = Text(\"A·v2 = 3·v2\", color=PURPLE, font_size=22).next_to(eigenvec2_t.get_end(), UR, buff=0.1)\n \n with self.voiceover(text=\"It stretches by a factor of three, again keeping its direction along the diagonal. The eigenvalue here is three.\") as tracker:\n self.play(Transform(eigenvec2, eigenvec2_t), Transform(label_e2, label_e2_t), run_time=2)\n \n # Show second eigenvalue formula\n eq2 = Text(\"A·v = 3·v\", font_size=24, color=WHITE)\n eq2.to_corner(UR, buff=0.5)\n \n with self.voiceover(text=\"So this second eigenvector has eigenvalue lambda equals three.\") as tracker:\n self.play(ReplacementTransform(eq1, eq2), run_time=1.5)\n \n # Summary: Show both together\n eigenvec1_copy = Arrow(ORIGIN, np.array([3, 0, 0]), buff=0, color=GREEN_B, stroke_width=3)\n eigenvec2_copy = Arrow(ORIGIN, np.array([2, 2, 0]), buff=0, color=GREEN_C, stroke_width=3)\n \n labels = VGroup(\n Text(\"v1\", color=GREEN_B, font_size=22),\n Text(\"v2\", color=GREEN_C, font_size=22),\n )\n labels[0].next_to(eigenvec1_copy.get_end(), DOWN, buff=0.1)\n labels[1].next_to(eigenvec2_copy.get_end(), UR, buff=0.1)\n \n with self.voiceover(text=\"These special vectors that resist rotation are called eigenvectors. They only scale. The scaling factors are the eigenvalues.\") as tracker:\n self.play(\n FadeOut(eigenvec2), FadeOut(label_e2), FadeOut(eq2),\n FadeIn(eigenvec1_copy), FadeIn(eigenvec2_copy), FadeIn(labels),\n run_time=2\n )\n \n # Final summary box using Text\n summary_title = Text(\"Key Takeaways:\", font_size=24, weight=BOLD)\n summary_item1 = Text(\"• A·v = λ·v (eigenvalue equation)\", font_size=20)\n summary_item2 = Text(\"• Eigenvectors: direction preserved\", font_size=20)\n summary_item3 = Text(\"• Eigenvalues (λ): scaling factor\", font_size=20)\n summary_item4 = Text(\"• Natural axes of transformation\", font_size=20)\n \n summary_group = VGroup(summary_title, summary_item1, summary_item2, summary_item3, summary_item4)\n summary_group.arrange(DOWN, aligned_edge=LEFT, buff=0.25)\n summary_box = SurroundingRectangle(summary_group, color=YELLOW, buff=0.3, corner_radius=0.1)\n summary_with_box = VGroup(summary_group, summary_box)\n summary_with_box.to_corner(DL, buff=0.4)\n summary_with_box.scale_to_fit_height(3)\n \n with self.voiceover(text=\"To summarize: eigenvectors are vectors that, when transformed by a matrix, only scale by their eigenvalues. They reveal the matrix's fundamental stretching directions.\") as tracker:\n self.play(FadeIn(summary_with_box), run_time=2)\n \n self.wait(1)\n \n with self.voiceover(text=\"Understanding eigenvalues and eigenvectors means seeing beyond the numbers, to the geometric heart of linear transformations.\") as tracker:\n self.wait(tracker.duration)\n \n self.wait(2)\n```", "rejected": "```python\nfrom manim import *\nfrom manim_voiceover import VoiceoverScene\nfrom manim_voiceover.services.gtts import GTTSService\n\nclass EigenvalueVisualization(VoiceoverScene):\n def construct(self):\n self.set_speech_service(\n GTTSService(voice=\"alba\", cache_dir=\"voiceover_cache\")\n )\n \n # Title - use Text instead of MathTex\n title = Text(\"Eigenvalues & Eigenvectors\", font_size=40)\n subtitle = Text(\"Geometric Meaning\", font_size=28, color=BLUE_B)\n title_group = VGroup(title, subtitle).arrange(DOWN, buff=0.3)\n title_group.to_edge(UP, buff=0.5)\n \n with self.voiceover(text=\"Have you ever wondered how certain matrices can stretch or flip vectors in space, while keeping their direction intact? Let's unlock this geometric mystery together!\") as tracker:\n self.play(Write(title), run_time=1.5)\n self.play(FadeIn(subtitle), run_time=1)\n self.wait(tracker.duration - 2.5)\n \n self.play(FadeOut(title_group))\n \n # Set up the coordinate system\n plane = NumberPlane(\n x_range=[-6, 6, 1],\n y_range=[-4, 4, 1],\n background_line_style={\n \"stroke_color\": BLUE_D,\n \"stroke_width\": 1,\n \"stroke_opacity\": 0.3,\n },\n )\n axes = Axes(axis_color=BLUE, \n x_range=[-6, 6, 1],\n y_range=[-4, 4, 1],\n axis_config={\"include_tip\": True, \"numbers_to_exclude\": [0]},\n )\n \n with self.voiceover(text=\"We begin with our coordinate plane, ready to explore how vectors transform.\") as tracker:\n self.play(Create(plane), run_time=1.5)\n self.play(Create(axes), run_time=1.5)\n \n # Define our transformation matrix using plain text\n matrix_A = [[2, 1], [0, 3]]\n matrix_tex = Text(\"A = [[2, 1], [0, 3]]\", font_size=24, font=\"Courier New\")\n matrix_tex.to_corner(UL, buff=0.5)\n \n with self.voiceover(text=\"Consider this transformation matrix A. It contains the recipe for stretching and rotating space.\") as tracker:\n self.play(Write(matrix_tex), run_time=1.5)\n \n # First, show a random vector being transformed\n random_vec_start = np.array([2, 1, 0])\n random_vec_end = np.array([2*2 + 1, 1*3, 0]) # [5, 3]\n \n vector_v = Arrow(ORIGIN, random_vec_start, buff=0, color=YELLOW, stroke_width=3)\n label_v = Text(\"v\", color=YELLOW, font_size=24).next_to(vector_v.get_end(), UR, buff=0.1)\n \n with self.voiceover(text=\"When we apply this transformation to any ordinary vector, both its length and direction change.\") as tracker:\n self.play(GrowArrow(vector_v), FadeIn(label_v), run_time=2)\n self.wait(0.5)\n \n # Show transformed vector\n vector_v2 = Arrow(ORIGIN, random_vec_end, buff=0, color=ORANGE, stroke_width=3)\n label_v2 = Text(\"A·v\", color=ORANGE, font_size=24).next_to(vector_v2.get_end(), UR, buff=0.1)\n \n with self.voiceover(text=\"The orange vector shows the result. Notice how it rotated and stretched.\") as tracker:\n self.play(Transform(vector_v, vector_v2), Transform(label_v, label_v2), run_time=2)\n \n self.play(FadeOut(vector_v), FadeOut(label_v))\n \n # Now show eigenvector 1: [1, 0] with eigenvalue 2\n ev1 = np.array([3, 0, 0])\n eigenvec1 = Arrow(ORIGIN, ev1, buff=0, color=GREEN, stroke_width=4)\n label_e1 = Text(\"v1\", color=GREEN, font_size=24).next_to(eigenvec1.get_end(), DOWN, buff=0.15)\n \n with self.voiceover(text=\"But watch this special vector. Its direction is along the x-axis.\") as tracker:\n self.play(GrowArrow(eigenvec1), FadeIn(label_e1), run_time=2)\n \n # After transformation: [1, 0] -> [2, 0], scaled by 2\n ev1_transformed = np.array([6, 0, 0])\n eigenvec1_t = Arrow(ORIGIN, ev1_transformed, buff=0, color=RED, stroke_width=4)\n label_e1_t = Text(\"A·v1 = 2·v1\", color=RED, font_size=22).next_to(eigenvec1_t.get_end(), DOWN, buff=0.15)\n \n with self.voiceover(text=\"After transformation, it stretches by a factor of two, but stays on the horizontal line. The direction is preserved!\") as tracker:\n self.play(Transform(eigenvec1, eigenvec1_t), Transform(label_e1, label_e1_t), run_time=2)\n \n self.wait(0.5)\n \n # Show eigenvalue formula for first one - using text\n eq1 = Text(\"A·v = λ·v\", font_size=24, color=WHITE)\n eq1.to_corner(UR, buff=0.5)\n \n with self.voiceover(text=\"This is the defining equation. The vector v is an eigenvector, and the scaling factor, lambda equals 2, is the eigenvalue.\") as tracker:\n self.play(Write(eq1), run_time=1.5)\n \n self.play(FadeOut(eigenvec1), FadeOut(label_e1))\n \n # Now show eigenvector 2: [1, 1] with eigenvalue 3\n ev2 = np.array([2, 2, 0])\n eigenvec2 = Arrow(ORIGIN, ev2, buff=0, color=GREEN, stroke_width=4)\n label_e2 = Text(\"v2\", color=GREEN, font_size=24).next_to(eigenvec2.get_end(), UR, buff=0.1)\n \n with self.voiceover(text=\"Here's another special vector, pointing along the diagonal. Watch what happens to it.\") as tracker:\n self.play(GrowArrow(eigenvec2), FadeIn(label_e2), run_time=2)\n \n # After transformation: [1, 1] -> [3, 3], scaled by 3\n ev2_transformed = np.array([2.5, 2.5, 0])\n eigenvec2_t = Arrow(ORIGIN, ev2_transformed, buff=0, color=PURPLE, stroke_width=4)\n label_e2_t = Text(\"A·v2 = 3·v2\", color=PURPLE, font_size=22).next_to(eigenvec2_t.get_end(), UR, buff=0.1)\n \n with self.voiceover(text=\"It stretches by a factor of three, again keeping its direction along the diagonal. The eigenvalue here is three.\") as tracker:\n self.play(Transform(eigenvec2, eigenvec2_t), Transform(label_e2, label_e2_t), run_time=2)\n \n # Show second eigenvalue formula\n eq2 = Text(\"A·v = 3·v\", font_size=24, color=WHITE)\n eq2.to_corner(UR, buff=0.5)\n \n with self.voiceover(text=\"So this second eigenvector has eigenvalue lambda equals three.\") as tracker:\n self.play(ReplacementTransform(eq1, eq2), run_time=1.5)\n \n # Summary: Show both together\n eigenvec1_copy = Arrow(ORIGIN, np.array([3, 0, 0]), buff=0, color=GREEN_B, stroke_width=3)\n eigenvec2_copy = Arrow(ORIGIN, np.array([2, 2, 0]), buff=0, color=GREEN_C, stroke_width=3)\n \n labels = VGroup(\n Text(\"v1\", color=GREEN_B, font_size=22),\n Text(\"v2\", color=GREEN_C, font_size=22),\n )\n labels[0].next_to(eigenvec1_copy.get_end(), DOWN, buff=0.1)\n labels[1].next_to(eigenvec2_copy.get_end(), UR, buff=0.1)\n \n with self.voiceover(text=\"These special vectors that resist rotation are called eigenvectors. They only scale. The scaling factors are the eigenvalues.\") as tracker:\n self.play(\n FadeOut(eigenvec2), FadeOut(label_e2), FadeOut(eq2),\n FadeIn(eigenvec1_copy), FadeIn(eigenvec2_copy), FadeIn(labels),\n run_time=2\n )\n \n # Final summary box using Text\n summary_title = Text(\"Key Takeaways:\", font_size=24, weight=BOLD)\n summary_item1 = Text(\"• A·v = λ·v (eigenvalue equation)\", font_size=20)\n summary_item2 = Text(\"• Eigenvectors: direction preserved\", font_size=20)\n summary_item3 = Text(\"• Eigenvalues (λ): scaling factor\", font_size=20)\n summary_item4 = Text(\"• Natural axes of transformation\", font_size=20)\n \n summary_group = VGroup(summary_title, summary_item1, summary_item2, summary_item3, summary_item4)\n summary_group.arrange(DOWN, aligned_edge=LEFT, buff=0.25)\n summary_box = SurroundingRectangle(summary_group, color=YELLOW, buff=0.3, corner_radius=0.1)\n summary_with_box = VGroup(summary_group, summary_box)\n summary_with_box.to_corner(DL, buff=0.4)\n summary_with_box.scale_to_fit_height(3)\n \n with self.voiceover(text=\"To summarize: eigenvectors are vectors that, when transformed by a matrix, only scale by their eigenvalues. They reveal the matrix's fundamental stretching directions.\") as tracker:\n self.play(FadeIn(summary_with_box), run_time=2)\n \n self.wait(1)\n \n with self.voiceover(text=\"Understanding eigenvalues and eigenvectors means seeing beyond the numbers, to the geometric heart of linear transformations.\") as tracker:\n self.wait(tracker.duration)\n \n self.wait(2)\n```", "category": "invalid_axes_kwarg", "source": "synthetic_hard_neg:nabin2004/AOS-Narrated-Manim-400"} +{"system": "You are an expert Manim Community Edition (ManimCE v0.19+) Python developer and mathematical animator. Given a user request, first plan the spatial layout, coordinate bounds, timing, and pedagogical flow inside ... tags (when reasoning is helpful), and then output a complete, runnable, self-contained ManimCE Python script using `from manim import *`. Never use deprecated ManimGL (`manimlib`) methods like `ShowCreation`, `TexMobject`, `TextMobject`, or `axes.get_graph`; always use modern ManimCE APIs (`Create`, `MathTex`, `Tex`, `Text`, `axes.plot`) and prevent visual overlap using `.to_edge()`, `.next_to()`, and `FadeOut`.", "prompt": "Curious about eigenvalues and eigenvectors? I want a geometric visualization for a 2x2 matrix: animate the plane under the linear map, highlight eigen-directions and their scaling, and compare with non-eigen directions. Then visualize the quadratic form x^T A x as a 3D surface and contours to show how eigenvalues shape the ridges. I'd like a quick intuition before the equations, and a brief discussion of diagonalizable vs non-diagonalizable cases with a real-world analogy.", "chosen": "```python\nfrom manim import *\nfrom manim_voiceover import VoiceoverScene\nfrom manim_voiceover.services.gtts import GTTSService\n\nclass EigenvalueVisualization(VoiceoverScene):\n def construct(self):\n self.set_speech_service(\n GTTSService(voice=\"alba\", cache_dir=\"voiceover_cache\")\n )\n \n # Title - use Text instead of MathTex\n title = Text(\"Eigenvalues & Eigenvectors\", font_size=40)\n subtitle = Text(\"Geometric Meaning\", font_size=28, color=BLUE_B)\n title_group = VGroup(title, subtitle).arrange(DOWN, buff=0.3)\n title_group.to_edge(UP, buff=0.5)\n \n with self.voiceover(text=\"Have you ever wondered how certain matrices can stretch or flip vectors in space, while keeping their direction intact? Let's unlock this geometric mystery together!\") as tracker:\n self.play(Write(title), run_time=1.5)\n self.play(FadeIn(subtitle), run_time=1)\n self.wait(tracker.duration - 2.5)\n \n self.play(FadeOut(title_group))\n \n # Set up the coordinate system\n plane = NumberPlane(\n x_range=[-6, 6, 1],\n y_range=[-4, 4, 1],\n background_line_style={\n \"stroke_color\": BLUE_D,\n \"stroke_width\": 1,\n \"stroke_opacity\": 0.3,\n },\n )\n axes = Axes(\n x_range=[-6, 6, 1],\n y_range=[-4, 4, 1],\n axis_config={\"include_tip\": True, \"numbers_to_exclude\": [0]},\n )\n \n with self.voiceover(text=\"We begin with our coordinate plane, ready to explore how vectors transform.\") as tracker:\n self.play(Create(plane), run_time=1.5)\n self.play(Create(axes), run_time=1.5)\n \n # Define our transformation matrix using plain text\n matrix_A = [[2, 1], [0, 3]]\n matrix_tex = Text(\"A = [[2, 1], [0, 3]]\", font_size=24, font=\"Courier New\")\n matrix_tex.to_corner(UL, buff=0.5)\n \n with self.voiceover(text=\"Consider this transformation matrix A. It contains the recipe for stretching and rotating space.\") as tracker:\n self.play(Write(matrix_tex), run_time=1.5)\n \n # First, show a random vector being transformed\n random_vec_start = np.array([2, 1, 0])\n random_vec_end = np.array([2*2 + 1, 1*3, 0]) # [5, 3]\n \n vector_v = Arrow(ORIGIN, random_vec_start, buff=0, color=YELLOW, stroke_width=3)\n label_v = Text(\"v\", color=YELLOW, font_size=24).next_to(vector_v.get_end(), UR, buff=0.1)\n \n with self.voiceover(text=\"When we apply this transformation to any ordinary vector, both its length and direction change.\") as tracker:\n self.play(GrowArrow(vector_v), FadeIn(label_v), run_time=2)\n self.wait(0.5)\n \n # Show transformed vector\n vector_v2 = Arrow(ORIGIN, random_vec_end, buff=0, color=ORANGE, stroke_width=3)\n label_v2 = Text(\"A·v\", color=ORANGE, font_size=24).next_to(vector_v2.get_end(), UR, buff=0.1)\n \n with self.voiceover(text=\"The orange vector shows the result. Notice how it rotated and stretched.\") as tracker:\n self.play(Transform(vector_v, vector_v2), Transform(label_v, label_v2), run_time=2)\n \n self.play(FadeOut(vector_v), FadeOut(label_v))\n \n # Now show eigenvector 1: [1, 0] with eigenvalue 2\n ev1 = np.array([3, 0, 0])\n eigenvec1 = Arrow(ORIGIN, ev1, buff=0, color=GREEN, stroke_width=4)\n label_e1 = Text(\"v1\", color=GREEN, font_size=24).next_to(eigenvec1.get_end(), DOWN, buff=0.15)\n \n with self.voiceover(text=\"But watch this special vector. Its direction is along the x-axis.\") as tracker:\n self.play(GrowArrow(eigenvec1), FadeIn(label_e1), run_time=2)\n \n # After transformation: [1, 0] -> [2, 0], scaled by 2\n ev1_transformed = np.array([6, 0, 0])\n eigenvec1_t = Arrow(ORIGIN, ev1_transformed, buff=0, color=RED, stroke_width=4)\n label_e1_t = Text(\"A·v1 = 2·v1\", color=RED, font_size=22).next_to(eigenvec1_t.get_end(), DOWN, buff=0.15)\n \n with self.voiceover(text=\"After transformation, it stretches by a factor of two, but stays on the horizontal line. The direction is preserved!\") as tracker:\n self.play(Transform(eigenvec1, eigenvec1_t), Transform(label_e1, label_e1_t), run_time=2)\n \n self.wait(0.5)\n \n # Show eigenvalue formula for first one - using text\n eq1 = Text(\"A·v = λ·v\", font_size=24, color=WHITE)\n eq1.to_corner(UR, buff=0.5)\n \n with self.voiceover(text=\"This is the defining equation. The vector v is an eigenvector, and the scaling factor, lambda equals 2, is the eigenvalue.\") as tracker:\n self.play(Write(eq1), run_time=1.5)\n \n self.play(FadeOut(eigenvec1), FadeOut(label_e1))\n \n # Now show eigenvector 2: [1, 1] with eigenvalue 3\n ev2 = np.array([2, 2, 0])\n eigenvec2 = Arrow(ORIGIN, ev2, buff=0, color=GREEN, stroke_width=4)\n label_e2 = Text(\"v2\", color=GREEN, font_size=24).next_to(eigenvec2.get_end(), UR, buff=0.1)\n \n with self.voiceover(text=\"Here's another special vector, pointing along the diagonal. Watch what happens to it.\") as tracker:\n self.play(GrowArrow(eigenvec2), FadeIn(label_e2), run_time=2)\n \n # After transformation: [1, 1] -> [3, 3], scaled by 3\n ev2_transformed = np.array([2.5, 2.5, 0])\n eigenvec2_t = Arrow(ORIGIN, ev2_transformed, buff=0, color=PURPLE, stroke_width=4)\n label_e2_t = Text(\"A·v2 = 3·v2\", color=PURPLE, font_size=22).next_to(eigenvec2_t.get_end(), UR, buff=0.1)\n \n with self.voiceover(text=\"It stretches by a factor of three, again keeping its direction along the diagonal. The eigenvalue here is three.\") as tracker:\n self.play(Transform(eigenvec2, eigenvec2_t), Transform(label_e2, label_e2_t), run_time=2)\n \n # Show second eigenvalue formula\n eq2 = Text(\"A·v = 3·v\", font_size=24, color=WHITE)\n eq2.to_corner(UR, buff=0.5)\n \n with self.voiceover(text=\"So this second eigenvector has eigenvalue lambda equals three.\") as tracker:\n self.play(ReplacementTransform(eq1, eq2), run_time=1.5)\n \n # Summary: Show both together\n eigenvec1_copy = Arrow(ORIGIN, np.array([3, 0, 0]), buff=0, color=GREEN_B, stroke_width=3)\n eigenvec2_copy = Arrow(ORIGIN, np.array([2, 2, 0]), buff=0, color=GREEN_C, stroke_width=3)\n \n labels = VGroup(\n Text(\"v1\", color=GREEN_B, font_size=22),\n Text(\"v2\", color=GREEN_C, font_size=22),\n )\n labels[0].next_to(eigenvec1_copy.get_end(), DOWN, buff=0.1)\n labels[1].next_to(eigenvec2_copy.get_end(), UR, buff=0.1)\n \n with self.voiceover(text=\"These special vectors that resist rotation are called eigenvectors. They only scale. The scaling factors are the eigenvalues.\") as tracker:\n self.play(\n FadeOut(eigenvec2), FadeOut(label_e2), FadeOut(eq2),\n FadeIn(eigenvec1_copy), FadeIn(eigenvec2_copy), FadeIn(labels),\n run_time=2\n )\n \n # Final summary box using Text\n summary_title = Text(\"Key Takeaways:\", font_size=24, weight=BOLD)\n summary_item1 = Text(\"• A·v = λ·v (eigenvalue equation)\", font_size=20)\n summary_item2 = Text(\"• Eigenvectors: direction preserved\", font_size=20)\n summary_item3 = Text(\"• Eigenvalues (λ): scaling factor\", font_size=20)\n summary_item4 = Text(\"• Natural axes of transformation\", font_size=20)\n \n summary_group = VGroup(summary_title, summary_item1, summary_item2, summary_item3, summary_item4)\n summary_group.arrange(DOWN, aligned_edge=LEFT, buff=0.25)\n summary_box = SurroundingRectangle(summary_group, color=YELLOW, buff=0.3, corner_radius=0.1)\n summary_with_box = VGroup(summary_group, summary_box)\n summary_with_box.to_corner(DL, buff=0.4)\n summary_with_box.scale_to_fit_height(3)\n \n with self.voiceover(text=\"To summarize: eigenvectors are vectors that, when transformed by a matrix, only scale by their eigenvalues. They reveal the matrix's fundamental stretching directions.\") as tracker:\n self.play(FadeIn(summary_with_box), run_time=2)\n \n self.wait(1)\n \n with self.voiceover(text=\"Understanding eigenvalues and eigenvectors means seeing beyond the numbers, to the geometric heart of linear transformations.\") as tracker:\n self.wait(tracker.duration)\n \n self.wait(2)\n```", "rejected": "```python\nfrom manim import *\n\nclass EigenvalueVisualization(Scene):\n\n def construct(self):\n title = Text('Eigenvalues & Eigenvectors', font_size=40)\n subtitle = Text('Geometric Meaning', font_size=28, color=BLUE_B)\n title_group = VGroup(title, subtitle).arrange(DOWN, buff=0.3)\n title_group.to_edge(UP, buff=0.5)\n self.play(Write(title), run_time=1.5)\n self.play(FadeIn(subtitle), run_time=1)\n self.wait(2.0 - 2.5)\n self.play(FadeOut(title_group))\n plane = NumberPlane(x_range=[-6, 6, 1], y_range=[-4, 4, 1], background_line_style={'stroke_color': BLUE_D, 'stroke_width': 1, 'stroke_opacity': 0.3})\n axes = Axes(x_range=[-6, 6, 1], y_range=[-4, 4, 1], axis_config={'include_tip': True, 'numbers_to_exclude': [0]})\n self.play(Create(plane), run_time=1.5)\n self.play(Create(axes), run_time=1.5)\n matrix_A = [[2, 1], [0, 3]]\n matrix_tex = Text('A = [[2, 1], [0, 3]]', font_size=24, font='Courier New')\n matrix_tex.to_corner(UL, buff=0.5)\n self.play(Write(matrix_tex), run_time=1.5)\n random_vec_start = np.array([2, 1, 0])\n random_vec_end = np.array([2 * 2 + 1, 1 * 3, 0])\n vector_v = Arrow(ORIGIN, random_vec_start, buff=0, color=YELLOW, stroke_width=3)\n label_v = Text('v', color=YELLOW, font_size=24).next_to(vector_v.get_end(), UR, buff=0.1)\n self.play(GrowArrow(vector_v), FadeIn(label_v), run_time=2)\n self.wait(0.5)\n vector_v2 = Arrow(ORIGIN, random_vec_end, buff=0, color=ORANGE, stroke_width=3)\n label_v2 = Text('A·v', color=ORANGE, font_size=24).next_to(vector_v2.get_end(), UR, buff=0.1)\n self.play(Transform(vector_v, vector_v2), Transform(label_v, label_v2), run_time=2)\n self.play(FadeOut(vector_v), FadeOut(label_v))\n ev1 = np.array([3, 0, 0])\n eigenvec1 = Arrow(ORIGIN, ev1, buff=0, color=GREEN, stroke_width=4)\n label_e1 = Text('v1', color=GREEN, font_size=24).next_to(eigenvec1.get_end(), DOWN, buff=0.15)\n self.play(GrowArrow(eigenvec1), FadeIn(label_e1), run_time=2)\n ev1_transformed = np.array([6, 0, 0])\n eigenvec1_t = Arrow(ORIGIN, ev1_transformed, buff=0, color=RED, stroke_width=4)\n label_e1_t = Text('A·v1 = 2·v1', color=RED, font_size=22).next_to(eigenvec1_t.get_end(), DOWN, buff=0.15)\n self.play(Transform(eigenvec1, eigenvec1_t), Transform(label_e1, label_e1_t), run_time=2)\n self.wait(0.5)\n eq1 = Text('A·v = λ·v', font_size=24, color=WHITE)\n eq1.to_corner(UR, buff=0.5)\n self.play(Write(eq1), run_time=1.5)\n self.play(FadeOut(eigenvec1), FadeOut(label_e1))\n ev2 = np.array([2, 2, 0])\n eigenvec2 = Arrow(ORIGIN, ev2, buff=0, color=GREEN, stroke_width=4)\n label_e2 = Text('v2', color=GREEN, font_size=24).next_to(eigenvec2.get_end(), UR, buff=0.1)\n self.play(GrowArrow(eigenvec2), FadeIn(label_e2), run_time=2)\n ev2_transformed = np.array([2.5, 2.5, 0])\n eigenvec2_t = Arrow(ORIGIN, ev2_transformed, buff=0, color=PURPLE, stroke_width=4)\n label_e2_t = Text('A·v2 = 3·v2', color=PURPLE, font_size=22).next_to(eigenvec2_t.get_end(), UR, buff=0.1)\n self.play(Transform(eigenvec2, eigenvec2_t), Transform(label_e2, label_e2_t), run_time=2)\n eq2 = Text('A·v = 3·v', font_size=24, color=WHITE)\n eq2.to_corner(UR, buff=0.5)\n self.play(ReplacementTransform(eq1, eq2), run_time=1.5)\n eigenvec1_copy = Arrow(ORIGIN, np.array([3, 0, 0]), buff=0, color=GREEN_B, stroke_width=3)\n eigenvec2_copy = Arrow(ORIGIN, np.array([2, 2, 0]), buff=0, color=GREEN_C, stroke_width=3)\n labels = VGroup(Text('v1', color=GREEN_B, font_size=22), Text('v2', color=GREEN_C, font_size=22))\n labels[0].next_to(eigenvec1_copy.get_end(), DOWN, buff=0.1)\n labels[1].next_to(eigenvec2_copy.get_end(), UR, buff=0.1)\n self.play(FadeOut(eigenvec2), FadeOut(label_e2), FadeOut(eq2), FadeIn(eigenvec1_copy), FadeIn(eigenvec2_copy), FadeIn(labels), run_time=2)\n summary_title = Text('Key Takeaways:', font_size=24, weight=BOLD)\n summary_item1 = Text('• A·v = λ·v (eigenvalue equation)', font_size=20)\n summary_item2 = Text('• Eigenvectors: direction preserved', font_size=20)\n summary_item3 = Text('• Eigenvalues (λ): scaling factor', font_size=20)\n summary_item4 = Text('• Natural axes of transformation', font_size=20)\n summary_group = VGroup(summary_title, summary_item1, summary_item2, summary_item3, summary_item4)\n summary_group.arrange(DOWN, aligned_edge=LEFT, buff=0.25)\n summary_box = SurroundingRectangle(summary_group, color=YELLOW, buff=0.3, corner_radius=0.1)\n summary_with_box = VGroup(summary_group, summary_box)\n summary_with_box.to_corner(DL, buff=0.4)\n summary_with_box.scale_to_fit_height(3)\n self.play(FadeIn(summary_with_box), run_time=2)\n self.wait(1)\n self.wait(2.0)\n self.wait(2)\n```", "category": "narrated_pedagogical_preference", "source": "nabin2004/manim-narrated-dpo-400"} +{"system": "You are an expert Manim Community Edition (ManimCE v0.19+) Python developer and mathematical animator. Given a user request, first plan the spatial layout, coordinate bounds, timing, and pedagogical flow inside ... tags (when reasoning is helpful), and then output a complete, runnable, self-contained ManimCE Python script using `from manim import *`. Never use deprecated ManimGL (`manimlib`) methods like `ShowCreation`, `TexMobject`, `TextMobject`, or `axes.get_graph`; always use modern ManimCE APIs (`Create`, `MathTex`, `Tex`, `Text`, `axes.plot`) and prevent visual overlap using `.to_edge()`, `.next_to()`, and `FadeOut`.", "prompt": "Create a step-by-step educational Manim CE lecture scene explaining: Gradient Descent Optimization on 2D Quadratic Function.\n\n```python\nfrom manim import *\nimport numpy as np\n\nclass PedagogicalScene795(Scene):\n def construct(self):\n title = Title(r\"Gradient Descent: $x_{k+1} = x_k - \\gamma \\nabla f(x_k)$\")\n ax = Axes(x_range=[-3, 3, 1], y_range=[0, 9, 3], x_length=6, y_length=4)\n parabola = ax.plot(lambda x: x**2, color=BLUE)\n \n gamma = 0.4\n x_val = 2.5\n dot = Dot(ax.c2p(x_val, x_val**2), color=RED)\n \n self.play(Write(title), Create(ax), Create(parabola), FadeIn(dot))\n for step in range(5):\n grad = 2 * x_val\n next_x = x_val - gamma * grad\n arrow = Arrow(ax.c2p(x_val, x_val**2), ax.c2p(next_x, next_x**2), color=YELLOW, buff=0)\n self.play(GrowArrow(arrow), dot.animate.move_to(ax.c2p(next_x, next_x**2)), run_time=0.8)\n self.remove(arrow)\n x_val = next_x\n self.wait(1)\n```", "chosen": "```python\nfrom manim import *\nfrom manim_voiceover import VoiceoverScene\nfrom manim_voiceover.services.gtts import GTTSService\nimport numpy as np\n\nMARGIN = 0.5\n\nclass PedagogicalScene795(VoiceoverScene):\n def fit_in_frame(self, mob: Mobject, w_frac=0.9, h_frac=0.9) -> Mobject:\n max_w = config.frame_width * w_frac\n max_h = config.frame_height * h_frac\n if mob.width > max_w:\n mob.width = max_w\n if mob.height > max_h:\n mob.height = max_h\n return mob\n\n def construct(self):\n self.set_speech_service(GTTSService(transcription_model=\"base\"))\n \n # [SETUP]\n title = Title(r\"Gradient Descent: $x_{k+1} = x_k - \\gamma \\nabla f(x_k)$\")\n ax = Axes(x_range=[-3, 3, 1], y_range=[0, 9, 3], x_length=6, y_length=4)\n parabola = ax.plot(lambda x: x**2, color=BLUE)\n \n gamma = 0.4\n x_val = 2.5\n dot = Dot(ax.c2p(x_val, x_val**2), color=RED)\n \n # [LAYOUT]\n group = VGroup(title, ax, parabola, dot)\n group = self.fit_in_frame(group)\n self.add(title, ax, parabola, dot)\n \n # [UPDATER]\n # [BEAT 1 | sync: b1]\n with self.voiceover(text=\"We visualize gradient descent on a quadratic function. \") as t:\n self.wait_until_bookmark(\"b1\")\n self.wait(1)\n \n # [BEAT 2 | sync: b2]\n with self.voiceover(text=\"The dot moves towards the minimum by taking steps proportional to the negative gradient. \") as t:\n self.wait_until_bookmark(\"b2\")\n for step in range(5):\n grad = 2 * x_val\n next_x = x_val - gamma * grad\n arrow = Arrow(ax.c2p(x_val, x_val**2), ax.c2p(next_x, next_x**2), color=YELLOW, buff=0)\n self.play(GrowArrow(arrow), dot.animate.move_to(ax.c2p(next_x, next_x**2)), run_time=0.8)\n self.remove(arrow)\n x_val = next_x\n self.wait(1)\n```", "rejected": "```python\nfrom manim import *\nfrom manim_voiceover import VoiceoverScene\nfrom manim_voiceover.services.gtts import GTTSService\nimport numpy as np\n\nMARGIN = 0.5\n\nclass PedagogicalScene795(VoiceoverScene):\n def fit_in_frame(self, mob: Mobject, w_frac=0.9, h_frac=0.9) -> Mobject:\n max_w = config.frame_width * w_frac\n max_h = config.frame_height * h_frac\n if mob.width > max_w:\n mob.width = max_w\n if mob.height > max_h:\n mob.height = max_h\n return mob\n\n def construct(self):\n self.set_speech_service(GTTSService(transcription_model=\"base\"))\n \n # [SETUP]\n title = Title(r\"Gradient Descent: $x_{k+1} = x_k - \\gamma \\nabla f(x_k)$\")\n ax = Axes(x_range=[-3, 3, 1], y_range=[0, 9, 3], x_length=6, y_length=4)\n parabola = ax.get_graph(lambda x: x**2, color=BLUE)\n \n gamma = 0.4\n x_val = 2.5\n dot = Dot(ax.c2p(x_val, x_val**2), color=RED)\n \n # [LAYOUT]\n group = VGroup(title, ax, parabola, dot)\n group = self.fit_in_frame(group)\n self.add(title, ax, parabola, dot)\n \n # [UPDATER]\n # [BEAT 1 | sync: b1]\n with self.voiceover(text=\"We visualize gradient descent on a quadratic function. \") as t:\n self.wait_until_bookmark(\"b1\")\n self.wait(1)\n \n # [BEAT 2 | sync: b2]\n with self.voiceover(text=\"The dot moves towards the minimum by taking steps proportional to the negative gradient. \") as t:\n self.wait_until_bookmark(\"b2\")\n for step in range(5):\n grad = 2 * x_val\n next_x = x_val - gamma * grad\n arrow = Arrow(ax.c2p(x_val, x_val**2), ax.c2p(next_x, next_x**2), color=YELLOW, buff=0)\n self.play(GrowArrow(arrow), dot.animate.move_to(ax.c2p(next_x, next_x**2)), run_time=0.8)\n self.remove(arrow)\n x_val = next_x\n self.wait(1)\n```", "category": "legacy_api_hallucination", "source": "synthetic_hard_neg:nabin2004/qwen3-8b-manimator-gold-sft"} +{"system": "You are an expert Manim Community Edition (ManimCE v0.19+) Python developer and mathematical animator. Given a user request, first plan the spatial layout, coordinate bounds, timing, and pedagogical flow inside ... tags (when reasoning is helpful), and then output a complete, runnable, self-contained ManimCE Python script using `from manim import *`. Never use deprecated ManimGL (`manimlib`) methods like `ShowCreation`, `TexMobject`, `TextMobject`, or `axes.get_graph`; always use modern ManimCE APIs (`Create`, `MathTex`, `Tex`, `Text`, `axes.plot`) and prevent visual overlap using `.to_edge()`, `.next_to()`, and `FadeOut`.", "prompt": "Create an interactive Manim CE animation demonstrating: Cycloid Generation with TracedPath and rolling circle. Use updaters and ValueTracker.\n\n```python\nfrom manim import *\nimport numpy as np\n\nclass DynamicScene535(Scene):\n def construct(self):\n ground = Line(LEFT * 4 + DOWN * 1.5, RIGHT * 4 + DOWN * 1.5, color=GREY)\n r = 0.8\n theta = ValueTracker(0.0)\n \n wheel = always_redraw(lambda: Circle(radius=r, color=WHITE).move_to(\n LEFT * 3 + RIGHT * (r * theta.get_value()) + DOWN * (1.5 - r)\n ))\n dot = always_redraw(lambda: Dot(\n wheel.get_center() + np.array([-r * np.sin(theta.get_value()), -r * np.cos(theta.get_value()), 0]),\n color=RED, radius=0.08\n ))\n trail = TracedPath(dot.get_center, stroke_color=YELLOW, stroke_width=3)\n \n self.add(ground, trail, wheel, dot)\n self.play(theta.animate.set_value(2 * PI * 1.2), run_time=4, rate_func=linear)\n self.wait(1)\n```", "chosen": "```python\nfrom manim import *\nfrom manim_voiceover import VoiceoverScene\nfrom manim_voiceover.services.gtts import GTTSService\nimport numpy as np\n\nclass DynamicScene535(VoiceoverScene):\n MARGIN = 0.5\n\n def fit_in_frame(self, mob: Mobject, w_frac=0.9, h_frac=0.9) -> Mobject:\n max_w = config.frame_width * w_frac\n max_h = config.frame_height * h_frac\n if mob.width > max_w:\n mob.width = max_w\n if mob.height > max_h:\n mob.height = max_h\n return mob\n\n def construct(self):\n self.set_speech_service(GTTSService(transcription_model=\"base\"))\n \n # [SETUP]\n title = Title(\"Cycloid Generation\")\n self.fit_in_frame(title)\n \n # [LAYOUT]\n ground = Line(LEFT * 4 + DOWN * 1.5, RIGHT * 4 + DOWN * 1.5, color=GREY)\n r = 0.8\n theta = ValueTracker(0.0)\n \n # [UPDATER]\n wheel = always_redraw(lambda: Circle(radius=r, color=WHITE).move_to(\n LEFT * 3 + RIGHT * (r * theta.get_value()) + DOWN * (1.5 - r)\n ))\n dot = always_redraw(lambda: Dot(\n wheel.get_center() + np.array([-r * np.sin(theta.get_value()), -r * np.cos(theta.get_value()), 0]),\n color=RED, radius=0.08\n ))\n trail = TracedPath(dot.get_center, stroke_color=YELLOW, stroke_width=3)\n \n self.fit_in_frame(VGroup(ground, trail, wheel, dot))\n \n # [BEAT 1 | sync: b1]\n with self.voiceover(text=\"A cycloid is the curve traced by a point on the rim of a circular wheel \") as t:\n self.wait_until_bookmark(\"b1\")\n self.play(Write(title), Create(ground), Create(wheel), Create(dot))\n \n # [BEAT 2 | sync: b2]\n with self.voiceover(text=\"as the wheel rolls along a straight line without slipping. Watch as the wheel rolls, and the point traces the cycloid path. \") as t:\n self.wait_until_bookmark(\"b2\")\n self.add(trail)\n self.play(theta.animate.set_value(2 * PI * 1.2), run_time=4, rate_func=linear)\n self.wait(1)\n```", "rejected": "```python\nfrom manim import *\nfrom manim_voiceover import VoiceoverScene\nfrom manim_voiceover.services.gtts import GTTSService\nimport numpy as np\n\nclass DynamicScene535(VoiceoverScene):\n MARGIN = 0.5\n\n def fit_in_frame(self, mob: Mobject, w_frac=0.9, h_frac=0.9) -> Mobject:\n max_w = config.frame_width * w_frac\n max_h = config.frame_height * h_frac\n if mob.width > max_w:\n mob.width = max_w\n if mob.height > max_h:\n mob.height = max_h\n return mob\n\n def construct(self):\n self.set_speech_service(GTTSService(transcription_model=\"base\"))\n \n # [SETUP]\n title = Title(\"Cycloid Generation\")\n self.fit_in_frame(title)\n \n # [LAYOUT]\n ground = Line(LEFT * 4 + DOWN * 1.5, RIGHT * 4 + DOWN * 1.5, color=GREY)\n r = 0.8\n theta = ValueTracker(0.0)\n \n # [UPDATER]\n wheel = always_redraw(lambda: Circle(radius=r, color=WHITE).move_to(\n LEFT * 3 + RIGHT * (r * theta.get_value()) + DOWN * (1.5 - r)\n ))\n dot = always_redraw(lambda: Dot(\n wheel.get_center() + np.array([-r * np.sin(theta.get_value()), -r * np.cos(theta.get_value()), 0]),\n color=RED, radius=0.08\n ))\n trail = TracedPath(dot.get_center, stroke_color=YELLOW, stroke_width=3)\n \n self.fit_in_frame(VGroup(ground, trail, wheel, dot))\n \n # [BEAT 1 | sync: b1]\n with self.voiceover(text=\"A cycloid is the curve traced by a point on the rim of a circular wheel \") as t:\n self.wait_until_bookmark(\"b1\")\n self.play(Write(title), ShowCreation(ground), Create(wheel), Create(dot))\n \n # [BEAT 2 | sync: b2]\n with self.voiceover(text=\"as the wheel rolls along a straight line without slipping. Watch as the wheel rolls, and the point traces the cycloid path. \") as t:\n self.wait_until_bookmark(\"b2\")\n self.add(trail)\n self.play(theta.animate.set_value(2 * PI * 1.2), run_time=4, rate_func=linear)\n self.wait(1)\n```", "category": "legacy_api_hallucination", "source": "synthetic_hard_neg:nabin2004/qwen3-8b-manimator-gold-sft"} +{"system": "You are an expert Manim Community Edition (ManimCE v0.19+) Python developer and mathematical animator. Given a user request, first plan the spatial layout, coordinate bounds, timing, and pedagogical flow inside ... tags (when reasoning is helpful), and then output a complete, runnable, self-contained ManimCE Python script using `from manim import *`. Never use deprecated ManimGL (`manimlib`) methods like `ShowCreation`, `TexMobject`, `TextMobject`, or `axes.get_graph`; always use modern ManimCE APIs (`Create`, `MathTex`, `Tex`, `Text`, `axes.plot`) and prevent visual overlap using `.to_edge()`, `.next_to()`, and `FadeOut`.", "prompt": "I'm learning linear algebra and want a visual that builds intuition for eigenvectors and eigenvalues. Show a general 2x2 linear transformation acting on the plane, with vectors colored by their stretching, then highlight the eigenlines and their scale factors. Then present a 3D symmetric matrix, decompose it into eigenvectors and eigenvalues, and illustrate spectral decomposition with an animated rotation and scale. Demonstrate a practical application by projecting sample data onto principal components and showing variance explained. Include multiple scenes, camera moves, transitions, and a clear derivation of the characteristic equation motivated by area/volume scaling, before the algebra.", "chosen": "```python\nfrom manim import *\nfrom manim_voiceover import VoiceoverScene\nfrom manim_voiceover.services.gtts import GTTSService\nimport numpy as np\n\nclass EigenvectorEigenvalueScene(ThreeDScene, VoiceoverScene):\n def construct(self):\n self.set_speech_service(\n GTTSService(voice=\"alba\", cache_dir=\"voiceover_cache\")\n )\n \n # Set up the 3D camera\n self.set_camera_orientation(phi=75 * DEGREES, theta=-45 * DEGREES)\n \n # Create 3D axes\n axes = ThreeDAxes(\n x_range=[-5, 5, 1],\n y_range=[-5, 5, 1],\n z_range=[-3, 3, 1],\n x_length=8,\n y_length=8,\n z_length=5,\n )\n \n # Add axis labels\n x_label = MathTex(\"x\").next_to(axes.x_axis, RIGHT, buff=0.2)\n y_label = MathTex(\"y\").next_to(axes.y_axis, UP, buff=0.2)\n z_label = MathTex(\"z\").next_to(axes.z_axis, OUT, buff=0.2)\n \n with self.voiceover(text=\"Welcome to the world of eigenvectors and eigenvalues. Today, we'll explore one of the most elegant concepts in linear algebra.\") as tracker:\n self.play(Create(axes), run_time=tracker.duration * 0.6)\n self.play(Write(x_label), Write(y_label), Write(z_label), run_time=tracker.duration * 0.4)\n \n # Title - fixed in frame\n title = Text(\"Eigenvectors & Eigenvalues\", font_size=36, color=YELLOW)\n title.to_edge(UL)\n \n with self.voiceover(text=\"Imagine you have a transformation that can stretch, compress, or rotate geometric shapes.\") as tracker:\n self.add_fixed_in_frame_mobjects(title)\n self.play(Write(title), run_time=tracker.duration)\n \n # Define transformation matrix A (symmetric for real eigenvalues)\n A = np.array([[2, 1, 0],\n [1, 2, 0],\n [0, 0, 1.5]], dtype=float)\n \n # Eigenvectors and eigenvalues of this matrix\n eigenvalues = [3, 1, 1.5]\n eigenvectors = [\n np.array([1, 1, 0], dtype=float) / np.sqrt(2),\n np.array([-1, 1, 0], dtype=float) / np.sqrt(2),\n np.array([0, 0, 1], dtype=float)\n ]\n \n # Create regular vector (not eigenvector)\n regular_vec = np.array([2, 1, 0.5], dtype=float)\n \n # Vector arrows\n regular_arrow = Arrow3D(\n start=np.array([0, 0, 0]),\n end=regular_vec,\n color=BLUE,\n thickness=0.04\n )\n \n regular_label = MathTex(r\"\\vec{v}\", color=BLUE, font_size=28)\n regular_label.move_to(regular_vec * 1.15)\n \n with self.voiceover(text=\"When we apply a linear transformation to most vectors, they both stretch and rotate.\") as tracker:\n self.play(Create(regular_arrow), run_time=tracker.duration * 0.6)\n self.add(regular_label)\n self.play(Write(regular_label), run_time=tracker.duration * 0.4)\n \n # Apply transformation to regular vector\n transformed_regular = A @ regular_vec\n transformed_arrow = Arrow3D(\n start=np.array([0, 0, 0]),\n end=transformed_regular,\n color=GREEN,\n thickness=0.04\n )\n \n transformed_label = MathTex(r\"A\\vec{v}\", color=GREEN, font_size=28)\n transformed_label.move_to(transformed_regular * 1.1)\n \n with self.voiceover(text=\"Look at this vector. After transformation, it points in a completely different direction.\") as tracker:\n self.play(Transform(regular_arrow, transformed_arrow), run_time=tracker.duration * 0.7)\n self.play(Transform(regular_label, transformed_label), run_time=tracker.duration * 0.3)\n \n # Fade out regular vector\n with self.voiceover(text=\"But what if some vectors don't change direction?\") as tracker:\n self.play(FadeOut(regular_arrow), FadeOut(regular_label), run_time=tracker.duration)\n \n # Create eigenvector\n eigen_vec = eigenvectors[0] * 2 # Scale for visibility\n eigen_arrow = Arrow3D(\n start=np.array([0, 0, 0]),\n end=eigen_vec,\n color=RED,\n thickness=0.05\n )\n \n eigen_label = MathTex(r\"\\vec{v}\", color=RED, font_size=28)\n eigen_label.move_to(eigen_vec * 1.2)\n \n with self.voiceover(text=\"These special vectors are called eigenvectors. Watch what happens when we apply the same transformation.\") as tracker:\n self.play(Create(eigen_arrow), run_time=tracker.duration * 0.6)\n self.add(eigen_label)\n self.play(Write(eigen_label), run_time=tracker.duration * 0.4)\n \n # Apply transformation to eigenvector - it only scales!\n transformed_eigen = A @ eigen_vec\n transformed_eigen_arrow = Arrow3D(\n start=np.array([0, 0, 0]),\n end=transformed_eigen,\n color=ORANGE,\n thickness=0.05\n )\n \n # The direction stays the same!\n transformed_eigen_label = MathTex(r\"A\\vec{v} = 3\\vec{v}\", color=ORANGE, font_size=28)\n transformed_eigen_label.move_to(transformed_eigen * 1.25)\n \n with self.voiceover(text=\"Notice that this vector only stretches. It stays on the same line! The direction doesn't change at all.\") as tracker:\n self.play(Transform(eigen_arrow, transformed_eigen_arrow), run_time=tracker.duration * 0.6)\n self.play(Transform(eigen_label, transformed_eigen_label), run_time=tracker.duration * 0.4)\n \n # Show the line extending\n eigen_line = Line3D(\n start=-3 * eigen_vec,\n end=3 * eigen_vec,\n color=YELLOW,\n thickness=0.02\n )\n \n with self.voiceover(text=\"The vector stays on this line. This is the defining property of an eigenvector.\") as tracker:\n self.play(Create(eigen_line), run_time=tracker.duration)\n \n # Move camera to show both vectors\n with self.voiceover(text=\"Let's look from another angle to see this clearly.\") as tracker:\n self.move_camera(phi=60 * DEGREES, theta=-30 * DEGREES, run_time=tracker.duration)\n \n # Display the eigenvalue equation\n equation = MathTex(r\"A\\vec{v} = \\lambda \\vec{v}\", font_size=40, color=WHITE)\n equation.to_edge(DR)\n \n explanation = Text(\"Eigenvalue equation\", font_size=24, color=YELLOW)\n explanation.next_to(equation, UP, buff=0.3)\n \n with self.voiceover(text=\"This is captured by the fundamental eigenvalue equation: A times v equals lambda times v.\") as tracker:\n self.add_fixed_in_frame_mobjects(equation, explanation)\n self.play(Write(equation), Write(explanation), run_time=tracker.duration)\n \n # Break down the equation\n breakdown = VGroup(\n MathTex(r\"A = \\text{transformation matrix}\", font_size=24, color=BLUE),\n MathTex(r\"\\vec{v} = \\text{eigenvector}\", font_size=24, color=RED),\n MathTex(r\"\\lambda = \\text{eigenvalue}\", font_size=24, color=GREEN)\n ).arrange(DOWN, aligned_edge=LEFT, buff=0.3)\n breakdown.to_edge(DL)\n \n with self.voiceover(text=\"Here, A is the transformation matrix, v is the eigenvector, and lambda is the eigenvalue - which tells us how much the vector stretches.\") as tracker:\n self.add_fixed_in_frame_mobjects(breakdown)\n self.play(Write(breakdown), run_time=tracker.duration)\n \n # Show multiple eigenvectors\n eigen_vec_2 = eigenvectors[1] * 2\n eigen_arrow_2 = Arrow3D(\n start=np.array([0, 0, 0]),\n end=eigen_vec_2,\n color=PURPLE,\n thickness=0.05\n )\n \n eigen_vec_3 = eigenvectors[2] * 2\n eigen_arrow_3 = Arrow3D(\n start=np.array([0, 0, 0]),\n end=eigen_vec_3,\n color=TEAL,\n thickness=0.05\n )\n \n with self.voiceover(text=\"A matrix can have multiple eigenvectors, each with its own eigenvalue. Let's see the other eigenvectors of this transformation.\") as tracker:\n self.play(Create(eigen_arrow_2), Create(eigen_arrow_3), run_time=tracker.duration)\n \n # Transform all eigenvectors\n transformed_2 = A @ eigen_vec_2\n transformed_3 = A @ eigen_vec_3\n \n transformed_arrow_2 = Arrow3D(\n start=np.array([0, 0, 0]),\n end=transformed_2,\n color=PINK,\n thickness=0.05\n )\n \n transformed_arrow_3 = Arrow3D(\n start=np.array([0, 0, 0]),\n end=transformed_3,\n color=BLUE_D,\n thickness=0.05\n )\n \n with self.voiceover(text=\"Each eigenvector scales by its eigenvalue. The purple one has eigenvalue 1, so it doesn't change. The teal one has eigenvalue 1.5.\") as tracker:\n self.play(\n Transform(eigen_arrow_2, transformed_arrow_2),\n Transform(eigen_arrow_3, transformed_arrow_3),\n run_time=tracker.duration\n )\n \n # Create summary\n summary_title = Text(\"Key Takeaways\", font_size=32, color=YELLOW)\n summary_title.to_edge(UP)\n \n takeaways = VGroup(\n Text(\"• Eigenvectors only scale, never rotate\", font_size=22),\n Text(\"• Eigenvalues determine the scale factor\", font_size=22),\n Text(\"• Av = λv captures this relationship\", font_size=22),\n Text(\"• Used in PCA, quantum mechanics, stability analysis\", font_size=22)\n ).arrange(DOWN, aligned_edge=LEFT, buff=0.25)\n takeaways.next_to(summary_title, DOWN, buff=0.4)\n \n with self.voiceover(text=\"To summarize: eigenvectors only scale, never rotate. Eigenvalues tell us by how much. This powerful concept appears everywhere from data science to quantum mechanics.\") as tracker:\n self.play(\n FadeOut(equation),\n FadeOut(explanation),\n FadeOut(breakdown),\n FadeOut(title),\n run_time=tracker.duration * 0.3\n )\n self.add_fixed_in_frame_mobjects(summary_title, takeaways)\n self.play(Write(summary_title), run_time=tracker.duration * 0.3)\n self.play(Write(takeaways), run_time=tracker.duration * 0.4)\n \n # Final camera movement\n with self.voiceover(text=\"Eigenvectors and eigenvalues reveal the intrinsic structure of linear transformations.\") as tracker:\n self.move_camera(phi=45 * DEGREES, theta=45 * DEGREES, run_time=tracker.duration)\n \n self.wait(1)\n```", "rejected": "```python\nfrom manim import *\nimport numpy as np\n\nclass EigenvectorEigenvalueScene(ThreeDScene, Scene):\n\n def construct(self):\n self.set_camera_orientation(phi=75 * DEGREES, theta=-45 * DEGREES)\n axes = ThreeDAxes(x_range=[-5, 5, 1], y_range=[-5, 5, 1], z_range=[-3, 3, 1], x_length=8, y_length=8, z_length=5)\n x_label = MathTex('x').next_to(axes.x_axis, RIGHT, buff=0.2)\n y_label = MathTex('y').next_to(axes.y_axis, UP, buff=0.2)\n z_label = MathTex('z').next_to(axes.z_axis, OUT, buff=0.2)\n self.play(Create(axes), run_time=2.0 * 0.6)\n self.play(Write(x_label), Write(y_label), Write(z_label), run_time=2.0 * 0.4)\n title = Text('Eigenvectors & Eigenvalues', font_size=36, color=YELLOW)\n title.to_edge(UL)\n self.add_fixed_in_frame_mobjects(title)\n self.play(Write(title), run_time=2.0)\n A = np.array([[2, 1, 0], [1, 2, 0], [0, 0, 1.5]], dtype=float)\n eigenvalues = [3, 1, 1.5]\n eigenvectors = [np.array([1, 1, 0], dtype=float) / np.sqrt(2), np.array([-1, 1, 0], dtype=float) / np.sqrt(2), np.array([0, 0, 1], dtype=float)]\n regular_vec = np.array([2, 1, 0.5], dtype=float)\n regular_arrow = Arrow3D(start=np.array([0, 0, 0]), end=regular_vec, color=BLUE, thickness=0.04)\n regular_label = MathTex('\\\\vec{v}', color=BLUE, font_size=28)\n regular_label.move_to(regular_vec * 1.15)\n self.play(Create(regular_arrow), run_time=2.0 * 0.6)\n self.add(regular_label)\n self.play(Write(regular_label), run_time=2.0 * 0.4)\n transformed_regular = A @ regular_vec\n transformed_arrow = Arrow3D(start=np.array([0, 0, 0]), end=transformed_regular, color=GREEN, thickness=0.04)\n transformed_label = MathTex('A\\\\vec{v}', color=GREEN, font_size=28)\n transformed_label.move_to(transformed_regular * 1.1)\n self.play(Transform(regular_arrow, transformed_arrow), run_time=2.0 * 0.7)\n self.play(Transform(regular_label, transformed_label), run_time=2.0 * 0.3)\n self.play(FadeOut(regular_arrow), FadeOut(regular_label), run_time=2.0)\n eigen_vec = eigenvectors[0] * 2\n eigen_arrow = Arrow3D(start=np.array([0, 0, 0]), end=eigen_vec, color=RED, thickness=0.05)\n eigen_label = MathTex('\\\\vec{v}', color=RED, font_size=28)\n eigen_label.move_to(eigen_vec * 1.2)\n self.play(Create(eigen_arrow), run_time=2.0 * 0.6)\n self.add(eigen_label)\n self.play(Write(eigen_label), run_time=2.0 * 0.4)\n transformed_eigen = A @ eigen_vec\n transformed_eigen_arrow = Arrow3D(start=np.array([0, 0, 0]), end=transformed_eigen, color=ORANGE, thickness=0.05)\n transformed_eigen_label = MathTex('A\\\\vec{v} = 3\\\\vec{v}', color=ORANGE, font_size=28)\n transformed_eigen_label.move_to(transformed_eigen * 1.25)\n self.play(Transform(eigen_arrow, transformed_eigen_arrow), run_time=2.0 * 0.6)\n self.play(Transform(eigen_label, transformed_eigen_label), run_time=2.0 * 0.4)\n eigen_line = Line3D(start=-3 * eigen_vec, end=3 * eigen_vec, color=YELLOW, thickness=0.02)\n self.play(Create(eigen_line), run_time=2.0)\n self.move_camera(phi=60 * DEGREES, theta=-30 * DEGREES, run_time=2.0)\n equation = MathTex('A\\\\vec{v} = \\\\lambda \\\\vec{v}', font_size=40, color=WHITE)\n equation.to_edge(DR)\n explanation = Text('Eigenvalue equation', font_size=24, color=YELLOW)\n explanation.next_to(equation, UP, buff=0.3)\n self.add_fixed_in_frame_mobjects(equation, explanation)\n self.play(Write(equation), Write(explanation), run_time=2.0)\n breakdown = VGroup(MathTex('A = \\\\text{transformation matrix}', font_size=24, color=BLUE), MathTex('\\\\vec{v} = \\\\text{eigenvector}', font_size=24, color=RED), MathTex('\\\\lambda = \\\\text{eigenvalue}', font_size=24, color=GREEN)).arrange(DOWN, aligned_edge=LEFT, buff=0.3)\n breakdown.to_edge(DL)\n self.add_fixed_in_frame_mobjects(breakdown)\n self.play(Write(breakdown), run_time=2.0)\n eigen_vec_2 = eigenvectors[1] * 2\n eigen_arrow_2 = Arrow3D(start=np.array([0, 0, 0]), end=eigen_vec_2, color=PURPLE, thickness=0.05)\n eigen_vec_3 = eigenvectors[2] * 2\n eigen_arrow_3 = Arrow3D(start=np.array([0, 0, 0]), end=eigen_vec_3, color=TEAL, thickness=0.05)\n self.play(Create(eigen_arrow_2), Create(eigen_arrow_3), run_time=2.0)\n transformed_2 = A @ eigen_vec_2\n transformed_3 = A @ eigen_vec_3\n transformed_arrow_2 = Arrow3D(start=np.array([0, 0, 0]), end=transformed_2, color=PINK, thickness=0.05)\n transformed_arrow_3 = Arrow3D(start=np.array([0, 0, 0]), end=transformed_3, color=BLUE_D, thickness=0.05)\n self.play(Transform(eigen_arrow_2, transformed_arrow_2), Transform(eigen_arrow_3, transformed_arrow_3), run_time=2.0)\n summary_title = Text('Key Takeaways', font_size=32, color=YELLOW)\n summary_title.to_edge(UP)\n takeaways = VGroup(Text('• Eigenvectors only scale, never rotate', font_size=22), Text('• Eigenvalues determine the scale factor', font_size=22), Text('• Av = λv captures this relationship', font_size=22), Text('• Used in PCA, quantum mechanics, stability analysis', font_size=22)).arrange(DOWN, aligned_edge=LEFT, buff=0.25)\n takeaways.next_to(summary_title, DOWN, buff=0.4)\n self.play(FadeOut(equation), FadeOut(explanation), FadeOut(breakdown), FadeOut(title), run_time=2.0 * 0.3)\n self.add_fixed_in_frame_mobjects(summary_title, takeaways)\n self.play(Write(summary_title), run_time=2.0 * 0.3)\n self.play(Write(takeaways), run_time=2.0 * 0.4)\n self.move_camera(phi=45 * DEGREES, theta=45 * DEGREES, run_time=2.0)\n self.wait(1)\n```", "category": "narrated_pedagogical_preference", "source": "nabin2004/manim-narrated-dpo-400"} +{"system": "You are an expert Manim Community Edition (ManimCE v0.19+) Python developer and mathematical animator. Given a user request, first plan the spatial layout, coordinate bounds, timing, and pedagogical flow inside ... tags (when reasoning is helpful), and then output a complete, runnable, self-contained ManimCE Python script using `from manim import *`. Never use deprecated ManimGL (`manimlib`) methods like `ShowCreation`, `TexMobject`, `TextMobject`, or `axes.get_graph`; always use modern ManimCE APIs (`Create`, `MathTex`, `Tex`, `Text`, `axes.plot`) and prevent visual overlap using `.to_edge()`, `.next_to()`, and `FadeOut`.", "prompt": "Create a closed shape by connecting four points in a square-like path using lines. Display text in the top-right corner showing the start, end, and center coordinates of the shape. Highlight the start point with a yellow dot, the end point with a red dot, the topmost point with a light green dot, the bottommost point with a dark green dot, the center with a blue dot, and the midpoint of the shape with an orange dot. Also, place small dots at every point that makes up the shape’s outline. Finally, display the shape itself.", "chosen": "```python\nfrom manim import *\n\nclass MobjectExample(Scene):\n def construct(self):\n p1 = [-1,-1, 0]\n p2 = [ 1,-1, 0]\n p3 = [ 1, 1, 0]\n p4 = [-1, 1, 0]\n a = Line(p1,p2).append_points(Line(p2,p3).points).append_points(Line(p3,p4).points)\n point_start = a.get_start()\n point_end = a.get_end()\n point_center = a.get_center()\n self.add(Text(f\"a.get_start() = {np.round(point_start,2).tolist()}\", font_size=24).to_edge(UR).set_color(YELLOW))\n self.add(Text(f\"a.get_end() = {np.round(point_end,2).tolist()}\", font_size=24).next_to(self.mobjects[-1],DOWN).set_color(RED))\n self.add(Text(f\"a.get_center() = {np.round(point_center,2).tolist()}\", font_size=24).next_to(self.mobjects[-1],DOWN).set_color(BLUE))\n\n self.add(Dot(a.get_start()).set_color(YELLOW).scale(2))\n self.add(Dot(a.get_end()).set_color(RED).scale(2))\n self.add(Dot(a.get_top()).set_color(GREEN_A).scale(2))\n self.add(Dot(a.get_bottom()).set_color(GREEN_D).scale(2))\n self.add(Dot(a.get_center()).set_color(BLUE).scale(2))\n self.add(Dot(a.point_from_proportion(0.5)).set_color(ORANGE).scale(2))\n self.add(*[Dot(x) for x in a.points])\n self.add(a)\n```", "rejected": "```python\nfrom manim import *\n\nclass MobjectExample(Scene):\n def construct(self):\n p1 = [-1,-1, 0]\n p2 = [ 1,-1, 0]\n p3 = [ 1, 1, 0]\n p4 = [-1, 1, 0]\n a = Line(p1,p2).append_points(Line(p2,p3).points).append_points(Line(p3,p4).points)\n point_start = a.get_start()\n point_end = a.get_end()\n point_center = a.get_center()\n self.add(Text(f\"a.get_start() = {np.round(point_start,2).tolist()}\", font_size=24).set_color(YELLOW))\n self.add(Text(f\"a.get_end() = {np.round(point_end,2).tolist()}\", font_size=24).set_color(RED))\n self.add(Text(f\"a.get_center() = {np.round(point_center,2).tolist()}\", font_size=24).set_color(BLUE))\n\n self.add(Dot(a.get_start()).set_color(YELLOW).scale(2))\n self.add(Dot(a.get_end()).set_color(RED).scale(2))\n self.add(Dot(a.get_top()).set_color(GREEN_A).scale(2))\n self.add(Dot(a.get_bottom()).set_color(GREEN_D).scale(2))\n self.add(Dot(a.get_center()).set_color(BLUE).scale(2))\n self.add(Dot(a.point_from_proportion(0.5)).set_color(ORANGE).scale(2))\n self.add(*[Dot(x) for x in a.points])\n self.add(a)\n```", "category": "spatial_layout_overlap", "source": "synthetic_hard_neg:SuienR/ManimBench-v1"} +{"system": "You are an expert Manim Community Edition (ManimCE v0.19+) Python developer and mathematical animator. Given a user request, first plan the spatial layout, coordinate bounds, timing, and pedagogical flow inside ... tags (when reasoning is helpful), and then output a complete, runnable, self-contained ManimCE Python script using `from manim import *`. Never use deprecated ManimGL (`manimlib`) methods like `ShowCreation`, `TexMobject`, `TextMobject`, or `axes.get_graph`; always use modern ManimCE APIs (`Create`, `MathTex`, `Tex`, `Text`, `axes.plot`) and prevent visual overlap using `.to_edge()`, `.next_to()`, and `FadeOut`.", "prompt": "Illustrate the concept of Pascal's triangle visually using Manim.", "chosen": "```python\nfrom manim import *\n\nclass PascalsTriangle(Scene):\n def construct(self):\n triangle = self.generate_pascals_triangle(10) # Change the number of rows as needed\n self.play(Create(triangle))\n self.wait()\n\n def generate_pascals_triangle(self, num_rows):\n triangle = VGroup()\n cell_size = 0.5\n for i in range(num_rows):\n row = VGroup()\n for j in range(i + 1):\n coefficient = self.binomial_coefficient(i, j)\n cell = Text(str(coefficient), font_size=24).scale(0.5)\n cell.move_to((j - i / 2) * cell_size * RIGHT + (i / 2 - i) * cell_size * UP)\n row.add(cell)\n triangle.add(row)\n return triangle\n\n def binomial_coefficient(self, n, k):\n return int(self.factorial(n) / (self.factorial(k) * self.factorial(n - k)))\n\n def factorial(self, n):\n if n == 0 or n == 1:\n return 1\n else:\n return n * self.factorial(n - 1)\n```", "rejected": "```python\nfrom manim import *\n\nclass PascalsTriangle(Scene):\n def construct(self):\n triangle = self.generate_pascals_triangle(10) # Change the number of rows as needed\n self.play(ShowCreation(triangle))\n self.wait()\n\n def generate_pascals_triangle(self, num_rows):\n triangle = VGroup()\n cell_size = 0.5\n for i in range(num_rows):\n row = VGroup()\n for j in range(i + 1):\n coefficient = self.binomial_coefficient(i, j)\n cell = Text(str(coefficient), font_size=24).scale(0.5)\n cell.move_to((j - i / 2) * cell_size * RIGHT + (i / 2 - i) * cell_size * UP)\n row.add(cell)\n triangle.add(row)\n return triangle\n\n def binomial_coefficient(self, n, k):\n return int(self.factorial(n) / (self.factorial(k) * self.factorial(n - k)))\n\n def factorial(self, n):\n if n == 0 or n == 1:\n return 1\n else:\n return n * self.factorial(n - 1)\n```", "category": "legacy_api_hallucination", "source": "synthetic_hard_neg:nabin2004/manim-sft-10k"} +{"system": "You are an expert Manim Community Edition (ManimCE v0.19+) Python developer and mathematical animator. Given a user request, first plan the spatial layout, coordinate bounds, timing, and pedagogical flow inside ... tags (when reasoning is helpful), and then output a complete, runnable, self-contained ManimCE Python script using `from manim import *`. Never use deprecated ManimGL (`manimlib`) methods like `ShowCreation`, `TexMobject`, `TextMobject`, or `axes.get_graph`; always use modern ManimCE APIs (`Create`, `MathTex`, `Tex`, `Text`, `axes.plot`) and prevent visual overlap using `.to_edge()`, `.next_to()`, and `FadeOut`.", "prompt": "vae_nn_code_snippet.py", "chosen": "```python\nfrom manim import *\nfrom manim_ml.neural_network.layers import FeedForwardLayer, ImageLayer, EmbeddingLayer\nfrom manim_ml.neural_network.neural_network import NeuralNetwork\nfrom PIL import Image\nimport numpy as np\n\nconfig.pixel_height = 720\nconfig.pixel_width = 1280\nconfig.frame_height = 6.0\nconfig.frame_width = 6.0\n\n\nclass VAECodeSnippetScene(Scene):\n def make_code_snippet(self):\n code_str = \"\"\"\n # 创建图像对象\n image = Image.open('images/image.jpeg')\n numpy_image = np.asarray(image)\n # 创建神经网络\n nn = NeuralNetwork([\n ImageLayer(numpy_image, height=1.2),\n FeedForwardLayer(5),\n FeedForwardLayer(3),\n EmbeddingLayer(),\n FeedForwardLayer(3),\n FeedForwardLayer(5),\n ImageLayer(numpy_image, height=1.2),\n ], layer_spacing=0.1)\n self.add(nn)\n # 播放动画\n self.play(\n nn.make_forward_pass_animation()\n )\n \"\"\"\n\n code = Code(\n code=code_str,\n tab_width=4,\n background_stroke_width=1,\n # background_stroke_color=WHITE,\n insert_line_no=False,\n background=\"window\",\n # font=\"Monospace\",\n style=\"one-dark\",\n language=\"py\",\n )\n code.scale(0.2)\n\n return code\n\n def construct(self):\n image = Image.open(\"../../tests/images/image.jpeg\")\n numpy_image = np.asarray(image)\n embedding_layer = EmbeddingLayer(dist_theme=\"ellipse\", point_radius=0.04).scale(\n 1.0\n )\n # 创建神经网络\n nn = NeuralNetwork(\n [\n ImageLayer(numpy_image, height=1.0),\n FeedForwardLayer(5),\n FeedForwardLayer(3),\n embedding_layer,\n FeedForwardLayer(3),\n FeedForwardLayer(5),\n ImageLayer(numpy_image, height=1.0),\n ],\n layer_spacing=0.1,\n )\n\n nn.scale(0.65)\n # 将神经网络居中\n nn.move_to(ORIGIN)\n nn.rotate(-PI / 2)\n nn.all_layers[0].image_mobject.rotate(PI / 2)\n # nn.all_layers[0].image_mobject.shift([0, -0.4, 0])\n nn.all_layers[-1].image_mobject.rotate(PI / 2)\n # nn.all_layers[-1].image_mobject.shift([0, -0.4, 0])\n nn.shift([1.5, 0.0, 0])\n self.add(nn)\n # 创建代码片段\n code_snippet = self.make_code_snippet()\n code_snippet.scale(1.9)\n code_snippet.shift([-1.25, 0, 0])\n self.add(code_snippet)\n # 播放动画\n self.play(nn.make_forward_pass_animation(), run_time=10)\n\n\nif __name__ == \"__main__\":\n \"\"\"渲染所有场景\"\"\"\n # 神经网络\n nn_scene = VAECodeSnippetScene()\n nn_scene.render()\n```", "rejected": "```python\nfrom manim import *\nfrom manim_ml.neural_network.layers import FeedForwardLayer, ImageLayer, EmbeddingLayer\nfrom manim_ml.neural_network.neural_network import NeuralNetwork\nfrom PIL import Image\nimport numpy as np\n\nconfig.pixel_height = 720\nconfig.pixel_width = 1280\nconfig.frame_height = 6.0\nconfig.frame_width = 6.0\n\n\nclass VAECodeSnippetScene(Scene):\n def make_code_snippet(self):\n code_str = \"\"\"\n # 创建图像对象\n image = Image.open('images/image.jpeg')\n numpy_image = np.asarray(image)\n # 创建神经网络\n nn = NeuralNetwork([\n ImageLayer(numpy_image, height=1.2),\n FeedForwardLayer(5),\n FeedForwardLayer(3),\n EmbeddingLayer(),\n FeedForwardLayer(3),\n FeedForwardLayer(5),\n ImageLayer(numpy_image, height=1.2),\n ], layer_spacing=0.1)\n self.add(nn)\n # 播放动画\n self.play(\n nn.make_forward_pass_animation()\n )\n \"\"\"\n\n code = Code(\n code=code_str,\n tab_width=4,\n background_stroke_width=1,\n # background_stroke_color=WHITE,\n insert_line_no=False,\n background=\"window\",\n # font=\"Monospace\",\n style=\"one-dark\",\n language=\"py\",\n )\n code.scale(0.2)\n\n return code\n\n def construct(self):\n image = Image.open(\"../../tests/images/image.jpeg\")\n numpy_image = np.asarray(image)\n embedding_layer = EmbeddingLayer(dist_theme=\"ellipse\", point_radius=0.04).scale(\n 1.0\n )\n # 创建神经网络\n nn = NeuralNetwork(\n [\n ImageLayer(numpy_image, height=1.0),\n FeedForwardLayer(5),\n FeedForwardLayer(3),\n embedding_layer,\n FeedForwardLayer(3),\n FeedForwardLayer(5),\n ImageLayer(numpy_image, height=1.0),\n ],\n layer_spacing=0.1,\n )\n\n nn.scale(0.65)\n # 将神经网络居中\n nn.move_to(ORIGIN)\n nn.rotate(-PI / 2)\n nn.all_layers[0].image_mobject.rotate(PI / 2)\n # nn.all_layers[0].image_mobject\n nn.all_layers[-1].image_mobject.rotate(PI / 2)\n # nn.all_layers[-1].image_mobject\n nn\n self.add(nn)\n # 创建代码片段\n code_snippet = self.make_code_snippet()\n code_snippet.scale(1.9)\n code_snippet.shift([-1.25, 0, 0])\n self.add(code_snippet)\n # 播放动画\n self.play(nn.make_forward_pass_animation(), run_time=10)\n\n\nif __name__ == \"__main__\":\n \"\"\"渲染所有场景\"\"\"\n # 神经网络\n nn_scene = VAECodeSnippetScene()\n nn_scene.render()\n```", "category": "spatial_layout_overlap", "source": "synthetic_hard_neg:nabin2004/manim-sft-10k"} +{"system": "You are an expert Manim Community Edition (ManimCE v0.19+) Python developer and mathematical animator. Given a user request, first plan the spatial layout, coordinate bounds, timing, and pedagogical flow inside ... tags (when reasoning is helpful), and then output a complete, runnable, self-contained ManimCE Python script using `from manim import *`. Never use deprecated ManimGL (`manimlib`) methods like `ShowCreation`, `TexMobject`, `TextMobject`, or `axes.get_graph`; always use modern ManimCE APIs (`Create`, `MathTex`, `Tex`, `Text`, `axes.plot`) and prevent visual overlap using `.to_edge()`, `.next_to()`, and `FadeOut`.", "prompt": "Create an interactive Manim CE animation demonstrating: Riemann Rectangles adapting dynamically with ValueTracker. Use updaters and ValueTracker.\n\n```python\nfrom manim import *\nimport numpy as np\n\nclass DynamicScene137(Scene):\n def construct(self):\n ax = Axes(x_range=[0, 4, 1], y_range=[0, 5, 1], x_length=6, y_length=4)\n curve = ax.plot(lambda x: 0.5 * x**2, color=BLUE)\n k = ValueTracker(4)\n rects = always_redraw(lambda: ax.get_riemann_rectangles(\n curve, x_range=[0, 3], dx=3.0 / max(int(k.get_value()), 1), stroke_color=WHITE, fill_opacity=0.6\n ))\n count_text = Integer(4).to_corner(UL)\n count_text.add_updater(lambda m: m.set_value(int(k.get_value())))\n \n self.add(ax, curve, rects, count_text)\n self.play(k.animate.set_value(30), run_time=4, rate_func=linear)\n self.wait(1)\n```", "chosen": "```python\nfrom manim import *\nfrom manim_voiceover import VoiceoverScene\nfrom manim_voiceover.services.gtts import GTTSService\nimport numpy as np\n\nclass DynamicScene137(VoiceoverScene):\n MARGIN = 0.5\n\n def fit_in_frame(self, mob: Mobject, w_frac=0.9, h_frac=0.9) -> Mobject:\n max_w = config.frame_width * w_frac\n max_h = config.frame_height * h_frac\n if mob.width > max_w:\n mob.width = max_w\n if mob.height > max_h:\n mob.height = max_h\n return mob\n\n def construct(self):\n self.set_speech_service(GTTSService(transcription_model=\"base\"))\n \n # [SETUP]\n title = Title(\"Riemann Rectangles\")\n self.fit_in_frame(title)\n \n # [LAYOUT]\n ax = Axes(x_range=[0, 4, 1], y_range=[0, 5, 1], x_length=6, y_length=4)\n curve = ax.plot(lambda x: 0.5 * x**2, color=BLUE)\n k = ValueTracker(4)\n \n # [UPDATER]\n rects = always_redraw(lambda: ax.get_riemann_rectangles(\n curve, x_range=[0, 3], dx=3.0 / max(int(k.get_value()), 1), stroke_color=WHITE, fill_opacity=0.6\n ))\n count_text = Integer(4).to_corner(UL)\n count_text.add_updater(lambda m: m.set_value(int(k.get_value())))\n \n self.fit_in_frame(VGroup(ax, curve, rects, count_text))\n \n # [BEAT 1 | sync: b1]\n with self.voiceover(text=\"We can approximate the area under a curve using Riemann rectangles. \") as t:\n self.wait_until_bookmark(\"b1\")\n self.play(Write(title), Create(ax), Create(curve), Create(rects), Write(count_text))\n \n # [BEAT 2 | sync: b2]\n with self.voiceover(text=\"As we increase the number of rectangles, the approximation becomes more accurate.\") as t:\n self.play(k.animate.set_value(30), run_time=4, rate_func=linear)\n self.wait(1)\n```", "rejected": "```python\nfrom manim import *\nfrom manim_voiceover import VoiceoverScene\nfrom manim_voiceover.services.gtts import GTTSService\nimport numpy as np\n\nclass DynamicScene137(VoiceoverScene):\n MARGIN = 0.5\n\n def fit_in_frame(self, mob: Mobject, w_frac=0.9, h_frac=0.9) -> Mobject:\n max_w = config.frame_width * w_frac\n max_h = config.frame_height * h_frac\n if mob.width > max_w:\n mob.width = max_w\n if mob.height > max_h:\n mob.height = max_h\n return mob\n\n def construct(self):\n self.set_speech_service(GTTSService(transcription_model=\"base\"))\n \n # [SETUP]\n title = Title(\"Riemann Rectangles\")\n self.fit_in_frame(title)\n \n # [LAYOUT]\n ax = Axes(x_range=[0, 4, 1], y_range=[0, 5, 1], x_length=6, y_length=4)\n curve = ax.get_graph(lambda x: 0.5 * x**2, color=BLUE)\n k = ValueTracker(4)\n \n # [UPDATER]\n rects = always_redraw(lambda: ax.get_riemann_rectangles(\n curve, x_range=[0, 3], dx=3.0 / max(int(k.get_value()), 1), stroke_color=WHITE, fill_opacity=0.6\n ))\n count_text = Integer(4).to_corner(UL)\n count_text.add_updater(lambda m: m.set_value(int(k.get_value())))\n \n self.fit_in_frame(VGroup(ax, curve, rects, count_text))\n \n # [BEAT 1 | sync: b1]\n with self.voiceover(text=\"We can approximate the area under a curve using Riemann rectangles. \") as t:\n self.wait_until_bookmark(\"b1\")\n self.play(Write(title), ShowCreation(ax), Create(curve), Create(rects), Write(count_text))\n \n # [BEAT 2 | sync: b2]\n with self.voiceover(text=\"As we increase the number of rectangles, the approximation becomes more accurate.\") as t:\n self.play(k.animate.set_value(30), run_time=4, rate_func=linear)\n self.wait(1)\n```", "category": "legacy_api_hallucination", "source": "synthetic_hard_neg:nabin2004/qwen3-8b-manimator-gold-sft"} +{"system": "You are an expert Manim Community Edition (ManimCE v0.19+) Python developer and mathematical animator. Given a user request, first plan the spatial layout, coordinate bounds, timing, and pedagogical flow inside ... tags (when reasoning is helpful), and then output a complete, runnable, self-contained ManimCE Python script using `from manim import *`. Never use deprecated ManimGL (`manimlib`) methods like `ShowCreation`, `TexMobject`, `TextMobject`, or `axes.get_graph`; always use modern ManimCE APIs (`Create`, `MathTex`, `Tex`, `Text`, `axes.plot`) and prevent visual overlap using `.to_edge()`, `.next_to()`, and `FadeOut`.", "prompt": "The following Manim CE scene failed to compile. Truncated traceback:\n\nTypeError: Animation only works on Mobjects\n\nFix the code. Return a complete working scene. Do not keep the invalid constructor kwargs or Unicode subscripts.\n\n```python\nfrom manim import *\n\nclass DoubleIntegralExample(Scene):\n def construct(self):\n self.play(1.5)\n # Displaying the problem\n problem = MathTex(r\"\\int_{0}^{1} \\int_{0}^{x} e^{y^2} dy\\,dx\")\n self.play(Write(problem))\n self.wait(1)\n\n # Explanation for inner integral\n explanation1 = Text(\"Integrate with respect to y first\", font_size=24).to_edge(UP)\n self.play(Write(explanation1))\n self.wait(2)\n\n # Inner integral step\n inner_integral = MathTex(r\"= \\int_{0}^{1} [e^{y^2}]_{0}^{x} dx\")\n self.play(ReplacementTransform(problem.copy(), inner_integral))\n self.wait(1)\n\n # Explanation for middle integral\n explanation2 = Text(\"Now integrate with respect to x\", font_size=24).to_edge(UP)\n self.play(Transform(explanation1, explanation2))\n self.wait(2)\n\n # Final solution\n final_solution = MathTex(r\"= [e^{x^2}]_{0}^{1}\")\n self.play(ReplacementTransform(inner_integral, final_solution))\n self.wait(1)\n\n # Final answer\n answer = MathTex(r\"= e - 1\")\n self.play(Write(answer))\n self.wait(2)\n```", "chosen": "```python\nfrom manim import *\n\nclass DoubleIntegralExample(Scene):\n def construct(self):\n # Displaying the problem\n problem = MathTex(r\"\\int_{0}^{1} \\int_{0}^{x} e^{y^2} dy\\,dx\")\n self.play(Write(problem))\n self.wait(1)\n\n # Explanation for inner integral\n explanation1 = Text(\"Integrate with respect to y first\", font_size=24).to_edge(UP)\n self.play(Write(explanation1))\n self.wait(2)\n\n # Inner integral step\n inner_integral = MathTex(r\"= \\int_{0}^{1} [e^{y^2}]_{0}^{x} dx\")\n self.play(ReplacementTransform(problem.copy(), inner_integral))\n self.wait(1)\n\n # Explanation for middle integral\n explanation2 = Text(\"Now integrate with respect to x\", font_size=24).to_edge(UP)\n self.play(Transform(explanation1, explanation2))\n self.wait(2)\n\n # Final solution\n final_solution = MathTex(r\"= [e^{x^2}]_{0}^{1}\")\n self.play(ReplacementTransform(inner_integral, final_solution))\n self.wait(1)\n\n # Final answer\n answer = MathTex(r\"= e - 1\")\n self.play(Write(answer))\n self.wait(2)\n```", "rejected": "```python\nfrom manim import *\n\nclass DoubleIntegralExample(Scene):\n def construct(self):\n # Displaying the problem\n problem = TexMobject(r\"\\int_{0}^{1} \\int_{0}^{x} e^{y^2} dy\\,dx\")\n self.play(Write(problem))\n self.wait(1)\n\n # Explanation for inner integral\n explanation1 = Text(\"Integrate with respect to y first\", font_size=24).to_edge(UP)\n self.play(Write(explanation1))\n self.wait(2)\n\n # Inner integral step\n inner_integral = MathTex(r\"= \\int_{0}^{1} [e^{y^2}]_{0}^{x} dx\")\n self.play(ReplacementTransform(problem.copy(), inner_integral))\n self.wait(1)\n\n # Explanation for middle integral\n explanation2 = Text(\"Now integrate with respect to x\", font_size=24).to_edge(UP)\n self.play(Transform(explanation1, explanation2))\n self.wait(2)\n\n # Final solution\n final_solution = MathTex(r\"= [e^{x^2}]_{0}^{1}\")\n self.play(ReplacementTransform(inner_integral, final_solution))\n self.wait(1)\n\n # Final answer\n answer = MathTex(r\"= e - 1\")\n self.play(Write(answer))\n self.wait(2)\n```", "category": "legacy_api_hallucination", "source": "synthetic_hard_neg:nabin2004/manim-sft-10k"} +{"system": "You are an expert Manim Community Edition (ManimCE v0.19+) Python developer and mathematical animator. Given a user request, first plan the spatial layout, coordinate bounds, timing, and pedagogical flow inside ... tags (when reasoning is helpful), and then output a complete, runnable, self-contained ManimCE Python script using `from manim import *`. Never use deprecated ManimGL (`manimlib`) methods like `ShowCreation`, `TexMobject`, `TextMobject`, or `axes.get_graph`; always use modern ManimCE APIs (`Create`, `MathTex`, `Tex`, `Text`, `axes.plot`) and prevent visual overlap using `.to_edge()`, `.next_to()`, and `FadeOut`.", "prompt": "Write a Manim CE visualization using scientific Python libraries (numpy, scipy, sympy) for: Fourier Series Square Wave Approximation with NumPy.\n\n```python\nfrom manim import *\nimport numpy as np\n\nclass SciComputeScene865(Scene):\n def construct(self):\n ax = Axes(x_range=[-PI, PI, PI/2], y_range=[-1.5, 1.5, 0.5], x_length=7, y_length=4)\n self.add(ax)\n \n def fourier_square(x, n_terms):\n y = np.zeros_like(x)\n for k in range(1, n_terms + 1):\n n = 2 * k - 1\n y += (4.0 / (np.pi * n)) * np.sin(n * x)\n return y\n \n for n in [1, 3, 7, 15]:\n curve = ax.plot(lambda x: fourier_square(np.array([x]), n)[0], color=interpolate_color(BLUE, YELLOW, n/15))\n label = MathTex(f\"N = {n}\").to_corner(UR)\n self.play(Create(curve), Write(label), run_time=1.5)\n self.wait(0.5)\n if n != 15:\n self.play(FadeOut(curve), FadeOut(label), run_time=0.5)\n```", "chosen": "```python\nfrom manim import *\nfrom manim_voiceover import VoiceoverScene\nfrom manim_voiceover.services.gtts import GTTSService\nimport numpy as np\n\nMARGIN = 0.5\n\nclass FourierSquareWaveScene(VoiceoverScene):\n def fit_in_frame(self, mob: Mobject, w_frac=0.9, h_frac=0.9) -> Mobject:\n max_w = config.frame_width * w_frac\n max_h = config.frame_height * h_frac\n if mob.width > max_w:\n mob.width = max_w\n if mob.height > max_h:\n mob.height = max_h\n return mob\n\n def construct(self):\n self.set_speech_service(GTTSService(transcription_model=\"base\"))\n \n # [SETUP]\n title = Title(\"Fourier Approximation\", buff=MARGIN)\n ax = Axes(x_range=[-PI, PI, PI/2], y_range=[-1.5, 1.5, 0.5], x_length=7, y_length=4).shift(DOWN * 0.5)\n \n def fourier_square(x, n_terms):\n y = np.zeros_like(x)\n for k in range(1, n_terms + 1):\n n = 2 * k - 1\n y += (4.0 / (np.pi * n)) * np.sin(n * x)\n return y\n \n c1 = ax.plot(lambda x: fourier_square(np.array([x]), 1)[0], color=BLUE)\n c3 = ax.plot(lambda x: fourier_square(np.array([x]), 3)[0], color=TEAL)\n c7 = ax.plot(lambda x: fourier_square(np.array([x]), 7)[0], color=GREEN)\n c15 = ax.plot(lambda x: fourier_square(np.array([x]), 15)[0], color=YELLOW)\n \n # [LAYOUT]\n main_group = self.fit_in_frame(VGroup(title, ax))\n self.add(main_group)\n \n # [UPDATER]\n # None\n \n # [BEAT 1 | sync: b1]\n with self.voiceover(text=\"A square wave can be approximated by summing sine waves of odd harmonics. \") as t_voice:\n self.wait_until_bookmark(\"b1\")\n self.play(Create(ax), Create(c1), run_time=1.5)\n \n # [BEAT 2 | sync: b2]\n with self.voiceover(text=\"Increasing the number of terms in the Fourier series yields a closer approximation to the ideal square wave. \") as t_voice:\n self.wait_until_bookmark(\"b2\")\n self.play(Transform(c1, c3), run_time=1)\n self.play(Transform(c1, c7), run_time=1)\n self.play(Transform(c1, c15), run_time=1.5)\n self.wait(1)\n```", "rejected": "```python\nfrom manim import *\nfrom manim_voiceover import VoiceoverScene\nfrom manim_voiceover.services.gtts import GTTSService\nimport numpy as np\n\nMARGIN = 0.5\n\nclass FourierSquareWaveScene(VoiceoverScene):\n def fit_in_frame(self, mob: Mobject, w_frac=0.9, h_frac=0.9) -> Mobject:\n max_w = config.frame_width * w_frac\n max_h = config.frame_height * h_frac\n if mob.width > max_w:\n mob.width = max_w\n if mob.height > max_h:\n mob.height = max_h\n return mob\n\n def construct(self):\n self.set_speech_service(GTTSService(transcription_model=\"base\"))\n \n # [SETUP]\n title = Title(\"Fourier Approximation\", buff=MARGIN)\n ax = Axes(axis_color=BLUE, x_range=[-PI, PI, PI/2], y_range=[-1.5, 1.5, 0.5], x_length=7, y_length=4).shift(DOWN * 0.5)\n \n def fourier_square(x, n_terms):\n y = np.zeros_like(x)\n for k in range(1, n_terms + 1):\n n = 2 * k - 1\n y += (4.0 / (np.pi * n)) * np.sin(n * x)\n return y\n \n c1 = ax.plot(lambda x: fourier_square(np.array([x]), 1)[0], color=BLUE)\n c3 = ax.plot(lambda x: fourier_square(np.array([x]), 3)[0], color=TEAL)\n c7 = ax.plot(lambda x: fourier_square(np.array([x]), 7)[0], color=GREEN)\n c15 = ax.plot(lambda x: fourier_square(np.array([x]), 15)[0], color=YELLOW)\n \n # [LAYOUT]\n main_group = self.fit_in_frame(VGroup(title, ax))\n self.add(main_group)\n \n # [UPDATER]\n # None\n \n # [BEAT 1 | sync: b1]\n with self.voiceover(text=\"A square wave can be approximated by summing sine waves of odd harmonics. \") as t_voice:\n self.wait_until_bookmark(\"b1\")\n self.play(Create(ax), Create(c1), run_time=1.5)\n \n # [BEAT 2 | sync: b2]\n with self.voiceover(text=\"Increasing the number of terms in the Fourier series yields a closer approximation to the ideal square wave. \") as t_voice:\n self.wait_until_bookmark(\"b2\")\n self.play(Transform(c1, c3), run_time=1)\n self.play(Transform(c1, c7), run_time=1)\n self.play(Transform(c1, c15), run_time=1.5)\n self.wait(1)\n```", "category": "invalid_axes_kwarg", "source": "synthetic_hard_neg:nabin2004/qwen3-8b-manimator-gold-sft"} +{"system": "You are an expert Manim Community Edition (ManimCE v0.19+) Python developer and mathematical animator. Given a user request, first plan the spatial layout, coordinate bounds, timing, and pedagogical flow inside ... tags (when reasoning is helpful), and then output a complete, runnable, self-contained ManimCE Python script using `from manim import *`. Never use deprecated ManimGL (`manimlib`) methods like `ShowCreation`, `TexMobject`, `TextMobject`, or `axes.get_graph`; always use modern ManimCE APIs (`Create`, `MathTex`, `Tex`, `Text`, `axes.plot`) and prevent visual overlap using `.to_edge()`, `.next_to()`, and `FadeOut`.", "prompt": "The following Manim CE scene failed to compile. Truncated traceback:\n\nAttributeError: VGroup object has no attribute 'c2p'\n\nFix the code. Return a complete working scene. Do not keep the invalid constructor kwargs or Unicode subscripts.\n\n```python\nfrom manim import *\n\nclass AreaUnderCurveExample(Scene):\n def construct(self):\n axes_group = VGroup(NumberLine(), NumberLine())\n p = axes_group.c2p(1, 0)\n # Display the function\n function = MathTex(r\"f(x) = 3x^2 - 2x + 1\")\n self.play(Write(function))\n self.wait(1)\n\n # Show the area problem\n area_problem = MathTex(r\"\\int_1^3 f(x) \\,dx\")\n self.play(Transform(function, area_problem))\n self.wait(2)\n\n # Set up the integral\n setup_integral = MathTex(r\"\\int_1^3\", r\"3x^2 - 2x + 1 \\,dx\")\n self.play(Transform(area_problem, setup_integral))\n self.wait(1)\n\n # Perform the integration step\n integration_step = MathTex(r\"= [\\frac{3}{3}x^3 - \\frac{2}{2}x^2 + x]_1^3\")\n self.play(ReplacementTransform(setup_integral.copy(), integration_step))\n self.wait(2)\n\n # Simplify the integral result\n simplified_result = MathTex(r\"= [x^3 - x^2 + x]_1^3\")\n self.play(Transform(integration_step, simplified_result))\n self.wait(2)\n\n # Final evaluation\n final_evaluation = MathTex(r\"= (3^3 - 3^2 + 3) - (1^3 - 1^2 + 1)\", r\"= 27 - 9 + 3 - (1 - 1 + 1)\", r\"= 20\")\n self.play(ReplacementTransform(simplified_result, final_evaluation))\n self.wait(2)\n\n # Clear scene and show the final answer\n self.clear()\n self.play(Write(final_evaluation))\n self.wait(2)\n```", "chosen": "```python\nfrom manim import *\n\nclass AreaUnderCurveExample(Scene):\n def construct(self):\n # Display the function\n function = MathTex(r\"f(x) = 3x^2 - 2x + 1\")\n self.play(Write(function))\n self.wait(1)\n\n # Show the area problem\n area_problem = MathTex(r\"\\int_1^3 f(x) \\,dx\")\n self.play(Transform(function, area_problem))\n self.wait(2)\n\n # Set up the integral\n setup_integral = MathTex(r\"\\int_1^3\", r\"3x^2 - 2x + 1 \\,dx\")\n self.play(Transform(area_problem, setup_integral))\n self.wait(1)\n\n # Perform the integration step\n integration_step = MathTex(r\"= [\\frac{3}{3}x^3 - \\frac{2}{2}x^2 + x]_1^3\")\n self.play(ReplacementTransform(setup_integral.copy(), integration_step))\n self.wait(2)\n\n # Simplify the integral result\n simplified_result = MathTex(r\"= [x^3 - x^2 + x]_1^3\")\n self.play(Transform(integration_step, simplified_result))\n self.wait(2)\n\n # Final evaluation\n final_evaluation = MathTex(r\"= (3^3 - 3^2 + 3) - (1^3 - 1^2 + 1)\", r\"= 27 - 9 + 3 - (1 - 1 + 1)\", r\"= 20\")\n self.play(ReplacementTransform(simplified_result, final_evaluation))\n self.wait(2)\n\n # Clear scene and show the final answer\n self.clear()\n self.play(Write(final_evaluation))\n self.wait(2)\n```", "rejected": "```python\nfrom manim import *\n\nclass AreaUnderCurveExample(Scene):\n def construct(self):\n # Display the function\n function = TexMobject(r\"f(x) = 3x^2 - 2x + 1\")\n self.play(Write(function))\n self.wait(1)\n\n # Show the area problem\n area_problem = MathTex(r\"\\int_1^3 f(x) \\,dx\")\n self.play(Transform(function, area_problem))\n self.wait(2)\n\n # Set up the integral\n setup_integral = MathTex(r\"\\int_1^3\", r\"3x^2 - 2x + 1 \\,dx\")\n self.play(Transform(area_problem, setup_integral))\n self.wait(1)\n\n # Perform the integration step\n integration_step = MathTex(r\"= [\\frac{3}{3}x^3 - \\frac{2}{2}x^2 + x]_1^3\")\n self.play(ReplacementTransform(setup_integral.copy(), integration_step))\n self.wait(2)\n\n # Simplify the integral result\n simplified_result = MathTex(r\"= [x^3 - x^2 + x]_1^3\")\n self.play(Transform(integration_step, simplified_result))\n self.wait(2)\n\n # Final evaluation\n final_evaluation = MathTex(r\"= (3^3 - 3^2 + 3) - (1^3 - 1^2 + 1)\", r\"= 27 - 9 + 3 - (1 - 1 + 1)\", r\"= 20\")\n self.play(ReplacementTransform(simplified_result, final_evaluation))\n self.wait(2)\n\n # Clear scene and show the final answer\n self.clear()\n self.play(Write(final_evaluation))\n self.wait(2)\n```", "category": "legacy_api_hallucination", "source": "synthetic_hard_neg:nabin2004/manim-sft-10k"} +{"system": "You are an expert Manim Community Edition (ManimCE v0.19+) Python developer and mathematical animator. Given a user request, first plan the spatial layout, coordinate bounds, timing, and pedagogical flow inside ... tags (when reasoning is helpful), and then output a complete, runnable, self-contained ManimCE Python script using `from manim import *`. Never use deprecated ManimGL (`manimlib`) methods like `ShowCreation`, `TexMobject`, `TextMobject`, or `axes.get_graph`; always use modern ManimCE APIs (`Create`, `MathTex`, `Tex`, `Text`, `axes.plot`) and prevent visual overlap using `.to_edge()`, `.next_to()`, and `FadeOut`.", "prompt": "I'm teaching undergrads ML and want a vivid visualization of WaveNet training loss as depth changes (10, 20, 30 layers).\nShow three loss curves over epochs on a common axis with color-coded lines and clear convergence annotations.\nInclude a quick intuition for how depth affects the receptive field and a side-by-side comparison panel.", "chosen": "```python\nfrom manim import *\nfrom manim_voiceover import VoiceoverScene\nfrom manim_voiceover.services.gtts import GTTSService\n\n\nclass WaveNetTrainingLossVisualization(VoiceoverScene):\n def construct(self):\n self.set_speech_service(\n GTTSService(voice=\"alba\", cache_dir=\"voiceover_cache\")\n )\n \n # Title introduction\n title = Text(\"WaveNet Training Loss Visualization\", font_size=40, color=BLUE)\n subtitle = Text(\"Understanding Model Performance Through Loss Curves\", font_size=24, color=GRAY)\n subtitle.next_to(title, DOWN, buff=0.3)\n \n title_group = VGroup(title, subtitle)\n \n with self.voiceover(text=\"Imagine you are training a neural network to generate audio, and you are trying to make it sound more human-like. Let's dive in and learn how to visualize this critical aspect of training your WaveNet.\") as tracker:\n self.play(Write(title), run_time=tracker.duration * 0.5)\n self.play(FadeIn(subtitle), run_time=tracker.duration * 0.5)\n \n self.wait(0.5)\n \n # Clear and transition to explanation\n with self.voiceover(text=\"Training loss helps us understand how well our model is learning. Let's explore what a typical loss curve looks like.\") as tracker:\n self.play(FadeOut(title_group), run_time=tracker.duration)\n \n # Create axes for the loss plot\n axes = Axes(\n x_range=[0, 10, 1],\n y_range=[0, 3, 0.5],\n axis_config={\"color\": WHITE},\n x_axis_config={\"numbers_to_include\": range(0, 11, 2)},\n y_axis_config={\"numbers_to_include\": [0, 0.5, 1, 1.5, 2, 2.5, 3]},\n tips=False,\n )\n \n x_label = axes.get_x_axis_label(\"Epochs\", direction=DOWN, buff=0.3)\n y_label = axes.get_y_axis_label(\"Loss\", direction=LEFT, buff=0.3)\n \n axes_group = VGroup(axes, x_label, y_label)\n axes_group.scale(0.9)\n axes_group.to_edge(DOWN, buff=0.5)\n \n with self.voiceover(text=\"Here we have our axes. The x-axis represents epochs, or training iterations, and the y-axis shows the loss value.\") as tracker:\n self.play(Create(axes), Write(x_label), Write(y_label), run_time=tracker.duration)\n \n # Ideal training curve - smoothly decreasing\n def ideal_loss(x):\n return 2.5 * (0.85 ** x) + 0.3\n \n ideal_graph = axes.plot(ideal_loss, x_range=[0, 10], color=GREEN)\n ideal_label = Text(\"Ideal Training\", font_size=20, color=GREEN)\n ideal_label.next_to(axes.c2p(8, ideal_loss(8)), UP + RIGHT, buff=0.2)\n \n with self.voiceover(text=\"This green curve represents ideal training. The loss decreases smoothly as the model learns patterns in the audio data.\") as tracker:\n self.play(Create(ideal_graph), FadeIn(ideal_label), run_time=tracker.duration)\n \n self.wait(0.5)\n \n # Overfitting scenario\n def overfit_loss(x):\n if x < 3:\n return 2.5 * (0.7 ** x) + 0.5\n else:\n return 1.2 + 0.15 * (x - 3) ** 1.5\n \n overfit_graph = axes.plot(overfit_loss, x_range=[0, 10], color=RED)\n overfit_label = Text(\"Overfitting\", font_size=20, color=RED)\n overfit_label.next_to(axes.c2p(8, overfit_loss(8)), UP, buff=0.1)\n \n # Add a vertical line to show where overfitting begins\n overfit_start = axes.get_vertical_line(axes.c2p(3, overfit_loss(3)), color=YELLOW, line_config={\"dashed_ratio\": 0.5})\n overfit_annotation = Text(\"Overfitting starts\", font_size=16, color=YELLOW)\n overfit_annotation.next_to(overfit_start, RIGHT, buff=0.1)\n \n with self.voiceover(text=\"Now watch this red curve. It shows overfitting. Initially, the loss decreases, but then it starts increasing again. This means the model is memorizing training data instead of generalizing.\") as tracker:\n self.play(Create(overfit_graph), FadeIn(overfit_label), run_time=tracker.duration * 0.7)\n self.play(Create(overfit_start), FadeIn(overfit_annotation), run_time=tracker.duration * 0.3)\n \n self.wait(0.5)\n \n # Underfitting scenario\n def underfit_loss(x):\n return 2.0 - 0.3 * x + 0.015 * x**2\n \n underfit_graph = axes.plot(underfit_loss, x_range=[0, 10], color=ORANGE)\n underfit_label = Text(\"Underfitting\", font_size=20, color=ORANGE)\n underfit_label.next_to(axes.c2p(8, underfit_loss(8)), DOWN, buff=0.1)\n \n with self.voiceover(text=\"This orange curve represents underfitting. The loss remains high because the model is too simple to capture the complex patterns in WaveNet audio generation.\") as tracker:\n self.play(Create(underfit_graph), FadeIn(underfit_label), run_time=tracker.duration)\n \n self.wait(0.5)\n \n # Show all curves together with key takeaways\n curves_group = VGroup(ideal_graph, ideal_label, overfit_graph, overfit_label, \n overfit_start, overfit_annotation, underfit_graph, underfit_label)\n \n # Create takeaway boxes\n takeaway1 = Text(\"Green: Ideal - Loss decreases steadily\", font_size=18, color=GREEN)\n takeaway2 = Text(\"Red: Overfitting - Loss increases after minimum\", font_size=18, color=RED)\n takeaway3 = Text(\"Orange: Underfitting - Loss stays high\", font_size=18, color=ORANGE)\n \n takeaways = VGroup(takeaway1, takeaway2, takeaway3)\n takeaways.arrange(DOWN, aligned_edge=LEFT, buff=0.3)\n takeaways.to_edge(UP, buff=0.5)\n takeaways.to_edge(LEFT, buff=0.5)\n \n # Surrounding rectangle for takeaways\n takeaway_box = SurroundingRectangle(takeaways, color=BLUE, buff=0.3)\n takeaway_title = Text(\"Key Insights\", font_size=22, color=BLUE)\n takeaway_title.next_to(takeaway_box, UP, buff=0.1)\n \n with self.voiceover(text=\"To summarize, watch for these patterns. Green means good training. Red warns of overfitting. Orange signals underfitting.\") as tracker:\n self.play(\n curves_group.animate.scale(0.85).to_edge(DOWN + RIGHT, buff=0.3),\n FadeIn(takeaways),\n Create(takeaway_box),\n FadeIn(takeaway_title),\n run_time=tracker.duration\n )\n \n # Final message\n final_text = Text(\"Monitor your loss curves to train better WaveNet models!\", font_size=24, color=YELLOW)\n final_text.next_to(takeaway_box, DOWN, buff=0.5)\n \n with self.voiceover(text=\"By monitoring your loss curves, you can make informed decisions to train better WaveNet models for audio generation.\") as tracker:\n self.play(FadeIn(final_text), run_time=tracker.duration)\n \n self.wait(1)\n \n # Fade out everything\n self.play(FadeOut(Group(*self.mobjects)))\n```", "rejected": "```python\nfrom manim import *\n\nclass WaveNetTrainingLossVisualization(Scene):\n\n def construct(self):\n title = Text('WaveNet Training Loss Visualization', font_size=40, color=BLUE)\n subtitle = Text('Understanding Model Performance Through Loss Curves', font_size=24, color=GRAY)\n subtitle.next_to(title, DOWN, buff=0.3)\n title_group = VGroup(title, subtitle)\n self.play(Write(title), run_time=2.0 * 0.5)\n self.play(FadeIn(subtitle), run_time=2.0 * 0.5)\n self.wait(0.5)\n self.play(FadeOut(title_group), run_time=2.0)\n axes = Axes(x_range=[0, 10, 1], y_range=[0, 3, 0.5], axis_config={'color': WHITE}, x_axis_config={'numbers_to_include': range(0, 11, 2)}, y_axis_config={'numbers_to_include': [0, 0.5, 1, 1.5, 2, 2.5, 3]}, tips=False)\n x_label = axes.get_x_axis_label('Epochs', direction=DOWN, buff=0.3)\n y_label = axes.get_y_axis_label('Loss', direction=LEFT, buff=0.3)\n axes_group = VGroup(axes, x_label, y_label)\n axes_group.scale(0.9)\n axes_group.to_edge(DOWN, buff=0.5)\n self.play(Create(axes), Write(x_label), Write(y_label), run_time=2.0)\n\n def ideal_loss(x):\n return 2.5 * 0.85 ** x + 0.3\n ideal_graph = axes.plot(ideal_loss, x_range=[0, 10], color=GREEN)\n ideal_label = Text('Ideal Training', font_size=20, color=GREEN)\n ideal_label.next_to(axes.c2p(8, ideal_loss(8)), UP + RIGHT, buff=0.2)\n self.play(Create(ideal_graph), FadeIn(ideal_label), run_time=2.0)\n self.wait(0.5)\n\n def overfit_loss(x):\n if x < 3:\n return 2.5 * 0.7 ** x + 0.5\n else:\n return 1.2 + 0.15 * (x - 3) ** 1.5\n overfit_graph = axes.plot(overfit_loss, x_range=[0, 10], color=RED)\n overfit_label = Text('Overfitting', font_size=20, color=RED)\n overfit_label.next_to(axes.c2p(8, overfit_loss(8)), UP, buff=0.1)\n overfit_start = axes.get_vertical_line(axes.c2p(3, overfit_loss(3)), color=YELLOW, line_config={'dashed_ratio': 0.5})\n overfit_annotation = Text('Overfitting starts', font_size=16, color=YELLOW)\n overfit_annotation.next_to(overfit_start, RIGHT, buff=0.1)\n self.play(Create(overfit_graph), FadeIn(overfit_label), run_time=2.0 * 0.7)\n self.play(Create(overfit_start), FadeIn(overfit_annotation), run_time=2.0 * 0.3)\n self.wait(0.5)\n\n def underfit_loss(x):\n return 2.0 - 0.3 * x + 0.015 * x ** 2\n underfit_graph = axes.plot(underfit_loss, x_range=[0, 10], color=ORANGE)\n underfit_label = Text('Underfitting', font_size=20, color=ORANGE)\n underfit_label.next_to(axes.c2p(8, underfit_loss(8)), DOWN, buff=0.1)\n self.play(Create(underfit_graph), FadeIn(underfit_label), run_time=2.0)\n self.wait(0.5)\n curves_group = VGroup(ideal_graph, ideal_label, overfit_graph, overfit_label, overfit_start, overfit_annotation, underfit_graph, underfit_label)\n takeaway1 = Text('Green: Ideal - Loss decreases steadily', font_size=18, color=GREEN)\n takeaway2 = Text('Red: Overfitting - Loss increases after minimum', font_size=18, color=RED)\n takeaway3 = Text('Orange: Underfitting - Loss stays high', font_size=18, color=ORANGE)\n takeaways = VGroup(takeaway1, takeaway2, takeaway3)\n takeaways.arrange(DOWN, aligned_edge=LEFT, buff=0.3)\n takeaways.to_edge(UP, buff=0.5)\n takeaways.to_edge(LEFT, buff=0.5)\n takeaway_box = SurroundingRectangle(takeaways, color=BLUE, buff=0.3)\n takeaway_title = Text('Key Insights', font_size=22, color=BLUE)\n takeaway_title.next_to(takeaway_box, UP, buff=0.1)\n self.play(curves_group.animate.scale(0.85).to_edge(DOWN + RIGHT, buff=0.3), FadeIn(takeaways), Create(takeaway_box), FadeIn(takeaway_title), run_time=2.0)\n final_text = Text('Monitor your loss curves to train better WaveNet models!', font_size=24, color=YELLOW)\n final_text.next_to(takeaway_box, DOWN, buff=0.5)\n self.play(FadeIn(final_text), run_time=2.0)\n self.wait(1)\n self.play(FadeOut(Group(*self.mobjects)))\n```", "category": "narrated_pedagogical_preference", "source": "nabin2004/manim-narrated-dpo-400"} +{"system": "You are an expert Manim Community Edition (ManimCE v0.19+) Python developer and mathematical animator. Given a user request, first plan the spatial layout, coordinate bounds, timing, and pedagogical flow inside ... tags (when reasoning is helpful), and then output a complete, runnable, self-contained ManimCE Python script using `from manim import *`. Never use deprecated ManimGL (`manimlib`) methods like `ShowCreation`, `TexMobject`, `TextMobject`, or `axes.get_graph`; always use modern ManimCE APIs (`Create`, `MathTex`, `Tex`, `Text`, `axes.plot`) and prevent visual overlap using `.to_edge()`, `.next_to()`, and `FadeOut`.", "prompt": "Create an interactive Manim CE animation demonstrating: Riemann Rectangles adapting dynamically with ValueTracker. Use updaters and ValueTracker.\n\n```python\nfrom manim import *\nimport numpy as np\n\nclass DynamicScene302(Scene):\n def construct(self):\n ax = Axes(x_range=[0, 4, 1], y_range=[0, 5, 1], x_length=6, y_length=4)\n curve = ax.plot(lambda x: 0.5 * x**2, color=BLUE)\n k = ValueTracker(4)\n rects = always_redraw(lambda: ax.get_riemann_rectangles(\n curve, x_range=[0, 3], dx=3.0 / max(int(k.get_value()), 1), stroke_color=WHITE, fill_opacity=0.6\n ))\n count_text = Integer(4).to_corner(UL)\n count_text.add_updater(lambda m: m.set_value(int(k.get_value())))\n \n self.add(ax, curve, rects, count_text)\n self.play(k.animate.set_value(30), run_time=4, rate_func=linear)\n self.wait(1)\n```", "chosen": "```python\nfrom manim import *\nfrom manim_voiceover import VoiceoverScene\nfrom manim_voiceover.services.gtts import GTTSService\nimport numpy as np\n\nMARGIN = 0.5\n\nclass DynamicRiemannRectanglesScene(VoiceoverScene):\n def fit_in_frame(self, mob: Mobject, w_frac=0.9, h_frac=0.9) -> Mobject:\n max_w = config.frame_width * w_frac\n max_h = config.frame_height * h_frac\n if mob.width > max_w: mob.width = max_w\n if mob.height > max_h: mob.height = max_h\n return mob\n\n def construct(self):\n self.set_speech_service(GTTSService(transcription_model=\"base\"))\n\n # [SETUP]\n title = MathTex(r\"\\int_0^3 f(x)\\,dx \\approx \\sum f(x_i)\\,\\Delta x\").to_corner(UL, buff=MARGIN)\n ax = Axes(x_range=[0, 4, 1], y_range=[0, 5, 1], x_length=6, y_length=4)\n curve = ax.plot(lambda x: 0.5 * x**2, color=BLUE)\n\n # [LAYOUT]\n main_group = self.fit_in_frame(VGroup(title, ax, curve))\n self.add(main_group)\n\n # [UPDATER]\n k = ValueTracker(4)\n rects = always_redraw(lambda: ax.get_riemann_rectangles(\n curve, x_range=[0, 3], dx=3.0 / max(int(k.get_value()), 1),\n stroke_color=WHITE, fill_opacity=0.6\n ))\n count_text = Integer(4).to_corner(UR, buff=MARGIN)\n count_text.add_updater(lambda m: m.set_value(int(k.get_value())))\n self.add(rects, count_text)\n\n # [BEAT 1 | sync: b1]\n with self.voiceover(text=\"We approximate the area under a curve using Riemann rectangles. \") as t_voice:\n self.wait_until_bookmark(\"b1\")\n self.play(Write(title), Create(ax), Create(curve), run_time=2)\n\n # [BEAT 2 | sync: b2]\n with self.voiceover(text=\"As the partition count increases, each rectangle narrows and the sum converges toward the true integral. \") as t_voice:\n self.wait_until_bookmark(\"b2\")\n self.play(k.animate.set_value(30), run_time=4, rate_func=linear)\n self.wait(1)\n```", "rejected": "```python\nfrom manim import *\nfrom manim_voiceover import VoiceoverScene\nfrom manim_voiceover.services.gtts import GTTSService\nimport numpy as np\n\nMARGIN = 0.5\n\nclass DynamicRiemannRectanglesScene(VoiceoverScene):\n def fit_in_frame(self, mob: Mobject, w_frac=0.9, h_frac=0.9) -> Mobject:\n max_w = config.frame_width * w_frac\n max_h = config.frame_height * h_frac\n if mob.width > max_w: mob.width = max_w\n if mob.height > max_h: mob.height = max_h\n return mob\n\n def construct(self):\n self.set_speech_service(GTTSService(transcription_model=\"base\"))\n\n # [SETUP]\n title = MathTex(r\"\\int_0^3 f(x)\\,dx \\approx \\sum f(x_i)\\,\\Delta x\").to_corner(UL, buff=MARGIN)\n ax = Axes(axis_color=BLUE, x_range=[0, 4, 1], y_range=[0, 5, 1], x_length=6, y_length=4)\n curve = ax.plot(lambda x: 0.5 * x**2, color=BLUE)\n\n # [LAYOUT]\n main_group = self.fit_in_frame(VGroup(title, ax, curve))\n self.add(main_group)\n\n # [UPDATER]\n k = ValueTracker(4)\n rects = always_redraw(lambda: ax.get_riemann_rectangles(\n curve, x_range=[0, 3], dx=3.0 / max(int(k.get_value()), 1),\n stroke_color=WHITE, fill_opacity=0.6\n ))\n count_text = Integer(4).to_corner(UR, buff=MARGIN)\n count_text.add_updater(lambda m: m.set_value(int(k.get_value())))\n self.add(rects, count_text)\n\n # [BEAT 1 | sync: b1]\n with self.voiceover(text=\"We approximate the area under a curve using Riemann rectangles. \") as t_voice:\n self.wait_until_bookmark(\"b1\")\n self.play(Write(title), Create(ax), Create(curve), run_time=2)\n\n # [BEAT 2 | sync: b2]\n with self.voiceover(text=\"As the partition count increases, each rectangle narrows and the sum converges toward the true integral. \") as t_voice:\n self.wait_until_bookmark(\"b2\")\n self.play(k.animate.set_value(30), run_time=4, rate_func=linear)\n self.wait(1)\n```", "category": "invalid_axes_kwarg", "source": "synthetic_hard_neg:nabin2004/qwen3-8b-manimator-gold-sft"} +{"system": "You are an expert Manim Community Edition (ManimCE v0.19+) Python developer and mathematical animator. Given a user request, first plan the spatial layout, coordinate bounds, timing, and pedagogical flow inside ... tags (when reasoning is helpful), and then output a complete, runnable, self-contained ManimCE Python script using `from manim import *`. Never use deprecated ManimGL (`manimlib`) methods like `ShowCreation`, `TexMobject`, `TextMobject`, or `axes.get_graph`; always use modern ManimCE APIs (`Create`, `MathTex`, `Tex`, `Text`, `axes.plot`) and prevent visual overlap using `.to_edge()`, `.next_to()`, and `FadeOut`.", "prompt": "Create a 20-second Manim scene that explains convolutional feature maps. Start with an input image grid, then show several stacked feature maps, a pooling stage, and a final compressed representation with arrows and labels.", "chosen": "```python\nfrom manim import *\n\nclass FeatureMapStack(Scene):\n def construct(self):\n title = Text(\"Convolutional Feature Maps\", font_size=36).to_edge(UP)\n input_grid = VGroup(*[\n Square(side_length=0.22, stroke_width=1, fill_color=BLUE_B, fill_opacity=0.38)\n for _ in range(25)\n ]).arrange_in_grid(5, 5, buff=0.03).move_to(LEFT * 5)\n conv_stack = VGroup(*[\n Rectangle(width=1.1, height=1.7, stroke_color=TEAL_D, fill_color=TEAL_C, fill_opacity=0.18).shift(RIGHT * 0.14 * i + UP * 0.08 * i)\n for i in range(4)\n ]).move_to(LEFT * 1.8)\n pool_stack = VGroup(*[\n Rectangle(width=0.85, height=1.25, stroke_color=GREEN_D, fill_color=GREEN_C, fill_opacity=0.18).shift(RIGHT * 0.11 * i + UP * 0.07 * i)\n for i in range(3)\n ]).move_to(RIGHT * 1.0)\n embedding = VGroup(*[\n RoundedRectangle(corner_radius=0.08, width=0.55, height=0.28, color=PURPLE_D, fill_opacity=0.2).shift(DOWN * 0.34 * i)\n for i in range(5)\n ]).move_to(RIGHT * 4.3)\n labels = VGroup(\n Text(\"Input image\", font_size=24).next_to(input_grid, DOWN),\n Text(\"Conv features\", font_size=24).next_to(conv_stack, DOWN),\n Text(\"Pooling\", font_size=24).next_to(pool_stack, DOWN),\n Text(\"Embedding\", font_size=24).next_to(embedding, DOWN),\n )\n arrows = VGroup(\n Arrow(input_grid.get_right(), conv_stack.get_left(), buff=0.18, color=GRAY_B),\n Arrow(conv_stack.get_right(), pool_stack.get_left(), buff=0.18, color=GRAY_B),\n Arrow(pool_stack.get_right(), embedding.get_left(), buff=0.18, color=GRAY_B),\n )\n detail_box = SurroundingRectangle(conv_stack, color=YELLOW_D, buff=0.08)\n detail_text = Text(\"Each map responds to a different learned pattern.\", font_size=24, color=GRAY_C).to_edge(DOWN)\n self.play(FadeIn(title), FadeIn(input_grid), FadeIn(labels[0]), run_time=2)\n self.play(GrowArrow(arrows[0]), FadeIn(conv_stack), FadeIn(labels[1]), run_time=3)\n self.play(GrowArrow(arrows[1]), FadeIn(pool_stack), FadeIn(labels[2]), run_time=2.5)\n self.play(GrowArrow(arrows[2]), FadeIn(embedding), FadeIn(labels[3]), run_time=2.5)\n self.play(Create(detail_box), run_time=1.5)\n self.play(FadeIn(detail_text), Indicate(conv_stack, color=TEAL_A), Indicate(pool_stack, color=GREEN_A), run_time=4)\n self.play(FadeOut(detail_box), run_time=1)\n self.wait(2)\n```", "rejected": "```python\nfrom manim import *\n\nclass FeatureMapStack(Scene):\n def construct(self):\n title = Text(\"Convolutional Feature Maps\", font_size=36).to_edge(UP)\n input_grid = VGroup(*[\n Square(side_length=0.22, stroke_width=1, fill_color=BLUE_B, fill_opacity=0.38)\n for _ in range(25)\n ]).arrange_in_grid(5, 5, buff=0.03).move_to(LEFT * 5)\n conv_stack = VGroup(*[\n Rectangle(width=1.1, height=1.7, stroke_color=TEAL_D, fill_color=TEAL_C, fill_opacity=0.18).shift(RIGHT * 0.14 * i + UP * 0.08 * i)\n for i in range(4)\n ]).move_to(LEFT * 1.8)\n pool_stack = VGroup(*[\n Rectangle(width=0.85, height=1.25, stroke_color=GREEN_D, fill_color=GREEN_C, fill_opacity=0.18).shift(RIGHT * 0.11 * i + UP * 0.07 * i)\n for i in range(3)\n ]).move_to(RIGHT * 1.0)\n embedding = VGroup(*[\n RoundedRectangle(corner_radius=0.08, width=0.55, height=0.28, color=PURPLE_D, fill_opacity=0.2).shift(DOWN * 0.34 * i)\n for i in range(5)\n ]).move_to(RIGHT * 4.3)\n labels = VGroup(\n Text(\"Input image\", font_size=24).next_to(input_grid, DOWN),\n Text(\"Conv features\", font_size=24).next_to(conv_stack, DOWN),\n Text(\"Pooling\", font_size=24).next_to(pool_stack, DOWN),\n Text(\"Embedding\", font_size=24).next_to(embedding, DOWN),\n )\n arrows = VGroup(\n Arrow(input_grid.get_right(), conv_stack.get_left(), buff=0.18, color=GRAY_B),\n Arrow(conv_stack.get_right(), pool_stack.get_left(), buff=0.18, color=GRAY_B),\n Arrow(pool_stack.get_right(), embedding.get_left(), buff=0.18, color=GRAY_B),\n )\n detail_box = SurroundingRectangle(conv_stack, color=YELLOW_D, buff=0.08)\n detail_text = Text(\"Each map responds to a different learned pattern.\", font_size=24, color=GRAY_C).to_edge(DOWN)\n self.play(FadeIn(title), FadeIn(input_grid), FadeIn(labels[0]), run_time=2)\n self.play(GrowArrow(arrows[0]), FadeIn(conv_stack), FadeIn(labels[1]), run_time=3)\n self.play(GrowArrow(arrows[1]), FadeIn(pool_stack), FadeIn(labels[2]), run_time=2.5)\n self.play(GrowArrow(arrows[2]), FadeIn(embedding), FadeIn(labels[3]), run_time=2.5)\n self.play(ShowCreation(detail_box), run_time=1.5)\n self.play(FadeIn(detail_text), Indicate(conv_stack, color=TEAL_A), Indicate(pool_stack, color=GREEN_A), run_time=4)\n self.play(FadeOut(detail_box), run_time=1)\n self.wait(2)\n```", "category": "legacy_api_hallucination", "source": "synthetic_hard_neg:sebastianboehler/autoresearch-manim"} +{"system": "You are an expert Manim Community Edition (ManimCE v0.19+) Python developer and mathematical animator. Given a user request, first plan the spatial layout, coordinate bounds, timing, and pedagogical flow inside ... tags (when reasoning is helpful), and then output a complete, runnable, self-contained ManimCE Python script using `from manim import *`. Never use deprecated ManimGL (`manimlib`) methods like `ShowCreation`, `TexMobject`, `TextMobject`, or `axes.get_graph`; always use modern ManimCE APIs (`Create`, `MathTex`, `Tex`, `Text`, `axes.plot`) and prevent visual overlap using `.to_edge()`, `.next_to()`, and `FadeOut`.", "prompt": "I'm teaching undergrads how to read API docs and locate functions quickly. Visualize a mini docs page with a search bar, a results panel, and a highlighted API reference for a specific function. Animate typing, selecting the result, and opening the reference to show the signature, parameters, and a short example. Include a slow zoom into the code snippet and callouts explaining common pitfalls and related functions.", "chosen": "```python\nfrom manim import *\nfrom manim_voiceover import VoiceoverScene\nfrom manim_voiceover.services.gtts import GTTSService\n\nclass ReadingApiDocumentation(VoiceoverScene):\n def construct(self):\n self.set_speech_service(\n GTTSService(voice=\"alba\", cache_dir=\"voiceover_cache\")\n )\n\n # ===== TITLE =====\n title = Text(\"Reading API Documentation\", font_size=40)\n subtitle = Text(\"Subject: Computer Science\", font_size=24)\n subtitle.next_to(title, DOWN, buff=0.2)\n\n with self.voiceover(text=\"Welcome to today's lecture! In this lesson, we are going to master the skill of reading API documentation.\") as tracker:\n self.play(Write(title), run_time=tracker.duration * 0.5)\n self.play(FadeIn(subtitle), run_time=tracker.duration * 0.5)\n\n self.wait(0.5)\n self.play(FadeOut(title), FadeOut(subtitle))\n\n # ===== OPENER =====\n opener_line1 = Text(\"Have you ever stared at API docs,\", font_size=28)\n opener_line2 = Text(\"feeling completely overwhelmed?\", font_size=28)\n opener_line3 = Text(\"You're not alone!\", font_size=28)\n opener_group = VGroup(opener_line1, opener_line2, opener_line3)\n opener_group.arrange(DOWN, buff=0.25)\n opener_group.center()\n\n with self.voiceover(text=\"Have you ever stared at API documentation, feeling completely overwhelmed and unsure of where to start? You're not alone!\") as tracker:\n self.play(Write(opener_line1), run_time=tracker.duration * 0.35)\n self.play(Write(opener_line2), run_time=tracker.duration * 0.35)\n self.play(Write(opener_line3), run_time=tracker.duration * 0.30)\n\n self.wait(0.3)\n self.play(FadeOut(opener_group))\n\n # ===== KEY SECTIONS =====\n sections_title = Text(\"Key Sections of API Docs\", font_size=32)\n sections_title.to_edge(UP, buff=0.5)\n\n sections = VGroup(\n Text(\"1. Base URL\", font_size=24),\n Text(\"2. Authentication\", font_size=24),\n Text(\"3. Endpoints\", font_size=24),\n Text(\"4. Parameters\", font_size=24),\n Text(\"5. Response Format\", font_size=24),\n )\n sections.arrange(DOWN, aligned_edge=LEFT, buff=0.25)\n sections.next_to(sections_title, DOWN, buff=0.5)\n sections_box = SurroundingRectangle(sections, buff=0.25, color=BLUE)\n\n with self.voiceover(text=\"Today, we will simplify that daunting task. First, let's identify the key sections of API documentation.\") as tracker:\n self.play(Write(sections_title), run_time=tracker.duration * 0.25)\n self.play(Create(sections_box), Write(sections), run_time=tracker.duration * 0.75)\n\n self.wait(0.3)\n self.play(FadeOut(sections_title), FadeOut(sections_box), FadeOut(sections))\n\n # ===== ENDPOINT BREAKDOWN =====\n endpoint_title = Text(\"Reading an Endpoint\", font_size=32)\n endpoint_title.to_edge(UP, buff=0.5)\n\n method_box = RoundedRectangle(width=1.0, height=0.4, corner_radius=0.1, fill_color=GREEN, fill_opacity=0.3, color=GREEN)\n method_text = Text(\"GET\", font_size=20, color=GREEN).move_to(method_box.get_center())\n method_group = VGroup(method_box, method_text)\n\n path_text = Text(\" /users/{id}\", font_size=24)\n endpoint_header = VGroup(method_group, path_text)\n endpoint_header.arrange(RIGHT, buff=0.2)\n endpoint_header.move_to(UP * 1.2)\n\n desc = Text(\"Retrieve a user by ID.\", font_size=22)\n desc.next_to(endpoint_header, DOWN, buff=0.4)\n\n param1 = Text(\"Parameter: id (integer, required)\", font_size=20)\n param2 = Text(\"Response: JSON user object\", font_size=20)\n details = VGroup(param1, param2)\n details.arrange(DOWN, aligned_edge=LEFT, buff=0.2)\n details.next_to(desc, DOWN, buff=0.3)\n\n with self.voiceover(text=\"When reading an endpoint, look for the HTTP method, the path, a description, required parameters, and the response format.\") as tracker:\n self.play(Write(endpoint_title), run_time=tracker.duration * 0.2)\n self.play(FadeIn(endpoint_header), run_time=tracker.duration * 0.3)\n self.play(Write(desc), run_time=tracker.duration * 0.25)\n self.play(Write(details), run_time=tracker.duration * 0.25)\n\n self.wait(0.3)\n self.play(FadeOut(endpoint_title), FadeOut(endpoint_header), FadeOut(desc), FadeOut(details))\n\n # ===== CODE EXAMPLE =====\n code_title = Text(\"Code Examples\", font_size=32)\n code_title.to_edge(UP, buff=0.5)\n\n code_lines = VGroup(\n Text(\"import requests\", font_size=20),\n Text(\"url = 'https://api.example.com/users/123'\", font_size=20),\n Text(\"headers = {'Authorization': 'Bearer token'}\", font_size=20),\n Text(\"response = requests.get(url, headers=headers)\", font_size=20),\n Text(\"data = response.json()\", font_size=20),\n )\n code_lines.arrange(DOWN, aligned_edge=LEFT, buff=0.12)\n code_lines.next_to(code_title, DOWN, buff=0.4)\n code_box = SurroundingRectangle(code_lines, buff=0.2, color=BLUE)\n\n with self.voiceover(text=\"Code examples show you exactly how to integrate the API. Pay attention to the URL, headers, and how the response is handled.\") as tracker:\n self.play(Write(code_title), run_time=tracker.duration * 0.2)\n self.play(Create(code_box), Write(code_lines), run_time=tracker.duration * 0.8)\n\n self.wait(0.3)\n self.play(FadeOut(code_title), FadeOut(code_box), FadeOut(code_lines))\n\n # ===== TAKEAWAYS =====\n takeaways_title = Text(\"Key Takeaways\", font_size=32)\n takeaways_title.to_edge(UP, buff=0.5)\n\n left_col = VGroup(\n Text(\"Identify sections\", font_size=20),\n Text(\"Read endpoints\", font_size=20),\n Text(\"Check parameters\", font_size=20),\n )\n left_col.arrange(DOWN, aligned_edge=LEFT, buff=0.2)\n\n right_col = VGroup(\n Text(\"Study code examples\", font_size=20),\n Text(\"Test responses\", font_size=20),\n Text(\"Build confidence!\", font_size=20),\n )\n right_col.arrange(DOWN, aligned_edge=LEFT, buff=0.2)\n\n cols = VGroup(left_col, right_col)\n cols.arrange(RIGHT, buff=0.6)\n cols.next_to(takeaways_title, DOWN, buff=0.4)\n\n takeaway_box = SurroundingRectangle(cols, buff=0.25, color=YELLOW)\n\n with self.voiceover(text=\"To summarize: identify the key sections, read endpoints carefully, check parameters, study code examples, and practice. You now have the confidence to use API documentation like a pro.\") as tracker:\n self.play(Write(takeaways_title), run_time=tracker.duration * 0.2)\n self.play(Create(takeaway_box), Write(cols), run_time=tracker.duration * 0.8)\n\n self.wait(1)\n```", "rejected": "```python\nfrom manim import *\nfrom manim_voiceover import VoiceoverScene\nfrom manim_voiceover.services.gtts import GTTSService\n\nclass ReadingApiDocumentation(VoiceoverScene):\n def construct(self):\n self.set_speech_service(\n GTTSService(voice=\"alba\", cache_dir=\"voiceover_cache\")\n )\n\n # ===== TITLE =====\n title = Text(\"Reading API Documentation\", font_size=40)\n subtitle = Text(\"Subject: Computer Science\", font_size=24)\n subtitle\n\n with self.voiceover(text=\"Welcome to today's lecture! In this lesson, we are going to master the skill of reading API documentation.\") as tracker:\n self.play(Write(title), run_time=tracker.duration * 0.5)\n self.play(FadeIn(subtitle), run_time=tracker.duration * 0.5)\n\n self.wait(0.5)\n self.play(FadeOut(title), FadeOut(subtitle))\n\n # ===== OPENER =====\n opener_line1 = Text(\"Have you ever stared at API docs,\", font_size=28)\n opener_line2 = Text(\"feeling completely overwhelmed?\", font_size=28)\n opener_line3 = Text(\"You're not alone!\", font_size=28)\n opener_group = VGroup(opener_line1, opener_line2, opener_line3)\n opener_group.arrange(DOWN, buff=0.25)\n opener_group.center()\n\n with self.voiceover(text=\"Have you ever stared at API documentation, feeling completely overwhelmed and unsure of where to start? You're not alone!\") as tracker:\n self.play(Write(opener_line1), run_time=tracker.duration * 0.35)\n self.play(Write(opener_line2), run_time=tracker.duration * 0.35)\n self.play(Write(opener_line3), run_time=tracker.duration * 0.30)\n\n self.wait(0.3)\n self.play(FadeOut(opener_group))\n\n # ===== KEY SECTIONS =====\n sections_title = Text(\"Key Sections of API Docs\", font_size=32)\n sections_title\n\n sections = VGroup(\n Text(\"1. Base URL\", font_size=24),\n Text(\"2. Authentication\", font_size=24),\n Text(\"3. Endpoints\", font_size=24),\n Text(\"4. Parameters\", font_size=24),\n Text(\"5. Response Format\", font_size=24),\n )\n sections.arrange(DOWN, aligned_edge=LEFT, buff=0.25)\n sections\n sections_box = SurroundingRectangle(sections, buff=0.25, color=BLUE)\n\n with self.voiceover(text=\"Today, we will simplify that daunting task. First, let's identify the key sections of API documentation.\") as tracker:\n self.play(Write(sections_title), run_time=tracker.duration * 0.25)\n self.play(Create(sections_box), Write(sections), run_time=tracker.duration * 0.75)\n\n self.wait(0.3)\n self.play(FadeOut(sections_title), FadeOut(sections_box), FadeOut(sections))\n\n # ===== ENDPOINT BREAKDOWN =====\n endpoint_title = Text(\"Reading an Endpoint\", font_size=32)\n endpoint_title.to_edge(UP, buff=0.5)\n\n method_box = RoundedRectangle(width=1.0, height=0.4, corner_radius=0.1, fill_color=GREEN, fill_opacity=0.3, color=GREEN)\n method_text = Text(\"GET\", font_size=20, color=GREEN).move_to(method_box.get_center())\n method_group = VGroup(method_box, method_text)\n\n path_text = Text(\" /users/{id}\", font_size=24)\n endpoint_header = VGroup(method_group, path_text)\n endpoint_header.arrange(RIGHT, buff=0.2)\n endpoint_header.move_to(UP * 1.2)\n\n desc = Text(\"Retrieve a user by ID.\", font_size=22)\n desc.next_to(endpoint_header, DOWN, buff=0.4)\n\n param1 = Text(\"Parameter: id (integer, required)\", font_size=20)\n param2 = Text(\"Response: JSON user object\", font_size=20)\n details = VGroup(param1, param2)\n details.arrange(DOWN, aligned_edge=LEFT, buff=0.2)\n details.next_to(desc, DOWN, buff=0.3)\n\n with self.voiceover(text=\"When reading an endpoint, look for the HTTP method, the path, a description, required parameters, and the response format.\") as tracker:\n self.play(Write(endpoint_title), run_time=tracker.duration * 0.2)\n self.play(FadeIn(endpoint_header), run_time=tracker.duration * 0.3)\n self.play(Write(desc), run_time=tracker.duration * 0.25)\n self.play(Write(details), run_time=tracker.duration * 0.25)\n\n self.wait(0.3)\n self.play(FadeOut(endpoint_title), FadeOut(endpoint_header), FadeOut(desc), FadeOut(details))\n\n # ===== CODE EXAMPLE =====\n code_title = Text(\"Code Examples\", font_size=32)\n code_title.to_edge(UP, buff=0.5)\n\n code_lines = VGroup(\n Text(\"import requests\", font_size=20),\n Text(\"url = 'https://api.example.com/users/123'\", font_size=20),\n Text(\"headers = {'Authorization': 'Bearer token'}\", font_size=20),\n Text(\"response = requests.get(url, headers=headers)\", font_size=20),\n Text(\"data = response.json()\", font_size=20),\n )\n code_lines.arrange(DOWN, aligned_edge=LEFT, buff=0.12)\n code_lines.next_to(code_title, DOWN, buff=0.4)\n code_box = SurroundingRectangle(code_lines, buff=0.2, color=BLUE)\n\n with self.voiceover(text=\"Code examples show you exactly how to integrate the API. Pay attention to the URL, headers, and how the response is handled.\") as tracker:\n self.play(Write(code_title), run_time=tracker.duration * 0.2)\n self.play(Create(code_box), Write(code_lines), run_time=tracker.duration * 0.8)\n\n self.wait(0.3)\n self.play(FadeOut(code_title), FadeOut(code_box), FadeOut(code_lines))\n\n # ===== TAKEAWAYS =====\n takeaways_title = Text(\"Key Takeaways\", font_size=32)\n takeaways_title.to_edge(UP, buff=0.5)\n\n left_col = VGroup(\n Text(\"Identify sections\", font_size=20),\n Text(\"Read endpoints\", font_size=20),\n Text(\"Check parameters\", font_size=20),\n )\n left_col.arrange(DOWN, aligned_edge=LEFT, buff=0.2)\n\n right_col = VGroup(\n Text(\"Study code examples\", font_size=20),\n Text(\"Test responses\", font_size=20),\n Text(\"Build confidence!\", font_size=20),\n )\n right_col.arrange(DOWN, aligned_edge=LEFT, buff=0.2)\n\n cols = VGroup(left_col, right_col)\n cols.arrange(RIGHT, buff=0.6)\n cols.next_to(takeaways_title, DOWN, buff=0.4)\n\n takeaway_box = SurroundingRectangle(cols, buff=0.25, color=YELLOW)\n\n with self.voiceover(text=\"To summarize: identify the key sections, read endpoints carefully, check parameters, study code examples, and practice. You now have the confidence to use API documentation like a pro.\") as tracker:\n self.play(Write(takeaways_title), run_time=tracker.duration * 0.2)\n self.play(Create(takeaway_box), Write(cols), run_time=tracker.duration * 0.8)\n\n self.wait(1)\n```", "category": "spatial_layout_overlap", "source": "synthetic_hard_neg:nabin2004/AOS-Narrated-Manim-400"} +{"system": "You are an expert Manim Community Edition (ManimCE v0.19+) Python developer and mathematical animator. Given a user request, first plan the spatial layout, coordinate bounds, timing, and pedagogical flow inside ... tags (when reasoning is helpful), and then output a complete, runnable, self-contained ManimCE Python script using `from manim import *`. Never use deprecated ManimGL (`manimlib`) methods like `ShowCreation`, `TexMobject`, `TextMobject`, or `axes.get_graph`; always use modern ManimCE APIs (`Create`, `MathTex`, `Tex`, `Text`, `axes.plot`) and prevent visual overlap using `.to_edge()`, `.next_to()`, and `FadeOut`.", "prompt": "Construct a clean Manim CE scene initializing Brace with verified keyword arguments. Ensure no deprecated ManimGL arguments (like element_color, max_value, or max_magnitude) are used.\n\n```python\nfrom manim import *\nimport numpy as np\n\nclass ApiValidBrace407(Scene):\n def construct(self):\n obj = Brace(Line(LEFT * 2, RIGHT * 2), direction=DOWN)\n obj.set_color(GREEN)\n self.play(Create(obj))\n self.wait(1)\n```", "chosen": "```python\nfrom manim import *\nfrom manim_voiceover import VoiceoverScene\nfrom manim_voiceover.services.gtts import GTTSService\n\nclass ApiValidBrace407(VoiceoverScene):\n MARGIN = 0.5\n\n def fit_in_frame(self, mob: Mobject, w_frac=0.9, h_frac=0.9) -> Mobject:\n max_w = config.frame_width * w_frac\n max_h = config.frame_height * h_frac\n if mob.width > max_w:\n mob.width = max_w\n if mob.height > max_h:\n mob.height = max_h\n return mob\n\n def construct(self):\n self.set_speech_service(GTTSService(transcription_model=\"base\"))\n \n # [SETUP]\n title = Title(\"Brace Initialization\")\n self.fit_in_frame(title)\n \n # [LAYOUT]\n obj = Brace(Line(LEFT * 2, RIGHT * 2), direction=DOWN)\n obj.set_color(GREEN)\n self.fit_in_frame(obj)\n \n # [BEAT 1 | sync: b1]\n with self.voiceover(text=\"Here is a correctly initialized brace in Manim Community Edition. We avoid deprecated arguments and use standard positioning.\") as t:\n self.wait_until_bookmark(\"b1\")\n self.play(Write(title), Create(obj))\n self.wait(1)\n```", "rejected": "```python\nfrom manim import *\nfrom manim_voiceover import VoiceoverScene\nfrom manim_voiceover.services.gtts import GTTSService\n\nclass ApiValidBrace407(VoiceoverScene):\n MARGIN = 0.5\n\n def fit_in_frame(self, mob: Mobject, w_frac=0.9, h_frac=0.9) -> Mobject:\n max_w = config.frame_width * w_frac\n max_h = config.frame_height * h_frac\n if mob.width > max_w:\n mob.width = max_w\n if mob.height > max_h:\n mob.height = max_h\n return mob\n\n def construct(self):\n self.set_speech_service(GTTSService(transcription_model=\"base\"))\n \n # [SETUP]\n title = Title(\"Brace Initialization\")\n self.fit_in_frame(title)\n \n # [LAYOUT]\n obj = Brace(Line(LEFT * 2, RIGHT * 2), direction=DOWN)\n obj.set_color(GREEN)\n self.fit_in_frame(obj)\n \n # [BEAT 1 | sync: b1]\n with self.voiceover(text=\"Here is a correctly initialized brace in Manim Community Edition. We avoid deprecated arguments and use standard positioning.\") as t:\n self.wait_until_bookmark(\"b1\")\n self.play(Write(title), ShowCreation(obj))\n self.wait(1)\n```", "category": "legacy_api_hallucination", "source": "synthetic_hard_neg:nabin2004/qwen3-8b-manimator-gold-sft"} +{"system": "You are an expert Manim Community Edition (ManimCE v0.19+) Python developer and mathematical animator. Given a user request, first plan the spatial layout, coordinate bounds, timing, and pedagogical flow inside ... tags (when reasoning is helpful), and then output a complete, runnable, self-contained ManimCE Python script using `from manim import *`. Never use deprecated ManimGL (`manimlib`) methods like `ShowCreation`, `TexMobject`, `TextMobject`, or `axes.get_graph`; always use modern ManimCE APIs (`Create`, `MathTex`, `Tex`, `Text`, `axes.plot`) and prevent visual overlap using `.to_edge()`, `.next_to()`, and `FadeOut`.", "prompt": "I'm teaching calculus to undergrads and want a geometric visualization of the product rule using rectangle areas. Construct small perturbations of f and g and decompose the change in area into four rectangles to illustrate d(fg) = f dg + g df. Include a sequence of scenes: a grid area for fg, traces of f and g, and a timed transition to the differential form. We should sweep parameters, show a quick algebraic check, and zoom into the tiny rectangles to reveal the limit process.", "chosen": "```python\nfrom manim import *\nfrom manim_voiceover import VoiceoverScene\nfrom manim_voiceover.services.gtts import GTTSService\n\nclass ProductRuleGeometricVisualization(VoiceoverScene):\n def construct(self):\n self.set_speech_service(\n GTTSService(voice=\"alba\", cache_dir=\"voiceover_cache\")\n )\n \n # Title\n title = Text(\"Product Rule: A Geometric View\", font_size=32).to_edge(UP, buff=0.2)\n \n # Geometry constants (bottom-left anchor)\n bl = np.array([-2, -1.0, 0])\n w0, h0 = 3.0, 2.0\n dw, dh = 1.5, 1.5\n \n # Original rectangle: area = f * g\n rect_orig = Rectangle(width=w0, height=h0, color=BLUE, fill_opacity=0.6, stroke_width=2)\n rect_orig.move_to(bl + np.array([w0/2, h0/2, 0]))\n \n # Right strip: area = g * df\n strip_r = Rectangle(width=dw, height=h0, color=GREEN, fill_opacity=0.6, stroke_width=2)\n strip_r.move_to(bl + np.array([w0 + dw/2, h0/2, 0]))\n \n # Top strip: area = f * dg\n strip_t = Rectangle(width=w0, height=dh, color=YELLOW, fill_opacity=0.6, stroke_width=2)\n strip_t.move_to(bl + np.array([w0/2, h0 + dh/2, 0]))\n \n # Corner: area = df * dg\n corner = Rectangle(width=dw, height=dh, color=RED, fill_opacity=0.6, stroke_width=2)\n corner.move_to(bl + np.array([w0 + dw/2, h0 + dh/2, 0]))\n \n # Dashed outline of the expanded rectangle\n new_total = Rectangle(width=w0+dw, height=h0+dh, color=WHITE, stroke_width=2)\n new_total.move_to(bl + np.array([(w0+dw)/2, (h0+dh)/2, 0]))\n dashed_outline = DashedVMobject(new_total, num_dashes=25)\n \n # Side labels\n label_f = MathTex(r\"f(x)\").scale(0.8).next_to(rect_orig, DOWN, buff=0.2)\n label_g = MathTex(r\"g(x)\").scale(0.8).next_to(rect_orig, LEFT, buff=0.15)\n label_df = MathTex(r\"df\").scale(0.8).next_to(strip_r, DOWN, buff=0.2)\n label_dg = MathTex(r\"dg\").scale(0.8).next_to(strip_t, LEFT, buff=0.15)\n \n # Internal area labels\n area_fg = MathTex(r\"f \\cdot g\", color=WHITE).scale(0.8).move_to(rect_orig.get_center())\n area_g_df = MathTex(r\"g \\, df\", color=BLACK).scale(0.7).move_to(strip_r.get_center())\n area_f_dg = MathTex(r\"f \\, dg\", color=BLACK).scale(0.7).move_to(strip_t.get_center())\n area_df_dg = MathTex(r\"df \\, dg\", color=WHITE).scale(0.6).move_to(corner.get_center())\n \n # Equations placed on the right side\n eq1 = MathTex(r\"d(fg) \\approx f \\, dg + g \\, df\").scale(0.9)\n eq2 = MathTex(r\"(fg)' = f \\, g' + g \\, f'\").scale(1.0)\n eq_group = VGroup(eq1, eq2).arrange(DOWN, buff=0.6).to_edge(RIGHT, buff=0.5).shift(UP*0.5)\n \n # --- Animations ---\n \n with self.voiceover(text=\"Have you ever wondered how the product of two functions changes as you differentiate them?\") as tracker:\n self.play(Write(title), run_time=tracker.duration)\n \n with self.voiceover(text=\"Imagine a rectangle whose sides are f of x and g of x. Its area is the product f times g.\") as tracker:\n self.play(Create(rect_orig), run_time=tracker.duration * 0.6)\n self.play(FadeIn(label_f), FadeIn(label_g), FadeIn(area_fg), run_time=tracker.duration * 0.4)\n \n with self.voiceover(text=\"Now, both dimensions change by tiny amounts: the width changes by d f, and the height changes by d g.\") as tracker:\n self.play(FadeIn(dashed_outline), FadeIn(label_df), FadeIn(label_dg), run_time=tracker.duration)\n \n with self.voiceover(text=\"The new area includes the original region plus three new pieces.\") as tracker:\n self.play(FadeIn(strip_r), FadeIn(strip_t), FadeIn(corner), run_time=tracker.duration * 0.6)\n self.play(FadeIn(area_g_df), FadeIn(area_f_dg), FadeIn(area_df_dg), run_time=tracker.duration * 0.4)\n \n with self.voiceover(text=\"On the right, the green strip has area g times d f.\") as tracker:\n self.play(strip_r.animate.set_fill(opacity=0.9), run_time=tracker.duration * 0.5)\n self.play(strip_r.animate.set_fill(opacity=0.6), run_time=tracker.duration * 0.5)\n \n with self.voiceover(text=\"On top, the yellow strip has area f times d g.\") as tracker:\n self.play(strip_t.animate.set_fill(opacity=0.9), run_time=tracker.duration * 0.5)\n self.play(strip_t.animate.set_fill(opacity=0.6), run_time=tracker.duration * 0.5)\n \n with self.voiceover(text=\"And in the corner, a tiny red rectangle with area d f times d g.\") as tracker:\n self.play(corner.animate.set_fill(opacity=0.9), run_time=tracker.duration * 0.5)\n self.play(corner.animate.set_fill(opacity=0.6), run_time=tracker.duration * 0.5)\n \n with self.voiceover(text=\"Because d f and d g are infinitesimally small, this corner piece is negligible compared to the other strips. So we ignore it.\") as tracker:\n self.play(FadeOut(corner), FadeOut(area_df_dg), run_time=tracker.duration)\n \n with self.voiceover(text=\"The total change in area is therefore approximately f d g plus g d f.\") as tracker:\n self.play(Write(eq1), run_time=tracker.duration)\n \n with self.voiceover(text=\"Dividing both sides by d x and taking the limit gives the product rule: the derivative of f g equals f g prime plus g f prime.\") as tracker:\n self.play(Write(eq2), run_time=tracker.duration)\n \n self.wait(2)\n```", "rejected": "```python\nfrom manim import *\nfrom manim_voiceover import VoiceoverScene\nfrom manim_voiceover.services.gtts import GTTSService\n\nclass ProductRuleGeometricVisualization(VoiceoverScene):\n def construct(self):\n self.set_speech_service(\n GTTSService(voice=\"alba\", cache_dir=\"voiceover_cache\")\n )\n \n # Title\n title = Text(\"Product Rule: A Geometric View\", font_size=32).to_edge(UP, buff=0.2)\n \n # Geometry constants (bottom-left anchor)\n bl = np.array([-2, -1.0, 0])\n w0, h0 = 3.0, 2.0\n dw, dh = 1.5, 1.5\n \n # Original rectangle: area = f * g\n rect_orig = Rectangle(width=w0, height=h0, color=BLUE, fill_opacity=0.6, stroke_width=2)\n rect_orig.move_to(bl + np.array([w0/2, h0/2, 0]))\n \n # Right strip: area = g * df\n strip_r = Rectangle(width=dw, height=h0, color=GREEN, fill_opacity=0.6, stroke_width=2)\n strip_r.move_to(bl + np.array([w0 + dw/2, h0/2, 0]))\n \n # Top strip: area = f * dg\n strip_t = Rectangle(width=w0, height=dh, color=YELLOW, fill_opacity=0.6, stroke_width=2)\n strip_t.move_to(bl + np.array([w0/2, h0 + dh/2, 0]))\n \n # Corner: area = df * dg\n corner = Rectangle(width=dw, height=dh, color=RED, fill_opacity=0.6, stroke_width=2)\n corner.move_to(bl + np.array([w0 + dw/2, h0 + dh/2, 0]))\n \n # Dashed outline of the expanded rectangle\n new_total = Rectangle(width=w0+dw, height=h0+dh, color=WHITE, stroke_width=2)\n new_total.move_to(bl + np.array([(w0+dw)/2, (h0+dh)/2, 0]))\n dashed_outline = DashedVMobject(new_total, num_dashes=25)\n \n # Side labels\n label_f = TexMobject(r\"f(x)\").scale(0.8).next_to(rect_orig, DOWN, buff=0.2)\n label_g = MathTex(r\"g(x)\").scale(0.8).next_to(rect_orig, LEFT, buff=0.15)\n label_df = MathTex(r\"df\").scale(0.8).next_to(strip_r, DOWN, buff=0.2)\n label_dg = MathTex(r\"dg\").scale(0.8).next_to(strip_t, LEFT, buff=0.15)\n \n # Internal area labels\n area_fg = MathTex(r\"f \\cdot g\", color=WHITE).scale(0.8).move_to(rect_orig.get_center())\n area_g_df = MathTex(r\"g \\, df\", color=BLACK).scale(0.7).move_to(strip_r.get_center())\n area_f_dg = MathTex(r\"f \\, dg\", color=BLACK).scale(0.7).move_to(strip_t.get_center())\n area_df_dg = MathTex(r\"df \\, dg\", color=WHITE).scale(0.6).move_to(corner.get_center())\n \n # Equations placed on the right side\n eq1 = MathTex(r\"d(fg) \\approx f \\, dg + g \\, df\").scale(0.9)\n eq2 = MathTex(r\"(fg)' = f \\, g' + g \\, f'\").scale(1.0)\n eq_group = VGroup(eq1, eq2).arrange(DOWN, buff=0.6).to_edge(RIGHT, buff=0.5).shift(UP*0.5)\n \n # --- Animations ---\n \n with self.voiceover(text=\"Have you ever wondered how the product of two functions changes as you differentiate them?\") as tracker:\n self.play(Write(title), run_time=tracker.duration)\n \n with self.voiceover(text=\"Imagine a rectangle whose sides are f of x and g of x. Its area is the product f times g.\") as tracker:\n self.play(ShowCreation(rect_orig), run_time=tracker.duration * 0.6)\n self.play(FadeIn(label_f), FadeIn(label_g), FadeIn(area_fg), run_time=tracker.duration * 0.4)\n \n with self.voiceover(text=\"Now, both dimensions change by tiny amounts: the width changes by d f, and the height changes by d g.\") as tracker:\n self.play(FadeIn(dashed_outline), FadeIn(label_df), FadeIn(label_dg), run_time=tracker.duration)\n \n with self.voiceover(text=\"The new area includes the original region plus three new pieces.\") as tracker:\n self.play(FadeIn(strip_r), FadeIn(strip_t), FadeIn(corner), run_time=tracker.duration * 0.6)\n self.play(FadeIn(area_g_df), FadeIn(area_f_dg), FadeIn(area_df_dg), run_time=tracker.duration * 0.4)\n \n with self.voiceover(text=\"On the right, the green strip has area g times d f.\") as tracker:\n self.play(strip_r.animate.set_fill(opacity=0.9), run_time=tracker.duration * 0.5)\n self.play(strip_r.animate.set_fill(opacity=0.6), run_time=tracker.duration * 0.5)\n \n with self.voiceover(text=\"On top, the yellow strip has area f times d g.\") as tracker:\n self.play(strip_t.animate.set_fill(opacity=0.9), run_time=tracker.duration * 0.5)\n self.play(strip_t.animate.set_fill(opacity=0.6), run_time=tracker.duration * 0.5)\n \n with self.voiceover(text=\"And in the corner, a tiny red rectangle with area d f times d g.\") as tracker:\n self.play(corner.animate.set_fill(opacity=0.9), run_time=tracker.duration * 0.5)\n self.play(corner.animate.set_fill(opacity=0.6), run_time=tracker.duration * 0.5)\n \n with self.voiceover(text=\"Because d f and d g are infinitesimally small, this corner piece is negligible compared to the other strips. So we ignore it.\") as tracker:\n self.play(FadeOut(corner), FadeOut(area_df_dg), run_time=tracker.duration)\n \n with self.voiceover(text=\"The total change in area is therefore approximately f d g plus g d f.\") as tracker:\n self.play(Write(eq1), run_time=tracker.duration)\n \n with self.voiceover(text=\"Dividing both sides by d x and taking the limit gives the product rule: the derivative of f g equals f g prime plus g f prime.\") as tracker:\n self.play(Write(eq2), run_time=tracker.duration)\n \n self.wait(2)\n```", "category": "legacy_api_hallucination", "source": "synthetic_hard_neg:nabin2004/AOS-Narrated-Manim-400"} +{"system": "You are an expert Manim Community Edition (ManimCE v0.19+) Python developer and mathematical animator. Given a user request, first plan the spatial layout, coordinate bounds, timing, and pedagogical flow inside ... tags (when reasoning is helpful), and then output a complete, runnable, self-contained ManimCE Python script using `from manim import *`. Never use deprecated ManimGL (`manimlib`) methods like `ShowCreation`, `TexMobject`, `TextMobject`, or `axes.get_graph`; always use modern ManimCE APIs (`Create`, `MathTex`, `Tex`, `Text`, `axes.plot`) and prevent visual overlap using `.to_edge()`, `.next_to()`, and `FadeOut`.", "prompt": "How do random walks in different geometric domains compare, such as on a plane versus a sphere?", "chosen": "```python\nfrom manim import *\nimport numpy as np\n\nclass RandomWalksComparison(Scene):\n def construct(self):\n # Title of the animation\n title = Text(\"Random Walks: Planes vs. Spheres\", font_size=32)\n self.play(Write(title))\n self.wait(1)\n self.play(title.animate.to_edge(UP))\n \n # Setup the plane side with a grid\n plane_title = Text(\"On a Plane\", font_size=24).shift(LEFT * 3 + UP * 2)\n \n # Create a simple grid to represent the plane\n grid = VGroup()\n for i in range(-2, 3):\n h_line = Line(LEFT * 2 + UP * i, RIGHT * 2 + UP * i, color=BLUE_E)\n v_line = Line(LEFT * i + UP * 2, LEFT * i + DOWN * 2, color=BLUE_E)\n grid.add(h_line, v_line)\n grid.scale(0.5).shift(LEFT * 3) # Scale and position the grid\n \n # Setup the sphere side with a circle (2D representation of a sphere)\n sphere_title = Text(\"On a Sphere\", font_size=24).shift(RIGHT * 3 + UP * 2)\n circle = Circle(radius=1.5, color=BLUE).shift(RIGHT * 3)\n \n # Show both geometric domains\n self.play(Write(plane_title), Create(grid))\n self.play(Write(sphere_title), Create(circle))\n self.wait(1)\n \n # Place a dot (representing an \"ant\") on the plane\n start_point_plane = LEFT * 3\n dot_plane = Dot(color=RED).move_to(start_point_plane)\n \n # Place a dot on the sphere (represented by the circle)\n start_point_sphere = RIGHT * 3 + UP * 1.5 # Top of circle\n dot_sphere = Dot(color=RED).move_to(start_point_sphere)\n \n self.play(FadeIn(dot_plane), FadeIn(dot_sphere))\n \n # Keep track of current positions\n current_plane_point = start_point_plane\n current_sphere_point = start_point_sphere\n \n # Create containers for the path lines\n plane_path = VGroup()\n sphere_path = VGroup()\n \n # Pre-generate points for the sphere walk to ensure they follow the circle\n sphere_points = [start_point_sphere]\n current_angle = PI/2 # Start at top (90 degrees)\n \n for _ in range(5):\n # Generate next angle with small random change\n angle_change = np.random.uniform(-PI/6, PI/6)\n current_angle = (current_angle + angle_change) % (2*PI) # Keep angle in [0, 2π]\n # Calculate point on circle (using parametric equation)\n new_sphere_point = RIGHT * 3 + np.array([\n 1.5 * np.cos(current_angle), \n 1.5 * np.sin(current_angle), \n 0\n ])\n sphere_points.append(new_sphere_point)\n \n # Animate both random walks\n for i in range(5):\n # Plane random step (simplified to 4 directions)\n direction = np.random.choice([UP, DOWN, LEFT, RIGHT])\n new_plane_point = current_plane_point + direction * 0.3\n plane_line = Line(current_plane_point, new_plane_point, color=YELLOW)\n plane_path.add(plane_line)\n \n # Get the pre-generated sphere point\n new_sphere_point = sphere_points[i+1]\n sphere_line = Line(current_sphere_point, new_sphere_point, color=GREEN)\n sphere_path.add(sphere_line)\n \n # Animate both dots moving and lines being created\n self.play(\n dot_plane.animate.move_to(new_plane_point),\n dot_sphere.animate.move_to(new_sphere_point),\n Create(plane_line),\n Create(sphere_line),\n run_time=0.5\n )\n \n # Update current positions\n current_plane_point = new_plane_point\n current_sphere_point = new_sphere_point\n \n # Add explanatory text about the key difference\n plane_msg = Text(\"May never return\", font_size=20).next_to(grid, DOWN)\n sphere_msg = Text(\"Will eventually return\", font_size=20).next_to(circle, DOWN)\n \n self.play(Write(plane_msg), Write(sphere_msg))\n self.wait(1)\n \n # Clear the visual elements to make space for equations\n self.play(\n FadeOut(plane_title), FadeOut(grid), FadeOut(dot_plane), \n FadeOut(plane_path), FadeOut(plane_msg),\n FadeOut(sphere_title), FadeOut(circle), FadeOut(dot_sphere), \n FadeOut(sphere_path), FadeOut(sphere_msg)\n )\n \n # Show the mathematical equations that express the key insight\n plane_eq = Text(\"P(return)_plane = 0 for n → ∞\", font_size=24)\n sphere_eq = Text(\"P(return)_sphere = 1 for n → ∞\", font_size=24)\n \n equations = VGroup(plane_eq, sphere_eq).arrange(DOWN, buff=0.5)\n \n self.play(Write(plane_eq))\n self.wait(0.5)\n self.play(Write(sphere_eq))\n self.wait(1)\n \n # Concluding message about the importance of geometry\n conclusion = Text(\"Geometry changes how random walks behave!\", font_size=28)\n \n self.play(FadeOut(equations))\n self.play(Write(conclusion))\n self.wait(1)\n \n # End scene by fading everything out\n self.play(FadeOut(conclusion), FadeOut(title))\n```", "rejected": "```python\nfrom manim import *\nimport numpy as np\n\nclass RandomWalksComparison(Scene):\n def construct(self):\n # Title of the animation\n title = Text(\"Random Walks: Planes vs. Spheres\", font_size=32)\n self.play(Write(title))\n self.wait(1)\n self.play(title.animate.to_edge(UP))\n \n # Setup the plane side with a grid\n plane_title = Text(\"On a Plane\", font_size=24).shift(LEFT * 3 + UP * 2)\n \n # Create a simple grid to represent the plane\n grid = VGroup()\n for i in range(-2, 3):\n h_line = Line(LEFT * 2 + UP * i, RIGHT * 2 + UP * i, color=BLUE_E)\n v_line = Line(LEFT * i + UP * 2, LEFT * i + DOWN * 2, color=BLUE_E)\n grid.add(h_line, v_line)\n grid.scale(0.5).shift(LEFT * 3) # Scale and position the grid\n \n # Setup the sphere side with a circle (2D representation of a sphere)\n sphere_title = Text(\"On a Sphere\", font_size=24).shift(RIGHT * 3 + UP * 2)\n circle = Circle(radius=1.5, color=BLUE).shift(RIGHT * 3)\n \n # Show both geometric domains\n self.play(Write(plane_title), ShowCreation(grid))\n self.play(Write(sphere_title), Create(circle))\n self.wait(1)\n \n # Place a dot (representing an \"ant\") on the plane\n start_point_plane = LEFT * 3\n dot_plane = Dot(color=RED).move_to(start_point_plane)\n \n # Place a dot on the sphere (represented by the circle)\n start_point_sphere = RIGHT * 3 + UP * 1.5 # Top of circle\n dot_sphere = Dot(color=RED).move_to(start_point_sphere)\n \n self.play(FadeIn(dot_plane), FadeIn(dot_sphere))\n \n # Keep track of current positions\n current_plane_point = start_point_plane\n current_sphere_point = start_point_sphere\n \n # Create containers for the path lines\n plane_path = VGroup()\n sphere_path = VGroup()\n \n # Pre-generate points for the sphere walk to ensure they follow the circle\n sphere_points = [start_point_sphere]\n current_angle = PI/2 # Start at top (90 degrees)\n \n for _ in range(5):\n # Generate next angle with small random change\n angle_change = np.random.uniform(-PI/6, PI/6)\n current_angle = (current_angle + angle_change) % (2*PI) # Keep angle in [0, 2π]\n # Calculate point on circle (using parametric equation)\n new_sphere_point = RIGHT * 3 + np.array([\n 1.5 * np.cos(current_angle), \n 1.5 * np.sin(current_angle), \n 0\n ])\n sphere_points.append(new_sphere_point)\n \n # Animate both random walks\n for i in range(5):\n # Plane random step (simplified to 4 directions)\n direction = np.random.choice([UP, DOWN, LEFT, RIGHT])\n new_plane_point = current_plane_point + direction * 0.3\n plane_line = Line(current_plane_point, new_plane_point, color=YELLOW)\n plane_path.add(plane_line)\n \n # Get the pre-generated sphere point\n new_sphere_point = sphere_points[i+1]\n sphere_line = Line(current_sphere_point, new_sphere_point, color=GREEN)\n sphere_path.add(sphere_line)\n \n # Animate both dots moving and lines being created\n self.play(\n dot_plane.animate.move_to(new_plane_point),\n dot_sphere.animate.move_to(new_sphere_point),\n Create(plane_line),\n Create(sphere_line),\n run_time=0.5\n )\n \n # Update current positions\n current_plane_point = new_plane_point\n current_sphere_point = new_sphere_point\n \n # Add explanatory text about the key difference\n plane_msg = Text(\"May never return\", font_size=20).next_to(grid, DOWN)\n sphere_msg = Text(\"Will eventually return\", font_size=20).next_to(circle, DOWN)\n \n self.play(Write(plane_msg), Write(sphere_msg))\n self.wait(1)\n \n # Clear the visual elements to make space for equations\n self.play(\n FadeOut(plane_title), FadeOut(grid), FadeOut(dot_plane), \n FadeOut(plane_path), FadeOut(plane_msg),\n FadeOut(sphere_title), FadeOut(circle), FadeOut(dot_sphere), \n FadeOut(sphere_path), FadeOut(sphere_msg)\n )\n \n # Show the mathematical equations that express the key insight\n plane_eq = Text(\"P(return)_plane = 0 for n → ∞\", font_size=24)\n sphere_eq = Text(\"P(return)_sphere = 1 for n → ∞\", font_size=24)\n \n equations = VGroup(plane_eq, sphere_eq).arrange(DOWN, buff=0.5)\n \n self.play(Write(plane_eq))\n self.wait(0.5)\n self.play(Write(sphere_eq))\n self.wait(1)\n \n # Concluding message about the importance of geometry\n conclusion = Text(\"Geometry changes how random walks behave!\", font_size=28)\n \n self.play(FadeOut(equations))\n self.play(Write(conclusion))\n self.wait(1)\n \n # End scene by fading everything out\n self.play(FadeOut(conclusion), FadeOut(title))\n```", "category": "legacy_api_hallucination", "source": "synthetic_hard_neg:nabin2004/manim-sft-10k"} +{"system": "You are an expert Manim Community Edition (ManimCE v0.19+) Python developer and mathematical animator. Given a user request, first plan the spatial layout, coordinate bounds, timing, and pedagogical flow inside ... tags (when reasoning is helpful), and then output a complete, runnable, self-contained ManimCE Python script using `from manim import *`. Never use deprecated ManimGL (`manimlib`) methods like `ShowCreation`, `TexMobject`, `TextMobject`, or `axes.get_graph`; always use modern ManimCE APIs (`Create`, `MathTex`, `Tex`, `Text`, `axes.plot`) and prevent visual overlap using `.to_edge()`, `.next_to()`, and `FadeOut`.", "prompt": "Create an educational ManimCE animation on 'Farey Sequences' (Unveiling Farey: Patterns in the Ladder of Fractions): How do the gaps between fractions in consecutive Farey sequences of different orders compare and what pattern arises?\nVisual style guidance: A blend of clear geometric shapes and gentle pastel colors to evoke simplicity and transparency, reminiscent of digital chalk drawings on a blackboard for clarity in complex patterns.", "chosen": "```python\nfrom manim import *\n\nclass FareySequenceScene(Scene):\n def construct(self):\n # Title\n title = Text(\"Unveiling Farey: Patterns in the Ladder of Fractions\", font_size=32)\n self.play(Write(title))\n self.wait(1)\n self.play(title.animate.to_edge(UP))\n \n # Create a number line for displaying fractions\n number_line = NumberLine(\n x_range=[0, 1, 0.2],\n length=8,\n include_numbers=True,\n ).shift(DOWN)\n self.play(Create(number_line))\n \n # Display Farey sequence of order 2\n f2_text = Text(\"Farey Sequence F₂\", font_size=28).next_to(title, DOWN)\n self.play(Write(f2_text))\n \n # Create dots and labels for F_2\n f2_points = [0, 0.5, 1]\n f2_labels = [\"0/1\", \"1/2\", \"1/1\"]\n \n f2_dots = VGroup()\n f2_labels_text = VGroup()\n \n for i, point in enumerate(f2_points):\n dot = Dot(number_line.n2p(point), color=BLUE)\n label = Text(f2_labels[i], font_size=20).next_to(dot, UP, buff=0.3)\n f2_dots.add(dot)\n f2_labels_text.add(label)\n \n self.play(Create(f2_dots), Write(f2_labels_text))\n self.wait(1)\n \n # Transition to Farey sequence of order 3\n f3_text = Text(\"Farey Sequence F₃\", font_size=28).next_to(title, DOWN)\n self.play(ReplacementTransform(f2_text, f3_text))\n \n # Add new fractions in F_3\n f3_new_points = [1/3, 2/3]\n f3_new_labels = [\"1/3\", \"2/3\"]\n \n f3_new_dots = VGroup()\n f3_new_labels_text = VGroup()\n \n for i, point in enumerate(f3_new_points):\n dot = Dot(number_line.n2p(point), color=RED)\n label = Text(f3_new_labels[i], font_size=20).next_to(dot, DOWN, buff=0.3)\n f3_new_dots.add(dot)\n f3_new_labels_text.add(label)\n \n self.play(Create(f3_new_dots), Write(f3_new_labels_text))\n self.wait(1)\n \n # Show arrows indicating reduced gaps\n arrows = VGroup()\n f3_all_points = sorted([0, 1/3, 1/2, 2/3, 1])\n \n for i in range(len(f3_all_points) - 1):\n start = number_line.n2p(f3_all_points[i])\n end = number_line.n2p(f3_all_points[i+1])\n arrow = Arrow(start, end, buff=0.1, color=YELLOW)\n arrows.add(arrow)\n \n gap_text = Text(\"Smaller gaps between fractions\", font_size=24).next_to(f3_text, DOWN)\n self.play(Create(arrows), Write(gap_text))\n self.wait(1)\n \n # Show equation about sequence growth\n eq_text = Text(\"As order n increases:\", font_size=24).next_to(gap_text, DOWN)\n eq = Text(\"Average gap size ≈ 1/n²\", font_size=24).next_to(eq_text, DOWN)\n self.play(Write(eq_text), Write(eq))\n self.wait(2)\n \n # Cleanup and conclusion\n self.play(\n FadeOut(title),\n FadeOut(f3_text),\n FadeOut(gap_text),\n FadeOut(eq_text),\n FadeOut(eq),\n FadeOut(f2_dots),\n FadeOut(f2_labels_text),\n FadeOut(f3_new_dots),\n FadeOut(f3_new_labels_text),\n FadeOut(arrows),\n FadeOut(number_line)\n )\n \n conclusion = Text(\"Farey sequences reveal beautiful patterns\\nin the distribution of fractions\", font_size=28)\n self.play(Write(conclusion))\n self.wait(2)\n self.play(FadeOut(conclusion))\n```", "rejected": "```python\nfrom manim import *\n\nclass FareySequenceScene(Scene):\n def construct(self):\n # Title\n title = Text(\"Unveiling Farey: Patterns in the Ladder of Fractions\", font_size=32)\n self.play(Write(title))\n self.wait(1)\n self.play(title.animate)\n \n # Create a number line for displaying fractions\n number_line = NumberLine(\n x_range=[0, 1, 0.2],\n length=8,\n include_numbers=True,\n )\n self.play(Create(number_line))\n \n # Display Farey sequence of order 2\n f2_text = Text(\"Farey Sequence F₂\", font_size=28)\n self.play(Write(f2_text))\n \n # Create dots and labels for F_2\n f2_points = [0, 0.5, 1]\n f2_labels = [\"0/1\", \"1/2\", \"1/1\"]\n \n f2_dots = VGroup()\n f2_labels_text = VGroup()\n \n for i, point in enumerate(f2_points):\n dot = Dot(number_line.n2p(point), color=BLUE)\n label = Text(f2_labels[i], font_size=20).next_to(dot, UP, buff=0.3)\n f2_dots.add(dot)\n f2_labels_text.add(label)\n \n self.play(Create(f2_dots), Write(f2_labels_text))\n self.wait(1)\n \n # Transition to Farey sequence of order 3\n f3_text = Text(\"Farey Sequence F₃\", font_size=28).next_to(title, DOWN)\n self.play(ReplacementTransform(f2_text, f3_text))\n \n # Add new fractions in F_3\n f3_new_points = [1/3, 2/3]\n f3_new_labels = [\"1/3\", \"2/3\"]\n \n f3_new_dots = VGroup()\n f3_new_labels_text = VGroup()\n \n for i, point in enumerate(f3_new_points):\n dot = Dot(number_line.n2p(point), color=RED)\n label = Text(f3_new_labels[i], font_size=20).next_to(dot, DOWN, buff=0.3)\n f3_new_dots.add(dot)\n f3_new_labels_text.add(label)\n \n self.play(Create(f3_new_dots), Write(f3_new_labels_text))\n self.wait(1)\n \n # Show arrows indicating reduced gaps\n arrows = VGroup()\n f3_all_points = sorted([0, 1/3, 1/2, 2/3, 1])\n \n for i in range(len(f3_all_points) - 1):\n start = number_line.n2p(f3_all_points[i])\n end = number_line.n2p(f3_all_points[i+1])\n arrow = Arrow(start, end, buff=0.1, color=YELLOW)\n arrows.add(arrow)\n \n gap_text = Text(\"Smaller gaps between fractions\", font_size=24).next_to(f3_text, DOWN)\n self.play(Create(arrows), Write(gap_text))\n self.wait(1)\n \n # Show equation about sequence growth\n eq_text = Text(\"As order n increases:\", font_size=24).next_to(gap_text, DOWN)\n eq = Text(\"Average gap size ≈ 1/n²\", font_size=24).next_to(eq_text, DOWN)\n self.play(Write(eq_text), Write(eq))\n self.wait(2)\n \n # Cleanup and conclusion\n self.play(\n FadeOut(title),\n FadeOut(f3_text),\n FadeOut(gap_text),\n FadeOut(eq_text),\n FadeOut(eq),\n FadeOut(f2_dots),\n FadeOut(f2_labels_text),\n FadeOut(f3_new_dots),\n FadeOut(f3_new_labels_text),\n FadeOut(arrows),\n FadeOut(number_line)\n )\n \n conclusion = Text(\"Farey sequences reveal beautiful patterns\\nin the distribution of fractions\", font_size=28)\n self.play(Write(conclusion))\n self.wait(2)\n self.play(FadeOut(conclusion))\n```", "category": "spatial_layout_overlap", "source": "synthetic_hard_neg:bespokelabs/bespoke-manim"} +{"system": "You are an expert Manim Community Edition (ManimCE v0.19+) Python developer and mathematical animator. Given a user request, first plan the spatial layout, coordinate bounds, timing, and pedagogical flow inside ... tags (when reasoning is helpful), and then output a complete, runnable, self-contained ManimCE Python script using `from manim import *`. Never use deprecated ManimGL (`manimlib`) methods like `ShowCreation`, `TexMobject`, `TextMobject`, or `axes.get_graph`; always use modern ManimCE APIs (`Create`, `MathTex`, `Tex`, `Text`, `axes.plot`) and prevent visual overlap using `.to_edge()`, `.next_to()`, and `FadeOut`.", "prompt": "I'm learning word embeddings and want to visualize a lookup as a table where selecting an index highlights the entire row vector. Show a grid of embedding vectors as rows; when a specific index is chosen, highlight that row with a bright color and display the vector in a side panel. Animate a search through the vocabulary, with a typing-like reveal and a demonstration of cosine similarity lighting up the nearest neighbors. Provide a short note on how embeddings cluster in projection space.", "chosen": "```python\nfrom manim import *\nfrom manim_voiceover import VoiceoverScene\nfrom manim_voiceover.services.gtts import GTTSService\n\n\nclass WordEmbeddingsScene(VoiceoverScene):\n def construct(self):\n self.set_speech_service(\n GTTSService(voice=\"alba\", cache_dir=\"voiceover_cache\")\n )\n \n # ==== SECTION 1: Introduction ====\n with self.voiceover(text=\"Imagine being able to visualize the relationship between words, each represented as points in a multidimensional space.\") as tracker:\n title = Text(\"Word Embeddings Visualization\", font_size=48, color=BLUE)\n subtitle = Text(\"Seeing Language in Vector Space\", font_size=28, color=GRAY)\n subtitle.next_to(title, DOWN, buff=0.3)\n title_group = VGroup(title, subtitle)\n self.play(Write(title), run_time=tracker.duration * 0.6)\n self.play(FadeIn(subtitle), run_time=tracker.duration * 0.4)\n \n self.wait(0.5)\n \n with self.voiceover(text=\"What if you could see how similar words cluster together, revealing the nuances and connections in language?\") as tracker:\n # Fade out title and show the concept\n self.play(title_group.animate.scale(0.6).to_edge(UP), run_time=tracker.duration)\n \n # ==== SECTION 2: From Words to Vectors ====\n with self.voiceover(text=\"In natural language processing, we convert words into numerical vectors called embeddings.\") as tracker:\n # Show word becoming a vector\n word_text = Text(\"\\'king\\'\", font_size=36, color=YELLOW)\n arrow = Arrow(LEFT, RIGHT, color=WHITE)\n vector_repr = MathTex(r\"[0.2, -0.5, 0.8, ...]\", font_size=32, color=GREEN)\n \n word_group = VGroup(word_text, arrow, vector_repr).arrange(RIGHT, buff=0.5)\n word_group.next_to(title_group, DOWN, buff=0.8)\n \n self.play(Write(word_text), run_time=tracker.duration * 0.3)\n self.play(Create(arrow), run_time=tracker.duration * 0.2)\n self.play(Write(vector_repr), run_time=tracker.duration * 0.5)\n \n self.wait(0.3)\n \n with self.voiceover(text=\"Each word becomes a point in high-dimensional space, typically 100 to 300 dimensions.\") as tracker:\n # Show dimensions\n dims_text = Text(\"300 dimensions\", font_size=24, color=GRAY)\n dims_text.next_to(vector_repr, DOWN, buff=0.2)\n self.play(FadeIn(dims_text), run_time=tracker.duration)\n \n self.wait(0.3)\n \n # ==== SECTION 3: 2D Visualization ====\n with self.voiceover(text=\"To visualize this, we project these high-dimensional vectors down to two dimensions.\") as tracker:\n # Clear previous and show 2D plane\n self.play(\n FadeOut(word_text), FadeOut(arrow), FadeOut(vector_repr), FadeOut(dims_text),\n run_time=tracker.duration * 0.4\n )\n \n # Create axes\n axes = Axes(\n x_range=[-5, 5, 1],\n y_range=[-4, 4, 1],\n axis_config={\"include_tip\": True, \"numbers_to_exclude\": []},\n x_length=8,\n y_length=6\n )\n axes.next_to(title_group, DOWN, buff=0.5)\n \n x_label = MathTex(\"x\", font_size=24).next_to(axes.x_axis, RIGHT)\n y_label = MathTex(\"y\", font_size=24).next_to(axes.y_axis, UP)\n \n self.play(Create(axes), Write(x_label), Write(y_label), run_time=tracker.duration * 0.6)\n \n self.wait(0.3)\n \n # ==== SECTION 4: Word Clusters Animation ====\n with self.voiceover(text=\"Watch as words appear on our 2D embedding space. Notice how similar words cluster together.\") as tracker:\n # Define word positions (clustered by category)\n # Royal cluster\n royal_words = [\n (\"king\", 2.5, 2, BLUE),\n (\"queen\", 3, 1.5, BLUE),\n (\"prince\", 2, 1.8, BLUE),\n (\"princess\", 2.8, 1.2, BLUE),\n ]\n \n # Animal cluster\n animal_words = [\n (\"cat\", -2, 2.5, ORANGE),\n (\"dog\", -1.5, 2.8, ORANGE),\n (\"lion\", -2.5, 2, ORANGE),\n (\"tiger\", -1.8, 1.5, ORANGE),\n ]\n \n # Food cluster\n food_words = [\n (\"pizza\", -1, -2, GREEN),\n (\"pasta\", -0.5, -2.5, GREEN),\n (\"burger\", -1.5, -1.8, GREEN),\n (\"sushi\", -0.8, -3, GREEN),\n ]\n \n all_words = royal_words + animal_words + food_words\n \n dots = VGroup()\n labels = VGroup()\n \n for word, x, y, color in all_words:\n dot = Dot(axes.c2p(x, y), color=color, radius=0.08)\n label = Text(word, font_size=18, color=color)\n label.next_to(dot, UP, buff=0.1)\n dots.add(dot)\n labels.add(label)\n \n # Animate dots appearing\n self.play(\n LaggedStart(*[FadeIn(dot) for dot in dots], lag_ratio=0.1),\n run_time=tracker.duration * 0.6\n )\n self.play(\n LaggedStart(*[Write(label) for label in labels], lag_ratio=0.1),\n run_time=tracker.duration * 0.4\n )\n \n self.wait(0.5)\n \n # ==== SECTION 5: Highlight Clusters ====\n with self.voiceover(text=\"See the royal words in blue cluster together, while animals in orange and food in green form their own groups.\") as tracker:\n # Create cluster circles\n royal_center = axes.c2p(2.6, 1.6)\n animal_center = axes.c2p(-2, 2.2)\n food_center = axes.c2p(-1, -2.3)\n \n royal_circle = Circle(radius=1.2, color=BLUE, stroke_width=2, fill_opacity=0.1, fill_color=BLUE)\n royal_circle.move_to(royal_center)\n \n animal_circle = Circle(radius=1.3, color=ORANGE, stroke_width=2, fill_opacity=0.1, fill_color=ORANGE)\n animal_circle.move_to(animal_center)\n \n food_circle = Circle(radius=1.2, color=GREEN, stroke_width=2, fill_opacity=0.1, fill_color=GREEN)\n food_circle.move_to(food_center)\n \n self.play(\n Create(royal_circle),\n Create(animal_circle),\n Create(food_circle),\n run_time=tracker.duration\n )\n \n self.wait(0.5)\n \n # ==== SECTION 6: Cosine Similarity Formula ====\n with self.voiceover(text=\"We measure word similarity using cosine similarity. Words with similar meanings have vectors pointing in similar directions.\") as tracker:\n # Move everything up and show formula\n self.play(\n FadeOut(royal_circle), FadeOut(animal_circle), FadeOut(food_circle),\n FadeOut(dots), FadeOut(labels),\n run_time=tracker.duration * 0.3\n )\n \n # Show cosine similarity formula\n formula_title = Text(\"Cosine Similarity\", font_size=32, color=YELLOW)\n formula_title.next_to(axes, DOWN, buff=0.5)\n \n cosine_formula = MathTex(\n r\"cos(\\theta) = \\frac{A \\cdot B}{||A|| \\cdot ||B||}\",\n font_size=36\n )\n cosine_formula.next_to(formula_title, DOWN, buff=0.3)\n \n self.play(Write(formula_title), run_time=tracker.duration * 0.3)\n self.play(Write(cosine_formula), run_time=tracker.duration * 0.4)\n \n self.wait(0.5)\n \n # ==== SECTION 7: Vector Angle Visualization ====\n with self.voiceover(text=\"When the angle between vectors is small, cosine similarity approaches one, meaning the words are very similar.\") as tracker:\n # Clear formula and show vectors from origin\n self.play(\n FadeOut(formula_title), FadeOut(cosine_formula),\n run_time=tracker.duration * 0.2\n )\n \n # Draw two vectors showing small angle\n origin = axes.c2p(0, 0)\n vec1_end = axes.c2p(3, 2)\n vec2_end = axes.c2p(2.5, 2.5)\n \n vec1 = Arrow(origin, vec1_end, color=BLUE, buff=0)\n vec2 = Arrow(origin, vec2_end, color=BLUE, buff=0)\n \n vec1_label = Text(\"\\'king\\'\", font_size=20, color=BLUE).next_to(vec1_end, RIGHT)\n vec2_label = Text(\"\\'queen\\'\", font_size=20, color=BLUE).next_to(vec2_end, UP)\n \n # Angle arc\n angle = Angle(vec1, vec2, radius=0.8, color=YELLOW)\n angle_label = MathTex(r\"\\theta\", font_size=24, color=YELLOW)\n angle_label.next_to(angle, RIGHT, buff=0.1)\n \n sim_text = MathTex(r\"cos(\\theta) \\approx 0.95\", font_size=28, color=GREEN)\n sim_text.to_edge(DOWN, buff=0.5)\n \n self.play(Create(vec1), Write(vec1_label), run_time=tracker.duration * 0.25)\n self.play(Create(vec2), Write(vec2_label), run_time=tracker.duration * 0.25)\n self.play(Create(angle), Write(angle_label), run_time=tracker.duration * 0.25)\n self.play(Write(sim_text), run_time=tracker.duration * 0.25)\n \n self.wait(0.5)\n \n # ==== SECTION 8: Dissimilar Words ====\n with self.voiceover(text=\"Conversely, dissimilar words have vectors pointing in very different directions, giving a low or even negative cosine similarity.\") as tracker:\n # Show vectors with large angle\n vec3_end = axes.c2p(-2, -3)\n vec3 = Arrow(origin, vec3_end, color=RED, buff=0)\n vec3_label = Text(\"\\'pizza\\'\", font_size=20, color=RED).next_to(vec3_end, DOWN)\n \n angle2 = Angle(vec1, vec3, radius=1, color=YELLOW, other_angle=True)\n angle2_label = MathTex(r\"\\theta\", font_size=24, color=YELLOW)\n angle2_label.move_to(axes.c2p(-0.5, -0.8))\n \n sim_text2 = MathTex(r\"cos(\\theta) \\approx -0.3\", font_size=28, color=RED)\n sim_text2.next_to(sim_text, DOWN, buff=0.2)\n \n self.play(\n FadeOut(vec2), FadeOut(vec2_label), FadeOut(angle), FadeOut(angle_label),\n run_time=tracker.duration * 0.3\n )\n self.play(Create(vec3), Write(vec3_label), run_time=tracker.duration * 0.35)\n self.play(Create(angle2), Write(angle2_label), run_time=tracker.duration * 0.35)\n self.play(Write(sim_text2), run_time=tracker.duration * 0.3)\n \n self.wait(0.5)\n \n # ==== SECTION 9: Key Takeaways ====\n with self.voiceover(text=\"Let\\'s summarize what we\\'ve learned about word embeddings visualization.\") as tracker:\n # Clear everything\n self.play(\n FadeOut(axes), FadeOut(x_label), FadeOut(y_label),\n FadeOut(vec1), FadeOut(vec1_label), FadeOut(vec3), FadeOut(vec3_label),\n FadeOut(angle2), FadeOut(angle2_label), FadeOut(sim_text), FadeOut(sim_text2),\n FadeOut(title_group),\n run_time=tracker.duration * 0.5\n )\n \n # Create takeaways\n takeaway_title = Text(\"Key Takeaways\", font_size=40, color=BLUE)\n takeaway_title.to_edge(UP, buff=0.5)\n \n takeaways = VGroup(\n Text(\"Words are represented as vectors in high-dimensional space\", font_size=24),\n Text(\"Similar words cluster together in the embedding space\", font_size=24),\n Text(\"Cosine similarity measures word relationships\", font_size=24),\n Text(\"Visualization helps us understand language structure\", font_size=24),\n ).arrange(DOWN, aligned_edge=LEFT, buff=0.4)\n takeaways.next_to(takeaway_title, DOWN, buff=0.6)\n \n self.play(Write(takeaway_title), run_time=tracker.duration * 0.3)\n self.play(LaggedStart(*[Write(t) for t in takeaways], lag_ratio=0.2), run_time=tracker.duration * 0.5)\n \n self.wait(0.5)\n \n # ==== SECTION 10: Python Implementation Hint ====\n with self.voiceover(text=\"In Python, you can create these visualizations using libraries like scikit-learn for dimensionality reduction and matplotlib for plotting.\") as tracker:\n code_text = \"\"\"from sklearn.decomposition import PCA\nimport matplotlib.pyplot as plt\n\n# Reduce 300D embeddings to 2D\npca = PCA(n_components=2)\nwords_2d = pca.fit_transform(embeddings)\n\n# Plot the words\nplt.scatter(words_2d[:, 0], words_2d[:, 1])\nfor i, word in enumerate(words):\n plt.annotate(word, (words_2d[i, 0], words_2d[i, 1]))\nplt.show()\"\"\"\n \n code_block = Code(\n code_string=code_text,\n language=\"python\",\n background=\"window\",\n add_line_numbers=False\n )\n code_block.scale(0.7)\n code_block.next_to(takeaways, DOWN, buff=0.4)\n \n self.play(FadeIn(code_block), run_time=tracker.duration)\n \n self.wait(1)\n \n # ==== SECTION 11: Closing ====\n with self.voiceover(text=\"Now you understand how word embeddings visualize language. You can see how words relate to each other in vector space!\") as tracker:\n # Fade everything out and show final message\n self.play(\n FadeOut(takeaway_title), FadeOut(takeaways), FadeOut(code_block),\n run_time=tracker.duration * 0.5\n )\n \n final_text = Text(\"Explore the Hidden Structure of Language!\", font_size=36, color=BLUE)\n final_text2 = Text(\"with Word Embeddings\", font_size=28, color=GRAY)\n final_group = VGroup(final_text, final_text2).arrange(DOWN, buff=0.3)\n final_group.move_to(ORIGIN)\n \n self.play(Write(final_text), run_time=tracker.duration * 0.3)\n self.play(FadeIn(final_text2), run_time=tracker.duration * 0.2)\n \n self.wait(2)\n```", "rejected": "```python\nfrom manim import *\nfrom manim_voiceover import VoiceoverScene\nfrom manim_voiceover.services.gtts import GTTSService\n\n\nclass WordEmbeddingsScene(VoiceoverScene):\n def construct(self):\n self.set_speech_service(\n GTTSService(voice=\"alba\", cache_dir=\"voiceover_cache\")\n )\n \n # ==== SECTION 1: Introduction ====\n with self.voiceover(text=\"Imagine being able to visualize the relationship between words, each represented as points in a multidimensional space.\") as tracker:\n title = Text(\"Word Embeddings Visualization\", font_size=48, color=BLUE)\n subtitle = Text(\"Seeing Language in Vector Space\", font_size=28, color=GRAY)\n subtitle\n title_group = VGroup(title, subtitle)\n self.play(Write(title), run_time=tracker.duration * 0.6)\n self.play(FadeIn(subtitle), run_time=tracker.duration * 0.4)\n \n self.wait(0.5)\n \n with self.voiceover(text=\"What if you could see how similar words cluster together, revealing the nuances and connections in language?\") as tracker:\n # Fade out title and show the concept\n self.play(title_group.animate.scale(0.6), run_time=tracker.duration)\n \n # ==== SECTION 2: From Words to Vectors ====\n with self.voiceover(text=\"In natural language processing, we convert words into numerical vectors called embeddings.\") as tracker:\n # Show word becoming a vector\n word_text = Text(\"\\'king\\'\", font_size=36, color=YELLOW)\n arrow = Arrow(LEFT, RIGHT, color=WHITE)\n vector_repr = MathTex(r\"[0.2, -0.5, 0.8, ...]\", font_size=32, color=GREEN)\n \n word_group = VGroup(word_text, arrow, vector_repr).arrange(RIGHT, buff=0.5)\n word_group\n \n self.play(Write(word_text), run_time=tracker.duration * 0.3)\n self.play(Create(arrow), run_time=tracker.duration * 0.2)\n self.play(Write(vector_repr), run_time=tracker.duration * 0.5)\n \n self.wait(0.3)\n \n with self.voiceover(text=\"Each word becomes a point in high-dimensional space, typically 100 to 300 dimensions.\") as tracker:\n # Show dimensions\n dims_text = Text(\"300 dimensions\", font_size=24, color=GRAY)\n dims_text.next_to(vector_repr, DOWN, buff=0.2)\n self.play(FadeIn(dims_text), run_time=tracker.duration)\n \n self.wait(0.3)\n \n # ==== SECTION 3: 2D Visualization ====\n with self.voiceover(text=\"To visualize this, we project these high-dimensional vectors down to two dimensions.\") as tracker:\n # Clear previous and show 2D plane\n self.play(\n FadeOut(word_text), FadeOut(arrow), FadeOut(vector_repr), FadeOut(dims_text),\n run_time=tracker.duration * 0.4\n )\n \n # Create axes\n axes = Axes(\n x_range=[-5, 5, 1],\n y_range=[-4, 4, 1],\n axis_config={\"include_tip\": True, \"numbers_to_exclude\": []},\n x_length=8,\n y_length=6\n )\n axes.next_to(title_group, DOWN, buff=0.5)\n \n x_label = MathTex(\"x\", font_size=24).next_to(axes.x_axis, RIGHT)\n y_label = MathTex(\"y\", font_size=24).next_to(axes.y_axis, UP)\n \n self.play(Create(axes), Write(x_label), Write(y_label), run_time=tracker.duration * 0.6)\n \n self.wait(0.3)\n \n # ==== SECTION 4: Word Clusters Animation ====\n with self.voiceover(text=\"Watch as words appear on our 2D embedding space. Notice how similar words cluster together.\") as tracker:\n # Define word positions (clustered by category)\n # Royal cluster\n royal_words = [\n (\"king\", 2.5, 2, BLUE),\n (\"queen\", 3, 1.5, BLUE),\n (\"prince\", 2, 1.8, BLUE),\n (\"princess\", 2.8, 1.2, BLUE),\n ]\n \n # Animal cluster\n animal_words = [\n (\"cat\", -2, 2.5, ORANGE),\n (\"dog\", -1.5, 2.8, ORANGE),\n (\"lion\", -2.5, 2, ORANGE),\n (\"tiger\", -1.8, 1.5, ORANGE),\n ]\n \n # Food cluster\n food_words = [\n (\"pizza\", -1, -2, GREEN),\n (\"pasta\", -0.5, -2.5, GREEN),\n (\"burger\", -1.5, -1.8, GREEN),\n (\"sushi\", -0.8, -3, GREEN),\n ]\n \n all_words = royal_words + animal_words + food_words\n \n dots = VGroup()\n labels = VGroup()\n \n for word, x, y, color in all_words:\n dot = Dot(axes.c2p(x, y), color=color, radius=0.08)\n label = Text(word, font_size=18, color=color)\n label.next_to(dot, UP, buff=0.1)\n dots.add(dot)\n labels.add(label)\n \n # Animate dots appearing\n self.play(\n LaggedStart(*[FadeIn(dot) for dot in dots], lag_ratio=0.1),\n run_time=tracker.duration * 0.6\n )\n self.play(\n LaggedStart(*[Write(label) for label in labels], lag_ratio=0.1),\n run_time=tracker.duration * 0.4\n )\n \n self.wait(0.5)\n \n # ==== SECTION 5: Highlight Clusters ====\n with self.voiceover(text=\"See the royal words in blue cluster together, while animals in orange and food in green form their own groups.\") as tracker:\n # Create cluster circles\n royal_center = axes.c2p(2.6, 1.6)\n animal_center = axes.c2p(-2, 2.2)\n food_center = axes.c2p(-1, -2.3)\n \n royal_circle = Circle(radius=1.2, color=BLUE, stroke_width=2, fill_opacity=0.1, fill_color=BLUE)\n royal_circle.move_to(royal_center)\n \n animal_circle = Circle(radius=1.3, color=ORANGE, stroke_width=2, fill_opacity=0.1, fill_color=ORANGE)\n animal_circle.move_to(animal_center)\n \n food_circle = Circle(radius=1.2, color=GREEN, stroke_width=2, fill_opacity=0.1, fill_color=GREEN)\n food_circle.move_to(food_center)\n \n self.play(\n Create(royal_circle),\n Create(animal_circle),\n Create(food_circle),\n run_time=tracker.duration\n )\n \n self.wait(0.5)\n \n # ==== SECTION 6: Cosine Similarity Formula ====\n with self.voiceover(text=\"We measure word similarity using cosine similarity. Words with similar meanings have vectors pointing in similar directions.\") as tracker:\n # Move everything up and show formula\n self.play(\n FadeOut(royal_circle), FadeOut(animal_circle), FadeOut(food_circle),\n FadeOut(dots), FadeOut(labels),\n run_time=tracker.duration * 0.3\n )\n \n # Show cosine similarity formula\n formula_title = Text(\"Cosine Similarity\", font_size=32, color=YELLOW)\n formula_title.next_to(axes, DOWN, buff=0.5)\n \n cosine_formula = MathTex(\n r\"cos(\\theta) = \\frac{A \\cdot B}{||A|| \\cdot ||B||}\",\n font_size=36\n )\n cosine_formula.next_to(formula_title, DOWN, buff=0.3)\n \n self.play(Write(formula_title), run_time=tracker.duration * 0.3)\n self.play(Write(cosine_formula), run_time=tracker.duration * 0.4)\n \n self.wait(0.5)\n \n # ==== SECTION 7: Vector Angle Visualization ====\n with self.voiceover(text=\"When the angle between vectors is small, cosine similarity approaches one, meaning the words are very similar.\") as tracker:\n # Clear formula and show vectors from origin\n self.play(\n FadeOut(formula_title), FadeOut(cosine_formula),\n run_time=tracker.duration * 0.2\n )\n \n # Draw two vectors showing small angle\n origin = axes.c2p(0, 0)\n vec1_end = axes.c2p(3, 2)\n vec2_end = axes.c2p(2.5, 2.5)\n \n vec1 = Arrow(origin, vec1_end, color=BLUE, buff=0)\n vec2 = Arrow(origin, vec2_end, color=BLUE, buff=0)\n \n vec1_label = Text(\"\\'king\\'\", font_size=20, color=BLUE).next_to(vec1_end, RIGHT)\n vec2_label = Text(\"\\'queen\\'\", font_size=20, color=BLUE).next_to(vec2_end, UP)\n \n # Angle arc\n angle = Angle(vec1, vec2, radius=0.8, color=YELLOW)\n angle_label = MathTex(r\"\\theta\", font_size=24, color=YELLOW)\n angle_label.next_to(angle, RIGHT, buff=0.1)\n \n sim_text = MathTex(r\"cos(\\theta) \\approx 0.95\", font_size=28, color=GREEN)\n sim_text.to_edge(DOWN, buff=0.5)\n \n self.play(Create(vec1), Write(vec1_label), run_time=tracker.duration * 0.25)\n self.play(Create(vec2), Write(vec2_label), run_time=tracker.duration * 0.25)\n self.play(Create(angle), Write(angle_label), run_time=tracker.duration * 0.25)\n self.play(Write(sim_text), run_time=tracker.duration * 0.25)\n \n self.wait(0.5)\n \n # ==== SECTION 8: Dissimilar Words ====\n with self.voiceover(text=\"Conversely, dissimilar words have vectors pointing in very different directions, giving a low or even negative cosine similarity.\") as tracker:\n # Show vectors with large angle\n vec3_end = axes.c2p(-2, -3)\n vec3 = Arrow(origin, vec3_end, color=RED, buff=0)\n vec3_label = Text(\"\\'pizza\\'\", font_size=20, color=RED).next_to(vec3_end, DOWN)\n \n angle2 = Angle(vec1, vec3, radius=1, color=YELLOW, other_angle=True)\n angle2_label = MathTex(r\"\\theta\", font_size=24, color=YELLOW)\n angle2_label.move_to(axes.c2p(-0.5, -0.8))\n \n sim_text2 = MathTex(r\"cos(\\theta) \\approx -0.3\", font_size=28, color=RED)\n sim_text2.next_to(sim_text, DOWN, buff=0.2)\n \n self.play(\n FadeOut(vec2), FadeOut(vec2_label), FadeOut(angle), FadeOut(angle_label),\n run_time=tracker.duration * 0.3\n )\n self.play(Create(vec3), Write(vec3_label), run_time=tracker.duration * 0.35)\n self.play(Create(angle2), Write(angle2_label), run_time=tracker.duration * 0.35)\n self.play(Write(sim_text2), run_time=tracker.duration * 0.3)\n \n self.wait(0.5)\n \n # ==== SECTION 9: Key Takeaways ====\n with self.voiceover(text=\"Let\\'s summarize what we\\'ve learned about word embeddings visualization.\") as tracker:\n # Clear everything\n self.play(\n FadeOut(axes), FadeOut(x_label), FadeOut(y_label),\n FadeOut(vec1), FadeOut(vec1_label), FadeOut(vec3), FadeOut(vec3_label),\n FadeOut(angle2), FadeOut(angle2_label), FadeOut(sim_text), FadeOut(sim_text2),\n FadeOut(title_group),\n run_time=tracker.duration * 0.5\n )\n \n # Create takeaways\n takeaway_title = Text(\"Key Takeaways\", font_size=40, color=BLUE)\n takeaway_title.to_edge(UP, buff=0.5)\n \n takeaways = VGroup(\n Text(\"Words are represented as vectors in high-dimensional space\", font_size=24),\n Text(\"Similar words cluster together in the embedding space\", font_size=24),\n Text(\"Cosine similarity measures word relationships\", font_size=24),\n Text(\"Visualization helps us understand language structure\", font_size=24),\n ).arrange(DOWN, aligned_edge=LEFT, buff=0.4)\n takeaways.next_to(takeaway_title, DOWN, buff=0.6)\n \n self.play(Write(takeaway_title), run_time=tracker.duration * 0.3)\n self.play(LaggedStart(*[Write(t) for t in takeaways], lag_ratio=0.2), run_time=tracker.duration * 0.5)\n \n self.wait(0.5)\n \n # ==== SECTION 10: Python Implementation Hint ====\n with self.voiceover(text=\"In Python, you can create these visualizations using libraries like scikit-learn for dimensionality reduction and matplotlib for plotting.\") as tracker:\n code_text = \"\"\"from sklearn.decomposition import PCA\nimport matplotlib.pyplot as plt\n\n# Reduce 300D embeddings to 2D\npca = PCA(n_components=2)\nwords_2d = pca.fit_transform(embeddings)\n\n# Plot the words\nplt.scatter(words_2d[:, 0], words_2d[:, 1])\nfor i, word in enumerate(words):\n plt.annotate(word, (words_2d[i, 0], words_2d[i, 1]))\nplt.show()\"\"\"\n \n code_block = Code(\n code_string=code_text,\n language=\"python\",\n background=\"window\",\n add_line_numbers=False\n )\n code_block.scale(0.7)\n code_block.next_to(takeaways, DOWN, buff=0.4)\n \n self.play(FadeIn(code_block), run_time=tracker.duration)\n \n self.wait(1)\n \n # ==== SECTION 11: Closing ====\n with self.voiceover(text=\"Now you understand how word embeddings visualize language. You can see how words relate to each other in vector space!\") as tracker:\n # Fade everything out and show final message\n self.play(\n FadeOut(takeaway_title), FadeOut(takeaways), FadeOut(code_block),\n run_time=tracker.duration * 0.5\n )\n \n final_text = Text(\"Explore the Hidden Structure of Language!\", font_size=36, color=BLUE)\n final_text2 = Text(\"with Word Embeddings\", font_size=28, color=GRAY)\n final_group = VGroup(final_text, final_text2).arrange(DOWN, buff=0.3)\n final_group.move_to(ORIGIN)\n \n self.play(Write(final_text), run_time=tracker.duration * 0.3)\n self.play(FadeIn(final_text2), run_time=tracker.duration * 0.2)\n \n self.wait(2)\n```", "category": "spatial_layout_overlap", "source": "synthetic_hard_neg:nabin2004/AOS-Narrated-Manim-400"} +{"system": "You are an expert Manim Community Edition (ManimCE v0.19+) Python developer and mathematical animator. Given a user request, first plan the spatial layout, coordinate bounds, timing, and pedagogical flow inside ... tags (when reasoning is helpful), and then output a complete, runnable, self-contained ManimCE Python script using `from manim import *`. Never use deprecated ManimGL (`manimlib`) methods like `ShowCreation`, `TexMobject`, `TextMobject`, or `axes.get_graph`; always use modern ManimCE APIs (`Create`, `MathTex`, `Tex`, `Text`, `axes.plot`) and prevent visual overlap using `.to_edge()`, `.next_to()`, and `FadeOut`.", "prompt": "I'm teaching an undergrad ML course and want a visualization of batch size effects on loss.\nPlot two loss curves in the same scene: a noisy, jagged line for small batches and a smooth curve for large batches, over the same number of iterations.\nAdd panels showing gradient variance and an intuition caption about why noise helps or hurts optimization depending on regime.\nInclude a comparison sweep where batch size increases stepwise and the system highlights when convergence improves.", "chosen": "```python\nfrom manim import *\nfrom manim_voiceover import VoiceoverScene\nfrom manim_voiceover.services.gtts import GTTSService\nimport numpy as np\n\nclass BatchSizeEffects(VoiceoverScene):\n def construct(self):\n # [SETUP]\n # [LAYOUT]\n self.set_speech_service(GTTSService(transcription_model=\"base\"))\n \n # [BEAT 1 | sync: DATASET]\n with self.voiceover(text=\"The batch size determines how many samples are processed before updating weights. A small batch processes few samples, while a large batch processes many.\") as tracker:\n title = Text(\"Batch Size Effects on Loss\", font_size=36, color=BLUE)\n self.fit_in_frame(title)\n title.to_edge(UP)\n \n dataset = VGroup(*[Dot(color=BLUE, radius=0.1) for _ in range(20)]).arrange_in_grid(4, 5, buff=0.3)\n small_batch = SurroundingRectangle(dataset[:4], color=GREEN, buff=0.1)\n large_batch = SurroundingRectangle(dataset[:16], color=RED, buff=0.1)\n \n self.wait_until_bookmark(\"DATASET\")\n self.play(Write(title), Create(dataset), Create(small_batch), Create(large_batch), run_time=tracker.duration)\n \n with self.voiceover(text=\"This choice dramatically affects the loss curve. Small batches yield noisy, jagged updates, while large batches produce smooth, stable descent.\") as tracker:\n axes = Axes(x_range=[0, 10], y_range=[0, 5], x_length=8, y_length=4)\n axes.shift(DOWN * 0.5)\n \n small_curve = axes.plot(lambda x: 4 * np.exp(-0.3 * x) + 0.5 + 0.3 * np.sin(5 * x) * np.exp(-0.2 * x), color=GREEN, stroke_width=3)\n large_curve = axes.plot(lambda x: 4.2 * np.exp(-0.2 * x) + 0.8, color=RED, stroke_width=3)\n \n self.wait_until_bookmark(\"CURVES\")\n self.play(FadeOut(dataset), FadeOut(small_batch), FadeOut(large_batch))\n self.play(Create(axes), Create(small_curve), Create(large_curve), run_time=tracker.duration)\n \n with self.voiceover(text=\"While noise can help escape shallow local minima, too much variance slows down convergence. Finding the right batch size balances update speed with gradient stability.\") as tracker:\n tradeoff_text = VGroup(\n Text(\"Small Batch: Noisy, better generalization\", font_size=20, color=GREEN),\n Text(\"Large Batch: Smooth, faster per-step\", font_size=20, color=RED)\n ).arrange(DOWN, aligned_edge=LEFT).to_edge(DOWN)\n \n self.wait_until_bookmark(\"TRADEOFF\")\n self.play(Write(tradeoff_text), run_time=tracker.duration)\n self.wait(1)\n\n def fit_in_frame(self, mob: Mobject, w_frac: float = 0.9, h_frac: float = 0.9) -> Mobject:\n max_w = config.frame_width * w_frac\n max_h = config.frame_height * h_frac\n if mob.width > max_w:\n mob.width = max_w\n if mob.height > max_h:\n mob.height = max_h\n return mob\n```", "rejected": "```python\nfrom manim import *\nfrom manim_voiceover import VoiceoverScene\nfrom manim_voiceover.services.gtts import GTTSService\nimport numpy as np\n\nclass BatchSizeEffects(VoiceoverScene):\n def construct(self):\n # [SETUP]\n # [LAYOUT]\n self.set_speech_service(GTTSService(transcription_model=\"base\"))\n \n # [BEAT 1 | sync: DATASET]\n with self.voiceover(text=\"The batch size determines how many samples are processed before updating weights. A small batch processes few samples, while a large batch processes many.\") as tracker:\n title = Text(\"Batch Size Effects on Loss\", font_size=36, color=BLUE)\n self.fit_in_frame(title)\n title\n \n dataset = VGroup(*[Dot(color=BLUE, radius=0.1) for _ in range(20)]).arrange_in_grid(4, 5, buff=0.3)\n small_batch = SurroundingRectangle(dataset[:4], color=GREEN, buff=0.1)\n large_batch = SurroundingRectangle(dataset[:16], color=RED, buff=0.1)\n \n self.wait_until_bookmark(\"DATASET\")\n self.play(Write(title), Create(dataset), Create(small_batch), Create(large_batch), run_time=tracker.duration)\n \n with self.voiceover(text=\"This choice dramatically affects the loss curve. Small batches yield noisy, jagged updates, while large batches produce smooth, stable descent.\") as tracker:\n axes = Axes(x_range=[0, 10], y_range=[0, 5], x_length=8, y_length=4)\n axes\n \n small_curve = axes.plot(lambda x: 4 * np.exp(-0.3 * x) + 0.5 + 0.3 * np.sin(5 * x) * np.exp(-0.2 * x), color=GREEN, stroke_width=3)\n large_curve = axes.plot(lambda x: 4.2 * np.exp(-0.2 * x) + 0.8, color=RED, stroke_width=3)\n \n self.wait_until_bookmark(\"CURVES\")\n self.play(FadeOut(dataset), FadeOut(small_batch), FadeOut(large_batch))\n self.play(Create(axes), Create(small_curve), Create(large_curve), run_time=tracker.duration)\n \n with self.voiceover(text=\"While noise can help escape shallow local minima, too much variance slows down convergence. Finding the right batch size balances update speed with gradient stability.\") as tracker:\n tradeoff_text = VGroup(\n Text(\"Small Batch: Noisy, better generalization\", font_size=20, color=GREEN),\n Text(\"Large Batch: Smooth, faster per-step\", font_size=20, color=RED)\n ).arrange(DOWN, aligned_edge=LEFT)\n \n self.wait_until_bookmark(\"TRADEOFF\")\n self.play(Write(tradeoff_text), run_time=tracker.duration)\n self.wait(1)\n\n def fit_in_frame(self, mob: Mobject, w_frac: float = 0.9, h_frac: float = 0.9) -> Mobject:\n max_w = config.frame_width * w_frac\n max_h = config.frame_height * h_frac\n if mob.width > max_w:\n mob.width = max_w\n if mob.height > max_h:\n mob.height = max_h\n return mob\n```", "category": "spatial_layout_overlap", "source": "synthetic_hard_neg:nabin2004/qwen3-8b-manimator-gold-sft"} +{"system": "You are an expert Manim Community Edition (ManimCE v0.19+) Python developer and mathematical animator. Given a user request, first plan the spatial layout, coordinate bounds, timing, and pedagogical flow inside ... tags (when reasoning is helpful), and then output a complete, runnable, self-contained ManimCE Python script using `from manim import *`. Never use deprecated ManimGL (`manimlib`) methods like `ShowCreation`, `TexMobject`, `TextMobject`, or `axes.get_graph`; always use modern ManimCE APIs (`Create`, `MathTex`, `Tex`, `Text`, `axes.plot`) and prevent visual overlap using `.to_edge()`, `.next_to()`, and `FadeOut`.", "prompt": "Display a coordinate grid with a purple curve representing the function \\( y = x^2 \\), and a second curve showing its derivative, \\( y = 2x \\), automatically computed and plotted. The original function is labeled “\\( x^2 \\)” near \\( x = -2 \\), and the derivative is labeled “\\( 2x \\)” near \\( x = 3 \\). This scene visually illustrates the relationship between a function and its derivative.", "chosen": "```python\nfrom manim import *\n\nclass DerivativeGraphExample(Scene):\n def construct(self):\n ax = NumberPlane(y_range=[-1, 7], background_line_style={\"stroke_opacity\": 0.4})\n\n curve_1 = ax.plot(lambda x: x ** 2, color=PURPLE_B)\n curve_2 = ax.plot_derivative_graph(curve_1)\n curves = VGroup(curve_1, curve_2)\n\n label_1 = ax.get_graph_label(curve_1, \"x^2\", x_val=-2, direction=DL)\n label_2 = ax.get_graph_label(curve_2, \"2x\", x_val=3, direction=RIGHT)\n labels = VGroup(label_1, label_2)\n\n self.add(ax, curves, labels)\n```", "rejected": "```python\nfrom manim import *\n\nclass DerivativeGraphExample(Scene):\n def construct(self):\n ax = NumberPlane(y_range=[-1, 7], background_line_style={\"stroke_opacity\": 0.4})\n\n curve_1 = ax.get_graph(lambda x: x ** 2, color=PURPLE_B)\n curve_2 = ax.plot_derivative_graph(curve_1)\n curves = VGroup(curve_1, curve_2)\n\n label_1 = ax.get_graph_label(curve_1, \"x^2\", x_val=-2, direction=DL)\n label_2 = ax.get_graph_label(curve_2, \"2x\", x_val=3, direction=RIGHT)\n labels = VGroup(label_1, label_2)\n\n self.add(ax, curves, labels)\n```", "category": "legacy_api_hallucination", "source": "synthetic_hard_neg:SuienR/ManimBench-v1"} +{"system": "You are an expert Manim Community Edition (ManimCE v0.19+) Python developer and mathematical animator. Given a user request, first plan the spatial layout, coordinate bounds, timing, and pedagogical flow inside ... tags (when reasoning is helpful), and then output a complete, runnable, self-contained ManimCE Python script using `from manim import *`. Never use deprecated ManimGL (`manimlib`) methods like `ShowCreation`, `TexMobject`, `TextMobject`, or `axes.get_graph`; always use modern ManimCE APIs (`Create`, `MathTex`, `Tex`, `Text`, `axes.plot`) and prevent visual overlap using `.to_edge()`, `.next_to()`, and `FadeOut`.", "prompt": "Here’s an enhanced version of the animation that retains the original hexagon while adding dynamic transformations, explanatory text, and a mathematical formula to deepen understanding: \n\nThe scene begins with a yellow regular hexagon centered on the screen, just as in the original script. As the hexagon appears, a label reading *\"Regular Hexagon (6 sides)\"* fades in below it, providing context. The hexagon then smoothly transforms into an equilateral triangle (3 sides) and back, demonstrating how regular polygons relate to one another. Simultaneously, the formula *\"Interior Angle = (n-2) × 180° / n\"* appears at the top of the screen, dynamically updating as the shape changes—showing 120° for the hexagon and 60° for the triangle. Finally, the hexagon divides into six equilateral triangles by drawing lines from the center to each vertex, reinforcing its symmetry before the animation concludes. This expanded version not only visualizes the hexagon but also teaches key geometric properties through interactive transformations and mathematical annotations.", "chosen": "```python\nfrom manim import *\n\nclass HexagonTransform(Scene):\n def construct(self):\n # Create a regular hexagon\n hexagon = RegularPolygon(n=6, color=YELLOW, fill_opacity=0.5)\n hex_label = Text(\"Regular Hexagon (6 sides)\", font_size=24).next_to(hexagon, DOWN)\n \n # Display the hexagon and label\n self.play(Create(hexagon), Write(hex_label))\n self.wait(1)\n \n # Show the interior angle formula\n formula = MathTex(\n r\"\\text{Interior Angle} = \\frac{(n-2) \\times 180^\\circ}{n}\",\n font_size=36\n ).to_edge(UP)\n self.play(Write(formula))\n self.wait(1)\n \n # Update formula for hexagon (n=6)\n hex_angle = MathTex(\n r\"\\text{Interior Angle} = \\frac{(6-2) \\times 180^\\circ}{6} = 120^\\circ\",\n font_size=36\n ).to_edge(UP)\n self.play(Transform(formula, hex_angle))\n self.wait(1)\n \n # Transform hexagon into a triangle\n triangle = RegularPolygon(n=3, color=BLUE, fill_opacity=0.5)\n tri_label = Text(\"Equilateral Triangle (3 sides)\", font_size=24).next_to(triangle, DOWN)\n tri_angle = MathTex(\n r\"\\text{Interior Angle} = \\frac{(3-2) \\times 180^\\circ}{3} = 60^\\circ\",\n font_size=36\n ).to_edge(UP)\n \n self.play(\n Transform(hexagon, triangle),\n Transform(hex_label, tri_label),\n Transform(formula, tri_angle)\n )\n self.wait(1)\n \n # Transform back to hexagon\n self.play(\n Transform(hexagon, RegularPolygon(n=6, color=YELLOW, fill_opacity=0.5)),\n Transform(hex_label, Text(\"Regular Hexagon (6 sides)\", font_size=24).next_to(hexagon, DOWN)),\n Transform(formula, hex_angle)\n )\n self.wait(1)\n \n # Divide hexagon into 6 equilateral triangles\n center = hexagon.get_center()\n vertices = hexagon.get_vertices()\n lines = VGroup(*[Line(center, vertex, color=RED) for vertex in vertices])\n \n self.play(Create(lines))\n self.wait(2)\n \n # Fade out everything\n self.play(\n FadeOut(hexagon),\n FadeOut(hex_label),\n FadeOut(formula),\n FadeOut(lines)\n )\n```", "rejected": "```python\nfrom manim import *\n\nclass HexagonTransform(Scene):\n def construct(self):\n # Create a regular hexagon\n hexagon = RegularPolygon(n=6, color=YELLOW, fill_opacity=0.5)\n hex_label = Text(\"Regular Hexagon (6 sides)\", font_size=24).next_to(hexagon, DOWN)\n \n # Display the hexagon and label\n self.play(ShowCreation(hexagon), Write(hex_label))\n self.wait(1)\n \n # Show the interior angle formula\n formula = TexMobject(\n r\"\\text{Interior Angle} = \\frac{(n-2) \\times 180^\\circ}{n}\",\n font_size=36\n ).to_edge(UP)\n self.play(Write(formula))\n self.wait(1)\n \n # Update formula for hexagon (n=6)\n hex_angle = MathTex(\n r\"\\text{Interior Angle} = \\frac{(6-2) \\times 180^\\circ}{6} = 120^\\circ\",\n font_size=36\n ).to_edge(UP)\n self.play(Transform(formula, hex_angle))\n self.wait(1)\n \n # Transform hexagon into a triangle\n triangle = RegularPolygon(n=3, color=BLUE, fill_opacity=0.5)\n tri_label = Text(\"Equilateral Triangle (3 sides)\", font_size=24).next_to(triangle, DOWN)\n tri_angle = MathTex(\n r\"\\text{Interior Angle} = \\frac{(3-2) \\times 180^\\circ}{3} = 60^\\circ\",\n font_size=36\n ).to_edge(UP)\n \n self.play(\n Transform(hexagon, triangle),\n Transform(hex_label, tri_label),\n Transform(formula, tri_angle)\n )\n self.wait(1)\n \n # Transform back to hexagon\n self.play(\n Transform(hexagon, RegularPolygon(n=6, color=YELLOW, fill_opacity=0.5)),\n Transform(hex_label, Text(\"Regular Hexagon (6 sides)\", font_size=24).next_to(hexagon, DOWN)),\n Transform(formula, hex_angle)\n )\n self.wait(1)\n \n # Divide hexagon into 6 equilateral triangles\n center = hexagon.get_center()\n vertices = hexagon.get_vertices()\n lines = VGroup(*[Line(center, vertex, color=RED) for vertex in vertices])\n \n self.play(Create(lines))\n self.wait(2)\n \n # Fade out everything\n self.play(\n FadeOut(hexagon),\n FadeOut(hex_label),\n FadeOut(formula),\n FadeOut(lines)\n )\n```", "category": "legacy_api_hallucination", "source": "synthetic_hard_neg:nabin2004/manim-sft-10k"} +{"system": "You are an expert Manim Community Edition (ManimCE v0.19+) Python developer and mathematical animator. Given a user request, first plan the spatial layout, coordinate bounds, timing, and pedagogical flow inside ... tags (when reasoning is helpful), and then output a complete, runnable, self-contained ManimCE Python script using `from manim import *`. Never use deprecated ManimGL (`manimlib`) methods like `ShowCreation`, `TexMobject`, `TextMobject`, or `axes.get_graph`; always use modern ManimCE APIs (`Create`, `MathTex`, `Tex`, `Text`, `axes.plot`) and prevent visual overlap using `.to_edge()`, `.next_to()`, and `FadeOut`.", "prompt": "Here is the enhanced animation instruction that includes all original features plus significant new elements:\n\nThe enhanced animation begins with a red square appearing at the left side of the screen, which then smoothly shifts right while simultaneously rotating 360 degrees. As it reaches the right side, the square transforms into a blue circle while a mathematical equation (x² + y² = r²) fades in below it to illustrate the relationship between squares and circles. The circle then follows a circular path around the center of the screen, leaving a glowing trail that gradually fades. During this motion, the circle periodically pulses in size and displays its changing radius value in real-time. As the path completes, the circle morphs back into a square while the equation transforms into A = s² (area formula). The square then scales up dramatically while splitting into four smaller squares that arrange in a grid pattern. Finally, all squares simultaneously rotate while fading out, leaving behind a lingering afterimage effect that dissolves. Throughout the animation, subtle background grid lines provide spatial reference, and smooth easing functions are applied to all transitions for a polished look. The entire sequence maintains the original timing structure while adding these rich visual and mathematical elements.", "chosen": "```python\nfrom manim import *\n\nclass EnhancedSquareToCircle(Scene):\n def construct(self):\n # Create initial square\n square = Square(color=RED, fill_opacity=0.8)\n square.move_to(LEFT * 4)\n \n # Add background grid\n grid = NumberPlane()\n self.add(grid)\n \n # Animate square moving and rotating\n self.play(\n square.animate.shift(RIGHT * 8).rotate(2 * PI),\n run_time=3,\n rate_func=smooth\n )\n \n # Transform square to circle with equation\n circle = Circle(color=BLUE, fill_opacity=0.8)\n equation = MathTex(\"x^2 + y^2 = r^2\").next_to(circle, DOWN)\n \n self.play(\n Transform(square, circle),\n FadeIn(equation),\n run_time=2,\n rate_func=smooth\n )\n \n # Create circular path and animate circle with trail\n path = Circle(radius=2, color=WHITE)\n moving_dot = always_redraw(lambda: Dot(circle.get_center(), color=YELLOW, radius=0.1))\n radius_label = always_redraw(lambda: DecimalNumber(circle.get_center()[0] + 2).next_to(circle, UP))\n \n self.add(moving_dot, radius_label)\n self.play(\n MoveAlongPath(circle, path),\n run_time=4,\n rate_func=smooth\n )\n \n # Pulsing effect during motion\n for _ in range(2):\n self.play(\n circle.animate.scale(1.2),\n run_time=0.5,\n rate_func=there_and_back\n )\n \n # Transform back to square with area equation\n new_square = Square(color=RED, fill_opacity=0.8)\n area_eq = MathTex(\"A = s^2\").next_to(new_square, DOWN)\n \n self.play(\n Transform(circle, new_square),\n Transform(equation, area_eq),\n run_time=2,\n rate_func=smooth\n )\n \n # Scale up and split into four squares\n self.play(\n new_square.animate.scale(2),\n run_time=1.5,\n rate_func=smooth\n )\n \n squares = VGroup(*[\n Square(color=RED, fill_opacity=0.6, side_length=1).move_to(\n new_square.get_center() + np.array([x, y, 0])\n )\n for x in [-1, 1]\n for y in [-1, 1]\n ])\n \n self.play(\n ReplacementTransform(new_square, squares),\n run_time=2,\n rate_func=smooth\n )\n \n # Create afterimages\n afterimages = [square.copy().set_opacity(0.3) for square in squares]\n self.add(*afterimages)\n \n # Rotate and fade out squares\n self.play(\n squares.animate.rotate(PI/2),\n FadeOut(squares),\n run_time=2,\n rate_func=smooth\n )\n \n # Fade out afterimages\n self.play(\n *[FadeOut(img) for img in afterimages],\n FadeOut(equation),\n FadeOut(grid),\n run_time=2,\n rate_func=smooth\n )\n```", "rejected": "```python\nfrom manim import *\n\nclass EnhancedSquareToCircle(Scene):\n def construct(self):\n # Create initial square\n square = Square(color=RED, fill_opacity=0.8)\n square.move_to(LEFT * 4)\n \n # Add background grid\n grid = NumberPlane()\n self.add(grid)\n \n # Animate square moving and rotating\n self.play(\n square.animate.shift(RIGHT * 8).rotate(2 * PI),\n run_time=3,\n rate_func=smooth\n )\n \n # Transform square to circle with equation\n circle = Circle(color=BLUE, fill_opacity=0.8)\n equation = TexMobject(\"x^2 + y^2 = r^2\").next_to(circle, DOWN)\n \n self.play(\n Transform(square, circle),\n FadeIn(equation),\n run_time=2,\n rate_func=smooth\n )\n \n # Create circular path and animate circle with trail\n path = Circle(radius=2, color=WHITE)\n moving_dot = always_redraw(lambda: Dot(circle.get_center(), color=YELLOW, radius=0.1))\n radius_label = always_redraw(lambda: DecimalNumber(circle.get_center()[0] + 2).next_to(circle, UP))\n \n self.add(moving_dot, radius_label)\n self.play(\n MoveAlongPath(circle, path),\n run_time=4,\n rate_func=smooth\n )\n \n # Pulsing effect during motion\n for _ in range(2):\n self.play(\n circle.animate.scale(1.2),\n run_time=0.5,\n rate_func=there_and_back\n )\n \n # Transform back to square with area equation\n new_square = Square(color=RED, fill_opacity=0.8)\n area_eq = MathTex(\"A = s^2\").next_to(new_square, DOWN)\n \n self.play(\n Transform(circle, new_square),\n Transform(equation, area_eq),\n run_time=2,\n rate_func=smooth\n )\n \n # Scale up and split into four squares\n self.play(\n new_square.animate.scale(2),\n run_time=1.5,\n rate_func=smooth\n )\n \n squares = VGroup(*[\n Square(color=RED, fill_opacity=0.6, side_length=1).move_to(\n new_square.get_center() + np.array([x, y, 0])\n )\n for x in [-1, 1]\n for y in [-1, 1]\n ])\n \n self.play(\n ReplacementTransform(new_square, squares),\n run_time=2,\n rate_func=smooth\n )\n \n # Create afterimages\n afterimages = [square.copy().set_opacity(0.3) for square in squares]\n self.add(*afterimages)\n \n # Rotate and fade out squares\n self.play(\n squares.animate.rotate(PI/2),\n FadeOut(squares),\n run_time=2,\n rate_func=smooth\n )\n \n # Fade out afterimages\n self.play(\n *[FadeOut(img) for img in afterimages],\n FadeOut(equation),\n FadeOut(grid),\n run_time=2,\n rate_func=smooth\n )\n```", "category": "legacy_api_hallucination", "source": "synthetic_hard_neg:nabin2004/manim-sft-10k"} +{"system": "You are an expert Manim Community Edition (ManimCE v0.19+) Python developer and mathematical animator. Given a user request, first plan the spatial layout, coordinate bounds, timing, and pedagogical flow inside ... tags (when reasoning is helpful), and then output a complete, runnable, self-contained ManimCE Python script using `from manim import *`. Never use deprecated ManimGL (`manimlib`) methods like `ShowCreation`, `TexMobject`, `TextMobject`, or `axes.get_graph`; always use modern ManimCE APIs (`Create`, `MathTex`, `Tex`, `Text`, `axes.plot`) and prevent visual overlap using `.to_edge()`, `.next_to()`, and `FadeOut`.", "prompt": "I'm studying weight initialization and want to compare Xavier and He schemes in terms of fan_in and fan_out. Visualize two initialization variants as grids of vectors in a layer and show how variance scales with layer width. Animate gradient norms and signal magnitudes across several layers to illustrate stability versus explosion under each scheme. Add a side-by-side caption explaining the intuition behind appropriate fan_in/out choices.", "chosen": "```python\nfrom manim import *\nfrom manim_voiceover import VoiceoverScene\nfrom manim_voiceover.services.gtts import GTTSService\n\n\nclass WeightInitializationComparison(VoiceoverScene):\n def construct(self):\n self.set_speech_service(\n GTTSService(voice=\"alba\", cache_dir=\"voiceover_cache\")\n )\n \n # Title section\n title = Text(\"Weight Initialization Comparison\", font_size=48, color=BLUE)\n subtitle = Text(\"Xavier vs He vs Random\", font_size=32, color=GRAY)\n subtitle.next_to(title, DOWN, buff=0.3)\n \n with self.voiceover(text=\"Imagine training a neural network from scratch. What if I told you that the way you initialize the weights could drastically affect the success of your training process?\") as tracker:\n self.play(Write(title), run_time=tracker.duration * 0.6)\n self.play(FadeIn(subtitle), run_time=tracker.duration * 0.4)\n \n self.wait(0.5)\n self.play(FadeOut(title), FadeOut(subtitle))\n \n # Section: Why initialization matters\n section_title = Text(\"Why Does Weight Initialization Matter?\", font_size=36, color=YELLOW)\n section_title.to_edge(UP, buff=0.5)\n \n with self.voiceover(text=\"Join me as we explore the fascinating world of weight initialization methods. First, let's understand why this matters so much.\") as tracker:\n self.play(Write(section_title), run_time=tracker.duration)\n \n # Create a simple neural network diagram\n nn_layers = VGroup()\n layer_sizes = [3, 4, 4, 2]\n layer_spacing = 2.5\n neuron_radius = 0.15\n \n layers = []\n for i, size in enumerate(layer_sizes):\n layer = VGroup()\n for j in range(size):\n neuron = Circle(radius=neuron_radius, fill_color=BLUE, fill_opacity=0.8, stroke_color=WHITE)\n neuron.shift(UP * (size - 1) * 0.5 - UP * j * 0.5)\n layer.add(neuron)\n layer.shift(RIGHT * i * layer_spacing - RIGHT * 3)\n layers.append(layer)\n nn_layers.add(layer)\n \n # Add connections\n connections = VGroup()\n for i in range(len(layers) - 1):\n for neuron1 in layers[i]:\n for neuron2 in layers[i + 1]:\n line = Line(neuron1.get_center(), neuron2.get_center(), stroke_width=1, stroke_opacity=0.3)\n connections.add(line)\n \n nn_group = VGroup(connections, nn_layers)\n nn_group.scale(0.9)\n nn_group.next_to(section_title, DOWN, buff=0.5)\n \n with self.voiceover(text=\"In a deep neural network, data flows through many layers. Each connection has a weight that gets multiplied with the input.\") as tracker:\n self.play(Create(connections), run_time=tracker.duration * 0.5)\n self.play(Create(nn_layers), run_time=tracker.duration * 0.5)\n \n # Show vanishing gradients\n vanishing_text = Text(\"Vanishing Gradients\", font_size=24, color=RED)\n vanishing_text.next_to(nn_group, DOWN, buff=0.3)\n \n exploding_text = Text(\"Exploding Gradients\", font_size=24, color=RED)\n exploding_text.next_to(nn_group, DOWN, buff=0.3)\n \n with self.voiceover(text=\"If weights are too small, gradients become smaller and smaller as they backpropagate through layers. This is called the vanishing gradient problem.\") as tracker:\n self.play(Write(vanishing_text), run_time=tracker.duration * 0.5)\n # Animate fading neurons to represent vanishing\n fade_anims = [neuron.animate.set_fill(opacity=0.2) for layer in layers[1:] for neuron in layer]\n self.play(*fade_anims, run_time=tracker.duration * 0.5)\n \n self.wait(0.3)\n \n # Reset and show exploding\n with self.voiceover(text=\"Conversely, if weights are too large, gradients can explode to huge values, making training unstable.\") as tracker:\n self.play(FadeOut(vanishing_text), run_time=tracker.duration * 0.2)\n reset_anims = [neuron.animate.set_fill(opacity=0.8) for layer in layers for neuron in layer]\n self.play(*reset_anims, run_time=tracker.duration * 0.3)\n self.play(Write(exploding_text), run_time=tracker.duration * 0.3)\n # Flash effect for exploding\n flash_anims = [neuron.animate.set_fill(RED, opacity=1.0) for layer in layers[1:] for neuron in layer]\n self.play(*flash_anims, run_time=tracker.duration * 0.2)\n \n self.play(FadeOut(exploding_text), FadeOut(nn_group), FadeOut(section_title))\n \n # Section: Random Initialization\n section_title2 = Text(\"Method 1: Random Initialization\", font_size=36, color=YELLOW)\n section_title2.to_edge(UP, buff=0.5)\n \n with self.voiceover(text=\"Let's explore three common initialization methods. First up: simple random initialization.\") as tracker:\n self.play(Write(section_title2), run_time=tracker.duration)\n \n # Formula for random init\n random_formula = MathTex(r\"W \\sim \\mathcal{N}(0, 1)\", font_size=40)\n random_formula.next_to(section_title2, DOWN, buff=0.8)\n \n random_desc = Text(\"Weights drawn from standard normal distribution\", font_size=22, color=GRAY)\n random_desc.next_to(random_formula, DOWN, buff=0.4)\n \n with self.voiceover(text=\"With random initialization, weights are drawn from a standard normal distribution with mean zero and standard deviation one.\") as tracker:\n self.play(Write(random_formula), run_time=tracker.duration * 0.6)\n self.play(FadeIn(random_desc), run_time=tracker.duration * 0.4)\n \n # Show problem with random init\n problem_text = Text(\"Problem: Can lead to vanishing or exploding gradients\", font_size=24, color=RED)\n problem_text.next_to(random_desc, DOWN, buff=0.5)\n \n with self.voiceover(text=\"The problem? This can easily lead to either vanishing or exploding gradients in deep networks, making it hard to train effectively.\") as tracker:\n self.play(Write(problem_text), run_time=tracker.duration)\n \n self.wait(0.3)\n self.play(FadeOut(random_formula), FadeOut(random_desc), FadeOut(problem_text), FadeOut(section_title2))\n \n # Section: Xavier/Glorot Initialization\n section_title3 = Text(\"Method 2: Xavier (Glorot) Initialization\", font_size=34, color=YELLOW)\n section_title3.to_edge(UP, buff=0.5)\n \n with self.voiceover(text=\"Next, let's look at Xavier initialization, also known as Glorot initialization. This method was designed to address the problems of random initialization.\") as tracker:\n self.play(Write(section_title3), run_time=tracker.duration)\n \n # Xavier formula\n xavier_formula = MathTex(r\"W \\sim \\mathcal{N}\\left(0, \\frac{2}{n_{in} + n_{out}}\\right)\", font_size=38)\n xavier_formula.next_to(section_title3, DOWN, buff=0.6)\n \n xavier_alt = MathTex(r\"W \\sim \\mathcal{U}\\left(-\\sqrt{\\frac{6}{n_{in} + n_{out}}}, \\sqrt{\\frac{6}{n_{in} + n_{out}}}\\right)\", font_size=34)\n xavier_alt.next_to(xavier_formula, DOWN, buff=0.4)\n \n with self.voiceover(text=\"Xavier initialization scales the weights based on the number of input and output neurons. The variance is set to 2 divided by the sum of input and output neurons.\") as tracker:\n self.play(Write(xavier_formula), run_time=tracker.duration * 0.6)\n self.play(Write(xavier_alt), run_time=tracker.duration * 0.4)\n \n # Best for\n xavier_best = Text(\"Best for: tanh and sigmoid activation functions\", font_size=24, color=GREEN)\n xavier_best.next_to(xavier_alt, DOWN, buff=0.5)\n \n with self.voiceover(text=\"Xavier initialization works best with tanh and sigmoid activation functions. It helps maintain the variance of activations throughout the network.\") as tracker:\n self.play(Write(xavier_best), run_time=tracker.duration)\n \n self.wait(0.3)\n self.play(FadeOut(xavier_formula), FadeOut(xavier_alt), FadeOut(xavier_best), FadeOut(section_title3))\n \n # Section: He Initialization\n section_title4 = Text(\"Method 3: He Initialization\", font_size=36, color=YELLOW)\n section_title4.to_edge(UP, buff=0.5)\n \n with self.voiceover(text=\"Finally, let's examine He initialization. This method was specifically designed for networks using ReLU activation functions.\") as tracker:\n self.play(Write(section_title4), run_time=tracker.duration)\n \n # He formula\n he_formula = MathTex(r\"W \\sim \\mathcal{N}\\left(0, \\frac{2}{n_{in}}\\right)\", font_size=40)\n he_formula.next_to(section_title4, DOWN, buff=0.6)\n \n he_alt = MathTex(r\"W \\sim \\mathcal{U}\\left(-\\sqrt{\\frac{6}{n_{in}}}, \\sqrt{\\frac{6}{n_{in}}}\\right)\", font_size=36)\n he_alt.next_to(he_formula, DOWN, buff=0.4)\n \n with self.voiceover(text=\"He initialization uses a variance of 2 divided by the number of input neurons. This accounts for the fact that ReLU sets half the inputs to zero.\") as tracker:\n self.play(Write(he_formula), run_time=tracker.duration * 0.6)\n self.play(Write(he_alt), run_time=tracker.duration * 0.4)\n \n # Best for\n he_best = Text(\"Best for: ReLU and its variants (Leaky ReLU, ELU)\", font_size=24, color=GREEN)\n he_best.next_to(he_alt, DOWN, buff=0.5)\n \n with self.voiceover(text=\"He initialization is ideal for ReLU and its variants like Leaky ReLU and ELU. It accounts for the sparsity ReLU introduces.\") as tracker:\n self.play(Write(he_best), run_time=tracker.duration)\n \n self.wait(0.3)\n self.play(FadeOut(he_formula), FadeOut(he_alt), FadeOut(he_best), FadeOut(section_title4))\n \n # Comparison Section\n section_title5 = Text(\"Performance Comparison\", font_size=36, color=YELLOW)\n section_title5.to_edge(UP, buff=0.5)\n \n with self.voiceover(text=\"Now let's compare these methods in terms of training convergence speed.\") as tracker:\n self.play(Write(section_title5), run_time=tracker.duration)\n \n # Create comparison chart\n chart_title = Text(\"Epochs to Convergence (lower is better)\", font_size=22, color=WHITE)\n chart_title.next_to(section_title5, DOWN, buff=0.4)\n \n # Bar chart showing convergence speed comparison\n chart = BarChart(\n values=[100, 55, 40],\n bar_names=[\"Random\", \"Xavier\", \"He\"],\n y_range=[0, 120, 20],\n x_length=8,\n y_length=4,\n bar_colors=[\"#ff6361\", \"#58508d\", \"#00c853\"],\n bar_width=0.5\n )\n chart.next_to(chart_title, DOWN, buff=0.3)\n \n bar_labels = chart.get_bar_labels(font_size=20)\n \n with self.voiceover(text=\"Random initialization typically takes the longest to converge, around 100 epochs. Xavier initialization speeds this up to about 55 epochs.\") as tracker:\n self.play(Write(chart_title), run_time=tracker.duration * 0.3)\n self.play(Create(chart), run_time=tracker.duration * 0.4)\n self.play(Create(bar_labels), run_time=tracker.duration * 0.3)\n \n with self.voiceover(text=\"He initialization performs best with ReLU, converging in just 40 epochs. The right initialization can cut training time by more than half!\") as tracker:\n self.wait(tracker.duration)\n \n self.wait(0.3)\n self.play(FadeOut(chart), FadeOut(bar_labels), FadeOut(chart_title))\n \n # Summary\n summary_box = RoundedRectangle(corner_radius=0.2, width=12, height=4.5, color=BLUE)\n summary_box.next_to(section_title5, DOWN, buff=0.3)\n \n summary_title = Text(\"Key Takeaways\", font_size=30, color=YELLOW)\n summary_title.next_to(summary_box.get_top(), DOWN, buff=0.3)\n \n # Two-column layout for takeaways\n left_col = VGroup()\n right_col = VGroup()\n \n takeaway1 = Text(\"• Use Xavier for tanh/sigmoid\", font_size=22, color=WHITE)\n takeaway2 = Text(\"• Use He for ReLU variants\", font_size=22, color=WHITE)\n takeaway3 = Text(\"• Proper init prevents gradient issues\", font_size=22, color=WHITE)\n takeaway4 = Text(\"• Faster convergence = saved time\", font_size=22, color=WHITE)\n \n left_col.add(takeaway1, takeaway2)\n right_col.add(takeaway3, takeaway4)\n \n left_col.arrange(DOWN, aligned_edge=LEFT, buff=0.4)\n right_col.arrange(DOWN, aligned_edge=LEFT, buff=0.4)\n \n left_col.next_to(summary_title, DOWN, buff=0.4)\n left_col.shift(LEFT * 2.5)\n right_col.next_to(summary_title, DOWN, buff=0.4)\n right_col.shift(RIGHT * 2.5)\n \n with self.voiceover(text=\"To summarize: Use Xavier initialization for tanh and sigmoid activations. Use He initialization for ReLU and its variants.\") as tracker:\n self.play(Create(summary_box), Write(summary_title), run_time=tracker.duration * 0.4)\n self.play(Write(left_col), run_time=tracker.duration * 0.3)\n self.play(Write(right_col), run_time=tracker.duration * 0.3)\n \n with self.voiceover(text=\"Proper initialization prevents vanishing and exploding gradients, leading to faster convergence and saving valuable training time.\") as tracker:\n self.wait(tracker.duration)\n \n # Final message\n final_text = Text(\"Choose wisely and train efficiently!\", font_size=28, color=GREEN)\n final_text.next_to(summary_box, DOWN, buff=0.4)\n \n with self.voiceover(text=\"Choose your initialization wisely and train your neural networks efficiently!\") as tracker:\n self.play(Write(final_text), run_time=tracker.duration)\n \n self.wait(1)\n self.play(FadeOut(summary_box), FadeOut(summary_title), FadeOut(left_col), FadeOut(right_col), FadeOut(final_text), FadeOut(section_title5))\n \n # End screen\n end_text = Text(\"Weight Initialization Comparison\", font_size=40, color=BLUE)\n thanks_text = Text(\"Thanks for watching!\", font_size=32, color=GRAY)\n thanks_text.next_to(end_text, DOWN, buff=0.4)\n \n self.play(Write(end_text), FadeIn(thanks_text))\n self.wait(2)\n```", "rejected": "```python\nfrom manim import *\nfrom manim_voiceover import VoiceoverScene\nfrom manim_voiceover.services.gtts import GTTSService\n\n\nclass WeightInitializationComparison(VoiceoverScene):\n def construct(self):\n self.set_speech_service(\n GTTSService(voice=\"alba\", cache_dir=\"voiceover_cache\")\n )\n \n # Title section\n title = Text(\"Weight Initialization Comparison\", font_size=48, color=BLUE)\n subtitle = Text(\"Xavier vs He vs Random\", font_size=32, color=GRAY)\n subtitle\n \n with self.voiceover(text=\"Imagine training a neural network from scratch. What if I told you that the way you initialize the weights could drastically affect the success of your training process?\") as tracker:\n self.play(Write(title), run_time=tracker.duration * 0.6)\n self.play(FadeIn(subtitle), run_time=tracker.duration * 0.4)\n \n self.wait(0.5)\n self.play(FadeOut(title), FadeOut(subtitle))\n \n # Section: Why initialization matters\n section_title = Text(\"Why Does Weight Initialization Matter?\", font_size=36, color=YELLOW)\n section_title\n \n with self.voiceover(text=\"Join me as we explore the fascinating world of weight initialization methods. First, let's understand why this matters so much.\") as tracker:\n self.play(Write(section_title), run_time=tracker.duration)\n \n # Create a simple neural network diagram\n nn_layers = VGroup()\n layer_sizes = [3, 4, 4, 2]\n layer_spacing = 2.5\n neuron_radius = 0.15\n \n layers = []\n for i, size in enumerate(layer_sizes):\n layer = VGroup()\n for j in range(size):\n neuron = Circle(radius=neuron_radius, fill_color=BLUE, fill_opacity=0.8, stroke_color=WHITE)\n neuron.shift(UP * (size - 1) * 0.5 - UP * j * 0.5)\n layer.add(neuron)\n layer\n layers.append(layer)\n nn_layers.add(layer)\n \n # Add connections\n connections = VGroup()\n for i in range(len(layers) - 1):\n for neuron1 in layers[i]:\n for neuron2 in layers[i + 1]:\n line = Line(neuron1.get_center(), neuron2.get_center(), stroke_width=1, stroke_opacity=0.3)\n connections.add(line)\n \n nn_group = VGroup(connections, nn_layers)\n nn_group.scale(0.9)\n nn_group.next_to(section_title, DOWN, buff=0.5)\n \n with self.voiceover(text=\"In a deep neural network, data flows through many layers. Each connection has a weight that gets multiplied with the input.\") as tracker:\n self.play(Create(connections), run_time=tracker.duration * 0.5)\n self.play(Create(nn_layers), run_time=tracker.duration * 0.5)\n \n # Show vanishing gradients\n vanishing_text = Text(\"Vanishing Gradients\", font_size=24, color=RED)\n vanishing_text.next_to(nn_group, DOWN, buff=0.3)\n \n exploding_text = Text(\"Exploding Gradients\", font_size=24, color=RED)\n exploding_text.next_to(nn_group, DOWN, buff=0.3)\n \n with self.voiceover(text=\"If weights are too small, gradients become smaller and smaller as they backpropagate through layers. This is called the vanishing gradient problem.\") as tracker:\n self.play(Write(vanishing_text), run_time=tracker.duration * 0.5)\n # Animate fading neurons to represent vanishing\n fade_anims = [neuron.animate.set_fill(opacity=0.2) for layer in layers[1:] for neuron in layer]\n self.play(*fade_anims, run_time=tracker.duration * 0.5)\n \n self.wait(0.3)\n \n # Reset and show exploding\n with self.voiceover(text=\"Conversely, if weights are too large, gradients can explode to huge values, making training unstable.\") as tracker:\n self.play(FadeOut(vanishing_text), run_time=tracker.duration * 0.2)\n reset_anims = [neuron.animate.set_fill(opacity=0.8) for layer in layers for neuron in layer]\n self.play(*reset_anims, run_time=tracker.duration * 0.3)\n self.play(Write(exploding_text), run_time=tracker.duration * 0.3)\n # Flash effect for exploding\n flash_anims = [neuron.animate.set_fill(RED, opacity=1.0) for layer in layers[1:] for neuron in layer]\n self.play(*flash_anims, run_time=tracker.duration * 0.2)\n \n self.play(FadeOut(exploding_text), FadeOut(nn_group), FadeOut(section_title))\n \n # Section: Random Initialization\n section_title2 = Text(\"Method 1: Random Initialization\", font_size=36, color=YELLOW)\n section_title2.to_edge(UP, buff=0.5)\n \n with self.voiceover(text=\"Let's explore three common initialization methods. First up: simple random initialization.\") as tracker:\n self.play(Write(section_title2), run_time=tracker.duration)\n \n # Formula for random init\n random_formula = MathTex(r\"W \\sim \\mathcal{N}(0, 1)\", font_size=40)\n random_formula.next_to(section_title2, DOWN, buff=0.8)\n \n random_desc = Text(\"Weights drawn from standard normal distribution\", font_size=22, color=GRAY)\n random_desc.next_to(random_formula, DOWN, buff=0.4)\n \n with self.voiceover(text=\"With random initialization, weights are drawn from a standard normal distribution with mean zero and standard deviation one.\") as tracker:\n self.play(Write(random_formula), run_time=tracker.duration * 0.6)\n self.play(FadeIn(random_desc), run_time=tracker.duration * 0.4)\n \n # Show problem with random init\n problem_text = Text(\"Problem: Can lead to vanishing or exploding gradients\", font_size=24, color=RED)\n problem_text.next_to(random_desc, DOWN, buff=0.5)\n \n with self.voiceover(text=\"The problem? This can easily lead to either vanishing or exploding gradients in deep networks, making it hard to train effectively.\") as tracker:\n self.play(Write(problem_text), run_time=tracker.duration)\n \n self.wait(0.3)\n self.play(FadeOut(random_formula), FadeOut(random_desc), FadeOut(problem_text), FadeOut(section_title2))\n \n # Section: Xavier/Glorot Initialization\n section_title3 = Text(\"Method 2: Xavier (Glorot) Initialization\", font_size=34, color=YELLOW)\n section_title3.to_edge(UP, buff=0.5)\n \n with self.voiceover(text=\"Next, let's look at Xavier initialization, also known as Glorot initialization. This method was designed to address the problems of random initialization.\") as tracker:\n self.play(Write(section_title3), run_time=tracker.duration)\n \n # Xavier formula\n xavier_formula = MathTex(r\"W \\sim \\mathcal{N}\\left(0, \\frac{2}{n_{in} + n_{out}}\\right)\", font_size=38)\n xavier_formula.next_to(section_title3, DOWN, buff=0.6)\n \n xavier_alt = MathTex(r\"W \\sim \\mathcal{U}\\left(-\\sqrt{\\frac{6}{n_{in} + n_{out}}}, \\sqrt{\\frac{6}{n_{in} + n_{out}}}\\right)\", font_size=34)\n xavier_alt.next_to(xavier_formula, DOWN, buff=0.4)\n \n with self.voiceover(text=\"Xavier initialization scales the weights based on the number of input and output neurons. The variance is set to 2 divided by the sum of input and output neurons.\") as tracker:\n self.play(Write(xavier_formula), run_time=tracker.duration * 0.6)\n self.play(Write(xavier_alt), run_time=tracker.duration * 0.4)\n \n # Best for\n xavier_best = Text(\"Best for: tanh and sigmoid activation functions\", font_size=24, color=GREEN)\n xavier_best.next_to(xavier_alt, DOWN, buff=0.5)\n \n with self.voiceover(text=\"Xavier initialization works best with tanh and sigmoid activation functions. It helps maintain the variance of activations throughout the network.\") as tracker:\n self.play(Write(xavier_best), run_time=tracker.duration)\n \n self.wait(0.3)\n self.play(FadeOut(xavier_formula), FadeOut(xavier_alt), FadeOut(xavier_best), FadeOut(section_title3))\n \n # Section: He Initialization\n section_title4 = Text(\"Method 3: He Initialization\", font_size=36, color=YELLOW)\n section_title4.to_edge(UP, buff=0.5)\n \n with self.voiceover(text=\"Finally, let's examine He initialization. This method was specifically designed for networks using ReLU activation functions.\") as tracker:\n self.play(Write(section_title4), run_time=tracker.duration)\n \n # He formula\n he_formula = MathTex(r\"W \\sim \\mathcal{N}\\left(0, \\frac{2}{n_{in}}\\right)\", font_size=40)\n he_formula.next_to(section_title4, DOWN, buff=0.6)\n \n he_alt = MathTex(r\"W \\sim \\mathcal{U}\\left(-\\sqrt{\\frac{6}{n_{in}}}, \\sqrt{\\frac{6}{n_{in}}}\\right)\", font_size=36)\n he_alt.next_to(he_formula, DOWN, buff=0.4)\n \n with self.voiceover(text=\"He initialization uses a variance of 2 divided by the number of input neurons. This accounts for the fact that ReLU sets half the inputs to zero.\") as tracker:\n self.play(Write(he_formula), run_time=tracker.duration * 0.6)\n self.play(Write(he_alt), run_time=tracker.duration * 0.4)\n \n # Best for\n he_best = Text(\"Best for: ReLU and its variants (Leaky ReLU, ELU)\", font_size=24, color=GREEN)\n he_best.next_to(he_alt, DOWN, buff=0.5)\n \n with self.voiceover(text=\"He initialization is ideal for ReLU and its variants like Leaky ReLU and ELU. It accounts for the sparsity ReLU introduces.\") as tracker:\n self.play(Write(he_best), run_time=tracker.duration)\n \n self.wait(0.3)\n self.play(FadeOut(he_formula), FadeOut(he_alt), FadeOut(he_best), FadeOut(section_title4))\n \n # Comparison Section\n section_title5 = Text(\"Performance Comparison\", font_size=36, color=YELLOW)\n section_title5.to_edge(UP, buff=0.5)\n \n with self.voiceover(text=\"Now let's compare these methods in terms of training convergence speed.\") as tracker:\n self.play(Write(section_title5), run_time=tracker.duration)\n \n # Create comparison chart\n chart_title = Text(\"Epochs to Convergence (lower is better)\", font_size=22, color=WHITE)\n chart_title.next_to(section_title5, DOWN, buff=0.4)\n \n # Bar chart showing convergence speed comparison\n chart = BarChart(\n values=[100, 55, 40],\n bar_names=[\"Random\", \"Xavier\", \"He\"],\n y_range=[0, 120, 20],\n x_length=8,\n y_length=4,\n bar_colors=[\"#ff6361\", \"#58508d\", \"#00c853\"],\n bar_width=0.5\n )\n chart.next_to(chart_title, DOWN, buff=0.3)\n \n bar_labels = chart.get_bar_labels(font_size=20)\n \n with self.voiceover(text=\"Random initialization typically takes the longest to converge, around 100 epochs. Xavier initialization speeds this up to about 55 epochs.\") as tracker:\n self.play(Write(chart_title), run_time=tracker.duration * 0.3)\n self.play(Create(chart), run_time=tracker.duration * 0.4)\n self.play(Create(bar_labels), run_time=tracker.duration * 0.3)\n \n with self.voiceover(text=\"He initialization performs best with ReLU, converging in just 40 epochs. The right initialization can cut training time by more than half!\") as tracker:\n self.wait(tracker.duration)\n \n self.wait(0.3)\n self.play(FadeOut(chart), FadeOut(bar_labels), FadeOut(chart_title))\n \n # Summary\n summary_box = RoundedRectangle(corner_radius=0.2, width=12, height=4.5, color=BLUE)\n summary_box.next_to(section_title5, DOWN, buff=0.3)\n \n summary_title = Text(\"Key Takeaways\", font_size=30, color=YELLOW)\n summary_title.next_to(summary_box.get_top(), DOWN, buff=0.3)\n \n # Two-column layout for takeaways\n left_col = VGroup()\n right_col = VGroup()\n \n takeaway1 = Text(\"• Use Xavier for tanh/sigmoid\", font_size=22, color=WHITE)\n takeaway2 = Text(\"• Use He for ReLU variants\", font_size=22, color=WHITE)\n takeaway3 = Text(\"• Proper init prevents gradient issues\", font_size=22, color=WHITE)\n takeaway4 = Text(\"• Faster convergence = saved time\", font_size=22, color=WHITE)\n \n left_col.add(takeaway1, takeaway2)\n right_col.add(takeaway3, takeaway4)\n \n left_col.arrange(DOWN, aligned_edge=LEFT, buff=0.4)\n right_col.arrange(DOWN, aligned_edge=LEFT, buff=0.4)\n \n left_col.next_to(summary_title, DOWN, buff=0.4)\n left_col.shift(LEFT * 2.5)\n right_col.next_to(summary_title, DOWN, buff=0.4)\n right_col.shift(RIGHT * 2.5)\n \n with self.voiceover(text=\"To summarize: Use Xavier initialization for tanh and sigmoid activations. Use He initialization for ReLU and its variants.\") as tracker:\n self.play(Create(summary_box), Write(summary_title), run_time=tracker.duration * 0.4)\n self.play(Write(left_col), run_time=tracker.duration * 0.3)\n self.play(Write(right_col), run_time=tracker.duration * 0.3)\n \n with self.voiceover(text=\"Proper initialization prevents vanishing and exploding gradients, leading to faster convergence and saving valuable training time.\") as tracker:\n self.wait(tracker.duration)\n \n # Final message\n final_text = Text(\"Choose wisely and train efficiently!\", font_size=28, color=GREEN)\n final_text.next_to(summary_box, DOWN, buff=0.4)\n \n with self.voiceover(text=\"Choose your initialization wisely and train your neural networks efficiently!\") as tracker:\n self.play(Write(final_text), run_time=tracker.duration)\n \n self.wait(1)\n self.play(FadeOut(summary_box), FadeOut(summary_title), FadeOut(left_col), FadeOut(right_col), FadeOut(final_text), FadeOut(section_title5))\n \n # End screen\n end_text = Text(\"Weight Initialization Comparison\", font_size=40, color=BLUE)\n thanks_text = Text(\"Thanks for watching!\", font_size=32, color=GRAY)\n thanks_text.next_to(end_text, DOWN, buff=0.4)\n \n self.play(Write(end_text), FadeIn(thanks_text))\n self.wait(2)\n```", "category": "spatial_layout_overlap", "source": "synthetic_hard_neg:nabin2004/AOS-Narrated-Manim-400"} +{"system": "You are an expert Manim Community Edition (ManimCE v0.19+) Python developer and mathematical animator. Given a user request, first plan the spatial layout, coordinate bounds, timing, and pedagogical flow inside ... tags (when reasoning is helpful), and then output a complete, runnable, self-contained ManimCE Python script using `from manim import *`. Never use deprecated ManimGL (`manimlib`) methods like `ShowCreation`, `TexMobject`, `TextMobject`, or `axes.get_graph`; always use modern ManimCE APIs (`Create`, `MathTex`, `Tex`, `Text`, `axes.plot`) and prevent visual overlap using `.to_edge()`, `.next_to()`, and `FadeOut`.", "prompt": "I'm learning k-fold cross-validation and want a visualization where the dataset rotates into k train/dev partitions. Show a grid of data points that reassigns to train vs dev across folds, with a rotating partition indicator. Include an animated accuracy curve across folds and a quick recap of how each sample participates in dev exactly once. Use transitions that emphasize overlap vs independence.", "chosen": "```python\nfrom manim import *\nfrom manim_voiceover import VoiceoverScene\nfrom manim_voiceover.services.gtts import GTTSService\n\n\nclass KFoldVisualization(VoiceoverScene):\n def construct(self):\n self.set_speech_service(\n GTTSService(voice=\"alba\", cache_dir=\"voiceover_cache\")\n )\n \n # Title\n title = Text(\"K-Fold Cross Validation\", font_size=48, color=BLUE)\n title.to_edge(UP, buff=0.5)\n \n with self.voiceover(text=\"Imagine you're training a machine learning model and want to know how well it's going to perform on real data. Wouldn't it be great if you could simulate this performance effectively? That's where K-Fold Cross Validation comes into play!\") as tracker:\n self.play(Write(title), run_time=tracker.duration)\n \n self.wait(0.5)\n \n # Clear title and move to corner\n title_small = Text(\"K-Fold Cross Validation\", font_size=28, color=BLUE)\n title_small.to_corner(UL, buff=0.3)\n \n with self.voiceover(text=\"Let's visualize this powerful model evaluation technique step by step.\") as tracker:\n self.play(Transform(title, title_small), run_time=tracker.duration)\n \n # Section 1: The Problem with Simple Train-Test Split\n problem_title = Text(\"The Problem: Simple Train-Test Split\", font_size=32, color=RED)\n problem_title.next_to(title, DOWN, buff=0.8)\n \n with self.voiceover(text=\"First, let's understand the problem. With a simple train-test split, we randomly divide our data into training and testing sets.\") as tracker:\n self.play(FadeIn(problem_title), run_time=tracker.duration)\n \n # Create dataset representation\n data_rects = VGroup()\n colors = [BLUE, BLUE, BLUE, BLUE, BLUE, BLUE, BLUE, BLUE, BLUE, BLUE]\n for i in range(10):\n rect = Rectangle(height=0.6, width=0.5, fill_color=BLUE, fill_opacity=0.8, stroke_color=WHITE, stroke_width=2)\n data_rects.add(rect)\n \n data_rects.arrange(RIGHT, buff=0.1)\n data_rects.next_to(problem_title, DOWN, buff=0.5)\n \n dataset_label = Text(\"Dataset\", font_size=24, color=WHITE)\n dataset_label.next_to(data_rects, DOWN, buff=0.3)\n \n with self.voiceover(text=\"Here's our complete dataset, represented as individual data points.\") as tracker:\n self.play(FadeIn(data_rects), Write(dataset_label), run_time=tracker.duration)\n \n # Split into train and test\n train_rects = VGroup(*data_rects[:7])\n test_rects = VGroup(*data_rects[7:])\n \n with self.voiceover(text=\"We might use 70 percent for training.\") as tracker:\n self.play(\n train_rects.animate.set_fill(GREEN, opacity=0.8),\n run_time=tracker.duration * 0.5\n )\n \n train_label = Text(\"Train (70%)\", font_size=20, color=GREEN)\n train_label.next_to(train_rects, DOWN, buff=0.3)\n \n with self.voiceover(text=\"And 30 percent for testing.\") as tracker:\n self.play(\n test_rects.animate.set_fill(RED, opacity=0.8),\n FadeIn(train_label),\n run_time=tracker.duration * 0.5\n )\n \n test_label = Text(\"Test (30%)\", font_size=20, color=RED)\n test_label.next_to(test_rects, DOWN, buff=0.3)\n self.play(FadeIn(test_label))\n \n # Problem highlight\n problem_text = Text(\"Problem: What if the split is unlucky?\", font_size=24, color=YELLOW)\n problem_text.next_to(data_rects, DOWN, buff=1.2)\n \n with self.voiceover(text=\"But here's the problem. What if our random split is unlucky? The test set might not be representative, giving us a misleading performance score.\") as tracker:\n self.play(FadeIn(problem_text), run_time=tracker.duration)\n \n self.wait(0.5)\n \n # Fade out problem section\n with self.voiceover(text=\"K-Fold Cross Validation solves this issue.\") as tracker:\n self.play(\n FadeOut(problem_title),\n FadeOut(data_rects),\n FadeOut(dataset_label),\n FadeOut(train_label),\n FadeOut(test_label),\n FadeOut(problem_text),\n run_time=tracker.duration\n )\n \n # Section 2: Introducing K-Fold\n kfold_title = Text(\"K-Fold Cross Validation\", font_size=32, color=GREEN)\n kfold_title.next_to(title, DOWN, buff=0.8)\n \n with self.voiceover(text=\"In K-Fold Cross Validation, we divide the dataset into K equal parts, called folds.\") as tracker:\n self.play(FadeIn(kfold_title), run_time=tracker.duration)\n \n # K formula\n k_formula = MathTex(r\"K = \\text{number of folds}\", font_size=36, color=YELLOW)\n k_formula.next_to(kfold_title, DOWN, buff=0.5)\n \n with self.voiceover(text=\"K represents the number of folds we want to create.\") as tracker:\n self.play(Write(k_formula), run_time=tracker.duration)\n \n self.wait(0.3)\n \n # Create 5-fold example\n fold_groups = VGroup()\n fold_colors = [BLUE, GREEN, YELLOW, ORANGE, PURPLE]\n \n for fold_idx in range(5):\n fold_rects = VGroup()\n for i in range(2): # 2 samples per fold for visualization\n rect = Rectangle(height=0.5, width=0.4, fill_color=fold_colors[fold_idx], \n fill_opacity=0.8, stroke_color=WHITE, stroke_width=1)\n fold_rects.add(rect)\n fold_rects.arrange(RIGHT, buff=0.05)\n \n # Add fold label\n fold_label = Text(f\"Fold {fold_idx + 1}\", font_size=16, color=fold_colors[fold_idx])\n fold_label.next_to(fold_rects, LEFT, buff=0.2)\n fold_group = VGroup(fold_label, fold_rects)\n fold_groups.add(fold_group)\n \n fold_groups.arrange(DOWN, buff=0.2)\n fold_groups.next_to(k_formula, DOWN, buff=0.5)\n \n with self.voiceover(text=\"Let's use 5-fold cross validation as an example. We split our data into 5 folds.\") as tracker:\n self.play(FadeIn(fold_groups), run_time=tracker.duration)\n \n self.wait(0.3)\n \n # Section 3: The Process\n process_title = Text(\"The Process: Each Fold Takes a Turn\", font_size=28, color=WHITE)\n process_title.next_to(fold_groups, DOWN, buff=0.5)\n \n with self.voiceover(text=\"Now comes the key insight. Each fold takes a turn being the validation set, while the remaining folds form the training set.\") as tracker:\n self.play(FadeIn(process_title), run_time=tracker.duration)\n \n self.wait(0.3)\n \n # Show iterations\n training_formula = MathTex(r\"\\text{Training Set} = \\text{Total Dataset} \\setminus \\text{Validation Set}\", \n font_size=28, color=WHITE)\n training_formula.to_edge(DOWN, buff=0.5)\n \n with self.voiceover(text=\"The training set is everything except the current validation fold.\") as tracker:\n self.play(Write(training_formula), run_time=tracker.duration)\n \n self.wait(0.5)\n \n # Animate each iteration\n for iteration in range(5):\n # Reset all folds to original colors\n for fold_idx, fold_group in enumerate(fold_groups):\n fold_rects = fold_group[1]\n for rect in fold_rects:\n rect.set_fill(fold_colors[fold_idx], opacity=0.8)\n \n # Highlight validation fold\n val_fold = fold_groups[iteration]\n val_rects = val_fold[1]\n \n iteration_text = Text(f\"Iteration {iteration + 1}: Fold {iteration + 1} is Validation\", \n font_size=22, color=RED)\n iteration_text.next_to(process_title, DOWN, buff=0.3)\n \n with self.voiceover(text=f\"In iteration {iteration + 1}, Fold {iteration + 1} becomes our validation set, shown in red.\") as tracker:\n self.play(\n val_rects.animate.set_fill(RED, opacity=1.0),\n FadeIn(iteration_text),\n run_time=tracker.duration * 0.6\n )\n \n # Highlight training folds\n train_folds = VGroup(*[fold_groups[i] for i in range(5) if i != iteration])\n \n with self.voiceover(text=f\"All other folds are combined to form the training set, shown in green.\") as tracker:\n self.play(\n *[fold_groups[i][1].animate.set_fill(GREEN, opacity=0.8) for i in range(5) if i != iteration],\n run_time=tracker.duration * 0.4\n )\n \n self.wait(0.3)\n \n if iteration < 4:\n with self.voiceover(text=\"We train the model and record the validation score.\") as tracker:\n self.play(FadeOut(iteration_text), run_time=tracker.duration)\n else:\n score_text = Text(\"Score Recorded\", font_size=18, color=YELLOW)\n score_text.next_to(val_fold, RIGHT, buff=0.5)\n with self.voiceover(text=\"We train the model and record the validation score.\") as tracker:\n self.play(FadeIn(score_text), run_time=tracker.duration)\n self.wait(0.3)\n self.play(FadeOut(iteration_text), FadeOut(score_text))\n \n self.wait(0.3)\n \n # Section 4: Final Result\n with self.voiceover(text=\"After all iterations, we have 5 different performance scores.\") as tracker:\n self.play(\n FadeOut(kfold_title),\n FadeOut(k_formula),\n FadeOut(fold_groups),\n FadeOut(process_title),\n FadeOut(training_formula),\n run_time=tracker.duration\n )\n \n result_title = Text(\"Final Result: Average the Scores\", font_size=32, color=GREEN)\n result_title.next_to(title, DOWN, buff=0.8)\n \n with self.voiceover(text=\"The final step is to average all the validation scores.\") as tracker:\n self.play(FadeIn(result_title), run_time=tracker.duration)\n \n # Show scores\n scores = VGroup()\n for i in range(5):\n score = MathTex(f\"Score_{{{i+1}}}\", font_size=32, color=fold_colors[i])\n scores.add(score)\n \n scores.arrange(RIGHT, buff=0.4)\n scores.next_to(result_title, DOWN, buff=0.5)\n \n with self.voiceover(text=\"Here are the scores from each of the 5 iterations.\") as tracker:\n self.play(FadeIn(scores), run_time=tracker.duration)\n \n # Show average formula\n avg_formula = MathTex(r\"\\text{Final Score} = \\frac{1}{K} \\sum_{i=1}^{K} \\text{Score}_i\", \n font_size=36, color=YELLOW)\n avg_formula.next_to(scores, DOWN, buff=0.6)\n \n with self.voiceover(text=\"We compute the mean of all scores to get our final performance estimate.\") as tracker:\n self.play(Write(avg_formula), run_time=tracker.duration)\n \n self.wait(0.5)\n \n # Benefits section\n benefits_title = Text(\"Benefits of K-Fold Cross Validation\", font_size=28, color=BLUE)\n benefits_title.next_to(avg_formula, DOWN, buff=0.6)\n \n with self.voiceover(text=\"K-Fold Cross Validation has several key benefits.\") as tracker:\n self.play(FadeIn(benefits_title), run_time=tracker.duration)\n \n benefits = VGroup(\n Text(\"✓ More robust performance estimate\", font_size=22, color=WHITE),\n Text(\"✓ Uses all data for both training and validation\", font_size=22, color=WHITE),\n Text(\"✓ Reduces variance in performance metrics\", font_size=22, color=WHITE),\n Text(\"✓ Better for small datasets\", font_size=22, color=WHITE)\n )\n benefits.arrange(DOWN, buff=0.25, aligned_edge=LEFT)\n benefits.next_to(benefits_title, DOWN, buff=0.4)\n \n with self.voiceover(text=\"It provides a more robust performance estimate, uses all data for both training and validation, reduces variance in our metrics, and works especially well for small datasets.\") as tracker:\n self.play(FadeIn(benefits), run_time=tracker.duration)\n \n self.wait(1)\n \n # Conclusion\n with self.voiceover(text=\"And that's K-Fold Cross Validation, a powerful technique for reliable model evaluation!\") as tracker:\n self.play(\n FadeOut(result_title),\n FadeOut(scores),\n FadeOut(avg_formula),\n FadeOut(benefits_title),\n FadeOut(benefits),\n run_time=tracker.duration * 0.5\n )\n \n # Summary\n summary = VGroup(\n Text(\"Summary:\", font_size=28, color=BLUE),\n Text(\"1. Split data into K folds\", font_size=22, color=WHITE),\n Text(\"2. Each fold is validation once\", font_size=22, color=WHITE),\n Text(\"3. Average all validation scores\", font_size=22, color=WHITE)\n )\n summary.arrange(DOWN, buff=0.3, aligned_edge=LEFT)\n summary.move_to(ORIGIN)\n \n with self.voiceover(text=\"To summarize: split your data into K folds, let each fold be the validation set once, and average all the scores for a reliable performance estimate.\") as tracker:\n self.play(FadeIn(summary), run_time=tracker.duration)\n \n self.wait(2)\n \n # Fade everything out\n self.play(FadeOut(summary), FadeOut(title))\n```", "rejected": "```python\nfrom manim import *\nfrom manim_voiceover import VoiceoverScene\nfrom manim_voiceover.services.gtts import GTTSService\n\n\nclass KFoldVisualization(VoiceoverScene):\n def construct(self):\n self.set_speech_service(\n GTTSService(voice=\"alba\", cache_dir=\"voiceover_cache\")\n )\n \n # Title\n title = Text(\"K-Fold Cross Validation\", font_size=48, color=BLUE)\n title\n \n with self.voiceover(text=\"Imagine you're training a machine learning model and want to know how well it's going to perform on real data. Wouldn't it be great if you could simulate this performance effectively? That's where K-Fold Cross Validation comes into play!\") as tracker:\n self.play(Write(title), run_time=tracker.duration)\n \n self.wait(0.5)\n \n # Clear title and move to corner\n title_small = Text(\"K-Fold Cross Validation\", font_size=28, color=BLUE)\n title_small\n \n with self.voiceover(text=\"Let's visualize this powerful model evaluation technique step by step.\") as tracker:\n self.play(Transform(title, title_small), run_time=tracker.duration)\n \n # Section 1: The Problem with Simple Train-Test Split\n problem_title = Text(\"The Problem: Simple Train-Test Split\", font_size=32, color=RED)\n problem_title\n \n with self.voiceover(text=\"First, let's understand the problem. With a simple train-test split, we randomly divide our data into training and testing sets.\") as tracker:\n self.play(FadeIn(problem_title), run_time=tracker.duration)\n \n # Create dataset representation\n data_rects = VGroup()\n colors = [BLUE, BLUE, BLUE, BLUE, BLUE, BLUE, BLUE, BLUE, BLUE, BLUE]\n for i in range(10):\n rect = Rectangle(height=0.6, width=0.5, fill_color=BLUE, fill_opacity=0.8, stroke_color=WHITE, stroke_width=2)\n data_rects.add(rect)\n \n data_rects.arrange(RIGHT, buff=0.1)\n data_rects.next_to(problem_title, DOWN, buff=0.5)\n \n dataset_label = Text(\"Dataset\", font_size=24, color=WHITE)\n dataset_label.next_to(data_rects, DOWN, buff=0.3)\n \n with self.voiceover(text=\"Here's our complete dataset, represented as individual data points.\") as tracker:\n self.play(FadeIn(data_rects), Write(dataset_label), run_time=tracker.duration)\n \n # Split into train and test\n train_rects = VGroup(*data_rects[:7])\n test_rects = VGroup(*data_rects[7:])\n \n with self.voiceover(text=\"We might use 70 percent for training.\") as tracker:\n self.play(\n train_rects.animate.set_fill(GREEN, opacity=0.8),\n run_time=tracker.duration * 0.5\n )\n \n train_label = Text(\"Train (70%)\", font_size=20, color=GREEN)\n train_label.next_to(train_rects, DOWN, buff=0.3)\n \n with self.voiceover(text=\"And 30 percent for testing.\") as tracker:\n self.play(\n test_rects.animate.set_fill(RED, opacity=0.8),\n FadeIn(train_label),\n run_time=tracker.duration * 0.5\n )\n \n test_label = Text(\"Test (30%)\", font_size=20, color=RED)\n test_label.next_to(test_rects, DOWN, buff=0.3)\n self.play(FadeIn(test_label))\n \n # Problem highlight\n problem_text = Text(\"Problem: What if the split is unlucky?\", font_size=24, color=YELLOW)\n problem_text.next_to(data_rects, DOWN, buff=1.2)\n \n with self.voiceover(text=\"But here's the problem. What if our random split is unlucky? The test set might not be representative, giving us a misleading performance score.\") as tracker:\n self.play(FadeIn(problem_text), run_time=tracker.duration)\n \n self.wait(0.5)\n \n # Fade out problem section\n with self.voiceover(text=\"K-Fold Cross Validation solves this issue.\") as tracker:\n self.play(\n FadeOut(problem_title),\n FadeOut(data_rects),\n FadeOut(dataset_label),\n FadeOut(train_label),\n FadeOut(test_label),\n FadeOut(problem_text),\n run_time=tracker.duration\n )\n \n # Section 2: Introducing K-Fold\n kfold_title = Text(\"K-Fold Cross Validation\", font_size=32, color=GREEN)\n kfold_title.next_to(title, DOWN, buff=0.8)\n \n with self.voiceover(text=\"In K-Fold Cross Validation, we divide the dataset into K equal parts, called folds.\") as tracker:\n self.play(FadeIn(kfold_title), run_time=tracker.duration)\n \n # K formula\n k_formula = MathTex(r\"K = \\text{number of folds}\", font_size=36, color=YELLOW)\n k_formula.next_to(kfold_title, DOWN, buff=0.5)\n \n with self.voiceover(text=\"K represents the number of folds we want to create.\") as tracker:\n self.play(Write(k_formula), run_time=tracker.duration)\n \n self.wait(0.3)\n \n # Create 5-fold example\n fold_groups = VGroup()\n fold_colors = [BLUE, GREEN, YELLOW, ORANGE, PURPLE]\n \n for fold_idx in range(5):\n fold_rects = VGroup()\n for i in range(2): # 2 samples per fold for visualization\n rect = Rectangle(height=0.5, width=0.4, fill_color=fold_colors[fold_idx], \n fill_opacity=0.8, stroke_color=WHITE, stroke_width=1)\n fold_rects.add(rect)\n fold_rects.arrange(RIGHT, buff=0.05)\n \n # Add fold label\n fold_label = Text(f\"Fold {fold_idx + 1}\", font_size=16, color=fold_colors[fold_idx])\n fold_label.next_to(fold_rects, LEFT, buff=0.2)\n fold_group = VGroup(fold_label, fold_rects)\n fold_groups.add(fold_group)\n \n fold_groups.arrange(DOWN, buff=0.2)\n fold_groups.next_to(k_formula, DOWN, buff=0.5)\n \n with self.voiceover(text=\"Let's use 5-fold cross validation as an example. We split our data into 5 folds.\") as tracker:\n self.play(FadeIn(fold_groups), run_time=tracker.duration)\n \n self.wait(0.3)\n \n # Section 3: The Process\n process_title = Text(\"The Process: Each Fold Takes a Turn\", font_size=28, color=WHITE)\n process_title.next_to(fold_groups, DOWN, buff=0.5)\n \n with self.voiceover(text=\"Now comes the key insight. Each fold takes a turn being the validation set, while the remaining folds form the training set.\") as tracker:\n self.play(FadeIn(process_title), run_time=tracker.duration)\n \n self.wait(0.3)\n \n # Show iterations\n training_formula = MathTex(r\"\\text{Training Set} = \\text{Total Dataset} \\setminus \\text{Validation Set}\", \n font_size=28, color=WHITE)\n training_formula.to_edge(DOWN, buff=0.5)\n \n with self.voiceover(text=\"The training set is everything except the current validation fold.\") as tracker:\n self.play(Write(training_formula), run_time=tracker.duration)\n \n self.wait(0.5)\n \n # Animate each iteration\n for iteration in range(5):\n # Reset all folds to original colors\n for fold_idx, fold_group in enumerate(fold_groups):\n fold_rects = fold_group[1]\n for rect in fold_rects:\n rect.set_fill(fold_colors[fold_idx], opacity=0.8)\n \n # Highlight validation fold\n val_fold = fold_groups[iteration]\n val_rects = val_fold[1]\n \n iteration_text = Text(f\"Iteration {iteration + 1}: Fold {iteration + 1} is Validation\", \n font_size=22, color=RED)\n iteration_text.next_to(process_title, DOWN, buff=0.3)\n \n with self.voiceover(text=f\"In iteration {iteration + 1}, Fold {iteration + 1} becomes our validation set, shown in red.\") as tracker:\n self.play(\n val_rects.animate.set_fill(RED, opacity=1.0),\n FadeIn(iteration_text),\n run_time=tracker.duration * 0.6\n )\n \n # Highlight training folds\n train_folds = VGroup(*[fold_groups[i] for i in range(5) if i != iteration])\n \n with self.voiceover(text=f\"All other folds are combined to form the training set, shown in green.\") as tracker:\n self.play(\n *[fold_groups[i][1].animate.set_fill(GREEN, opacity=0.8) for i in range(5) if i != iteration],\n run_time=tracker.duration * 0.4\n )\n \n self.wait(0.3)\n \n if iteration < 4:\n with self.voiceover(text=\"We train the model and record the validation score.\") as tracker:\n self.play(FadeOut(iteration_text), run_time=tracker.duration)\n else:\n score_text = Text(\"Score Recorded\", font_size=18, color=YELLOW)\n score_text.next_to(val_fold, RIGHT, buff=0.5)\n with self.voiceover(text=\"We train the model and record the validation score.\") as tracker:\n self.play(FadeIn(score_text), run_time=tracker.duration)\n self.wait(0.3)\n self.play(FadeOut(iteration_text), FadeOut(score_text))\n \n self.wait(0.3)\n \n # Section 4: Final Result\n with self.voiceover(text=\"After all iterations, we have 5 different performance scores.\") as tracker:\n self.play(\n FadeOut(kfold_title),\n FadeOut(k_formula),\n FadeOut(fold_groups),\n FadeOut(process_title),\n FadeOut(training_formula),\n run_time=tracker.duration\n )\n \n result_title = Text(\"Final Result: Average the Scores\", font_size=32, color=GREEN)\n result_title.next_to(title, DOWN, buff=0.8)\n \n with self.voiceover(text=\"The final step is to average all the validation scores.\") as tracker:\n self.play(FadeIn(result_title), run_time=tracker.duration)\n \n # Show scores\n scores = VGroup()\n for i in range(5):\n score = MathTex(f\"Score_{{{i+1}}}\", font_size=32, color=fold_colors[i])\n scores.add(score)\n \n scores.arrange(RIGHT, buff=0.4)\n scores.next_to(result_title, DOWN, buff=0.5)\n \n with self.voiceover(text=\"Here are the scores from each of the 5 iterations.\") as tracker:\n self.play(FadeIn(scores), run_time=tracker.duration)\n \n # Show average formula\n avg_formula = MathTex(r\"\\text{Final Score} = \\frac{1}{K} \\sum_{i=1}^{K} \\text{Score}_i\", \n font_size=36, color=YELLOW)\n avg_formula.next_to(scores, DOWN, buff=0.6)\n \n with self.voiceover(text=\"We compute the mean of all scores to get our final performance estimate.\") as tracker:\n self.play(Write(avg_formula), run_time=tracker.duration)\n \n self.wait(0.5)\n \n # Benefits section\n benefits_title = Text(\"Benefits of K-Fold Cross Validation\", font_size=28, color=BLUE)\n benefits_title.next_to(avg_formula, DOWN, buff=0.6)\n \n with self.voiceover(text=\"K-Fold Cross Validation has several key benefits.\") as tracker:\n self.play(FadeIn(benefits_title), run_time=tracker.duration)\n \n benefits = VGroup(\n Text(\"✓ More robust performance estimate\", font_size=22, color=WHITE),\n Text(\"✓ Uses all data for both training and validation\", font_size=22, color=WHITE),\n Text(\"✓ Reduces variance in performance metrics\", font_size=22, color=WHITE),\n Text(\"✓ Better for small datasets\", font_size=22, color=WHITE)\n )\n benefits.arrange(DOWN, buff=0.25, aligned_edge=LEFT)\n benefits.next_to(benefits_title, DOWN, buff=0.4)\n \n with self.voiceover(text=\"It provides a more robust performance estimate, uses all data for both training and validation, reduces variance in our metrics, and works especially well for small datasets.\") as tracker:\n self.play(FadeIn(benefits), run_time=tracker.duration)\n \n self.wait(1)\n \n # Conclusion\n with self.voiceover(text=\"And that's K-Fold Cross Validation, a powerful technique for reliable model evaluation!\") as tracker:\n self.play(\n FadeOut(result_title),\n FadeOut(scores),\n FadeOut(avg_formula),\n FadeOut(benefits_title),\n FadeOut(benefits),\n run_time=tracker.duration * 0.5\n )\n \n # Summary\n summary = VGroup(\n Text(\"Summary:\", font_size=28, color=BLUE),\n Text(\"1. Split data into K folds\", font_size=22, color=WHITE),\n Text(\"2. Each fold is validation once\", font_size=22, color=WHITE),\n Text(\"3. Average all validation scores\", font_size=22, color=WHITE)\n )\n summary.arrange(DOWN, buff=0.3, aligned_edge=LEFT)\n summary.move_to(ORIGIN)\n \n with self.voiceover(text=\"To summarize: split your data into K folds, let each fold be the validation set once, and average all the scores for a reliable performance estimate.\") as tracker:\n self.play(FadeIn(summary), run_time=tracker.duration)\n \n self.wait(2)\n \n # Fade everything out\n self.play(FadeOut(summary), FadeOut(title))\n```", "category": "spatial_layout_overlap", "source": "synthetic_hard_neg:nabin2004/AOS-Narrated-Manim-400"} +{"system": "You are an expert Manim Community Edition (ManimCE v0.19+) Python developer and mathematical animator. Given a user request, first plan the spatial layout, coordinate bounds, timing, and pedagogical flow inside ... tags (when reasoning is helpful), and then output a complete, runnable, self-contained ManimCE Python script using `from manim import *`. Never use deprecated ManimGL (`manimlib`) methods like `ShowCreation`, `TexMobject`, `TextMobject`, or `axes.get_graph`; always use modern ManimCE APIs (`Create`, `MathTex`, `Tex`, `Text`, `axes.plot`) and prevent visual overlap using `.to_edge()`, `.next_to()`, and `FadeOut`.", "prompt": "Create an interactive Manim CE animation demonstrating: Tangent line dynamically tracking curve f(x) = x^2. Use updaters and ValueTracker.\n\n```python\nfrom manim import *\nimport numpy as np\n\nclass DynamicScene41(Scene):\n def construct(self):\n ax = Axes(x_range=[-3, 3, 1], y_range=[0, 9, 3], x_length=6, y_length=4)\n curve = ax.plot(lambda x: x**2, color=BLUE)\n t = ValueTracker(1.0)\n dot = always_redraw(lambda: Dot(ax.c2p(t.get_value(), t.get_value()**2), color=RED))\n tangent = always_redraw(lambda: ax.get_secant_slope_group(\n t.get_value(), curve, dx=0.01, dx_line_color=YELLOW, secant_line_length=3, secant_line_color=YELLOW\n ))\n num = DecimalNumber(0, num_decimal_places=2, color=YELLOW).to_corner(UR)\n num.add_updater(lambda m: m.set_value(t.get_value()))\n \n self.add(ax, curve, dot, tangent, num)\n self.play(t.animate.set_value(2.5), run_time=3)\n self.play(t.animate.set_value(-2.0), run_time=3)\n```", "chosen": "```python\nfrom manim import *\nfrom manim_voiceover import VoiceoverScene\nfrom manim_voiceover.services.gtts import GTTSService\n\nMARGIN = 0.5\n\nclass DynamicTangentScene(VoiceoverScene):\n def fit_in_frame(self, mob: Mobject, w_frac=0.9, h_frac=0.9) -> Mobject:\n max_w = config.frame_width * w_frac\n max_h = config.frame_height * h_frac\n if mob.width > max_w:\n mob.width = max_w\n if mob.height > max_h:\n mob.height = max_h\n return mob\n\n def construct(self):\n self.set_speech_service(GTTSService(transcription_model=\"base\"))\n \n # [SETUP]\n title = Title(r\"Tangent Line to $f(x) = x^2$\", buff=MARGIN)\n ax = Axes(x_range=[-3, 3, 1], y_range=[0, 9, 3], x_length=6, y_length=4)\n curve = ax.plot(lambda x: x**2, color=BLUE)\n t = ValueTracker(1.0)\n \n dot = always_redraw(lambda: Dot(ax.c2p(t.get_value(), t.get_value()**2), color=RED))\n \n def get_tangent():\n x_val = t.get_value()\n y_val = x_val**2\n slope = 2 * x_val\n p1 = ax.c2p(x_val - 1, y_val - slope)\n p2 = ax.c2p(x_val + 1, y_val + slope)\n return Line(p1, p2, color=YELLOW)\n \n tangent = always_redraw(get_tangent)\n num = DecimalNumber(0, num_decimal_places=2, color=YELLOW).to_corner(UR, buff=MARGIN)\n num.add_updater(lambda m: m.set_value(t.get_value()))\n \n # [LAYOUT]\n main_group = self.fit_in_frame(VGroup(title, ax, curve, dot, tangent, num))\n self.add(main_group)\n \n # [UPDATER]\n # Defined above with always_redraw\n \n # [BEAT 1 | sync: b1]\n with self.voiceover(text=\"We visualize the tangent line to a parabola. \") as t_voice:\n self.wait_until_bookmark(\"b1\")\n self.wait(1)\n \n # [BEAT 2 | sync: b2]\n with self.voiceover(text=\"As the point moves along the curve, the tangent line dynamically adjusts its slope to match the derivative. This illustrates the geometric meaning of the derivative.\") as t_voice:\n self.wait_until_bookmark(\"b2\")\n self.play(t.animate.set_value(2.5), run_time=3)\n self.play(t.animate.set_value(-2.0), run_time=3)\n```", "rejected": "```python\nfrom manim import *\nfrom manim_voiceover import VoiceoverScene\nfrom manim_voiceover.services.gtts import GTTSService\n\nMARGIN = 0.5\n\nclass DynamicTangentScene(VoiceoverScene):\n def fit_in_frame(self, mob: Mobject, w_frac=0.9, h_frac=0.9) -> Mobject:\n max_w = config.frame_width * w_frac\n max_h = config.frame_height * h_frac\n if mob.width > max_w:\n mob.width = max_w\n if mob.height > max_h:\n mob.height = max_h\n return mob\n\n def construct(self):\n self.set_speech_service(GTTSService(transcription_model=\"base\"))\n \n # [SETUP]\n title = Title(r\"Tangent Line to $f(x) = x^2$\", buff=MARGIN)\n ax = Axes(axis_color=BLUE, x_range=[-3, 3, 1], y_range=[0, 9, 3], x_length=6, y_length=4)\n curve = ax.plot(lambda x: x**2, color=BLUE)\n t = ValueTracker(1.0)\n \n dot = always_redraw(lambda: Dot(ax.c2p(t.get_value(), t.get_value()**2), color=RED))\n \n def get_tangent():\n x_val = t.get_value()\n y_val = x_val**2\n slope = 2 * x_val\n p1 = ax.c2p(x_val - 1, y_val - slope)\n p2 = ax.c2p(x_val + 1, y_val + slope)\n return Line(p1, p2, color=YELLOW)\n \n tangent = always_redraw(get_tangent)\n num = DecimalNumber(0, num_decimal_places=2, color=YELLOW).to_corner(UR, buff=MARGIN)\n num.add_updater(lambda m: m.set_value(t.get_value()))\n \n # [LAYOUT]\n main_group = self.fit_in_frame(VGroup(title, ax, curve, dot, tangent, num))\n self.add(main_group)\n \n # [UPDATER]\n # Defined above with always_redraw\n \n # [BEAT 1 | sync: b1]\n with self.voiceover(text=\"We visualize the tangent line to a parabola. \") as t_voice:\n self.wait_until_bookmark(\"b1\")\n self.wait(1)\n \n # [BEAT 2 | sync: b2]\n with self.voiceover(text=\"As the point moves along the curve, the tangent line dynamically adjusts its slope to match the derivative. This illustrates the geometric meaning of the derivative.\") as t_voice:\n self.wait_until_bookmark(\"b2\")\n self.play(t.animate.set_value(2.5), run_time=3)\n self.play(t.animate.set_value(-2.0), run_time=3)\n```", "category": "invalid_axes_kwarg", "source": "synthetic_hard_neg:nabin2004/qwen3-8b-manimator-gold-sft"} +{"system": "You are an expert Manim Community Edition (ManimCE v0.19+) Python developer and mathematical animator. Given a user request, first plan the spatial layout, coordinate bounds, timing, and pedagogical flow inside ... tags (when reasoning is helpful), and then output a complete, runnable, self-contained ManimCE Python script using `from manim import *`. Never use deprecated ManimGL (`manimlib`) methods like `ShowCreation`, `TexMobject`, `TextMobject`, or `axes.get_graph`; always use modern ManimCE APIs (`Create`, `MathTex`, `Tex`, `Text`, `axes.plot`) and prevent visual overlap using `.to_edge()`, `.next_to()`, and `FadeOut`.", "prompt": "Create a step-by-step educational Manim CE lecture scene explaining: Proof of Pythagorean Theorem via geometric rearrangement.\n\n```python\nfrom manim import *\nimport numpy as np\n\nclass PedagogicalScene31(Scene):\n def construct(self):\n title = Title(\"Pythagorean Theorem: $a^2 + b^2 = c^2$\")\n formula = MathTex(r\"a^2 + b^2 = c^2\", color=YELLOW).next_to(title, DOWN, buff=0.5)\n tri = Polygon(ORIGIN, RIGHT * 3, RIGHT * 3 + UP * 2, color=BLUE, fill_opacity=0.4)\n brace_a = Brace(Line(ORIGIN, RIGHT * 3), direction=DOWN)\n label_a = MathTex(\"a\").next_to(brace_a, DOWN)\n brace_b = Brace(Line(RIGHT * 3, RIGHT * 3 + UP * 2), direction=RIGHT)\n label_b = MathTex(\"b\").next_to(brace_b, RIGHT)\n hyp = Line(ORIGIN, RIGHT * 3 + UP * 2, color=GOLD)\n label_c = MathTex(\"c\", color=GOLD).next_to(hyp.get_center(), UL)\n \n self.play(Write(title))\n self.play(Create(tri), FadeIn(brace_a, label_a), FadeIn(brace_b, label_b), Create(hyp), Write(label_c))\n self.wait(1)\n self.play(Write(formula))\n self.wait(2)\n```", "chosen": "```python\nfrom manim import *\nfrom manim_voiceover import VoiceoverScene\nfrom manim_voiceover.services.gtts import GTTSService\nimport numpy as np\n\nMARGIN = 0.5\n\nclass PedagogicalScene31(VoiceoverScene):\n def fit_in_frame(self, mob: Mobject, w_frac=0.9, h_frac=0.9) -> Mobject:\n max_w = config.frame_width * w_frac\n max_h = config.frame_height * h_frac\n if mob.width > max_w:\n mob.width = max_w\n if mob.height > max_h:\n mob.height = max_h\n return mob\n\n def construct(self):\n self.set_speech_service(GTTSService(transcription_model=\"base\"))\n \n # [SETUP]\n title = Title(\"Pythagorean Theorem: $a^2 + b^2 = c^2$\")\n formula = MathTex(r\"a^2 + b^2 = c^2\", color=YELLOW).next_to(title, DOWN, buff=0.5)\n tri = Polygon(ORIGIN, RIGHT * 3, RIGHT * 3 + UP * 2, color=BLUE, fill_opacity=0.4)\n brace_a = Brace(Line(ORIGIN, RIGHT * 3), direction=DOWN)\n label_a = MathTex(\"a\").next_to(brace_a, DOWN)\n brace_b = Brace(Line(RIGHT * 3, RIGHT * 3 + UP * 2), direction=RIGHT)\n label_b = MathTex(\"b\").next_to(brace_b, RIGHT)\n hyp = Line(ORIGIN, RIGHT * 3 + UP * 2, color=GOLD)\n label_c = MathTex(\"c\", color=GOLD).next_to(hyp.get_center(), UL)\n \n # [LAYOUT]\n group = VGroup(title, formula, tri, brace_a, label_a, brace_b, label_b, hyp, label_c)\n group = self.fit_in_frame(group)\n self.add(title)\n \n # [UPDATER]\n # [BEAT 1 | sync: b1]\n with self.voiceover(text=\"We construct a right triangle with sides a, b, and hypotenuse c. \") as t:\n self.wait_until_bookmark(\"b1\")\n self.play(Create(tri), FadeIn(brace_a, label_a), FadeIn(brace_b, label_b), Create(hyp), Write(label_c))\n self.wait(1)\n \n # [BEAT 2 | sync: b2]\n with self.voiceover(text=\"The Pythagorean theorem states that a squared plus b squared equals c squared. \") as t:\n self.wait_until_bookmark(\"b2\")\n self.play(Write(formula))\n self.wait(2)\n```", "rejected": "```python\nfrom manim import *\nfrom manim_voiceover import VoiceoverScene\nfrom manim_voiceover.services.gtts import GTTSService\nimport numpy as np\n\nMARGIN = 0.5\n\nclass PedagogicalScene31(VoiceoverScene):\n def fit_in_frame(self, mob: Mobject, w_frac=0.9, h_frac=0.9) -> Mobject:\n max_w = config.frame_width * w_frac\n max_h = config.frame_height * h_frac\n if mob.width > max_w:\n mob.width = max_w\n if mob.height > max_h:\n mob.height = max_h\n return mob\n\n def construct(self):\n self.set_speech_service(GTTSService(transcription_model=\"base\"))\n \n # [SETUP]\n title = Title(\"Pythagorean Theorem: $a^2 + b^2 = c^2$\")\n formula = MathTex(r\"a^2 + b^2 = c^2\", color=YELLOW)\n tri = Polygon(ORIGIN, RIGHT * 3, RIGHT * 3 + UP * 2, color=BLUE, fill_opacity=0.4)\n brace_a = Brace(Line(ORIGIN, RIGHT * 3), direction=DOWN)\n label_a = MathTex(\"a\")\n brace_b = Brace(Line(RIGHT * 3, RIGHT * 3 + UP * 2), direction=RIGHT)\n label_b = MathTex(\"b\")\n hyp = Line(ORIGIN, RIGHT * 3 + UP * 2, color=GOLD)\n label_c = MathTex(\"c\", color=GOLD).next_to(hyp.get_center(), UL)\n \n # [LAYOUT]\n group = VGroup(title, formula, tri, brace_a, label_a, brace_b, label_b, hyp, label_c)\n group = self.fit_in_frame(group)\n self.add(title)\n \n # [UPDATER]\n # [BEAT 1 | sync: b1]\n with self.voiceover(text=\"We construct a right triangle with sides a, b, and hypotenuse c. \") as t:\n self.wait_until_bookmark(\"b1\")\n self.play(Create(tri), FadeIn(brace_a, label_a), FadeIn(brace_b, label_b), Create(hyp), Write(label_c))\n self.wait(1)\n \n # [BEAT 2 | sync: b2]\n with self.voiceover(text=\"The Pythagorean theorem states that a squared plus b squared equals c squared. \") as t:\n self.wait_until_bookmark(\"b2\")\n self.play(Write(formula))\n self.wait(2)\n```", "category": "spatial_layout_overlap", "source": "synthetic_hard_neg:nabin2004/qwen3-8b-manimator-gold-sft"} +{"system": "You are an expert Manim Community Edition (ManimCE v0.19+) Python developer and mathematical animator. Given a user request, first plan the spatial layout, coordinate bounds, timing, and pedagogical flow inside ... tags (when reasoning is helpful), and then output a complete, runnable, self-contained ManimCE Python script using `from manim import *`. Never use deprecated ManimGL (`manimlib`) methods like `ShowCreation`, `TexMobject`, `TextMobject`, or `axes.get_graph`; always use modern ManimCE APIs (`Create`, `MathTex`, `Tex`, `Text`, `axes.plot`) and prevent visual overlap using `.to_edge()`, `.next_to()`, and `FadeOut`.", "prompt": "Create a Manim animation for an advanced chemistry class explaining the electromeric effect in conjugated systems. The video should be 16:9 format.\n\nStart with a title slide displaying \"Conjugated Systems and the Electromeric Effect\" in the center. Below it, add a subtitle \"Electron Shift in Organic Molecules.\"\n\nNext, show the question on screen: \"Provide an example of a molecule that exhibits the electromeric effect.\" Display this as if it's being read from a worksheet, with clear typography.\n\nThen, introduce the concept of conjugated systems. Show the structure of 1,3-butadiene with alternating single and double bonds highlighted in different colors. Animate arrows showing how pi-electrons can delocalize across the conjugated system. Include a brief text explanation: \"Conjugated systems have alternating single and double bonds allowing electron delocalization.\"\n\nTransition to explaining the electromeric effect with an animation showing electron movement. Display the nitrobenzene molecule structure on the left side of the screen. Highlight the nitro group (NO₂) with a box or arrow. Then animate temporary electron shifts within the molecule using colored arrows pointing toward and away from the nitro group. Include text that reads: \"The electromeric effect: temporary electron shift due to a multiple bond.\"\n\nFinally, reveal the answer at the bottom of the screen: \"Nitrobenzene is an example of a molecule exhibiting the electromeric effect. The nitro group causes temporary electron shifts, influencing reactivity and stability.\"\n\nEnd with a summary slide listing the three examples mentioned: 1,3-butadiene, aniline, and nitrobenzene.", "chosen": "```python\nfrom manim import *\nimport numpy as np\nimport random\nimport math\n\nclass ElectromericEffectScene(Scene):\n def construct(self):\n # --- SCENE 1: TITLE (0-6s) ---\n title = Text(\"Conjugated Systems and\\nthe Electromeric Effect\", font_size=48, line_spacing=1.2)\n title.to_edge(UP, buff=1.0)\n \n subtitle = Text(\"Electron Shift in Organic Molecules\", font_size=32, color=BLUE)\n subtitle.next_to(title, DOWN, buff=0.5)\n\n self.play(Write(title), run_time=2.0)\n self.play(FadeIn(subtitle), run_time=1.5)\n self.wait(2.5)\n \n self.play(\n FadeOut(title),\n FadeOut(subtitle),\n run_time=1.0\n )\n\n # --- SCENE 2: QUESTION (6-12s) ---\n question_header = Text(\"Worksheet Question:\", font_size=36, color=YELLOW)\n question_header.to_edge(UP, buff=1.0)\n \n question_text = Text(\n \"Provide an example of a molecule that\\nexhibits the electromeric effect.\",\n font_size=32,\n t2c={\"electromeric effect\": ORANGE}\n )\n question_text.next_to(question_header, DOWN, buff=0.5)\n\n self.play(FadeIn(question_header), run_time=1.0)\n self.play(Write(question_text), run_time=2.0)\n self.wait(3.0)\n\n self.play(\n FadeOut(question_header),\n FadeOut(question_text),\n run_time=1.0\n )\n\n # --- SCENE 3: CONJUGATED SYSTEMS (1,3-BUTADIENE) (12-32s) ---\n # Concept Text\n concept_title = Text(\"Conjugated Systems\", font_size=42, color=GREEN)\n concept_title.to_edge(UP, buff=0.5)\n \n concept_desc = Text(\n \"Alternating single and double bonds allow\\npi-electrons to delocalize.\",\n font_size=28\n )\n concept_desc.next_to(concept_title, DOWN, buff=0.4)\n\n self.play(Write(concept_title), FadeIn(concept_desc), run_time=1.5)\n\n # Butadiene Structure: CH2=CH-CH=CH2\n # Building visually\n c1_text = MathTex(r\"CH_2\").scale(1.2)\n db1 = DoubleArrow(start=LEFT, end=RIGHT, stroke_width=4, buff=0, tip_length=0).scale(0.5)\n # Hack to make double bond look like =\n db1_line1 = Line(LEFT*0.4, RIGHT*0.4, color=BLUE).shift(UP*0.08)\n db1_line2 = Line(LEFT*0.4, RIGHT*0.4, color=BLUE).shift(DOWN*0.08)\n db1_group = VGroup(db1_line1, db1_line2)\n \n c2_text = MathTex(r\"CH\").scale(1.2)\n sb_line = Line(LEFT*0.4, RIGHT*0.4, color=WHITE)\n c3_text = MathTex(r\"CH\").scale(1.2)\n \n db2_line1 = Line(LEFT*0.4, RIGHT*0.4, color=BLUE).shift(UP*0.08)\n db2_line2 = Line(LEFT*0.4, RIGHT*0.4, color=BLUE).shift(DOWN*0.08)\n db2_group = VGroup(db2_line1, db2_line2)\n \n c4_text = MathTex(r\"CH_2\").scale(1.2)\n\n # Arrange\n molecule_group = VGroup(\n c1_text, db1_group, c2_text, sb_line, c3_text, db2_group, c4_text\n ).arrange(RIGHT, buff=0.2)\n \n molecule_group.move_to(ORIGIN).shift(DOWN*0.5)\n \n label_butadiene = Text(\"1,3-Butadiene\", font_size=24, color=GRAY)\n label_butadiene.next_to(molecule_group, DOWN, buff=0.5)\n\n self.play(Create(molecule_group), run_time=2.0)\n self.play(FadeIn(label_butadiene), run_time=1.0)\n self.wait(1.0)\n\n # Arrows showing delocalization\n # Arrow from first double bond to single bond\n arrow1 = CurvedArrow(\n start_point=db1_group.get_top() + UP*0.1,\n end_point=sb_line.get_top() + UP*0.1,\n angle=-TAU/4,\n color=YELLOW\n )\n \n # Arrow from second double bond to end (showing movement)\n arrow2 = CurvedArrow(\n start_point=db2_group.get_top() + UP*0.1,\n end_point=c4_text.get_top() + UP*0.1 + RIGHT*0.2,\n angle=-TAU/4,\n color=YELLOW\n )\n\n self.play(Create(arrow1), Create(arrow2), run_time=1.5)\n self.wait(2.0)\n \n # Explanation of delocalization\n deloc_text = Text(\"Pi-electrons spread across the system\", font_size=24, color=YELLOW)\n deloc_text.next_to(arrow1, UP, buff=0.2)\n self.play(Write(deloc_text), run_time=1.0)\n self.wait(3.0)\n\n # Clean up Scene 3\n self.play(\n FadeOut(concept_title), FadeOut(concept_desc),\n FadeOut(molecule_group), FadeOut(label_butadiene),\n FadeOut(arrow1), FadeOut(arrow2), FadeOut(deloc_text),\n run_time=1.0\n )\n\n # --- SCENE 4: ELECTROMERIC EFFECT (NITROBENZENE) (32-62s) ---\n \n e_effect_title = Text(\"The Electromeric Effect\", font_size=42, color=ORANGE)\n e_effect_title.to_edge(UP, buff=0.5)\n \n e_effect_def = Text(\"Temporary electron shift due to a multiple bond\", font_size=28)\n e_effect_def.next_to(e_effect_title, DOWN, buff=0.4)\n \n self.play(FadeIn(e_effect_title), Write(e_effect_def), run_time=1.5)\n\n # Draw Nitrobenzene\n # Benzene Ring\n hex_points = [\n [np.sin(i*TAU/6), np.cos(i*TAU/6), 0] for i in range(6)\n ]\n benzene = Polygon(*hex_points, color=WHITE).scale(1.2)\n \n # Double bonds inside benzene\n b_bond1 = Line(hex_points[0], hex_points[1]).scale(0.7).shift(LEFT*0.15 + DOWN*0.1) # Top right\n b_bond2 = Line(hex_points[2], hex_points[3]).scale(0.7).shift(UP*0.2) # Bottom\n b_bond3 = Line(hex_points[4], hex_points[5]).scale(0.7).shift(RIGHT*0.15 + DOWN*0.1) # Top left\n \n inner_bonds = VGroup(b_bond1, b_bond2, b_bond3).set_color(BLUE).scale(1.2).move_to(benzene.get_center())\n benzene_group = VGroup(benzene, inner_bonds)\n\n # Nitro Group\n n_pos = benzene.get_vertices()[0] # Top point (index 0 is usually right or top depending on rotation)\n # Adjust hex points logic: sin(0)=0, cos(0)=1 -> Top point is index 0\n top_vertex = benzene.get_vertices()[0]\n \n nitro_bond = Line(top_vertex, top_vertex + UP*1.0, color=WHITE)\n n_atom = Text(\"N\", font_size=36).move_to(nitro_bond.get_end())\n \n # O atoms\n o_left_bond = Line(n_atom.get_center(), n_atom.get_center() + UL*0.8, color=BLUE) # Double bond\n o_left_bond2 = Line(n_atom.get_center(), n_atom.get_center() + UL*0.8, color=BLUE).shift(LEFT*0.05+DOWN*0.05)\n o_left = Text(\"O\", font_size=36).move_to(o_left_bond.get_end())\n \n o_right_bond = Line(n_atom.get_center(), n_atom.get_center() + UR*0.8, color=WHITE)\n o_right = Text(\"O\", font_size=36).move_to(o_right_bond.get_end())\n \n nitro_group = VGroup(nitro_bond, n_atom, o_left_bond, o_left_bond2, o_left, o_right_bond, o_right)\n \n full_molecule = VGroup(benzene_group, nitro_group)\n full_molecule.move_to(LEFT * 2.5 + DOWN * 0.5)\n \n mol_label = Text(\"Nitrobenzene\", font_size=28, color=GRAY)\n mol_label.next_to(full_molecule, DOWN, buff=0.5)\n \n self.play(Create(full_molecule), FadeIn(mol_label), run_time=2.0)\n \n # Highlight Nitro Group\n highlight_box = SurroundingRectangle(nitro_group, color=YELLOW, buff=0.2)\n highlight_label = Text(\"Nitro Group (-NO₂)\", font_size=24, color=YELLOW)\n highlight_label.next_to(highlight_box, RIGHT, buff=0.3)\n \n self.play(Create(highlight_box), Write(highlight_label), run_time=1.5)\n self.wait(1.0)\n self.play(FadeOut(highlight_box), FadeOut(highlight_label), run_time=0.5)\n\n # Animate Electron Shifts\n # Arrow from ring to C-N bond\n shift_arrow1 = CurvedArrow(\n start_point=top_vertex + DOWN*0.5 + RIGHT*0.2, # Approx inside ring near top\n end_point=nitro_bond.get_center() + RIGHT*0.2,\n angle=TAU/6,\n color=RED\n )\n \n # Arrow from N=O to O\n shift_arrow2 = CurvedArrow(\n start_point=o_left_bond.get_center() + RIGHT*0.1,\n end_point=o_left.get_center() + DOWN*0.2,\n angle=TAU/6,\n color=RED\n )\n \n # Description on right\n desc_group = VGroup(\n Text(\"Electron withdrawing group\", font_size=24, color=RED),\n Text(\"causes electrons to shift\", font_size=24),\n Text(\"towards itself.\", font_size=24)\n ).arrange(DOWN, aligned_edge=LEFT)\n desc_group.next_to(full_molecule, RIGHT, buff=1.5).shift(UP*0.5)\n\n self.play(Create(shift_arrow1), Create(shift_arrow2), run_time=1.5)\n self.play(Write(desc_group), run_time=2.0)\n \n # Pulse the arrows to emphasize effect\n self.play(\n shift_arrow1.animate.set_stroke(width=6),\n shift_arrow2.animate.set_stroke(width=6),\n run_time=0.5\n )\n self.play(\n shift_arrow1.animate.set_stroke(width=4),\n shift_arrow2.animate.set_stroke(width=4),\n run_time=0.5\n )\n self.wait(2.0)\n\n # Clean up Scene 4\n self.play(\n FadeOut(full_molecule), FadeOut(mol_label),\n FadeOut(shift_arrow1), FadeOut(shift_arrow2),\n FadeOut(desc_group), FadeOut(e_effect_title), FadeOut(e_effect_def),\n run_time=1.0\n )\n\n # --- SCENE 5: ANSWER (62-77s) ---\n answer_title = Text(\"The Answer\", font_size=36, color=GREEN)\n answer_title.to_edge(UP, buff=1.5)\n \n answer_body = Text(\n \"Nitrobenzene is an example of a molecule\\n\"\n \"exhibiting the electromeric effect.\",\n font_size=32,\n t2c={\"Nitrobenzene\": BLUE}\n )\n answer_body.move_to(ORIGIN)\n \n answer_detail = Text(\n \"The nitro group causes temporary electron shifts,\\n\"\n \"influencing reactivity and stability.\",\n font_size=28,\n color=GRAY_B\n )\n answer_detail.next_to(answer_body, DOWN, buff=0.8)\n\n self.play(Write(answer_title), run_time=1.0)\n self.play(FadeIn(answer_body), run_time=1.5)\n self.wait(1.0)\n self.play(Write(answer_detail), run_time=2.0)\n self.wait(3.0)\n\n self.play(\n FadeOut(answer_title),\n FadeOut(answer_body),\n FadeOut(answer_detail),\n run_time=1.0\n )\n\n # --- SCENE 6: SUMMARY (77-90s) ---\n summary_title = Text(\"Summary: Key Examples\", font_size=42)\n summary_title.to_edge(UP, buff=1.0)\n\n # List items\n item1 = Text(\"1. 1,3-Butadiene (Conjugated)\", font_size=32)\n item2 = Text(\"2. Aniline (Resonance/Electromeric)\", font_size=32)\n item3 = Text(\"3. Nitrobenzene (Electron Withdrawing)\", font_size=32)\n\n summary_list = VGroup(item1, item2, item3).arrange(DOWN, aligned_edge=LEFT, buff=0.6)\n summary_list.move_to(ORIGIN)\n\n self.play(Write(summary_title), run_time=1.0)\n \n # Staggered reveal\n for item in summary_list:\n self.play(FadeIn(item, shift=RIGHT), run_time=0.8)\n self.wait(0.2)\n \n self.wait(3.0)\n \n # Final fadeout\n self.play(FadeOut(summary_title), FadeOut(summary_list), run_time=1.0)\n```", "rejected": "```python\nfrom manim import *\nimport numpy as np\nimport random\nimport math\n\nclass ElectromericEffectScene(Scene):\n def construct(self):\n # --- SCENE 1: TITLE (0-6s) ---\n title = Text(\"Conjugated Systems and\\nthe Electromeric Effect\", font_size=48, line_spacing=1.2)\n title\n \n subtitle = Text(\"Electron Shift in Organic Molecules\", font_size=32, color=BLUE)\n subtitle\n\n self.play(Write(title), run_time=2.0)\n self.play(FadeIn(subtitle), run_time=1.5)\n self.wait(2.5)\n \n self.play(\n FadeOut(title),\n FadeOut(subtitle),\n run_time=1.0\n )\n\n # --- SCENE 2: QUESTION (6-12s) ---\n question_header = Text(\"Worksheet Question:\", font_size=36, color=YELLOW)\n question_header\n \n question_text = Text(\n \"Provide an example of a molecule that\\nexhibits the electromeric effect.\",\n font_size=32,\n t2c={\"electromeric effect\": ORANGE}\n )\n question_text.next_to(question_header, DOWN, buff=0.5)\n\n self.play(FadeIn(question_header), run_time=1.0)\n self.play(Write(question_text), run_time=2.0)\n self.wait(3.0)\n\n self.play(\n FadeOut(question_header),\n FadeOut(question_text),\n run_time=1.0\n )\n\n # --- SCENE 3: CONJUGATED SYSTEMS (1,3-BUTADIENE) (12-32s) ---\n # Concept Text\n concept_title = Text(\"Conjugated Systems\", font_size=42, color=GREEN)\n concept_title.to_edge(UP, buff=0.5)\n \n concept_desc = Text(\n \"Alternating single and double bonds allow\\npi-electrons to delocalize.\",\n font_size=28\n )\n concept_desc.next_to(concept_title, DOWN, buff=0.4)\n\n self.play(Write(concept_title), FadeIn(concept_desc), run_time=1.5)\n\n # Butadiene Structure: CH2=CH-CH=CH2\n # Building visually\n c1_text = MathTex(r\"CH_2\").scale(1.2)\n db1 = DoubleArrow(start=LEFT, end=RIGHT, stroke_width=4, buff=0, tip_length=0).scale(0.5)\n # Hack to make double bond look like =\n db1_line1 = Line(LEFT*0.4, RIGHT*0.4, color=BLUE).shift(UP*0.08)\n db1_line2 = Line(LEFT*0.4, RIGHT*0.4, color=BLUE).shift(DOWN*0.08)\n db1_group = VGroup(db1_line1, db1_line2)\n \n c2_text = MathTex(r\"CH\").scale(1.2)\n sb_line = Line(LEFT*0.4, RIGHT*0.4, color=WHITE)\n c3_text = MathTex(r\"CH\").scale(1.2)\n \n db2_line1 = Line(LEFT*0.4, RIGHT*0.4, color=BLUE).shift(UP*0.08)\n db2_line2 = Line(LEFT*0.4, RIGHT*0.4, color=BLUE).shift(DOWN*0.08)\n db2_group = VGroup(db2_line1, db2_line2)\n \n c4_text = MathTex(r\"CH_2\").scale(1.2)\n\n # Arrange\n molecule_group = VGroup(\n c1_text, db1_group, c2_text, sb_line, c3_text, db2_group, c4_text\n ).arrange(RIGHT, buff=0.2)\n \n molecule_group.move_to(ORIGIN).shift(DOWN*0.5)\n \n label_butadiene = Text(\"1,3-Butadiene\", font_size=24, color=GRAY)\n label_butadiene.next_to(molecule_group, DOWN, buff=0.5)\n\n self.play(Create(molecule_group), run_time=2.0)\n self.play(FadeIn(label_butadiene), run_time=1.0)\n self.wait(1.0)\n\n # Arrows showing delocalization\n # Arrow from first double bond to single bond\n arrow1 = CurvedArrow(\n start_point=db1_group.get_top() + UP*0.1,\n end_point=sb_line.get_top() + UP*0.1,\n angle=-TAU/4,\n color=YELLOW\n )\n \n # Arrow from second double bond to end (showing movement)\n arrow2 = CurvedArrow(\n start_point=db2_group.get_top() + UP*0.1,\n end_point=c4_text.get_top() + UP*0.1 + RIGHT*0.2,\n angle=-TAU/4,\n color=YELLOW\n )\n\n self.play(Create(arrow1), Create(arrow2), run_time=1.5)\n self.wait(2.0)\n \n # Explanation of delocalization\n deloc_text = Text(\"Pi-electrons spread across the system\", font_size=24, color=YELLOW)\n deloc_text.next_to(arrow1, UP, buff=0.2)\n self.play(Write(deloc_text), run_time=1.0)\n self.wait(3.0)\n\n # Clean up Scene 3\n self.play(\n FadeOut(concept_title), FadeOut(concept_desc),\n FadeOut(molecule_group), FadeOut(label_butadiene),\n FadeOut(arrow1), FadeOut(arrow2), FadeOut(deloc_text),\n run_time=1.0\n )\n\n # --- SCENE 4: ELECTROMERIC EFFECT (NITROBENZENE) (32-62s) ---\n \n e_effect_title = Text(\"The Electromeric Effect\", font_size=42, color=ORANGE)\n e_effect_title.to_edge(UP, buff=0.5)\n \n e_effect_def = Text(\"Temporary electron shift due to a multiple bond\", font_size=28)\n e_effect_def.next_to(e_effect_title, DOWN, buff=0.4)\n \n self.play(FadeIn(e_effect_title), Write(e_effect_def), run_time=1.5)\n\n # Draw Nitrobenzene\n # Benzene Ring\n hex_points = [\n [np.sin(i*TAU/6), np.cos(i*TAU/6), 0] for i in range(6)\n ]\n benzene = Polygon(*hex_points, color=WHITE).scale(1.2)\n \n # Double bonds inside benzene\n b_bond1 = Line(hex_points[0], hex_points[1]).scale(0.7).shift(LEFT*0.15 + DOWN*0.1) # Top right\n b_bond2 = Line(hex_points[2], hex_points[3]).scale(0.7).shift(UP*0.2) # Bottom\n b_bond3 = Line(hex_points[4], hex_points[5]).scale(0.7).shift(RIGHT*0.15 + DOWN*0.1) # Top left\n \n inner_bonds = VGroup(b_bond1, b_bond2, b_bond3).set_color(BLUE).scale(1.2).move_to(benzene.get_center())\n benzene_group = VGroup(benzene, inner_bonds)\n\n # Nitro Group\n n_pos = benzene.get_vertices()[0] # Top point (index 0 is usually right or top depending on rotation)\n # Adjust hex points logic: sin(0)=0, cos(0)=1 -> Top point is index 0\n top_vertex = benzene.get_vertices()[0]\n \n nitro_bond = Line(top_vertex, top_vertex + UP*1.0, color=WHITE)\n n_atom = Text(\"N\", font_size=36).move_to(nitro_bond.get_end())\n \n # O atoms\n o_left_bond = Line(n_atom.get_center(), n_atom.get_center() + UL*0.8, color=BLUE) # Double bond\n o_left_bond2 = Line(n_atom.get_center(), n_atom.get_center() + UL*0.8, color=BLUE).shift(LEFT*0.05+DOWN*0.05)\n o_left = Text(\"O\", font_size=36).move_to(o_left_bond.get_end())\n \n o_right_bond = Line(n_atom.get_center(), n_atom.get_center() + UR*0.8, color=WHITE)\n o_right = Text(\"O\", font_size=36).move_to(o_right_bond.get_end())\n \n nitro_group = VGroup(nitro_bond, n_atom, o_left_bond, o_left_bond2, o_left, o_right_bond, o_right)\n \n full_molecule = VGroup(benzene_group, nitro_group)\n full_molecule.move_to(LEFT * 2.5 + DOWN * 0.5)\n \n mol_label = Text(\"Nitrobenzene\", font_size=28, color=GRAY)\n mol_label.next_to(full_molecule, DOWN, buff=0.5)\n \n self.play(Create(full_molecule), FadeIn(mol_label), run_time=2.0)\n \n # Highlight Nitro Group\n highlight_box = SurroundingRectangle(nitro_group, color=YELLOW, buff=0.2)\n highlight_label = Text(\"Nitro Group (-NO₂)\", font_size=24, color=YELLOW)\n highlight_label.next_to(highlight_box, RIGHT, buff=0.3)\n \n self.play(Create(highlight_box), Write(highlight_label), run_time=1.5)\n self.wait(1.0)\n self.play(FadeOut(highlight_box), FadeOut(highlight_label), run_time=0.5)\n\n # Animate Electron Shifts\n # Arrow from ring to C-N bond\n shift_arrow1 = CurvedArrow(\n start_point=top_vertex + DOWN*0.5 + RIGHT*0.2, # Approx inside ring near top\n end_point=nitro_bond.get_center() + RIGHT*0.2,\n angle=TAU/6,\n color=RED\n )\n \n # Arrow from N=O to O\n shift_arrow2 = CurvedArrow(\n start_point=o_left_bond.get_center() + RIGHT*0.1,\n end_point=o_left.get_center() + DOWN*0.2,\n angle=TAU/6,\n color=RED\n )\n \n # Description on right\n desc_group = VGroup(\n Text(\"Electron withdrawing group\", font_size=24, color=RED),\n Text(\"causes electrons to shift\", font_size=24),\n Text(\"towards itself.\", font_size=24)\n ).arrange(DOWN, aligned_edge=LEFT)\n desc_group.next_to(full_molecule, RIGHT, buff=1.5).shift(UP*0.5)\n\n self.play(Create(shift_arrow1), Create(shift_arrow2), run_time=1.5)\n self.play(Write(desc_group), run_time=2.0)\n \n # Pulse the arrows to emphasize effect\n self.play(\n shift_arrow1.animate.set_stroke(width=6),\n shift_arrow2.animate.set_stroke(width=6),\n run_time=0.5\n )\n self.play(\n shift_arrow1.animate.set_stroke(width=4),\n shift_arrow2.animate.set_stroke(width=4),\n run_time=0.5\n )\n self.wait(2.0)\n\n # Clean up Scene 4\n self.play(\n FadeOut(full_molecule), FadeOut(mol_label),\n FadeOut(shift_arrow1), FadeOut(shift_arrow2),\n FadeOut(desc_group), FadeOut(e_effect_title), FadeOut(e_effect_def),\n run_time=1.0\n )\n\n # --- SCENE 5: ANSWER (62-77s) ---\n answer_title = Text(\"The Answer\", font_size=36, color=GREEN)\n answer_title.to_edge(UP, buff=1.5)\n \n answer_body = Text(\n \"Nitrobenzene is an example of a molecule\\n\"\n \"exhibiting the electromeric effect.\",\n font_size=32,\n t2c={\"Nitrobenzene\": BLUE}\n )\n answer_body.move_to(ORIGIN)\n \n answer_detail = Text(\n \"The nitro group causes temporary electron shifts,\\n\"\n \"influencing reactivity and stability.\",\n font_size=28,\n color=GRAY_B\n )\n answer_detail.next_to(answer_body, DOWN, buff=0.8)\n\n self.play(Write(answer_title), run_time=1.0)\n self.play(FadeIn(answer_body), run_time=1.5)\n self.wait(1.0)\n self.play(Write(answer_detail), run_time=2.0)\n self.wait(3.0)\n\n self.play(\n FadeOut(answer_title),\n FadeOut(answer_body),\n FadeOut(answer_detail),\n run_time=1.0\n )\n\n # --- SCENE 6: SUMMARY (77-90s) ---\n summary_title = Text(\"Summary: Key Examples\", font_size=42)\n summary_title.to_edge(UP, buff=1.0)\n\n # List items\n item1 = Text(\"1. 1,3-Butadiene (Conjugated)\", font_size=32)\n item2 = Text(\"2. Aniline (Resonance/Electromeric)\", font_size=32)\n item3 = Text(\"3. Nitrobenzene (Electron Withdrawing)\", font_size=32)\n\n summary_list = VGroup(item1, item2, item3).arrange(DOWN, aligned_edge=LEFT, buff=0.6)\n summary_list.move_to(ORIGIN)\n\n self.play(Write(summary_title), run_time=1.0)\n \n # Staggered reveal\n for item in summary_list:\n self.play(FadeIn(item, shift=RIGHT), run_time=0.8)\n self.wait(0.2)\n \n self.wait(3.0)\n \n # Final fadeout\n self.play(FadeOut(summary_title), FadeOut(summary_list), run_time=1.0)\n```", "category": "spatial_layout_overlap", "source": "synthetic_hard_neg:nabin2004/manim-sft-10k"} +{"system": "You are an expert Manim Community Edition (ManimCE v0.19+) Python developer and mathematical animator. Given a user request, first plan the spatial layout, coordinate bounds, timing, and pedagogical flow inside ... tags (when reasoning is helpful), and then output a complete, runnable, self-contained ManimCE Python script using `from manim import *`. Never use deprecated ManimGL (`manimlib`) methods like `ShowCreation`, `TexMobject`, `TextMobject`, or `axes.get_graph`; always use modern ManimCE APIs (`Create`, `MathTex`, `Tex`, `Text`, `axes.plot`) and prevent visual overlap using `.to_edge()`, `.next_to()`, and `FadeOut`.", "prompt": "I'm learning MATLAB's Deep Learning Toolbox and want to visualize a CNN training on a toy dataset. Show the network architecture, data flow, and the evolving loss/accuracy with live plots. Demonstrate how to modify layers, apply data augmentation, and export a short training storyboard. Include 3D plots of feature maps and annotated timelines of hyperparameter changes.", "chosen": "```python\nfrom manim import *\nfrom manim_voiceover import VoiceoverScene\nfrom manim_voiceover.services.gtts import GTTSService\n\nclass CNNTrainingVisualizationMATLAB(VoiceoverScene):\n def construct(self):\n # Set up speech service\n self.set_speech_service(\n GTTSService(voice=\"alba\", cache_dir=\"voiceover_cache\")\n )\n \n # Title scene\n title = Text(\"CNN Training Visualization in MATLAB\", font_size=48, color=BLUE)\n subtitle = Text(\"Understanding Deep Learning Training\", font_size=28, color=GRAY)\n subtitle.next_to(title, DOWN, buff=0.5)\n \n with self.voiceover(text=\"Have you ever wondered how a Convolutional Neural Network learns from images?\") as tracker:\n self.play(Write(title), run_time=tracker.duration * 0.6)\n self.play(FadeIn(subtitle), run_time=tracker.duration * 0.4)\n \n self.wait(0.5)\n \n with self.voiceover(text=\"Picture this: with each epoch, your model is adjusting its filters and weights, gradually improving its ability to recognize patterns.\") as tracker:\n self.play(\n title.animate.scale(0.5).to_corner(UL),\n FadeOut(subtitle),\n run_time=tracker.duration\n )\n \n # Introduction to CNN\n cnn_text = Text(\"Convolutional Neural Network\", font_size=32, color=YELLOW)\n cnn_text.next_to(title, DOWN, buff=0.3)\n \n with self.voiceover(text=\"But how do we visualize this complex process effectively? Today, you will explore exactly how to see the training of a CNN unfold in real-time using MATLAB.\") as tracker:\n self.play(Write(cnn_text), run_time=tracker.duration)\n \n self.wait(0.3)\n \n # Clear for architecture diagram\n self.play(FadeOut(cnn_text))\n \n # CNN Architecture Visualization\n with self.voiceover(text=\"A CNN consists of multiple layers. First, convolutional layers extract features from input images using learnable filters.\") as tracker:\n # Input Image\n input_box = Rectangle(width=1.5, height=1.5, fill_color=BLUE_E, fill_opacity=0.8)\n input_label = Text(\"Input Image\", font_size=18).next_to(input_box, DOWN, buff=0.2)\n input_group = VGroup(input_box, input_label)\n input_group.shift(LEFT * 5)\n \n # Conv Layer 1\n conv1_box = Rectangle(width=1.2, height=1.2, fill_color=GREEN_E, fill_opacity=0.8)\n conv1_label = Text(\"Conv Layer 1\", font_size=16).next_to(conv1_box, DOWN, buff=0.2)\n conv1_group = VGroup(conv1_box, conv1_label)\n conv1_group.shift(LEFT * 2.5)\n \n # Arrow 1\n arrow1 = Arrow(input_box.get_right(), conv1_box.get_left(), buff=0.3, color=WHITE)\n \n self.play(Create(input_group), run_time=tracker.duration * 0.3)\n self.play(Create(arrow1), run_time=tracker.duration * 0.2)\n self.play(Create(conv1_group), run_time=tracker.duration * 0.5)\n \n # Pooling layer\n with self.voiceover(text=\"Then pooling layers reduce spatial dimensions while preserving important features.\") as tracker:\n pool_box = Rectangle(width=1, height=1, fill_color=ORANGE, fill_opacity=0.8)\n pool_label = Text(\"Pooling\", font_size=16).next_to(pool_box, DOWN, buff=0.2)\n pool_group = VGroup(pool_box, pool_label)\n pool_group.shift(LEFT * 0.3)\n \n arrow2 = Arrow(conv1_box.get_right(), pool_box.get_left(), buff=0.3, color=WHITE)\n \n self.play(Create(arrow2), run_time=tracker.duration * 0.3)\n self.play(Create(pool_group), run_time=tracker.duration * 0.7)\n \n # More conv layers\n with self.voiceover(text=\"Additional convolutional layers extract higher-level features, building a hierarchical representation.\") as tracker:\n conv2_box = Rectangle(width=0.9, height=0.9, fill_color=GREEN_D, fill_opacity=0.8)\n conv2_label = Text(\"Conv Layer 2\", font_size=14).next_to(conv2_box, DOWN, buff=0.15)\n conv2_group = VGroup(conv2_box, conv2_label)\n conv2_group.shift(RIGHT * 1.8)\n \n arrow3 = Arrow(pool_box.get_right(), conv2_box.get_left(), buff=0.3, color=WHITE)\n \n self.play(Create(arrow3), run_time=tracker.duration * 0.3)\n self.play(Create(conv2_group), run_time=tracker.duration * 0.7)\n \n # Fully connected\n with self.voiceover(text=\"Finally, fully connected layers perform classification based on the extracted features.\") as tracker:\n fc_box = Rectangle(width=0.8, height=0.8, fill_color=RED_E, fill_opacity=0.8)\n fc_label = Text(\"FC Layer\", font_size=14).next_to(fc_box, DOWN, buff=0.15)\n fc_group = VGroup(fc_box, fc_label)\n fc_group.shift(RIGHT * 3.8)\n \n arrow4 = Arrow(conv2_box.get_right(), fc_box.get_left(), buff=0.3, color=WHITE)\n \n # Output\n output_box = Rectangle(width=0.6, height=0.6, fill_color=PURPLE_E, fill_opacity=0.8)\n output_label = Text(\"Output\", font_size=14).next_to(output_box, DOWN, buff=0.15)\n output_group = VGroup(output_box, output_label)\n output_group.shift(RIGHT * 5.5)\n \n arrow5 = Arrow(fc_box.get_right(), output_box.get_left(), buff=0.3, color=WHITE)\n \n self.play(Create(arrow4), Create(fc_group), run_time=tracker.duration * 0.5)\n self.play(Create(arrow5), Create(output_group), run_time=tracker.duration * 0.5)\n \n self.wait(0.5)\n \n # Fade out architecture\n all_architecture = VGroup(\n input_group, arrow1, conv1_group, arrow2, pool_group,\n arrow3, conv2_group, arrow4, fc_group, arrow5, output_group\n )\n \n with self.voiceover(text=\"During training, these layers learn by adjusting weights through backpropagation.\") as tracker:\n self.play(FadeOut(all_architecture), run_time=tracker.duration)\n \n # Training metrics visualization\n with self.voiceover(text=\"Now let us see how to visualize the training process in MATLAB.\") as tracker:\n matlab_label = Text(\"MATLAB Training Monitor\", font_size=32, color=BLUE)\n matlab_label.next_to(title, DOWN, buff=0.5)\n self.play(Write(matlab_label), run_time=tracker.duration)\n \n # Create axes for loss curve\n with self.voiceover(text=\"The training progress window shows loss decreasing over epochs.\") as tracker:\n axes1 = Axes(\n x_range=[0, 10, 1],\n y_range=[0, 2, 0.5],\n x_length=5,\n y_length=3,\n axis_config={\"include_tip\": False, \"font_size\": 16},\n )\n axes1.shift(LEFT * 2.5 + DOWN * 0.5)\n \n loss_label = Text(\"Training Loss\", font_size=20, color=RED)\n loss_label.next_to(axes1, UP, buff=0.2)\n \n x_label1 = Text(\"Epochs\", font_size=14).next_to(axes1.x_axis, DOWN, buff=0.2)\n y_label1 = Text(\"Loss\", font_size=14).next_to(axes1.y_axis, LEFT, buff=0.2)\n \n self.play(\n Create(axes1),\n Write(loss_label),\n Write(x_label1),\n Write(y_label1),\n run_time=tracker.duration\n )\n \n # Loss curve animation\n with self.voiceover(text=\"Watch as the loss curve decreases, indicating the model is learning.\") as tracker:\n loss_curve = axes1.plot(\n lambda x: 1.8 * (0.7 ** x) + 0.2,\n x_range=[0, 10],\n color=RED,\n stroke_width=3\n )\n \n self.play(Create(loss_curve), run_time=tracker.duration)\n \n # Accuracy curve\n with self.voiceover(text=\"Similarly, the accuracy curve shows how well the model classifies images correctly.\") as tracker:\n axes2 = Axes(\n x_range=[0, 10, 1],\n y_range=[0, 100, 25],\n x_length=5,\n y_length=3,\n axis_config={\"include_tip\": False, \"font_size\": 16},\n )\n axes2.shift(RIGHT * 2.5 + DOWN * 0.5)\n \n acc_label = Text(\"Accuracy (%)\", font_size=20, color=GREEN)\n acc_label.next_to(axes2, UP, buff=0.2)\n \n x_label2 = Text(\"Epochs\", font_size=14).next_to(axes2.x_axis, DOWN, buff=0.2)\n y_label2 = Text(\"Accuracy\", font_size=14).next_to(axes2.y_axis, RIGHT, buff=0.2)\n \n acc_curve = axes2.plot(\n lambda x: 100 * (1 - 0.8 ** x),\n x_range=[0, 10],\n color=GREEN,\n stroke_width=3\n )\n \n self.play(\n Create(axes2),\n Write(acc_label),\n Write(x_label2),\n Write(y_label2),\n run_time=tracker.duration * 0.5\n )\n self.play(Create(acc_curve), run_time=tracker.duration * 0.5)\n \n self.wait(0.5)\n \n # MATLAB code snippet\n with self.voiceover(text=\"In MATLAB, you can use the trainingOptions function with the plots parameter set to training-progress.\") as tracker:\n # Clear curves\n self.play(\n FadeOut(matlab_label),\n FadeOut(axes1), FadeOut(loss_label), FadeOut(x_label1), FadeOut(y_label1),\n FadeOut(loss_curve),\n FadeOut(axes2), FadeOut(acc_label), FadeOut(x_label2), FadeOut(y_label2),\n FadeOut(acc_curve),\n run_time=tracker.duration * 0.3\n )\n \n # MATLAB code - using Text without problematic quotes\n code_lines = [\n \"options = trainingOptions('sgdm', ...\",\n \" 'MaxEpochs', 10, ...\",\n \" 'Plots', 'training-progress', ...\",\n \" 'Metrics', 'accuracy');\",\n \"\",\n \"net = trainNetwork(data, layers, options);\"\n ]\n \n code_box = Rectangle(\n width=8, height=3,\n fill_color=BLACK, fill_opacity=0.9,\n stroke_color=BLUE, stroke_width=2\n )\n code_box.shift(DOWN * 0.5)\n \n code_display = VGroup()\n for i, line in enumerate(code_lines):\n txt = Text(line, font_size=18, font=\"monospace\", color=WHITE)\n txt.shift(DOWN * 0.5 + UP * (0.8 - i * 0.4))\n code_display.add(txt)\n \n matlab_title = Text(\"MATLAB Code\", font_size=28, color=BLUE)\n matlab_title.next_to(code_box, UP, buff=0.3)\n \n self.play(\n Create(code_box),\n Write(matlab_title),\n run_time=tracker.duration * 0.4\n )\n self.play(Write(code_display), run_time=tracker.duration * 0.3)\n \n self.wait(0.5)\n \n # Learning outcomes\n with self.voiceover(text=\"By the end of this lesson, you will understand the training process of CNNs, visualize training metrics in real-time, and analyze model performance using MATLAB visualizations.\") as tracker:\n self.play(\n FadeOut(code_box),\n FadeOut(code_display),\n FadeOut(matlab_title),\n run_time=tracker.duration * 0.2\n )\n \n outcomes_title = Text(\"Learning Outcomes\", font_size=36, color=BLUE)\n outcomes_title.shift(UP * 2)\n \n outcome1 = Text(\"• Understand CNN training process\", font_size=24)\n outcome2 = Text(\"• Visualize metrics in real-time\", font_size=24)\n outcome3 = Text(\"• Analyze model performance in MATLAB\", font_size=24)\n \n outcomes = VGroup(outcome1, outcome2, outcome3)\n outcomes.arrange(DOWN, buff=0.5, aligned_edge=LEFT)\n outcomes.shift(LEFT * 1)\n \n self.play(Write(outcomes_title), run_time=tracker.duration * 0.3)\n self.play(Write(outcome1), run_time=tracker.duration * 0.25)\n self.play(Write(outcome2), run_time=tracker.duration * 0.25)\n self.play(Write(outcome3), run_time=tracker.duration * 0.3)\n \n self.wait(0.5)\n \n # Conclusion\n with self.voiceover(text=\"Start visualizing your CNN training in MATLAB today and gain deeper insights into your model's learning journey.\") as tracker:\n conclusion = Text(\"Start Training & Visualizing!\", font_size=32, color=GREEN)\n conclusion.next_to(outcomes, DOWN, buff=0.8)\n \n self.play(Write(conclusion), run_time=tracker.duration)\n \n self.wait(1)\n \n # Fade out everything\n self.play(\n FadeOut(title),\n FadeOut(outcomes_title),\n FadeOut(outcomes),\n FadeOut(conclusion),\n run_time=2\n )\n```", "rejected": "```python\nfrom manim import *\n\nclass CNNTrainingVisualizationMATLAB(Scene):\n\n def construct(self):\n title = Text('CNN Training Visualization in MATLAB', font_size=48, color=BLUE)\n subtitle = Text('Understanding Deep Learning Training', font_size=28, color=GRAY)\n subtitle.next_to(title, DOWN, buff=0.5)\n self.play(Write(title), run_time=2.0 * 0.6)\n self.play(FadeIn(subtitle), run_time=2.0 * 0.4)\n self.wait(0.5)\n self.play(title.animate.scale(0.5).to_corner(UL), FadeOut(subtitle), run_time=2.0)\n cnn_text = Text('Convolutional Neural Network', font_size=32, color=YELLOW)\n cnn_text.next_to(title, DOWN, buff=0.3)\n self.play(Write(cnn_text), run_time=2.0)\n self.wait(0.3)\n self.play(FadeOut(cnn_text))\n input_box = Rectangle(width=1.5, height=1.5, fill_color=BLUE_E, fill_opacity=0.8)\n input_label = Text('Input Image', font_size=18).next_to(input_box, DOWN, buff=0.2)\n input_group = VGroup(input_box, input_label)\n input_group.shift(LEFT * 5)\n conv1_box = Rectangle(width=1.2, height=1.2, fill_color=GREEN_E, fill_opacity=0.8)\n conv1_label = Text('Conv Layer 1', font_size=16).next_to(conv1_box, DOWN, buff=0.2)\n conv1_group = VGroup(conv1_box, conv1_label)\n conv1_group.shift(LEFT * 2.5)\n arrow1 = Arrow(input_box.get_right(), conv1_box.get_left(), buff=0.3, color=WHITE)\n self.play(Create(input_group), run_time=2.0 * 0.3)\n self.play(Create(arrow1), run_time=2.0 * 0.2)\n self.play(Create(conv1_group), run_time=2.0 * 0.5)\n pool_box = Rectangle(width=1, height=1, fill_color=ORANGE, fill_opacity=0.8)\n pool_label = Text('Pooling', font_size=16).next_to(pool_box, DOWN, buff=0.2)\n pool_group = VGroup(pool_box, pool_label)\n pool_group.shift(LEFT * 0.3)\n arrow2 = Arrow(conv1_box.get_right(), pool_box.get_left(), buff=0.3, color=WHITE)\n self.play(Create(arrow2), run_time=2.0 * 0.3)\n self.play(Create(pool_group), run_time=2.0 * 0.7)\n conv2_box = Rectangle(width=0.9, height=0.9, fill_color=GREEN_D, fill_opacity=0.8)\n conv2_label = Text('Conv Layer 2', font_size=14).next_to(conv2_box, DOWN, buff=0.15)\n conv2_group = VGroup(conv2_box, conv2_label)\n conv2_group.shift(RIGHT * 1.8)\n arrow3 = Arrow(pool_box.get_right(), conv2_box.get_left(), buff=0.3, color=WHITE)\n self.play(Create(arrow3), run_time=2.0 * 0.3)\n self.play(Create(conv2_group), run_time=2.0 * 0.7)\n fc_box = Rectangle(width=0.8, height=0.8, fill_color=RED_E, fill_opacity=0.8)\n fc_label = Text('FC Layer', font_size=14).next_to(fc_box, DOWN, buff=0.15)\n fc_group = VGroup(fc_box, fc_label)\n fc_group.shift(RIGHT * 3.8)\n arrow4 = Arrow(conv2_box.get_right(), fc_box.get_left(), buff=0.3, color=WHITE)\n output_box = Rectangle(width=0.6, height=0.6, fill_color=PURPLE_E, fill_opacity=0.8)\n output_label = Text('Output', font_size=14).next_to(output_box, DOWN, buff=0.15)\n output_group = VGroup(output_box, output_label)\n output_group.shift(RIGHT * 5.5)\n arrow5 = Arrow(fc_box.get_right(), output_box.get_left(), buff=0.3, color=WHITE)\n self.play(Create(arrow4), Create(fc_group), run_time=2.0 * 0.5)\n self.play(Create(arrow5), Create(output_group), run_time=2.0 * 0.5)\n self.wait(0.5)\n all_architecture = VGroup(input_group, arrow1, conv1_group, arrow2, pool_group, arrow3, conv2_group, arrow4, fc_group, arrow5, output_group)\n self.play(FadeOut(all_architecture), run_time=2.0)\n matlab_label = Text('MATLAB Training Monitor', font_size=32, color=BLUE)\n matlab_label.next_to(title, DOWN, buff=0.5)\n self.play(Write(matlab_label), run_time=2.0)\n axes1 = Axes(x_range=[0, 10, 1], y_range=[0, 2, 0.5], x_length=5, y_length=3, axis_config={'include_tip': False, 'font_size': 16})\n axes1.shift(LEFT * 2.5 + DOWN * 0.5)\n loss_label = Text('Training Loss', font_size=20, color=RED)\n loss_label.next_to(axes1, UP, buff=0.2)\n x_label1 = Text('Epochs', font_size=14).next_to(axes1.x_axis, DOWN, buff=0.2)\n y_label1 = Text('Loss', font_size=14).next_to(axes1.y_axis, LEFT, buff=0.2)\n self.play(Create(axes1), Write(loss_label), Write(x_label1), Write(y_label1), run_time=2.0)\n loss_curve = axes1.plot(lambda x: 1.8 * 0.7 ** x + 0.2, x_range=[0, 10], color=RED, stroke_width=3)\n self.play(Create(loss_curve), run_time=2.0)\n axes2 = Axes(x_range=[0, 10, 1], y_range=[0, 100, 25], x_length=5, y_length=3, axis_config={'include_tip': False, 'font_size': 16})\n axes2.shift(RIGHT * 2.5 + DOWN * 0.5)\n acc_label = Text('Accuracy (%)', font_size=20, color=GREEN)\n acc_label.next_to(axes2, UP, buff=0.2)\n x_label2 = Text('Epochs', font_size=14).next_to(axes2.x_axis, DOWN, buff=0.2)\n y_label2 = Text('Accuracy', font_size=14).next_to(axes2.y_axis, RIGHT, buff=0.2)\n acc_curve = axes2.plot(lambda x: 100 * (1 - 0.8 ** x), x_range=[0, 10], color=GREEN, stroke_width=3)\n self.play(Create(axes2), Write(acc_label), Write(x_label2), Write(y_label2), run_time=2.0 * 0.5)\n self.play(Create(acc_curve), run_time=2.0 * 0.5)\n self.wait(0.5)\n self.play(FadeOut(matlab_label), FadeOut(axes1), FadeOut(loss_label), FadeOut(x_label1), FadeOut(y_label1), FadeOut(loss_curve), FadeOut(axes2), FadeOut(acc_label), FadeOut(x_label2), FadeOut(y_label2), FadeOut(acc_curve), run_time=2.0 * 0.3)\n code_lines = [\"options = trainingOptions('sgdm', ...\", \" 'MaxEpochs', 10, ...\", \" 'Plots', 'training-progress', ...\", \" 'Metrics', 'accuracy');\", '', 'net = trainNetwork(data, layers, options);']\n code_box = Rectangle(width=8, height=3, fill_color=BLACK, fill_opacity=0.9, stroke_color=BLUE, stroke_width=2)\n code_box.shift(DOWN * 0.5)\n code_display = VGroup()\n for i, line in enumerate(code_lines):\n txt = Text(line, font_size=18, font='monospace', color=WHITE)\n txt.shift(DOWN * 0.5 + UP * (0.8 - i * 0.4))\n code_display.add(txt)\n matlab_title = Text('MATLAB Code', font_size=28, color=BLUE)\n matlab_title.next_to(code_box, UP, buff=0.3)\n self.play(Create(code_box), Write(matlab_title), run_time=2.0 * 0.4)\n self.play(Write(code_display), run_time=2.0 * 0.3)\n self.wait(0.5)\n self.play(FadeOut(code_box), FadeOut(code_display), FadeOut(matlab_title), run_time=2.0 * 0.2)\n outcomes_title = Text('Learning Outcomes', font_size=36, color=BLUE)\n outcomes_title.shift(UP * 2)\n outcome1 = Text('• Understand CNN training process', font_size=24)\n outcome2 = Text('• Visualize metrics in real-time', font_size=24)\n outcome3 = Text('• Analyze model performance in MATLAB', font_size=24)\n outcomes = VGroup(outcome1, outcome2, outcome3)\n outcomes.arrange(DOWN, buff=0.5, aligned_edge=LEFT)\n outcomes.shift(LEFT * 1)\n self.play(Write(outcomes_title), run_time=2.0 * 0.3)\n self.play(Write(outcome1), run_time=2.0 * 0.25)\n self.play(Write(outcome2), run_time=2.0 * 0.25)\n self.play(Write(outcome3), run_time=2.0 * 0.3)\n self.wait(0.5)\n conclusion = Text('Start Training & Visualizing!', font_size=32, color=GREEN)\n conclusion.next_to(outcomes, DOWN, buff=0.8)\n self.play(Write(conclusion), run_time=2.0)\n self.wait(1)\n self.play(FadeOut(title), FadeOut(outcomes_title), FadeOut(outcomes), FadeOut(conclusion), run_time=2)\n```", "category": "narrated_pedagogical_preference", "source": "nabin2004/manim-narrated-dpo-400"} +{"system": "You are an expert Manim Community Edition (ManimCE v0.19+) Python developer and mathematical animator. Given a user request, first plan the spatial layout, coordinate bounds, timing, and pedagogical flow inside ... tags (when reasoning is helpful), and then output a complete, runnable, self-contained ManimCE Python script using `from manim import *`. Never use deprecated ManimGL (`manimlib`) methods like `ShowCreation`, `TexMobject`, `TextMobject`, or `axes.get_graph`; always use modern ManimCE APIs (`Create`, `MathTex`, `Tex`, `Text`, `axes.plot`) and prevent visual overlap using `.to_edge()`, `.next_to()`, and `FadeOut`.", "prompt": "I'm studying audio models and want to visualize a WaveNet block: input → Dilated Conv → gated tanh/sigmoid path → 1x1 Conv → + Input (residual).\nAnimate time-aligned signals through dilation steps, gating, and the residual merge.\nColor-code the two branches and highlight how the residual sustains gradients across layers.\nInclude a timeline showing how dilation expands receptive field.", "chosen": "```python\nfrom manim import *\nfrom manim_voiceover import VoiceoverScene\nfrom manim_voiceover.services.gtts import GTTSService\n\nclass WaveNetBlockVisualization(VoiceoverScene):\n def construct(self):\n self.set_speech_service(\n GTTSService(voice=\"alba\", cache_dir=\"voiceover_cache\")\n )\n \n # INTRO\n title = Text(\"WaveNet Block\", font_size=48)\n subtitle = Text(\"Dilated Causal Convolutions & Gated Activations\", font_size=26)\n header = VGroup(title, subtitle).arrange(DOWN, buff=0.4)\n header.to_edge(UP, buff=0.6)\n \n with self.voiceover(text=\"Have you ever wondered how machines can generate realistic human-like speech? The secret lies in a powerful architecture called WaveNet, and today, we're going to break it down and visualize its components step by step!\") as tracker:\n self.play(Write(title), run_time=tracker.duration * 0.5)\n self.play(FadeIn(subtitle, shift=DOWN * 0.2), run_time=tracker.duration * 0.5)\n \n # SECTION 1: INSIDE ONE BLOCK\n with self.voiceover(text=\"At the heart of WaveNet is a repeating block built around dilated causal convolutions. Let's zoom into one block and follow the data flow.\") as tracker:\n self.play(FadeOut(subtitle), title.animate.to_edge(UP).scale(0.6), run_time=tracker.duration)\n \n section_title = Text(\"Inside One Block\", font_size=32).to_edge(UP, buff=0.3)\n \n x_node = MathTex(r\"\\mathbf{x}\", font_size=36).move_to(LEFT * 5.2)\n \n dil_conv = Rectangle(width=1.5, height=0.7, color=BLUE, fill_opacity=0.3).move_to(LEFT * 3.6)\n dil_text = Text(\"Dilated\\nConv\", font_size=16).move_to(dil_conv.get_center())\n dil_group = VGroup(dil_conv, dil_text)\n \n split1 = Dot(color=WHITE).move_to(LEFT * 2.3)\n \n tanh_box = Rectangle(width=1.0, height=0.6, color=GREEN, fill_opacity=0.3).move_to(LEFT * 1.3 + UP * 1.0)\n tanh_text = MathTex(r\"\\tanh\", font_size=24).move_to(tanh_box.get_center())\n tanh_grp = VGroup(tanh_box, tanh_text)\n \n sig_box = Rectangle(width=1.0, height=0.6, color=RED, fill_opacity=0.3).move_to(LEFT * 1.3 + DOWN * 1.0)\n sig_text = MathTex(r\"\\sigma\", font_size=24).move_to(sig_box.get_center())\n sig_grp = VGroup(sig_box, sig_text)\n \n mul_circ = Circle(radius=0.25, color=YELLOW, fill_opacity=0.3).move_to(RIGHT * 0.2)\n mul_text = MathTex(r\"\\times\", font_size=24).move_to(mul_circ.get_center())\n mul_grp = VGroup(mul_circ, mul_text)\n \n conv1x1 = Rectangle(width=1.2, height=0.6, color=PURPLE, fill_opacity=0.3).move_to(RIGHT * 1.7)\n conv1x1_text = Text(\"1x1 Conv\", font_size=16).move_to(conv1x1.get_center())\n conv1x1_grp = VGroup(conv1x1, conv1x1_text)\n \n split2 = Dot(color=WHITE).move_to(RIGHT * 2.9)\n \n add_circ = Circle(radius=0.25, color=ORANGE, fill_opacity=0.3).move_to(RIGHT * 4.2 + UP * 1.0)\n add_text = MathTex(r\"+\", font_size=24).move_to(add_circ.get_center())\n add_grp = VGroup(add_circ, add_text)\n res_out = MathTex(r\"\\mathbf{x}_{\\text{out}}\", font_size=28).next_to(add_grp, RIGHT, buff=0.15)\n \n skip_box = Rectangle(width=1.0, height=0.5, color=TEAL, fill_opacity=0.3).move_to(RIGHT * 4.2 + DOWN * 1.0)\n skip_text = Text(\"Skip\", font_size=16).move_to(skip_box.get_center())\n skip_grp = VGroup(skip_box, skip_text)\n \n a1 = Arrow(x_node.get_right(), dil_group.get_left(), buff=0.15, stroke_width=2)\n a2 = Arrow(dil_group.get_right(), split1.get_left(), buff=0.1, stroke_width=2)\n a3a = Arrow(split1.get_right(), tanh_grp.get_left(), buff=0.1, stroke_width=2)\n a3b = Arrow(split1.get_right(), sig_grp.get_left(), buff=0.1, stroke_width=2)\n a4a = Arrow(tanh_grp.get_right(), mul_grp.get_left(), buff=0.1, stroke_width=2)\n a4b = Arrow(sig_grp.get_right(), mul_grp.get_left(), buff=0.1, stroke_width=2)\n a5 = Arrow(mul_grp.get_right(), conv1x1_grp.get_left(), buff=0.1, stroke_width=2)\n a6 = Arrow(conv1x1_grp.get_right(), split2.get_left(), buff=0.1, stroke_width=2)\n a7a = Arrow(split2.get_right(), add_grp.get_left(), buff=0.1, stroke_width=2)\n a7b = Arrow(split2.get_right(), skip_grp.get_left(), buff=0.1, stroke_width=2)\n \n res_arrow = CurvedArrow(\n x_node.get_bottom() + DOWN * 0.05,\n add_grp.get_left() + LEFT * 0.05,\n angle=-TAU * 0.25,\n color=GRAY,\n stroke_width=2\n )\n \n block_diagram = VGroup(\n x_node, dil_group, split1, tanh_grp, sig_grp, mul_grp, conv1x1_grp, split2,\n add_grp, skip_grp, res_out,\n a1, a2, a3a, a3b, a4a, a4b, a5, a6, a7a, a7b, res_arrow\n )\n block_diagram.scale(0.9)\n block_diagram.move_to(DOWN * 0.2)\n \n with self.voiceover(text=\"The input first passes through a dilated causal convolution layer.\") as tracker:\n self.play(Write(section_title), run_time=0.3)\n self.play(FadeIn(x_node), Create(a1), Create(dil_group), Create(a2), Create(split1), run_time=tracker.duration * 0.7)\n \n with self.voiceover(text=\"The output splits into two branches. One flows through a hyperbolic tangent, the other through a sigmoid.\") as tracker:\n self.play(Create(a3a), FadeIn(tanh_grp), Create(a3b), FadeIn(sig_grp), run_time=tracker.duration)\n \n with self.voiceover(text=\"This pairing is the gated activation unit. The tanh filters the signal, while the sigmoid opens or closes the gate. Their product controls exactly how much information passes through.\") as tracker:\n self.play(Create(a4a), Create(a4b), FadeIn(mul_grp), run_time=tracker.duration * 0.5)\n self.play(Indicate(mul_grp), run_time=tracker.duration * 0.5)\n \n with self.voiceover(text=\"Next, a one-by-one convolution mixes the channels. Then the stream splits into a residual update and a skip connection.\") as tracker:\n self.play(Create(a5), FadeIn(conv1x1_grp), Create(a6), FadeIn(split2), run_time=tracker.duration * 0.4)\n self.play(Create(a7a), FadeIn(add_grp), Create(a7b), FadeIn(skip_grp), Write(res_out), run_time=tracker.duration * 0.6)\n \n with self.voiceover(text=\"The residual branch is added back to the original input, enabling training of extremely deep networks. Every skip connection simultaneously carries information forward to the final output.\") as tracker:\n self.play(Create(res_arrow), run_time=tracker.duration * 0.5)\n self.play(Indicate(add_grp), Indicate(skip_grp), run_time=tracker.duration * 0.5)\n \n # SECTION 2: DILATION\n with self.voiceover(text=\"Now, what makes WaveNet unique is dilation. Let's visualize how dilated convolutions work on a raw audio sequence.\") as tracker:\n self.play(FadeOut(block_diagram), FadeOut(section_title), run_time=tracker.duration * 0.5)\n self.play(title.animate.scale(0.0).set_opacity(0), run_time=tracker.duration * 0.5)\n \n section_title2 = Text(\"Dilated Convolution\", font_size=32).to_edge(UP, buff=0.3)\n \n n = 9\n samples = VGroup()\n idx_labels = VGroup()\n for i in range(n):\n s = Square(side_length=0.45, color=BLUE, fill_opacity=0.2)\n s.move_to(LEFT * 3.2 + RIGHT * i * 0.8)\n lab = MathTex(str(i), font_size=20).next_to(s, DOWN, buff=0.15)\n samples.add(s)\n idx_labels.add(lab)\n sample_group = VGroup(samples, idx_labels)\n sample_group.center().shift(UP * 0.2)\n \n k1_rects = VGroup(*[SurroundingRectangle(samples[i], color=GREEN, buff=0.03) for i in range(3, 6)])\n k2_rects = VGroup(*[SurroundingRectangle(samples[i], color=RED, buff=0.03) for i in [2, 4, 6]])\n k4_rects = VGroup(*[SurroundingRectangle(samples[i], color=YELLOW, buff=0.03) for i in [0, 4, 8]])\n \n d1_text = MathTex(r\"d=1\", color=GREEN, font_size=28).next_to(sample_group, DOWN, buff=0.8).shift(LEFT * 2.5)\n d2_text = MathTex(r\"d=2\", color=RED, font_size=28).next_to(sample_group, DOWN, buff=0.8)\n d4_text = MathTex(r\"d=4\", color=YELLOW, font_size=28).next_to(sample_group, DOWN, buff=0.8).shift(RIGHT * 2.5)\n \n with self.voiceover(text=\"Here are audio samples arranged in time. A standard convolution with dilation one uses three adjacent samples to compute the next output.\") as tracker:\n self.play(Write(section_title2), run_time=0.3)\n self.play(LaggedStart(*[FadeIn(s) for s in samples], lag_ratio=0.05), run_time=tracker.duration * 0.3)\n self.play(Write(idx_labels), run_time=tracker.duration * 0.2)\n self.play(Create(k1_rects), FadeIn(d1_text), run_time=tracker.duration * 0.5)\n \n with self.voiceover(text=\"With dilation two, the kernel skips every other sample. This doubles the receptive field without adding parameters.\") as tracker:\n self.play(ReplacementTransform(k1_rects, k2_rects), ReplacementTransform(d1_text, d2_text), run_time=tracker.duration)\n \n with self.voiceover(text=\"With dilation four, the receptive field grows even larger. In WaveNet, dilation doubles at every layer, giving the model a huge temporal context.\") as tracker:\n self.play(ReplacementTransform(k2_rects, k4_rects), ReplacementTransform(d2_text, d4_text), run_time=tracker.duration)\n \n # SECTION 3: STACKED BLOCKS\n with self.voiceover(text=\"Finally, WaveNet stacks many of these blocks with exponentially increasing dilations. Skip connections from every layer are summed to form the final output.\") as tracker:\n self.play(FadeOut(sample_group), FadeOut(k4_rects), FadeOut(d4_text), FadeOut(section_title2), run_time=tracker.duration * 0.5)\n \n section_title3 = Text(\"Stacked Blocks & Skip Connections\", font_size=28).to_edge(UP, buff=0.3)\n \n blocks = VGroup()\n for i, d in enumerate([1, 2, 4]):\n rect = Rectangle(width=1.4, height=0.7, color=BLUE, fill_opacity=0.3)\n txt = MathTex(f\"d={d}\", font_size=22)\n grp = VGroup(rect, txt)\n grp.move_to(LEFT * 2 + UP * (1.2 - i * 1.2))\n blocks.add(grp)\n \n res_arrows = VGroup()\n for i in range(len(blocks) - 1):\n a = Arrow(blocks[i].get_bottom(), blocks[i+1].get_top(), buff=0.05, stroke_width=2)\n res_arrows.add(a)\n \n in_arr = Arrow(LEFT * 4, blocks[0].get_left(), buff=0.1, stroke_width=2)\n out_arr = Arrow(blocks[-1].get_right(), RIGHT * 4 + blocks[-1].get_right()[1] * UP, buff=0.1, stroke_width=2)\n \n sum_circ = Circle(radius=0.35, color=ORANGE, fill_opacity=0.3).move_to(RIGHT * 3)\n sum_text = MathTex(r\"\\Sigma\", font_size=28).move_to(sum_circ.get_center())\n sum_node = VGroup(sum_circ, sum_text)\n \n skip_arrs = VGroup()\n for block in blocks:\n a = Arrow(block.get_right(), sum_node.get_left(), buff=0.15, color=TEAL, stroke_width=2)\n skip_arrs.add(a)\n \n final_out = MathTex(r\"\\text{Output}\", font_size=28).next_to(sum_node, RIGHT, buff=0.3)\n \n with self.voiceover(text=\"The residual path flows downward through the stack, while teal skip connections leap directly to the final summation. This combination lets WaveNet model long audio sequences with remarkable fidelity.\") as tracker:\n self.play(Write(section_title3), run_time=0.3)\n self.play(Create(in_arr), LaggedStart(*[FadeIn(b) for b in blocks], lag_ratio=0.2), run_time=tracker.duration * 0.3)\n self.play(Create(res_arrows), Create(out_arr), run_time=tracker.duration * 0.2)\n self.play(Create(skip_arrs), FadeIn(sum_node), Write(final_out), run_time=tracker.duration * 0.5)\n \n # OUTRO\n with self.voiceover(text=\"And that is how a WaveNet block works. Thank you for watching!\") as tracker:\n self.wait(tracker.duration)\n```", "rejected": "```python\nfrom manim import *\n\nclass WaveNetBlockVisualization(Scene):\n\n def construct(self):\n title = Text('WaveNet Block', font_size=48)\n subtitle = Text('Dilated Causal Convolutions & Gated Activations', font_size=26)\n header = VGroup(title, subtitle).arrange(DOWN, buff=0.4)\n header.to_edge(UP, buff=0.6)\n self.play(Write(title), run_time=2.0 * 0.5)\n self.play(FadeIn(subtitle, shift=DOWN * 0.2), run_time=2.0 * 0.5)\n self.play(FadeOut(subtitle), title.animate.to_edge(UP).scale(0.6), run_time=2.0)\n section_title = Text('Inside One Block', font_size=32).to_edge(UP, buff=0.3)\n x_node = MathTex('\\\\mathbf{x}', font_size=36).move_to(LEFT * 5.2)\n dil_conv = Rectangle(width=1.5, height=0.7, color=BLUE, fill_opacity=0.3).move_to(LEFT * 3.6)\n dil_text = Text('Dilated\\nConv', font_size=16).move_to(dil_conv.get_center())\n dil_group = VGroup(dil_conv, dil_text)\n split1 = Dot(color=WHITE).move_to(LEFT * 2.3)\n tanh_box = Rectangle(width=1.0, height=0.6, color=GREEN, fill_opacity=0.3).move_to(LEFT * 1.3 + UP * 1.0)\n tanh_text = MathTex('\\\\tanh', font_size=24).move_to(tanh_box.get_center())\n tanh_grp = VGroup(tanh_box, tanh_text)\n sig_box = Rectangle(width=1.0, height=0.6, color=RED, fill_opacity=0.3).move_to(LEFT * 1.3 + DOWN * 1.0)\n sig_text = MathTex('\\\\sigma', font_size=24).move_to(sig_box.get_center())\n sig_grp = VGroup(sig_box, sig_text)\n mul_circ = Circle(radius=0.25, color=YELLOW, fill_opacity=0.3).move_to(RIGHT * 0.2)\n mul_text = MathTex('\\\\times', font_size=24).move_to(mul_circ.get_center())\n mul_grp = VGroup(mul_circ, mul_text)\n conv1x1 = Rectangle(width=1.2, height=0.6, color=PURPLE, fill_opacity=0.3).move_to(RIGHT * 1.7)\n conv1x1_text = Text('1x1 Conv', font_size=16).move_to(conv1x1.get_center())\n conv1x1_grp = VGroup(conv1x1, conv1x1_text)\n split2 = Dot(color=WHITE).move_to(RIGHT * 2.9)\n add_circ = Circle(radius=0.25, color=ORANGE, fill_opacity=0.3).move_to(RIGHT * 4.2 + UP * 1.0)\n add_text = MathTex('+', font_size=24).move_to(add_circ.get_center())\n add_grp = VGroup(add_circ, add_text)\n res_out = MathTex('\\\\mathbf{x}_{\\\\text{out}}', font_size=28).next_to(add_grp, RIGHT, buff=0.15)\n skip_box = Rectangle(width=1.0, height=0.5, color=TEAL, fill_opacity=0.3).move_to(RIGHT * 4.2 + DOWN * 1.0)\n skip_text = Text('Skip', font_size=16).move_to(skip_box.get_center())\n skip_grp = VGroup(skip_box, skip_text)\n a1 = Arrow(x_node.get_right(), dil_group.get_left(), buff=0.15, stroke_width=2)\n a2 = Arrow(dil_group.get_right(), split1.get_left(), buff=0.1, stroke_width=2)\n a3a = Arrow(split1.get_right(), tanh_grp.get_left(), buff=0.1, stroke_width=2)\n a3b = Arrow(split1.get_right(), sig_grp.get_left(), buff=0.1, stroke_width=2)\n a4a = Arrow(tanh_grp.get_right(), mul_grp.get_left(), buff=0.1, stroke_width=2)\n a4b = Arrow(sig_grp.get_right(), mul_grp.get_left(), buff=0.1, stroke_width=2)\n a5 = Arrow(mul_grp.get_right(), conv1x1_grp.get_left(), buff=0.1, stroke_width=2)\n a6 = Arrow(conv1x1_grp.get_right(), split2.get_left(), buff=0.1, stroke_width=2)\n a7a = Arrow(split2.get_right(), add_grp.get_left(), buff=0.1, stroke_width=2)\n a7b = Arrow(split2.get_right(), skip_grp.get_left(), buff=0.1, stroke_width=2)\n res_arrow = CurvedArrow(x_node.get_bottom() + DOWN * 0.05, add_grp.get_left() + LEFT * 0.05, angle=-TAU * 0.25, color=GRAY, stroke_width=2)\n block_diagram = VGroup(x_node, dil_group, split1, tanh_grp, sig_grp, mul_grp, conv1x1_grp, split2, add_grp, skip_grp, res_out, a1, a2, a3a, a3b, a4a, a4b, a5, a6, a7a, a7b, res_arrow)\n block_diagram.scale(0.9)\n block_diagram.move_to(DOWN * 0.2)\n self.play(Write(section_title), run_time=0.3)\n self.play(FadeIn(x_node), Create(a1), Create(dil_group), Create(a2), Create(split1), run_time=2.0 * 0.7)\n self.play(Create(a3a), FadeIn(tanh_grp), Create(a3b), FadeIn(sig_grp), run_time=2.0)\n self.play(Create(a4a), Create(a4b), FadeIn(mul_grp), run_time=2.0 * 0.5)\n self.play(Indicate(mul_grp), run_time=2.0 * 0.5)\n self.play(Create(a5), FadeIn(conv1x1_grp), Create(a6), FadeIn(split2), run_time=2.0 * 0.4)\n self.play(Create(a7a), FadeIn(add_grp), Create(a7b), FadeIn(skip_grp), Write(res_out), run_time=2.0 * 0.6)\n self.play(Create(res_arrow), run_time=2.0 * 0.5)\n self.play(Indicate(add_grp), Indicate(skip_grp), run_time=2.0 * 0.5)\n self.play(FadeOut(block_diagram), FadeOut(section_title), run_time=2.0 * 0.5)\n self.play(title.animate.scale(0.0).set_opacity(0), run_time=2.0 * 0.5)\n section_title2 = Text('Dilated Convolution', font_size=32).to_edge(UP, buff=0.3)\n n = 9\n samples = VGroup()\n idx_labels = VGroup()\n for i in range(n):\n s = Square(side_length=0.45, color=BLUE, fill_opacity=0.2)\n s.move_to(LEFT * 3.2 + RIGHT * i * 0.8)\n lab = MathTex(str(i), font_size=20).next_to(s, DOWN, buff=0.15)\n samples.add(s)\n idx_labels.add(lab)\n sample_group = VGroup(samples, idx_labels)\n sample_group.center().shift(UP * 0.2)\n k1_rects = VGroup(*[SurroundingRectangle(samples[i], color=GREEN, buff=0.03) for i in range(3, 6)])\n k2_rects = VGroup(*[SurroundingRectangle(samples[i], color=RED, buff=0.03) for i in [2, 4, 6]])\n k4_rects = VGroup(*[SurroundingRectangle(samples[i], color=YELLOW, buff=0.03) for i in [0, 4, 8]])\n d1_text = MathTex('d=1', color=GREEN, font_size=28).next_to(sample_group, DOWN, buff=0.8).shift(LEFT * 2.5)\n d2_text = MathTex('d=2', color=RED, font_size=28).next_to(sample_group, DOWN, buff=0.8)\n d4_text = MathTex('d=4', color=YELLOW, font_size=28).next_to(sample_group, DOWN, buff=0.8).shift(RIGHT * 2.5)\n self.play(Write(section_title2), run_time=0.3)\n self.play(LaggedStart(*[FadeIn(s) for s in samples], lag_ratio=0.05), run_time=2.0 * 0.3)\n self.play(Write(idx_labels), run_time=2.0 * 0.2)\n self.play(Create(k1_rects), FadeIn(d1_text), run_time=2.0 * 0.5)\n self.play(ReplacementTransform(k1_rects, k2_rects), ReplacementTransform(d1_text, d2_text), run_time=2.0)\n self.play(ReplacementTransform(k2_rects, k4_rects), ReplacementTransform(d2_text, d4_text), run_time=2.0)\n self.play(FadeOut(sample_group), FadeOut(k4_rects), FadeOut(d4_text), FadeOut(section_title2), run_time=2.0 * 0.5)\n section_title3 = Text('Stacked Blocks & Skip Connections', font_size=28).to_edge(UP, buff=0.3)\n blocks = VGroup()\n for i, d in enumerate([1, 2, 4]):\n rect = Rectangle(width=1.4, height=0.7, color=BLUE, fill_opacity=0.3)\n txt = MathTex(f'd={d}', font_size=22)\n grp = VGroup(rect, txt)\n grp.move_to(LEFT * 2 + UP * (1.2 - i * 1.2))\n blocks.add(grp)\n res_arrows = VGroup()\n for i in range(len(blocks) - 1):\n a = Arrow(blocks[i].get_bottom(), blocks[i + 1].get_top(), buff=0.05, stroke_width=2)\n res_arrows.add(a)\n in_arr = Arrow(LEFT * 4, blocks[0].get_left(), buff=0.1, stroke_width=2)\n out_arr = Arrow(blocks[-1].get_right(), RIGHT * 4 + blocks[-1].get_right()[1] * UP, buff=0.1, stroke_width=2)\n sum_circ = Circle(radius=0.35, color=ORANGE, fill_opacity=0.3).move_to(RIGHT * 3)\n sum_text = MathTex('\\\\Sigma', font_size=28).move_to(sum_circ.get_center())\n sum_node = VGroup(sum_circ, sum_text)\n skip_arrs = VGroup()\n for block in blocks:\n a = Arrow(block.get_right(), sum_node.get_left(), buff=0.15, color=TEAL, stroke_width=2)\n skip_arrs.add(a)\n final_out = MathTex('\\\\text{Output}', font_size=28).next_to(sum_node, RIGHT, buff=0.3)\n self.play(Write(section_title3), run_time=0.3)\n self.play(Create(in_arr), LaggedStart(*[FadeIn(b) for b in blocks], lag_ratio=0.2), run_time=2.0 * 0.3)\n self.play(Create(res_arrows), Create(out_arr), run_time=2.0 * 0.2)\n self.play(Create(skip_arrs), FadeIn(sum_node), Write(final_out), run_time=2.0 * 0.5)\n self.wait(2.0)\n```", "category": "narrated_pedagogical_preference", "source": "nabin2004/manim-narrated-dpo-400"} +{"system": "You are an expert Manim Community Edition (ManimCE v0.19+) Python developer and mathematical animator. Given a user request, first plan the spatial layout, coordinate bounds, timing, and pedagogical flow inside ... tags (when reasoning is helpful), and then output a complete, runnable, self-contained ManimCE Python script using `from manim import *`. Never use deprecated ManimGL (`manimlib`) methods like `ShowCreation`, `TexMobject`, `TextMobject`, or `axes.get_graph`; always use modern ManimCE APIs (`Create`, `MathTex`, `Tex`, `Text`, `axes.plot`) and prevent visual overlap using `.to_edge()`, `.next_to()`, and `FadeOut`.", "prompt": "Here’s an enhanced version of the animation that retains all the original features while adding explanatory text, a graphical representation of the integral as area under a curve, and a smoother transition sequence:\n\nThe animation begins by displaying the integral problem \\(\\int_1^3 3x^2 \\,dx\\) with a fade-in effect. As the general solution \\(\\left[ \\frac{3x^{2+1}}{2+1} \\right]_1^3\\) appears via a transform, an accompanying text box fades in below it, explaining the power rule for integration. Next, the scene splits: the left side continues simplifying the expression to \\(\\left[ x^3 \\right]_1^3\\) and then to \\(3^3 - 1^3\\), while the right side dynamically plots the function \\(3x^2\\) on an axes system, shading the area under the curve between \\(x=1\\) and \\(x=3\\) to visually represent the integral. As the evaluation concludes with \\(27 - 1 = 26\\), the numerical result pulses for emphasis, and the shaded area on the graph briefly flashes to reinforce the connection between the algebraic solution and its geometric meaning. Finally, the scene clears, leaving only the final result, which scales up for prominence. This enhanced version not only demonstrates the computational steps but also provides visual and textual context to deepen understanding of the integral's significance.", "chosen": "```python\nfrom manim import *\n\nclass EnhancedIntegralAnimation(Scene):\n def construct(self):\n # Initial integral expression\n integral = MathTex(r\"\\int_1^3 3x^2 \\,dx\").scale(1.5)\n self.play(Write(integral))\n self.wait(1)\n\n # General solution with power rule explanation\n general_solution = MathTex(\n r\"\\left[ \\frac{3x^{2+1}}{2+1} \\right]_1^3\"\n ).scale(1.5)\n power_rule_explanation = Tex(\"Power rule for integration:\",\n r\"$\\int x^n dx = \\frac{x^{n+1}}{n+1} + C$\"\n ).scale(0.8)\n power_rule_explanation.next_to(general_solution, DOWN, buff=0.5)\n\n self.play(\n Transform(integral, general_solution),\n FadeIn(power_rule_explanation, shift=UP*0.5)\n )\n self.wait(2)\n\n # Split the scene into left (algebra) and right (graph)\n left_group = VGroup(integral, power_rule_explanation).to_edge(LEFT)\n self.play(left_group.animate.to_edge(LEFT))\n\n # Create axes and plot\n axes = Axes(\n x_range=[0, 4, 1],\n y_range=[0, 30, 5],\n axis_config={\"color\": BLUE},\n ).to_edge(RIGHT)\n labels = axes.get_axis_labels(x_label=\"x\", y_label=\"y\")\n graph = axes.plot(lambda x: 3*x**2, color=GREEN)\n graph_label = axes.get_graph_label(graph, label=\"3x^2\")\n\n self.play(\n Create(axes),\n Write(labels),\n Create(graph),\n Write(graph_label)\n )\n self.wait(1)\n\n # Shade the area under the curve\n area = axes.get_area(graph, x_range=(1, 3), color=BLUE, opacity=0.3)\n self.play(FadeIn(area))\n self.wait(1)\n\n # Simplify the expression step by step\n simplified1 = MathTex(r\"\\left[ x^3 \\right]_1^3\").scale(1.5).to_edge(LEFT)\n self.play(\n Transform(integral, simplified1),\n FadeOut(power_rule_explanation)\n )\n self.wait(1)\n\n simplified2 = MathTex(r\"3^3 - 1^3\").scale(1.5).to_edge(LEFT)\n self.play(Transform(integral, simplified2))\n self.wait(1)\n\n # Final evaluation\n result = MathTex(r\"27 - 1 = 26\").scale(1.5).to_edge(LEFT)\n self.play(Transform(integral, result))\n self.wait(1)\n\n # Emphasize the result and the area\n self.play(\n integral.animate.scale(1.2).set_color(YELLOW),\n area.animate.set_color(RED),\n rate_func=there_and_back,\n run_time=2\n )\n self.wait(2)\n\n # Clear everything except the final result\n self.play(\n FadeOut(axes),\n FadeOut(labels),\n FadeOut(graph),\n FadeOut(graph_label),\n FadeOut(area),\n integral.animate.move_to(ORIGIN).scale(1.5)\n )\n self.wait(2)\n```", "rejected": "```python\nfrom manim import *\n\nclass EnhancedIntegralAnimation(Scene):\n def construct(self):\n # Initial integral expression\n integral = MathTex(r\"\\int_1^3 3x^2 \\,dx\").scale(1.5)\n self.play(Write(integral))\n self.wait(1)\n\n # General solution with power rule explanation\n general_solution = MathTex(\n r\"\\left[ \\frac{3x^{2+1}}{2+1} \\right]_1^3\"\n ).scale(1.5)\n power_rule_explanation = Tex(\"Power rule for integration:\",\n r\"$\\int x^n dx = \\frac{x^{n+1}}{n+1} + C$\"\n ).scale(0.8)\n power_rule_explanation\n\n self.play(\n Transform(integral, general_solution),\n FadeIn(power_rule_explanation, shift=UP*0.5)\n )\n self.wait(2)\n\n # Split the scene into left (algebra) and right (graph)\n left_group = VGroup(integral, power_rule_explanation)\n self.play(left_group.animate)\n\n # Create axes and plot\n axes = Axes(\n x_range=[0, 4, 1],\n y_range=[0, 30, 5],\n axis_config={\"color\": BLUE},\n ).to_edge(RIGHT)\n labels = axes.get_axis_labels(x_label=\"x\", y_label=\"y\")\n graph = axes.plot(lambda x: 3*x**2, color=GREEN)\n graph_label = axes.get_graph_label(graph, label=\"3x^2\")\n\n self.play(\n Create(axes),\n Write(labels),\n Create(graph),\n Write(graph_label)\n )\n self.wait(1)\n\n # Shade the area under the curve\n area = axes.get_area(graph, x_range=(1, 3), color=BLUE, opacity=0.3)\n self.play(FadeIn(area))\n self.wait(1)\n\n # Simplify the expression step by step\n simplified1 = MathTex(r\"\\left[ x^3 \\right]_1^3\").scale(1.5).to_edge(LEFT)\n self.play(\n Transform(integral, simplified1),\n FadeOut(power_rule_explanation)\n )\n self.wait(1)\n\n simplified2 = MathTex(r\"3^3 - 1^3\").scale(1.5).to_edge(LEFT)\n self.play(Transform(integral, simplified2))\n self.wait(1)\n\n # Final evaluation\n result = MathTex(r\"27 - 1 = 26\").scale(1.5).to_edge(LEFT)\n self.play(Transform(integral, result))\n self.wait(1)\n\n # Emphasize the result and the area\n self.play(\n integral.animate.scale(1.2).set_color(YELLOW),\n area.animate.set_color(RED),\n rate_func=there_and_back,\n run_time=2\n )\n self.wait(2)\n\n # Clear everything except the final result\n self.play(\n FadeOut(axes),\n FadeOut(labels),\n FadeOut(graph),\n FadeOut(graph_label),\n FadeOut(area),\n integral.animate.move_to(ORIGIN).scale(1.5)\n )\n self.wait(2)\n```", "category": "spatial_layout_overlap", "source": "synthetic_hard_neg:nabin2004/manim-sft-10k"} +{"system": "You are an expert Manim Community Edition (ManimCE v0.19+) Python developer and mathematical animator. Given a user request, first plan the spatial layout, coordinate bounds, timing, and pedagogical flow inside ... tags (when reasoning is helpful), and then output a complete, runnable, self-contained ManimCE Python script using `from manim import *`. Never use deprecated ManimGL (`manimlib`) methods like `ShowCreation`, `TexMobject`, `TextMobject`, or `axes.get_graph`; always use modern ManimCE APIs (`Create`, `MathTex`, `Tex`, `Text`, `axes.plot`) and prevent visual overlap using `.to_edge()`, `.next_to()`, and `FadeOut`.", "prompt": "Create a step-by-step educational Manim CE lecture scene explaining: Taylor Series Expansion of exp(x).\n\n```python\nfrom manim import *\nimport numpy as np\n\nclass PedagogicalScene857(Scene):\n def construct(self):\n title = Title(r\"Taylor Series of $f(x) = e^x$ around $x=0$\")\n ax = Axes(x_range=[-3, 3, 1], y_range=[-1, 8, 2], x_length=6, y_length=4)\n exp_curve = ax.plot(lambda x: np.exp(x), color=WHITE)\n exp_label = MathTex(r\"e^x\").next_to(ax.c2p(2, np.exp(2)), RIGHT)\n \n t1 = ax.plot(lambda x: 1 + x, color=BLUE)\n t2 = ax.plot(lambda x: 1 + x + 0.5 * x**2, color=GREEN)\n t3 = ax.plot(lambda x: 1 + x + 0.5 * x**2 + (1/6) * x**3, color=YELLOW)\n \n self.play(Write(title), Create(ax), Create(exp_curve), Write(exp_label))\n self.play(Create(t1), run_time=1.5)\n self.wait(0.5)\n self.play(Transform(t1, t2), run_time=1.5)\n self.wait(0.5)\n self.play(Transform(t1, t3), run_time=1.5)\n self.wait(2)\n```", "chosen": "```python\nfrom manim import *\nfrom manim_voiceover import VoiceoverScene\nfrom manim_voiceover.services.gtts import GTTSService\nimport numpy as np\n\nMARGIN = 0.5\n\nclass TaylorSeriesExpScene(VoiceoverScene):\n def fit_in_frame(self, mob: Mobject, w_frac=0.9, h_frac=0.9) -> Mobject:\n max_w = config.frame_width * w_frac\n max_h = config.frame_height * h_frac\n if mob.width > max_w: mob.width = max_w\n if mob.height > max_h: mob.height = max_h\n return mob\n\n def construct(self):\n self.set_speech_service(GTTSService(transcription_model=\"base\"))\n \n # [SETUP]\n title = Title(r\"Taylor Series of $f(x) = e^x$\", buff=MARGIN)\n ax = Axes(x_range=[-3, 3, 1], y_range=[-1, 8, 2], x_length=6, y_length=4)\n exp_curve = ax.plot(lambda x: np.exp(x), color=WHITE)\n exp_label = MathTex(r\"e^x\").next_to(ax.c2p(2, np.exp(2)), RIGHT)\n \n t1 = ax.plot(lambda x: 1 + x, color=BLUE)\n t2 = ax.plot(lambda x: 1 + x + 0.5 * x**2, color=GREEN)\n t3 = ax.plot(lambda x: 1 + x + 0.5 * x**2 + (1/6) * x**3, color=YELLOW)\n \n # [LAYOUT]\n main_group = self.fit_in_frame(VGroup(title, ax, exp_curve, exp_label))\n self.add(main_group)\n \n # [UPDATER]\n # None\n \n # [BEAT 1 | sync: b1]\n with self.voiceover(text=\"We explore the Taylor series expansion of the exponential function. \") as t_voice:\n self.wait_until_bookmark(\"b1\")\n self.play(Create(t1), run_time=1.5)\n \n # [BEAT 2 | sync: b2]\n with self.voiceover(text=\"Starting with a linear approximation, we add higher-order terms to better match the true curve. \") as t_voice:\n self.wait_until_bookmark(\"b2\")\n self.play(Transform(t1, t2), run_time=1.5)\n self.play(Transform(t1, t3), run_time=1.5)\n self.wait(1)\n```", "rejected": "```python\nfrom manim import *\nfrom manim_voiceover import VoiceoverScene\nfrom manim_voiceover.services.gtts import GTTSService\nimport numpy as np\n\nMARGIN = 0.5\n\nclass TaylorSeriesExpScene(VoiceoverScene):\n def fit_in_frame(self, mob: Mobject, w_frac=0.9, h_frac=0.9) -> Mobject:\n max_w = config.frame_width * w_frac\n max_h = config.frame_height * h_frac\n if mob.width > max_w: mob.width = max_w\n if mob.height > max_h: mob.height = max_h\n return mob\n\n def construct(self):\n self.set_speech_service(GTTSService(transcription_model=\"base\"))\n \n # [SETUP]\n title = Title(r\"Taylor Series of $f(x) = e^x$\", buff=MARGIN)\n ax = Axes(axis_color=BLUE, x_range=[-3, 3, 1], y_range=[-1, 8, 2], x_length=6, y_length=4)\n exp_curve = ax.plot(lambda x: np.exp(x), color=WHITE)\n exp_label = MathTex(r\"e^x\").next_to(ax.c2p(2, np.exp(2)), RIGHT)\n \n t1 = ax.plot(lambda x: 1 + x, color=BLUE)\n t2 = ax.plot(lambda x: 1 + x + 0.5 * x**2, color=GREEN)\n t3 = ax.plot(lambda x: 1 + x + 0.5 * x**2 + (1/6) * x**3, color=YELLOW)\n \n # [LAYOUT]\n main_group = self.fit_in_frame(VGroup(title, ax, exp_curve, exp_label))\n self.add(main_group)\n \n # [UPDATER]\n # None\n \n # [BEAT 1 | sync: b1]\n with self.voiceover(text=\"We explore the Taylor series expansion of the exponential function. \") as t_voice:\n self.wait_until_bookmark(\"b1\")\n self.play(Create(t1), run_time=1.5)\n \n # [BEAT 2 | sync: b2]\n with self.voiceover(text=\"Starting with a linear approximation, we add higher-order terms to better match the true curve. \") as t_voice:\n self.wait_until_bookmark(\"b2\")\n self.play(Transform(t1, t2), run_time=1.5)\n self.play(Transform(t1, t3), run_time=1.5)\n self.wait(1)\n```", "category": "invalid_axes_kwarg", "source": "synthetic_hard_neg:nabin2004/qwen3-8b-manimator-gold-sft"} +{"system": "You are an expert Manim Community Edition (ManimCE v0.19+) Python developer and mathematical animator. Given a user request, first plan the spatial layout, coordinate bounds, timing, and pedagogical flow inside ... tags (when reasoning is helpful), and then output a complete, runnable, self-contained ManimCE Python script using `from manim import *`. Never use deprecated ManimGL (`manimlib`) methods like `ShowCreation`, `TexMobject`, `TextMobject`, or `axes.get_graph`; always use modern ManimCE APIs (`Create`, `MathTex`, `Tex`, `Text`, `axes.plot`) and prevent visual overlap using `.to_edge()`, `.next_to()`, and `FadeOut`.", "prompt": "You are a Manim expert. Please convert the Markdown lecture notes into executable Manim CE v0.19.0 code that displays content in English. The page layout must be clear, with no overlapping elements, and you must not output any explanatory or descriptive text outside the code. Pay special attention to avoiding common errors such as LaTeX syntax issues and index out-of-range errors, and ensure the code can run directly. The Markdown lecture notes are as follows:\n\n#### Web Middleware\n##### SOAP Protocol\nSimple Object Access Protocol, an XML-based message protocol that typically runs over HTTP, with strict specifications and type checking.\n\n##### WSDL Description\nWeb Services Description Language, an XML-based language used to describe the functionality, interface parameters, and location of Web services.\n\n##### UDDI Registration\nUniversal Description, Discovery, and Integration protocol, a directory service used for publishing and finding Web services.\n\n##### RESTful Services\nA lightweight architectural style that leverages HTTP standard methods, typically using JSON format for data transmission, and is gradually replacing the complex SOAP/WSDL framework.\n\n\nThe context location of this section (from highest to current level):\n# Inter-process Communication\n## Main Content\n### Middleware Technologies\n", "chosen": "```python\nfrom manim import *\nfrom manim import config\nText.set_default(font='SimHei')\n\nclass WebMiddleware(Scene):\n\n def construct(self):\n context_text = Text('Inter-process Communication > Middleware Technologies', font_size=18, color=GRAY)\n main_title = Text('Web Middleware', font_size=36, color=YELLOW, weight=BOLD)\n header = VGroup(context_text, main_title).arrange(DOWN, aligned_edge=LEFT, buff=0.2)\n header.to_corner(UL)\n self.play(FadeIn(header, shift=DOWN * 0.3))\n self.wait(0.5)\n\n def create_item(title_str, desc_str, color):\n title = Text(f'• {title_str}', font_size=26, color=color, weight=BOLD)\n desc = Text(desc_str, font_size=22, color=WHITE, line_spacing=0.6)\n desc.next_to(title, DOWN, aligned_edge=LEFT, buff=0.15)\n desc.shift(RIGHT * 0.4)\n return VGroup(title, desc)\n item_soap = create_item('SOAP Protocol', 'Simple Object Access Protocol, an XML-based message protocol\\nthat typically runs over HTTP, with strict specifications and type checking.', BLUE_C)\n item_wsdl = create_item('WSDL Description', 'Web Services Description Language, an XML-based language used to describe\\nthe functionality, interface parameters, and location of Web services.', TEAL_C)\n item_uddi = create_item('UDDI Registration', 'Universal Description, Discovery, and Integration protocol, a directory\\nservice used for publishing and finding Web services.', GREEN_C)\n item_restful = create_item('RESTful Services', 'A lightweight architectural style that leverages HTTP standard methods,\\ntypically using JSON format for data transmission, and is gradually\\nreplacing the complex SOAP/WSDL framework.', ORANGE)\n items = VGroup(item_soap, item_wsdl, item_uddi, item_restful)\n items.arrange(DOWN, aligned_edge=LEFT, buff=0.4)\n items.next_to(header, DOWN, buff=0.5).align_to(header, LEFT).shift(RIGHT * 0.2)\n for item in items:\n title = item[0]\n desc = item[1]\n self.play(FadeIn(title, shift=RIGHT * 0.3), run_time=0.8)\n self.play(FadeIn(desc, shift=UP * 0.2), run_time=0.8)\n self.wait(0.3)\n else:\n pass\n self.wait(2)\n```", "rejected": "```python\nfrom manim import *\nfrom manim import config\nText.set_default(font='SimHei')\n\nclass WebMiddleware(Scene):\n\n def construct(self):\n context_text = Text('Inter-process Communication > Middleware Technologies', font_size=18, color=GRAY)\n main_title = Text('Web Middleware', font_size=36, color=YELLOW, weight=BOLD)\n header = VGroup(context_text, main_title).arrange(DOWN, aligned_edge=LEFT, buff=0.2)\n header\n self.play(FadeIn(header, shift=DOWN * 0.3))\n self.wait(0.5)\n\n def create_item(title_str, desc_str, color):\n title = Text(f'• {title_str}', font_size=26, color=color, weight=BOLD)\n desc = Text(desc_str, font_size=22, color=WHITE, line_spacing=0.6)\n desc\n desc\n return VGroup(title, desc)\n item_soap = create_item('SOAP Protocol', 'Simple Object Access Protocol, an XML-based message protocol\\nthat typically runs over HTTP, with strict specifications and type checking.', BLUE_C)\n item_wsdl = create_item('WSDL Description', 'Web Services Description Language, an XML-based language used to describe\\nthe functionality, interface parameters, and location of Web services.', TEAL_C)\n item_uddi = create_item('UDDI Registration', 'Universal Description, Discovery, and Integration protocol, a directory\\nservice used for publishing and finding Web services.', GREEN_C)\n item_restful = create_item('RESTful Services', 'A lightweight architectural style that leverages HTTP standard methods,\\ntypically using JSON format for data transmission, and is gradually\\nreplacing the complex SOAP/WSDL framework.', ORANGE)\n items = VGroup(item_soap, item_wsdl, item_uddi, item_restful)\n items.arrange(DOWN, aligned_edge=LEFT, buff=0.4)\n items.next_to(header, DOWN, buff=0.5).align_to(header, LEFT).shift(RIGHT * 0.2)\n for item in items:\n title = item[0]\n desc = item[1]\n self.play(FadeIn(title, shift=RIGHT * 0.3), run_time=0.8)\n self.play(FadeIn(desc, shift=UP * 0.2), run_time=0.8)\n self.wait(0.3)\n else:\n pass\n self.wait(2)\n```", "category": "spatial_layout_overlap", "source": "synthetic_hard_neg:nabin2004/manim-sft-10k"} +{"system": "You are an expert Manim Community Edition (ManimCE v0.19+) Python developer and mathematical animator. Given a user request, first plan the spatial layout, coordinate bounds, timing, and pedagogical flow inside ... tags (when reasoning is helpful), and then output a complete, runnable, self-contained ManimCE Python script using `from manim import *`. Never use deprecated ManimGL (`manimlib`) methods like `ShowCreation`, `TexMobject`, `TextMobject`, or `axes.get_graph`; always use modern ManimCE APIs (`Create`, `MathTex`, `Tex`, `Text`, `axes.plot`) and prevent visual overlap using `.to_edge()`, `.next_to()`, and `FadeOut`.", "prompt": "Here's an enhanced version of the animation that maintains all original features while adding significant new elements:\n\nThe enhanced animation begins by displaying the triple integral problem (∫∫∫ xyz dz dy dx) with a 3D coordinate system fading in behind it to provide spatial context. As the narrator explains each integration step, the corresponding dimension of the integral is visually highlighted - first the z-axis (blue) grows upward with a glowing effect while the explanation text appears, then the evaluated integral transforms into the next step with accompanying color-coded brackets that match the axis color. For the middle integral (y-axis, green), a 2D plane emerges showing the remaining double integral's domain, and for the final x-integration (red), a number line appears beneath the expression. Throughout the process, a small persistent graphic in the corner shows the progressive simplification from 3D to 2D to 1D to scalar value. When reaching the final solution (1/8), the animation concludes by morphing the fraction into a rotating cube (representing the original volume) divided into 8 equal smaller cubes, with one highlighted in gold to visually demonstrate the fractional result, while the mathematical expression remains displayed below with a glowing border for emphasis. All transitions are smooth with appropriate timing for comprehension, and the coordinate system dynamically adjusts its perspective to follow the dimensional reduction of the problem.", "chosen": "```python\nfrom manim import *\n\nclass TripleIntegralSolution(Scene):\n def construct(self):\n # Colors for each dimension\n z_color = BLUE\n y_color = GREEN\n x_color = RED\n \n # Create 3D axes\n axes = ThreeDAxes(\n x_range=[0, 1, 0.5],\n y_range=[0, 1, 0.5],\n z_range=[0, 1, 0.5],\n axis_config={\"color\": WHITE}\n )\n \n # Initial integral expression\n integral = MathTex(\n r\"\\int_0^1 \\int_0^1 \\int_0^1 xyz \\,dz\\,dy\\,dx\",\n font_size=40\n )\n \n # Add everything to scene\n self.play(FadeIn(integral))\n self.wait(0.5)\n \n # Show 3D axes behind integral\n self.play(\n integral.animate.to_edge(UP),\n Create(axes),\n run_time=1.5\n )\n self.wait(1)\n \n # Step 1: Integrate over z\n step1 = MathTex(\n r\"\\int_0^1 \\int_0^1 \\left[ \\frac{xyz^2}{2} \\right]_0^1 \\,dy\\,dx\",\n font_size=40,\n substrings_to_isolate=[\"dz\"]\n )\n step1.set_color_by_tex(\"dz\", z_color)\n \n # Highlight z-axis\n z_axis = axes.get_z_axis()\n z_highlight = z_axis.copy().set_color(z_color).set_stroke(width=8)\n \n self.play(\n Transform(integral, step1),\n Create(z_highlight),\n run_time=2\n )\n self.wait(1)\n \n # Evaluate z integral\n step1_eval = MathTex(\n r\"\\int_0^1 \\int_0^1 \\frac{xy}{2} \\,dy\\,dx\",\n font_size=40\n )\n \n self.play(\n Transform(integral, step1_eval),\n FadeOut(z_highlight),\n run_time=1.5\n )\n self.wait(1)\n \n # Step 2: Integrate over y\n step2 = MathTex(\n r\"\\int_0^1 \\left[ \\frac{xy^2}{4} \\right]_0^1 \\,dx\",\n font_size=40,\n substrings_to_isolate=[\"dy\"]\n )\n step2.set_color_by_tex(\"dy\", y_color)\n \n # Highlight y-axis and show xy plane\n y_axis = axes.get_y_axis()\n y_highlight = y_axis.copy().set_color(y_color).set_stroke(width=8)\n xy_plane = Rectangle(\n width=axes.get_x_axis().get_length(),\n height=axes.get_y_axis().get_length(),\n fill_color=y_color,\n fill_opacity=0.2,\n stroke_color=y_color\n ).move_to(axes.c2p(0.5, 0.5, 0))\n \n self.play(\n Transform(integral, step2),\n Create(y_highlight),\n FadeIn(xy_plane),\n run_time=2\n )\n self.wait(1)\n \n # Evaluate y integral\n step2_eval = MathTex(\n r\"\\int_0^1 \\frac{x}{4} \\,dx\",\n font_size=40\n )\n \n self.play(\n Transform(integral, step2_eval),\n FadeOut(y_highlight),\n FadeOut(xy_plane),\n run_time=1.5\n )\n self.wait(1)\n \n # Step 3: Integrate over x\n step3 = MathTex(\n r\"\\left[ \\frac{x^2}{8} \\right]_0^1\",\n font_size=40,\n substrings_to_isolate=[\"dx\"]\n )\n step3.set_color_by_tex(\"dx\", x_color)\n \n # Highlight x-axis and show number line\n x_axis = axes.get_x_axis()\n x_highlight = x_axis.copy().set_color(x_color).set_stroke(width=8)\n number_line = NumberLine(\n x_range=[0, 1, 0.5],\n length=x_axis.get_length(),\n color=x_color\n ).move_to(x_axis)\n \n self.play(\n Transform(integral, step3),\n Create(x_highlight),\n Transform(x_axis, number_line),\n run_time=2\n )\n self.wait(1)\n \n # Final evaluation\n final = MathTex(\n r\"\\frac{1}{8}\",\n font_size=60\n )\n \n # Create cube visualization\n cube = Cube(side_length=2, fill_color=BLUE, fill_opacity=0.6)\n cube.set_stroke(WHITE, width=1)\n \n # Divide cube into 8 smaller cubes\n small_cubes = VGroup()\n for i in range(2):\n for j in range(2):\n for k in range(2):\n small_cube = Cube(side_length=1, fill_color=BLUE, fill_opacity=0.6)\n small_cube.set_stroke(WHITE, width=0.5)\n small_cube.move_to(cube.get_center() + np.array([i-0.5, j-0.5, k-0.5]))\n small_cubes.add(small_cube)\n \n # Highlight one small cube\n highlighted_cube = small_cubes[0].copy()\n highlighted_cube.set_fill(GOLD, opacity=0.9)\n \n self.play(\n Transform(integral, final),\n FadeOut(x_highlight),\n FadeOut(axes),\n run_time=1.5\n )\n self.wait(1)\n \n # Show cube visualization\n self.play(\n integral.animate.shift(2*UP),\n FadeIn(cube),\n run_time=1.5\n )\n self.wait(0.5)\n \n self.play(\n Transform(cube, small_cubes),\n run_time=2\n )\n self.wait(0.5)\n \n self.play(\n Transform(small_cubes[0], highlighted_cube),\n run_time=1\n )\n \n # Add glow to final answer\n glow = SurroundingRectangle(integral, color=YELLOW, buff=0.2, fill_opacity=0.2)\n self.play(\n Create(glow),\n run_time=1.5\n )\n self.wait(3)\n```", "rejected": "```python\nfrom manim import *\n\nclass TripleIntegralSolution(Scene):\n def construct(self):\n # Colors for each dimension\n z_color = BLUE\n y_color = GREEN\n x_color = RED\n \n # Create 3D axes\n axes = ThreeDAxes(\n x_range=[0, 1, 0.5],\n y_range=[0, 1, 0.5],\n z_range=[0, 1, 0.5],\n axis_config={\"color\": WHITE}\n )\n \n # Initial integral expression\n integral = TexMobject(\n r\"\\int_0^1 \\int_0^1 \\int_0^1 xyz \\,dz\\,dy\\,dx\",\n font_size=40\n )\n \n # Add everything to scene\n self.play(FadeIn(integral))\n self.wait(0.5)\n \n # Show 3D axes behind integral\n self.play(\n integral.animate.to_edge(UP),\n ShowCreation(axes),\n run_time=1.5\n )\n self.wait(1)\n \n # Step 1: Integrate over z\n step1 = MathTex(\n r\"\\int_0^1 \\int_0^1 \\left[ \\frac{xyz^2}{2} \\right]_0^1 \\,dy\\,dx\",\n font_size=40,\n substrings_to_isolate=[\"dz\"]\n )\n step1.set_color_by_tex(\"dz\", z_color)\n \n # Highlight z-axis\n z_axis = axes.get_z_axis()\n z_highlight = z_axis.copy().set_color(z_color).set_stroke(width=8)\n \n self.play(\n Transform(integral, step1),\n Create(z_highlight),\n run_time=2\n )\n self.wait(1)\n \n # Evaluate z integral\n step1_eval = MathTex(\n r\"\\int_0^1 \\int_0^1 \\frac{xy}{2} \\,dy\\,dx\",\n font_size=40\n )\n \n self.play(\n Transform(integral, step1_eval),\n FadeOut(z_highlight),\n run_time=1.5\n )\n self.wait(1)\n \n # Step 2: Integrate over y\n step2 = MathTex(\n r\"\\int_0^1 \\left[ \\frac{xy^2}{4} \\right]_0^1 \\,dx\",\n font_size=40,\n substrings_to_isolate=[\"dy\"]\n )\n step2.set_color_by_tex(\"dy\", y_color)\n \n # Highlight y-axis and show xy plane\n y_axis = axes.get_y_axis()\n y_highlight = y_axis.copy().set_color(y_color).set_stroke(width=8)\n xy_plane = Rectangle(\n width=axes.get_x_axis().get_length(),\n height=axes.get_y_axis().get_length(),\n fill_color=y_color,\n fill_opacity=0.2,\n stroke_color=y_color\n ).move_to(axes.c2p(0.5, 0.5, 0))\n \n self.play(\n Transform(integral, step2),\n Create(y_highlight),\n FadeIn(xy_plane),\n run_time=2\n )\n self.wait(1)\n \n # Evaluate y integral\n step2_eval = MathTex(\n r\"\\int_0^1 \\frac{x}{4} \\,dx\",\n font_size=40\n )\n \n self.play(\n Transform(integral, step2_eval),\n FadeOut(y_highlight),\n FadeOut(xy_plane),\n run_time=1.5\n )\n self.wait(1)\n \n # Step 3: Integrate over x\n step3 = MathTex(\n r\"\\left[ \\frac{x^2}{8} \\right]_0^1\",\n font_size=40,\n substrings_to_isolate=[\"dx\"]\n )\n step3.set_color_by_tex(\"dx\", x_color)\n \n # Highlight x-axis and show number line\n x_axis = axes.get_x_axis()\n x_highlight = x_axis.copy().set_color(x_color).set_stroke(width=8)\n number_line = NumberLine(\n x_range=[0, 1, 0.5],\n length=x_axis.get_length(),\n color=x_color\n ).move_to(x_axis)\n \n self.play(\n Transform(integral, step3),\n Create(x_highlight),\n Transform(x_axis, number_line),\n run_time=2\n )\n self.wait(1)\n \n # Final evaluation\n final = MathTex(\n r\"\\frac{1}{8}\",\n font_size=60\n )\n \n # Create cube visualization\n cube = Cube(side_length=2, fill_color=BLUE, fill_opacity=0.6)\n cube.set_stroke(WHITE, width=1)\n \n # Divide cube into 8 smaller cubes\n small_cubes = VGroup()\n for i in range(2):\n for j in range(2):\n for k in range(2):\n small_cube = Cube(side_length=1, fill_color=BLUE, fill_opacity=0.6)\n small_cube.set_stroke(WHITE, width=0.5)\n small_cube.move_to(cube.get_center() + np.array([i-0.5, j-0.5, k-0.5]))\n small_cubes.add(small_cube)\n \n # Highlight one small cube\n highlighted_cube = small_cubes[0].copy()\n highlighted_cube.set_fill(GOLD, opacity=0.9)\n \n self.play(\n Transform(integral, final),\n FadeOut(x_highlight),\n FadeOut(axes),\n run_time=1.5\n )\n self.wait(1)\n \n # Show cube visualization\n self.play(\n integral.animate.shift(2*UP),\n FadeIn(cube),\n run_time=1.5\n )\n self.wait(0.5)\n \n self.play(\n Transform(cube, small_cubes),\n run_time=2\n )\n self.wait(0.5)\n \n self.play(\n Transform(small_cubes[0], highlighted_cube),\n run_time=1\n )\n \n # Add glow to final answer\n glow = SurroundingRectangle(integral, color=YELLOW, buff=0.2, fill_opacity=0.2)\n self.play(\n Create(glow),\n run_time=1.5\n )\n self.wait(3)\n```", "category": "legacy_api_hallucination", "source": "synthetic_hard_neg:nabin2004/manim-sft-10k"} +{"system": "You are an expert Manim Community Edition (ManimCE v0.19+) Python developer and mathematical animator. Given a user request, first plan the spatial layout, coordinate bounds, timing, and pedagogical flow inside ... tags (when reasoning is helpful), and then output a complete, runnable, self-contained ManimCE Python script using `from manim import *`. Never use deprecated ManimGL (`manimlib`) methods like `ShowCreation`, `TexMobject`, `TextMobject`, or `axes.get_graph`; always use modern ManimCE APIs (`Create`, `MathTex`, `Tex`, `Text`, `axes.plot`) and prevent visual overlap using `.to_edge()`, `.next_to()`, and `FadeOut`.", "prompt": "You are a Manim expert. Please convert the Markdown lecture notes into executable Manim CE v0.19.0 code that displays content in English. The page layout must be clear, with no overlapping elements, and you must not output any explanatory or descriptive text outside the code. Pay special attention to avoiding common errors such as LaTeX syntax issues and index out-of-range errors, and ensure the code can run directly. The Markdown lecture notes are as follows:\n\n### Nonlinear Dimensionality Reduction\n\n### Why Nonlinear? Data may lie on a nonlinear low-dimensional manifold in a high-dimensional space.\n\nTypical methods: Isomap - uses geodesic distances instead of Euclidean distances; t-SNE - preserves local neighborhood structure (good for visualization); UMAP - more popular recently, faster and more stable\n\n\nThe context of this section (from highest to current level):\n# Unsupervised Learning\n## Data Dimensionality Reduction\n", "chosen": "```python\nfrom manim import *\nfrom manim import config\nText.set_default(font='SimHei')\n\nclass NonlinearDimensionalityReduction(Scene):\n\n def construct(self):\n context = Text('Unsupervised Learning > Data Dimensionality Reduction', font_size=24, color=GRAY)\n context.to_corner(UL)\n title = Text('Nonlinear Dimensionality Reduction', font_size=48, color=BLUE_B, weight=BOLD)\n why_title = Text('Why Nonlinear?', font_size=36, color=YELLOW_C, weight=BOLD)\n why_desc = Text('Data may lie on a nonlinear low-dimensional manifold\\nin a high-dimensional space.', font_size=30, t2c={'nonlinear': RED_C, 'low-dimensional manifold': RED_C, 'high-dimensional space': RED_C}, line_spacing=1.2)\n why_desc.next_to(why_title, DOWN, buff=0.3).align_to(why_title, LEFT)\n why_group = VGroup(why_title, why_desc)\n methods_title = Text('Typical methods:', font_size=36, color=GREEN_C, weight=BOLD)\n m1 = MarkupText('• Isomap - uses geodesic distances instead of Euclidean distances', font_size=28)\n m2 = MarkupText('• t-SNE - preserves local neighborhood structure (good for visualization)', font_size=28)\n m3 = MarkupText('• UMAP - more popular recently, faster and more stable', font_size=28)\n methods_list = VGroup(m1, m2, m3).arrange(DOWN, aligned_edge=LEFT, buff=0.4)\n methods_list.next_to(methods_title, DOWN, buff=0.4).align_to(methods_title, LEFT).shift(RIGHT * 0.5)\n methods_group = VGroup(methods_title, methods_list)\n why_group.next_to(title, DOWN, buff=0.8).align_to(title, LEFT)\n methods_group.next_to(why_group, DOWN, buff=0.8).align_to(why_group, LEFT)\n content = VGroup(title, why_group, methods_group)\n content.next_to(context, DOWN, buff=0.6).align_to(context, LEFT)\n VGroup(context, content).move_to(ORIGIN)\n self.play(FadeIn(context))\n self.play(Write(title))\n self.wait(0.5)\n self.play(FadeIn(why_title, shift=RIGHT * 0.5))\n self.play(FadeIn(why_desc))\n self.wait(1)\n self.play(FadeIn(methods_title, shift=RIGHT * 0.5))\n self.wait(0.5)\n for m in [m1, m2, m3]:\n self.play(FadeIn(m, shift=UP * 0.2), run_time=0.6)\n else:\n pass\n self.wait(2)\n```", "rejected": "```python\nfrom manim import *\nfrom manim import config\nText.set_default(font='SimHei')\n\nclass NonlinearDimensionalityReduction(Scene):\n\n def construct(self):\n context = Text('Unsupervised Learning > Data Dimensionality Reduction', font_size=24, color=GRAY)\n context\n title = Text('Nonlinear Dimensionality Reduction', font_size=48, color=BLUE_B, weight=BOLD)\n why_title = Text('Why Nonlinear?', font_size=36, color=YELLOW_C, weight=BOLD)\n why_desc = Text('Data may lie on a nonlinear low-dimensional manifold\\nin a high-dimensional space.', font_size=30, t2c={'nonlinear': RED_C, 'low-dimensional manifold': RED_C, 'high-dimensional space': RED_C}, line_spacing=1.2)\n why_desc.align_to(why_title, LEFT)\n why_group = VGroup(why_title, why_desc)\n methods_title = Text('Typical methods:', font_size=36, color=GREEN_C, weight=BOLD)\n m1 = MarkupText('• Isomap - uses geodesic distances instead of Euclidean distances', font_size=28)\n m2 = MarkupText('• t-SNE - preserves local neighborhood structure (good for visualization)', font_size=28)\n m3 = MarkupText('• UMAP - more popular recently, faster and more stable', font_size=28)\n methods_list = VGroup(m1, m2, m3).arrange(DOWN, aligned_edge=LEFT, buff=0.4)\n methods_list.align_to(methods_title, LEFT).shift(RIGHT * 0.5)\n methods_group = VGroup(methods_title, methods_list)\n why_group.next_to(title, DOWN, buff=0.8).align_to(title, LEFT)\n methods_group.next_to(why_group, DOWN, buff=0.8).align_to(why_group, LEFT)\n content = VGroup(title, why_group, methods_group)\n content.next_to(context, DOWN, buff=0.6).align_to(context, LEFT)\n VGroup(context, content).move_to(ORIGIN)\n self.play(FadeIn(context))\n self.play(Write(title))\n self.wait(0.5)\n self.play(FadeIn(why_title, shift=RIGHT * 0.5))\n self.play(FadeIn(why_desc))\n self.wait(1)\n self.play(FadeIn(methods_title, shift=RIGHT * 0.5))\n self.wait(0.5)\n for m in [m1, m2, m3]:\n self.play(FadeIn(m, shift=UP * 0.2), run_time=0.6)\n else:\n pass\n self.wait(2)\n```", "category": "spatial_layout_overlap", "source": "synthetic_hard_neg:nabin2004/manim-sft-10k"} +{"system": "You are an expert Manim Community Edition (ManimCE v0.19+) Python developer and mathematical animator. Given a user request, first plan the spatial layout, coordinate bounds, timing, and pedagogical flow inside ... tags (when reasoning is helpful), and then output a complete, runnable, self-contained ManimCE Python script using `from manim import *`. Never use deprecated ManimGL (`manimlib`) methods like `ShowCreation`, `TexMobject`, `TextMobject`, or `axes.get_graph`; always use modern ManimCE APIs (`Create`, `MathTex`, `Tex`, `Text`, `axes.plot`) and prevent visual overlap using `.to_edge()`, `.next_to()`, and `FadeOut`.", "prompt": "The following Manim CE scene failed to compile. Truncated traceback:\n\nNameError: name 'series_missing' is not defined\n\nFix the code. Return a complete working scene. Do not keep the invalid constructor kwargs or Unicode subscripts.\n\n```python\nfrom manim import *\n\nclass SeriesConvergenceExample(Scene):\n def construct(self):\n # Display the series to be tested\n series = MathTex(r\"\\sum_{n=1}^{\\infty} \\frac{1}{n^2}\")\n self.play(Write(series))\n self.wait(1)\n\n # Explanation of the convergence test\n explanation1 = Text(\"Apply the p-test for convergence\", font_size=24).to_edge(UP)\n self.play(Write(explanation1))\n self.wait(2)\n\n # Display the p-test condition\n p_test = MathTex(r\"p > 1\")\n self.play(Write(p_test))\n self.wait(1)\n\n # Showing that p=2 satisfies the p-test (since our series has n^2)\n satisfaction = MathTex(r\"2 > 1\")\n self.play(Write(satisfaction))\n self.wait(1)\n\n # Explanation for the convergence conclusion\n explanation2 = Text(\"The series converges by the p-test\", font_size=24).to_edge(UP)\n self.play(Transform(explanation1, explanation2))\n self.wait(2)\n\n # Conclusion that the series converges\n conclusion = MathTex(r\"\\sum_{n=1}^{\\infty} \\frac{1}{n^2}\", r\"\\text{ converges}\")\n self.play(ReplacementTransform(series, conclusion[0]), Write(conclusion[1]))\n self.wait(1)\n\n # Clear the scene and conclude\n self.clear()\n self.wait(1)\n self.play(Write(conclusion))\n self.wait(1)\n self.play(FadeOut(series_missing))\n\n```", "chosen": "```python\nfrom manim import *\n\nclass SeriesConvergenceExample(Scene):\n def construct(self):\n # Display the series to be tested\n series = MathTex(r\"\\sum_{n=1}^{\\infty} \\frac{1}{n^2}\")\n self.play(Write(series))\n self.wait(1)\n\n # Explanation of the convergence test\n explanation1 = Text(\"Apply the p-test for convergence\", font_size=24).to_edge(UP)\n self.play(Write(explanation1))\n self.wait(2)\n\n # Display the p-test condition\n p_test = MathTex(r\"p > 1\")\n self.play(Write(p_test))\n self.wait(1)\n\n # Showing that p=2 satisfies the p-test (since our series has n^2)\n satisfaction = MathTex(r\"2 > 1\")\n self.play(Write(satisfaction))\n self.wait(1)\n\n # Explanation for the convergence conclusion\n explanation2 = Text(\"The series converges by the p-test\", font_size=24).to_edge(UP)\n self.play(Transform(explanation1, explanation2))\n self.wait(2)\n\n # Conclusion that the series converges\n conclusion = MathTex(r\"\\sum_{n=1}^{\\infty} \\frac{1}{n^2}\", r\"\\text{ converges}\")\n self.play(ReplacementTransform(series, conclusion[0]), Write(conclusion[1]))\n self.wait(1)\n\n # Clear the scene and conclude\n self.clear()\n self.wait(1)\n self.play(Write(conclusion))\n self.wait(1)\n```", "rejected": "```python\nfrom manim import *\n\nclass SeriesConvergenceExample(Scene):\n def construct(self):\n # Display the series to be tested\n series = TexMobject(r\"\\sum_{n=1}^{\\infty} \\frac{1}{n^2}\")\n self.play(Write(series))\n self.wait(1)\n\n # Explanation of the convergence test\n explanation1 = Text(\"Apply the p-test for convergence\", font_size=24).to_edge(UP)\n self.play(Write(explanation1))\n self.wait(2)\n\n # Display the p-test condition\n p_test = MathTex(r\"p > 1\")\n self.play(Write(p_test))\n self.wait(1)\n\n # Showing that p=2 satisfies the p-test (since our series has n^2)\n satisfaction = MathTex(r\"2 > 1\")\n self.play(Write(satisfaction))\n self.wait(1)\n\n # Explanation for the convergence conclusion\n explanation2 = Text(\"The series converges by the p-test\", font_size=24).to_edge(UP)\n self.play(Transform(explanation1, explanation2))\n self.wait(2)\n\n # Conclusion that the series converges\n conclusion = MathTex(r\"\\sum_{n=1}^{\\infty} \\frac{1}{n^2}\", r\"\\text{ converges}\")\n self.play(ReplacementTransform(series, conclusion[0]), Write(conclusion[1]))\n self.wait(1)\n\n # Clear the scene and conclude\n self.clear()\n self.wait(1)\n self.play(Write(conclusion))\n self.wait(1)\n```", "category": "legacy_api_hallucination", "source": "synthetic_hard_neg:nabin2004/manim-sft-10k"} +{"system": "You are an expert Manim Community Edition (ManimCE v0.19+) Python developer and mathematical animator. Given a user request, first plan the spatial layout, coordinate bounds, timing, and pedagogical flow inside ... tags (when reasoning is helpful), and then output a complete, runnable, self-contained ManimCE Python script using `from manim import *`. Never use deprecated ManimGL (`manimlib`) methods like `ShowCreation`, `TexMobject`, `TextMobject`, or `axes.get_graph`; always use modern ManimCE APIs (`Create`, `MathTex`, `Tex`, `Text`, `axes.plot`) and prevent visual overlap using `.to_edge()`, `.next_to()`, and `FadeOut`.", "prompt": "I'm teaching sequence models and want a visual of the causal constraint in convolutions. Show a filter sliding over tokens with a masked future window, illustrating how only past tokens contribute. Compare with an ungated version to emphasize information leakage, and include a step-by-step masking animation.", "chosen": "```python\nfrom manim import *\nfrom manim_voiceover import VoiceoverScene\nfrom manim_voiceover.services.gtts import GTTSService\n\n\nclass CausalConstraintInConvolutions(VoiceoverScene):\n def construct(self):\n # Set up speech service\n self.set_speech_service(\n GTTSService(voice=\"alba\", cache_dir=\"voiceover_cache\")\n )\n \n # Colors\n color_input = BLUE\n color_kernel = RED\n color_output = GREEN\n color_past = YELLOW\n color_future = GRAY\n \n # ============================================\n # INTRODUCTION\n # ============================================\n title = Text(\"Causal Constraint in Convolutions\", font_size=48)\n subtitle = Text(\"Subject: AI\", font_size=28, color=GRAY)\n subtitle.next_to(title, DOWN, buff=0.5)\n \n with self.voiceover(\n text=\"Imagine a signal that carries vital information, where every moment counts. \"\n \"What if your model could only rely on past data to make predictions? \"\n \"This scenario highlights the essence of causal constraints in convolutions. \"\n \"Today, you will dive into the fascinating world of causal convolution and uncover how it shapes predictive models!\"\n ) as tracker:\n self.play(Write(title), run_time=tracker.duration * 0.5)\n self.play(FadeIn(subtitle), run_time=tracker.duration * 0.5)\n \n self.wait(0.5)\n self.play(FadeOut(title), FadeOut(subtitle))\n \n # ============================================\n # STANDARD CONVOLUTION REVIEW\n # ============================================\n with self.voiceover(\n text=\"Let us begin with the standard convolution formula. \"\n \"Convolution combines an input signal with a kernel to produce an output.\"\n ) as tracker:\n conv_formula = MathTex(\n r\"y[n] = (x * w)[n] = \\sum_{m=-\\infty}^{\\infty} x[m] \\, w[n - m]\",\n font_size=40\n )\n self.play(Write(conv_formula), run_time=tracker.duration)\n \n self.wait(0.3)\n \n with self.voiceover(\n text=\"Here, x is the input signal, w is the kernel or filter, and y is the output. \"\n \"Notice that the summation ranges over all integers, from negative infinity to positive infinity.\"\n ) as tracker:\n # Label the parts\n x_label = MathTex(r\"x = \\text{input}\", font_size=24, color=color_input)\n w_label = MathTex(r\"w = \\text{kernel}\", font_size=24, color=color_kernel)\n y_label = MathTex(r\"y = \\text{output}\", font_size=24, color=color_output)\n \n labels_group = VGroup(x_label, w_label, y_label).arrange(RIGHT, buff=1)\n labels_group.next_to(conv_formula, DOWN, buff=0.8)\n \n self.play(FadeIn(labels_group), run_time=tracker.duration)\n \n self.wait(0.3)\n self.play(FadeOut(conv_formula), FadeOut(labels_group))\n \n # ============================================\n # VISUAL: Standard Convolution (The Problem)\n # ============================================\n with self.voiceover(\n text=\"Let us visualize this. Imagine we want to compute the output at time n equals 3. \"\n \"In standard convolution, the kernel looks at samples both before and after position n.\"\n ) as tracker:\n # Create a timeline\n timeline = NumberLine(\n x_range=[0, 7, 1],\n length=6,\n include_numbers=True,\n numbers_to_include=[0, 1, 2, 3, 4, 5, 6],\n font_size=20\n )\n timeline.to_edge(UP, buff=1)\n \n time_label = Text(\"Time index n\", font_size=20)\n time_label.next_to(timeline, DOWN, buff=0.2)\n \n self.play(Create(timeline), FadeIn(time_label), run_time=tracker.duration * 0.6)\n \n # Input signal squares\n input_vals = [2, 3, 1, 4, 2, 5, 3]\n input_squares = VGroup()\n for i, val in enumerate(input_vals):\n sq = Square(side_length=0.4, fill_color=color_input, fill_opacity=0.6)\n num = MathTex(str(val), font_size=16)\n group = VGroup(sq, num)\n group.move_to(timeline.n2p(i) + DOWN * 0.8)\n input_squares.add(group)\n \n input_label = MathTex(r\"x[n]\", font_size=24, color=color_input)\n input_label.next_to(input_squares, LEFT, buff=0.3)\n \n with self.voiceover(\n text=\"Here is our input signal x. Each square represents a sample at a specific time index.\"\n ) as tracker:\n self.play(FadeIn(input_label), run_time=tracker.duration * 0.3)\n self.play(AnimationGroup(*[FadeIn(sq) for sq in input_squares], lag_ratio=0.1), \n run_time=tracker.duration * 0.7)\n \n self.wait(0.3)\n \n # Show kernel centered at n=3\n kernel_size = 3\n center_idx = 3\n kernel_squares = VGroup()\n kernel_weights = [0.5, 1.0, 0.5]\n \n for i, w in enumerate(kernel_weights):\n idx = center_idx - 1 + i\n sq = Square(side_length=0.4, fill_color=color_kernel, fill_opacity=0.6)\n num = MathTex(str(w), font_size=16)\n group = VGroup(sq, num)\n group.move_to(timeline.n2p(idx) + DOWN * 0.8)\n kernel_squares.add(group)\n \n kernel_label = MathTex(r\"w\", font_size=24, color=color_kernel)\n kernel_label.next_to(kernel_squares, RIGHT, buff=0.3)\n \n # Highlight position n=3\n current_arrow = Arrow(\n timeline.n2p(center_idx) + UP * 0.3,\n timeline.n2p(center_idx) + UP * 0.8,\n color=YELLOW,\n buff=0\n )\n current_label = MathTex(r\"n=3\", font_size=20, color=YELLOW)\n current_label.next_to(current_arrow, UP, buff=0.1)\n \n with self.voiceover(\n text=\"To compute the output at n equals 3, a standard convolution kernel of size 3 \"\n \"would look at inputs from n equals 2, n equals 3, and n equals 4.\"\n ) as tracker:\n self.play(\n FadeIn(current_arrow), \n FadeIn(current_label),\n run_time=tracker.duration * 0.4\n )\n self.play(\n FadeIn(kernel_label),\n AnimationGroup(*[TransformFromCopy(input_squares[center_idx - 1 + i], kernel_squares[i]) \n for i in range(kernel_size)]),\n run_time=tracker.duration * 0.6\n )\n \n self.wait(0.3)\n \n # THE PROBLEM: Using future data\n future_brace = Brace(input_squares[4], DOWN, color=RED)\n future_text = Text(\"FUTURE data!\", font_size=16, color=RED)\n future_text.next_to(future_brace, DOWN, buff=0.1)\n \n with self.voiceover(\n text=\"But wait! At time n equals 3, we can access samples from n equals 2 and n equals 3, \"\n \"but n equals 4 is in the future. We should not be able to see it yet! \"\n \"This is the fundamental problem with standard convolution for prediction tasks.\"\n ) as tracker:\n self.play(\n Create(future_brace),\n FadeIn(future_text),\n run_time=tracker.duration\n )\n \n self.wait(0.5)\n self.play(\n FadeOut(timeline), FadeOut(time_label),\n FadeOut(input_squares), FadeOut(input_label),\n FadeOut(kernel_squares), FadeOut(kernel_label),\n FadeOut(current_arrow), FadeOut(current_label),\n FadeOut(future_brace), FadeOut(future_text)\n )\n \n # ============================================\n # CAUSAL CONSTRAINT INTRODUCTION\n # ============================================\n with self.voiceover(\n text=\"This is where the causal constraint comes in. \"\n \"A causal system is one where the output at any time depends only on present and past inputs, \"\n \"never on future inputs.\"\n ) as tracker:\n causal_title = Text(\"Causal Constraint\", font_size=40, color=YELLOW)\n causal_def = Text(\n \"Output depends only on present and past inputs\",\n font_size=24,\n color=GRAY\n )\n causal_def.next_to(causal_title, DOWN, buff=0.3)\n \n self.play(Write(causal_title), run_time=tracker.duration * 0.5)\n self.play(FadeIn(causal_def), run_time=tracker.duration * 0.5)\n \n self.wait(0.3)\n self.play(FadeOut(causal_title), FadeOut(causal_def))\n \n # ============================================\n # CAUSAL CONSTRAINT FORMULA\n # ============================================\n with self.voiceover(\n text=\"Mathematically, we enforce causality by requiring that the kernel weights are zero \"\n \"for all negative indices.\"\n ) as tracker:\n causal_formula = MathTex(\n r\"w[n] = 0 \\quad \\text{for} \\quad n < 0\",\n font_size=44,\n color=YELLOW\n )\n self.play(Write(causal_formula), run_time=tracker.duration)\n \n self.wait(0.3)\n \n with self.voiceover(\n text=\"This simple constraint ensures that when we compute the convolution, \"\n \"we never use input samples from the future.\"\n ) as tracker:\n # Add explanation\n explanation = Text(\n \"Kernel is zero for all negative time indices\",\n font_size=22,\n color=GRAY\n )\n explanation.next_to(causal_formula, DOWN, buff=0.5)\n self.play(FadeIn(explanation), run_time=tracker.duration)\n \n self.wait(0.3)\n self.play(FadeOut(causal_formula), FadeOut(explanation))\n \n # ============================================\n # VISUAL: Causal Convolution\n # ============================================\n with self.voiceover(\n text=\"Let us see causal convolution in action. We will use the same input signal, \"\n \"but now with a causal kernel.\"\n ) as tracker:\n timeline2 = NumberLine(\n x_range=[0, 7, 1],\n length=6,\n include_numbers=True,\n numbers_to_include=[0, 1, 2, 3, 4, 5, 6],\n font_size=20\n )\n timeline2.to_edge(UP, buff=1)\n \n time_label2 = Text(\"Time index n\", font_size=20)\n time_label2.next_to(timeline2, DOWN, buff=0.2)\n \n self.play(Create(timeline2), FadeIn(time_label2), run_time=tracker.duration)\n \n # Recreate input squares\n input_squares2 = VGroup()\n for i, val in enumerate(input_vals):\n sq = Square(side_length=0.4, fill_color=color_input, fill_opacity=0.6)\n num = MathTex(str(val), font_size=16)\n group = VGroup(sq, num)\n group.move_to(timeline2.n2p(i) + DOWN * 0.8)\n input_squares2.add(group)\n \n input_label2 = MathTex(r\"x[n]\", font_size=24, color=color_input)\n input_label2.next_to(input_squares2, LEFT, buff=0.3)\n \n self.play(FadeIn(input_label2), FadeIn(input_squares2))\n \n self.wait(0.3)\n \n # Show causal kernel - only looks at current and past\n center_idx2 = 3\n causal_kernel_squares = VGroup()\n causal_weights = [0.3, 0.4, 0.3] # Different weights for causal kernel\n \n for i, w in enumerate(causal_weights):\n idx = center_idx2 - 2 + i # Look at n-2, n-1, n (not n+1!)\n if idx >= 0:\n sq = Square(side_length=0.4, fill_color=color_kernel, fill_opacity=0.6)\n num = MathTex(str(w), font_size=16)\n group = VGroup(sq, num)\n group.move_to(timeline2.n2p(idx) + DOWN * 0.8)\n causal_kernel_squares.add(group)\n \n kernel_label2 = MathTex(r\"w_{\\text{causal}}\", font_size=24, color=color_kernel)\n kernel_label2.next_to(causal_kernel_squares, RIGHT, buff=0.3)\n \n current_arrow2 = Arrow(\n timeline2.n2p(center_idx2) + UP * 0.3,\n timeline2.n2p(center_idx2) + UP * 0.8,\n color=YELLOW,\n buff=0\n )\n current_label2 = MathTex(r\"n=3\", font_size=20, color=YELLOW)\n current_label2.next_to(current_arrow2, UP, buff=0.1)\n \n with self.voiceover(\n text=\"With a causal kernel centered at n equals 3, we only look at samples \"\n \"from n equals 1, n equals 2, and n equals 3. All these are in the past or present.\"\n ) as tracker:\n self.play(\n FadeIn(current_arrow2), \n FadeIn(current_label2),\n run_time=tracker.duration * 0.4\n )\n self.play(\n FadeIn(kernel_label2),\n AnimationGroup(*[FadeIn(sq) for sq in causal_kernel_squares]),\n run_time=tracker.duration * 0.6\n )\n \n self.wait(0.3)\n \n # Show the boundary clearly\n boundary_line = DashedLine(\n timeline2.n2p(center_idx2) + DOWN * 1.5,\n timeline2.n2p(center_idx2) + UP * 0.2,\n color=YELLOW\n )\n past_text = Text(\"Past & Present\", font_size=16, color=color_past)\n past_text.next_to(timeline2.n2p(1.5), DOWN, buff=1.5)\n \n with self.voiceover(\n text=\"The dashed line marks the present moment. Everything to the left is past or present, \"\n \"and can be used for prediction. Everything to the right is the future, and is inaccessible.\"\n ) as tracker:\n self.play(\n Create(boundary_line),\n FadeIn(past_text),\n run_time=tracker.duration\n )\n \n self.wait(0.5)\n self.play(\n FadeOut(timeline2), FadeOut(time_label2),\n FadeOut(input_squares2), FadeOut(input_label2),\n FadeOut(causal_kernel_squares), FadeOut(kernel_label2),\n FadeOut(current_arrow2), FadeOut(current_label2),\n FadeOut(boundary_line), FadeOut(past_text)\n )\n \n # ============================================\n # APPLICATION IN NEURAL NETWORKS\n # ============================================\n with self.voiceover(\n text=\"Causal convolutions are crucial in neural networks for sequential prediction. \"\n \"Let us see some key applications.\"\n ) as tracker:\n nn_title = Text(\"Applications in Neural Networks\", font_size=36)\n self.play(Write(nn_title), run_time=tracker.duration)\n \n self.wait(0.3)\n self.play(FadeOut(nn_title))\n \n # Applications list\n with self.voiceover(\n text=\"First, in language modeling and text generation, models must predict the next word \"\n \"without seeing future words in the sequence.\"\n ) as tracker:\n app1 = Text(\"1. Language Modeling\", font_size=28, color=BLUE)\n app1_desc = Text(\"Predict next word without seeing future text\", font_size=20, color=GRAY)\n app1_desc.next_to(app1, DOWN, buff=0.2, aligned_edge=LEFT)\n app1_group = VGroup(app1, app1_desc)\n app1_group.to_edge(UP, buff=1.5)\n \n self.play(Write(app1), run_time=tracker.duration * 0.5)\n self.play(FadeIn(app1_desc), run_time=tracker.duration * 0.5)\n \n self.wait(0.3)\n \n with self.voiceover(\n text=\"Second, in time series forecasting, we predict future values using only historical data.\"\n ) as tracker:\n app2 = Text(\"2. Time Series Forecasting\", font_size=28, color=GREEN)\n app2_desc = Text(\"Use only historical data to predict future values\", font_size=20, color=GRAY)\n app2_desc.next_to(app2, DOWN, buff=0.2, aligned_edge=LEFT)\n app2_group = VGroup(app2, app2_desc)\n app2_group.next_to(app1_group, DOWN, buff=0.5, aligned_edge=LEFT)\n \n self.play(Write(app2), run_time=tracker.duration * 0.5)\n self.play(FadeIn(app2_desc), run_time=tracker.duration * 0.5)\n \n self.wait(0.3)\n \n with self.voiceover(\n text=\"Third, in audio processing and speech synthesis, generating audio samples requires \"\n \"only past context to maintain causality.\"\n ) as tracker:\n app3 = Text(\"3. Audio & Speech Synthesis\", font_size=28, color=RED)\n app3_desc = Text(\"Generate audio using only past samples\", font_size=20, color=GRAY)\n app3_desc.next_to(app3, DOWN, buff=0.2, aligned_edge=LEFT)\n app3_group = VGroup(app3, app3_desc)\n app3_group.next_to(app2_group, DOWN, buff=0.5, aligned_edge=LEFT)\n \n self.play(Write(app3), run_time=tracker.duration * 0.5)\n self.play(FadeIn(app3_desc), run_time=tracker.duration * 0.5)\n \n self.wait(0.5)\n self.play(\n FadeOut(app1_group), \n FadeOut(app2_group), \n FadeOut(app3_group)\n )\n \n # ============================================\n # KEY BENEFITS\n # ============================================\n with self.voiceover(\n text=\"The key benefit of causal convolution is that it ensures the model makes predictions \"\n \"the same way humans do: by only considering what we already know.\"\n ) as tracker:\n benefit_title = Text(\"Why Causal Convolution Matters\", font_size=28, color=YELLOW)\n benefit_title.to_edge(UP, buff=2)\n \n benefits = VGroup(\n Text(\"✓ Prevents data leakage from the future\", font_size=22),\n Text(\"✓ Ensures realistic prediction scenarios\", font_size=22),\n Text(\"✓ Maintains temporal ordering integrity\", font_size=22)\n ).arrange(DOWN, buff=0.3, aligned_edge=LEFT)\n benefits.next_to(benefit_title, DOWN, buff=0.5)\n \n # Create a box around the benefits\n benefit_box = SurroundingRectangle(\n VGroup(benefit_title, benefits),\n fill_color=BLACK,\n fill_opacity=0.3,\n stroke_color=YELLOW,\n stroke_width=2,\n buff=0.3\n )\n \n self.play(Create(benefit_box), FadeIn(benefit_title), run_time=tracker.duration * 0.5)\n self.play(AnimationGroup(*[FadeIn(b) for b in benefits], lag_ratio=0.2), \n run_time=tracker.duration * 0.5)\n \n self.wait(0.5)\n self.play(FadeOut(benefit_box), FadeOut(benefit_title), FadeOut(benefits))\n \n # ============================================\n # SUMMARY\n # ============================================\n with self.voiceover(\n text=\"To summarize: Causal convolution modifies standard convolution by ensuring \"\n \"the kernel only accesses present and past data. This is essential for any \"\n \"prediction task where using future information would be cheating.\"\n ) as tracker:\n summary_title = Text(\"Summary\", font_size=40, color=YELLOW)\n summary_title.to_edge(UP, buff=1)\n \n summary_points = VGroup(\n MathTex(r\"\\bullet\\ \\text{Causal: } w[n] = 0 \\text{ for } n < 0\", font_size=28),\n MathTex(r\"\\bullet\\ \\text{Output depends only on } x[k] \\text{ where } k \\leq n\", font_size=28),\n MathTex(r\"\\bullet\\ \\text{Essential for real-time prediction}\", font_size=28)\n ).arrange(DOWN, buff=0.4, aligned_edge=LEFT)\n summary_points.next_to(summary_title, DOWN, buff=0.5)\n \n self.play(Write(summary_title), run_time=tracker.duration * 0.3)\n self.play(AnimationGroup(*[Write(p) for p in summary_points], lag_ratio=0.2),\n run_time=tracker.duration * 0.7)\n \n self.wait(0.5)\n \n with self.voiceover(\n text=\"By applying causal constraints, you can build neural networks that make \"\n \"accurate, realistic predictions without looking ahead. This improves \"\n \"model reliability and ensures your predictions are practical for real-world deployment.\"\n ) as tracker:\n closing = Text(\n \"Build reliable predictive models with causal convolutions!\",\n font_size=28,\n color=GREEN\n )\n closing.next_to(summary_points, DOWN, buff=0.8)\n self.play(FadeIn(closing), run_time=tracker.duration)\n \n self.wait(1)\n```", "rejected": "```python\nfrom manim import *\n\nclass CausalConstraintInConvolutions(Scene):\n\n def construct(self):\n color_input = BLUE\n color_kernel = RED\n color_output = GREEN\n color_past = YELLOW\n color_future = GRAY\n title = Text('Causal Constraint in Convolutions', font_size=48)\n subtitle = Text('Subject: AI', font_size=28, color=GRAY)\n subtitle.next_to(title, DOWN, buff=0.5)\n self.play(Write(title), run_time=2.0 * 0.5)\n self.play(FadeIn(subtitle), run_time=2.0 * 0.5)\n self.wait(0.5)\n self.play(FadeOut(title), FadeOut(subtitle))\n conv_formula = MathTex('y[n] = (x * w)[n] = \\\\sum_{m=-\\\\infty}^{\\\\infty} x[m] \\\\, w[n - m]', font_size=40)\n self.play(Write(conv_formula), run_time=2.0)\n self.wait(0.3)\n x_label = MathTex('x = \\\\text{input}', font_size=24, color=color_input)\n w_label = MathTex('w = \\\\text{kernel}', font_size=24, color=color_kernel)\n y_label = MathTex('y = \\\\text{output}', font_size=24, color=color_output)\n labels_group = VGroup(x_label, w_label, y_label).arrange(RIGHT, buff=1)\n labels_group.next_to(conv_formula, DOWN, buff=0.8)\n self.play(FadeIn(labels_group), run_time=2.0)\n self.wait(0.3)\n self.play(FadeOut(conv_formula), FadeOut(labels_group))\n timeline = NumberLine(x_range=[0, 7, 1], length=6, include_numbers=True, numbers_to_include=[0, 1, 2, 3, 4, 5, 6], font_size=20)\n timeline.to_edge(UP, buff=1)\n time_label = Text('Time index n', font_size=20)\n time_label.next_to(timeline, DOWN, buff=0.2)\n self.play(Create(timeline), FadeIn(time_label), run_time=2.0 * 0.6)\n input_vals = [2, 3, 1, 4, 2, 5, 3]\n input_squares = VGroup()\n for i, val in enumerate(input_vals):\n sq = Square(side_length=0.4, fill_color=color_input, fill_opacity=0.6)\n num = MathTex(str(val), font_size=16)\n group = VGroup(sq, num)\n group.move_to(timeline.n2p(i) + DOWN * 0.8)\n input_squares.add(group)\n input_label = MathTex('x[n]', font_size=24, color=color_input)\n input_label.next_to(input_squares, LEFT, buff=0.3)\n self.play(FadeIn(input_label), run_time=2.0 * 0.3)\n self.play(AnimationGroup(*[FadeIn(sq) for sq in input_squares], lag_ratio=0.1), run_time=2.0 * 0.7)\n self.wait(0.3)\n kernel_size = 3\n center_idx = 3\n kernel_squares = VGroup()\n kernel_weights = [0.5, 1.0, 0.5]\n for i, w in enumerate(kernel_weights):\n idx = center_idx - 1 + i\n sq = Square(side_length=0.4, fill_color=color_kernel, fill_opacity=0.6)\n num = MathTex(str(w), font_size=16)\n group = VGroup(sq, num)\n group.move_to(timeline.n2p(idx) + DOWN * 0.8)\n kernel_squares.add(group)\n kernel_label = MathTex('w', font_size=24, color=color_kernel)\n kernel_label.next_to(kernel_squares, RIGHT, buff=0.3)\n current_arrow = Arrow(timeline.n2p(center_idx) + UP * 0.3, timeline.n2p(center_idx) + UP * 0.8, color=YELLOW, buff=0)\n current_label = MathTex('n=3', font_size=20, color=YELLOW)\n current_label.next_to(current_arrow, UP, buff=0.1)\n self.play(FadeIn(current_arrow), FadeIn(current_label), run_time=2.0 * 0.4)\n self.play(FadeIn(kernel_label), AnimationGroup(*[TransformFromCopy(input_squares[center_idx - 1 + i], kernel_squares[i]) for i in range(kernel_size)]), run_time=2.0 * 0.6)\n self.wait(0.3)\n future_brace = Brace(input_squares[4], DOWN, color=RED)\n future_text = Text('FUTURE data!', font_size=16, color=RED)\n future_text.next_to(future_brace, DOWN, buff=0.1)\n self.play(Create(future_brace), FadeIn(future_text), run_time=2.0)\n self.wait(0.5)\n self.play(FadeOut(timeline), FadeOut(time_label), FadeOut(input_squares), FadeOut(input_label), FadeOut(kernel_squares), FadeOut(kernel_label), FadeOut(current_arrow), FadeOut(current_label), FadeOut(future_brace), FadeOut(future_text))\n causal_title = Text('Causal Constraint', font_size=40, color=YELLOW)\n causal_def = Text('Output depends only on present and past inputs', font_size=24, color=GRAY)\n causal_def.next_to(causal_title, DOWN, buff=0.3)\n self.play(Write(causal_title), run_time=2.0 * 0.5)\n self.play(FadeIn(causal_def), run_time=2.0 * 0.5)\n self.wait(0.3)\n self.play(FadeOut(causal_title), FadeOut(causal_def))\n causal_formula = MathTex('w[n] = 0 \\\\quad \\\\text{for} \\\\quad n < 0', font_size=44, color=YELLOW)\n self.play(Write(causal_formula), run_time=2.0)\n self.wait(0.3)\n explanation = Text('Kernel is zero for all negative time indices', font_size=22, color=GRAY)\n explanation.next_to(causal_formula, DOWN, buff=0.5)\n self.play(FadeIn(explanation), run_time=2.0)\n self.wait(0.3)\n self.play(FadeOut(causal_formula), FadeOut(explanation))\n timeline2 = NumberLine(x_range=[0, 7, 1], length=6, include_numbers=True, numbers_to_include=[0, 1, 2, 3, 4, 5, 6], font_size=20)\n timeline2.to_edge(UP, buff=1)\n time_label2 = Text('Time index n', font_size=20)\n time_label2.next_to(timeline2, DOWN, buff=0.2)\n self.play(Create(timeline2), FadeIn(time_label2), run_time=2.0)\n input_squares2 = VGroup()\n for i, val in enumerate(input_vals):\n sq = Square(side_length=0.4, fill_color=color_input, fill_opacity=0.6)\n num = MathTex(str(val), font_size=16)\n group = VGroup(sq, num)\n group.move_to(timeline2.n2p(i) + DOWN * 0.8)\n input_squares2.add(group)\n input_label2 = MathTex('x[n]', font_size=24, color=color_input)\n input_label2.next_to(input_squares2, LEFT, buff=0.3)\n self.play(FadeIn(input_label2), FadeIn(input_squares2))\n self.wait(0.3)\n center_idx2 = 3\n causal_kernel_squares = VGroup()\n causal_weights = [0.3, 0.4, 0.3]\n for i, w in enumerate(causal_weights):\n idx = center_idx2 - 2 + i\n if idx >= 0:\n sq = Square(side_length=0.4, fill_color=color_kernel, fill_opacity=0.6)\n num = MathTex(str(w), font_size=16)\n group = VGroup(sq, num)\n group.move_to(timeline2.n2p(idx) + DOWN * 0.8)\n causal_kernel_squares.add(group)\n kernel_label2 = MathTex('w_{\\\\text{causal}}', font_size=24, color=color_kernel)\n kernel_label2.next_to(causal_kernel_squares, RIGHT, buff=0.3)\n current_arrow2 = Arrow(timeline2.n2p(center_idx2) + UP * 0.3, timeline2.n2p(center_idx2) + UP * 0.8, color=YELLOW, buff=0)\n current_label2 = MathTex('n=3', font_size=20, color=YELLOW)\n current_label2.next_to(current_arrow2, UP, buff=0.1)\n self.play(FadeIn(current_arrow2), FadeIn(current_label2), run_time=2.0 * 0.4)\n self.play(FadeIn(kernel_label2), AnimationGroup(*[FadeIn(sq) for sq in causal_kernel_squares]), run_time=2.0 * 0.6)\n self.wait(0.3)\n boundary_line = DashedLine(timeline2.n2p(center_idx2) + DOWN * 1.5, timeline2.n2p(center_idx2) + UP * 0.2, color=YELLOW)\n past_text = Text('Past & Present', font_size=16, color=color_past)\n past_text.next_to(timeline2.n2p(1.5), DOWN, buff=1.5)\n self.play(Create(boundary_line), FadeIn(past_text), run_time=2.0)\n self.wait(0.5)\n self.play(FadeOut(timeline2), FadeOut(time_label2), FadeOut(input_squares2), FadeOut(input_label2), FadeOut(causal_kernel_squares), FadeOut(kernel_label2), FadeOut(current_arrow2), FadeOut(current_label2), FadeOut(boundary_line), FadeOut(past_text))\n nn_title = Text('Applications in Neural Networks', font_size=36)\n self.play(Write(nn_title), run_time=2.0)\n self.wait(0.3)\n self.play(FadeOut(nn_title))\n app1 = Text('1. Language Modeling', font_size=28, color=BLUE)\n app1_desc = Text('Predict next word without seeing future text', font_size=20, color=GRAY)\n app1_desc.next_to(app1, DOWN, buff=0.2, aligned_edge=LEFT)\n app1_group = VGroup(app1, app1_desc)\n app1_group.to_edge(UP, buff=1.5)\n self.play(Write(app1), run_time=2.0 * 0.5)\n self.play(FadeIn(app1_desc), run_time=2.0 * 0.5)\n self.wait(0.3)\n app2 = Text('2. Time Series Forecasting', font_size=28, color=GREEN)\n app2_desc = Text('Use only historical data to predict future values', font_size=20, color=GRAY)\n app2_desc.next_to(app2, DOWN, buff=0.2, aligned_edge=LEFT)\n app2_group = VGroup(app2, app2_desc)\n app2_group.next_to(app1_group, DOWN, buff=0.5, aligned_edge=LEFT)\n self.play(Write(app2), run_time=2.0 * 0.5)\n self.play(FadeIn(app2_desc), run_time=2.0 * 0.5)\n self.wait(0.3)\n app3 = Text('3. Audio & Speech Synthesis', font_size=28, color=RED)\n app3_desc = Text('Generate audio using only past samples', font_size=20, color=GRAY)\n app3_desc.next_to(app3, DOWN, buff=0.2, aligned_edge=LEFT)\n app3_group = VGroup(app3, app3_desc)\n app3_group.next_to(app2_group, DOWN, buff=0.5, aligned_edge=LEFT)\n self.play(Write(app3), run_time=2.0 * 0.5)\n self.play(FadeIn(app3_desc), run_time=2.0 * 0.5)\n self.wait(0.5)\n self.play(FadeOut(app1_group), FadeOut(app2_group), FadeOut(app3_group))\n benefit_title = Text('Why Causal Convolution Matters', font_size=28, color=YELLOW)\n benefit_title.to_edge(UP, buff=2)\n benefits = VGroup(Text('✓ Prevents data leakage from the future', font_size=22), Text('✓ Ensures realistic prediction scenarios', font_size=22), Text('✓ Maintains temporal ordering integrity', font_size=22)).arrange(DOWN, buff=0.3, aligned_edge=LEFT)\n benefits.next_to(benefit_title, DOWN, buff=0.5)\n benefit_box = SurroundingRectangle(VGroup(benefit_title, benefits), fill_color=BLACK, fill_opacity=0.3, stroke_color=YELLOW, stroke_width=2, buff=0.3)\n self.play(Create(benefit_box), FadeIn(benefit_title), run_time=2.0 * 0.5)\n self.play(AnimationGroup(*[FadeIn(b) for b in benefits], lag_ratio=0.2), run_time=2.0 * 0.5)\n self.wait(0.5)\n self.play(FadeOut(benefit_box), FadeOut(benefit_title), FadeOut(benefits))\n summary_title = Text('Summary', font_size=40, color=YELLOW)\n summary_title.to_edge(UP, buff=1)\n summary_points = VGroup(MathTex('\\\\bullet\\\\ \\\\text{Causal: } w[n] = 0 \\\\text{ for } n < 0', font_size=28), MathTex('\\\\bullet\\\\ \\\\text{Output depends only on } x[k] \\\\text{ where } k \\\\leq n', font_size=28), MathTex('\\\\bullet\\\\ \\\\text{Essential for real-time prediction}', font_size=28)).arrange(DOWN, buff=0.4, aligned_edge=LEFT)\n summary_points.next_to(summary_title, DOWN, buff=0.5)\n self.play(Write(summary_title), run_time=2.0 * 0.3)\n self.play(AnimationGroup(*[Write(p) for p in summary_points], lag_ratio=0.2), run_time=2.0 * 0.7)\n self.wait(0.5)\n closing = Text('Build reliable predictive models with causal convolutions!', font_size=28, color=GREEN)\n closing.next_to(summary_points, DOWN, buff=0.8)\n self.play(FadeIn(closing), run_time=2.0)\n self.wait(1)\n```", "category": "narrated_pedagogical_preference", "source": "nabin2004/manim-narrated-dpo-400"} +{"system": "You are an expert Manim Community Edition (ManimCE v0.19+) Python developer and mathematical animator. Given a user request, first plan the spatial layout, coordinate bounds, timing, and pedagogical flow inside ... tags (when reasoning is helpful), and then output a complete, runnable, self-contained ManimCE Python script using `from manim import *`. Never use deprecated ManimGL (`manimlib`) methods like `ShowCreation`, `TexMobject`, `TextMobject`, or `axes.get_graph`; always use modern ManimCE APIs (`Create`, `MathTex`, `Tex`, `Text`, `axes.plot`) and prevent visual overlap using `.to_edge()`, `.next_to()`, and `FadeOut`.", "prompt": "I'm teaching a graduate course on deep learning and want a toggle between model.train() and model.eval(), highlighting BN behavior: batch statistics in train and running statistics in eval. Visualize a small network with BatchNorm, animate batch mean/var versus running mean/var, and show how outputs differ when switching modes. Add a side-by-side comparison and a caption explaining why BN uses different statistics.", "chosen": "```python\nfrom manim import *\nfrom manim_voiceover import VoiceoverScene\nfrom manim_voiceover.services.gtts import GTTSService\nimport numpy as np\n\nclass BatchNormBehaviorVisualization(VoiceoverScene):\n def construct(self):\n self.set_speech_service(\n GTTSService(voice=\"alba\", cache_dir=\"voiceover_cache\")\n )\n \n # Title\n title = Text(\"Batch Normalization\", font_size=48, color=BLUE)\n subtitle = Text(\"Stabilizing Deep Neural Networks\", font_size=28, color=GRAY)\n title_group = VGroup(title, subtitle).arrange(DOWN, buff=0.3)\n \n with self.voiceover(text=\"Imagine you are training a neural network on a complex dataset, overwhelmed by varying scales of features. How do you ensure each feature contributes equally? That is where Batch Normalization comes in! Today, you will learn how BatchNorm stabilizes and accelerates training.\") as tracker:\n self.play(Write(title), run_time=tracker.duration * 0.6)\n self.play(FadeIn(subtitle), run_time=tracker.duration * 0.4)\n \n self.wait(0.5)\n self.play(FadeOut(title_group))\n \n # Section 1: The Problem - Feature Scale Variation\n problem_title = Text(\"The Problem: Feature Scale Variation\", font_size=36, color=RED)\n problem_title.to_edge(UP)\n \n with self.voiceover(text=\"First, let us understand the problem. Different features often have vastly different scales, which can destabilize training.\") as tracker:\n self.play(Write(problem_title), run_time=tracker.duration)\n \n # Create axes for feature distribution visualization\n axes = Axes(\n x_range=[-3, 15, 3],\n y_range=[0, 0.8, 0.2],\n x_length=10,\n y_length=4,\n axis_config={\"include_tip\": False},\n )\n axes.shift(DOWN * 0.5)\n \n x_label = MathTex(r\"\text{Feature Value}\", font_size=24).next_to(axes.x_axis, DOWN)\n y_label = MathTex(r\"\text{Density}\", font_size=24).next_to(axes.y_axis, LEFT).rotate(90 * DEGREES)\n \n with self.voiceover(text=\"Here we have two features with very different distributions.\") as tracker:\n self.play(Create(axes), Write(x_label), Write(y_label), run_time=tracker.duration * 0.6)\n \n # Create Gaussian distributions using plot with lambda functions\n curve_1 = axes.plot(\n lambda x: 0.4 * np.exp(-0.5 * ((x - 2) / 1.5) ** 2),\n x_range=[-3, 5],\n color=BLUE\n )\n \n curve_2 = axes.plot(\n lambda x: 0.2 * np.exp(-0.5 * ((x - 10) / 2) ** 2),\n x_range=[4, 16],\n color=ORANGE\n )\n \n area_1 = axes.get_area(curve_1, x_range=[-3, 5], color=BLUE, opacity=0.3)\n area_2 = axes.get_area(curve_2, x_range=[4, 16], color=ORANGE, opacity=0.3)\n \n legend = VGroup(\n VGroup(Dot(color=BLUE), Text(\"Feature A (Small Scale)\", font_size=20)).arrange(RIGHT, buff=0.2),\n VGroup(Dot(color=ORANGE), Text(\"Feature B (Large Scale)\", font_size=20)).arrange(RIGHT, buff=0.2),\n ).arrange(DOWN, buff=0.2, aligned_edge=LEFT)\n legend.to_corner(UR).shift(LEFT * 0.5 + DOWN * 0.5)\n \n with self.voiceover(text=\"Feature A in blue has a small scale with values around 2. Feature B in orange has a large scale centered at 10.\") as tracker:\n self.play(\n Create(curve_1),\n FadeIn(area_1),\n Create(curve_2),\n FadeIn(area_2),\n FadeIn(legend),\n run_time=tracker.duration\n )\n \n # Show gradient arrows\n grad_arrow_1 = Arrow(axes.c2p(2, 0.4), axes.c2p(3, 0.4), color=GREEN, buff=0)\n grad_arrow_2 = Arrow(axes.c2p(10, 0.2), axes.c2p(12, 0.2), color=GREEN, buff=0)\n \n grad_label = Text(\"Uneven Gradients!\", font_size=24, color=GREEN)\n grad_label.next_to(axes, DOWN, buff=0.8)\n \n with self.voiceover(text=\"This causes uneven gradients. The large scale feature dominates, making optimization difficult and slow.\") as tracker:\n self.play(\n GrowArrow(grad_arrow_1),\n GrowArrow(grad_arrow_2),\n FadeIn(grad_label),\n run_time=tracker.duration\n )\n \n self.wait(0.5)\n self.play(FadeOut(problem_title, curve_1, curve_2, area_1, area_2, legend, grad_arrow_1, grad_arrow_2, grad_label))\n \n # Section 2: The BatchNorm Solution\n solution_title = Text(\"BatchNorm Solution\", font_size=36, color=GREEN)\n solution_title.to_edge(UP)\n \n with self.voiceover(text=\"Batch Normalization solves this by normalizing inputs to have zero mean and unit variance.\") as tracker:\n self.play(Write(solution_title), run_time=tracker.duration)\n \n # Formula\n formula = MathTex(\n r\"\\hat{x} = \\frac{x - \\mu_B}{\\sqrt{\\sigma_B^2 + \\epsilon}}\",\n font_size=36\n )\n formula.shift(UP * 1.5)\n \n with self.voiceover(text=\"Here is the formula. We subtract the batch mean and divide by the standard deviation.\") as tracker:\n self.play(Write(formula), run_time=tracker.duration)\n \n # Show animated dots representing batch samples\n np.random.seed(123)\n batch_size = 20\n \n # Generate batch samples for Feature A\n samples_a = np.random.normal(2, 1.5, batch_size)\n samples_b = np.random.normal(10, 2, batch_size)\n \n dots_a = VGroup(*[\n Dot(axes.c2p(x, 0.05), color=BLUE, radius=0.08)\n for x in samples_a if -3 <= x <= 5\n ])\n \n dots_b = VGroup(*[\n Dot(axes.c2p(x, 0.05), color=ORANGE, radius=0.08)\n for x in samples_b if 4 <= x <= 16\n ])\n \n batch_label = Text(\"Batch Samples\", font_size=24, color=WHITE)\n batch_label.next_to(axes, DOWN, buff=0.5)\n \n with self.voiceover(text=\"Consider a batch of samples from each feature.\") as tracker:\n self.play(\n FadeIn(dots_a),\n FadeIn(dots_b),\n FadeIn(batch_label),\n run_time=tracker.duration * 0.7\n )\n \n # Calculate and show mean\n mean_a = np.mean(samples_a)\n mean_b = np.mean(samples_b)\n \n mean_line_a = DashedLine(\n axes.c2p(mean_a, 0),\n axes.c2p(mean_a, 0.5),\n color=YELLOW\n )\n mean_line_b = DashedLine(\n axes.c2p(mean_b, 0),\n axes.c2p(mean_b, 0.5),\n color=YELLOW\n )\n \n mean_label = MathTex(r\"\\mu_B\", font_size=24, color=YELLOW)\n mean_label_a = mean_label.copy().next_to(mean_line_a, UP)\n mean_label_b = mean_label.copy().next_to(mean_line_b, UP)\n \n with self.voiceover(text=\"First, compute the batch mean for each feature.\") as tracker:\n self.play(\n Create(mean_line_a),\n Create(mean_line_b),\n FadeIn(mean_label_a),\n FadeIn(mean_label_b),\n run_time=tracker.duration\n )\n \n # Animate centering (subtract mean)\n centered_dots_a = VGroup(*[\n Dot(axes.c2p(x - mean_a + 6, 0.05), color=BLUE, radius=0.08)\n for x in samples_a if -3 <= x <= 5\n ])\n \n centered_dots_b = VGroup(*[\n Dot(axes.c2p(x - mean_b + 6, 0.05), color=ORANGE, radius=0.08)\n for x in samples_b if 4 <= x <= 16\n ])\n \n shift_label = Text(\"Subtract Mean → Center at Origin\", font_size=24, color=WHITE)\n shift_label.next_to(axes, DOWN, buff=0.5)\n \n with self.voiceover(text=\"Subtract the mean to center both distributions around zero.\") as tracker:\n self.play(\n FadeOut(mean_line_a, mean_line_b, mean_label_a, mean_label_b),\n Transform(dots_a, centered_dots_a),\n Transform(dots_b, centered_dots_b),\n ReplacementTransform(batch_label, shift_label),\n run_time=tracker.duration\n )\n \n # Show the normalization to unit variance\n std_a = np.std(samples_a)\n std_b = np.std(samples_b)\n \n # Scale dots to unit variance\n normalized_dots_a = VGroup(*[\n Dot(axes.c2p(((x - mean_a) / std_a) * 1.5 + 6, 0.05), color=BLUE, radius=0.08)\n for x in samples_a if -3 <= x <= 5\n ])\n \n normalized_dots_b = VGroup(*[\n Dot(axes.c2p(((x - mean_b) / std_b) * 1.5 + 6, 0.05), color=ORANGE, radius=0.08)\n for x in samples_b if 4 <= x <= 16\n ])\n \n norm_label = Text(\"Divide by Std → Unit Variance\", font_size=24, color=WHITE)\n norm_label.next_to(axes, DOWN, buff=0.5)\n \n with self.voiceover(text=\"Then divide by the standard deviation to achieve unit variance. Notice both features now have similar distributions!\") as tracker:\n self.play(\n Transform(dots_a, normalized_dots_a),\n Transform(dots_b, normalized_dots_b),\n ReplacementTransform(shift_label, norm_label),\n run_time=tracker.duration\n )\n \n self.wait(0.5)\n self.play(FadeOut(solution_title, formula, dots_a, dots_b, norm_label, axes, x_label, y_label))\n \n # Section 3: Learnable Parameters (Gamma and Beta)\n params_title = Text(\"Learnable Parameters\", font_size=36, color=PURPLE)\n params_title.to_edge(UP)\n \n with self.voiceover(text=\"But wait, we do not want to lose the representational power. BatchNorm introduces learnable parameters gamma and beta.\") as tracker:\n self.play(Write(params_title), run_time=tracker.duration)\n \n # Final BatchNorm formula with gamma and beta\n full_formula = MathTex(\n r\"y = \\gamma \\cdot \\hat{x} + \\beta\",\n font_size=44\n )\n full_formula.shift(UP * 1)\n \n gamma_beta_text = VGroup(\n Text(\"γ (gamma): Scale parameter\", font_size=24, color=GREEN),\n Text(\"β (beta): Shift parameter\", font_size=24, color=BLUE),\n ).arrange(DOWN, buff=0.3, aligned_edge=LEFT)\n gamma_beta_text.next_to(full_formula, DOWN, buff=0.5)\n \n with self.voiceover(text=\"The network learns optimal scale and shift values for each layer. This allows it to recover the original distribution if needed.\") as tracker:\n self.play(Write(full_formula), run_time=tracker.duration * 0.5)\n self.play(FadeIn(gamma_beta_text), run_time=tracker.duration * 0.5)\n \n # Visual representation\n axes2 = Axes(\n x_range=[-3, 9, 2],\n y_range=[0, 0.8, 0.2],\n x_length=8,\n y_length=3,\n axis_config={\"include_tip\": False},\n )\n axes2.shift(DOWN * 1.5)\n \n # Standard normal\n curve_std = axes2.plot(\n lambda x: 0.4 * np.exp(-0.5 * (x - 3) ** 2),\n x_range=[0, 6],\n color=GRAY\n )\n \n # Scaled and shifted\n curve_transformed = axes2.plot(\n lambda x: 0.27 * np.exp(-0.5 * ((x - 4) / 1.5) ** 2),\n x_range=[1, 7],\n color=PURPLE\n )\n \n with self.voiceover(text=\"Here, the gray curve is the standardized input. The purple curve shows how gamma scales and beta shifts it to the optimal distribution.\") as tracker:\n self.play(\n Create(axes2),\n Create(curve_std),\n run_time=tracker.duration * 0.6\n )\n self.play(Create(curve_transformed), run_time=tracker.duration * 0.4)\n \n # Arrow showing transformation\n transform_arrow = Arrow(\n axes2.c2p(3, 0.3),\n axes2.c2p(4, 0.3),\n color=YELLOW,\n buff=0.1\n )\n transform_label = Text(\"γ·x + β\", font_size=20, color=YELLOW)\n transform_label.next_to(transform_arrow, UP, buff=0.1)\n \n with self.voiceover(text=\"The network learns to transform the standardized distribution for optimal performance.\") as tracker:\n self.play(\n GrowArrow(transform_arrow),\n FadeIn(transform_label),\n run_time=tracker.duration\n )\n \n self.wait(0.5)\n self.play(FadeOut(params_title, full_formula, gamma_beta_text, axes2, curve_std, curve_transformed, transform_arrow, transform_label))\n \n # Section 4: Benefits Summary\n benefits_title = Text(\"Key Benefits\", font_size=40, color=GREEN)\n benefits_title.to_edge(UP)\n \n benefits = VGroup(\n VGroup(\n Circle(radius=0.15, color=BLUE, fill_opacity=1),\n Text(\"Faster Training Convergence\", font_size=26)\n ).arrange(RIGHT, buff=0.3),\n VGroup(\n Circle(radius=0.15, color=GREEN, fill_opacity=1),\n Text(\"Higher Learning Rates Possible\", font_size=26)\n ).arrange(RIGHT, buff=0.3),\n VGroup(\n Circle(radius=0.15, color=ORANGE, fill_opacity=1),\n Text(\"Reduces Internal Covariate Shift\", font_size=26)\n ).arrange(RIGHT, buff=0.3),\n VGroup(\n Circle(radius=0.15, color=PURPLE, fill_opacity=1),\n Text(\"Acts as Regularization\", font_size=26)\n ).arrange(RIGHT, buff=0.3),\n ).arrange(DOWN, buff=0.4, aligned_edge=LEFT)\n benefits.shift(DOWN * 0.5)\n \n with self.voiceover(text=\"To summarize, BatchNorm provides four key benefits. First, faster training convergence.\") as tracker:\n self.play(Write(benefits_title), run_time=tracker.duration * 0.3)\n self.play(FadeIn(benefits[0]), run_time=tracker.duration * 0.35)\n \n with self.voiceover(text=\"Second, you can use higher learning rates.\") as tracker:\n self.play(FadeIn(benefits[1]), run_time=tracker.duration)\n \n with self.voiceover(text=\"Third, it reduces internal covariate shift.\") as tracker:\n self.play(FadeIn(benefits[2]), run_time=tracker.duration)\n \n with self.voiceover(text=\"And fourth, it acts as a regularizer, reducing overfitting.\") as tracker:\n self.play(FadeIn(benefits[3]), run_time=tracker.duration)\n \n # Final takeaway\n takeaway_box = SurroundingRectangle(benefits, color=YELLOW, buff=0.3)\n takeaway = Text(\"BatchNorm: Normalize → Learn → Optimize\", font_size=28, color=YELLOW)\n takeaway.next_to(takeaway_box, DOWN, buff=0.3)\n \n with self.voiceover(text=\"Remember, BatchNorm normalizes inputs, learns optimal transformations, and enables faster, more stable training.\") as tracker:\n self.play(\n Create(takeaway_box),\n FadeIn(takeaway),\n run_time=tracker.duration\n )\n \n self.wait(1)\n self.play(FadeOut(benefits_title, benefits, takeaway_box, takeaway))\n \n # End\n end_text = Text(\"Thanks for watching!\", font_size=40, color=BLUE)\n with self.voiceover(text=\"Thanks for watching!\") as tracker:\n self.play(Write(end_text), run_time=tracker.duration)\n \n self.wait(1)\n```", "rejected": "```python\nfrom manim import *\nimport numpy as np\n\nclass BatchNormBehaviorVisualization(Scene):\n\n def construct(self):\n title = Text('Batch Normalization', font_size=48, color=BLUE)\n subtitle = Text('Stabilizing Deep Neural Networks', font_size=28, color=GRAY)\n title_group = VGroup(title, subtitle).arrange(DOWN, buff=0.3)\n self.play(Write(title), run_time=2.0 * 0.6)\n self.play(FadeIn(subtitle), run_time=2.0 * 0.4)\n self.wait(0.5)\n self.play(FadeOut(title_group))\n problem_title = Text('The Problem: Feature Scale Variation', font_size=36, color=RED)\n problem_title.to_edge(UP)\n self.play(Write(problem_title), run_time=2.0)\n axes = Axes(x_range=[-3, 15, 3], y_range=[0, 0.8, 0.2], x_length=10, y_length=4, axis_config={'include_tip': False})\n axes.shift(DOWN * 0.5)\n x_label = MathTex('\\text{Feature Value}', font_size=24).next_to(axes.x_axis, DOWN)\n y_label = MathTex('\\text{Density}', font_size=24).next_to(axes.y_axis, LEFT).rotate(90 * DEGREES)\n self.play(Create(axes), Write(x_label), Write(y_label), run_time=2.0 * 0.6)\n curve_1 = axes.plot(lambda x: 0.4 * np.exp(-0.5 * ((x - 2) / 1.5) ** 2), x_range=[-3, 5], color=BLUE)\n curve_2 = axes.plot(lambda x: 0.2 * np.exp(-0.5 * ((x - 10) / 2) ** 2), x_range=[4, 16], color=ORANGE)\n area_1 = axes.get_area(curve_1, x_range=[-3, 5], color=BLUE, opacity=0.3)\n area_2 = axes.get_area(curve_2, x_range=[4, 16], color=ORANGE, opacity=0.3)\n legend = VGroup(VGroup(Dot(color=BLUE), Text('Feature A (Small Scale)', font_size=20)).arrange(RIGHT, buff=0.2), VGroup(Dot(color=ORANGE), Text('Feature B (Large Scale)', font_size=20)).arrange(RIGHT, buff=0.2)).arrange(DOWN, buff=0.2, aligned_edge=LEFT)\n legend.to_corner(UR).shift(LEFT * 0.5 + DOWN * 0.5)\n self.play(Create(curve_1), FadeIn(area_1), Create(curve_2), FadeIn(area_2), FadeIn(legend), run_time=2.0)\n grad_arrow_1 = Arrow(axes.c2p(2, 0.4), axes.c2p(3, 0.4), color=GREEN, buff=0)\n grad_arrow_2 = Arrow(axes.c2p(10, 0.2), axes.c2p(12, 0.2), color=GREEN, buff=0)\n grad_label = Text('Uneven Gradients!', font_size=24, color=GREEN)\n grad_label.next_to(axes, DOWN, buff=0.8)\n self.play(GrowArrow(grad_arrow_1), GrowArrow(grad_arrow_2), FadeIn(grad_label), run_time=2.0)\n self.wait(0.5)\n self.play(FadeOut(problem_title, curve_1, curve_2, area_1, area_2, legend, grad_arrow_1, grad_arrow_2, grad_label))\n solution_title = Text('BatchNorm Solution', font_size=36, color=GREEN)\n solution_title.to_edge(UP)\n self.play(Write(solution_title), run_time=2.0)\n formula = MathTex('\\\\hat{x} = \\\\frac{x - \\\\mu_B}{\\\\sqrt{\\\\sigma_B^2 + \\\\epsilon}}', font_size=36)\n formula.shift(UP * 1.5)\n self.play(Write(formula), run_time=2.0)\n np.random.seed(123)\n batch_size = 20\n samples_a = np.random.normal(2, 1.5, batch_size)\n samples_b = np.random.normal(10, 2, batch_size)\n dots_a = VGroup(*[Dot(axes.c2p(x, 0.05), color=BLUE, radius=0.08) for x in samples_a if -3 <= x <= 5])\n dots_b = VGroup(*[Dot(axes.c2p(x, 0.05), color=ORANGE, radius=0.08) for x in samples_b if 4 <= x <= 16])\n batch_label = Text('Batch Samples', font_size=24, color=WHITE)\n batch_label.next_to(axes, DOWN, buff=0.5)\n self.play(FadeIn(dots_a), FadeIn(dots_b), FadeIn(batch_label), run_time=2.0 * 0.7)\n mean_a = np.mean(samples_a)\n mean_b = np.mean(samples_b)\n mean_line_a = DashedLine(axes.c2p(mean_a, 0), axes.c2p(mean_a, 0.5), color=YELLOW)\n mean_line_b = DashedLine(axes.c2p(mean_b, 0), axes.c2p(mean_b, 0.5), color=YELLOW)\n mean_label = MathTex('\\\\mu_B', font_size=24, color=YELLOW)\n mean_label_a = mean_label.copy().next_to(mean_line_a, UP)\n mean_label_b = mean_label.copy().next_to(mean_line_b, UP)\n self.play(Create(mean_line_a), Create(mean_line_b), FadeIn(mean_label_a), FadeIn(mean_label_b), run_time=2.0)\n centered_dots_a = VGroup(*[Dot(axes.c2p(x - mean_a + 6, 0.05), color=BLUE, radius=0.08) for x in samples_a if -3 <= x <= 5])\n centered_dots_b = VGroup(*[Dot(axes.c2p(x - mean_b + 6, 0.05), color=ORANGE, radius=0.08) for x in samples_b if 4 <= x <= 16])\n shift_label = Text('Subtract Mean → Center at Origin', font_size=24, color=WHITE)\n shift_label.next_to(axes, DOWN, buff=0.5)\n self.play(FadeOut(mean_line_a, mean_line_b, mean_label_a, mean_label_b), Transform(dots_a, centered_dots_a), Transform(dots_b, centered_dots_b), ReplacementTransform(batch_label, shift_label), run_time=2.0)\n std_a = np.std(samples_a)\n std_b = np.std(samples_b)\n normalized_dots_a = VGroup(*[Dot(axes.c2p((x - mean_a) / std_a * 1.5 + 6, 0.05), color=BLUE, radius=0.08) for x in samples_a if -3 <= x <= 5])\n normalized_dots_b = VGroup(*[Dot(axes.c2p((x - mean_b) / std_b * 1.5 + 6, 0.05), color=ORANGE, radius=0.08) for x in samples_b if 4 <= x <= 16])\n norm_label = Text('Divide by Std → Unit Variance', font_size=24, color=WHITE)\n norm_label.next_to(axes, DOWN, buff=0.5)\n self.play(Transform(dots_a, normalized_dots_a), Transform(dots_b, normalized_dots_b), ReplacementTransform(shift_label, norm_label), run_time=2.0)\n self.wait(0.5)\n self.play(FadeOut(solution_title, formula, dots_a, dots_b, norm_label, axes, x_label, y_label))\n params_title = Text('Learnable Parameters', font_size=36, color=PURPLE)\n params_title.to_edge(UP)\n self.play(Write(params_title), run_time=2.0)\n full_formula = MathTex('y = \\\\gamma \\\\cdot \\\\hat{x} + \\\\beta', font_size=44)\n full_formula.shift(UP * 1)\n gamma_beta_text = VGroup(Text('γ (gamma): Scale parameter', font_size=24, color=GREEN), Text('β (beta): Shift parameter', font_size=24, color=BLUE)).arrange(DOWN, buff=0.3, aligned_edge=LEFT)\n gamma_beta_text.next_to(full_formula, DOWN, buff=0.5)\n self.play(Write(full_formula), run_time=2.0 * 0.5)\n self.play(FadeIn(gamma_beta_text), run_time=2.0 * 0.5)\n axes2 = Axes(x_range=[-3, 9, 2], y_range=[0, 0.8, 0.2], x_length=8, y_length=3, axis_config={'include_tip': False})\n axes2.shift(DOWN * 1.5)\n curve_std = axes2.plot(lambda x: 0.4 * np.exp(-0.5 * (x - 3) ** 2), x_range=[0, 6], color=GRAY)\n curve_transformed = axes2.plot(lambda x: 0.27 * np.exp(-0.5 * ((x - 4) / 1.5) ** 2), x_range=[1, 7], color=PURPLE)\n self.play(Create(axes2), Create(curve_std), run_time=2.0 * 0.6)\n self.play(Create(curve_transformed), run_time=2.0 * 0.4)\n transform_arrow = Arrow(axes2.c2p(3, 0.3), axes2.c2p(4, 0.3), color=YELLOW, buff=0.1)\n transform_label = Text('γ·x + β', font_size=20, color=YELLOW)\n transform_label.next_to(transform_arrow, UP, buff=0.1)\n self.play(GrowArrow(transform_arrow), FadeIn(transform_label), run_time=2.0)\n self.wait(0.5)\n self.play(FadeOut(params_title, full_formula, gamma_beta_text, axes2, curve_std, curve_transformed, transform_arrow, transform_label))\n benefits_title = Text('Key Benefits', font_size=40, color=GREEN)\n benefits_title.to_edge(UP)\n benefits = VGroup(VGroup(Circle(radius=0.15, color=BLUE, fill_opacity=1), Text('Faster Training Convergence', font_size=26)).arrange(RIGHT, buff=0.3), VGroup(Circle(radius=0.15, color=GREEN, fill_opacity=1), Text('Higher Learning Rates Possible', font_size=26)).arrange(RIGHT, buff=0.3), VGroup(Circle(radius=0.15, color=ORANGE, fill_opacity=1), Text('Reduces Internal Covariate Shift', font_size=26)).arrange(RIGHT, buff=0.3), VGroup(Circle(radius=0.15, color=PURPLE, fill_opacity=1), Text('Acts as Regularization', font_size=26)).arrange(RIGHT, buff=0.3)).arrange(DOWN, buff=0.4, aligned_edge=LEFT)\n benefits.shift(DOWN * 0.5)\n self.play(Write(benefits_title), run_time=2.0 * 0.3)\n self.play(FadeIn(benefits[0]), run_time=2.0 * 0.35)\n self.play(FadeIn(benefits[1]), run_time=2.0)\n self.play(FadeIn(benefits[2]), run_time=2.0)\n self.play(FadeIn(benefits[3]), run_time=2.0)\n takeaway_box = SurroundingRectangle(benefits, color=YELLOW, buff=0.3)\n takeaway = Text('BatchNorm: Normalize → Learn → Optimize', font_size=28, color=YELLOW)\n takeaway.next_to(takeaway_box, DOWN, buff=0.3)\n self.play(Create(takeaway_box), FadeIn(takeaway), run_time=2.0)\n self.wait(1)\n self.play(FadeOut(benefits_title, benefits, takeaway_box, takeaway))\n end_text = Text('Thanks for watching!', font_size=40, color=BLUE)\n self.play(Write(end_text), run_time=2.0)\n self.wait(1)\n```", "category": "narrated_pedagogical_preference", "source": "nabin2004/manim-narrated-dpo-400"} +{"system": "You are an expert Manim Community Edition (ManimCE v0.19+) Python developer and mathematical animator. Given a user request, first plan the spatial layout, coordinate bounds, timing, and pedagogical flow inside ... tags (when reasoning is helpful), and then output a complete, runnable, self-contained ManimCE Python script using `from manim import *`. Never use deprecated ManimGL (`manimlib`) methods like `ShowCreation`, `TexMobject`, `TextMobject`, or `axes.get_graph`; always use modern ManimCE APIs (`Create`, `MathTex`, `Tex`, `Text`, `axes.plot`) and prevent visual overlap using `.to_edge()`, `.next_to()`, and `FadeOut`.", "prompt": "I'm learning about Xavier initialization and want a visual that shows backward pass gradient variance staying constant across layers, depicted as equal-height bars.\nShow an initialization stage, then a backward pass where variances propagate and remain balanced, with colors highlighting variance retention.\nInclude a mode where mis-specified variance causes shrinking or exploding bars to illustrate failure and how Xavier prevents that.\nAdd small annotations tying variance to layer width and activation nonlinearity.", "chosen": "```python\nfrom manim import *\nfrom manim_voiceover import VoiceoverScene\nfrom manim_voiceover.services.gtts import GTTSService\n\nclass XavierInitialization(VoiceoverScene):\n def construct(self):\n self.set_speech_service(\n GTTSService(voice=\"alba\", cache_dir=\"voiceover_cache\")\n )\n\n # Title at top\n title = Text(\"Xavier Initialization and Gradient Variance\", font_size=34)\n title.to_edge(UP, buff=0.4)\n\n with self.voiceover(\n text=\"Welcome to our lecture! Have you ever wondered why your neural network isn't learning as fast as you expected, even with the right model and dataset? Often, it all comes down to how we initialize our weights.\"\n ) as tracker:\n self.play(Write(title), run_time=tracker.duration)\n\n subtitle = Text(\"Weight Initialization Matters\", font_size=26)\n subtitle.next_to(title, DOWN, buff=0.3)\n\n with self.voiceover(\n text=\"In this session, we will dive into the fascinating world of Xavier Initialization and see how it can impact gradient variance, making your networks train more effectively!\"\n ) as tracker:\n self.play(Write(subtitle), run_time=tracker.duration)\n\n self.wait(0.3)\n self.play(FadeOut(subtitle))\n\n # Neural network layer diagram\n layer_label = Text(\"Fully Connected Layer\", font_size=24)\n layer_label.next_to(title, DOWN, buff=0.3)\n\n left_nodes = VGroup(*[Circle(radius=0.12, color=BLUE, fill_opacity=0.8) for _ in range(4)])\n left_nodes.arrange(DOWN, buff=0.35)\n left_nodes.shift(LEFT * 2.2 + DOWN * 0.2)\n\n right_nodes = VGroup(*[Circle(radius=0.12, color=GREEN, fill_opacity=0.8) for _ in range(3)])\n right_nodes.arrange(DOWN, buff=0.35)\n right_nodes.shift(RIGHT * 2.2 + DOWN * 0.2)\n\n edges = VGroup()\n for ln in left_nodes:\n for rn in right_nodes:\n edge = Line(ln.get_center(), rn.get_center(), stroke_width=1.2, color=GRAY_C)\n edges.add(edge)\n\n network = VGroup(left_nodes, right_nodes, edges)\n\n with self.voiceover(\n text=\"Consider a fully connected layer. Every input node connects to every output node, and each edge carries a weight.\"\n ) as tracker:\n self.play(Write(layer_label), Create(network), run_time=tracker.duration)\n\n # Xavier formula\n xavier_formula = MathTex(\n r\"\\text{Var}(W)\", r\"=\", r\"\\frac{6}{\\text{fan\\_in} + \\text{fan\\_out}}\",\n font_size=36\n )\n xavier_formula.next_to(network, DOWN, buff=0.5)\n\n with self.voiceover(\n text=\"Xavier, or Glorot, initialization defines weight variance as six divided by fan in plus fan out. This balances signal flow across the layer.\"\n ) as tracker:\n self.play(Write(xavier_formula), run_time=tracker.duration)\n\n highlight_box = SurroundingRectangle(xavier_formula, color=YELLOW, buff=0.15)\n with self.voiceover(\n text=\"By keeping variance in this sweet spot, we prevent signals from growing or shrinking too much as they propagate forward.\"\n ) as tracker:\n self.play(Create(highlight_box), run_time=tracker.duration)\n\n self.play(FadeOut(highlight_box), FadeOut(network), FadeOut(layer_label))\n\n # Move formula up to make room for gradient discussion\n self.play(xavier_formula.animate.to_edge(UP, buff=0.5))\n\n # Gradient variance formula\n grad_formula = MathTex(\n r\"\\text{Var}(\\nabla)\", r\"=\", r\"a^2\", r\"\\cdot\", r\"\\text{Var}(W)\",\n font_size=36\n )\n grad_formula.next_to(xavier_formula, DOWN, buff=0.7)\n\n with self.voiceover(\n text=\"Now let's look at gradients. The variance of gradients scales with a squared times the variance of weights.\"\n ) as tracker:\n self.play(Write(grad_formula), run_time=tracker.duration)\n\n arrow = Arrow(\n xavier_formula.get_bottom(), grad_formula.get_top(),\n buff=0.25, color=YELLOW\n )\n\n with self.voiceover(\n text=\"If weight variance is too high, gradients explode during back propagation. If too low, they vanish. Xavier initialization keeps gradients healthy too.\"\n ) as tracker:\n self.play(Create(arrow), run_time=tracker.duration * 0.5)\n self.play(arrow.animate.set_color(GREEN), run_time=tracker.duration * 0.5)\n\n self.wait(0.3)\n self.play(FadeOut(xavier_formula), FadeOut(grad_formula), FadeOut(arrow))\n\n # Takeaways\n takeaway_title = Text(\"Key Takeaways\", font_size=30)\n takeaway_title.to_edge(UP, buff=0.4)\n\n points = VGroup(\n Text(\"• Xavier init stabilizes signal variance\", font_size=22),\n Text(\"• It balances fan in and fan out\", font_size=22),\n Text(\"• Controls gradient variance\", font_size=22),\n Text(\"• Prevents vanishing and exploding gradients\", font_size=22)\n ).arrange(DOWN, aligned_edge=LEFT, buff=0.3)\n points.next_to(takeaway_title, DOWN, buff=0.45)\n\n with self.voiceover(\n text=\"To summarize: Xavier Initialization stabilizes signal variance by balancing the number of inputs and outputs, which controls gradient variance and prevents vanishing or exploding gradients. Thank you for watching!\"\n ) as tracker:\n self.play(Write(takeaway_title), run_time=tracker.duration * 0.3)\n self.play(Write(points), run_time=tracker.duration * 0.7)\n\n self.wait(1)\n```", "rejected": "```python\nfrom manim import *\n\nclass XavierInitialization(Scene):\n\n def construct(self):\n title = Text('Xavier Initialization and Gradient Variance', font_size=34)\n title.to_edge(UP, buff=0.4)\n self.play(Write(title), run_time=2.0)\n subtitle = Text('Weight Initialization Matters', font_size=26)\n subtitle.next_to(title, DOWN, buff=0.3)\n self.play(Write(subtitle), run_time=2.0)\n self.wait(0.3)\n self.play(FadeOut(subtitle))\n layer_label = Text('Fully Connected Layer', font_size=24)\n layer_label.next_to(title, DOWN, buff=0.3)\n left_nodes = VGroup(*[Circle(radius=0.12, color=BLUE, fill_opacity=0.8) for _ in range(4)])\n left_nodes.arrange(DOWN, buff=0.35)\n left_nodes.shift(LEFT * 2.2 + DOWN * 0.2)\n right_nodes = VGroup(*[Circle(radius=0.12, color=GREEN, fill_opacity=0.8) for _ in range(3)])\n right_nodes.arrange(DOWN, buff=0.35)\n right_nodes.shift(RIGHT * 2.2 + DOWN * 0.2)\n edges = VGroup()\n for ln in left_nodes:\n for rn in right_nodes:\n edge = Line(ln.get_center(), rn.get_center(), stroke_width=1.2, color=GRAY_C)\n edges.add(edge)\n network = VGroup(left_nodes, right_nodes, edges)\n self.play(Write(layer_label), Create(network), run_time=2.0)\n xavier_formula = MathTex('\\\\text{Var}(W)', '=', '\\\\frac{6}{\\\\text{fan\\\\_in} + \\\\text{fan\\\\_out}}', font_size=36)\n xavier_formula.next_to(network, DOWN, buff=0.5)\n self.play(Write(xavier_formula), run_time=2.0)\n highlight_box = SurroundingRectangle(xavier_formula, color=YELLOW, buff=0.15)\n self.play(Create(highlight_box), run_time=2.0)\n self.play(FadeOut(highlight_box), FadeOut(network), FadeOut(layer_label))\n self.play(xavier_formula.animate.to_edge(UP, buff=0.5))\n grad_formula = MathTex('\\\\text{Var}(\\\\nabla)', '=', 'a^2', '\\\\cdot', '\\\\text{Var}(W)', font_size=36)\n grad_formula.next_to(xavier_formula, DOWN, buff=0.7)\n self.play(Write(grad_formula), run_time=2.0)\n arrow = Arrow(xavier_formula.get_bottom(), grad_formula.get_top(), buff=0.25, color=YELLOW)\n self.play(Create(arrow), run_time=2.0 * 0.5)\n self.play(arrow.animate.set_color(GREEN), run_time=2.0 * 0.5)\n self.wait(0.3)\n self.play(FadeOut(xavier_formula), FadeOut(grad_formula), FadeOut(arrow))\n takeaway_title = Text('Key Takeaways', font_size=30)\n takeaway_title.to_edge(UP, buff=0.4)\n points = VGroup(Text('• Xavier init stabilizes signal variance', font_size=22), Text('• It balances fan in and fan out', font_size=22), Text('• Controls gradient variance', font_size=22), Text('• Prevents vanishing and exploding gradients', font_size=22)).arrange(DOWN, aligned_edge=LEFT, buff=0.3)\n points.next_to(takeaway_title, DOWN, buff=0.45)\n self.play(Write(takeaway_title), run_time=2.0 * 0.3)\n self.play(Write(points), run_time=2.0 * 0.7)\n self.wait(1)\n```", "category": "narrated_pedagogical_preference", "source": "nabin2004/manim-narrated-dpo-400"} +{"system": "You are an expert Manim Community Edition (ManimCE v0.19+) Python developer and mathematical animator. Given a user request, first plan the spatial layout, coordinate bounds, timing, and pedagogical flow inside ... tags (when reasoning is helpful), and then output a complete, runnable, self-contained ManimCE Python script using `from manim import *`. Never use deprecated ManimGL (`manimlib`) methods like `ShowCreation`, `TexMobject`, `TextMobject`, or `axes.get_graph`; always use modern ManimCE APIs (`Create`, `MathTex`, `Tex`, `Text`, `axes.plot`) and prevent visual overlap using `.to_edge()`, `.next_to()`, and `FadeOut`.", "prompt": "I'm learning calculus and want to see disk/washer methods in action for volumes of revolution.\nRevolve a region around an axis to form a solid, showing outer and inner radii and the volume integral V=π∫(R^2−r^2) dx, plus a comparison to the disk method.\nUse concrete examples like y=√x rotated about the x-axis or a washer with a hole, and animate slicing, rotation, and a parameter sweep of bounds.", "chosen": "```python\nfrom manim import *\n\nclass DiskAndWasherMethods(Scene):\n\n def construct(self):\n title = Text('Disk and Washer Methods', font_size=40)\n subtitle = Text('Volumes of Revolution', font_size=28, color=BLUE)\n title_group = VGroup(title, subtitle).arrange(DOWN, buff=0.3)\n self.play(Write(title), run_time=2.0 * 0.6)\n self.play(FadeIn(subtitle), run_time=2.0 * 0.4)\n self.wait(0.5)\n self.play(FadeOut(title_group))\n self.wait(0.3)\n disk_title = Text('Disk Method', font_size=36, color=GREEN)\n disk_title.to_edge(UP, buff=0.4)\n self.play(Write(disk_title), run_time=2.0)\n axes = Axes(x_range=[0, 4, 1], y_range=[0, 3, 1], x_length=5, y_length=3, axis_config={'include_tip': False})\n axes.shift(LEFT * 2.5 + DOWN * 0.5)\n graph = axes.plot(lambda x: 0.9 * x ** 0.5, x_range=[0.5, 3.5], color=BLUE)\n self.play(Create(axes), run_time=2.0 * 0.4)\n self.play(Create(graph), run_time=2.0 * 0.6)\n x_sample = 2.0\n y_sample = 0.9 * x_sample ** 0.5\n dot = Dot(axes.c2p(x_sample, y_sample), color=YELLOW)\n radius_line = Line(axes.c2p(x_sample, 0), axes.c2p(x_sample, y_sample), color=YELLOW)\n radius_brace = Brace(radius_line, direction=RIGHT, buff=0.05, color=YELLOW)\n radius_label = MathTex('r(x)', font_size=24, color=YELLOW)\n radius_label.next_to(radius_brace, RIGHT, buff=0.1)\n self.play(Create(dot), Create(radius_line), run_time=2.0 * 0.5)\n self.play(GrowFromCenter(radius_brace), Write(radius_label), run_time=2.0 * 0.5)\n disk = Circle(radius=0.6, color=GREEN, fill_opacity=0.3, fill_color=GREEN)\n disk.next_to(axes, RIGHT, buff=1.2)\n disk_label = MathTex('\\\\pi [r(x)]^2', font_size=28, color=GREEN)\n disk_label.next_to(disk, DOWN, buff=0.2)\n self.play(Create(disk), Write(disk_label), run_time=2.0)\n disk_formula = MathTex('V = \\\\pi \\\\int_{a}^{b} [r(x)]^2 \\\\, dx', font_size=34)\n disk_formula.next_to(disk, RIGHT, buff=0.6)\n self.play(Write(disk_formula), run_time=2.0)\n self.wait(0.5)\n to_fade = VGroup(axes, graph, dot, radius_line, radius_brace, radius_label, disk, disk_label, disk_formula)\n self.play(FadeOut(to_fade), FadeOut(disk_title), run_time=2.0)\n washer_title = Text('Washer Method', font_size=36, color=RED)\n washer_title.to_edge(UP, buff=0.4)\n self.play(Write(washer_title), run_time=2.0)\n axes2 = Axes(x_range=[0, 4, 1], y_range=[0, 3.5, 1], x_length=5, y_length=3.2, axis_config={'include_tip': False})\n axes2.shift(LEFT * 2.5 + DOWN * 0.3)\n graph_R = axes2.plot(lambda x: 0.25 * x + 1.5, x_range=[0.5, 3.5], color=BLUE)\n graph_r = axes2.plot(lambda x: 0.15 * x + 0.4, x_range=[0.5, 3.5], color=GRAY)\n self.play(Create(axes2), run_time=2.0 * 0.3)\n self.play(Create(graph_R), run_time=2.0 * 0.35)\n self.play(Create(graph_r), run_time=2.0 * 0.35)\n x2 = 2.0\n y_R = 0.25 * x2 + 1.5\n y_r = 0.15 * x2 + 0.4\n pt_R = Dot(axes2.c2p(x2, y_R), color=BLUE)\n pt_r = Dot(axes2.c2p(x2, y_r), color=GRAY)\n line_R = Line(axes2.c2p(x2, 0), axes2.c2p(x2, y_R), color=BLUE)\n line_r = Line(axes2.c2p(x2, 0), axes2.c2p(x2, y_r), color=GRAY)\n brace_R = Brace(line_R, direction=RIGHT, buff=0.05, color=BLUE)\n label_R = MathTex('R(x)', font_size=24, color=BLUE)\n label_R.next_to(brace_R, RIGHT, buff=0.1)\n brace_r = Brace(line_r, direction=RIGHT, buff=0.05, color=GRAY)\n label_r = MathTex('r(x)', font_size=24, color=GRAY)\n label_r.next_to(brace_r, RIGHT, buff=0.1)\n self.play(Create(pt_R), Create(pt_r), run_time=2.0 * 0.3)\n self.play(Create(line_R), GrowFromCenter(brace_R), Write(label_R), run_time=2.0 * 0.35)\n self.play(Create(line_r), GrowFromCenter(brace_r), Write(label_r), run_time=2.0 * 0.35)\n outer_circle = Circle(radius=0.7, color=RED, fill_opacity=0.3, fill_color=RED)\n inner_circle = Circle(radius=0.35, color=BLACK, fill_opacity=1)\n washer = VGroup(outer_circle, inner_circle)\n washer.next_to(axes2, RIGHT, buff=0.9)\n washer.shift(UP * 0.3)\n washer_label = MathTex('\\\\pi [R(x)^2 - r(x)^2]', font_size=26, color=RED)\n washer_label.next_to(washer, DOWN, buff=0.2)\n self.play(Create(outer_circle), Create(inner_circle), Write(washer_label), run_time=2.0)\n washer_formula = MathTex('V = \\\\pi \\\\int_{a}^{b} \\\\left([R(x)]^2 - [r(x)]^2\\\\right) dx', font_size=32)\n washer_formula.next_to(washer, RIGHT, buff=0.5)\n self.play(Write(washer_formula), run_time=2.0)\n self.wait(0.5)\n summary_title = Text('Summary', font_size=36, color=YELLOW)\n summary_title.to_edge(UP, buff=0.4)\n summary_group = VGroup(MathTex('\\\\text{Disk: } V = \\\\pi \\\\int_{a}^{b} [r(x)]^2 \\\\, dx', font_size=28), MathTex('\\\\text{Washer: } V = \\\\pi \\\\int_{a}^{b} \\\\left([R(x)]^2 - [r(x)]^2\\\\right) dx', font_size=28)).arrange(DOWN, buff=0.6)\n summary_group.shift(DOWN * 0.3)\n self.play(FadeOut(VGroup(axes2, graph_R, graph_r, pt_R, pt_r, line_R, line_r, brace_R, label_R, brace_r, label_r, washer, washer_label, washer_formula)), ReplacementTransform(washer_title, summary_title), run_time=2.0 * 0.5)\n self.play(Write(summary_group), run_time=2.0 * 0.5)\n self.wait(1)\n self.play(FadeOut(summary_title), FadeOut(summary_group))\n self.wait(0.5)\n```", "rejected": "```python\nfrom manim import *\n\nclass DiskAndWasherMethods(Scene):\n\n def construct(self):\n title = Text('Disk and Washer Methods', font_size=40)\n subtitle = Text('Volumes of Revolution', font_size=28, color=BLUE)\n title_group = VGroup(title, subtitle).arrange(DOWN, buff=0.3)\n self.play(Write(title), run_time=2.0 * 0.6)\n self.play(FadeIn(subtitle), run_time=2.0 * 0.4)\n self.wait(0.5)\n self.play(FadeOut(title_group))\n self.wait(0.3)\n disk_title = Text('Disk Method', font_size=36, color=GREEN)\n disk_title.to_edge(UP, buff=0.4)\n self.play(Write(disk_title), run_time=2.0)\n axes = Axes(axis_color=BLUE, x_range=[0, 4, 1], y_range=[0, 3, 1], x_length=5, y_length=3, axis_config={'include_tip': False})\n axes.shift(LEFT * 2.5 + DOWN * 0.5)\n graph = axes.plot(lambda x: 0.9 * x ** 0.5, x_range=[0.5, 3.5], color=BLUE)\n self.play(Create(axes), run_time=2.0 * 0.4)\n self.play(Create(graph), run_time=2.0 * 0.6)\n x_sample = 2.0\n y_sample = 0.9 * x_sample ** 0.5\n dot = Dot(axes.c2p(x_sample, y_sample), color=YELLOW)\n radius_line = Line(axes.c2p(x_sample, 0), axes.c2p(x_sample, y_sample), color=YELLOW)\n radius_brace = Brace(radius_line, direction=RIGHT, buff=0.05, color=YELLOW)\n radius_label = MathTex('r(x)', font_size=24, color=YELLOW)\n radius_label.next_to(radius_brace, RIGHT, buff=0.1)\n self.play(Create(dot), Create(radius_line), run_time=2.0 * 0.5)\n self.play(GrowFromCenter(radius_brace), Write(radius_label), run_time=2.0 * 0.5)\n disk = Circle(radius=0.6, color=GREEN, fill_opacity=0.3, fill_color=GREEN)\n disk.next_to(axes, RIGHT, buff=1.2)\n disk_label = MathTex('\\\\pi [r(x)]^2', font_size=28, color=GREEN)\n disk_label.next_to(disk, DOWN, buff=0.2)\n self.play(Create(disk), Write(disk_label), run_time=2.0)\n disk_formula = MathTex('V = \\\\pi \\\\int_{a}^{b} [r(x)]^2 \\\\, dx', font_size=34)\n disk_formula.next_to(disk, RIGHT, buff=0.6)\n self.play(Write(disk_formula), run_time=2.0)\n self.wait(0.5)\n to_fade = VGroup(axes, graph, dot, radius_line, radius_brace, radius_label, disk, disk_label, disk_formula)\n self.play(FadeOut(to_fade), FadeOut(disk_title), run_time=2.0)\n washer_title = Text('Washer Method', font_size=36, color=RED)\n washer_title.to_edge(UP, buff=0.4)\n self.play(Write(washer_title), run_time=2.0)\n axes2 = Axes(x_range=[0, 4, 1], y_range=[0, 3.5, 1], x_length=5, y_length=3.2, axis_config={'include_tip': False})\n axes2.shift(LEFT * 2.5 + DOWN * 0.3)\n graph_R = axes2.plot(lambda x: 0.25 * x + 1.5, x_range=[0.5, 3.5], color=BLUE)\n graph_r = axes2.plot(lambda x: 0.15 * x + 0.4, x_range=[0.5, 3.5], color=GRAY)\n self.play(Create(axes2), run_time=2.0 * 0.3)\n self.play(Create(graph_R), run_time=2.0 * 0.35)\n self.play(Create(graph_r), run_time=2.0 * 0.35)\n x2 = 2.0\n y_R = 0.25 * x2 + 1.5\n y_r = 0.15 * x2 + 0.4\n pt_R = Dot(axes2.c2p(x2, y_R), color=BLUE)\n pt_r = Dot(axes2.c2p(x2, y_r), color=GRAY)\n line_R = Line(axes2.c2p(x2, 0), axes2.c2p(x2, y_R), color=BLUE)\n line_r = Line(axes2.c2p(x2, 0), axes2.c2p(x2, y_r), color=GRAY)\n brace_R = Brace(line_R, direction=RIGHT, buff=0.05, color=BLUE)\n label_R = MathTex('R(x)', font_size=24, color=BLUE)\n label_R.next_to(brace_R, RIGHT, buff=0.1)\n brace_r = Brace(line_r, direction=RIGHT, buff=0.05, color=GRAY)\n label_r = MathTex('r(x)', font_size=24, color=GRAY)\n label_r.next_to(brace_r, RIGHT, buff=0.1)\n self.play(Create(pt_R), Create(pt_r), run_time=2.0 * 0.3)\n self.play(Create(line_R), GrowFromCenter(brace_R), Write(label_R), run_time=2.0 * 0.35)\n self.play(Create(line_r), GrowFromCenter(brace_r), Write(label_r), run_time=2.0 * 0.35)\n outer_circle = Circle(radius=0.7, color=RED, fill_opacity=0.3, fill_color=RED)\n inner_circle = Circle(radius=0.35, color=BLACK, fill_opacity=1)\n washer = VGroup(outer_circle, inner_circle)\n washer.next_to(axes2, RIGHT, buff=0.9)\n washer.shift(UP * 0.3)\n washer_label = MathTex('\\\\pi [R(x)^2 - r(x)^2]', font_size=26, color=RED)\n washer_label.next_to(washer, DOWN, buff=0.2)\n self.play(Create(outer_circle), Create(inner_circle), Write(washer_label), run_time=2.0)\n washer_formula = MathTex('V = \\\\pi \\\\int_{a}^{b} \\\\left([R(x)]^2 - [r(x)]^2\\\\right) dx', font_size=32)\n washer_formula.next_to(washer, RIGHT, buff=0.5)\n self.play(Write(washer_formula), run_time=2.0)\n self.wait(0.5)\n summary_title = Text('Summary', font_size=36, color=YELLOW)\n summary_title.to_edge(UP, buff=0.4)\n summary_group = VGroup(MathTex('\\\\text{Disk: } V = \\\\pi \\\\int_{a}^{b} [r(x)]^2 \\\\, dx', font_size=28), MathTex('\\\\text{Washer: } V = \\\\pi \\\\int_{a}^{b} \\\\left([R(x)]^2 - [r(x)]^2\\\\right) dx', font_size=28)).arrange(DOWN, buff=0.6)\n summary_group.shift(DOWN * 0.3)\n self.play(FadeOut(VGroup(axes2, graph_R, graph_r, pt_R, pt_r, line_R, line_r, brace_R, label_R, brace_r, label_r, washer, washer_label, washer_formula)), ReplacementTransform(washer_title, summary_title), run_time=2.0 * 0.5)\n self.play(Write(summary_group), run_time=2.0 * 0.5)\n self.wait(1)\n self.play(FadeOut(summary_title), FadeOut(summary_group))\n self.wait(0.5)\n```", "category": "invalid_axes_kwarg", "source": "synthetic_hard_neg:nabin2004/AOS-Manim-SFT"} +{"system": "You are an expert Manim Community Edition (ManimCE v0.19+) Python developer and mathematical animator. Given a user request, first plan the spatial layout, coordinate bounds, timing, and pedagogical flow inside ... tags (when reasoning is helpful), and then output a complete, runnable, self-contained ManimCE Python script using `from manim import *`. Never use deprecated ManimGL (`manimlib`) methods like `ShowCreation`, `TexMobject`, `TextMobject`, or `axes.get_graph`; always use modern ManimCE APIs (`Create`, `MathTex`, `Tex`, `Text`, `axes.plot`) and prevent visual overlap using `.to_edge()`, `.next_to()`, and `FadeOut`.", "prompt": "Create a 30-second Manim scene in a 3Blue1Brown-inspired style that explains how a secant line turns into a tangent line. Use a moving dx tracker, clear labels, and staged captions that walk from average change to instantaneous change.", "chosen": "```python\nfrom manim import *\n\nclass SecantTangentStory(Scene):\n def construct(self):\n def f(x):\n return 0.14 * (x - 3.4) ** 3 - 0.7 * (x - 3.4) + 2.2\n\n x0 = 3.4\n dx = ValueTracker(1.4)\n title = Text(\"Average Change Becomes Instantaneous Change\", font_size=35).to_edge(UP)\n axes = Axes(x_range=[0, 7, 1], y_range=[0, 4.6, 1], x_length=8.2, y_length=4.8, tips=False).shift(DOWN * 0.2)\n graph = axes.plot(f, x_range=[0.4, 6.6], color=BLUE_D)\n base_dot = Dot(axes.c2p(x0, f(x0)), color=YELLOW, radius=0.08)\n move_dot = always_redraw(lambda: Dot(axes.c2p(x0 + dx.get_value(), f(x0 + dx.get_value())), color=TEAL_D, radius=0.08))\n secant = always_redraw(lambda: Line(base_dot.get_center(), move_dot.get_center(), color=ORANGE, stroke_width=5))\n dx_brace = always_redraw(lambda: BraceBetweenPoints(axes.c2p(x0, 0), axes.c2p(x0 + dx.get_value(), 0), direction=DOWN))\n dx_label = always_redraw(lambda: MathTex(\"dx\", color=ORANGE).scale(0.9).next_to(dx_brace, DOWN, buff=0.08))\n slope_label = always_redraw(lambda: MathTex(\"\\\\frac{df}{dx}\", color=ORANGE).scale(0.9).next_to(secant.get_center(), UP, buff=0.14))\n tangent = always_redraw(lambda: self._tangent_segment(axes, f, x0))\n caption_a = Text(\"With a visible gap, the secant line measures average change.\", font_size=24, color=GRAY_D).to_edge(DOWN)\n caption_b = Text(\"As dx shrinks, the second point slides toward the first.\", font_size=24, color=GRAY_D).to_edge(DOWN)\n caption_c = Text(\"In the limit, the secant settles into the tangent direction.\", font_size=24, color=GRAY_D).to_edge(DOWN)\n\n self.play(FadeIn(title), Create(axes), Create(graph), run_time=4)\n self.play(FadeIn(base_dot), FadeIn(move_dot), Create(secant), FadeIn(dx_brace), FadeIn(dx_label), FadeIn(slope_label), FadeIn(caption_a), run_time=4)\n self.play(dx.animate.set_value(0.9), run_time=4)\n self.play(ReplacementTransform(caption_a, caption_b), dx.animate.set_value(0.35), run_time=5)\n self.play(ReplacementTransform(caption_b, caption_c), FadeIn(tangent), dx.animate.set_value(0.08), run_time=5)\n self.wait(2)\n\n def _tangent_segment(self, axes, f, x_value, width=1.15):\n slope = (f(x_value + 0.02) - f(x_value - 0.02)) / 0.04\n center = axes.c2p(x_value, f(x_value))\n dx = width / (2 * np.sqrt(1 + slope**2))\n dy = slope * dx\n return Line(center + np.array([-dx, -dy, 0]), center + np.array([dx, dy, 0]), color=YELLOW_D, stroke_width=6)\n```", "rejected": "```python\nfrom manim import *\n\nclass SecantTangentStory(Scene):\n def construct(self):\n def f(x):\n return 0.14 * (x - 3.4) ** 3 - 0.7 * (x - 3.4) + 2.2\n\n x0 = 3.4\n dx = ValueTracker(1.4)\n title = Text(\"Average Change Becomes Instantaneous Change\", font_size=35).to_edge(UP)\n axes = Axes(x_range=[0, 7, 1], y_range=[0, 4.6, 1], x_length=8.2, y_length=4.8, tips=False).shift(DOWN * 0.2)\n graph = axes.get_graph(f, x_range=[0.4, 6.6], color=BLUE_D)\n base_dot = Dot(axes.c2p(x0, f(x0)), color=YELLOW, radius=0.08)\n move_dot = always_redraw(lambda: Dot(axes.c2p(x0 + dx.get_value(), f(x0 + dx.get_value())), color=TEAL_D, radius=0.08))\n secant = always_redraw(lambda: Line(base_dot.get_center(), move_dot.get_center(), color=ORANGE, stroke_width=5))\n dx_brace = always_redraw(lambda: BraceBetweenPoints(axes.c2p(x0, 0), axes.c2p(x0 + dx.get_value(), 0), direction=DOWN))\n dx_label = always_redraw(lambda: TexMobject(\"dx\", color=ORANGE).scale(0.9).next_to(dx_brace, DOWN, buff=0.08))\n slope_label = always_redraw(lambda: MathTex(\"\\\\frac{df}{dx}\", color=ORANGE).scale(0.9).next_to(secant.get_center(), UP, buff=0.14))\n tangent = always_redraw(lambda: self._tangent_segment(axes, f, x0))\n caption_a = Text(\"With a visible gap, the secant line measures average change.\", font_size=24, color=GRAY_D).to_edge(DOWN)\n caption_b = Text(\"As dx shrinks, the second point slides toward the first.\", font_size=24, color=GRAY_D).to_edge(DOWN)\n caption_c = Text(\"In the limit, the secant settles into the tangent direction.\", font_size=24, color=GRAY_D).to_edge(DOWN)\n\n self.play(FadeIn(title), ShowCreation(axes), Create(graph), run_time=4)\n self.play(FadeIn(base_dot), FadeIn(move_dot), Create(secant), FadeIn(dx_brace), FadeIn(dx_label), FadeIn(slope_label), FadeIn(caption_a), run_time=4)\n self.play(dx.animate.set_value(0.9), run_time=4)\n self.play(ReplacementTransform(caption_a, caption_b), dx.animate.set_value(0.35), run_time=5)\n self.play(ReplacementTransform(caption_b, caption_c), FadeIn(tangent), dx.animate.set_value(0.08), run_time=5)\n self.wait(2)\n\n def _tangent_segment(self, axes, f, x_value, width=1.15):\n slope = (f(x_value + 0.02) - f(x_value - 0.02)) / 0.04\n center = axes.c2p(x_value, f(x_value))\n dx = width / (2 * np.sqrt(1 + slope**2))\n dy = slope * dx\n return Line(center + np.array([-dx, -dy, 0]), center + np.array([dx, dy, 0]), color=YELLOW_D, stroke_width=6)\n```", "category": "legacy_api_hallucination", "source": "synthetic_hard_neg:sebastianboehler/autoresearch-manim"} +{"system": "You are an expert Manim Community Edition (ManimCE v0.19+) Python developer and mathematical animator. Given a user request, first plan the spatial layout, coordinate bounds, timing, and pedagogical flow inside ... tags (when reasoning is helpful), and then output a complete, runnable, self-contained ManimCE Python script using `from manim import *`. Never use deprecated ManimGL (`manimlib`) methods like `ShowCreation`, `TexMobject`, `TextMobject`, or `axes.get_graph`; always use modern ManimCE APIs (`Create`, `MathTex`, `Tex`, `Text`, `axes.plot`) and prevent visual overlap using `.to_edge()`, `.next_to()`, and `FadeOut`.", "prompt": "Create an interactive Manim CE animation demonstrating: Tangent line dynamically tracking curve f(x) = x^2. Use updaters and ValueTracker.\n\n```python\nfrom manim import *\nimport numpy as np\n\nclass DynamicScene91(Scene):\n def construct(self):\n ax = Axes(x_range=[-3, 3, 1], y_range=[0, 9, 3], x_length=6, y_length=4)\n curve = ax.plot(lambda x: x**2, color=BLUE)\n t = ValueTracker(1.0)\n dot = always_redraw(lambda: Dot(ax.c2p(t.get_value(), t.get_value()**2), color=RED))\n tangent = always_redraw(lambda: ax.get_secant_slope_group(\n t.get_value(), curve, dx=0.01, dx_line_color=YELLOW, secant_line_length=3, secant_line_color=YELLOW\n ))\n num = DecimalNumber(0, num_decimal_places=2, color=YELLOW).to_corner(UR)\n num.add_updater(lambda m: m.set_value(t.get_value()))\n \n self.add(ax, curve, dot, tangent, num)\n self.play(t.animate.set_value(2.5), run_time=3)\n self.play(t.animate.set_value(-2.0), run_time=3)\n```", "chosen": "```python\nfrom manim import *\nfrom manim_voiceover import VoiceoverScene\nfrom manim_voiceover.services.gtts import GTTSService\nimport numpy as np\n\nMARGIN = 0.5\n\nclass DynamicScene91(VoiceoverScene):\n def fit_in_frame(self, mob: Mobject, w_frac=0.9, h_frac=0.9) -> Mobject:\n max_w = config.frame_width * w_frac\n max_h = config.frame_height * h_frac\n if mob.width > max_w: mob.width = max_w\n if mob.height > max_h: mob.height = max_h\n return mob\n\n def construct(self):\n self.set_speech_service(GTTSService(transcription_model=\"base\"))\n \n # [SETUP]\n ax = Axes(x_range=[-3, 3, 1], y_range=[0, 9, 3], x_length=6, y_length=4)\n curve = ax.plot(lambda x: x**2, color=BLUE)\n t = ValueTracker(1.0)\n \n # [LAYOUT]\n title = MathTex(r\"\\text{Tangent Line Tracking}\").to_edge(UP, buff=MARGIN)\n self.fit_in_frame(title)\n \n # [UPDATER]\n dot = always_redraw(lambda: Dot(ax.c2p(t.get_value(), t.get_value()**2), color=RED))\n tangent = always_redraw(lambda: ax.get_secant_slope_group(\n t.get_value(), curve, dx=0.01, dx_line_color=YELLOW, secant_line_length=3, secant_line_color=YELLOW\n ))\n num = DecimalNumber(0, num_decimal_places=2, color=YELLOW).to_corner(UR)\n num.add_updater(lambda m: m.set_value(t.get_value()))\n \n self.add(title, ax, curve, dot, tangent, num)\n \n # [BEAT 1 | sync: b1]\n with self.voiceover(text=\"As the point moves along the parabola, the tangent line dynamically updates to reflect the instantaneous rate of change. \") as t_v:\n self.wait_until_bookmark(\"b1\")\n self.play(t.animate.set_value(2.5), run_time=3)\n \n # [BEAT 2 | sync: b2]\n with self.voiceover(text=\"Notice how the slope changes sign as we cross the vertex of the parabola. \") as t_v:\n self.wait_until_bookmark(\"b2\")\n self.play(t.animate.set_value(-2.0), run_time=3)\n \n self.wait(1)\n```", "rejected": "```python\nfrom manim import *\nfrom manim_voiceover import VoiceoverScene\nfrom manim_voiceover.services.gtts import GTTSService\nimport numpy as np\n\nMARGIN = 0.5\n\nclass DynamicScene91(VoiceoverScene):\n def fit_in_frame(self, mob: Mobject, w_frac=0.9, h_frac=0.9) -> Mobject:\n max_w = config.frame_width * w_frac\n max_h = config.frame_height * h_frac\n if mob.width > max_w: mob.width = max_w\n if mob.height > max_h: mob.height = max_h\n return mob\n\n def construct(self):\n self.set_speech_service(GTTSService(transcription_model=\"base\"))\n \n # [SETUP]\n ax = Axes(x_range=[-3, 3, 1], y_range=[0, 9, 3], x_length=6, y_length=4)\n curve = ax.get_graph(lambda x: x**2, color=BLUE)\n t = ValueTracker(1.0)\n \n # [LAYOUT]\n title = TexMobject(r\"\\text{Tangent Line Tracking}\").to_edge(UP, buff=MARGIN)\n self.fit_in_frame(title)\n \n # [UPDATER]\n dot = always_redraw(lambda: Dot(ax.c2p(t.get_value(), t.get_value()**2), color=RED))\n tangent = always_redraw(lambda: ax.get_secant_slope_group(\n t.get_value(), curve, dx=0.01, dx_line_color=YELLOW, secant_line_length=3, secant_line_color=YELLOW\n ))\n num = DecimalNumber(0, num_decimal_places=2, color=YELLOW).to_corner(UR)\n num.add_updater(lambda m: m.set_value(t.get_value()))\n \n self.add(title, ax, curve, dot, tangent, num)\n \n # [BEAT 1 | sync: b1]\n with self.voiceover(text=\"As the point moves along the parabola, the tangent line dynamically updates to reflect the instantaneous rate of change. \") as t_v:\n self.wait_until_bookmark(\"b1\")\n self.play(t.animate.set_value(2.5), run_time=3)\n \n # [BEAT 2 | sync: b2]\n with self.voiceover(text=\"Notice how the slope changes sign as we cross the vertex of the parabola. \") as t_v:\n self.wait_until_bookmark(\"b2\")\n self.play(t.animate.set_value(-2.0), run_time=3)\n \n self.wait(1)\n```", "category": "legacy_api_hallucination", "source": "synthetic_hard_neg:nabin2004/qwen3-8b-manimator-gold-sft"} +{"system": "You are an expert Manim Community Edition (ManimCE v0.19+) Python developer and mathematical animator. Given a user request, first plan the spatial layout, coordinate bounds, timing, and pedagogical flow inside ... tags (when reasoning is helpful), and then output a complete, runnable, self-contained ManimCE Python script using `from manim import *`. Never use deprecated ManimGL (`manimlib`) methods like `ShowCreation`, `TexMobject`, `TextMobject`, or `axes.get_graph`; always use modern ManimCE APIs (`Create`, `MathTex`, `Tex`, `Text`, `axes.plot`) and prevent visual overlap using `.to_edge()`, `.next_to()`, and `FadeOut`.", "prompt": "What are the geometric implications of non-symmetric connections in torsion and curvature, and how can these be showcased visually?", "chosen": "```python\nfrom manim import *\n\nclass NonSymmetricConnections(Scene):\n def construct(self):\n # Title\n title = Text(\"Twisting Paths: Unraveling Non-Symmetric Connections\", font_size=32)\n self.play(Write(title))\n self.wait(1)\n self.play(FadeOut(title))\n \n # Symmetric Connection Path\n sym_label = Text(\"Symmetric Connection\", font_size=28)\n sym_label.to_edge(UP)\n self.play(Write(sym_label))\n \n # Draw a straight path\n straight_path = Line(start=LEFT*3, end=RIGHT*3, color=BLUE)\n self.play(Create(straight_path))\n \n # Particle moving along straight path\n dot = Dot(color=RED).move_to(straight_path.get_start())\n self.play(MoveAlongPath(dot, straight_path), run_time=2)\n self.wait(1)\n \n # Non-Symmetric Connection Path\n nonsym_label = Text(\"Non-Symmetric Connection with Torsion\", font_size=28)\n nonsym_label.to_edge(UP)\n self.play(ReplacementTransform(sym_label, nonsym_label))\n \n # Draw a curved path showing torsion\n curved_path = CubicBezier(\n start_anchor=LEFT*3,\n start_handle=LEFT*1+DOWN*2,\n end_handle=RIGHT*1+UP*2,\n end_anchor=RIGHT*3,\n color=GREEN\n )\n self.play(\n ReplacementTransform(straight_path, curved_path),\n dot.animate.move_to(curved_path.get_start())\n )\n \n # Particle following curved path\n self.play(MoveAlongPath(dot, curved_path), run_time=3)\n self.wait(1)\n \n # Show torsion equation\n self.play(FadeOut(nonsym_label, curved_path, dot))\n \n torsion_title = Text(\"Torsion in Non-Symmetric Connections\", font_size=28)\n torsion_title.to_edge(UP)\n torsion_eq = Text(\"T(X,Y) = Difference in Vector Transport Directions\", font_size=24)\n torsion_eq.next_to(torsion_title, DOWN, buff=0.5)\n \n self.play(Write(torsion_title), Write(torsion_eq))\n self.wait(2)\n \n # Visual demonstration of torsion with vectors\n self.play(FadeOut(torsion_title, torsion_eq))\n \n vector_title = Text(\"Vector Transport with Torsion\", font_size=28)\n vector_title.to_edge(UP)\n self.play(Write(vector_title))\n \n # Create two vectors\n vec1 = Arrow(ORIGIN, RIGHT*2, color=YELLOW)\n vec2 = Arrow(ORIGIN, UP*2, color=GREEN)\n \n self.play(Create(vec1), Create(vec2))\n self.wait(1)\n \n # Show torsion effect (twisted transport)\n vec2_moved = Arrow(RIGHT*2, RIGHT*2+UP*1.5+RIGHT*0.5, color=GREEN)\n torsion_text = Text(\"Torsion Effect\", font_size=24)\n torsion_text.next_to(vec2_moved, RIGHT)\n \n self.play(Transform(vec2, vec2_moved), Write(torsion_text))\n self.wait(2)\n \n # Conclusion\n self.play(FadeOut(vector_title, vec1, vec2, torsion_text))\n \n conclusion = Text(\"Non-symmetric connections introduce torsion,\\ntwisting paths in geometric spaces\", font_size=28)\n self.play(Write(conclusion))\n self.wait(2)\n self.play(FadeOut(conclusion))\n```", "rejected": "```python\nfrom manim import *\n\nclass NonSymmetricConnections(Scene):\n def construct(self):\n # Title\n title = Text(\"Twisting Paths: Unraveling Non-Symmetric Connections\", font_size=32)\n self.play(Write(title))\n self.wait(1)\n self.play(FadeOut(title))\n \n # Symmetric Connection Path\n sym_label = Text(\"Symmetric Connection\", font_size=28)\n sym_label\n self.play(Write(sym_label))\n \n # Draw a straight path\n straight_path = Line(start=LEFT*3, end=RIGHT*3, color=BLUE)\n self.play(Create(straight_path))\n \n # Particle moving along straight path\n dot = Dot(color=RED).move_to(straight_path.get_start())\n self.play(MoveAlongPath(dot, straight_path), run_time=2)\n self.wait(1)\n \n # Non-Symmetric Connection Path\n nonsym_label = Text(\"Non-Symmetric Connection with Torsion\", font_size=28)\n nonsym_label\n self.play(ReplacementTransform(sym_label, nonsym_label))\n \n # Draw a curved path showing torsion\n curved_path = CubicBezier(\n start_anchor=LEFT*3,\n start_handle=LEFT*1+DOWN*2,\n end_handle=RIGHT*1+UP*2,\n end_anchor=RIGHT*3,\n color=GREEN\n )\n self.play(\n ReplacementTransform(straight_path, curved_path),\n dot.animate.move_to(curved_path.get_start())\n )\n \n # Particle following curved path\n self.play(MoveAlongPath(dot, curved_path), run_time=3)\n self.wait(1)\n \n # Show torsion equation\n self.play(FadeOut(nonsym_label, curved_path, dot))\n \n torsion_title = Text(\"Torsion in Non-Symmetric Connections\", font_size=28)\n torsion_title\n torsion_eq = Text(\"T(X,Y) = Difference in Vector Transport Directions\", font_size=24)\n torsion_eq.next_to(torsion_title, DOWN, buff=0.5)\n \n self.play(Write(torsion_title), Write(torsion_eq))\n self.wait(2)\n \n # Visual demonstration of torsion with vectors\n self.play(FadeOut(torsion_title, torsion_eq))\n \n vector_title = Text(\"Vector Transport with Torsion\", font_size=28)\n vector_title.to_edge(UP)\n self.play(Write(vector_title))\n \n # Create two vectors\n vec1 = Arrow(ORIGIN, RIGHT*2, color=YELLOW)\n vec2 = Arrow(ORIGIN, UP*2, color=GREEN)\n \n self.play(Create(vec1), Create(vec2))\n self.wait(1)\n \n # Show torsion effect (twisted transport)\n vec2_moved = Arrow(RIGHT*2, RIGHT*2+UP*1.5+RIGHT*0.5, color=GREEN)\n torsion_text = Text(\"Torsion Effect\", font_size=24)\n torsion_text.next_to(vec2_moved, RIGHT)\n \n self.play(Transform(vec2, vec2_moved), Write(torsion_text))\n self.wait(2)\n \n # Conclusion\n self.play(FadeOut(vector_title, vec1, vec2, torsion_text))\n \n conclusion = Text(\"Non-symmetric connections introduce torsion,\\ntwisting paths in geometric spaces\", font_size=28)\n self.play(Write(conclusion))\n self.wait(2)\n self.play(FadeOut(conclusion))\n```", "category": "spatial_layout_overlap", "source": "synthetic_hard_neg:nabin2004/manim-sft-10k"} +{"system": "You are an expert Manim Community Edition (ManimCE v0.19+) Python developer and mathematical animator. Given a user request, first plan the spatial layout, coordinate bounds, timing, and pedagogical flow inside ... tags (when reasoning is helpful), and then output a complete, runnable, self-contained ManimCE Python script using `from manim import *`. Never use deprecated ManimGL (`manimlib`) methods like `ShowCreation`, `TexMobject`, `TextMobject`, or `axes.get_graph`; always use modern ManimCE APIs (`Create`, `MathTex`, `Tex`, `Text`, `axes.plot`) and prevent visual overlap using `.to_edge()`, `.next_to()`, and `FadeOut`.", "prompt": "I'm teaching undergrads optimization and want a vivid visualization of the running-mean EMA update: running_mean = momentum * running_mean + (1 - momentum) * batch_mean. Create a scene where the running_mean updates each step as a weighted blend of the previous value and the batch mean, with a momentum slider. Show a dynamic trace of running_mean over time and a separate trace for batch_mean; compare different momentum values. Highlight the limiting cases momentum=0 and momentum=1 and how quickly the estimate adapts.", "chosen": "```python\nfrom manim import *\n\nclass EMAUpdateScene(Scene):\n\n def construct(self):\n title = Text('Exponential Moving Average (EMA)', font_size=36)\n subtitle = Text('Running Mean Update Visualization', font_size=24, color=BLUE)\n title_group = VGroup(title, subtitle).arrange(DOWN, buff=0.3)\n self.play(Write(title), run_time=2.0 * 0.6)\n self.play(FadeIn(subtitle), run_time=2.0 * 0.4)\n self.wait(0.5)\n self.play(FadeOut(title_group))\n formula_title = Text('The EMA Formula:', font_size=28, color=YELLOW)\n formula_title.to_edge(UP, buff=0.5)\n ema_formula = MathTex('EMA_t = (1 - \\\\alpha) \\\\cdot EMA_{t-1} + \\\\alpha \\\\cdot X_t', font_size=32)\n alpha_formula = MathTex('\\\\alpha = \\\\frac{2}{N + 1}', font_size=28)\n formulas = VGroup(ema_formula, alpha_formula).arrange(DOWN, buff=0.5)\n formulas.next_to(formula_title, DOWN, buff=0.5)\n self.play(Write(formula_title), run_time=2.0 * 0.2)\n self.play(Write(ema_formula), run_time=2.0 * 0.5)\n self.play(Write(alpha_formula), run_time=2.0 * 0.3)\n self.wait(2.0)\n self.play(FadeOut(formula_title), FadeOut(formulas))\n axes = Axes(x_range=[0, 12, 1], y_range=[0, 15, 3], axis_config={'include_tip': False, 'numbers_to_exclude': []}, x_length=10, y_length=5)\n axes.to_edge(DOWN, buff=0.8)\n x_label = Text('Time (t)', font_size=20).next_to(axes.x_axis, DOWN, buff=0.2)\n y_label = Text('Value', font_size=20).next_to(axes.y_axis, LEFT, buff=0.2).rotate(90 * DEGREES)\n self.play(Create(axes), Write(x_label), Write(y_label), run_time=2.0)\n data_points = [5, 7, 6, 8, 12, 9, 7, 6, 8, 10, 7, 6]\n alpha = 0.3\n ema_values = [data_points[0]]\n for i in range(1, len(data_points)):\n new_ema = (1 - alpha) * ema_values[-1] + alpha * data_points[i]\n ema_values.append(new_ema)\n dots = VGroup()\n for i, val in enumerate(data_points):\n dot = Dot(axes.c2p(i + 1, val), color=BLUE, radius=0.08)\n dots.add(dot)\n ema_line_points = [axes.c2p(i + 1, val) for i, val in enumerate(ema_values)]\n ema_line = VMobject(color=RED, stroke_width=3)\n ema_line.set_points_as_corners(ema_line_points)\n self.play(FadeIn(dots), run_time=2.0)\n current_ema_dot = Dot(axes.c2p(1, ema_values[0]), color=RED, radius=0.1)\n current_ema_label = MathTex('EMA_1 = X_1', font_size=20, color=RED)\n current_ema_label.next_to(current_ema_dot, UP, buff=0.3)\n self.play(FadeIn(current_ema_dot), Write(current_ema_label), run_time=2.0)\n for i in range(1, len(data_points)):\n new_ema_dot = Dot(axes.c2p(i + 1, ema_values[i]), color=RED, radius=0.1)\n connector = Line(axes.c2p(i, ema_values[i - 1]), axes.c2p(i + 1, ema_values[i]), color=RED, stroke_width=3)\n calc_text = MathTex(f'EMA_{{{i + 1}}} = {1 - alpha:.1f} \\times {ema_values[i - 1]:.1f} + {alpha:.1f} \\times {data_points[i]}', font_size=18, color=RED)\n calc_text.to_edge(UP, buff=0.3)\n result_text = MathTex(f'= {ema_values[i]:.2f}', font_size=18, color=RED)\n result_text.next_to(calc_text, RIGHT, buff=0.3)\n self.play(FadeOut(current_ema_label), Create(connector), FadeIn(new_ema_dot), Write(calc_text), run_time=2.0 * 0.7)\n self.play(Write(result_text), run_time=2.0 * 0.3)\n current_ema_dot = new_ema_dot\n current_ema_label = VGroup(calc_text, result_text)\n self.play(FadeOut(current_ema_label))\n self.play(Create(ema_line), run_time=2.0)\n self.play(FadeOut(dots), FadeOut(ema_line), FadeOut(current_ema_dot))\n comparison_title = Text('Impact of Alpha on Smoothing', font_size=24, color=YELLOW)\n comparison_title.to_edge(UP, buff=0.3)\n self.play(Write(comparison_title), run_time=2.0)\n alphas = [0.1, 0.3, 0.6]\n colors = [GREEN, RED, PURPLE]\n labels = ['α=0.1 (Smooth)', 'α=0.3 (Medium)', 'α=0.6 (Responsive)']\n legend_group = VGroup()\n ema_lines = VGroup()\n for alpha_val, color, label in zip(alphas, colors, labels):\n ema_vals = [data_points[0]]\n for j in range(1, len(data_points)):\n new_ema = (1 - alpha_val) * ema_vals[-1] + alpha_val * data_points[j]\n ema_vals.append(new_ema)\n line_points = [axes.c2p(j + 1, val) for j, val in enumerate(ema_vals)]\n line = VMobject(color=color, stroke_width=2.5)\n line.set_points_as_corners(line_points)\n ema_lines.add(line)\n legend_dot = Dot(color=color, radius=0.08)\n legend_text = Text(label, font_size=16, color=color)\n legend_entry = VGroup(legend_dot, legend_text).arrange(RIGHT, buff=0.2)\n legend_group.add(legend_entry)\n legend_group.arrange(RIGHT, buff=0.8)\n legend_group.next_to(comparison_title, DOWN, buff=0.3)\n self.play(FadeIn(legend_group), run_time=2.0 * 0.3)\n for line in ema_lines:\n self.play(Create(line), run_time=2.0 * 0.23)\n self.play(FadeIn(dots), run_time=2.0)\n self.wait(0.5)\n summary_title = Text('Key Takeaways', font_size=28, color=YELLOW)\n summary_title.move_to(ORIGIN).to_edge(UP, buff=1)\n takeaways = VGroup(Text('• EMA blends previous average with new data', font_size=20), Text('• Alpha controls the smoothing vs responsiveness trade-off', font_size=20), Text('• Higher α = more responsive, Lower α = smoother', font_size=20), Text('• EMA is widely used in time series analysis and ML', font_size=20)).arrange(DOWN, buff=0.4, aligned_edge=LEFT)\n takeaways.next_to(summary_title, DOWN, buff=0.5)\n self.play(FadeOut(axes), FadeOut(x_label), FadeOut(y_label), FadeOut(dots), FadeOut(ema_lines), FadeOut(legend_group), FadeOut(comparison_title), run_time=0.5)\n self.play(Write(summary_title), run_time=2.0 * 0.2)\n for item in takeaways:\n self.play(Write(item), run_time=2.0 * 0.2)\n self.wait(1)\n```", "rejected": "```python\nfrom manim import *\n\nclass EMAUpdateScene(Scene):\n\n def construct(self):\n title = Text('Exponential Moving Average (EMA)', font_size=36)\n subtitle = Text('Running Mean Update Visualization', font_size=24, color=BLUE)\n title_group = VGroup(title, subtitle).arrange(DOWN, buff=0.3)\n self.play(Write(title), run_time=2.0 * 0.6)\n self.play(FadeIn(subtitle), run_time=2.0 * 0.4)\n self.wait(0.5)\n self.play(FadeOut(title_group))\n formula_title = Text('The EMA Formula:', font_size=28, color=YELLOW)\n formula_title.to_edge(UP, buff=0.5)\n ema_formula = MathTex('EMA_t = (1 - \\\\alpha) \\\\cdot EMA_{t-1} + \\\\alpha \\\\cdot X_t', font_size=32)\n alpha_formula = MathTex('\\\\alpha = \\\\frac{2}{N + 1}', font_size=28)\n formulas = VGroup(ema_formula, alpha_formula).arrange(DOWN, buff=0.5)\n formulas.next_to(formula_title, DOWN, buff=0.5)\n self.play(Write(formula_title), run_time=2.0 * 0.2)\n self.play(Write(ema_formula), run_time=2.0 * 0.5)\n self.play(Write(alpha_formula), run_time=2.0 * 0.3)\n self.wait(2.0)\n self.play(FadeOut(formula_title), FadeOut(formulas))\n axes = Axes(axis_color=BLUE, x_range=[0, 12, 1], y_range=[0, 15, 3], axis_config={'include_tip': False, 'numbers_to_exclude': []}, x_length=10, y_length=5)\n axes.to_edge(DOWN, buff=0.8)\n x_label = Text('Time (t)', font_size=20).next_to(axes.x_axis, DOWN, buff=0.2)\n y_label = Text('Value', font_size=20).next_to(axes.y_axis, LEFT, buff=0.2).rotate(90 * DEGREES)\n self.play(Create(axes), Write(x_label), Write(y_label), run_time=2.0)\n data_points = [5, 7, 6, 8, 12, 9, 7, 6, 8, 10, 7, 6]\n alpha = 0.3\n ema_values = [data_points[0]]\n for i in range(1, len(data_points)):\n new_ema = (1 - alpha) * ema_values[-1] + alpha * data_points[i]\n ema_values.append(new_ema)\n dots = VGroup()\n for i, val in enumerate(data_points):\n dot = Dot(axes.c2p(i + 1, val), color=BLUE, radius=0.08)\n dots.add(dot)\n ema_line_points = [axes.c2p(i + 1, val) for i, val in enumerate(ema_values)]\n ema_line = VMobject(color=RED, stroke_width=3)\n ema_line.set_points_as_corners(ema_line_points)\n self.play(FadeIn(dots), run_time=2.0)\n current_ema_dot = Dot(axes.c2p(1, ema_values[0]), color=RED, radius=0.1)\n current_ema_label = MathTex('EMA_1 = X_1', font_size=20, color=RED)\n current_ema_label.next_to(current_ema_dot, UP, buff=0.3)\n self.play(FadeIn(current_ema_dot), Write(current_ema_label), run_time=2.0)\n for i in range(1, len(data_points)):\n new_ema_dot = Dot(axes.c2p(i + 1, ema_values[i]), color=RED, radius=0.1)\n connector = Line(axes.c2p(i, ema_values[i - 1]), axes.c2p(i + 1, ema_values[i]), color=RED, stroke_width=3)\n calc_text = MathTex(f'EMA_{{{i + 1}}} = {1 - alpha:.1f} \\times {ema_values[i - 1]:.1f} + {alpha:.1f} \\times {data_points[i]}', font_size=18, color=RED)\n calc_text.to_edge(UP, buff=0.3)\n result_text = MathTex(f'= {ema_values[i]:.2f}', font_size=18, color=RED)\n result_text.next_to(calc_text, RIGHT, buff=0.3)\n self.play(FadeOut(current_ema_label), Create(connector), FadeIn(new_ema_dot), Write(calc_text), run_time=2.0 * 0.7)\n self.play(Write(result_text), run_time=2.0 * 0.3)\n current_ema_dot = new_ema_dot\n current_ema_label = VGroup(calc_text, result_text)\n self.play(FadeOut(current_ema_label))\n self.play(Create(ema_line), run_time=2.0)\n self.play(FadeOut(dots), FadeOut(ema_line), FadeOut(current_ema_dot))\n comparison_title = Text('Impact of Alpha on Smoothing', font_size=24, color=YELLOW)\n comparison_title.to_edge(UP, buff=0.3)\n self.play(Write(comparison_title), run_time=2.0)\n alphas = [0.1, 0.3, 0.6]\n colors = [GREEN, RED, PURPLE]\n labels = ['α=0.1 (Smooth)', 'α=0.3 (Medium)', 'α=0.6 (Responsive)']\n legend_group = VGroup()\n ema_lines = VGroup()\n for alpha_val, color, label in zip(alphas, colors, labels):\n ema_vals = [data_points[0]]\n for j in range(1, len(data_points)):\n new_ema = (1 - alpha_val) * ema_vals[-1] + alpha_val * data_points[j]\n ema_vals.append(new_ema)\n line_points = [axes.c2p(j + 1, val) for j, val in enumerate(ema_vals)]\n line = VMobject(color=color, stroke_width=2.5)\n line.set_points_as_corners(line_points)\n ema_lines.add(line)\n legend_dot = Dot(color=color, radius=0.08)\n legend_text = Text(label, font_size=16, color=color)\n legend_entry = VGroup(legend_dot, legend_text).arrange(RIGHT, buff=0.2)\n legend_group.add(legend_entry)\n legend_group.arrange(RIGHT, buff=0.8)\n legend_group.next_to(comparison_title, DOWN, buff=0.3)\n self.play(FadeIn(legend_group), run_time=2.0 * 0.3)\n for line in ema_lines:\n self.play(Create(line), run_time=2.0 * 0.23)\n self.play(FadeIn(dots), run_time=2.0)\n self.wait(0.5)\n summary_title = Text('Key Takeaways', font_size=28, color=YELLOW)\n summary_title.move_to(ORIGIN).to_edge(UP, buff=1)\n takeaways = VGroup(Text('• EMA blends previous average with new data', font_size=20), Text('• Alpha controls the smoothing vs responsiveness trade-off', font_size=20), Text('• Higher α = more responsive, Lower α = smoother', font_size=20), Text('• EMA is widely used in time series analysis and ML', font_size=20)).arrange(DOWN, buff=0.4, aligned_edge=LEFT)\n takeaways.next_to(summary_title, DOWN, buff=0.5)\n self.play(FadeOut(axes), FadeOut(x_label), FadeOut(y_label), FadeOut(dots), FadeOut(ema_lines), FadeOut(legend_group), FadeOut(comparison_title), run_time=0.5)\n self.play(Write(summary_title), run_time=2.0 * 0.2)\n for item in takeaways:\n self.play(Write(item), run_time=2.0 * 0.2)\n self.wait(1)\n```", "category": "invalid_axes_kwarg", "source": "synthetic_hard_neg:nabin2004/AOS-Manim-SFT"} +{"system": "You are an expert Manim Community Edition (ManimCE v0.19+) Python developer and mathematical animator. Given a user request, first plan the spatial layout, coordinate bounds, timing, and pedagogical flow inside ... tags (when reasoning is helpful), and then output a complete, runnable, self-contained ManimCE Python script using `from manim import *`. Never use deprecated ManimGL (`manimlib`) methods like `ShowCreation`, `TexMobject`, `TextMobject`, or `axes.get_graph`; always use modern ManimCE APIs (`Create`, `MathTex`, `Tex`, `Text`, `axes.plot`) and prevent visual overlap using `.to_edge()`, `.next_to()`, and `FadeOut`.", "prompt": "I'm learning how the gradient of Cross-Entropy loss with respect to logits looks.\nAnimate the derivation for a simple vector z and one-hot y, showing softmax(z) and the error softmax(z)-y, with a live update as z changes.\nInclude multiple classes and a heatmap of dL/dz across the logit dimensions, and let me tweak z to see the gradient respond.", "chosen": "```python\nfrom manim import *\nfrom manim_voiceover import VoiceoverScene\nfrom manim_voiceover.services.gtts import GTTSService\n\nclass CrossEntropyGradientScene(VoiceoverScene):\n def construct(self):\n self.set_speech_service(\n GTTSService(voice=\"alba\", cache_dir=\"voiceover_cache\")\n )\n self.camera.background_color = \"#1e1e1e\"\n\n # Title\n title = Text(\"Gradient of Cross Entropy Loss\", font_size=40, color=WHITE)\n title.to_edge(UP, buff=0.5)\n\n # ---- Opener ----\n with self.voiceover(text=\"Imagine you're training a model to distinguish between cats and dogs. You're getting results, but they aren't quite right. What if I told you that by understanding the gradient of cross entropy loss, you could dramatically enhance your model's ability to learn?\") as tracker:\n self.play(Write(title), run_time=tracker.duration)\n\n self.wait(0.3)\n\n # ---- Cross Entropy Loss ----\n ce_formula = MathTex(r\"L = -\\sum_{i} y_i \\log(y'_i)\", font_size=40)\n ce_formula.next_to(title, DOWN, buff=0.8)\n\n with self.voiceover(text=\"Cross entropy loss measures how far your predictions are from the true labels. It's written as L equals negative sum over i of y sub i times the log of y prime sub i. Here, y is the true label, and y prime is the model's predicted probability.\") as tracker:\n self.play(Write(ce_formula), run_time=tracker.duration)\n\n self.wait(0.3)\n\n lbl_true = Text(\"y = true label\", font_size=28, color=BLUE)\n lbl_pred = Text(\"y' = predicted probability\", font_size=28, color=YELLOW)\n labels = VGroup(lbl_true, lbl_pred).arrange(RIGHT, buff=1.5)\n labels.next_to(ce_formula, DOWN, buff=0.6)\n\n with self.voiceover(text=\"The true label y is often one-hot encoded, while y prime comes from the model's softmax output.\") as tracker:\n self.play(FadeIn(lbl_true), FadeIn(lbl_pred), run_time=tracker.duration)\n\n self.wait(0.3)\n\n # ---- Softmax & Goal ----\n self.play(FadeOut(labels))\n\n softmax = MathTex(r\"y'_i = \\frac{e^{z_i}}{\\sum_j e^{z_j}}\", font_size=38)\n softmax.next_to(ce_formula, DOWN, buff=0.6)\n\n goal = MathTex(r\"\\frac{\\partial L}{\\partial z_k} = \\,?\", font_size=38, color=GREEN)\n goal.next_to(softmax, DOWN, buff=0.6)\n\n with self.voiceover(text=\"In a multi-class problem, the prediction y prime is the softmax of the logits z. Our goal is to find the derivative of the loss with respect to these logits.\") as tracker:\n self.play(Write(softmax), run_time=tracker.duration * 0.6)\n self.play(Write(goal), run_time=tracker.duration * 0.4)\n\n self.wait(0.3)\n\n # ---- Derivation ----\n self.play(FadeOut(ce_formula), FadeOut(softmax), FadeOut(goal))\n\n step1 = MathTex(\n r\"\\frac{\\partial L}{\\partial z_k} = -\\sum_{i} y_i \\frac{1}{y'_i} \\frac{\\partial y'_i}{\\partial z_k}\",\n font_size=30\n )\n step1.move_to(UP * 1.2)\n\n with self.voiceover(text=\"Using the chain rule, the derivative becomes negative sum over i of y sub i over y prime sub i, times the derivative of y prime sub i with respect to z sub k.\") as tracker:\n self.play(Write(step1), run_time=tracker.duration)\n\n self.wait(0.3)\n\n step2 = MathTex(\n r\"\\frac{\\partial y'_i}{\\partial z_k} = y'_i \\bigl(\\delta_{ik} - y'_k\\bigr)\",\n font_size=30,\n color=YELLOW\n )\n step2.next_to(step1, DOWN, buff=0.5)\n\n with self.voiceover(text=\"The derivative of the softmax function has a special property. It equals y prime sub i times the Kronecker delta i k minus y prime sub k.\") as tracker:\n self.play(Write(step2), run_time=tracker.duration)\n\n self.wait(0.3)\n\n step3 = MathTex(\n r\"= -\\sum_{i} y_i \\bigl(\\delta_{ik} - y'_k\\bigr)\",\n font_size=30\n )\n step3.next_to(step2, DOWN, buff=0.5)\n\n with self.voiceover(text=\"Substituting this back in, the y prime sub i terms cancel, leaving negative sum over i of y sub i times delta i k minus y prime sub k.\") as tracker:\n self.play(Write(step3), run_time=tracker.duration)\n\n self.wait(0.3)\n\n step4 = MathTex(\n r\"= -y_k + y'_k \\sum_{i} y_i\",\n font_size=30\n )\n step4.next_to(step3, DOWN, buff=0.5)\n\n with self.voiceover(text=\"Because the Kronecker delta picks out y sub k, and y prime sub k is constant with respect to i. Since the true label y is one-hot, the sum of y sub i over i equals one.\") as tracker:\n self.play(Write(step4), run_time=tracker.duration)\n\n self.wait(0.3)\n\n step5 = MathTex(\n r\"\\frac{\\partial L}{\\partial z_k} = y'_k - y_k\",\n font_size=38,\n color=GREEN\n )\n step5.move_to(ORIGIN + UP * 0.5)\n\n inter_group = VGroup(step1, step2, step3, step4)\n\n with self.voiceover(text=\"This beautifully simplifies to y prime sub k minus y sub k. The gradient of the loss with respect to a logit is simply the prediction minus the target.\") as tracker:\n self.play(FadeOut(inter_group), run_time=tracker.duration * 0.4)\n self.play(Write(step5), run_time=tracker.duration * 0.6)\n\n self.wait(0.3)\n\n # ---- Batch Average ----\n batch_eq = MathTex(\n r\"\\nabla L = \\frac{1}{N} \\sum_{n=1}^{N} \\bigl( y'^{(n)} - y^{(n)} \\bigr)\",\n font_size=36,\n color=YELLOW\n )\n batch_eq.next_to(step5, DOWN, buff=0.7)\n\n with self.voiceover(text=\"For a mini-batch of N samples, we average this gradient across all examples. The final result is one over N times the sum of predictions minus targets, which matches the compact formula you set out to understand.\") as tracker:\n self.play(Write(batch_eq), run_time=tracker.duration)\n\n self.wait(0.3)\n\n # ---- Takeaways ----\n tk1 = Text(\"• Error signal = prediction − target\", font_size=28)\n tk2 = Text(\"• Enables efficient backpropagation\", font_size=28)\n tk3 = Text(\"• Essential for training classifiers\", font_size=28)\n takeaways = VGroup(tk1, tk2, tk3).arrange(DOWN, aligned_edge=LEFT, buff=0.35)\n takeaways.to_edge(DOWN, buff=0.5)\n\n rect = SurroundingRectangle(takeaways, buff=0.25, color=BLUE, corner_radius=0.1)\n\n with self.voiceover(text=\"So remember, the gradient of cross entropy loss takes a shockingly simple form. The error signal is prediction minus target. This makes backpropagation efficient and is why this loss dominates classification tasks.\") as tracker:\n self.play(FadeIn(rect), FadeIn(takeaways), run_time=tracker.duration)\n\n self.wait(1)\n```", "rejected": "```python\nfrom manim import *\nfrom manim_voiceover import VoiceoverScene\nfrom manim_voiceover.services.gtts import GTTSService\n\nclass CrossEntropyGradientScene(VoiceoverScene):\n def construct(self):\n self.set_speech_service(\n GTTSService(voice=\"alba\", cache_dir=\"voiceover_cache\")\n )\n self.camera.background_color = \"#1e1e1e\"\n\n # Title\n title = Text(\"Gradient of Cross Entropy Loss\", font_size=40, color=WHITE)\n title.to_edge(UP, buff=0.5)\n\n # ---- Opener ----\n with self.voiceover(text=\"Imagine you're training a model to distinguish between cats and dogs. You're getting results, but they aren't quite right. What if I told you that by understanding the gradient of cross entropy loss, you could dramatically enhance your model's ability to learn?\") as tracker:\n self.play(Write(title), run_time=tracker.duration)\n\n self.wait(0.3)\n\n # ---- Cross Entropy Loss ----\n ce_formula = TexMobject(r\"L = -\\sum_{i} y_i \\log(y'_i)\", font_size=40)\n ce_formula.next_to(title, DOWN, buff=0.8)\n\n with self.voiceover(text=\"Cross entropy loss measures how far your predictions are from the true labels. It's written as L equals negative sum over i of y sub i times the log of y prime sub i. Here, y is the true label, and y prime is the model's predicted probability.\") as tracker:\n self.play(Write(ce_formula), run_time=tracker.duration)\n\n self.wait(0.3)\n\n lbl_true = Text(\"y = true label\", font_size=28, color=BLUE)\n lbl_pred = Text(\"y' = predicted probability\", font_size=28, color=YELLOW)\n labels = VGroup(lbl_true, lbl_pred).arrange(RIGHT, buff=1.5)\n labels.next_to(ce_formula, DOWN, buff=0.6)\n\n with self.voiceover(text=\"The true label y is often one-hot encoded, while y prime comes from the model's softmax output.\") as tracker:\n self.play(FadeIn(lbl_true), FadeIn(lbl_pred), run_time=tracker.duration)\n\n self.wait(0.3)\n\n # ---- Softmax & Goal ----\n self.play(FadeOut(labels))\n\n softmax = MathTex(r\"y'_i = \\frac{e^{z_i}}{\\sum_j e^{z_j}}\", font_size=38)\n softmax.next_to(ce_formula, DOWN, buff=0.6)\n\n goal = MathTex(r\"\\frac{\\partial L}{\\partial z_k} = \\,?\", font_size=38, color=GREEN)\n goal.next_to(softmax, DOWN, buff=0.6)\n\n with self.voiceover(text=\"In a multi-class problem, the prediction y prime is the softmax of the logits z. Our goal is to find the derivative of the loss with respect to these logits.\") as tracker:\n self.play(Write(softmax), run_time=tracker.duration * 0.6)\n self.play(Write(goal), run_time=tracker.duration * 0.4)\n\n self.wait(0.3)\n\n # ---- Derivation ----\n self.play(FadeOut(ce_formula), FadeOut(softmax), FadeOut(goal))\n\n step1 = MathTex(\n r\"\\frac{\\partial L}{\\partial z_k} = -\\sum_{i} y_i \\frac{1}{y'_i} \\frac{\\partial y'_i}{\\partial z_k}\",\n font_size=30\n )\n step1.move_to(UP * 1.2)\n\n with self.voiceover(text=\"Using the chain rule, the derivative becomes negative sum over i of y sub i over y prime sub i, times the derivative of y prime sub i with respect to z sub k.\") as tracker:\n self.play(Write(step1), run_time=tracker.duration)\n\n self.wait(0.3)\n\n step2 = MathTex(\n r\"\\frac{\\partial y'_i}{\\partial z_k} = y'_i \\bigl(\\delta_{ik} - y'_k\\bigr)\",\n font_size=30,\n color=YELLOW\n )\n step2.next_to(step1, DOWN, buff=0.5)\n\n with self.voiceover(text=\"The derivative of the softmax function has a special property. It equals y prime sub i times the Kronecker delta i k minus y prime sub k.\") as tracker:\n self.play(Write(step2), run_time=tracker.duration)\n\n self.wait(0.3)\n\n step3 = MathTex(\n r\"= -\\sum_{i} y_i \\bigl(\\delta_{ik} - y'_k\\bigr)\",\n font_size=30\n )\n step3.next_to(step2, DOWN, buff=0.5)\n\n with self.voiceover(text=\"Substituting this back in, the y prime sub i terms cancel, leaving negative sum over i of y sub i times delta i k minus y prime sub k.\") as tracker:\n self.play(Write(step3), run_time=tracker.duration)\n\n self.wait(0.3)\n\n step4 = MathTex(\n r\"= -y_k + y'_k \\sum_{i} y_i\",\n font_size=30\n )\n step4.next_to(step3, DOWN, buff=0.5)\n\n with self.voiceover(text=\"Because the Kronecker delta picks out y sub k, and y prime sub k is constant with respect to i. Since the true label y is one-hot, the sum of y sub i over i equals one.\") as tracker:\n self.play(Write(step4), run_time=tracker.duration)\n\n self.wait(0.3)\n\n step5 = MathTex(\n r\"\\frac{\\partial L}{\\partial z_k} = y'_k - y_k\",\n font_size=38,\n color=GREEN\n )\n step5.move_to(ORIGIN + UP * 0.5)\n\n inter_group = VGroup(step1, step2, step3, step4)\n\n with self.voiceover(text=\"This beautifully simplifies to y prime sub k minus y sub k. The gradient of the loss with respect to a logit is simply the prediction minus the target.\") as tracker:\n self.play(FadeOut(inter_group), run_time=tracker.duration * 0.4)\n self.play(Write(step5), run_time=tracker.duration * 0.6)\n\n self.wait(0.3)\n\n # ---- Batch Average ----\n batch_eq = MathTex(\n r\"\\nabla L = \\frac{1}{N} \\sum_{n=1}^{N} \\bigl( y'^{(n)} - y^{(n)} \\bigr)\",\n font_size=36,\n color=YELLOW\n )\n batch_eq.next_to(step5, DOWN, buff=0.7)\n\n with self.voiceover(text=\"For a mini-batch of N samples, we average this gradient across all examples. The final result is one over N times the sum of predictions minus targets, which matches the compact formula you set out to understand.\") as tracker:\n self.play(Write(batch_eq), run_time=tracker.duration)\n\n self.wait(0.3)\n\n # ---- Takeaways ----\n tk1 = Text(\"• Error signal = prediction − target\", font_size=28)\n tk2 = Text(\"• Enables efficient backpropagation\", font_size=28)\n tk3 = Text(\"• Essential for training classifiers\", font_size=28)\n takeaways = VGroup(tk1, tk2, tk3).arrange(DOWN, aligned_edge=LEFT, buff=0.35)\n takeaways.to_edge(DOWN, buff=0.5)\n\n rect = SurroundingRectangle(takeaways, buff=0.25, color=BLUE, corner_radius=0.1)\n\n with self.voiceover(text=\"So remember, the gradient of cross entropy loss takes a shockingly simple form. The error signal is prediction minus target. This makes backpropagation efficient and is why this loss dominates classification tasks.\") as tracker:\n self.play(FadeIn(rect), FadeIn(takeaways), run_time=tracker.duration)\n\n self.wait(1)\n```", "category": "legacy_api_hallucination", "source": "synthetic_hard_neg:nabin2004/AOS-Narrated-Manim-400"} +{"system": "You are an expert Manim Community Edition (ManimCE v0.19+) Python developer and mathematical animator. Given a user request, first plan the spatial layout, coordinate bounds, timing, and pedagogical flow inside ... tags (when reasoning is helpful), and then output a complete, runnable, self-contained ManimCE Python script using `from manim import *`. Never use deprecated ManimGL (`manimlib`) methods like `ShowCreation`, `TexMobject`, `TextMobject`, or `axes.get_graph`; always use modern ManimCE APIs (`Create`, `MathTex`, `Tex`, `Text`, `axes.plot`) and prevent visual overlap using `.to_edge()`, `.next_to()`, and `FadeOut`.", "prompt": "Construct a clean Manim CE scene initializing ArrowVectorField with verified keyword arguments. Ensure no deprecated ManimGL arguments (like element_color, max_value, or max_magnitude) are used.\n\n```python\nfrom manim import *\nimport numpy as np\n\nclass ApiValidArrowVectorField76(Scene):\n def construct(self):\n obj = ArrowVectorField(lambda p: np.array([-p[1], p[0], 0]), x_range=[-3, 3, 1], y_range=[-3, 3, 1])\n obj.set_color(ORANGE)\n self.play(Create(obj))\n self.wait(1)\n```", "chosen": "```python\nfrom manim import *\nfrom manim_voiceover import VoiceoverScene\nfrom manim_voiceover.services.gtts import GTTSService\nimport numpy as np\n\nMARGIN = 0.5\n\nclass ApiValidArrowVectorField76(VoiceoverScene):\n def fit_in_frame(self, mob: Mobject, w_frac=0.9, h_frac=0.9) -> Mobject:\n max_w = config.frame_width * w_frac\n max_h = config.frame_height * h_frac\n if mob.width > max_w:\n mob.width = max_w\n if mob.height > max_h:\n mob.height = max_h\n return mob\n\n def construct(self):\n self.set_speech_service(GTTSService(transcription_model=\"base\"))\n \n # [SETUP]\n # [LAYOUT]\n obj = ArrowVectorField(lambda p: np.array([-p[1], p[0], 0]), x_range=[-3, 3, 1], y_range=[-3, 3, 1])\n obj.set_color(ORANGE)\n obj = self.fit_in_frame(obj)\n self.add(obj)\n \n # [UPDATER]\n # [BEAT 1 | sync: b1]\n with self.voiceover(text=\"We initialize a rotational vector field. \") as t:\n self.wait_until_bookmark(\"b1\")\n self.play(Create(obj))\n \n # [BEAT 2 | sync: b2]\n with self.voiceover(text=\"Notice the clean setup without deprecated arguments. \") as t:\n self.wait_until_bookmark(\"b2\")\n self.wait(1)\n```", "rejected": "```python\nfrom manim import *\nfrom manim_voiceover import VoiceoverScene\nfrom manim_voiceover.services.gtts import GTTSService\nimport numpy as np\n\nMARGIN = 0.5\n\nclass ApiValidArrowVectorField76(VoiceoverScene):\n def fit_in_frame(self, mob: Mobject, w_frac=0.9, h_frac=0.9) -> Mobject:\n max_w = config.frame_width * w_frac\n max_h = config.frame_height * h_frac\n if mob.width > max_w:\n mob.width = max_w\n if mob.height > max_h:\n mob.height = max_h\n return mob\n\n def construct(self):\n self.set_speech_service(GTTSService(transcription_model=\"base\"))\n \n # [SETUP]\n # [LAYOUT]\n obj = ArrowVectorField(lambda p: np.array([-p[1], p[0], 0]), x_range=[-3, 3, 1], y_range=[-3, 3, 1])\n obj.set_color(ORANGE)\n obj = self.fit_in_frame(obj)\n self.add(obj)\n \n # [UPDATER]\n # [BEAT 1 | sync: b1]\n with self.voiceover(text=\"We initialize a rotational vector field. \") as t:\n self.wait_until_bookmark(\"b1\")\n self.play(ShowCreation(obj))\n \n # [BEAT 2 | sync: b2]\n with self.voiceover(text=\"Notice the clean setup without deprecated arguments. \") as t:\n self.wait_until_bookmark(\"b2\")\n self.wait(1)\n```", "category": "legacy_api_hallucination", "source": "synthetic_hard_neg:nabin2004/qwen3-8b-manimator-gold-sft"} +{"system": "You are an expert Manim Community Edition (ManimCE v0.19+) Python developer and mathematical animator. Given a user request, first plan the spatial layout, coordinate bounds, timing, and pedagogical flow inside ... tags (when reasoning is helpful), and then output a complete, runnable, self-contained ManimCE Python script using `from manim import *`. Never use deprecated ManimGL (`manimlib`) methods like `ShowCreation`, `TexMobject`, `TextMobject`, or `axes.get_graph`; always use modern ManimCE APIs (`Create`, `MathTex`, `Tex`, `Text`, `axes.plot`) and prevent visual overlap using `.to_edge()`, `.next_to()`, and `FadeOut`.", "prompt": "You are a Manim expert. Please convert the Markdown lecture notes into executable Manim CE v0.19.0 code that displays content in English. The page layout must be clear, with no overlapping elements, and you must not output any explanatory or descriptive text outside the code. Pay special attention to avoiding common errors such as LaTeX syntax issues and index out-of-range errors, and ensure the code can run directly. The Markdown lecture notes are as follows:\n\n### Keep the generated language unchanged\nThe deleted parts essentially do not contribute any valid strings belonging to the language.\n\n### Improve grammar analysis efficiency\nReduce the size of the grammar to decrease the time and space overhead of subsequent algorithms.\n\n## Definition of Chomsky Normal Form (CNF)\n\n### Form Requirements for CNF\nEach production rule either generates two non-terminal symbols ($A \\to BC$) or one terminal symbol ($A \\to a$).\n\n### Binary Productions and Terminal Productions\nThis strict binary structure ensures that the parse tree is always a binary tree, which is convenient for computation.\n\n\nThe context position of this section (from highest level to current):\n# Convert context-free grammars to standard form and perform algorithmic parsing\n## Eliminate useless symbols\n", "chosen": "```python\nfrom manim import *\nfrom manim import config\nText.set_default(font='SimHei')\n\nclass GrammarParsingNotes(Scene):\n\n def construct(self):\n title1 = Text('Eliminate Useless Symbols', font_size=42, weight=BOLD, color=BLUE)\n title1.to_edge(UP, buff=0.8)\n h1 = Text('• Keep the generated language unchanged', font_size=32, color=YELLOW)\n p1 = Text('The deleted parts essentially do not contribute any\\nvalid strings belonging to the language.', font_size=24, color=LIGHT_GREY)\n h2 = Text('• Improve grammar analysis efficiency', font_size=32, color=YELLOW)\n p2 = Text('Reduce the size of the grammar to decrease the time\\nand space overhead of subsequent algorithms.', font_size=24, color=LIGHT_GREY)\n slide1_content = VGroup(h1, p1, h2, p2).arrange(DOWN, aligned_edge=LEFT, buff=0.5)\n p1.shift(RIGHT * 0.5)\n p2.shift(RIGHT * 0.5)\n slide1_content.next_to(title1, DOWN, buff=1.0)\n self.play(Write(title1))\n self.play(FadeIn(h1, shift=RIGHT * 0.2))\n self.play(FadeIn(p1))\n self.wait(1)\n self.play(FadeIn(h2, shift=RIGHT * 0.2))\n self.play(FadeIn(p2))\n self.wait(2)\n self.play(FadeOut(title1), FadeOut(slide1_content))\n title2 = Text('Definition of Chomsky Normal Form (CNF)', font_size=42, weight=BOLD, color=BLUE)\n title2.to_edge(UP, buff=0.8)\n h3 = Text('• Form Requirements for CNF', font_size=32, color=YELLOW)\n p3 = Text('Each production rule either generates two non-terminal\\nsymbols or one terminal symbol.', font_size=24, color=LIGHT_GREY)\n math3 = MathTex('A \\\\to BC \\\\quad \\\\text{or} \\\\quad A \\\\to a', font_size=36, color=GREEN)\n h4 = Text('• Binary Productions and Terminal Productions', font_size=32, color=YELLOW)\n p4 = Text('This strict binary structure ensures that the parse tree\\nis always a binary tree, which is convenient for computation.', font_size=24, color=LIGHT_GREY)\n slide2_content = VGroup(h3, p3, math3, h4, p4).arrange(DOWN, aligned_edge=LEFT, buff=0.4)\n p3.shift(RIGHT * 0.5)\n math3.shift(RIGHT * 1.0)\n p4.shift(RIGHT * 0.5)\n slide2_content.next_to(title2, DOWN, buff=0.8)\n self.play(Write(title2))\n self.play(FadeIn(h3, shift=RIGHT * 0.2))\n self.play(FadeIn(p3))\n self.play(Write(math3))\n self.wait(1)\n self.play(FadeIn(h4, shift=RIGHT * 0.2))\n self.play(FadeIn(p4))\n self.wait(2)\n self.play(FadeOut(title2), FadeOut(slide2_content))\n self.wait(1)\n```", "rejected": "```python\nfrom manim import *\nfrom manim import config\nText.set_default(font='SimHei')\n\nclass GrammarParsingNotes(Scene):\n\n def construct(self):\n title1 = Text('Eliminate Useless Symbols', font_size=42, weight=BOLD, color=BLUE)\n title1.to_edge(UP, buff=0.8)\n h1 = Text('• Keep the generated language unchanged', font_size=32, color=YELLOW)\n p1 = Text('The deleted parts essentially do not contribute any\\nvalid strings belonging to the language.', font_size=24, color=LIGHT_GREY)\n h2 = Text('• Improve grammar analysis efficiency', font_size=32, color=YELLOW)\n p2 = Text('Reduce the size of the grammar to decrease the time\\nand space overhead of subsequent algorithms.', font_size=24, color=LIGHT_GREY)\n slide1_content = VGroup(h1, p1, h2, p2).arrange(DOWN, aligned_edge=LEFT, buff=0.5)\n p1.shift(RIGHT * 0.5)\n p2.shift(RIGHT * 0.5)\n slide1_content.next_to(title1, DOWN, buff=1.0)\n self.play(Write(title1))\n self.play(FadeIn(h1, shift=RIGHT * 0.2))\n self.play(FadeIn(p1))\n self.wait(1)\n self.play(FadeIn(h2, shift=RIGHT * 0.2))\n self.play(FadeIn(p2))\n self.wait(2)\n self.play(FadeOut(title1), FadeOut(slide1_content))\n title2 = Text('Definition of Chomsky Normal Form (CNF)', font_size=42, weight=BOLD, color=BLUE)\n title2.to_edge(UP, buff=0.8)\n h3 = Text('• Form Requirements for CNF', font_size=32, color=YELLOW)\n p3 = Text('Each production rule either generates two non-terminal\\nsymbols or one terminal symbol.', font_size=24, color=LIGHT_GREY)\n math3 = TexMobject('A \\\\to BC \\\\quad \\\\text{or} \\\\quad A \\\\to a', font_size=36, color=GREEN)\n h4 = Text('• Binary Productions and Terminal Productions', font_size=32, color=YELLOW)\n p4 = Text('This strict binary structure ensures that the parse tree\\nis always a binary tree, which is convenient for computation.', font_size=24, color=LIGHT_GREY)\n slide2_content = VGroup(h3, p3, math3, h4, p4).arrange(DOWN, aligned_edge=LEFT, buff=0.4)\n p3.shift(RIGHT * 0.5)\n math3.shift(RIGHT * 1.0)\n p4.shift(RIGHT * 0.5)\n slide2_content.next_to(title2, DOWN, buff=0.8)\n self.play(Write(title2))\n self.play(FadeIn(h3, shift=RIGHT * 0.2))\n self.play(FadeIn(p3))\n self.play(Write(math3))\n self.wait(1)\n self.play(FadeIn(h4, shift=RIGHT * 0.2))\n self.play(FadeIn(p4))\n self.wait(2)\n self.play(FadeOut(title2), FadeOut(slide2_content))\n self.wait(1)\n```", "category": "legacy_api_hallucination", "source": "synthetic_hard_neg:nabin2004/manim-sft-10k"} +{"system": "You are an expert Manim Community Edition (ManimCE v0.19+) Python developer and mathematical animator. Given a user request, first plan the spatial layout, coordinate bounds, timing, and pedagogical flow inside ... tags (when reasoning is helpful), and then output a complete, runnable, self-contained ManimCE Python script using `from manim import *`. Never use deprecated ManimGL (`manimlib`) methods like `ShowCreation`, `TexMobject`, `TextMobject`, or `axes.get_graph`; always use modern ManimCE APIs (`Create`, `MathTex`, `Tex`, `Text`, `axes.plot`) and prevent visual overlap using `.to_edge()`, `.next_to()`, and `FadeOut`.", "prompt": "You are a Manim expert. Please convert the Markdown lecture notes into executable Manim CE v0.19.0 code that displays content in English. The page layout must be clear, with no overlapping elements, and you must not output any explanatory or descriptive text outside the code. Pay special attention to avoiding common errors such as LaTeX syntax issues and index out-of-range errors, and ensure the code can run directly. The Markdown lecture notes are as follows:\n\n### Rules Adjust During the Learning Process\n* Avoid static rules being overfitted or exploited by agents, achieving dynamic balance.\n\n### Automated Mechanism Design\n* Use meta-learning or reinforcement learning to automatically search for the optimal incentive mechanisms (such as taxes, auction rules).\n\n\nThe context location of this section (from highest to current level):\n# Emerging Directions and Open Questions\n## Deep Integration of Mechanism Design and Learning\n", "chosen": "```python\nfrom manim import *\nfrom manim import config\nText.set_default(font='SimHei')\n\nclass MechanismDesignAndLearning(Scene):\n\n def construct(self):\n title = Text('Emerging Directions and Open Questions', font_size=36, weight=BOLD)\n subtitle = Text('Deep Integration of Mechanism Design and Learning', font_size=28, color=BLUE)\n title_group = VGroup(title, subtitle).arrange(DOWN, buff=0.2)\n title_group.to_edge(UP, buff=0.5)\n bullet_1 = Text('• Rules Adjust During the Learning Process', font_size=26, weight=BOLD)\n sub_bullet_1 = Text(' - Avoid static rules being overfitted or exploited by agents,\\n achieving dynamic balance.', font_size=22, color=LIGHT_GREY)\n group_1 = VGroup(bullet_1, sub_bullet_1).arrange(DOWN, aligned_edge=LEFT, buff=0.2)\n bullet_2 = Text('• Automated Mechanism Design', font_size=26, weight=BOLD)\n sub_bullet_2 = Text(' - Use meta-learning or reinforcement learning to automatically search\\n for the optimal incentive mechanisms (such as taxes, auction rules).', font_size=22, color=LIGHT_GREY)\n group_2 = VGroup(bullet_2, sub_bullet_2).arrange(DOWN, aligned_edge=LEFT, buff=0.2)\n content_group = VGroup(group_1, group_2).arrange(DOWN, aligned_edge=LEFT, buff=0.6)\n content_group.next_to(title_group, DOWN, buff=0.8)\n content_group.to_edge(LEFT, buff=1.0)\n self.play(FadeIn(title_group, shift=DOWN))\n self.wait(1)\n self.play(Write(bullet_1))\n self.play(FadeIn(sub_bullet_1, shift=RIGHT))\n self.wait(2)\n self.play(Write(bullet_2))\n self.play(FadeIn(sub_bullet_2, shift=RIGHT))\n self.wait(3)\n```", "rejected": "```python\nfrom manim import *\nfrom manim import config\nText.set_default(font='SimHei')\n\nclass MechanismDesignAndLearning(Scene):\n\n def construct(self):\n title = Text('Emerging Directions and Open Questions', font_size=36, weight=BOLD)\n subtitle = Text('Deep Integration of Mechanism Design and Learning', font_size=28, color=BLUE)\n title_group = VGroup(title, subtitle).arrange(DOWN, buff=0.2)\n title_group\n bullet_1 = Text('• Rules Adjust During the Learning Process', font_size=26, weight=BOLD)\n sub_bullet_1 = Text(' - Avoid static rules being overfitted or exploited by agents,\\n achieving dynamic balance.', font_size=22, color=LIGHT_GREY)\n group_1 = VGroup(bullet_1, sub_bullet_1).arrange(DOWN, aligned_edge=LEFT, buff=0.2)\n bullet_2 = Text('• Automated Mechanism Design', font_size=26, weight=BOLD)\n sub_bullet_2 = Text(' - Use meta-learning or reinforcement learning to automatically search\\n for the optimal incentive mechanisms (such as taxes, auction rules).', font_size=22, color=LIGHT_GREY)\n group_2 = VGroup(bullet_2, sub_bullet_2).arrange(DOWN, aligned_edge=LEFT, buff=0.2)\n content_group = VGroup(group_1, group_2).arrange(DOWN, aligned_edge=LEFT, buff=0.6)\n content_group\n content_group\n self.play(FadeIn(title_group, shift=DOWN))\n self.wait(1)\n self.play(Write(bullet_1))\n self.play(FadeIn(sub_bullet_1, shift=RIGHT))\n self.wait(2)\n self.play(Write(bullet_2))\n self.play(FadeIn(sub_bullet_2, shift=RIGHT))\n self.wait(3)\n```", "category": "spatial_layout_overlap", "source": "synthetic_hard_neg:nabin2004/manim-sft-10k"} +{"system": "You are an expert Manim Community Edition (ManimCE v0.19+) Python developer and mathematical animator. Given a user request, first plan the spatial layout, coordinate bounds, timing, and pedagogical flow inside ... tags (when reasoning is helpful), and then output a complete, runnable, self-contained ManimCE Python script using `from manim import *`. Never use deprecated ManimGL (`manimlib`) methods like `ShowCreation`, `TexMobject`, `TextMobject`, or `axes.get_graph`; always use modern ManimCE APIs (`Create`, `MathTex`, `Tex`, `Text`, `axes.plot`) and prevent visual overlap using `.to_edge()`, `.next_to()`, and `FadeOut`.", "prompt": "I'm teaching information theory in ML and want a visual equation: cross-entropy decomposed into KL-divergence plus entropy.\nAnimate two distributions p and q, show KL divergence as the difference in their areas, and add a constant entropy term that leaves the total unchanged.\nPlot the two terms separately as colored areas, then combine to show the cross-entropy, with a note on invariance due to the added term.\nAllow adjusting the target distribution to see how the terms shift while entropy constant remains fixed.", "chosen": "```python\nfrom manim import *\nfrom manim_voiceover import VoiceoverScene\nfrom manim_voiceover.services.gtts import GTTSService\n\nclass CrossEntropyKLScene(VoiceoverScene):\n def construct(self):\n # [SETUP]\n # [LAYOUT]\n self.set_speech_service(GTTSService(transcription_model=\"base\"))\n \n # [BEAT 1 | sync: CE]\n with self.voiceover(text=\"In information theory, Cross-Entropy measures the difference between two probability distributions. It is widely used as a loss function in classification tasks.\") as tracker:\n title = Text(\"Cross-Entropy & KL Divergence\", font_size=36, color=BLUE)\n self.fit_in_frame(title)\n title.to_edge(UP)\n ce_formula = MathTex(\"H(P, Q) = -\\\\sum_{x} P(x) \\\\log Q(x)\", font_size=36)\n ce_formula.next_to(title, DOWN, buff=0.8)\n self.wait_until_bookmark(\"CE\")\n self.play(Write(title), Write(ce_formula), run_time=tracker.duration)\n \n with self.voiceover(text=\"KL Divergence measures the extra information needed when using Q instead of P. It is always non-negative and zero only when the distributions are identical.\") as tracker:\n kl_formula = MathTex(\"D_{KL}(P \\\\parallel Q) = \\\\sum_{x} P(x) \\\\log \\\\frac{P(x)}{Q(x)}\", font_size=36)\n kl_formula.next_to(ce_formula, DOWN, buff=0.8)\n self.wait_until_bookmark(\"KL\")\n self.play(Write(kl_formula), run_time=tracker.duration)\n \n with self.voiceover(text=\"The relationship is elegant: Cross-Entropy is simply the Entropy of P plus the KL Divergence. This shows why minimizing Cross-Entropy is equivalent to minimizing KL Divergence.\") as tracker:\n rel_formula = MathTex(\"H(P, Q) = H(P) + D_{KL}(P \\\\parallel Q)\", font_size=36, color=GREEN)\n rel_formula.next_to(kl_formula, DOWN, buff=0.8)\n self.wait_until_bookmark(\"REL\")\n self.play(Write(rel_formula), run_time=tracker.duration)\n self.wait(1)\n\n def fit_in_frame(self, mob: Mobject, w_frac: float = 0.9, h_frac: float = 0.9) -> Mobject:\n max_w = config.frame_width * w_frac\n max_h = config.frame_height * h_frac\n if mob.width > max_w:\n mob.width = max_w\n if mob.height > max_h:\n mob.height = max_h\n return mob\n```", "rejected": "```python\nfrom manim import *\nfrom manim_voiceover import VoiceoverScene\nfrom manim_voiceover.services.gtts import GTTSService\n\nclass CrossEntropyKLScene(VoiceoverScene):\n def construct(self):\n # [SETUP]\n # [LAYOUT]\n self.set_speech_service(GTTSService(transcription_model=\"base\"))\n \n # [BEAT 1 | sync: CE]\n with self.voiceover(text=\"In information theory, Cross-Entropy measures the difference between two probability distributions. It is widely used as a loss function in classification tasks.\") as tracker:\n title = Text(\"Cross-Entropy & KL Divergence\", font_size=36, color=BLUE)\n self.fit_in_frame(title)\n title\n ce_formula = MathTex(\"H(P, Q) = -\\\\sum_{x} P(x) \\\\log Q(x)\", font_size=36)\n ce_formula\n self.wait_until_bookmark(\"CE\")\n self.play(Write(title), Write(ce_formula), run_time=tracker.duration)\n \n with self.voiceover(text=\"KL Divergence measures the extra information needed when using Q instead of P. It is always non-negative and zero only when the distributions are identical.\") as tracker:\n kl_formula = MathTex(\"D_{KL}(P \\\\parallel Q) = \\\\sum_{x} P(x) \\\\log \\\\frac{P(x)}{Q(x)}\", font_size=36)\n kl_formula\n self.wait_until_bookmark(\"KL\")\n self.play(Write(kl_formula), run_time=tracker.duration)\n \n with self.voiceover(text=\"The relationship is elegant: Cross-Entropy is simply the Entropy of P plus the KL Divergence. This shows why minimizing Cross-Entropy is equivalent to minimizing KL Divergence.\") as tracker:\n rel_formula = MathTex(\"H(P, Q) = H(P) + D_{KL}(P \\\\parallel Q)\", font_size=36, color=GREEN)\n rel_formula.next_to(kl_formula, DOWN, buff=0.8)\n self.wait_until_bookmark(\"REL\")\n self.play(Write(rel_formula), run_time=tracker.duration)\n self.wait(1)\n\n def fit_in_frame(self, mob: Mobject, w_frac: float = 0.9, h_frac: float = 0.9) -> Mobject:\n max_w = config.frame_width * w_frac\n max_h = config.frame_height * h_frac\n if mob.width > max_w:\n mob.width = max_w\n if mob.height > max_h:\n mob.height = max_h\n return mob\n```", "category": "spatial_layout_overlap", "source": "synthetic_hard_neg:nabin2004/qwen3-8b-manimator-gold-sft"} +{"system": "You are an expert Manim Community Edition (ManimCE v0.19+) Python developer and mathematical animator. Given a user request, first plan the spatial layout, coordinate bounds, timing, and pedagogical flow inside ... tags (when reasoning is helpful), and then output a complete, runnable, self-contained ManimCE Python script using `from manim import *`. Never use deprecated ManimGL (`manimlib`) methods like `ShowCreation`, `TexMobject`, `TextMobject`, or `axes.get_graph`; always use modern ManimCE APIs (`Create`, `MathTex`, `Tex`, `Text`, `axes.plot`) and prevent visual overlap using `.to_edge()`, `.next_to()`, and `FadeOut`.", "prompt": "You are a Manim expert. Please convert the Markdown lecture notes into executable Manim CE v0.19.0 code that displays content in English. The page layout must be clear, with no overlapping elements, and you must not output any explanatory or descriptive text outside the code. Pay special attention to avoiding common errors such as LaTeX syntax issues and index out-of-range errors, and ensure the code can run directly. The Markdown lecture notes are as follows:\n\n### Proof Command and Qed Command\n\nProof and Qed are the start and end markers of a proof, respectively. All Coq commands between them are part of the proof script. In Coq, users complete proofs through proof scripts. Typically, Coq proof scripts ensure that the logical transformations and reductions they perform are valid. In special cases, the Coq theorem prover also requires additional checks at the Qed command. After passing the Qed check, a Coq proof of a mathematical proposition is considered complete.\n\n\nContext location within the document (from highest to current level):\n# Simple Coq Proofs and Coq Definitions\n## Integer Arithmetic Operations and Size Comparisons\n", "chosen": "```python\nfrom manim import *\nfrom manim import config\nText.set_default(font='SimHei')\n\nclass ProofAndQed(Scene):\n\n def construct(self):\n title = Tex('\\\\textbf{Proof Command and Qed Command}', font_size=40, color=BLUE)\n context = Tex('Context: Simple Coq Proofs $\\\\rightarrow$ Integer Arithmetic', font_size=28, color=GRAY)\n title_group = VGroup(title, context).arrange(DOWN, buff=0.2).to_edge(UP)\n self.play(FadeIn(title_group, shift=DOWN))\n self.wait(1)\n proof_text = Tex('\\\\textbf{Proof.}', font_size=36, color=YELLOW)\n script_text = Tex('\\\\textit{... Proof Script ...}', font_size=32, color=LIGHT_GREY)\n qed_text = Tex('\\\\textbf{Qed.}', font_size=36, color=GREEN)\n code_group = VGroup(proof_text, script_text, qed_text).arrange(DOWN, buff=1.8).shift(LEFT * 3 + DOWN * 0.2)\n desc1 = Tex('Start marker of the proof', font_size=30)\n desc2 = Tex('Users complete proofs through scripts\\\\\\\\Ensures valid logical transformations\\\\\\\\and reductions', font_size=30)\n desc3 = Tex('End marker of the proof\\\\\\\\Prover requires additional checks', font_size=30)\n for desc, code in zip([desc1, desc2, desc3], [proof_text, script_text, qed_text]):\n desc.set_x(2.5)\n desc.match_y(code)\n else:\n pass\n arrow1 = Arrow(desc1.get_left(), proof_text.get_right(), buff=0.2, color=YELLOW)\n arrow2 = Arrow(desc2.get_left(), script_text.get_right(), buff=0.2, color=LIGHT_GREY)\n arrow3 = Arrow(desc3.get_left(), qed_text.get_right(), buff=0.2, color=GREEN)\n script_box = SurroundingRectangle(script_text, color=BLUE, buff=0.2)\n self.play(Write(proof_text))\n self.play(FadeIn(desc1, shift=LEFT), GrowArrow(arrow1))\n self.wait(0.5)\n self.play(Write(script_text))\n self.play(Create(script_box))\n self.play(FadeIn(desc2, shift=LEFT), GrowArrow(arrow2))\n self.wait(0.5)\n self.play(Write(qed_text))\n self.play(FadeIn(desc3, shift=LEFT), GrowArrow(arrow3))\n self.wait(1)\n check_box = SurroundingRectangle(desc3, color=RED, buff=0.15)\n self.play(Create(check_box))\n self.play(Indicate(qed_text, color=RED, scale_factor=1.2))\n self.wait(0.5)\n checkmark = MathTex('\\\\checkmark', color=GREEN, font_size=60).next_to(qed_text, LEFT, buff=0.5)\n complete_text = Tex('\\\\textbf{Mathematical Proposition Fully Proven!}', font_size=36, color=YELLOW).to_edge(DOWN, buff=0.5)\n self.play(Write(checkmark))\n self.play(FadeOut(check_box))\n self.play(FadeIn(complete_text, shift=UP))\n self.wait(2)\n```", "rejected": "```python\nfrom manim import *\nfrom manim import config\nText.set_default(font='SimHei')\n\nclass ProofAndQed(Scene):\n\n def construct(self):\n title = Tex('\\\\textbf{Proof Command and Qed Command}', font_size=40, color=BLUE)\n context = Tex('Context: Simple Coq Proofs $\\\\rightarrow$ Integer Arithmetic', font_size=28, color=GRAY)\n title_group = VGroup(title, context).arrange(DOWN, buff=0.2).to_edge(UP)\n self.play(FadeIn(title_group, shift=DOWN))\n self.wait(1)\n proof_text = Tex('\\\\textbf{Proof.}', font_size=36, color=YELLOW)\n script_text = Tex('\\\\textit{... Proof Script ...}', font_size=32, color=LIGHT_GREY)\n qed_text = Tex('\\\\textbf{Qed.}', font_size=36, color=GREEN)\n code_group = VGroup(proof_text, script_text, qed_text).arrange(DOWN, buff=1.8).shift(LEFT * 3 + DOWN * 0.2)\n desc1 = Tex('Start marker of the proof', font_size=30)\n desc2 = Tex('Users complete proofs through scripts\\\\\\\\Ensures valid logical transformations\\\\\\\\and reductions', font_size=30)\n desc3 = Tex('End marker of the proof\\\\\\\\Prover requires additional checks', font_size=30)\n for desc, code in zip([desc1, desc2, desc3], [proof_text, script_text, qed_text]):\n desc.set_x(2.5)\n desc.match_y(code)\n else:\n pass\n arrow1 = Arrow(desc1.get_left(), proof_text.get_right(), buff=0.2, color=YELLOW)\n arrow2 = Arrow(desc2.get_left(), script_text.get_right(), buff=0.2, color=LIGHT_GREY)\n arrow3 = Arrow(desc3.get_left(), qed_text.get_right(), buff=0.2, color=GREEN)\n script_box = SurroundingRectangle(script_text, color=BLUE, buff=0.2)\n self.play(Write(proof_text))\n self.play(FadeIn(desc1, shift=LEFT), GrowArrow(arrow1))\n self.wait(0.5)\n self.play(Write(script_text))\n self.play(ShowCreation(script_box))\n self.play(FadeIn(desc2, shift=LEFT), GrowArrow(arrow2))\n self.wait(0.5)\n self.play(Write(qed_text))\n self.play(FadeIn(desc3, shift=LEFT), GrowArrow(arrow3))\n self.wait(1)\n check_box = SurroundingRectangle(desc3, color=RED, buff=0.15)\n self.play(Create(check_box))\n self.play(Indicate(qed_text, color=RED, scale_factor=1.2))\n self.wait(0.5)\n checkmark = TexMobject('\\\\checkmark', color=GREEN, font_size=60).next_to(qed_text, LEFT, buff=0.5)\n complete_text = Tex('\\\\textbf{Mathematical Proposition Fully Proven!}', font_size=36, color=YELLOW).to_edge(DOWN, buff=0.5)\n self.play(Write(checkmark))\n self.play(FadeOut(check_box))\n self.play(FadeIn(complete_text, shift=UP))\n self.wait(2)\n```", "category": "legacy_api_hallucination", "source": "synthetic_hard_neg:nabin2004/manim-sft-10k"} +{"system": "You are an expert Manim Community Edition (ManimCE v0.19+) Python developer and mathematical animator. Given a user request, first plan the spatial layout, coordinate bounds, timing, and pedagogical flow inside ... tags (when reasoning is helpful), and then output a complete, runnable, self-contained ManimCE Python script using `from manim import *`. Never use deprecated ManimGL (`manimlib`) methods like `ShowCreation`, `TexMobject`, `TextMobject`, or `axes.get_graph`; always use modern ManimCE APIs (`Create`, `MathTex`, `Tex`, `Text`, `axes.plot`) and prevent visual overlap using `.to_edge()`, `.next_to()`, and `FadeOut`.", "prompt": "I'm teaching undergrads a course on normalization in neural nets and want a visualization of learnable scale and shift parameters (gamma and beta) reintroducing flexibility after normalization. Show gamma scaling and beta shifting on normalized features with animated parameter updates, and a side panel tracing their values over time. Include a before/after comparison and a short intuitive explanation of the mechanism.", "chosen": "```python\nfrom manim import *\nimport math\n\nclass GammaAndBetaNormalization(Scene):\n\n def construct(self):\n title = Text('Gamma and Beta in Normalization', font_size=42, color=BLUE)\n title.to_edge(UP, buff=0.5)\n self.play(Write(title), run_time=2.0)\n subtitle = Text('The Keys to Learnable Normalization', font_size=24, color=GRAY)\n subtitle.next_to(title, DOWN, buff=0.3)\n self.play(FadeIn(subtitle), run_time=2.0)\n self.wait(0.5)\n self.play(FadeOut(title), FadeOut(subtitle))\n norm_title = Text('Standard Normalization', font_size=32, color=YELLOW)\n norm_title.to_edge(UP, buff=0.5)\n eq1 = MathTex('y = \\\\frac{x - \\\\mu}{\\\\sqrt{\\\\sigma^2 + \\\\epsilon}}')\n eq1.set_color(WHITE)\n eq1.scale(1.2)\n self.play(Write(norm_title), run_time=2.0 * 0.4)\n self.play(Write(eq1), run_time=2.0 * 0.6)\n mean_label = MathTex('\\\\mu: \\\\text{mean}', font_size=20)\n mean_label.set_color(GREEN)\n mean_label.next_to(eq1, DOWN, buff=0.8)\n mean_label.shift(LEFT * 2)\n std_label = MathTex('\\\\sigma: \\\\text{standard deviation}', font_size=20)\n std_label.set_color(ORANGE)\n std_label.next_to(eq1, DOWN, buff=0.8)\n eps_label = MathTex('\\\\epsilon: \\\\text{small constant}', font_size=20)\n eps_label.set_color(PURPLE)\n eps_label.next_to(eq1, DOWN, buff=0.8)\n eps_label.shift(RIGHT * 2.5)\n self.play(FadeIn(mean_label), FadeIn(std_label), FadeIn(eps_label), run_time=2.0)\n self.wait(0.5)\n standard_result = Text('Result: Zero mean, Unit variance', font_size=22, color=LIGHT_GRAY)\n standard_result.next_to(eq1, DOWN, buff=2)\n self.play(Write(standard_result), run_time=2.0)\n self.wait(0.5)\n question = Text('But is this always optimal?', font_size=26, color=RED)\n question.to_edge(DOWN, buff=0.5)\n self.play(Write(question), run_time=2.0)\n self.wait(0.3)\n self.play(FadeOut(question))\n self.play(FadeOut(norm_title), FadeOut(mean_label), FadeOut(std_label), FadeOut(eps_label), FadeOut(standard_result), eq1.animate.to_edge(UP, buff=1.5).scale(0.8))\n gamma_beta_title = Text('Learnable Parameters: Gamma and Beta', font_size=30, color=YELLOW)\n gamma_beta_title.to_edge(UP, buff=0.5)\n eq2 = MathTex('\\\\hat{x} = \\\\gamma \\\\cdot y + \\\\beta')\n eq2.set_color(WHITE)\n eq2.scale(1.2)\n eq2.next_to(eq1, DOWN, buff=0.8)\n self.play(Write(gamma_beta_title), run_time=2.0 * 0.4)\n self.play(Write(eq2), run_time=2.0 * 0.6)\n gamma_label = MathTex('\\\\gamma: \\\\text{scale parameter}', font_size=22)\n gamma_label.set_color(BLUE)\n gamma_label.next_to(eq2, DOWN, buff=0.8)\n gamma_label.shift(LEFT * 2)\n beta_label = MathTex('\\\\beta: \\\\text{shift parameter}', font_size=22)\n beta_label.set_color(RED)\n beta_label.next_to(eq2, DOWN, buff=0.8)\n beta_label.shift(RIGHT * 2)\n self.play(FadeIn(gamma_label), FadeIn(beta_label), run_time=2.0)\n self.wait(0.5)\n self.play(FadeOut(gamma_beta_title), FadeOut(gamma_label), FadeOut(beta_label), FadeOut(eq1), eq2.animate.move_to(UP * 2).scale(0.9))\n base_dist = VGroup()\n for i in range(-4, 5):\n height = math.exp(-i ** 2 / 2) * 1.5\n bar = Rectangle(width=0.3, height=height, fill_color=BLUE, fill_opacity=0.7)\n bar.move_to(DOWN * 0.5 + RIGHT * i * 0.4)\n base_dist.add(bar)\n gamma_val = MathTex('\\\\gamma = 1, \\\\beta = 0', font_size=24)\n gamma_val.set_color(WHITE)\n gamma_val.next_to(base_dist, DOWN, buff=0.5)\n self.play(FadeIn(base_dist), Write(gamma_val), run_time=2.0)\n self.wait(0.3)\n scaled_dist = VGroup()\n for i in range(-6, 7):\n if abs(i) <= 4:\n height = math.exp(-i ** 2 / 2) * 2.5\n bar = Rectangle(width=0.3, height=height, fill_color=GREEN, fill_opacity=0.7)\n bar.move_to(DOWN * 0.5 + RIGHT * i * 0.6)\n scaled_dist.add(bar)\n gamma_val2 = MathTex('\\\\gamma = 2, \\\\beta = 0', font_size=24)\n gamma_val2.set_color(GREEN)\n gamma_val2.next_to(scaled_dist, DOWN, buff=0.5)\n self.play(Transform(base_dist, scaled_dist), Transform(gamma_val, gamma_val2), run_time=2.0)\n self.wait(0.3)\n shifted_dist = VGroup()\n for i in range(-4, 5):\n j = i - 2\n height = math.exp(-i ** 2 / 2) * 2.5\n bar = Rectangle(width=0.3, height=height, fill_color=ORANGE, fill_opacity=0.7)\n bar.move_to(DOWN * 0.5 + RIGHT * j * 0.6)\n shifted_dist.add(bar)\n gamma_val3 = MathTex('\\\\gamma = 2, \\\\beta = \\\\text{shift}', font_size=24)\n gamma_val3.set_color(ORANGE)\n gamma_val3.next_to(shifted_dist, DOWN, buff=0.5)\n self.play(Transform(base_dist, shifted_dist), Transform(gamma_val, gamma_val3), run_time=2.0)\n self.wait(0.5)\n self.play(FadeOut(base_dist), FadeOut(gamma_val))\n complete_title = Text('Complete Batch Normalization', font_size=32, color=YELLOW)\n complete_title.to_edge(UP, buff=0.5)\n complete_eq = MathTex('\\\\hat{x} = \\\\gamma \\\\cdot \\\\frac{x - \\\\mu_B}{\\\\sqrt{\\\\sigma_B^2 + \\\\epsilon}} + \\\\beta')\n complete_eq.set_color(WHITE)\n complete_eq.scale(1.1)\n self.play(Write(complete_title), run_time=2.0 * 0.3)\n self.play(Write(complete_eq), run_time=2.0 * 0.7)\n box = SurroundingRectangle(complete_eq, color=YELLOW, buff=0.3)\n self.play(Create(box), run_time=2.0)\n self.wait(0.5)\n self.play(FadeOut(complete_title), FadeOut(complete_eq), FadeOut(box), FadeOut(eq2))\n takeaway_title = Text('Key Takeaways', font_size=34, color=YELLOW)\n takeaway_title.to_edge(UP, buff=0.5)\n self.play(Write(takeaway_title), run_time=2.0)\n takeaways = VGroup()\n t1 = Text('1. Gamma and Beta are learnable parameters', font_size=22, color=BLUE)\n t1.next_to(takeaway_title, DOWN, buff=0.8)\n self.play(Write(t1), run_time=2.0)\n takeaways.add(t1)\n t2 = Text('2. Gamma controls the scale (variance)', font_size=22, color=GREEN)\n t2.next_to(t1, DOWN, buff=0.5)\n self.play(Write(t2), run_time=2.0)\n takeaways.add(t2)\n t3 = Text('3. Beta controls the shift (mean)', font_size=22, color=ORANGE)\n t3.next_to(t2, DOWN, buff=0.5)\n self.play(Write(t3), run_time=2.0)\n takeaways.add(t3)\n t4 = Text('4. Allow network to learn optimal distributions', font_size=22, color=PURPLE)\n t4.next_to(t3, DOWN, buff=0.5)\n self.play(Write(t4), run_time=2.0)\n takeaways.add(t4)\n final_box = SurroundingRectangle(takeaways, color=YELLOW, buff=0.3)\n self.play(Create(final_box), run_time=2.0)\n self.wait(1)\n thanks = Text('Thanks for watching!', font_size=36, color=BLUE)\n thanks.move_to(ORIGIN)\n self.play(FadeOut(takeaway_title), FadeOut(takeaways), FadeOut(final_box), run_time=0.5)\n self.play(Write(thanks), run_time=2.0 * 0.8)\n self.wait(2.0 * 0.2)\n```", "rejected": "```python\nfrom manim import *\nimport math\n\nclass GammaAndBetaNormalization(Scene):\n\n def construct(self):\n title = Text('Gamma and Beta in Normalization', font_size=42, color=BLUE)\n title\n self.play(Write(title), run_time=2.0)\n subtitle = Text('The Keys to Learnable Normalization', font_size=24, color=GRAY)\n subtitle\n self.play(FadeIn(subtitle), run_time=2.0)\n self.wait(0.5)\n self.play(FadeOut(title), FadeOut(subtitle))\n norm_title = Text('Standard Normalization', font_size=32, color=YELLOW)\n norm_title\n eq1 = MathTex('y = \\\\frac{x - \\\\mu}{\\\\sqrt{\\\\sigma^2 + \\\\epsilon}}')\n eq1.set_color(WHITE)\n eq1.scale(1.2)\n self.play(Write(norm_title), run_time=2.0 * 0.4)\n self.play(Write(eq1), run_time=2.0 * 0.6)\n mean_label = MathTex('\\\\mu: \\\\text{mean}', font_size=20)\n mean_label.set_color(GREEN)\n mean_label.next_to(eq1, DOWN, buff=0.8)\n mean_label.shift(LEFT * 2)\n std_label = MathTex('\\\\sigma: \\\\text{standard deviation}', font_size=20)\n std_label.set_color(ORANGE)\n std_label.next_to(eq1, DOWN, buff=0.8)\n eps_label = MathTex('\\\\epsilon: \\\\text{small constant}', font_size=20)\n eps_label.set_color(PURPLE)\n eps_label.next_to(eq1, DOWN, buff=0.8)\n eps_label.shift(RIGHT * 2.5)\n self.play(FadeIn(mean_label), FadeIn(std_label), FadeIn(eps_label), run_time=2.0)\n self.wait(0.5)\n standard_result = Text('Result: Zero mean, Unit variance', font_size=22, color=LIGHT_GRAY)\n standard_result.next_to(eq1, DOWN, buff=2)\n self.play(Write(standard_result), run_time=2.0)\n self.wait(0.5)\n question = Text('But is this always optimal?', font_size=26, color=RED)\n question.to_edge(DOWN, buff=0.5)\n self.play(Write(question), run_time=2.0)\n self.wait(0.3)\n self.play(FadeOut(question))\n self.play(FadeOut(norm_title), FadeOut(mean_label), FadeOut(std_label), FadeOut(eps_label), FadeOut(standard_result), eq1.animate.to_edge(UP, buff=1.5).scale(0.8))\n gamma_beta_title = Text('Learnable Parameters: Gamma and Beta', font_size=30, color=YELLOW)\n gamma_beta_title.to_edge(UP, buff=0.5)\n eq2 = MathTex('\\\\hat{x} = \\\\gamma \\\\cdot y + \\\\beta')\n eq2.set_color(WHITE)\n eq2.scale(1.2)\n eq2.next_to(eq1, DOWN, buff=0.8)\n self.play(Write(gamma_beta_title), run_time=2.0 * 0.4)\n self.play(Write(eq2), run_time=2.0 * 0.6)\n gamma_label = MathTex('\\\\gamma: \\\\text{scale parameter}', font_size=22)\n gamma_label.set_color(BLUE)\n gamma_label.next_to(eq2, DOWN, buff=0.8)\n gamma_label.shift(LEFT * 2)\n beta_label = MathTex('\\\\beta: \\\\text{shift parameter}', font_size=22)\n beta_label.set_color(RED)\n beta_label.next_to(eq2, DOWN, buff=0.8)\n beta_label.shift(RIGHT * 2)\n self.play(FadeIn(gamma_label), FadeIn(beta_label), run_time=2.0)\n self.wait(0.5)\n self.play(FadeOut(gamma_beta_title), FadeOut(gamma_label), FadeOut(beta_label), FadeOut(eq1), eq2.animate.move_to(UP * 2).scale(0.9))\n base_dist = VGroup()\n for i in range(-4, 5):\n height = math.exp(-i ** 2 / 2) * 1.5\n bar = Rectangle(width=0.3, height=height, fill_color=BLUE, fill_opacity=0.7)\n bar.move_to(DOWN * 0.5 + RIGHT * i * 0.4)\n base_dist.add(bar)\n gamma_val = MathTex('\\\\gamma = 1, \\\\beta = 0', font_size=24)\n gamma_val.set_color(WHITE)\n gamma_val.next_to(base_dist, DOWN, buff=0.5)\n self.play(FadeIn(base_dist), Write(gamma_val), run_time=2.0)\n self.wait(0.3)\n scaled_dist = VGroup()\n for i in range(-6, 7):\n if abs(i) <= 4:\n height = math.exp(-i ** 2 / 2) * 2.5\n bar = Rectangle(width=0.3, height=height, fill_color=GREEN, fill_opacity=0.7)\n bar.move_to(DOWN * 0.5 + RIGHT * i * 0.6)\n scaled_dist.add(bar)\n gamma_val2 = MathTex('\\\\gamma = 2, \\\\beta = 0', font_size=24)\n gamma_val2.set_color(GREEN)\n gamma_val2.next_to(scaled_dist, DOWN, buff=0.5)\n self.play(Transform(base_dist, scaled_dist), Transform(gamma_val, gamma_val2), run_time=2.0)\n self.wait(0.3)\n shifted_dist = VGroup()\n for i in range(-4, 5):\n j = i - 2\n height = math.exp(-i ** 2 / 2) * 2.5\n bar = Rectangle(width=0.3, height=height, fill_color=ORANGE, fill_opacity=0.7)\n bar.move_to(DOWN * 0.5 + RIGHT * j * 0.6)\n shifted_dist.add(bar)\n gamma_val3 = MathTex('\\\\gamma = 2, \\\\beta = \\\\text{shift}', font_size=24)\n gamma_val3.set_color(ORANGE)\n gamma_val3.next_to(shifted_dist, DOWN, buff=0.5)\n self.play(Transform(base_dist, shifted_dist), Transform(gamma_val, gamma_val3), run_time=2.0)\n self.wait(0.5)\n self.play(FadeOut(base_dist), FadeOut(gamma_val))\n complete_title = Text('Complete Batch Normalization', font_size=32, color=YELLOW)\n complete_title.to_edge(UP, buff=0.5)\n complete_eq = MathTex('\\\\hat{x} = \\\\gamma \\\\cdot \\\\frac{x - \\\\mu_B}{\\\\sqrt{\\\\sigma_B^2 + \\\\epsilon}} + \\\\beta')\n complete_eq.set_color(WHITE)\n complete_eq.scale(1.1)\n self.play(Write(complete_title), run_time=2.0 * 0.3)\n self.play(Write(complete_eq), run_time=2.0 * 0.7)\n box = SurroundingRectangle(complete_eq, color=YELLOW, buff=0.3)\n self.play(Create(box), run_time=2.0)\n self.wait(0.5)\n self.play(FadeOut(complete_title), FadeOut(complete_eq), FadeOut(box), FadeOut(eq2))\n takeaway_title = Text('Key Takeaways', font_size=34, color=YELLOW)\n takeaway_title.to_edge(UP, buff=0.5)\n self.play(Write(takeaway_title), run_time=2.0)\n takeaways = VGroup()\n t1 = Text('1. Gamma and Beta are learnable parameters', font_size=22, color=BLUE)\n t1.next_to(takeaway_title, DOWN, buff=0.8)\n self.play(Write(t1), run_time=2.0)\n takeaways.add(t1)\n t2 = Text('2. Gamma controls the scale (variance)', font_size=22, color=GREEN)\n t2.next_to(t1, DOWN, buff=0.5)\n self.play(Write(t2), run_time=2.0)\n takeaways.add(t2)\n t3 = Text('3. Beta controls the shift (mean)', font_size=22, color=ORANGE)\n t3.next_to(t2, DOWN, buff=0.5)\n self.play(Write(t3), run_time=2.0)\n takeaways.add(t3)\n t4 = Text('4. Allow network to learn optimal distributions', font_size=22, color=PURPLE)\n t4.next_to(t3, DOWN, buff=0.5)\n self.play(Write(t4), run_time=2.0)\n takeaways.add(t4)\n final_box = SurroundingRectangle(takeaways, color=YELLOW, buff=0.3)\n self.play(Create(final_box), run_time=2.0)\n self.wait(1)\n thanks = Text('Thanks for watching!', font_size=36, color=BLUE)\n thanks.move_to(ORIGIN)\n self.play(FadeOut(takeaway_title), FadeOut(takeaways), FadeOut(final_box), run_time=0.5)\n self.play(Write(thanks), run_time=2.0 * 0.8)\n self.wait(2.0 * 0.2)\n```", "category": "spatial_layout_overlap", "source": "synthetic_hard_neg:nabin2004/AOS-Manim-SFT"} +{"system": "You are an expert Manim Community Edition (ManimCE v0.19+) Python developer and mathematical animator. Given a user request, first plan the spatial layout, coordinate bounds, timing, and pedagogical flow inside ... tags (when reasoning is helpful), and then output a complete, runnable, self-contained ManimCE Python script using `from manim import *`. Never use deprecated ManimGL (`manimlib`) methods like `ShowCreation`, `TexMobject`, `TextMobject`, or `axes.get_graph`; always use modern ManimCE APIs (`Create`, `MathTex`, `Tex`, `Text`, `axes.plot`) and prevent visual overlap using `.to_edge()`, `.next_to()`, and `FadeOut`.", "prompt": "You are a Manim expert. Please convert the Markdown lecture notes into executable Manim CE v0.19.0 code that displays content in English. The page layout must be clear, with no overlapping elements, and you must not output any explanatory or descriptive text outside the code. Pay special attention to avoiding common errors such as LaTeX syntax issues and index out-of-range errors, and ensure the code can run directly. The Markdown lecture notes are as follows:\n\n### Security Updates and Patch Management\n- The majority of attacks exploit publicly known but unpatched vulnerabilities (N-day vulnerabilities).\n- Establishing an automated patch management process is a fundamental aspect of operational security.\n\n## Summary and Reflections\n\n### Key Points Review\n- Provided an overview of the complete defense system from identity authentication, file permissions (DAC/ACL) to kernel-level protection (ASLR/DEP).\n- Emphasized the importance of threat modeling analysis and the core role of permission control mechanisms in limiting the impact of attacks.\n- Introduced new isolation approaches brought by container and virtualization technologies and their security boundaries.\n\n\nThe context of this section (from highest to current level):\n# Overview of Operating System Security and Permission Control\n## Security Design Principles and Practical Recommendations\n", "chosen": "```python\nfrom manim import *\nfrom manim import config\nText.set_default(font='SimHei')\n\nclass SecurityUpdatesAndSummary(Scene):\n\n def construct(self):\n title = Text('Security Updates and System Defense', font_size=34, color=WHITE, weight=BOLD)\n title.to_edge(UP, buff=0.3)\n title_line = Line(LEFT, RIGHT, color=ORANGE).next_to(title, DOWN, buff=0.1)\n title_line.match_width(title)\n title_group = VGroup(title, title_line)\n self.play(Write(title, run_time=1.5), GrowFromCenter(title_line, run_time=0.8))\n patch_title = Text('1. Patch Management', font_size=28, color=BLUE_C)\n patch_title.next_to(title_line, DOWN, buff=0.4).to_edge(LEFT, buff=0.8)\n p_text1 = Text('- Prevents exploits of known N-day vulnerabilities', font_size=24)\n p_text2 = Text('- Automated patch process is a fundamental security aspect', font_size=24)\n p_group = VGroup(p_text1, p_text2).arrange(DOWN, aligned_edge=LEFT, buff=0.2)\n p_group.next_to(patch_title, DOWN, buff=0.2).align_to(patch_title, LEFT).shift(RIGHT * 0.5)\n self.play(Write(patch_title, run_time=0.8))\n self.play(Write(p_group, run_time=1.5))\n summary_title = Text('2. Complete Defense Architecture', font_size=28, color=BLUE_C)\n summary_title.next_to(p_group, DOWN, buff=0.5).align_to(patch_title, LEFT)\n self.play(Write(summary_title, run_time=0.8))\n layer_texts = ['Identity Authentication', 'File Permissions (DAC / ACL)', 'Kernel Protection (ASLR / DEP)', 'Container and Virtualization Isolation']\n colors = [RED_D, ORANGE, YELLOW_D, GREEN_D]\n layers = VGroup()\n for l_text, col in zip(layer_texts, colors):\n txt = Text(l_text, font_size=22)\n dummy_line = Line(LEFT * 3.5, RIGHT * 3.5).set_opacity(0)\n group = VGroup(txt, dummy_line)\n box = SurroundingRectangle(group, color=col, fill_opacity=0.15, buff=0.15)\n layer = VGroup(box, txt)\n layers.add(layer)\n else:\n pass\n layers.arrange(UP, buff=0.15)\n layers.next_to(summary_title, DOWN, buff=0.2).shift(RIGHT * 1.5)\n for layer in layers:\n self.play(FadeIn(layer, shift=UP * 0.2), run_time=0.6)\n else:\n pass\n side_text = Text('Threat Modeling\\n&\\nPermission Control', font_size=22, color=YELLOW)\n side_text.next_to(layers, RIGHT, buff=0.6)\n arrow = Arrow(start=side_text.get_left(), end=layers.get_right(), color=YELLOW, buff=0.1)\n self.play(Write(side_text, run_time=1.2), Create(arrow, run_time=0.8))\n self.wait(1)\n```", "rejected": "```python\nfrom manim import *\nfrom manim import config\nText.set_default(font='SimHei')\n\nclass SecurityUpdatesAndSummary(Scene):\n\n def construct(self):\n title = Text('Security Updates and System Defense', font_size=34, color=WHITE, weight=BOLD)\n title.to_edge(UP, buff=0.3)\n title_line = Line(LEFT, RIGHT, color=ORANGE).next_to(title, DOWN, buff=0.1)\n title_line.match_width(title)\n title_group = VGroup(title, title_line)\n self.play(Write(title, run_time=1.5), GrowFromCenter(title_line, run_time=0.8))\n patch_title = Text('1. Patch Management', font_size=28, color=BLUE_C)\n patch_title.next_to(title_line, DOWN, buff=0.4).to_edge(LEFT, buff=0.8)\n p_text1 = Text('- Prevents exploits of known N-day vulnerabilities', font_size=24)\n p_text2 = Text('- Automated patch process is a fundamental security aspect', font_size=24)\n p_group = VGroup(p_text1, p_text2).arrange(DOWN, aligned_edge=LEFT, buff=0.2)\n p_group.next_to(patch_title, DOWN, buff=0.2).align_to(patch_title, LEFT).shift(RIGHT * 0.5)\n self.play(Write(patch_title, run_time=0.8))\n self.play(Write(p_group, run_time=1.5))\n summary_title = Text('2. Complete Defense Architecture', font_size=28, color=BLUE_C)\n summary_title.next_to(p_group, DOWN, buff=0.5).align_to(patch_title, LEFT)\n self.play(Write(summary_title, run_time=0.8))\n layer_texts = ['Identity Authentication', 'File Permissions (DAC / ACL)', 'Kernel Protection (ASLR / DEP)', 'Container and Virtualization Isolation']\n colors = [RED_D, ORANGE, YELLOW_D, GREEN_D]\n layers = VGroup()\n for l_text, col in zip(layer_texts, colors):\n txt = Text(l_text, font_size=22)\n dummy_line = Line(LEFT * 3.5, RIGHT * 3.5).set_opacity(0)\n group = VGroup(txt, dummy_line)\n box = SurroundingRectangle(group, color=col, fill_opacity=0.15, buff=0.15)\n layer = VGroup(box, txt)\n layers.add(layer)\n else:\n pass\n layers.arrange(UP, buff=0.15)\n layers.next_to(summary_title, DOWN, buff=0.2).shift(RIGHT * 1.5)\n for layer in layers:\n self.play(FadeIn(layer, shift=UP * 0.2), run_time=0.6)\n else:\n pass\n side_text = Text('Threat Modeling\\n&\\nPermission Control', font_size=22, color=YELLOW)\n side_text.next_to(layers, RIGHT, buff=0.6)\n arrow = Arrow(start=side_text.get_left(), end=layers.get_right(), color=YELLOW, buff=0.1)\n self.play(Write(side_text, run_time=1.2), ShowCreation(arrow, run_time=0.8))\n self.wait(1)\n```", "category": "legacy_api_hallucination", "source": "synthetic_hard_neg:nabin2004/manim-sft-10k"} +{"system": "You are an expert Manim Community Edition (ManimCE v0.19+) Python developer and mathematical animator. Given a user request, first plan the spatial layout, coordinate bounds, timing, and pedagogical flow inside ... tags (when reasoning is helpful), and then output a complete, runnable, self-contained ManimCE Python script using `from manim import *`. Never use deprecated ManimGL (`manimlib`) methods like `ShowCreation`, `TexMobject`, `TextMobject`, or `axes.get_graph`; always use modern ManimCE APIs (`Create`, `MathTex`, `Tex`, `Text`, `axes.plot`) and prevent visual overlap using `.to_edge()`, `.next_to()`, and `FadeOut`.", "prompt": "You are a Manim expert. Please convert the Markdown lecture notes into executable Manim CE v0.19.0 code that displays content in English. The page layout must be clear, with no overlapping elements, and you must not output any explanatory or descriptive text outside the code. Pay special attention to avoiding common errors such as LaTeX syntax issues and index out-of-range errors, and ensure the code can run directly. The Markdown lecture notes are as follows:\n\n### Toffoli Gate Decomposition\nRefer to the literature and try to illustrate how to combine H, T, and CNOT gates to form a Toffoli gate (or specify the required resource level).\n* Background: The Toffoli gate is a non-Clifford gate, and its decomposition requires T gate resources.\n\n### Complexity Analysis\nIf it is proven that $P = NP$, what impact would this have on the future of quantum computing (BQP vs P)? Would quantum computers still be valuable?\n* Deep Thought: Even if $P = NP$, does Grover's search provide a polynomial speedup that is still meaningful under physical limits?\n\n\nThe context of this section (from highest to current level):\n# Fundamentals of Quantum Mechanics (II) and Computer Science\n## Comprehensive Exercises and Deep Thinking (II)\n", "chosen": "```python\nfrom manim import *\nfrom manim import config\nText.set_default(font='SimHei')\n\nclass QuantumLectureNotes(Scene):\n\n def construct(self):\n title = Tex('\\\\textbf{Fundamentals of Quantum Mechanics (II) and Computer Science}')\n title.scale(0.85).to_edge(UP, buff=0.4)\n subtitle = Tex('Comprehensive Exercises and Deep Thinking (II)')\n subtitle.scale(0.7).next_to(title, DOWN, buff=0.2)\n subtitle.set_color(LIGHT_GREY)\n s1_title = Tex('\\\\textbf{Toffoli Gate Decomposition}')\n s1_title.scale(0.75).set_color(BLUE_C)\n s1_text = Tex('Refer to the literature and try to illustrate how to combine $H$, $T$, and CNOT gates\\\\\\\\', 'to form a Toffoli gate (or specify the required resource level).')\n s1_text.scale(0.6)\n s1_bullet = Tex('$\\\\bullet$ \\\\textbf{Background:} The Toffoli gate is a non-Clifford gate,\\\\\\\\', 'and its decomposition requires $T$ gate resources.')\n s1_bullet.scale(0.6).set_color(YELLOW_C)\n s1_group = VGroup(s1_title, s1_text, s1_bullet)\n s1_group.arrange(DOWN, aligned_edge=LEFT, buff=0.25)\n s2_title = Tex('\\\\textbf{Complexity Analysis}')\n s2_title.scale(0.75).set_color(BLUE_C)\n s2_text = Tex('If it is proven that $P = NP$, what impact would this have on the future of\\\\\\\\', 'quantum computing (BQP vs P)? Would quantum computers still be valuable?')\n s2_text.scale(0.6)\n s2_bullet = Tex(\"$\\\\bullet$ \\\\textbf{Deep Thought:} Even if $P = NP$, does Grover's search provide a\\\\\\\\\", 'polynomial speedup that is still meaningful under physical limits?')\n s2_bullet.scale(0.6).set_color(YELLOW_C)\n s2_group = VGroup(s2_title, s2_text, s2_bullet)\n s2_group.arrange(DOWN, aligned_edge=LEFT, buff=0.25)\n content_group = VGroup(s1_group, s2_group)\n content_group.arrange(DOWN, aligned_edge=LEFT, buff=0.6)\n content_group.next_to(subtitle, DOWN, buff=0.5).to_edge(LEFT, buff=1.0)\n self.play(Write(title))\n self.play(FadeIn(subtitle, shift=UP * 0.2))\n self.wait(0.5)\n self.play(Write(s1_title))\n self.play(FadeIn(s1_text, shift=RIGHT * 0.2))\n self.play(FadeIn(s1_bullet, shift=RIGHT * 0.2))\n self.wait(1)\n self.play(Write(s2_title))\n self.play(FadeIn(s2_text, shift=RIGHT * 0.2))\n self.play(FadeIn(s2_bullet, shift=RIGHT * 0.2))\n self.wait(2)\n```", "rejected": "```python\nfrom manim import *\nfrom manim import config\nText.set_default(font='SimHei')\n\nclass QuantumLectureNotes(Scene):\n\n def construct(self):\n title = Tex('\\\\textbf{Fundamentals of Quantum Mechanics (II) and Computer Science}')\n title.scale(0.85)\n subtitle = Tex('Comprehensive Exercises and Deep Thinking (II)')\n subtitle.scale(0.7)\n subtitle.set_color(LIGHT_GREY)\n s1_title = Tex('\\\\textbf{Toffoli Gate Decomposition}')\n s1_title.scale(0.75).set_color(BLUE_C)\n s1_text = Tex('Refer to the literature and try to illustrate how to combine $H$, $T$, and CNOT gates\\\\\\\\', 'to form a Toffoli gate (or specify the required resource level).')\n s1_text.scale(0.6)\n s1_bullet = Tex('$\\\\bullet$ \\\\textbf{Background:} The Toffoli gate is a non-Clifford gate,\\\\\\\\', 'and its decomposition requires $T$ gate resources.')\n s1_bullet.scale(0.6).set_color(YELLOW_C)\n s1_group = VGroup(s1_title, s1_text, s1_bullet)\n s1_group.arrange(DOWN, aligned_edge=LEFT, buff=0.25)\n s2_title = Tex('\\\\textbf{Complexity Analysis}')\n s2_title.scale(0.75).set_color(BLUE_C)\n s2_text = Tex('If it is proven that $P = NP$, what impact would this have on the future of\\\\\\\\', 'quantum computing (BQP vs P)? Would quantum computers still be valuable?')\n s2_text.scale(0.6)\n s2_bullet = Tex(\"$\\\\bullet$ \\\\textbf{Deep Thought:} Even if $P = NP$, does Grover's search provide a\\\\\\\\\", 'polynomial speedup that is still meaningful under physical limits?')\n s2_bullet.scale(0.6).set_color(YELLOW_C)\n s2_group = VGroup(s2_title, s2_text, s2_bullet)\n s2_group.arrange(DOWN, aligned_edge=LEFT, buff=0.25)\n content_group = VGroup(s1_group, s2_group)\n content_group.arrange(DOWN, aligned_edge=LEFT, buff=0.6)\n content_group.to_edge(LEFT, buff=1.0)\n self.play(Write(title))\n self.play(FadeIn(subtitle, shift=UP * 0.2))\n self.wait(0.5)\n self.play(Write(s1_title))\n self.play(FadeIn(s1_text, shift=RIGHT * 0.2))\n self.play(FadeIn(s1_bullet, shift=RIGHT * 0.2))\n self.wait(1)\n self.play(Write(s2_title))\n self.play(FadeIn(s2_text, shift=RIGHT * 0.2))\n self.play(FadeIn(s2_bullet, shift=RIGHT * 0.2))\n self.wait(2)\n```", "category": "spatial_layout_overlap", "source": "synthetic_hard_neg:nabin2004/manim-sft-10k"} +{"system": "You are an expert Manim Community Edition (ManimCE v0.19+) Python developer and mathematical animator. Given a user request, first plan the spatial layout, coordinate bounds, timing, and pedagogical flow inside ... tags (when reasoning is helpful), and then output a complete, runnable, self-contained ManimCE Python script using `from manim import *`. Never use deprecated ManimGL (`manimlib`) methods like `ShowCreation`, `TexMobject`, `TextMobject`, or `axes.get_graph`; always use modern ManimCE APIs (`Create`, `MathTex`, `Tex`, `Text`, `axes.plot`) and prevent visual overlap using `.to_edge()`, `.next_to()`, and `FadeOut`.", "prompt": "I'm teaching an NLP course and want to illustrate a causal mask matrix used in Transformers. Visualize a square attention mask where the upper triangle is filled with -inf and the lower triangle with 0. Animate the mask being applied to an attention score matrix, show how logits are masked, and highlight the effect on subsequent token predictions. Include a transition that sweeps from no mask to full causal mask, with labeled diagonals and a color legend.", "chosen": "```python\nfrom manim import *\nfrom manim_voiceover import VoiceoverScene\nfrom manim_voiceover.services.gtts import GTTSService\n\nclass CausalMaskScene(VoiceoverScene):\n def construct(self):\n self.set_speech_service(\n GTTSService(voice=\"alba\", cache_dir=\"voiceover_cache\")\n )\n\n # ------------------------------------------------------------------\n # 1. Title & Opener\n # ------------------------------------------------------------------\n title = Text(\"Causal Mask Matrix in Transformers\", font_size=38)\n title.to_edge(UP, buff=0.4)\n\n with self.voiceover(\n text=\"Imagine a world where sequences of information flow in a way that respects order. \"\n \"In transformers, the causal mask matrix ensures the model processes data sequentially, \"\n \"treating future information as unavailable. Let's uncover how it works.\"\n ) as tracker:\n self.play(Write(title), run_time=tracker.duration)\n\n # ------------------------------------------------------------------\n # 2. Tokens\n # ------------------------------------------------------------------\n words = [\"The\", \"cat\", \"sat\", \"down\"]\n tokens = VGroup(*[Text(f'\"{w}\"', font_size=26) for w in words])\n tokens.arrange(RIGHT, buff=0.6)\n tokens.next_to(title, DOWN, buff=0.4)\n\n with self.voiceover(\n text=\"Consider a simple sentence broken into four tokens.\"\n ) as tracker:\n self.play(FadeIn(tokens), run_time=tracker.duration)\n\n # ------------------------------------------------------------------\n # 3. Raw attention scores matrix\n # ------------------------------------------------------------------\n score_entries = [\n [\"2.0\", \"1.0\", \"0.5\", \"1.2\"],\n [\"0.8\", \"3.0\", \"1.5\", \"0.2\"],\n [\"1.1\", \"0.3\", \"2.5\", \"1.8\"],\n [\"0.2\", \"1.0\", \"0.4\", \"3.2\"],\n ]\n score_matrix = Matrix(\n score_entries,\n element_to_mobject_config={\"font_size\": 26},\n h_buff=1.0,\n v_buff=0.6,\n ).scale(0.75)\n\n label_scores = MathTex(r\"\\text{Scores} = QK^T\", font_size=30)\n group_scores = VGroup(label_scores, score_matrix).arrange(DOWN, buff=0.25)\n group_scores.next_to(tokens, DOWN, buff=0.3)\n\n with self.voiceover(\n text=\"Before computing attention, we calculate raw scores between every query and key. \"\n \"Right now, every token can look at every other token, including future ones.\"\n ) as tracker:\n self.play(Create(score_matrix), Write(label_scores), run_time=tracker.duration)\n\n # ------------------------------------------------------------------\n # 4. Causal mask matrix\n # ------------------------------------------------------------------\n mask_entries = [\n [\"1\", \"0\", \"0\", \"0\"],\n [\"1\", \"1\", \"0\", \"0\"],\n [\"1\", \"1\", \"1\", \"0\"],\n [\"1\", \"1\", \"1\", \"1\"],\n ]\n mask_matrix = Matrix(\n mask_entries,\n element_to_mobject_config={\"font_size\": 26},\n h_buff=1.0,\n v_buff=0.6,\n ).scale(0.75)\n\n label_mask = MathTex(r\"\\text{Causal Mask}\", font_size=30)\n group_mask = VGroup(label_mask, mask_matrix).arrange(DOWN, buff=0.25)\n group_mask.next_to(group_scores, RIGHT, buff=0.9)\n\n with self.voiceover(\n text=\"To preserve order, we introduce a causal mask. \"\n \"It is a lower-triangular matrix: ones on and below the diagonal, zeros above.\"\n ) as tracker:\n self.play(Create(mask_matrix), Write(label_mask), run_time=tracker.duration)\n\n # Arrow + operation text between the two matrices\n arrow = Arrow(\n group_scores.get_right(),\n group_mask.get_left(),\n buff=0.1,\n stroke_width=2,\n tip_length=0.2,\n )\n op_text = MathTex(r\"\\times\", font_size=34)\n op_text.move_to(arrow.get_center())\n\n with self.voiceover(\n text=\"We apply the mask element-wise. Watch what happens to the scores.\"\n ) as tracker:\n self.play(GrowArrow(arrow), Write(op_text), run_time=tracker.duration)\n\n # ------------------------------------------------------------------\n # 5. Masked scores (future -> -inf)\n # ------------------------------------------------------------------\n masked_entries = [\n [\"2.0\", r\"-\\infty\", r\"-\\infty\", r\"-\\infty\"],\n [\"0.8\", \"3.0\", r\"-\\infty\", r\"-\\infty\"],\n [\"1.1\", \"0.3\", \"2.5\", r\"-\\infty\"],\n [\"0.2\", \"1.0\", \"0.4\", \"3.2\"],\n ]\n masked_matrix = Matrix(\n masked_entries,\n element_to_mobject_config={\"font_size\": 26},\n h_buff=1.0,\n v_buff=0.6,\n ).scale(0.75)\n\n label_masked = MathTex(r\"\\text{Masked Scores}\", font_size=30)\n group_masked = VGroup(label_masked, masked_matrix).arrange(DOWN, buff=0.25)\n group_masked.move_to(group_scores.get_center())\n\n with self.voiceover(\n text=\"Every future position is replaced by negative infinity. \"\n \"This prevents any information leakage from later tokens into the current prediction.\"\n ) as tracker:\n self.play(\n ReplacementTransform(score_matrix, masked_matrix),\n Transform(label_scores, label_masked),\n FadeOut(group_mask, arrow, op_text),\n run_time=tracker.duration,\n )\n\n # ------------------------------------------------------------------\n # 6. Softmax formula\n # ------------------------------------------------------------------\n softmax_formula = MathTex(\n r\"\\text{Softmax}(x_i) = \\frac{e^{x_i}}{\\sum_j e^{x_j}}\",\n font_size=32,\n )\n softmax_formula.next_to(group_masked, RIGHT, buff=0.7)\n\n with self.voiceover(\n text=\"Next comes the softmax function. \"\n \"Because the exponential of negative infinity is zero, \"\n \"all forbidden positions receive exactly zero probability mass.\"\n ) as tracker:\n self.play(Write(softmax_formula), run_time=tracker.duration)\n\n # ------------------------------------------------------------------\n # 7. Final attention weights\n # ------------------------------------------------------------------\n weight_entries = [\n [\"1.00\", \"0\", \"0\", \"0\"],\n [\"0.10\", \"0.90\", \"0\", \"0\"],\n [\"0.20\", \"0.05\", \"0.75\", \"0\"],\n [\"0.06\", \"0.08\", \"0.05\", \"0.81\"],\n ]\n weight_matrix = Matrix(\n weight_entries,\n element_to_mobject_config={\"font_size\": 26},\n h_buff=1.0,\n v_buff=0.6,\n ).scale(0.75)\n\n label_weight = MathTex(r\"\\text{Attention Weights}\", font_size=30)\n group_weight = VGroup(label_weight, weight_matrix).arrange(DOWN, buff=0.25)\n group_weight.move_to(group_masked.get_center())\n\n with self.voiceover(\n text=\"The final attention weights form a clean lower-triangular pattern. \"\n \"Each row sums to one, and every future token contributes nothing.\"\n ) as tracker:\n self.play(\n ReplacementTransform(masked_matrix, weight_matrix),\n Transform(label_masked, label_weight),\n FadeOut(softmax_formula),\n run_time=tracker.duration,\n )\n\n # ------------------------------------------------------------------\n # 8. Summary takeaways\n # ------------------------------------------------------------------\n summary_title = Text(\"Key Takeaways\", font_size=28, color=YELLOW)\n summary_title.next_to(group_weight, DOWN, buff=0.4)\n\n pt1 = MathTex(r\"\\bullet\\ \\text{Causal mask: lower-triangular matrix}\", font_size=24)\n pt2 = MathTex(r\"\\bullet\\ \\text{Blocks future-token leakage}\", font_size=24)\n pt3 = MathTex(r\"\\bullet\\ \\text{Vital for autoregressive models like GPT}\", font_size=24)\n\n summary_pts = VGroup(pt1, pt2, pt3).arrange(DOWN, aligned_edge=LEFT, buff=0.25)\n summary_pts.next_to(summary_title, DOWN, buff=0.25)\n\n with self.voiceover(\n text=\"To recap: the causal mask is a lower-triangular matrix. \"\n \"It stops the model from peeking ahead, making it essential for autoregressive transformers.\"\n ) as tracker:\n self.play(Write(summary_title), run_time=0.5)\n self.play(\n LaggedStart(*[Write(p) for p in [pt1, pt2, pt3]], lag_ratio=0.3),\n run_time=tracker.duration - 0.5,\n )\n\n self.wait(1)\n```", "rejected": "```python\nfrom manim import *\n\nclass CausalMaskScene(Scene):\n\n def construct(self):\n title = Text('Causal Mask Matrix in Transformers', font_size=38)\n title.to_edge(UP, buff=0.4)\n self.play(Write(title), run_time=2.0)\n words = ['The', 'cat', 'sat', 'down']\n tokens = VGroup(*[Text(f'\"{w}\"', font_size=26) for w in words])\n tokens.arrange(RIGHT, buff=0.6)\n tokens.next_to(title, DOWN, buff=0.4)\n self.play(FadeIn(tokens), run_time=2.0)\n score_entries = [['2.0', '1.0', '0.5', '1.2'], ['0.8', '3.0', '1.5', '0.2'], ['1.1', '0.3', '2.5', '1.8'], ['0.2', '1.0', '0.4', '3.2']]\n score_matrix = Matrix(score_entries, element_to_mobject_config={'font_size': 26}, h_buff=1.0, v_buff=0.6).scale(0.75)\n label_scores = MathTex('\\\\text{Scores} = QK^T', font_size=30)\n group_scores = VGroup(label_scores, score_matrix).arrange(DOWN, buff=0.25)\n group_scores.next_to(tokens, DOWN, buff=0.3)\n self.play(Create(score_matrix), Write(label_scores), run_time=2.0)\n mask_entries = [['1', '0', '0', '0'], ['1', '1', '0', '0'], ['1', '1', '1', '0'], ['1', '1', '1', '1']]\n mask_matrix = Matrix(mask_entries, element_to_mobject_config={'font_size': 26}, h_buff=1.0, v_buff=0.6).scale(0.75)\n label_mask = MathTex('\\\\text{Causal Mask}', font_size=30)\n group_mask = VGroup(label_mask, mask_matrix).arrange(DOWN, buff=0.25)\n group_mask.next_to(group_scores, RIGHT, buff=0.9)\n self.play(Create(mask_matrix), Write(label_mask), run_time=2.0)\n arrow = Arrow(group_scores.get_right(), group_mask.get_left(), buff=0.1, stroke_width=2, tip_length=0.2)\n op_text = MathTex('\\\\times', font_size=34)\n op_text.move_to(arrow.get_center())\n self.play(GrowArrow(arrow), Write(op_text), run_time=2.0)\n masked_entries = [['2.0', '-\\\\infty', '-\\\\infty', '-\\\\infty'], ['0.8', '3.0', '-\\\\infty', '-\\\\infty'], ['1.1', '0.3', '2.5', '-\\\\infty'], ['0.2', '1.0', '0.4', '3.2']]\n masked_matrix = Matrix(masked_entries, element_to_mobject_config={'font_size': 26}, h_buff=1.0, v_buff=0.6).scale(0.75)\n label_masked = MathTex('\\\\text{Masked Scores}', font_size=30)\n group_masked = VGroup(label_masked, masked_matrix).arrange(DOWN, buff=0.25)\n group_masked.move_to(group_scores.get_center())\n self.play(ReplacementTransform(score_matrix, masked_matrix), Transform(label_scores, label_masked), FadeOut(group_mask, arrow, op_text), run_time=2.0)\n softmax_formula = MathTex('\\\\text{Softmax}(x_i) = \\\\frac{e^{x_i}}{\\\\sum_j e^{x_j}}', font_size=32)\n softmax_formula.next_to(group_masked, RIGHT, buff=0.7)\n self.play(Write(softmax_formula), run_time=2.0)\n weight_entries = [['1.00', '0', '0', '0'], ['0.10', '0.90', '0', '0'], ['0.20', '0.05', '0.75', '0'], ['0.06', '0.08', '0.05', '0.81']]\n weight_matrix = Matrix(weight_entries, element_to_mobject_config={'font_size': 26}, h_buff=1.0, v_buff=0.6).scale(0.75)\n label_weight = MathTex('\\\\text{Attention Weights}', font_size=30)\n group_weight = VGroup(label_weight, weight_matrix).arrange(DOWN, buff=0.25)\n group_weight.move_to(group_masked.get_center())\n self.play(ReplacementTransform(masked_matrix, weight_matrix), Transform(label_masked, label_weight), FadeOut(softmax_formula), run_time=2.0)\n summary_title = Text('Key Takeaways', font_size=28, color=YELLOW)\n summary_title.next_to(group_weight, DOWN, buff=0.4)\n pt1 = MathTex('\\\\bullet\\\\ \\\\text{Causal mask: lower-triangular matrix}', font_size=24)\n pt2 = MathTex('\\\\bullet\\\\ \\\\text{Blocks future-token leakage}', font_size=24)\n pt3 = MathTex('\\\\bullet\\\\ \\\\text{Vital for autoregressive models like GPT}', font_size=24)\n summary_pts = VGroup(pt1, pt2, pt3).arrange(DOWN, aligned_edge=LEFT, buff=0.25)\n summary_pts.next_to(summary_title, DOWN, buff=0.25)\n self.play(Write(summary_title), run_time=0.5)\n self.play(LaggedStart(*[Write(p) for p in [pt1, pt2, pt3]], lag_ratio=0.3), run_time=2.0 - 0.5)\n self.wait(1)\n```", "category": "narrated_pedagogical_preference", "source": "nabin2004/manim-narrated-dpo-400"} +{"system": "You are an expert Manim Community Edition (ManimCE v0.19+) Python developer and mathematical animator. Given a user request, first plan the spatial layout, coordinate bounds, timing, and pedagogical flow inside ... tags (when reasoning is helpful), and then output a complete, runnable, self-contained ManimCE Python script using `from manim import *`. Never use deprecated ManimGL (`manimlib`) methods like `ShowCreation`, `TexMobject`, `TextMobject`, or `axes.get_graph`; always use modern ManimCE APIs (`Create`, `MathTex`, `Tex`, `Text`, `axes.plot`) and prevent visual overlap using `.to_edge()`, `.next_to()`, and `FadeOut`.", "prompt": "In a two-dimensional system, how do limit cycles surrounding a fixed point in the phase plane relate to the stability of that fixed point?", "chosen": "```python\nfrom manim import *\n\nclass LimitCyclesStability(Scene):\n def construct(self):\n # Title\n title = Text(\"Embracing Stability:\", font_size=40)\n subtitle = Text(\"The Dance of Limit Cycles and Fixed Points\", font_size=30)\n subtitle.next_to(title, DOWN)\n \n self.play(Write(title))\n self.play(Write(subtitle))\n self.wait(1)\n self.play(FadeOut(title), FadeOut(subtitle))\n \n # Create a phase plane\n axes = Axes(\n x_range=[-3, 3, 1],\n y_range=[-3, 3, 1],\n )\n self.play(Create(axes))\n \n # Create a fixed point\n fixed_point = Dot(axes.c2p(0, 0), color=RED)\n fixed_point_label = Text(\"Fixed Point\", font_size=24).next_to(fixed_point, UP)\n self.play(Create(fixed_point), Write(fixed_point_label))\n \n # Show system equations\n equation = MathTex(r\"\\dot{x} = f(x, y)\", r\"\\\\\\dot{y} = g(x, y)\")\n equation.to_corner(UL)\n self.play(Write(equation))\n \n # Create a limit cycle\n limit_cycle = Circle(radius=2, color=BLUE).move_to(axes.c2p(0, 0))\n limit_cycle_label = Text(\"Limit Cycle\", font_size=24).next_to(limit_cycle, RIGHT)\n self.play(Create(limit_cycle), Write(limit_cycle_label))\n \n # Show limit cycle equation\n limit_cycle_eq = MathTex(r\"\\text{Limit cycles: }\\frac{d\\theta}{dt} = \\omega\")\n limit_cycle_eq.next_to(equation, DOWN, aligned_edge=LEFT)\n self.play(Write(limit_cycle_eq))\n \n # Show arrows on the limit cycle\n cycle_arrows = VGroup()\n for angle in np.linspace(0, 2*PI, 8, endpoint=False):\n point = axes.c2p(2*np.cos(angle), 2*np.sin(angle))\n direction = np.array([-np.sin(angle), np.cos(angle), 0])\n arrow = Arrow(point, point + 0.5*direction, color=BLUE, buff=0)\n cycle_arrows.add(arrow)\n self.play(Create(cycle_arrows))\n \n # Show outward arrows from fixed point (indicating instability)\n outward_arrows = VGroup()\n for angle in np.linspace(0, 2*PI, 8, endpoint=False):\n start = axes.c2p(0.5*np.cos(angle), 0.5*np.sin(angle))\n end = axes.c2p(1.0*np.cos(angle), 1.0*np.sin(angle))\n arrow = Arrow(start, end, color=RED, buff=0)\n outward_arrows.add(arrow)\n self.play(Create(outward_arrows))\n \n # Add a stability label\n stability_label = Text(\"Unstable Fixed Point\", font_size=24, color=RED)\n stability_label.to_edge(UP)\n self.play(Write(stability_label))\n \n # Add a key insight text\n insight = Text(\"Limit cycles indicate stability properties\", font_size=20)\n insight.to_edge(DOWN)\n self.play(Write(insight))\n \n # Conclusion\n conclusion = Text(\"Limit cycles form boundaries in phase space\", font_size=30)\n self.play(\n FadeOut(axes), FadeOut(fixed_point), FadeOut(fixed_point_label),\n FadeOut(limit_cycle), FadeOut(limit_cycle_label), FadeOut(cycle_arrows),\n FadeOut(outward_arrows), FadeOut(stability_label), FadeOut(insight),\n FadeOut(equation), FadeOut(limit_cycle_eq)\n )\n self.play(Write(conclusion))\n self.wait(2)\n```", "rejected": "```python\nfrom manim import *\n\nclass LimitCyclesStability(Scene):\n def construct(self):\n # Title\n title = Text(\"Embracing Stability:\", font_size=40)\n subtitle = Text(\"The Dance of Limit Cycles and Fixed Points\", font_size=30)\n subtitle\n \n self.play(Write(title))\n self.play(Write(subtitle))\n self.wait(1)\n self.play(FadeOut(title), FadeOut(subtitle))\n \n # Create a phase plane\n axes = Axes(\n x_range=[-3, 3, 1],\n y_range=[-3, 3, 1],\n )\n self.play(Create(axes))\n \n # Create a fixed point\n fixed_point = Dot(axes.c2p(0, 0), color=RED)\n fixed_point_label = Text(\"Fixed Point\", font_size=24)\n self.play(Create(fixed_point), Write(fixed_point_label))\n \n # Show system equations\n equation = MathTex(r\"\\dot{x} = f(x, y)\", r\"\\\\\\dot{y} = g(x, y)\")\n equation\n self.play(Write(equation))\n \n # Create a limit cycle\n limit_cycle = Circle(radius=2, color=BLUE).move_to(axes.c2p(0, 0))\n limit_cycle_label = Text(\"Limit Cycle\", font_size=24).next_to(limit_cycle, RIGHT)\n self.play(Create(limit_cycle), Write(limit_cycle_label))\n \n # Show limit cycle equation\n limit_cycle_eq = MathTex(r\"\\text{Limit cycles: }\\frac{d\\theta}{dt} = \\omega\")\n limit_cycle_eq.next_to(equation, DOWN, aligned_edge=LEFT)\n self.play(Write(limit_cycle_eq))\n \n # Show arrows on the limit cycle\n cycle_arrows = VGroup()\n for angle in np.linspace(0, 2*PI, 8, endpoint=False):\n point = axes.c2p(2*np.cos(angle), 2*np.sin(angle))\n direction = np.array([-np.sin(angle), np.cos(angle), 0])\n arrow = Arrow(point, point + 0.5*direction, color=BLUE, buff=0)\n cycle_arrows.add(arrow)\n self.play(Create(cycle_arrows))\n \n # Show outward arrows from fixed point (indicating instability)\n outward_arrows = VGroup()\n for angle in np.linspace(0, 2*PI, 8, endpoint=False):\n start = axes.c2p(0.5*np.cos(angle), 0.5*np.sin(angle))\n end = axes.c2p(1.0*np.cos(angle), 1.0*np.sin(angle))\n arrow = Arrow(start, end, color=RED, buff=0)\n outward_arrows.add(arrow)\n self.play(Create(outward_arrows))\n \n # Add a stability label\n stability_label = Text(\"Unstable Fixed Point\", font_size=24, color=RED)\n stability_label.to_edge(UP)\n self.play(Write(stability_label))\n \n # Add a key insight text\n insight = Text(\"Limit cycles indicate stability properties\", font_size=20)\n insight.to_edge(DOWN)\n self.play(Write(insight))\n \n # Conclusion\n conclusion = Text(\"Limit cycles form boundaries in phase space\", font_size=30)\n self.play(\n FadeOut(axes), FadeOut(fixed_point), FadeOut(fixed_point_label),\n FadeOut(limit_cycle), FadeOut(limit_cycle_label), FadeOut(cycle_arrows),\n FadeOut(outward_arrows), FadeOut(stability_label), FadeOut(insight),\n FadeOut(equation), FadeOut(limit_cycle_eq)\n )\n self.play(Write(conclusion))\n self.wait(2)\n```", "category": "spatial_layout_overlap", "source": "synthetic_hard_neg:nabin2004/manim-sft-10k"} +{"system": "You are an expert Manim Community Edition (ManimCE v0.19+) Python developer and mathematical animator. Given a user request, first plan the spatial layout, coordinate bounds, timing, and pedagogical flow inside ... tags (when reasoning is helpful), and then output a complete, runnable, self-contained ManimCE Python script using `from manim import *`. Never use deprecated ManimGL (`manimlib`) methods like `ShowCreation`, `TexMobject`, `TextMobject`, or `axes.get_graph`; always use modern ManimCE APIs (`Create`, `MathTex`, `Tex`, `Text`, `axes.plot`) and prevent visual overlap using `.to_edge()`, `.next_to()`, and `FadeOut`.", "prompt": "Construct a clean Manim CE scene initializing BarChart with verified keyword arguments. Ensure no deprecated ManimGL arguments (like element_color, max_value, or max_magnitude) are used.\n\n```python\nfrom manim import *\nimport numpy as np\n\nclass ApiValidBarChart66(Scene):\n def construct(self):\n obj = BarChart(values=[2, 4, 3, 5], bar_names=['A', 'B', 'C', 'D'], y_range=[0, 6, 2], y_length=4, x_length=6)\n obj.set_color(YELLOW)\n self.play(Create(obj))\n self.wait(1)\n```", "chosen": "```python\nfrom manim import *\nfrom manim_voiceover import VoiceoverScene\nfrom manim_voiceover.services.gtts import GTTSService\nimport numpy as np\n\nMARGIN = 0.5\n\nclass ApiValidBarChart66(VoiceoverScene):\n def fit_in_frame(self, mob: Mobject, w_frac=0.9, h_frac=0.9) -> Mobject:\n max_w = config.frame_width * w_frac\n max_h = config.frame_height * h_frac\n if mob.width > max_w:\n mob.width = max_w\n if mob.height > max_h:\n mob.height = max_h\n return mob\n\n def construct(self):\n self.set_speech_service(GTTSService(transcription_model=\"base\"))\n \n # [SETUP]\n # [LAYOUT]\n obj = BarChart(values=[2, 4, 3, 5], bar_names=['A', 'B', 'C', 'D'], y_range=[0, 6, 2], y_length=4, x_length=6)\n obj.set_color(YELLOW)\n obj = self.fit_in_frame(obj)\n self.add(obj)\n \n # [UPDATER]\n # [BEAT 1 | sync: b1]\n with self.voiceover(text=\"We initialize a bar chart displaying four categories. \") as t:\n self.wait_until_bookmark(\"b1\")\n self.play(Create(obj))\n \n # [BEAT 2 | sync: b2]\n with self.voiceover(text=\"Notice the clean setup without deprecated arguments. \") as t:\n self.wait_until_bookmark(\"b2\")\n self.wait(1)\n```", "rejected": "```python\nfrom manim import *\nfrom manim_voiceover import VoiceoverScene\nfrom manim_voiceover.services.gtts import GTTSService\nimport numpy as np\n\nMARGIN = 0.5\n\nclass ApiValidBarChart66(VoiceoverScene):\n def fit_in_frame(self, mob: Mobject, w_frac=0.9, h_frac=0.9) -> Mobject:\n max_w = config.frame_width * w_frac\n max_h = config.frame_height * h_frac\n if mob.width > max_w:\n mob.width = max_w\n if mob.height > max_h:\n mob.height = max_h\n return mob\n\n def construct(self):\n self.set_speech_service(GTTSService(transcription_model=\"base\"))\n \n # [SETUP]\n # [LAYOUT]\n obj = BarChart(values=[2, 4, 3, 5], bar_names=['A', 'B', 'C', 'D'], y_range=[0, 6, 2], y_length=4, x_length=6)\n obj.set_color(YELLOW)\n obj = self.fit_in_frame(obj)\n self.add(obj)\n \n # [UPDATER]\n # [BEAT 1 | sync: b1]\n with self.voiceover(text=\"We initialize a bar chart displaying four categories. \") as t:\n self.wait_until_bookmark(\"b1\")\n self.play(ShowCreation(obj))\n \n # [BEAT 2 | sync: b2]\n with self.voiceover(text=\"Notice the clean setup without deprecated arguments. \") as t:\n self.wait_until_bookmark(\"b2\")\n self.wait(1)\n```", "category": "legacy_api_hallucination", "source": "synthetic_hard_neg:nabin2004/qwen3-8b-manimator-gold-sft"} +{"system": "You are an expert Manim Community Edition (ManimCE v0.19+) Python developer and mathematical animator. Given a user request, first plan the spatial layout, coordinate bounds, timing, and pedagogical flow inside ... tags (when reasoning is helpful), and then output a complete, runnable, self-contained ManimCE Python script using `from manim import *`. Never use deprecated ManimGL (`manimlib`) methods like `ShowCreation`, `TexMobject`, `TextMobject`, or `axes.get_graph`; always use modern ManimCE APIs (`Create`, `MathTex`, `Tex`, `Text`, `axes.plot`) and prevent visual overlap using `.to_edge()`, `.next_to()`, and `FadeOut`.", "prompt": "In what ways do different configurations of root systems influence the classification of Lie Algebras and their associated symmetries?", "chosen": "```python\nfrom manim import *\n\nclass RootSystemsLieAlgebras(Scene):\n def construct(self):\n # Title\n title = Text(\"The Symphony of Symmetries: Root Systems in Lie Algebras\", font_size=32)\n self.play(Write(title))\n self.wait(1)\n self.play(title.animate.scale(0.6).to_edge(UP))\n \n # Introduction\n intro_text = Text(\"Root systems are configurations of vectors that define Lie Algebras\", \n font_size=24)\n self.play(Write(intro_text))\n self.wait(1)\n self.play(FadeOut(intro_text))\n \n # Visualization of vectors in a coordinate system\n axes = Axes(\n x_range=[-3, 3],\n y_range=[-3, 3],\n axis_config={\"color\": BLUE},\n )\n self.play(Create(axes))\n \n # Create simple vectors to illustrate a root system\n vectors = [\n Arrow(start=ORIGIN, end=[1, 0, 0], color=RED),\n Arrow(start=ORIGIN, end=[0, 1, 0], color=RED),\n Arrow(start=ORIGIN, end=[-1, 0, 0], color=RED),\n Arrow(start=ORIGIN, end=[0, -1, 0], color=RED)\n ]\n \n vector_group = VGroup(*vectors)\n self.play(Create(vector_group))\n self.wait(1)\n \n # Type A root system\n self.play(FadeOut(vector_group), FadeOut(axes))\n \n type_a_title = Text(\"Type A Root System\", font_size=28)\n self.play(Write(type_a_title))\n self.play(type_a_title.animate.to_edge(UP))\n \n # Create nodes for Type A\n nodes = [Dot(point=np.array([i-2, 0, 0]), color=BLUE) for i in range(5)]\n lines = [Line(nodes[i].get_center(), nodes[i+1].get_center(), color=WHITE) \n for i in range(len(nodes)-1)]\n \n type_a_diagram = VGroup(*nodes, *lines)\n \n self.play(Create(type_a_diagram))\n \n # Type A equation\n eq_a = Text(\"Type A: (alpha_i, alpha_i+1) > 0\", font_size=24)\n eq_a.next_to(type_a_diagram, DOWN, buff=1)\n self.play(Write(eq_a))\n self.wait(1)\n \n # Transition to Type B/C\n self.play(FadeOut(type_a_diagram), FadeOut(eq_a), FadeOut(type_a_title))\n \n type_bc_title = Text(\"Type B/C Root Systems\", font_size=28)\n self.play(Write(type_bc_title))\n self.play(type_bc_title.animate.to_edge(UP))\n \n # Create Type B/C diagram\n nodes_b = [Dot(point=np.array([i-2, 0, 0]), color=BLUE) for i in range(5)]\n \n # Make the last node special (different color)\n nodes_b[-1].set_color(PURPLE)\n \n lines_b = [Line(nodes_b[i].get_center(), nodes_b[i+1].get_center(), color=WHITE) \n for i in range(len(nodes_b)-1)]\n \n # Make the last line different (double line to represent B/C difference)\n lines_b[-1] = Line(nodes_b[-2].get_center(), nodes_b[-1].get_center(), color=PURPLE_A, stroke_width=3)\n \n type_bc_diagram = VGroup(*nodes_b, *lines_b)\n \n self.play(Create(type_bc_diagram))\n \n # Type B/C equation\n eq_bc = Text(\"Type B/C: (alpha_i, alpha_i+1) = 0\", font_size=24)\n eq_bc.next_to(type_bc_diagram, DOWN, buff=1)\n self.play(Write(eq_bc))\n self.wait(1)\n \n # Transition to Type D\n self.play(FadeOut(type_bc_diagram), FadeOut(eq_bc), FadeOut(type_bc_title))\n \n type_d_title = Text(\"Type D Root System\", font_size=28)\n self.play(Write(type_d_title))\n self.play(type_d_title.animate.to_edge(UP))\n \n # Create Type D diagram - a branching structure\n main_node = Dot(point=ORIGIN, color=BLUE)\n branch_nodes = [\n Dot(point=np.array([-1, 1, 0]), color=BLUE),\n Dot(point=np.array([-1, -1, 0]), color=BLUE),\n Dot(point=np.array([-2, 0, 0]), color=BLUE)\n ]\n \n branch_lines = [\n Line(main_node.get_center(), branch_nodes[0].get_center(), color=WHITE),\n Line(main_node.get_center(), branch_nodes[1].get_center(), color=WHITE),\n Line(main_node.get_center(), branch_nodes[2].get_center(), color=WHITE)\n ]\n \n type_d_diagram = VGroup(main_node, *branch_nodes, *branch_lines)\n \n self.play(Create(type_d_diagram))\n \n # Type D equation\n eq_d = Text(\"Type D: Perpendicular vectors forming symmetries\", font_size=24)\n eq_d.next_to(type_d_diagram, DOWN, buff=1)\n self.play(Write(eq_d))\n self.wait(1)\n \n # Key insight\n self.play(FadeOut(type_d_diagram), FadeOut(eq_d), FadeOut(type_d_title))\n \n insight_text = Text(\"Root system configurations classify Lie Algebras\\nand determine their symmetry properties\", \n font_size=24, line_spacing=1.5)\n self.play(Write(insight_text))\n self.wait(1)\n \n # Conclusion\n self.play(FadeOut(insight_text))\n \n conclusion = Text(\"Root systems form the symphony of symmetries\\nin the world of Lie Algebras\", \n font_size=28, line_spacing=1.5)\n self.play(Write(conclusion))\n self.wait(1)\n \n # Final fade out\n self.play(FadeOut(conclusion), FadeOut(title))\n```", "rejected": "```python\nfrom manim import *\n\nclass RootSystemsLieAlgebras(Scene):\n def construct(self):\n # Title\n title = Text(\"The Symphony of Symmetries: Root Systems in Lie Algebras\", font_size=32)\n self.play(Write(title))\n self.wait(1)\n self.play(title.animate.scale(0.6).to_edge(UP))\n \n # Introduction\n intro_text = Text(\"Root systems are configurations of vectors that define Lie Algebras\", \n font_size=24)\n self.play(Write(intro_text))\n self.wait(1)\n self.play(FadeOut(intro_text))\n \n # Visualization of vectors in a coordinate system\n axes = Axes(\n x_range=[-3, 3],\n y_range=[-3, 3],\n axis_config={\"color\": BLUE},\n )\n self.play(ShowCreation(axes))\n \n # Create simple vectors to illustrate a root system\n vectors = [\n Arrow(start=ORIGIN, end=[1, 0, 0], color=RED),\n Arrow(start=ORIGIN, end=[0, 1, 0], color=RED),\n Arrow(start=ORIGIN, end=[-1, 0, 0], color=RED),\n Arrow(start=ORIGIN, end=[0, -1, 0], color=RED)\n ]\n \n vector_group = VGroup(*vectors)\n self.play(Create(vector_group))\n self.wait(1)\n \n # Type A root system\n self.play(FadeOut(vector_group), FadeOut(axes))\n \n type_a_title = Text(\"Type A Root System\", font_size=28)\n self.play(Write(type_a_title))\n self.play(type_a_title.animate.to_edge(UP))\n \n # Create nodes for Type A\n nodes = [Dot(point=np.array([i-2, 0, 0]), color=BLUE) for i in range(5)]\n lines = [Line(nodes[i].get_center(), nodes[i+1].get_center(), color=WHITE) \n for i in range(len(nodes)-1)]\n \n type_a_diagram = VGroup(*nodes, *lines)\n \n self.play(Create(type_a_diagram))\n \n # Type A equation\n eq_a = Text(\"Type A: (alpha_i, alpha_i+1) > 0\", font_size=24)\n eq_a.next_to(type_a_diagram, DOWN, buff=1)\n self.play(Write(eq_a))\n self.wait(1)\n \n # Transition to Type B/C\n self.play(FadeOut(type_a_diagram), FadeOut(eq_a), FadeOut(type_a_title))\n \n type_bc_title = Text(\"Type B/C Root Systems\", font_size=28)\n self.play(Write(type_bc_title))\n self.play(type_bc_title.animate.to_edge(UP))\n \n # Create Type B/C diagram\n nodes_b = [Dot(point=np.array([i-2, 0, 0]), color=BLUE) for i in range(5)]\n \n # Make the last node special (different color)\n nodes_b[-1].set_color(PURPLE)\n \n lines_b = [Line(nodes_b[i].get_center(), nodes_b[i+1].get_center(), color=WHITE) \n for i in range(len(nodes_b)-1)]\n \n # Make the last line different (double line to represent B/C difference)\n lines_b[-1] = Line(nodes_b[-2].get_center(), nodes_b[-1].get_center(), color=PURPLE_A, stroke_width=3)\n \n type_bc_diagram = VGroup(*nodes_b, *lines_b)\n \n self.play(Create(type_bc_diagram))\n \n # Type B/C equation\n eq_bc = Text(\"Type B/C: (alpha_i, alpha_i+1) = 0\", font_size=24)\n eq_bc.next_to(type_bc_diagram, DOWN, buff=1)\n self.play(Write(eq_bc))\n self.wait(1)\n \n # Transition to Type D\n self.play(FadeOut(type_bc_diagram), FadeOut(eq_bc), FadeOut(type_bc_title))\n \n type_d_title = Text(\"Type D Root System\", font_size=28)\n self.play(Write(type_d_title))\n self.play(type_d_title.animate.to_edge(UP))\n \n # Create Type D diagram - a branching structure\n main_node = Dot(point=ORIGIN, color=BLUE)\n branch_nodes = [\n Dot(point=np.array([-1, 1, 0]), color=BLUE),\n Dot(point=np.array([-1, -1, 0]), color=BLUE),\n Dot(point=np.array([-2, 0, 0]), color=BLUE)\n ]\n \n branch_lines = [\n Line(main_node.get_center(), branch_nodes[0].get_center(), color=WHITE),\n Line(main_node.get_center(), branch_nodes[1].get_center(), color=WHITE),\n Line(main_node.get_center(), branch_nodes[2].get_center(), color=WHITE)\n ]\n \n type_d_diagram = VGroup(main_node, *branch_nodes, *branch_lines)\n \n self.play(Create(type_d_diagram))\n \n # Type D equation\n eq_d = Text(\"Type D: Perpendicular vectors forming symmetries\", font_size=24)\n eq_d.next_to(type_d_diagram, DOWN, buff=1)\n self.play(Write(eq_d))\n self.wait(1)\n \n # Key insight\n self.play(FadeOut(type_d_diagram), FadeOut(eq_d), FadeOut(type_d_title))\n \n insight_text = Text(\"Root system configurations classify Lie Algebras\\nand determine their symmetry properties\", \n font_size=24, line_spacing=1.5)\n self.play(Write(insight_text))\n self.wait(1)\n \n # Conclusion\n self.play(FadeOut(insight_text))\n \n conclusion = Text(\"Root systems form the symphony of symmetries\\nin the world of Lie Algebras\", \n font_size=28, line_spacing=1.5)\n self.play(Write(conclusion))\n self.wait(1)\n \n # Final fade out\n self.play(FadeOut(conclusion), FadeOut(title))\n```", "category": "legacy_api_hallucination", "source": "synthetic_hard_neg:nabin2004/manim-sft-10k"} +{"system": "You are an expert Manim Community Edition (ManimCE v0.19+) Python developer and mathematical animator. Given a user request, first plan the spatial layout, coordinate bounds, timing, and pedagogical flow inside ... tags (when reasoning is helpful), and then output a complete, runnable, self-contained ManimCE Python script using `from manim import *`. Never use deprecated ManimGL (`manimlib`) methods like `ShowCreation`, `TexMobject`, `TextMobject`, or `axes.get_graph`; always use modern ManimCE APIs (`Create`, `MathTex`, `Tex`, `Text`, `axes.plot`) and prevent visual overlap using `.to_edge()`, `.next_to()`, and `FadeOut`.", "prompt": "I'm learning MATLAB's Deep Learning Toolbox and want to visualize a CNN training on a toy dataset. Show the network architecture, data flow, and the evolving loss/accuracy with live plots. Demonstrate how to modify layers, apply data augmentation, and export a short training storyboard. Include 3D plots of feature maps and annotated timelines of hyperparameter changes.", "chosen": "```python\nfrom manim import *\nfrom manim_voiceover import VoiceoverScene\nfrom manim_voiceover.services.gtts import GTTSService\n\nclass CNNTrainingVisualizationMATLAB(VoiceoverScene):\n def construct(self):\n # Set up speech service\n self.set_speech_service(\n GTTSService(voice=\"alba\", cache_dir=\"voiceover_cache\")\n )\n \n # Title scene\n title = Text(\"CNN Training Visualization in MATLAB\", font_size=48, color=BLUE)\n subtitle = Text(\"Understanding Deep Learning Training\", font_size=28, color=GRAY)\n subtitle.next_to(title, DOWN, buff=0.5)\n \n with self.voiceover(text=\"Have you ever wondered how a Convolutional Neural Network learns from images?\") as tracker:\n self.play(Write(title), run_time=tracker.duration * 0.6)\n self.play(FadeIn(subtitle), run_time=tracker.duration * 0.4)\n \n self.wait(0.5)\n \n with self.voiceover(text=\"Picture this: with each epoch, your model is adjusting its filters and weights, gradually improving its ability to recognize patterns.\") as tracker:\n self.play(\n title.animate.scale(0.5).to_corner(UL),\n FadeOut(subtitle),\n run_time=tracker.duration\n )\n \n # Introduction to CNN\n cnn_text = Text(\"Convolutional Neural Network\", font_size=32, color=YELLOW)\n cnn_text.next_to(title, DOWN, buff=0.3)\n \n with self.voiceover(text=\"But how do we visualize this complex process effectively? Today, you will explore exactly how to see the training of a CNN unfold in real-time using MATLAB.\") as tracker:\n self.play(Write(cnn_text), run_time=tracker.duration)\n \n self.wait(0.3)\n \n # Clear for architecture diagram\n self.play(FadeOut(cnn_text))\n \n # CNN Architecture Visualization\n with self.voiceover(text=\"A CNN consists of multiple layers. First, convolutional layers extract features from input images using learnable filters.\") as tracker:\n # Input Image\n input_box = Rectangle(width=1.5, height=1.5, fill_color=BLUE_E, fill_opacity=0.8)\n input_label = Text(\"Input Image\", font_size=18).next_to(input_box, DOWN, buff=0.2)\n input_group = VGroup(input_box, input_label)\n input_group.shift(LEFT * 5)\n \n # Conv Layer 1\n conv1_box = Rectangle(width=1.2, height=1.2, fill_color=GREEN_E, fill_opacity=0.8)\n conv1_label = Text(\"Conv Layer 1\", font_size=16).next_to(conv1_box, DOWN, buff=0.2)\n conv1_group = VGroup(conv1_box, conv1_label)\n conv1_group.shift(LEFT * 2.5)\n \n # Arrow 1\n arrow1 = Arrow(input_box.get_right(), conv1_box.get_left(), buff=0.3, color=WHITE)\n \n self.play(Create(input_group), run_time=tracker.duration * 0.3)\n self.play(Create(arrow1), run_time=tracker.duration * 0.2)\n self.play(Create(conv1_group), run_time=tracker.duration * 0.5)\n \n # Pooling layer\n with self.voiceover(text=\"Then pooling layers reduce spatial dimensions while preserving important features.\") as tracker:\n pool_box = Rectangle(width=1, height=1, fill_color=ORANGE, fill_opacity=0.8)\n pool_label = Text(\"Pooling\", font_size=16).next_to(pool_box, DOWN, buff=0.2)\n pool_group = VGroup(pool_box, pool_label)\n pool_group.shift(LEFT * 0.3)\n \n arrow2 = Arrow(conv1_box.get_right(), pool_box.get_left(), buff=0.3, color=WHITE)\n \n self.play(Create(arrow2), run_time=tracker.duration * 0.3)\n self.play(Create(pool_group), run_time=tracker.duration * 0.7)\n \n # More conv layers\n with self.voiceover(text=\"Additional convolutional layers extract higher-level features, building a hierarchical representation.\") as tracker:\n conv2_box = Rectangle(width=0.9, height=0.9, fill_color=GREEN_D, fill_opacity=0.8)\n conv2_label = Text(\"Conv Layer 2\", font_size=14).next_to(conv2_box, DOWN, buff=0.15)\n conv2_group = VGroup(conv2_box, conv2_label)\n conv2_group.shift(RIGHT * 1.8)\n \n arrow3 = Arrow(pool_box.get_right(), conv2_box.get_left(), buff=0.3, color=WHITE)\n \n self.play(Create(arrow3), run_time=tracker.duration * 0.3)\n self.play(Create(conv2_group), run_time=tracker.duration * 0.7)\n \n # Fully connected\n with self.voiceover(text=\"Finally, fully connected layers perform classification based on the extracted features.\") as tracker:\n fc_box = Rectangle(width=0.8, height=0.8, fill_color=RED_E, fill_opacity=0.8)\n fc_label = Text(\"FC Layer\", font_size=14).next_to(fc_box, DOWN, buff=0.15)\n fc_group = VGroup(fc_box, fc_label)\n fc_group.shift(RIGHT * 3.8)\n \n arrow4 = Arrow(conv2_box.get_right(), fc_box.get_left(), buff=0.3, color=WHITE)\n \n # Output\n output_box = Rectangle(width=0.6, height=0.6, fill_color=PURPLE_E, fill_opacity=0.8)\n output_label = Text(\"Output\", font_size=14).next_to(output_box, DOWN, buff=0.15)\n output_group = VGroup(output_box, output_label)\n output_group.shift(RIGHT * 5.5)\n \n arrow5 = Arrow(fc_box.get_right(), output_box.get_left(), buff=0.3, color=WHITE)\n \n self.play(Create(arrow4), Create(fc_group), run_time=tracker.duration * 0.5)\n self.play(Create(arrow5), Create(output_group), run_time=tracker.duration * 0.5)\n \n self.wait(0.5)\n \n # Fade out architecture\n all_architecture = VGroup(\n input_group, arrow1, conv1_group, arrow2, pool_group,\n arrow3, conv2_group, arrow4, fc_group, arrow5, output_group\n )\n \n with self.voiceover(text=\"During training, these layers learn by adjusting weights through backpropagation.\") as tracker:\n self.play(FadeOut(all_architecture), run_time=tracker.duration)\n \n # Training metrics visualization\n with self.voiceover(text=\"Now let us see how to visualize the training process in MATLAB.\") as tracker:\n matlab_label = Text(\"MATLAB Training Monitor\", font_size=32, color=BLUE)\n matlab_label.next_to(title, DOWN, buff=0.5)\n self.play(Write(matlab_label), run_time=tracker.duration)\n \n # Create axes for loss curve\n with self.voiceover(text=\"The training progress window shows loss decreasing over epochs.\") as tracker:\n axes1 = Axes(\n x_range=[0, 10, 1],\n y_range=[0, 2, 0.5],\n x_length=5,\n y_length=3,\n axis_config={\"include_tip\": False, \"font_size\": 16},\n )\n axes1.shift(LEFT * 2.5 + DOWN * 0.5)\n \n loss_label = Text(\"Training Loss\", font_size=20, color=RED)\n loss_label.next_to(axes1, UP, buff=0.2)\n \n x_label1 = Text(\"Epochs\", font_size=14).next_to(axes1.x_axis, DOWN, buff=0.2)\n y_label1 = Text(\"Loss\", font_size=14).next_to(axes1.y_axis, LEFT, buff=0.2)\n \n self.play(\n Create(axes1),\n Write(loss_label),\n Write(x_label1),\n Write(y_label1),\n run_time=tracker.duration\n )\n \n # Loss curve animation\n with self.voiceover(text=\"Watch as the loss curve decreases, indicating the model is learning.\") as tracker:\n loss_curve = axes1.plot(\n lambda x: 1.8 * (0.7 ** x) + 0.2,\n x_range=[0, 10],\n color=RED,\n stroke_width=3\n )\n \n self.play(Create(loss_curve), run_time=tracker.duration)\n \n # Accuracy curve\n with self.voiceover(text=\"Similarly, the accuracy curve shows how well the model classifies images correctly.\") as tracker:\n axes2 = Axes(\n x_range=[0, 10, 1],\n y_range=[0, 100, 25],\n x_length=5,\n y_length=3,\n axis_config={\"include_tip\": False, \"font_size\": 16},\n )\n axes2.shift(RIGHT * 2.5 + DOWN * 0.5)\n \n acc_label = Text(\"Accuracy (%)\", font_size=20, color=GREEN)\n acc_label.next_to(axes2, UP, buff=0.2)\n \n x_label2 = Text(\"Epochs\", font_size=14).next_to(axes2.x_axis, DOWN, buff=0.2)\n y_label2 = Text(\"Accuracy\", font_size=14).next_to(axes2.y_axis, RIGHT, buff=0.2)\n \n acc_curve = axes2.plot(\n lambda x: 100 * (1 - 0.8 ** x),\n x_range=[0, 10],\n color=GREEN,\n stroke_width=3\n )\n \n self.play(\n Create(axes2),\n Write(acc_label),\n Write(x_label2),\n Write(y_label2),\n run_time=tracker.duration * 0.5\n )\n self.play(Create(acc_curve), run_time=tracker.duration * 0.5)\n \n self.wait(0.5)\n \n # MATLAB code snippet\n with self.voiceover(text=\"In MATLAB, you can use the trainingOptions function with the plots parameter set to training-progress.\") as tracker:\n # Clear curves\n self.play(\n FadeOut(matlab_label),\n FadeOut(axes1), FadeOut(loss_label), FadeOut(x_label1), FadeOut(y_label1),\n FadeOut(loss_curve),\n FadeOut(axes2), FadeOut(acc_label), FadeOut(x_label2), FadeOut(y_label2),\n FadeOut(acc_curve),\n run_time=tracker.duration * 0.3\n )\n \n # MATLAB code - using Text without problematic quotes\n code_lines = [\n \"options = trainingOptions('sgdm', ...\",\n \" 'MaxEpochs', 10, ...\",\n \" 'Plots', 'training-progress', ...\",\n \" 'Metrics', 'accuracy');\",\n \"\",\n \"net = trainNetwork(data, layers, options);\"\n ]\n \n code_box = Rectangle(\n width=8, height=3,\n fill_color=BLACK, fill_opacity=0.9,\n stroke_color=BLUE, stroke_width=2\n )\n code_box.shift(DOWN * 0.5)\n \n code_display = VGroup()\n for i, line in enumerate(code_lines):\n txt = Text(line, font_size=18, font=\"monospace\", color=WHITE)\n txt.shift(DOWN * 0.5 + UP * (0.8 - i * 0.4))\n code_display.add(txt)\n \n matlab_title = Text(\"MATLAB Code\", font_size=28, color=BLUE)\n matlab_title.next_to(code_box, UP, buff=0.3)\n \n self.play(\n Create(code_box),\n Write(matlab_title),\n run_time=tracker.duration * 0.4\n )\n self.play(Write(code_display), run_time=tracker.duration * 0.3)\n \n self.wait(0.5)\n \n # Learning outcomes\n with self.voiceover(text=\"By the end of this lesson, you will understand the training process of CNNs, visualize training metrics in real-time, and analyze model performance using MATLAB visualizations.\") as tracker:\n self.play(\n FadeOut(code_box),\n FadeOut(code_display),\n FadeOut(matlab_title),\n run_time=tracker.duration * 0.2\n )\n \n outcomes_title = Text(\"Learning Outcomes\", font_size=36, color=BLUE)\n outcomes_title.shift(UP * 2)\n \n outcome1 = Text(\"• Understand CNN training process\", font_size=24)\n outcome2 = Text(\"• Visualize metrics in real-time\", font_size=24)\n outcome3 = Text(\"• Analyze model performance in MATLAB\", font_size=24)\n \n outcomes = VGroup(outcome1, outcome2, outcome3)\n outcomes.arrange(DOWN, buff=0.5, aligned_edge=LEFT)\n outcomes.shift(LEFT * 1)\n \n self.play(Write(outcomes_title), run_time=tracker.duration * 0.3)\n self.play(Write(outcome1), run_time=tracker.duration * 0.25)\n self.play(Write(outcome2), run_time=tracker.duration * 0.25)\n self.play(Write(outcome3), run_time=tracker.duration * 0.3)\n \n self.wait(0.5)\n \n # Conclusion\n with self.voiceover(text=\"Start visualizing your CNN training in MATLAB today and gain deeper insights into your model's learning journey.\") as tracker:\n conclusion = Text(\"Start Training & Visualizing!\", font_size=32, color=GREEN)\n conclusion.next_to(outcomes, DOWN, buff=0.8)\n \n self.play(Write(conclusion), run_time=tracker.duration)\n \n self.wait(1)\n \n # Fade out everything\n self.play(\n FadeOut(title),\n FadeOut(outcomes_title),\n FadeOut(outcomes),\n FadeOut(conclusion),\n run_time=2\n )\n```", "rejected": "```python\nfrom manim import *\nfrom manim_voiceover import VoiceoverScene\nfrom manim_voiceover.services.gtts import GTTSService\n\nclass CNNTrainingVisualizationMATLAB(VoiceoverScene):\n def construct(self):\n # Set up speech service\n self.set_speech_service(\n GTTSService(voice=\"alba\", cache_dir=\"voiceover_cache\")\n )\n \n # Title scene\n title = Text(\"CNN Training Visualization in MATLAB\", font_size=48, color=BLUE)\n subtitle = Text(\"Understanding Deep Learning Training\", font_size=28, color=GRAY)\n subtitle.next_to(title, DOWN, buff=0.5)\n \n with self.voiceover(text=\"Have you ever wondered how a Convolutional Neural Network learns from images?\") as tracker:\n self.play(Write(title), run_time=tracker.duration * 0.6)\n self.play(FadeIn(subtitle), run_time=tracker.duration * 0.4)\n \n self.wait(0.5)\n \n with self.voiceover(text=\"Picture this: with each epoch, your model is adjusting its filters and weights, gradually improving its ability to recognize patterns.\") as tracker:\n self.play(\n title.animate.scale(0.5).to_corner(UL),\n FadeOut(subtitle),\n run_time=tracker.duration\n )\n \n # Introduction to CNN\n cnn_text = Text(\"Convolutional Neural Network\", font_size=32, color=YELLOW)\n cnn_text.next_to(title, DOWN, buff=0.3)\n \n with self.voiceover(text=\"But how do we visualize this complex process effectively? Today, you will explore exactly how to see the training of a CNN unfold in real-time using MATLAB.\") as tracker:\n self.play(Write(cnn_text), run_time=tracker.duration)\n \n self.wait(0.3)\n \n # Clear for architecture diagram\n self.play(FadeOut(cnn_text))\n \n # CNN Architecture Visualization\n with self.voiceover(text=\"A CNN consists of multiple layers. First, convolutional layers extract features from input images using learnable filters.\") as tracker:\n # Input Image\n input_box = Rectangle(width=1.5, height=1.5, fill_color=BLUE_E, fill_opacity=0.8)\n input_label = Text(\"Input Image\", font_size=18).next_to(input_box, DOWN, buff=0.2)\n input_group = VGroup(input_box, input_label)\n input_group.shift(LEFT * 5)\n \n # Conv Layer 1\n conv1_box = Rectangle(width=1.2, height=1.2, fill_color=GREEN_E, fill_opacity=0.8)\n conv1_label = Text(\"Conv Layer 1\", font_size=16).next_to(conv1_box, DOWN, buff=0.2)\n conv1_group = VGroup(conv1_box, conv1_label)\n conv1_group.shift(LEFT * 2.5)\n \n # Arrow 1\n arrow1 = Arrow(input_box.get_right(), conv1_box.get_left(), buff=0.3, color=WHITE)\n \n self.play(Create(input_group), run_time=tracker.duration * 0.3)\n self.play(Create(arrow1), run_time=tracker.duration * 0.2)\n self.play(Create(conv1_group), run_time=tracker.duration * 0.5)\n \n # Pooling layer\n with self.voiceover(text=\"Then pooling layers reduce spatial dimensions while preserving important features.\") as tracker:\n pool_box = Rectangle(width=1, height=1, fill_color=ORANGE, fill_opacity=0.8)\n pool_label = Text(\"Pooling\", font_size=16).next_to(pool_box, DOWN, buff=0.2)\n pool_group = VGroup(pool_box, pool_label)\n pool_group.shift(LEFT * 0.3)\n \n arrow2 = Arrow(conv1_box.get_right(), pool_box.get_left(), buff=0.3, color=WHITE)\n \n self.play(Create(arrow2), run_time=tracker.duration * 0.3)\n self.play(Create(pool_group), run_time=tracker.duration * 0.7)\n \n # More conv layers\n with self.voiceover(text=\"Additional convolutional layers extract higher-level features, building a hierarchical representation.\") as tracker:\n conv2_box = Rectangle(width=0.9, height=0.9, fill_color=GREEN_D, fill_opacity=0.8)\n conv2_label = Text(\"Conv Layer 2\", font_size=14).next_to(conv2_box, DOWN, buff=0.15)\n conv2_group = VGroup(conv2_box, conv2_label)\n conv2_group.shift(RIGHT * 1.8)\n \n arrow3 = Arrow(pool_box.get_right(), conv2_box.get_left(), buff=0.3, color=WHITE)\n \n self.play(Create(arrow3), run_time=tracker.duration * 0.3)\n self.play(Create(conv2_group), run_time=tracker.duration * 0.7)\n \n # Fully connected\n with self.voiceover(text=\"Finally, fully connected layers perform classification based on the extracted features.\") as tracker:\n fc_box = Rectangle(width=0.8, height=0.8, fill_color=RED_E, fill_opacity=0.8)\n fc_label = Text(\"FC Layer\", font_size=14).next_to(fc_box, DOWN, buff=0.15)\n fc_group = VGroup(fc_box, fc_label)\n fc_group.shift(RIGHT * 3.8)\n \n arrow4 = Arrow(conv2_box.get_right(), fc_box.get_left(), buff=0.3, color=WHITE)\n \n # Output\n output_box = Rectangle(width=0.6, height=0.6, fill_color=PURPLE_E, fill_opacity=0.8)\n output_label = Text(\"Output\", font_size=14).next_to(output_box, DOWN, buff=0.15)\n output_group = VGroup(output_box, output_label)\n output_group.shift(RIGHT * 5.5)\n \n arrow5 = Arrow(fc_box.get_right(), output_box.get_left(), buff=0.3, color=WHITE)\n \n self.play(Create(arrow4), Create(fc_group), run_time=tracker.duration * 0.5)\n self.play(Create(arrow5), Create(output_group), run_time=tracker.duration * 0.5)\n \n self.wait(0.5)\n \n # Fade out architecture\n all_architecture = VGroup(\n input_group, arrow1, conv1_group, arrow2, pool_group,\n arrow3, conv2_group, arrow4, fc_group, arrow5, output_group\n )\n \n with self.voiceover(text=\"During training, these layers learn by adjusting weights through backpropagation.\") as tracker:\n self.play(FadeOut(all_architecture), run_time=tracker.duration)\n \n # Training metrics visualization\n with self.voiceover(text=\"Now let us see how to visualize the training process in MATLAB.\") as tracker:\n matlab_label = Text(\"MATLAB Training Monitor\", font_size=32, color=BLUE)\n matlab_label.next_to(title, DOWN, buff=0.5)\n self.play(Write(matlab_label), run_time=tracker.duration)\n \n # Create axes for loss curve\n with self.voiceover(text=\"The training progress window shows loss decreasing over epochs.\") as tracker:\n axes1 = Axes(axis_color=BLUE, \n x_range=[0, 10, 1],\n y_range=[0, 2, 0.5],\n x_length=5,\n y_length=3,\n axis_config={\"include_tip\": False, \"font_size\": 16},\n )\n axes1.shift(LEFT * 2.5 + DOWN * 0.5)\n \n loss_label = Text(\"Training Loss\", font_size=20, color=RED)\n loss_label.next_to(axes1, UP, buff=0.2)\n \n x_label1 = Text(\"Epochs\", font_size=14).next_to(axes1.x_axis, DOWN, buff=0.2)\n y_label1 = Text(\"Loss\", font_size=14).next_to(axes1.y_axis, LEFT, buff=0.2)\n \n self.play(\n Create(axes1),\n Write(loss_label),\n Write(x_label1),\n Write(y_label1),\n run_time=tracker.duration\n )\n \n # Loss curve animation\n with self.voiceover(text=\"Watch as the loss curve decreases, indicating the model is learning.\") as tracker:\n loss_curve = axes1.plot(\n lambda x: 1.8 * (0.7 ** x) + 0.2,\n x_range=[0, 10],\n color=RED,\n stroke_width=3\n )\n \n self.play(Create(loss_curve), run_time=tracker.duration)\n \n # Accuracy curve\n with self.voiceover(text=\"Similarly, the accuracy curve shows how well the model classifies images correctly.\") as tracker:\n axes2 = Axes(\n x_range=[0, 10, 1],\n y_range=[0, 100, 25],\n x_length=5,\n y_length=3,\n axis_config={\"include_tip\": False, \"font_size\": 16},\n )\n axes2.shift(RIGHT * 2.5 + DOWN * 0.5)\n \n acc_label = Text(\"Accuracy (%)\", font_size=20, color=GREEN)\n acc_label.next_to(axes2, UP, buff=0.2)\n \n x_label2 = Text(\"Epochs\", font_size=14).next_to(axes2.x_axis, DOWN, buff=0.2)\n y_label2 = Text(\"Accuracy\", font_size=14).next_to(axes2.y_axis, RIGHT, buff=0.2)\n \n acc_curve = axes2.plot(\n lambda x: 100 * (1 - 0.8 ** x),\n x_range=[0, 10],\n color=GREEN,\n stroke_width=3\n )\n \n self.play(\n Create(axes2),\n Write(acc_label),\n Write(x_label2),\n Write(y_label2),\n run_time=tracker.duration * 0.5\n )\n self.play(Create(acc_curve), run_time=tracker.duration * 0.5)\n \n self.wait(0.5)\n \n # MATLAB code snippet\n with self.voiceover(text=\"In MATLAB, you can use the trainingOptions function with the plots parameter set to training-progress.\") as tracker:\n # Clear curves\n self.play(\n FadeOut(matlab_label),\n FadeOut(axes1), FadeOut(loss_label), FadeOut(x_label1), FadeOut(y_label1),\n FadeOut(loss_curve),\n FadeOut(axes2), FadeOut(acc_label), FadeOut(x_label2), FadeOut(y_label2),\n FadeOut(acc_curve),\n run_time=tracker.duration * 0.3\n )\n \n # MATLAB code - using Text without problematic quotes\n code_lines = [\n \"options = trainingOptions('sgdm', ...\",\n \" 'MaxEpochs', 10, ...\",\n \" 'Plots', 'training-progress', ...\",\n \" 'Metrics', 'accuracy');\",\n \"\",\n \"net = trainNetwork(data, layers, options);\"\n ]\n \n code_box = Rectangle(\n width=8, height=3,\n fill_color=BLACK, fill_opacity=0.9,\n stroke_color=BLUE, stroke_width=2\n )\n code_box.shift(DOWN * 0.5)\n \n code_display = VGroup()\n for i, line in enumerate(code_lines):\n txt = Text(line, font_size=18, font=\"monospace\", color=WHITE)\n txt.shift(DOWN * 0.5 + UP * (0.8 - i * 0.4))\n code_display.add(txt)\n \n matlab_title = Text(\"MATLAB Code\", font_size=28, color=BLUE)\n matlab_title.next_to(code_box, UP, buff=0.3)\n \n self.play(\n Create(code_box),\n Write(matlab_title),\n run_time=tracker.duration * 0.4\n )\n self.play(Write(code_display), run_time=tracker.duration * 0.3)\n \n self.wait(0.5)\n \n # Learning outcomes\n with self.voiceover(text=\"By the end of this lesson, you will understand the training process of CNNs, visualize training metrics in real-time, and analyze model performance using MATLAB visualizations.\") as tracker:\n self.play(\n FadeOut(code_box),\n FadeOut(code_display),\n FadeOut(matlab_title),\n run_time=tracker.duration * 0.2\n )\n \n outcomes_title = Text(\"Learning Outcomes\", font_size=36, color=BLUE)\n outcomes_title.shift(UP * 2)\n \n outcome1 = Text(\"• Understand CNN training process\", font_size=24)\n outcome2 = Text(\"• Visualize metrics in real-time\", font_size=24)\n outcome3 = Text(\"• Analyze model performance in MATLAB\", font_size=24)\n \n outcomes = VGroup(outcome1, outcome2, outcome3)\n outcomes.arrange(DOWN, buff=0.5, aligned_edge=LEFT)\n outcomes.shift(LEFT * 1)\n \n self.play(Write(outcomes_title), run_time=tracker.duration * 0.3)\n self.play(Write(outcome1), run_time=tracker.duration * 0.25)\n self.play(Write(outcome2), run_time=tracker.duration * 0.25)\n self.play(Write(outcome3), run_time=tracker.duration * 0.3)\n \n self.wait(0.5)\n \n # Conclusion\n with self.voiceover(text=\"Start visualizing your CNN training in MATLAB today and gain deeper insights into your model's learning journey.\") as tracker:\n conclusion = Text(\"Start Training & Visualizing!\", font_size=32, color=GREEN)\n conclusion.next_to(outcomes, DOWN, buff=0.8)\n \n self.play(Write(conclusion), run_time=tracker.duration)\n \n self.wait(1)\n \n # Fade out everything\n self.play(\n FadeOut(title),\n FadeOut(outcomes_title),\n FadeOut(outcomes),\n FadeOut(conclusion),\n run_time=2\n )\n```", "category": "invalid_axes_kwarg", "source": "synthetic_hard_neg:nabin2004/AOS-Narrated-Manim-400"} +{"system": "You are an expert Manim Community Edition (ManimCE v0.19+) Python developer and mathematical animator. Given a user request, first plan the spatial layout, coordinate bounds, timing, and pedagogical flow inside ... tags (when reasoning is helpful), and then output a complete, runnable, self-contained ManimCE Python script using `from manim import *`. Never use deprecated ManimGL (`manimlib`) methods like `ShowCreation`, `TexMobject`, `TextMobject`, or `axes.get_graph`; always use modern ManimCE APIs (`Create`, `MathTex`, `Tex`, `Text`, `axes.plot`) and prevent visual overlap using `.to_edge()`, `.next_to()`, and `FadeOut`.", "prompt": "Construct a clean Manim CE scene initializing TangentLine with verified keyword arguments. Ensure no deprecated ManimGL arguments (like element_color, max_value, or max_magnitude) are used.\n\n```python\nfrom manim import *\nimport numpy as np\n\nclass ApiValidTangentLine9(Scene):\n def construct(self):\n obj = TangentLine(Circle(radius=1.5), alpha=0.25, length=3, color=YELLOW)\n obj.set_color(BLUE)\n self.play(Create(obj))\n self.wait(1)\n```", "chosen": "```python\nfrom manim import *\nfrom manim_voiceover import VoiceoverScene\nfrom manim_voiceover.services.gtts import GTTSService\nimport numpy as np\n\nMARGIN = 0.5\n\nclass ApiValidTangentLine9(VoiceoverScene):\n def fit_in_frame(self, mob: Mobject, w_frac=0.9, h_frac=0.9) -> Mobject:\n max_w = config.frame_width * w_frac\n max_h = config.frame_height * h_frac\n if mob.width > max_w: mob.width = max_w\n if mob.height > max_h: mob.height = max_h\n return mob\n\n def construct(self):\n self.set_speech_service(GTTSService(transcription_model=\"base\"))\n \n # [SETUP]\n obj = TangentLine(Circle(radius=1.5), alpha=0.25, length=3)\n obj.set_color(YELLOW)\n \n # [LAYOUT]\n title = MathTex(r\"\\text{Valid TangentLine}\").to_edge(UP, buff=MARGIN)\n self.fit_in_frame(title)\n self.add(title, obj)\n \n # [UPDATER]\n # none\n \n # [BEAT 1 | sync: b1]\n with self.voiceover(text=\"Here is a properly initialized TangentLine mobject, avoiding deprecated arguments like element color. \") as t:\n self.wait_until_bookmark(\"b1\")\n self.play(Create(obj))\n \n self.wait(1)\n```", "rejected": "```python\nfrom manim import *\nfrom manim_voiceover import VoiceoverScene\nfrom manim_voiceover.services.gtts import GTTSService\nimport numpy as np\n\nMARGIN = 0.5\n\nclass ApiValidTangentLine9(VoiceoverScene):\n def fit_in_frame(self, mob: Mobject, w_frac=0.9, h_frac=0.9) -> Mobject:\n max_w = config.frame_width * w_frac\n max_h = config.frame_height * h_frac\n if mob.width > max_w: mob.width = max_w\n if mob.height > max_h: mob.height = max_h\n return mob\n\n def construct(self):\n self.set_speech_service(GTTSService(transcription_model=\"base\"))\n \n # [SETUP]\n obj = TangentLine(Circle(radius=1.5), alpha=0.25, length=3)\n obj.set_color(YELLOW)\n \n # [LAYOUT]\n title = TexMobject(r\"\\text{Valid TangentLine}\").to_edge(UP, buff=MARGIN)\n self.fit_in_frame(title)\n self.add(title, obj)\n \n # [UPDATER]\n # none\n \n # [BEAT 1 | sync: b1]\n with self.voiceover(text=\"Here is a properly initialized TangentLine mobject, avoiding deprecated arguments like element color. \") as t:\n self.wait_until_bookmark(\"b1\")\n self.play(ShowCreation(obj))\n \n self.wait(1)\n```", "category": "legacy_api_hallucination", "source": "synthetic_hard_neg:nabin2004/qwen3-8b-manimator-gold-sft"} +{"system": "You are an expert Manim Community Edition (ManimCE v0.19+) Python developer and mathematical animator. Given a user request, first plan the spatial layout, coordinate bounds, timing, and pedagogical flow inside ... tags (when reasoning is helpful), and then output a complete, runnable, self-contained ManimCE Python script using `from manim import *`. Never use deprecated ManimGL (`manimlib`) methods like `ShowCreation`, `TexMobject`, `TextMobject`, or `axes.get_graph`; always use modern ManimCE APIs (`Create`, `MathTex`, `Tex`, `Text`, `axes.plot`) and prevent visual overlap using `.to_edge()`, `.next_to()`, and `FadeOut`.", "prompt": "I'm teaching an undergrad course on sequence models and want a probabilistic sampling visualization. Animate a spinning wheel divided into character slices, landing on the next character according to the learned distribution. Show the probability weights as arc lengths and reflect the sample decision with a glow and a landing pointer. Include a short, repeatable loop with different temperature settings to compare sampling diversity.", "chosen": "```python\nfrom manim import *\nfrom manim_voiceover import VoiceoverScene\nfrom manim_voiceover.services.gtts import GTTSService\n\nclass ProbabilisticSampling(VoiceoverScene):\n def construct(self):\n # [SETUP]\n # [LAYOUT]\n self.set_speech_service(GTTSService(transcription_model=\"base\"))\n \n # [BEAT 1 | sync: WHEEL]\n with self.voiceover(text=\"Probabilistic sampling can be visualized as a spinning wheel divided into character slices. The arc lengths represent the probability weights of each character.\") as tracker:\n title = Text(\"Probabilistic Sampling\", font_size=36, color=BLUE)\n self.fit_in_frame(title)\n title.to_edge(UP)\n \n wheel = Circle(radius=2, color=WHITE)\n slices = VGroup()\n angles = [0, PI/2, PI, 3*PI/2, 2*PI]\n colors = [RED, GREEN, BLUE, YELLOW]\n for i in range(4):\n sector = AnnularSector(inner_radius=0, outer_radius=2, angle=angles[i+1]-angles[i], start_angle=angles[i], color=colors[i], fill_opacity=0.5)\n slices.add(sector)\n \n self.wait_until_bookmark(\"WHEEL\")\n self.play(Write(title), Create(wheel), Create(slices), run_time=tracker.duration)\n \n with self.voiceover(text=\"The wheel lands on the next character according to the learned distribution. The landing pointer glows to reflect the sample decision.\") as tracker:\n pointer = Polygon(ORIGIN, UP*0.3, LEFT*0.1, RIGHT*0.1, color=WHITE, fill_opacity=1)\n pointer.next_to(wheel, UP, buff=0)\n \n self.wait_until_bookmark(\"POINTER\")\n self.play(Create(pointer), run_time=tracker.duration)\n \n with self.voiceover(text=\"By adjusting the temperature setting, we can compare the sampling diversity. Lower temperatures make the distribution peakier, while higher temperatures flatten it.\") as tracker:\n temp_text = Text(\"Temperature = 1.0\", font_size=24, color=YELLOW)\n temp_text.to_edge(DOWN)\n \n self.wait_until_bookmark(\"TEMP\")\n self.play(Write(temp_text), run_time=tracker.duration)\n self.wait(1)\n\n def fit_in_frame(self, mob: Mobject, w_frac: float = 0.9, h_frac: float = 0.9) -> Mobject:\n max_w = config.frame_width * w_frac\n max_h = config.frame_height * h_frac\n if mob.width > max_w:\n mob.width = max_w\n if mob.height > max_h:\n mob.height = max_h\n return mob\n```", "rejected": "```python\nfrom manim import *\nfrom manim_voiceover import VoiceoverScene\nfrom manim_voiceover.services.gtts import GTTSService\n\nclass ProbabilisticSampling(VoiceoverScene):\n def construct(self):\n # [SETUP]\n # [LAYOUT]\n self.set_speech_service(GTTSService(transcription_model=\"base\"))\n \n # [BEAT 1 | sync: WHEEL]\n with self.voiceover(text=\"Probabilistic sampling can be visualized as a spinning wheel divided into character slices. The arc lengths represent the probability weights of each character.\") as tracker:\n title = Text(\"Probabilistic Sampling\", font_size=36, color=BLUE)\n self.fit_in_frame(title)\n title.to_edge(UP)\n \n wheel = Circle(radius=2, color=WHITE)\n slices = VGroup()\n angles = [0, PI/2, PI, 3*PI/2, 2*PI]\n colors = [RED, GREEN, BLUE, YELLOW]\n for i in range(4):\n sector = AnnularSector(inner_radius=0, outer_radius=2, angle=angles[i+1]-angles[i], start_angle=angles[i], color=colors[i], fill_opacity=0.5)\n slices.add(sector)\n \n self.wait_until_bookmark(\"WHEEL\")\n self.play(Write(title), ShowCreation(wheel), Create(slices), run_time=tracker.duration)\n \n with self.voiceover(text=\"The wheel lands on the next character according to the learned distribution. The landing pointer glows to reflect the sample decision.\") as tracker:\n pointer = Polygon(ORIGIN, UP*0.3, LEFT*0.1, RIGHT*0.1, color=WHITE, fill_opacity=1)\n pointer.next_to(wheel, UP, buff=0)\n \n self.wait_until_bookmark(\"POINTER\")\n self.play(Create(pointer), run_time=tracker.duration)\n \n with self.voiceover(text=\"By adjusting the temperature setting, we can compare the sampling diversity. Lower temperatures make the distribution peakier, while higher temperatures flatten it.\") as tracker:\n temp_text = Text(\"Temperature = 1.0\", font_size=24, color=YELLOW)\n temp_text.to_edge(DOWN)\n \n self.wait_until_bookmark(\"TEMP\")\n self.play(Write(temp_text), run_time=tracker.duration)\n self.wait(1)\n\n def fit_in_frame(self, mob: Mobject, w_frac: float = 0.9, h_frac: float = 0.9) -> Mobject:\n max_w = config.frame_width * w_frac\n max_h = config.frame_height * h_frac\n if mob.width > max_w:\n mob.width = max_w\n if mob.height > max_h:\n mob.height = max_h\n return mob\n```", "category": "legacy_api_hallucination", "source": "synthetic_hard_neg:nabin2004/qwen3-8b-manimator-gold-sft"} +{"system": "You are an expert Manim Community Edition (ManimCE v0.19+) Python developer and mathematical animator. Given a user request, first plan the spatial layout, coordinate bounds, timing, and pedagogical flow inside ... tags (when reasoning is helpful), and then output a complete, runnable, self-contained ManimCE Python script using `from manim import *`. Never use deprecated ManimGL (`manimlib`) methods like `ShowCreation`, `TexMobject`, `TextMobject`, or `axes.get_graph`; always use modern ManimCE APIs (`Create`, `MathTex`, `Tex`, `Text`, `axes.plot`) and prevent visual overlap using `.to_edge()`, `.next_to()`, and `FadeOut`.", "prompt": "I'm teaching ML diagnostics. Visualize classic train and dev loss curves with both curves starting high for underfitting, then train drops while dev stays high for overfitting, and finally both converge for the ideal case. Use color-coded regions, annotations for interpretation, and an optional overlay showing the corresponding model accuracy.", "chosen": "```python\nfrom manim import *\nfrom manim_voiceover import VoiceoverScene\nfrom manim_voiceover.services.gtts import GTTSService\nimport math\n\nclass LossCurvesScene(VoiceoverScene):\n def construct(self):\n self.set_speech_service(\n GTTSService(voice=\"alba\", cache_dir=\"voiceover_cache\")\n )\n\n # === INTRO ===\n title = Text(\"Machine Learning Loss Curves\", font_size=40)\n subtitle = Text(\"Learning vs. Memorizing\", font_size=24, color=BLUE)\n title_group = VGroup(title, subtitle).arrange(DOWN, buff=0.3)\n\n with self.voiceover(\n text=\"Have you ever wondered how we can tell if a machine learning model is actually learning or just memorizing? Loss curves hold the key! They give us insight into the training process of the model and help us understand when we should stop training for the best performance.\"\n ) as tracker:\n self.play(Write(title), run_time=tracker.duration * 0.5)\n self.play(FadeIn(subtitle), run_time=tracker.duration * 0.5)\n\n self.wait(0.5)\n self.play(FadeOut(title_group))\n\n # === AXES ===\n axes = Axes(\n x_range=[0, 10, 1],\n y_range=[0, 7, 1],\n x_length=7,\n y_length=4,\n axis_config={\"include_tip\": False},\n tips=False,\n )\n x_label = Text(\"Epochs\", font_size=20).next_to(axes.x_axis, DOWN, buff=0.2)\n y_label = Text(\"Loss\", font_size=20).next_to(axes.y_axis, LEFT, buff=0.2)\n\n with self.voiceover(\n text=\"Loss curves plot the model's error over training epochs. The horizontal axis shows epochs, and the vertical axis shows loss.\"\n ) as tracker:\n self.play(Create(axes), FadeIn(x_label), FadeIn(y_label), run_time=tracker.duration)\n\n # === TRAINING LOSS ===\n def train_loss(x):\n return 6 * math.exp(-0.4 * x) + 1.2\n\n train_curve = axes.plot(train_loss, x_range=[0.1, 10], color=BLUE, stroke_width=3)\n train_dot = Dot(axes.c2p(8, train_loss(8)), color=BLUE, radius=0.05)\n train_text = Text(\"Training Loss\", font_size=18, color=BLUE).next_to(train_dot, RIGHT, buff=0.1)\n\n with self.voiceover(\n text=\"As training progresses, training loss should decrease. This tells us the model is adjusting its weights to fit the training data.\"\n ) as tracker:\n self.play(\n Create(train_curve), FadeIn(train_dot), FadeIn(train_text),\n run_time=tracker.duration\n )\n\n self.wait(0.3)\n\n # === VALIDATION LOSS ===\n def val_loss(x):\n return 6.5 * math.exp(-0.35 * x) + 1.5 + 0.02 * x\n\n val_curve = axes.plot(val_loss, x_range=[0.1, 10], color=GREEN, stroke_width=3)\n val_dot = Dot(axes.c2p(8, val_loss(8)), color=GREEN, radius=0.05)\n val_text = Text(\"Validation Loss\", font_size=18, color=GREEN).next_to(val_dot, RIGHT, buff=0.1)\n\n with self.voiceover(\n text=\"Validation loss measures performance on unseen data. We track both to see not just if the model learns, but if it generalizes.\"\n ) as tracker:\n self.play(\n Create(val_curve), FadeIn(val_dot), FadeIn(val_text),\n run_time=tracker.duration\n )\n\n self.wait(0.5)\n\n # === TRANSITION TO SCENARIOS ===\n with self.voiceover(\n text=\"Now let's look at three patterns every practitioner must recognize.\"\n ) as tracker:\n self.play(\n FadeOut(VGroup(axes, x_label, y_label, train_curve, val_curve, train_dot, val_dot, train_text, val_text)),\n run_time=tracker.duration\n )\n\n # === THREE SCENARIOS ===\n small_config = {\n \"x_range\": [0, 10, 2],\n \"y_range\": [0, 7, 2],\n \"x_length\": 2.8,\n \"y_length\": 1.8,\n \"axis_config\": {\"include_tip\": False},\n \"tips\": False,\n }\n\n # Good Fit\n ax_g = Axes(**small_config)\n g_train = ax_g.plot(lambda x: 6 * math.exp(-0.4 * x) + 1.2, x_range=[0.1, 10], color=BLUE, stroke_width=2.5)\n g_val = ax_g.plot(lambda x: 6.5 * math.exp(-0.35 * x) + 1.5, x_range=[0.1, 10], color=GREEN, stroke_width=2.5)\n g_label = Text(\"Good Fit\", font_size=20, color=GREEN).next_to(ax_g, UP, buff=0.15)\n g_group = VGroup(ax_g, g_train, g_val, g_label)\n\n # Underfitting\n ax_u = Axes(**small_config)\n u_train = ax_u.plot(lambda x: 6 * math.exp(-0.08 * x) + 4, x_range=[0.1, 10], color=BLUE, stroke_width=2.5)\n u_val = ax_u.plot(lambda x: 6.5 * math.exp(-0.08 * x) + 4.3, x_range=[0.1, 10], color=GREEN, stroke_width=2.5)\n u_label = Text(\"Underfitting\", font_size=20, color=YELLOW).next_to(ax_u, UP, buff=0.15)\n u_group = VGroup(ax_u, u_train, u_val, u_label)\n\n # Overfitting\n ax_o = Axes(**small_config)\n o_train = ax_o.plot(lambda x: 6 * math.exp(-0.4 * x) + 1.2, x_range=[0.1, 10], color=BLUE, stroke_width=2.5)\n def o_val(x):\n if x < 4:\n return 6.5 * math.exp(-0.35 * x) + 1.8\n else:\n return (6.5 * math.exp(-0.35 * 4) + 1.8) + 0.18 * (x - 4) ** 1.3\n o_val_curve = ax_o.plot(o_val, x_range=[0.1, 10], color=GREEN, stroke_width=2.5)\n o_label = Text(\"Overfitting\", font_size=20, color=RED).next_to(ax_o, UP, buff=0.15)\n o_group = VGroup(ax_o, o_train, o_val_curve, o_label)\n\n scenarios = VGroup(g_group, u_group, o_group).arrange(RIGHT, buff=0.5)\n scenarios.move_to(ORIGIN)\n if scenarios.get_width() > 12:\n scenarios.scale_to_fit_width(11)\n if scenarios.get_height() > 5.5:\n scenarios.scale_to_fit_height(5)\n scenarios.move_to(ORIGIN)\n\n with self.voiceover(\n text=\"In a good fit, both losses drop and stay close. The model learns patterns that apply to new data.\"\n ) as tracker:\n self.play(Create(ax_g), Create(g_train), Create(g_val), FadeIn(g_label), run_time=tracker.duration)\n\n self.wait(0.2)\n\n with self.voiceover(\n text=\"Underfitting means both curves remain high. The model is too simple to capture the underlying structure.\"\n ) as tracker:\n self.play(Create(ax_u), Create(u_train), Create(u_val), FadeIn(u_label), run_time=tracker.duration)\n\n self.wait(0.2)\n\n with self.voiceover(\n text=\"Overfitting is when training loss keeps falling, but validation loss climbs. The model is memorizing, not generalizing.\"\n ) as tracker:\n self.play(Create(ax_o), Create(o_train), Create(o_val_curve), FadeIn(o_label), run_time=tracker.duration)\n\n self.wait(0.5)\n\n # Legend\n legend_train = Text(\"Training Loss\", font_size=18, color=BLUE)\n legend_val = Text(\"Validation Loss\", font_size=18, color=GREEN)\n legend = VGroup(legend_train, legend_val).arrange(RIGHT, buff=0.8).to_edge(DOWN, buff=0.4)\n\n with self.voiceover(\n text=\"Always watch both curves together. The gap between them reveals the true health of your model.\"\n ) as tracker:\n self.play(FadeIn(legend), run_time=tracker.duration)\n\n self.wait(0.5)\n\n # === TAKEAWAYS ===\n self.play(FadeOut(VGroup(scenarios, legend)))\n\n takeaways = VGroup(\n Text(\"• Identify loss curves to monitor training.\", font_size=22),\n Text(\"• Underfitting = high loss on both sets.\", font_size=22),\n Text(\"• Overfitting = growing gap, validation rises.\", font_size=22),\n ).arrange(DOWN, aligned_edge=LEFT, buff=0.35)\n takeaways.to_edge(LEFT, buff=0.8)\n if takeaways.get_height() > 4.5:\n takeaways.scale_to_fit_height(4)\n\n with self.voiceover(\n text=\"To summarize: you will identify loss curves during model training, differentiate underfitting and overfitting by analyzing their shapes, and understand why both training and validation loss are essential for robust model development.\"\n ) as tracker:\n for item in takeaways:\n self.play(FadeIn(item), run_time=tracker.duration / len(takeaways))\n\n self.wait(1)\n```", "rejected": "```python\nfrom manim import *\nfrom manim_voiceover import VoiceoverScene\nfrom manim_voiceover.services.gtts import GTTSService\nimport math\n\nclass LossCurvesScene(VoiceoverScene):\n def construct(self):\n self.set_speech_service(\n GTTSService(voice=\"alba\", cache_dir=\"voiceover_cache\")\n )\n\n # === INTRO ===\n title = Text(\"Machine Learning Loss Curves\", font_size=40)\n subtitle = Text(\"Learning vs. Memorizing\", font_size=24, color=BLUE)\n title_group = VGroup(title, subtitle).arrange(DOWN, buff=0.3)\n\n with self.voiceover(\n text=\"Have you ever wondered how we can tell if a machine learning model is actually learning or just memorizing? Loss curves hold the key! They give us insight into the training process of the model and help us understand when we should stop training for the best performance.\"\n ) as tracker:\n self.play(Write(title), run_time=tracker.duration * 0.5)\n self.play(FadeIn(subtitle), run_time=tracker.duration * 0.5)\n\n self.wait(0.5)\n self.play(FadeOut(title_group))\n\n # === AXES ===\n axes = Axes(\n x_range=[0, 10, 1],\n y_range=[0, 7, 1],\n x_length=7,\n y_length=4,\n axis_config={\"include_tip\": False},\n tips=False,\n )\n x_label = Text(\"Epochs\", font_size=20)\n y_label = Text(\"Loss\", font_size=20)\n\n with self.voiceover(\n text=\"Loss curves plot the model's error over training epochs. The horizontal axis shows epochs, and the vertical axis shows loss.\"\n ) as tracker:\n self.play(Create(axes), FadeIn(x_label), FadeIn(y_label), run_time=tracker.duration)\n\n # === TRAINING LOSS ===\n def train_loss(x):\n return 6 * math.exp(-0.4 * x) + 1.2\n\n train_curve = axes.plot(train_loss, x_range=[0.1, 10], color=BLUE, stroke_width=3)\n train_dot = Dot(axes.c2p(8, train_loss(8)), color=BLUE, radius=0.05)\n train_text = Text(\"Training Loss\", font_size=18, color=BLUE)\n\n with self.voiceover(\n text=\"As training progresses, training loss should decrease. This tells us the model is adjusting its weights to fit the training data.\"\n ) as tracker:\n self.play(\n Create(train_curve), FadeIn(train_dot), FadeIn(train_text),\n run_time=tracker.duration\n )\n\n self.wait(0.3)\n\n # === VALIDATION LOSS ===\n def val_loss(x):\n return 6.5 * math.exp(-0.35 * x) + 1.5 + 0.02 * x\n\n val_curve = axes.plot(val_loss, x_range=[0.1, 10], color=GREEN, stroke_width=3)\n val_dot = Dot(axes.c2p(8, val_loss(8)), color=GREEN, radius=0.05)\n val_text = Text(\"Validation Loss\", font_size=18, color=GREEN).next_to(val_dot, RIGHT, buff=0.1)\n\n with self.voiceover(\n text=\"Validation loss measures performance on unseen data. We track both to see not just if the model learns, but if it generalizes.\"\n ) as tracker:\n self.play(\n Create(val_curve), FadeIn(val_dot), FadeIn(val_text),\n run_time=tracker.duration\n )\n\n self.wait(0.5)\n\n # === TRANSITION TO SCENARIOS ===\n with self.voiceover(\n text=\"Now let's look at three patterns every practitioner must recognize.\"\n ) as tracker:\n self.play(\n FadeOut(VGroup(axes, x_label, y_label, train_curve, val_curve, train_dot, val_dot, train_text, val_text)),\n run_time=tracker.duration\n )\n\n # === THREE SCENARIOS ===\n small_config = {\n \"x_range\": [0, 10, 2],\n \"y_range\": [0, 7, 2],\n \"x_length\": 2.8,\n \"y_length\": 1.8,\n \"axis_config\": {\"include_tip\": False},\n \"tips\": False,\n }\n\n # Good Fit\n ax_g = Axes(**small_config)\n g_train = ax_g.plot(lambda x: 6 * math.exp(-0.4 * x) + 1.2, x_range=[0.1, 10], color=BLUE, stroke_width=2.5)\n g_val = ax_g.plot(lambda x: 6.5 * math.exp(-0.35 * x) + 1.5, x_range=[0.1, 10], color=GREEN, stroke_width=2.5)\n g_label = Text(\"Good Fit\", font_size=20, color=GREEN).next_to(ax_g, UP, buff=0.15)\n g_group = VGroup(ax_g, g_train, g_val, g_label)\n\n # Underfitting\n ax_u = Axes(**small_config)\n u_train = ax_u.plot(lambda x: 6 * math.exp(-0.08 * x) + 4, x_range=[0.1, 10], color=BLUE, stroke_width=2.5)\n u_val = ax_u.plot(lambda x: 6.5 * math.exp(-0.08 * x) + 4.3, x_range=[0.1, 10], color=GREEN, stroke_width=2.5)\n u_label = Text(\"Underfitting\", font_size=20, color=YELLOW).next_to(ax_u, UP, buff=0.15)\n u_group = VGroup(ax_u, u_train, u_val, u_label)\n\n # Overfitting\n ax_o = Axes(**small_config)\n o_train = ax_o.plot(lambda x: 6 * math.exp(-0.4 * x) + 1.2, x_range=[0.1, 10], color=BLUE, stroke_width=2.5)\n def o_val(x):\n if x < 4:\n return 6.5 * math.exp(-0.35 * x) + 1.8\n else:\n return (6.5 * math.exp(-0.35 * 4) + 1.8) + 0.18 * (x - 4) ** 1.3\n o_val_curve = ax_o.plot(o_val, x_range=[0.1, 10], color=GREEN, stroke_width=2.5)\n o_label = Text(\"Overfitting\", font_size=20, color=RED).next_to(ax_o, UP, buff=0.15)\n o_group = VGroup(ax_o, o_train, o_val_curve, o_label)\n\n scenarios = VGroup(g_group, u_group, o_group).arrange(RIGHT, buff=0.5)\n scenarios.move_to(ORIGIN)\n if scenarios.get_width() > 12:\n scenarios.scale_to_fit_width(11)\n if scenarios.get_height() > 5.5:\n scenarios.scale_to_fit_height(5)\n scenarios.move_to(ORIGIN)\n\n with self.voiceover(\n text=\"In a good fit, both losses drop and stay close. The model learns patterns that apply to new data.\"\n ) as tracker:\n self.play(Create(ax_g), Create(g_train), Create(g_val), FadeIn(g_label), run_time=tracker.duration)\n\n self.wait(0.2)\n\n with self.voiceover(\n text=\"Underfitting means both curves remain high. The model is too simple to capture the underlying structure.\"\n ) as tracker:\n self.play(Create(ax_u), Create(u_train), Create(u_val), FadeIn(u_label), run_time=tracker.duration)\n\n self.wait(0.2)\n\n with self.voiceover(\n text=\"Overfitting is when training loss keeps falling, but validation loss climbs. The model is memorizing, not generalizing.\"\n ) as tracker:\n self.play(Create(ax_o), Create(o_train), Create(o_val_curve), FadeIn(o_label), run_time=tracker.duration)\n\n self.wait(0.5)\n\n # Legend\n legend_train = Text(\"Training Loss\", font_size=18, color=BLUE)\n legend_val = Text(\"Validation Loss\", font_size=18, color=GREEN)\n legend = VGroup(legend_train, legend_val).arrange(RIGHT, buff=0.8).to_edge(DOWN, buff=0.4)\n\n with self.voiceover(\n text=\"Always watch both curves together. The gap between them reveals the true health of your model.\"\n ) as tracker:\n self.play(FadeIn(legend), run_time=tracker.duration)\n\n self.wait(0.5)\n\n # === TAKEAWAYS ===\n self.play(FadeOut(VGroup(scenarios, legend)))\n\n takeaways = VGroup(\n Text(\"• Identify loss curves to monitor training.\", font_size=22),\n Text(\"• Underfitting = high loss on both sets.\", font_size=22),\n Text(\"• Overfitting = growing gap, validation rises.\", font_size=22),\n ).arrange(DOWN, aligned_edge=LEFT, buff=0.35)\n takeaways.to_edge(LEFT, buff=0.8)\n if takeaways.get_height() > 4.5:\n takeaways.scale_to_fit_height(4)\n\n with self.voiceover(\n text=\"To summarize: you will identify loss curves during model training, differentiate underfitting and overfitting by analyzing their shapes, and understand why both training and validation loss are essential for robust model development.\"\n ) as tracker:\n for item in takeaways:\n self.play(FadeIn(item), run_time=tracker.duration / len(takeaways))\n\n self.wait(1)\n```", "category": "spatial_layout_overlap", "source": "synthetic_hard_neg:nabin2004/AOS-Narrated-Manim-400"} +{"system": "You are an expert Manim Community Edition (ManimCE v0.19+) Python developer and mathematical animator. Given a user request, first plan the spatial layout, coordinate bounds, timing, and pedagogical flow inside ... tags (when reasoning is helpful), and then output a complete, runnable, self-contained ManimCE Python script using `from manim import *`. Never use deprecated ManimGL (`manimlib`) methods like `ShowCreation`, `TexMobject`, `TextMobject`, or `axes.get_graph`; always use modern ManimCE APIs (`Create`, `MathTex`, `Tex`, `Text`, `axes.plot`) and prevent visual overlap using `.to_edge()`, `.next_to()`, and `FadeOut`.", "prompt": "Create a 10-second Manim scene that shows a training loss curve dropping over epochs and flattening near convergence. Include axes, several highlighted checkpoints, and a short caption about diminishing returns.", "chosen": "```python\nfrom manim import *\n\nclass TrainingLossCurve(Scene):\n def construct(self):\n title = Text(\"Training Loss\", font_size=36).to_edge(UP)\n axes = Axes(x_range=[0, 8, 1], y_range=[0, 4.5, 1], x_length=7, y_length=4, tips=False).shift(DOWN * 0.2)\n axis_labels = axes.get_axis_labels(Text(\"epoch\", font_size=22), Text(\"loss\", font_size=22))\n points = [(0, 4.0), (1, 2.8), (2, 1.9), (3, 1.3), (4, 0.95), (5, 0.72), (6, 0.58), (7, 0.50)]\n graph = VMobject(color=BLUE_D, stroke_width=4)\n graph.set_points_smoothly([axes.c2p(x, y) for x, y in points])\n dots = VGroup(*[Dot(axes.c2p(x, y), color=YELLOW_D, radius=0.06) for x, y in points[1::2]])\n plateau = SurroundingRectangle(VGroup(dots[-2], dots[-1]), color=GREEN_D, buff=0.16)\n caption = Text(\"Early updates help most. Later steps still matter, but less.\", font_size=24, color=GRAY_C).to_edge(DOWN)\n self.play(FadeIn(title), Create(axes), FadeIn(axis_labels), run_time=2)\n self.play(Create(graph), run_time=3)\n self.play(LaggedStart(*[FadeIn(dot) for dot in dots], lag_ratio=0.25), run_time=2)\n self.play(Create(plateau), FadeIn(caption), run_time=2)\n self.wait(1)\n```", "rejected": "```python\nfrom manim import *\n\nclass TrainingLossCurve(Scene):\n def construct(self):\n title = Text(\"Training Loss\", font_size=36).to_edge(UP)\n axes = Axes(x_range=[0, 8, 1], y_range=[0, 4.5, 1], x_length=7, y_length=4, tips=False).shift(DOWN * 0.2)\n axis_labels = axes.get_axis_labels(Text(\"epoch\", font_size=22), Text(\"loss\", font_size=22))\n points = [(0, 4.0), (1, 2.8), (2, 1.9), (3, 1.3), (4, 0.95), (5, 0.72), (6, 0.58), (7, 0.50)]\n graph = VMobject(color=BLUE_D, stroke_width=4)\n graph.set_points_smoothly([axes.c2p(x, y) for x, y in points])\n dots = VGroup(*[Dot(axes.c2p(x, y), color=YELLOW_D, radius=0.06) for x, y in points[1::2]])\n plateau = SurroundingRectangle(VGroup(dots[-2], dots[-1]), color=GREEN_D, buff=0.16)\n caption = Text(\"Early updates help most. Later steps still matter, but less.\", font_size=24, color=GRAY_C).to_edge(DOWN)\n self.play(FadeIn(title), ShowCreation(axes), FadeIn(axis_labels), run_time=2)\n self.play(Create(graph), run_time=3)\n self.play(LaggedStart(*[FadeIn(dot) for dot in dots], lag_ratio=0.25), run_time=2)\n self.play(Create(plateau), FadeIn(caption), run_time=2)\n self.wait(1)\n```", "category": "legacy_api_hallucination", "source": "synthetic_hard_neg:sebastianboehler/autoresearch-manim"} +{"system": "You are an expert Manim Community Edition (ManimCE v0.19+) Python developer and mathematical animator. Given a user request, first plan the spatial layout, coordinate bounds, timing, and pedagogical flow inside ... tags (when reasoning is helpful), and then output a complete, runnable, self-contained ManimCE Python script using `from manim import *`. Never use deprecated ManimGL (`manimlib`) methods like `ShowCreation`, `TexMobject`, `TextMobject`, or `axes.get_graph`; always use modern ManimCE APIs (`Create`, `MathTex`, `Tex`, `Text`, `axes.plot`) and prevent visual overlap using `.to_edge()`, `.next_to()`, and `FadeOut`.", "prompt": "Here is the enhanced animation instruction that includes all original features plus significant new elements:\n\nThe enhanced animation begins by displaying the input sequence [1,2,3,4,5] as before, but now each number pulses with a different color as it appears, creating a visual distinction between elements. As the sequence moves to the top, we simultaneously introduce a mathematical formula below it showing the LSTM equations (input, forget, output gates and cell state updates) that fade in sequentially. The neural network construction now includes animated labels for each layer (\"Input\", \"LSTM Cell\", \"Output\") that appear as each layer is drawn. During the forward pass, we add a dynamic visualization where the activation values flow through the network while corresponding numbers appear along the connections showing weight values. When focusing on the LSTM neuron, we enhance this by having its internal structure (gates and cell state) expand into a detailed schematic view that animates the gate operations, with accompanying explanatory text that appears and highlights each component. The transformed output sequence now appears with a smooth morphing animation where each number transforms into its new value, and we add a final comparison visualization that shows both sequences side-by-side with arrows indicating the transformation, along with a concluding text label explaining how the LSTM processed the sequential information. Throughout the animation, we maintain smooth transitions between all elements and ensure visual consistency with color-coding that matches components across different parts of the visualization.", "chosen": "```python\nfrom manim import *\nimport numpy as np\n\nclass EnhancedLSTMAnimation(Scene):\n def construct(self):\n # Colors for different elements\n input_color = BLUE\n lstm_color = GREEN\n output_color = RED\n gate_colors = [YELLOW, PURPLE, ORANGE, PINK]\n \n # Create input sequence with pulsing colors\n input_sequence = [1, 2, 3, 4, 5]\n input_texts = VGroup(*[\n Text(str(num), font_size=36).set_color(color)\n for num, color in zip(input_sequence, [BLUE, GREEN, RED, YELLOW, PURPLE])\n ])\n input_texts.arrange(RIGHT, buff=0.5)\n \n # Animate input sequence appearing with pulsing colors\n for text in input_texts:\n self.play(\n FadeIn(text),\n text.animate.scale(1.2).set_color(WHITE),\n run_time=0.5\n )\n self.play(\n text.animate.scale(1/1.2).set_color(text.get_color()),\n run_time=0.5\n )\n \n # Move input sequence to top\n self.play(input_texts.animate.to_edge(UP))\n \n # Show LSTM equations\n equations = VGroup(\n MathTex(r\"i_t = \\sigma(W_{xi}x_t + W_{hi}h_{t-1} + b_i)\").set_color(gate_colors[0]),\n MathTex(r\"f_t = \\sigma(W_{xf}x_t + W_{hf}h_{t-1} + b_f)\").set_color(gate_colors[1]),\n MathTex(r\"o_t = \\sigma(W_{xo}x_t + W_{ho}h_{t-1} + b_o)\").set_color(gate_colors[2]),\n MathTex(r\"\\tilde{C}_t = \\tanh(W_{xc}x_t + W_{hc}h_{t-1} + b_c)\").set_color(gate_colors[3]),\n MathTex(r\"C_t = f_t \\odot C_{t-1} + i_t \\odot \\tilde{C}_t\").set_color(WHITE),\n MathTex(r\"h_t = o_t \\odot \\tanh(C_t)\").set_color(WHITE)\n )\n equations.arrange(DOWN, buff=0.3, aligned_edge=LEFT)\n equations.next_to(input_texts, DOWN, buff=1)\n \n # Animate equations appearing\n for eq in equations:\n self.play(FadeIn(eq))\n self.wait(0.3)\n \n # Create neural network\n input_layer = Circle(radius=0.5, color=input_color, fill_opacity=0.2)\n lstm_layer = Circle(radius=0.8, color=lstm_color, fill_opacity=0.2)\n output_layer = Circle(radius=0.5, color=output_color, fill_opacity=0.2)\n \n layers = VGroup(input_layer, lstm_layer, output_layer)\n layers.arrange(RIGHT, buff=2)\n layers.next_to(equations, DOWN, buff=1)\n \n # Add layer labels\n layer_labels = VGroup(\n Text(\"Input\").next_to(input_layer, DOWN),\n Text(\"LSTM Cell\").next_to(lstm_layer, DOWN),\n Text(\"Output\").next_to(output_layer, DOWN)\n )\n \n # Draw network with labels appearing\n for i, (layer, label) in enumerate(zip(layers, layer_labels)):\n self.play(\n Create(layer),\n FadeIn(label),\n run_time=0.7\n )\n if i == 1: # LSTM layer\n self.wait(0.5)\n \n # Create connections with weights\n connections = VGroup()\n weight_labels = VGroup()\n \n for i in range(3):\n for j in range(3):\n if i != j and abs(i-j) <= 1:\n start = layers[i].get_right() if i < j else layers[i].get_left()\n end = layers[j].get_left() if i < j else layers[j].get_right()\n connection = Arrow(start, end, buff=0.1, color=WHITE)\n connections.add(connection)\n \n weight = DecimalNumber(np.random.uniform(-1, 1), num_decimal_places=2)\n weight.move_to(connection.get_center())\n weight.scale(0.7)\n weight_labels.add(weight)\n \n # Animate connections and weights\n self.play(LaggedStart(*[Create(c) for c in connections], lag_ratio=0.2))\n self.play(LaggedStart(*[FadeIn(w) for w in weight_labels], lag_ratio=0.2))\n \n # Animate forward pass\n for i, num in enumerate(input_sequence):\n # Highlight input\n input_dot = Dot(input_layer.get_center(), color=input_texts[i].get_color(), radius=0.3)\n self.play(FadeIn(input_dot))\n \n # Flow through connections\n for j, connection in enumerate(connections):\n flow = Dot(color=WHITE, radius=0.1).move_to(connection.get_start())\n self.play(\n MoveAlongPath(flow, connection),\n run_time=0.5\n )\n self.remove(flow)\n \n # Show activation in LSTM\n lstm_activation = Dot(lstm_layer.get_center(), color=lstm_color, radius=0.4)\n self.play(FadeIn(lstm_activation))\n \n # Show output\n output_dot = Dot(output_layer.get_center(), color=output_color, radius=0.3)\n self.play(FadeIn(output_dot))\n \n # Clean up\n self.play(\n FadeOut(input_dot),\n FadeOut(lstm_activation),\n FadeOut(output_dot)\n )\n \n # Focus on LSTM neuron\n self.play(\n layers.animate.scale(1.5).shift(UP*1.5),\n connections.animate.scale(1.5).shift(UP*1.5),\n weight_labels.animate.scale(1.5).shift(UP*1.5),\n layer_labels.animate.scale(1.5).shift(UP*1.5),\n equations.animate.shift(LEFT*2),\n input_texts.animate.shift(UP*0.5)\n )\n \n # Detailed LSTM structure\n lstm_center = lstm_layer.get_center()\n lstm_components = VGroup()\n \n # Gates\n gate_positions = [UP, RIGHT, DOWN, LEFT]\n gates = VGroup()\n gate_names = [\"Input Gate\", \"Forget Gate\", \"Output Gate\", \"Cell State\"]\n \n for i, (pos, color, name) in enumerate(zip(gate_positions, gate_colors, gate_names)):\n gate = Circle(radius=0.4, color=color, fill_opacity=0.2)\n gate.move_to(lstm_center + pos*1.5)\n gate_label = Text(name, font_size=24).next_to(gate, pos)\n gates.add(VGroup(gate, gate_label))\n \n # Connections between gates\n inner_connections = VGroup()\n for i in range(4):\n for j in range(4):\n if i != j:\n inner_connections.add(\n Line(gates[i][0].get_center(), gates[j][0].get_center(), color=WHITE, stroke_width=2)\n )\n \n # Animate detailed structure\n self.play(FadeIn(gates))\n self.play(Create(inner_connections))\n \n # Show gate operations\n for i, (gate, name) in enumerate(zip(gates, gate_names)):\n explanation = Text(f\"{name} operation\", font_size=24).next_to(gates, DOWN)\n self.play(\n gate.animate.scale(1.2),\n FadeIn(explanation)\n )\n self.wait(0.5)\n self.play(\n gate.animate.scale(1/1.2),\n FadeOut(explanation)\n )\n \n # Transform output sequence\n output_sequence = [0.5, 1.5, 2.5, 3.5, 4.5]\n output_texts = VGroup(*[\n Text(str(num), font_size=36).set_color(color)\n for num, color in zip(output_sequence, [BLUE, GREEN, RED, YELLOW, PURPLE])\n ])\n output_texts.arrange(RIGHT, buff=0.5)\n output_texts.next_to(layers, DOWN, buff=1)\n \n # Morph input to output\n for input_text, output_text in zip(input_texts, output_texts):\n output_text.move_to(input_text.get_center())\n self.play(\n Transform(input_text.copy(), output_text),\n run_time=0.7\n )\n \n # Show side-by-side comparison\n comparison_group = VGroup(input_texts.copy(), output_texts.copy())\n comparison_group.arrange(RIGHT, buff=2)\n comparison_group.center()\n \n arrow = Arrow(\n comparison_group[0].get_right(),\n comparison_group[1].get_left(),\n buff=0.2,\n color=WHITE\n )\n \n comparison_label = Text(\"LSTM Transformation\", font_size=32).next_to(comparison_group, UP)\n \n self.play(\n Transform(input_texts.copy(), comparison_group[0]),\n Transform(output_texts.copy(), comparison_group[1]),\n FadeIn(arrow),\n FadeIn(comparison_label)\n )\n \n # Final explanation\n final_text = Text(\n \"The LSTM processed the sequential information\\nusing its gating mechanisms to transform the input\",\n font_size=28\n ).next_to(comparison_group, DOWN)\n \n self.play(FadeIn(final_text))\n self.wait(2)\n```", "rejected": "```python\nfrom manim import *\nimport numpy as np\n\nclass EnhancedLSTMAnimation(Scene):\n def construct(self):\n # Colors for different elements\n input_color = BLUE\n lstm_color = GREEN\n output_color = RED\n gate_colors = [YELLOW, PURPLE, ORANGE, PINK]\n \n # Create input sequence with pulsing colors\n input_sequence = [1, 2, 3, 4, 5]\n input_texts = VGroup(*[\n Text(str(num), font_size=36).set_color(color)\n for num, color in zip(input_sequence, [BLUE, GREEN, RED, YELLOW, PURPLE])\n ])\n input_texts.arrange(RIGHT, buff=0.5)\n \n # Animate input sequence appearing with pulsing colors\n for text in input_texts:\n self.play(\n FadeIn(text),\n text.animate.scale(1.2).set_color(WHITE),\n run_time=0.5\n )\n self.play(\n text.animate.scale(1/1.2).set_color(text.get_color()),\n run_time=0.5\n )\n \n # Move input sequence to top\n self.play(input_texts.animate.to_edge(UP))\n \n # Show LSTM equations\n equations = VGroup(\n TexMobject(r\"i_t = \\sigma(W_{xi}x_t + W_{hi}h_{t-1} + b_i)\").set_color(gate_colors[0]),\n MathTex(r\"f_t = \\sigma(W_{xf}x_t + W_{hf}h_{t-1} + b_f)\").set_color(gate_colors[1]),\n MathTex(r\"o_t = \\sigma(W_{xo}x_t + W_{ho}h_{t-1} + b_o)\").set_color(gate_colors[2]),\n MathTex(r\"\\tilde{C}_t = \\tanh(W_{xc}x_t + W_{hc}h_{t-1} + b_c)\").set_color(gate_colors[3]),\n MathTex(r\"C_t = f_t \\odot C_{t-1} + i_t \\odot \\tilde{C}_t\").set_color(WHITE),\n MathTex(r\"h_t = o_t \\odot \\tanh(C_t)\").set_color(WHITE)\n )\n equations.arrange(DOWN, buff=0.3, aligned_edge=LEFT)\n equations.next_to(input_texts, DOWN, buff=1)\n \n # Animate equations appearing\n for eq in equations:\n self.play(FadeIn(eq))\n self.wait(0.3)\n \n # Create neural network\n input_layer = Circle(radius=0.5, color=input_color, fill_opacity=0.2)\n lstm_layer = Circle(radius=0.8, color=lstm_color, fill_opacity=0.2)\n output_layer = Circle(radius=0.5, color=output_color, fill_opacity=0.2)\n \n layers = VGroup(input_layer, lstm_layer, output_layer)\n layers.arrange(RIGHT, buff=2)\n layers.next_to(equations, DOWN, buff=1)\n \n # Add layer labels\n layer_labels = VGroup(\n Text(\"Input\").next_to(input_layer, DOWN),\n Text(\"LSTM Cell\").next_to(lstm_layer, DOWN),\n Text(\"Output\").next_to(output_layer, DOWN)\n )\n \n # Draw network with labels appearing\n for i, (layer, label) in enumerate(zip(layers, layer_labels)):\n self.play(\n ShowCreation(layer),\n FadeIn(label),\n run_time=0.7\n )\n if i == 1: # LSTM layer\n self.wait(0.5)\n \n # Create connections with weights\n connections = VGroup()\n weight_labels = VGroup()\n \n for i in range(3):\n for j in range(3):\n if i != j and abs(i-j) <= 1:\n start = layers[i].get_right() if i < j else layers[i].get_left()\n end = layers[j].get_left() if i < j else layers[j].get_right()\n connection = Arrow(start, end, buff=0.1, color=WHITE)\n connections.add(connection)\n \n weight = DecimalNumber(np.random.uniform(-1, 1), num_decimal_places=2)\n weight.move_to(connection.get_center())\n weight.scale(0.7)\n weight_labels.add(weight)\n \n # Animate connections and weights\n self.play(LaggedStart(*[Create(c) for c in connections], lag_ratio=0.2))\n self.play(LaggedStart(*[FadeIn(w) for w in weight_labels], lag_ratio=0.2))\n \n # Animate forward pass\n for i, num in enumerate(input_sequence):\n # Highlight input\n input_dot = Dot(input_layer.get_center(), color=input_texts[i].get_color(), radius=0.3)\n self.play(FadeIn(input_dot))\n \n # Flow through connections\n for j, connection in enumerate(connections):\n flow = Dot(color=WHITE, radius=0.1).move_to(connection.get_start())\n self.play(\n MoveAlongPath(flow, connection),\n run_time=0.5\n )\n self.remove(flow)\n \n # Show activation in LSTM\n lstm_activation = Dot(lstm_layer.get_center(), color=lstm_color, radius=0.4)\n self.play(FadeIn(lstm_activation))\n \n # Show output\n output_dot = Dot(output_layer.get_center(), color=output_color, radius=0.3)\n self.play(FadeIn(output_dot))\n \n # Clean up\n self.play(\n FadeOut(input_dot),\n FadeOut(lstm_activation),\n FadeOut(output_dot)\n )\n \n # Focus on LSTM neuron\n self.play(\n layers.animate.scale(1.5).shift(UP*1.5),\n connections.animate.scale(1.5).shift(UP*1.5),\n weight_labels.animate.scale(1.5).shift(UP*1.5),\n layer_labels.animate.scale(1.5).shift(UP*1.5),\n equations.animate.shift(LEFT*2),\n input_texts.animate.shift(UP*0.5)\n )\n \n # Detailed LSTM structure\n lstm_center = lstm_layer.get_center()\n lstm_components = VGroup()\n \n # Gates\n gate_positions = [UP, RIGHT, DOWN, LEFT]\n gates = VGroup()\n gate_names = [\"Input Gate\", \"Forget Gate\", \"Output Gate\", \"Cell State\"]\n \n for i, (pos, color, name) in enumerate(zip(gate_positions, gate_colors, gate_names)):\n gate = Circle(radius=0.4, color=color, fill_opacity=0.2)\n gate.move_to(lstm_center + pos*1.5)\n gate_label = Text(name, font_size=24).next_to(gate, pos)\n gates.add(VGroup(gate, gate_label))\n \n # Connections between gates\n inner_connections = VGroup()\n for i in range(4):\n for j in range(4):\n if i != j:\n inner_connections.add(\n Line(gates[i][0].get_center(), gates[j][0].get_center(), color=WHITE, stroke_width=2)\n )\n \n # Animate detailed structure\n self.play(FadeIn(gates))\n self.play(Create(inner_connections))\n \n # Show gate operations\n for i, (gate, name) in enumerate(zip(gates, gate_names)):\n explanation = Text(f\"{name} operation\", font_size=24).next_to(gates, DOWN)\n self.play(\n gate.animate.scale(1.2),\n FadeIn(explanation)\n )\n self.wait(0.5)\n self.play(\n gate.animate.scale(1/1.2),\n FadeOut(explanation)\n )\n \n # Transform output sequence\n output_sequence = [0.5, 1.5, 2.5, 3.5, 4.5]\n output_texts = VGroup(*[\n Text(str(num), font_size=36).set_color(color)\n for num, color in zip(output_sequence, [BLUE, GREEN, RED, YELLOW, PURPLE])\n ])\n output_texts.arrange(RIGHT, buff=0.5)\n output_texts.next_to(layers, DOWN, buff=1)\n \n # Morph input to output\n for input_text, output_text in zip(input_texts, output_texts):\n output_text.move_to(input_text.get_center())\n self.play(\n Transform(input_text.copy(), output_text),\n run_time=0.7\n )\n \n # Show side-by-side comparison\n comparison_group = VGroup(input_texts.copy(), output_texts.copy())\n comparison_group.arrange(RIGHT, buff=2)\n comparison_group.center()\n \n arrow = Arrow(\n comparison_group[0].get_right(),\n comparison_group[1].get_left(),\n buff=0.2,\n color=WHITE\n )\n \n comparison_label = Text(\"LSTM Transformation\", font_size=32).next_to(comparison_group, UP)\n \n self.play(\n Transform(input_texts.copy(), comparison_group[0]),\n Transform(output_texts.copy(), comparison_group[1]),\n FadeIn(arrow),\n FadeIn(comparison_label)\n )\n \n # Final explanation\n final_text = Text(\n \"The LSTM processed the sequential information\\nusing its gating mechanisms to transform the input\",\n font_size=28\n ).next_to(comparison_group, DOWN)\n \n self.play(FadeIn(final_text))\n self.wait(2)\n```", "category": "legacy_api_hallucination", "source": "synthetic_hard_neg:nabin2004/manim-sft-10k"} +{"system": "You are an expert Manim Community Edition (ManimCE v0.19+) Python developer and mathematical animator. Given a user request, first plan the spatial layout, coordinate bounds, timing, and pedagogical flow inside ... tags (when reasoning is helpful), and then output a complete, runnable, self-contained ManimCE Python script using `from manim import *`. Never use deprecated ManimGL (`manimlib`) methods like `ShowCreation`, `TexMobject`, `TextMobject`, or `axes.get_graph`; always use modern ManimCE APIs (`Create`, `MathTex`, `Tex`, `Text`, `axes.plot`) and prevent visual overlap using `.to_edge()`, `.next_to()`, and `FadeOut`.", "prompt": "The following Manim CE scene failed to compile. Truncated traceback:\n\nTypeError: Animation only works on Mobjects\n\nFix the code. Return a complete working scene. Do not keep the invalid constructor kwargs or Unicode subscripts.\n\n```python\nfrom manim import *\n\nclass TripleIntegralExample(Scene):\n def construct(self):\n self.play(1.5)\n # Displaying the problem\n problem = MathTex(r\"\\iiint_V xyz \\,dx\\,dy\\,dz\")\n self.play(Write(problem))\n self.wait(1)\n\n # Explanation for innermost integral\n explanation1 = Text(\"Integrate with respect to x\", font_size=24).to_edge(UP)\n self.play(Write(explanation1))\n self.wait(2)\n\n # Innermost integral step\n innermost_integral = MathTex(r\"= \\iint_V \\frac{1}{2}x^2yz \\,dy\\,dz\")\n self.play(ReplacementTransform(problem.copy(), innermost_integral))\n self.wait(1)\n\n # Explanation for middle integral\n explanation2 = Text(\"Now, integrate with respect to y\", font_size=24).to_edge(UP)\n self.play(Transform(explanation1, explanation2))\n self.wait(2)\n\n # Middle integral step\n middle_integral = MathTex(r\"= \\int_V \\frac{1}{2}x^2\\frac{1}{2}y^2z \\,dz\")\n self.play(ReplacementTransform(innermost_integral, middle_integral))\n self.wait(1)\n\n # Explanation for outermost integral\n explanation3 = Text(\"Finally, integrate with respect to z\", font_size=24).to_edge(UP)\n self.play(Transform(explanation1, explanation3))\n self.wait(2)\n\n # Outermost integral step and final solution\n final_solution = MathTex(r\"= \\frac{1}{4}x^2y^2\\frac{1}{2}z^2\\Big|_V\")\n self.play(ReplacementTransform(middle_integral, final_solution))\n self.wait(1)\n\n # Clear the scene and end\n self.clear()\n self.wait(1)\n self.play(Write(final_solution))\n self.wait(1)\n```", "chosen": "```python\nfrom manim import *\n\nclass TripleIntegralExample(Scene):\n def construct(self):\n # Displaying the problem\n problem = MathTex(r\"\\iiint_V xyz \\,dx\\,dy\\,dz\")\n self.play(Write(problem))\n self.wait(1)\n\n # Explanation for innermost integral\n explanation1 = Text(\"Integrate with respect to x\", font_size=24).to_edge(UP)\n self.play(Write(explanation1))\n self.wait(2)\n\n # Innermost integral step\n innermost_integral = MathTex(r\"= \\iint_V \\frac{1}{2}x^2yz \\,dy\\,dz\")\n self.play(ReplacementTransform(problem.copy(), innermost_integral))\n self.wait(1)\n\n # Explanation for middle integral\n explanation2 = Text(\"Now, integrate with respect to y\", font_size=24).to_edge(UP)\n self.play(Transform(explanation1, explanation2))\n self.wait(2)\n\n # Middle integral step\n middle_integral = MathTex(r\"= \\int_V \\frac{1}{2}x^2\\frac{1}{2}y^2z \\,dz\")\n self.play(ReplacementTransform(innermost_integral, middle_integral))\n self.wait(1)\n\n # Explanation for outermost integral\n explanation3 = Text(\"Finally, integrate with respect to z\", font_size=24).to_edge(UP)\n self.play(Transform(explanation1, explanation3))\n self.wait(2)\n\n # Outermost integral step and final solution\n final_solution = MathTex(r\"= \\frac{1}{4}x^2y^2\\frac{1}{2}z^2\\Big|_V\")\n self.play(ReplacementTransform(middle_integral, final_solution))\n self.wait(1)\n\n # Clear the scene and end\n self.clear()\n self.wait(1)\n self.play(Write(final_solution))\n self.wait(1)\n```", "rejected": "```python\nfrom manim import *\n\nclass TripleIntegralExample(Scene):\n def construct(self):\n # Displaying the problem\n problem = TexMobject(r\"\\iiint_V xyz \\,dx\\,dy\\,dz\")\n self.play(Write(problem))\n self.wait(1)\n\n # Explanation for innermost integral\n explanation1 = Text(\"Integrate with respect to x\", font_size=24).to_edge(UP)\n self.play(Write(explanation1))\n self.wait(2)\n\n # Innermost integral step\n innermost_integral = MathTex(r\"= \\iint_V \\frac{1}{2}x^2yz \\,dy\\,dz\")\n self.play(ReplacementTransform(problem.copy(), innermost_integral))\n self.wait(1)\n\n # Explanation for middle integral\n explanation2 = Text(\"Now, integrate with respect to y\", font_size=24).to_edge(UP)\n self.play(Transform(explanation1, explanation2))\n self.wait(2)\n\n # Middle integral step\n middle_integral = MathTex(r\"= \\int_V \\frac{1}{2}x^2\\frac{1}{2}y^2z \\,dz\")\n self.play(ReplacementTransform(innermost_integral, middle_integral))\n self.wait(1)\n\n # Explanation for outermost integral\n explanation3 = Text(\"Finally, integrate with respect to z\", font_size=24).to_edge(UP)\n self.play(Transform(explanation1, explanation3))\n self.wait(2)\n\n # Outermost integral step and final solution\n final_solution = MathTex(r\"= \\frac{1}{4}x^2y^2\\frac{1}{2}z^2\\Big|_V\")\n self.play(ReplacementTransform(middle_integral, final_solution))\n self.wait(1)\n\n # Clear the scene and end\n self.clear()\n self.wait(1)\n self.play(Write(final_solution))\n self.wait(1)\n```", "category": "legacy_api_hallucination", "source": "synthetic_hard_neg:nabin2004/manim-sft-10k"} +{"system": "You are an expert Manim Community Edition (ManimCE v0.19+) Python developer and mathematical animator. Given a user request, first plan the spatial layout, coordinate bounds, timing, and pedagogical flow inside ... tags (when reasoning is helpful), and then output a complete, runnable, self-contained ManimCE Python script using `from manim import *`. Never use deprecated ManimGL (`manimlib`) methods like `ShowCreation`, `TexMobject`, `TextMobject`, or `axes.get_graph`; always use modern ManimCE APIs (`Create`, `MathTex`, `Tex`, `Text`, `axes.plot`) and prevent visual overlap using `.to_edge()`, `.next_to()`, and `FadeOut`.", "prompt": "I'm learning undergraduate linear algebra and want a visual intuition for eigenvalues and eigenvectors. Animate a 3×3 matrix acting on vectors, showing how the transformation stretches along eigenvectors and rotates elsewhere. Include a demonstration of the power method: animate repeated applications to show convergence to the dominant eigenvector, with the eigenvalues displayed. Show two scenes: a global 3D view of the matrix action and a focused view on the invariant directions, plus a side panel that updates the eigenvalues as the scene evolves. I'd like smooth camera motion, transitions between scenes, and annotations explaining the geometry and the intuition behind diagonalization.", "chosen": "```python\nfrom manim import *\nfrom manim_voiceover import VoiceoverScene\nfrom manim_voiceover.services.gtts import GTTSService\n\nclass EigenvaluesPowerMethod(ThreeDScene, VoiceoverScene):\n def construct(self):\n # [SETUP]\n # [LAYOUT]\n self.set_camera_orientation(phi=70 * DEGREES, theta=-45 * DEGREES)\n self.set_speech_service(GTTSService(transcription_model=\"base\"))\n\n # [BEAT 1 | sync: VECTORS]\n with self.voiceover(text=\"Let's explore how a three by three matrix transforms vectors in 3D space. Most vectors change both direction and magnitude.\") as tracker:\n axes = ThreeDAxes()\n v1 = Arrow3D(ORIGIN, [1, 1, 1], color=BLUE)\n v2 = Arrow3D(ORIGIN, [2, 0, 1], color=GREEN)\n v3 = Arrow3D(ORIGIN, [0, 2, 1], color=RED)\n self.wait_until_bookmark(\"VECTORS\")\n self.play(Create(axes), Create(v1), Create(v2), Create(v3), run_time=tracker.duration)\n\n with self.voiceover(text=\"The power method reveals the dominant eigenvector. By repeatedly applying the matrix, any vector converges to the direction of the largest eigenvalue.\") as tracker:\n dominant = Arrow3D(ORIGIN, [2, 2, 1], color=YELLOW, thickness=0.06)\n self.wait_until_bookmark(\"POWER\")\n self.play(FadeOut(v2), FadeOut(v3), run_time=0.5)\n self.play(Transform(v1, dominant), run_time=tracker.duration * 0.5)\n \n eigen_label = MathTex(\"\\\\lambda_1 = 3.0\", font_size=36, color=YELLOW)\n self.fit_in_frame(eigen_label)\n self.add_fixed_in_frame_mobjects(eigen_label)\n eigen_label.to_corner(UR)\n self.play(Write(eigen_label), run_time=tracker.duration * 0.5)\n\n with self.voiceover(text=\"This is the geometric essence of diagonalization. In the eigenbasis, the matrix acts as a simple scaling along each axis.\") as tracker:\n eq = MathTex(\"A = Q \\\\Lambda Q^{-1}\", font_size=40)\n self.add_fixed_in_frame_mobjects(eq)\n eq.to_corner(UL)\n self.wait_until_bookmark(\"DIAG\")\n self.play(Write(eq), run_time=tracker.duration)\n self.begin_ambient_camera_rotation(rate=0.1)\n self.wait(1)\n\n def fit_in_frame(self, mob: Mobject, w_frac: float = 0.9, h_frac: float = 0.9) -> Mobject:\n max_w = config.frame_width * w_frac\n max_h = config.frame_height * h_frac\n if mob.width > max_w:\n mob.width = max_w\n if mob.height > max_h:\n mob.height = max_h\n return mob\n```", "rejected": "```python\nfrom manim import *\nfrom manim_voiceover import VoiceoverScene\nfrom manim_voiceover.services.gtts import GTTSService\n\nclass EigenvaluesPowerMethod(ThreeDScene, VoiceoverScene):\n def construct(self):\n # [SETUP]\n # [LAYOUT]\n self.set_camera_orientation(phi=70 * DEGREES, theta=-45 * DEGREES)\n self.set_speech_service(GTTSService(transcription_model=\"base\"))\n\n # [BEAT 1 | sync: VECTORS]\n with self.voiceover(text=\"Let's explore how a three by three matrix transforms vectors in 3D space. Most vectors change both direction and magnitude.\") as tracker:\n axes = ThreeDAxes()\n v1 = Arrow3D(ORIGIN, [1, 1, 1], color=BLUE)\n v2 = Arrow3D(ORIGIN, [2, 0, 1], color=GREEN)\n v3 = Arrow3D(ORIGIN, [0, 2, 1], color=RED)\n self.wait_until_bookmark(\"VECTORS\")\n self.play(ShowCreation(axes), Create(v1), Create(v2), Create(v3), run_time=tracker.duration)\n\n with self.voiceover(text=\"The power method reveals the dominant eigenvector. By repeatedly applying the matrix, any vector converges to the direction of the largest eigenvalue.\") as tracker:\n dominant = Arrow3D(ORIGIN, [2, 2, 1], color=YELLOW, thickness=0.06)\n self.wait_until_bookmark(\"POWER\")\n self.play(FadeOut(v2), FadeOut(v3), run_time=0.5)\n self.play(Transform(v1, dominant), run_time=tracker.duration * 0.5)\n \n eigen_label = TexMobject(\"\\\\lambda_1 = 3.0\", font_size=36, color=YELLOW)\n self.fit_in_frame(eigen_label)\n self.add_fixed_in_frame_mobjects(eigen_label)\n eigen_label.to_corner(UR)\n self.play(Write(eigen_label), run_time=tracker.duration * 0.5)\n\n with self.voiceover(text=\"This is the geometric essence of diagonalization. In the eigenbasis, the matrix acts as a simple scaling along each axis.\") as tracker:\n eq = MathTex(\"A = Q \\\\Lambda Q^{-1}\", font_size=40)\n self.add_fixed_in_frame_mobjects(eq)\n eq.to_corner(UL)\n self.wait_until_bookmark(\"DIAG\")\n self.play(Write(eq), run_time=tracker.duration)\n self.begin_ambient_camera_rotation(rate=0.1)\n self.wait(1)\n\n def fit_in_frame(self, mob: Mobject, w_frac: float = 0.9, h_frac: float = 0.9) -> Mobject:\n max_w = config.frame_width * w_frac\n max_h = config.frame_height * h_frac\n if mob.width > max_w:\n mob.width = max_w\n if mob.height > max_h:\n mob.height = max_h\n return mob\n```", "category": "legacy_api_hallucination", "source": "synthetic_hard_neg:nabin2004/qwen3-8b-manimator-gold-sft"} +{"system": "You are an expert Manim Community Edition (ManimCE v0.19+) Python developer and mathematical animator. Given a user request, first plan the spatial layout, coordinate bounds, timing, and pedagogical flow inside ... tags (when reasoning is helpful), and then output a complete, runnable, self-contained ManimCE Python script using `from manim import *`. Never use deprecated ManimGL (`manimlib`) methods like `ShowCreation`, `TexMobject`, `TextMobject`, or `axes.get_graph`; always use modern ManimCE APIs (`Create`, `MathTex`, `Tex`, `Text`, `axes.plot`) and prevent visual overlap using `.to_edge()`, `.next_to()`, and `FadeOut`.", "prompt": "What are the implications of reducing a planar graph into its minimal triangulated form regarding edge connectivity and planarity?", "chosen": "```python\nfrom manim import *\n\nclass GraphTriangulationScene(Scene):\n def construct(self):\n # Introduction with title\n title = Text(\"The Beauty of Triangulation\", font_size=38)\n subtitle = Text(\"Unlocking Planar Graph Secrets\", font_size=24)\n subtitle.next_to(title, DOWN)\n \n self.play(Write(title))\n self.play(FadeIn(subtitle))\n self.wait(1)\n self.play(FadeOut(title), FadeOut(subtitle))\n \n # Create a simple planar graph\n # First, create vertices as dots\n vertices = []\n positions = [\n [-2, -1, 0], [0, -2, 0], [2, -1, 0], \n [1, 1, 0], [-1, 1, 0]\n ]\n \n for pos in positions:\n vertices.append(Dot(point=np.array(pos)))\n \n # Create edges as lines connecting the vertices\n edge_pairs = [\n (0, 1), (1, 2), (2, 3), (3, 4), (4, 0)\n ]\n \n edges = []\n for pair in edge_pairs:\n edges.append(Line(\n vertices[pair[0]].get_center(),\n vertices[pair[1]].get_center()\n ))\n \n # Group vertices and edges into a graph\n graph = VGroup(*vertices, *edges)\n \n # Show the graph being built\n intro_text = Text(\"A simple planar graph\", font_size=32).to_edge(UP)\n self.play(Write(intro_text))\n self.play(Create(graph))\n self.wait(1)\n \n # Highlight non-triangular areas with red\n self.play(FadeOut(intro_text))\n non_triangular_text = Text(\"Non-triangular face\", font_size=32).to_edge(UP)\n self.play(Write(non_triangular_text))\n \n # Create a polygon to highlight the non-triangular face\n face = Polygon(\n vertices[0].get_center(),\n vertices[1].get_center(),\n vertices[2].get_center(),\n vertices[3].get_center(),\n vertices[4].get_center(),\n color=RED,\n fill_opacity=0.2\n )\n \n self.play(Create(face))\n self.wait(1)\n \n # Add new edges to triangulate the graph\n self.play(FadeOut(non_triangular_text))\n triangulation_text = Text(\"Adding edges to triangulate\", font_size=32).to_edge(UP)\n self.play(Write(triangulation_text))\n \n # Add diagonal edges (in blue) to create triangles\n new_edge_pairs = [(0, 2), (0, 3)]\n new_edges = []\n \n for pair in new_edge_pairs:\n new_edge = Line(\n vertices[pair[0]].get_center(),\n vertices[pair[1]].get_center(),\n color=BLUE\n )\n new_edges.append(new_edge)\n self.play(Create(new_edge))\n \n # Highlight the newly formed triangle in green\n triangle_vertices = []\n if pair == (0, 2):\n triangle_vertices = [0, 1, 2]\n elif pair == (0, 3):\n triangle_vertices = [0, 3, 4]\n \n if triangle_vertices:\n triangle = Polygon(\n vertices[triangle_vertices[0]].get_center(),\n vertices[triangle_vertices[1]].get_center(),\n vertices[triangle_vertices[2]].get_center(),\n color=GREEN,\n fill_opacity=0.2\n )\n self.play(Create(triangle))\n self.wait(0.5)\n self.play(FadeOut(triangle))\n \n self.wait(1)\n \n # Show Euler's formula for planar graphs\n self.play(FadeOut(triangulation_text), FadeOut(face))\n equation_text = Text(\"Euler's Formula for Planar Graphs\", font_size=28).to_edge(UP)\n self.play(Write(equation_text))\n \n eq = MathTex(\"E = F + V - 2\")\n eq_description = Text(\"Edges = Faces + Vertices - 2\", font_size=20)\n eq_description.next_to(eq, DOWN)\n \n self.play(Write(eq))\n self.play(Write(eq_description))\n self.wait(1)\n \n # Conclusion and final thoughts\n self.play(\n FadeOut(equation_text), \n FadeOut(eq), \n FadeOut(eq_description), \n FadeOut(graph), \n FadeOut(VGroup(*new_edges))\n )\n \n conclusion_text = Text(\"Graph triangulation enhances connectivity\\nwhile preserving planarity\", font_size=32)\n final_text = Text(\"Redefining complexity into simplicity\", font_size=24)\n final_text.next_to(conclusion_text, DOWN, buff=0.5)\n \n self.play(Write(conclusion_text))\n self.wait(0.5)\n self.play(Write(final_text))\n self.wait(2)\n self.play(FadeOut(conclusion_text), FadeOut(final_text))\n```", "rejected": "```python\nfrom manim import *\n\nclass GraphTriangulationScene(Scene):\n def construct(self):\n # Introduction with title\n title = Text(\"The Beauty of Triangulation\", font_size=38)\n subtitle = Text(\"Unlocking Planar Graph Secrets\", font_size=24)\n subtitle.next_to(title, DOWN)\n \n self.play(Write(title))\n self.play(FadeIn(subtitle))\n self.wait(1)\n self.play(FadeOut(title), FadeOut(subtitle))\n \n # Create a simple planar graph\n # First, create vertices as dots\n vertices = []\n positions = [\n [-2, -1, 0], [0, -2, 0], [2, -1, 0], \n [1, 1, 0], [-1, 1, 0]\n ]\n \n for pos in positions:\n vertices.append(Dot(point=np.array(pos)))\n \n # Create edges as lines connecting the vertices\n edge_pairs = [\n (0, 1), (1, 2), (2, 3), (3, 4), (4, 0)\n ]\n \n edges = []\n for pair in edge_pairs:\n edges.append(Line(\n vertices[pair[0]].get_center(),\n vertices[pair[1]].get_center()\n ))\n \n # Group vertices and edges into a graph\n graph = VGroup(*vertices, *edges)\n \n # Show the graph being built\n intro_text = Text(\"A simple planar graph\", font_size=32).to_edge(UP)\n self.play(Write(intro_text))\n self.play(ShowCreation(graph))\n self.wait(1)\n \n # Highlight non-triangular areas with red\n self.play(FadeOut(intro_text))\n non_triangular_text = Text(\"Non-triangular face\", font_size=32).to_edge(UP)\n self.play(Write(non_triangular_text))\n \n # Create a polygon to highlight the non-triangular face\n face = Polygon(\n vertices[0].get_center(),\n vertices[1].get_center(),\n vertices[2].get_center(),\n vertices[3].get_center(),\n vertices[4].get_center(),\n color=RED,\n fill_opacity=0.2\n )\n \n self.play(Create(face))\n self.wait(1)\n \n # Add new edges to triangulate the graph\n self.play(FadeOut(non_triangular_text))\n triangulation_text = Text(\"Adding edges to triangulate\", font_size=32).to_edge(UP)\n self.play(Write(triangulation_text))\n \n # Add diagonal edges (in blue) to create triangles\n new_edge_pairs = [(0, 2), (0, 3)]\n new_edges = []\n \n for pair in new_edge_pairs:\n new_edge = Line(\n vertices[pair[0]].get_center(),\n vertices[pair[1]].get_center(),\n color=BLUE\n )\n new_edges.append(new_edge)\n self.play(Create(new_edge))\n \n # Highlight the newly formed triangle in green\n triangle_vertices = []\n if pair == (0, 2):\n triangle_vertices = [0, 1, 2]\n elif pair == (0, 3):\n triangle_vertices = [0, 3, 4]\n \n if triangle_vertices:\n triangle = Polygon(\n vertices[triangle_vertices[0]].get_center(),\n vertices[triangle_vertices[1]].get_center(),\n vertices[triangle_vertices[2]].get_center(),\n color=GREEN,\n fill_opacity=0.2\n )\n self.play(Create(triangle))\n self.wait(0.5)\n self.play(FadeOut(triangle))\n \n self.wait(1)\n \n # Show Euler's formula for planar graphs\n self.play(FadeOut(triangulation_text), FadeOut(face))\n equation_text = Text(\"Euler's Formula for Planar Graphs\", font_size=28).to_edge(UP)\n self.play(Write(equation_text))\n \n eq = TexMobject(\"E = F + V - 2\")\n eq_description = Text(\"Edges = Faces + Vertices - 2\", font_size=20)\n eq_description.next_to(eq, DOWN)\n \n self.play(Write(eq))\n self.play(Write(eq_description))\n self.wait(1)\n \n # Conclusion and final thoughts\n self.play(\n FadeOut(equation_text), \n FadeOut(eq), \n FadeOut(eq_description), \n FadeOut(graph), \n FadeOut(VGroup(*new_edges))\n )\n \n conclusion_text = Text(\"Graph triangulation enhances connectivity\\nwhile preserving planarity\", font_size=32)\n final_text = Text(\"Redefining complexity into simplicity\", font_size=24)\n final_text.next_to(conclusion_text, DOWN, buff=0.5)\n \n self.play(Write(conclusion_text))\n self.wait(0.5)\n self.play(Write(final_text))\n self.wait(2)\n self.play(FadeOut(conclusion_text), FadeOut(final_text))\n```", "category": "legacy_api_hallucination", "source": "synthetic_hard_neg:nabin2004/manim-sft-10k"} +{"system": "You are an expert Manim Community Edition (ManimCE v0.19+) Python developer and mathematical animator. Given a user request, first plan the spatial layout, coordinate bounds, timing, and pedagogical flow inside ... tags (when reasoning is helpful), and then output a complete, runnable, self-contained ManimCE Python script using `from manim import *`. Never use deprecated ManimGL (`manimlib`) methods like `ShowCreation`, `TexMobject`, `TextMobject`, or `axes.get_graph`; always use modern ManimCE APIs (`Create`, `MathTex`, `Tex`, `Text`, `axes.plot`) and prevent visual overlap using `.to_edge()`, `.next_to()`, and `FadeOut`.", "prompt": "The following Manim CE scene failed to compile. Truncated traceback:\n\nTypeError: Mobject.__init__() got an unexpected keyword argument 'max_magnitude'\n\nFix the code. Return a complete working scene. Do not keep the invalid constructor kwargs or Unicode subscripts.\n\n```python\nfrom manim import *\n\nclass FourierSeriesExample(Scene):\n def construct(self):\n bad = ArrowVectorField(lambda p: p, max_magnitude=2)\n # Display Fourier Series definition\n fourier_series_def = MathTex(\n r\"f(x) = a_0 + \\sum_{n=1}^{\\infty} \\left(a_n \\cos\\left(\\frac{2\\pi n x}{P}\\right) + b_n \\sin\\left(\\frac{2\\pi n x}{P}\\right)\\right)\"\n )\n self.play(Write(fourier_series_def))\n self.wait(2)\n\n # Explanation about Fourier Series\n explanation1 = Text(\n \"A Fourier series is a way to represent a function as a sum of sinusoidal bases.\",\n font_size=24,\n ).to_edge(UP)\n self.play(Write(explanation1))\n self.wait(3)\n\n # Specific example with a square wave\n explanation2 = Text(\n \"For example, a square wave can be approximated by a Fourier series.\",\n font_size=24,\n ).to_edge(UP)\n self.play(Transform(explanation1, explanation2))\n self.wait(3)\n\n # Display the square wave approximation equation\n square_wave_approx = MathTex(\n r\"f(x) \\approx \\sum_{n=1,3,5}^{\\infty} \\frac{4}{n\\pi} \\sin\\left(\\frac{2\\pi n x}{P}\\right)\"\n )\n self.play(ReplacementTransform(fourier_series_def, square_wave_approx))\n self.wait(2)\n\n # Explanation for convergence\n explanation3 = Text(\n \"The series converges to the actual function as the number of terms increases.\",\n font_size=24,\n ).to_edge(UP)\n self.play(Transform(explanation1, explanation3))\n self.wait(3)\n\n # Clear the scene and conclude\n self.clear()\n self.wait(1)\n self.play(Write(square_wave_approx))\n self.wait(1)\n```", "chosen": "```python\nfrom manim import *\n\nclass FourierSeriesExample(Scene):\n def construct(self):\n # Display Fourier Series definition\n fourier_series_def = MathTex(\n r\"f(x) = a_0 + \\sum_{n=1}^{\\infty} \\left(a_n \\cos\\left(\\frac{2\\pi n x}{P}\\right) + b_n \\sin\\left(\\frac{2\\pi n x}{P}\\right)\\right)\"\n )\n self.play(Write(fourier_series_def))\n self.wait(2)\n\n # Explanation about Fourier Series\n explanation1 = Text(\n \"A Fourier series is a way to represent a function as a sum of sinusoidal bases.\",\n font_size=24,\n ).to_edge(UP)\n self.play(Write(explanation1))\n self.wait(3)\n\n # Specific example with a square wave\n explanation2 = Text(\n \"For example, a square wave can be approximated by a Fourier series.\",\n font_size=24,\n ).to_edge(UP)\n self.play(Transform(explanation1, explanation2))\n self.wait(3)\n\n # Display the square wave approximation equation\n square_wave_approx = MathTex(\n r\"f(x) \\approx \\sum_{n=1,3,5}^{\\infty} \\frac{4}{n\\pi} \\sin\\left(\\frac{2\\pi n x}{P}\\right)\"\n )\n self.play(ReplacementTransform(fourier_series_def, square_wave_approx))\n self.wait(2)\n\n # Explanation for convergence\n explanation3 = Text(\n \"The series converges to the actual function as the number of terms increases.\",\n font_size=24,\n ).to_edge(UP)\n self.play(Transform(explanation1, explanation3))\n self.wait(3)\n\n # Clear the scene and conclude\n self.clear()\n self.wait(1)\n self.play(Write(square_wave_approx))\n self.wait(1)\n```", "rejected": "```python\nfrom manim import *\n\nclass FourierSeriesExample(Scene):\n def construct(self):\n # Display Fourier Series definition\n fourier_series_def = MathTex(\n r\"f(x) = a_0 + \\sum_{n=1}^{\\infty} \\left(a_n \\cos\\left(\\frac{2\\pi n x}{P}\\right) + b_n \\sin\\left(\\frac{2\\pi n x}{P}\\right)\\right)\"\n )\n self.play(Write(fourier_series_def))\n self.wait(2)\n\n # Explanation about Fourier Series\n explanation1 = Text(\n \"A Fourier series is a way to represent a function as a sum of sinusoidal bases.\",\n font_size=24,\n )\n self.play(Write(explanation1))\n self.wait(3)\n\n # Specific example with a square wave\n explanation2 = Text(\n \"For example, a square wave can be approximated by a Fourier series.\",\n font_size=24,\n )\n self.play(Transform(explanation1, explanation2))\n self.wait(3)\n\n # Display the square wave approximation equation\n square_wave_approx = MathTex(\n r\"f(x) \\approx \\sum_{n=1,3,5}^{\\infty} \\frac{4}{n\\pi} \\sin\\left(\\frac{2\\pi n x}{P}\\right)\"\n )\n self.play(ReplacementTransform(fourier_series_def, square_wave_approx))\n self.wait(2)\n\n # Explanation for convergence\n explanation3 = Text(\n \"The series converges to the actual function as the number of terms increases.\",\n font_size=24,\n )\n self.play(Transform(explanation1, explanation3))\n self.wait(3)\n\n # Clear the scene and conclude\n self.clear()\n self.wait(1)\n self.play(Write(square_wave_approx))\n self.wait(1)\n```", "category": "spatial_layout_overlap", "source": "synthetic_hard_neg:nabin2004/manim-sft-10k"} +{"system": "You are an expert Manim Community Edition (ManimCE v0.19+) Python developer and mathematical animator. Given a user request, first plan the spatial layout, coordinate bounds, timing, and pedagogical flow inside ... tags (when reasoning is helpful), and then output a complete, runnable, self-contained ManimCE Python script using `from manim import *`. Never use deprecated ManimGL (`manimlib`) methods like `ShowCreation`, `TexMobject`, `TextMobject`, or `axes.get_graph`; always use modern ManimCE APIs (`Create`, `MathTex`, `Tex`, `Text`, `axes.plot`) and prevent visual overlap using `.to_edge()`, `.next_to()`, and `FadeOut`.", "prompt": "Can you create an animated visualization of the bubble sort algorithm using colored bars where the height of each bar represents a different value in an array? The animation should show the swapping process of the bars as they are being sorted in ascending order.", "chosen": "```python\nfrom manim import *\n\nclass HarmonicOscillatorScene(Scene):\n def construct(self):\n # Displaying the ODE\n ode = MathTex(r\"m \\frac{d^2x}{dt^2} + b \\frac{dx}{dt} + kx = 0\")\n self.play(Write(ode))\n self.wait(1)\n\n # Explanation of the physical context\n explanation1 = Text(\"Damped Harmonic Oscillator\", font_size=24).to_edge(UP)\n self.play(Write(explanation1))\n self.wait(2)\n\n # Explanation for the associate characteristic equation\n explanation2 = Text(\"Associated characteristic equation\", font_size=24).to_edge(UP)\n self.play(Transform(explanation1, explanation2))\n self.wait(1)\n\n # Writing the characteristic equation\n char_eq = MathTex(r\"mr^2 + br + k = 0\")\n self.play(ReplacementTransform(ode.copy(), char_eq))\n self.wait(2)\n\n # Calculate the roots of the characteristic equation\n roots_title = Text(\"Roots of the characteristic equation\", font_size=24).to_edge(UP)\n self.play(Transform(explanation1, roots_title))\n roots = MathTex(r\"r = \\frac{-b \\pm \\sqrt{b^2 - 4mk}}{2m}\")\n self.play(ReplacementTransform(char_eq, roots))\n self.wait(2)\n\n # Display the general solution depending on the discriminant\n solution_title = Text(\"General solution depends on the discriminant\", font_size=24).to_edge(UP)\n self.play(Transform(explanation1, solution_title))\n different_cases = VGroup(\n MathTex(r\"\\text{If } \\Delta > 0: x(t) = C_1 e^{r_1 t} + C_2 e^{r_2 t}\"),\n MathTex(r\"\\text{If } \\Delta = 0: x(t) = (C_1 + C_2 t) e^{-bt / 2m}\"),\n MathTex(r\"\\text{If } \\Delta < 0: x(t) = e^{-bt / 2m}(C_1 \\cos{\\omega t} + C_2 \\sin{\\omega t})\")\n ).arrange(DOWN, aligned_edge=LEFT, buff=0.5)\n\n self.play(Write(different_cases))\n self.wait(2)\n\n # Clear scene and conclude with the case of critical damping\n self.clear()\n self.wait(1)\n crit_damping = Text(\"Case of critical damping (\\\\(\\\\Delta = 0\\\\))\", font_size=24)\n crit_solution = MathTex(r\"x(t) = (C_1 + C_2 t) e^{-bt / 2m}\")\n self.play(Write(crit_damping))\n self.wait(1)\n self.play(Write(crit_solution))\n self.wait(2)\n```", "rejected": "```python\nfrom manim import *\n\nclass HarmonicOscillatorScene(Scene):\n def construct(self):\n # Displaying the ODE\n ode = TexMobject(r\"m \\frac{d^2x}{dt^2} + b \\frac{dx}{dt} + kx = 0\")\n self.play(Write(ode))\n self.wait(1)\n\n # Explanation of the physical context\n explanation1 = Text(\"Damped Harmonic Oscillator\", font_size=24).to_edge(UP)\n self.play(Write(explanation1))\n self.wait(2)\n\n # Explanation for the associate characteristic equation\n explanation2 = Text(\"Associated characteristic equation\", font_size=24).to_edge(UP)\n self.play(Transform(explanation1, explanation2))\n self.wait(1)\n\n # Writing the characteristic equation\n char_eq = MathTex(r\"mr^2 + br + k = 0\")\n self.play(ReplacementTransform(ode.copy(), char_eq))\n self.wait(2)\n\n # Calculate the roots of the characteristic equation\n roots_title = Text(\"Roots of the characteristic equation\", font_size=24).to_edge(UP)\n self.play(Transform(explanation1, roots_title))\n roots = MathTex(r\"r = \\frac{-b \\pm \\sqrt{b^2 - 4mk}}{2m}\")\n self.play(ReplacementTransform(char_eq, roots))\n self.wait(2)\n\n # Display the general solution depending on the discriminant\n solution_title = Text(\"General solution depends on the discriminant\", font_size=24).to_edge(UP)\n self.play(Transform(explanation1, solution_title))\n different_cases = VGroup(\n MathTex(r\"\\text{If } \\Delta > 0: x(t) = C_1 e^{r_1 t} + C_2 e^{r_2 t}\"),\n MathTex(r\"\\text{If } \\Delta = 0: x(t) = (C_1 + C_2 t) e^{-bt / 2m}\"),\n MathTex(r\"\\text{If } \\Delta < 0: x(t) = e^{-bt / 2m}(C_1 \\cos{\\omega t} + C_2 \\sin{\\omega t})\")\n ).arrange(DOWN, aligned_edge=LEFT, buff=0.5)\n\n self.play(Write(different_cases))\n self.wait(2)\n\n # Clear scene and conclude with the case of critical damping\n self.clear()\n self.wait(1)\n crit_damping = Text(\"Case of critical damping (\\\\(\\\\Delta = 0\\\\))\", font_size=24)\n crit_solution = MathTex(r\"x(t) = (C_1 + C_2 t) e^{-bt / 2m}\")\n self.play(Write(crit_damping))\n self.wait(1)\n self.play(Write(crit_solution))\n self.wait(2)\n```", "category": "legacy_api_hallucination", "source": "synthetic_hard_neg:nabin2004/manim-sft-10k"} +{"system": "You are an expert Manim Community Edition (ManimCE v0.19+) Python developer and mathematical animator. Given a user request, first plan the spatial layout, coordinate bounds, timing, and pedagogical flow inside ... tags (when reasoning is helpful), and then output a complete, runnable, self-contained ManimCE Python script using `from manim import *`. Never use deprecated ManimGL (`manimlib`) methods like `ShowCreation`, `TexMobject`, `TextMobject`, or `axes.get_graph`; always use modern ManimCE APIs (`Create`, `MathTex`, `Tex`, `Text`, `axes.plot`) and prevent visual overlap using `.to_edge()`, `.next_to()`, and `FadeOut`.", "prompt": "How does Zorn's Lemma assist in proving Tychonoff's theorem in topology?", "chosen": "```python\nfrom manim import *\n\nclass ZornsLemmaTychonoffTheorem(Scene):\n def construct(self):\n # Introduction scene - Title\n title = Text(\"Tying Topology: Zorn's Lemma & Tychonoff's Theorem\", font_size=32)\n self.play(Write(title))\n self.wait(1)\n self.play(FadeOut(title))\n \n # Element 1: Visualizing abstract algebra and topology symbols\n algebra_text = Text(\"Abstract Algebra\", font_size=28).shift(UP)\n topology_text = Text(\"Topology\", font_size=28).shift(DOWN)\n \n self.play(\n FadeIn(algebra_text, shift=UP),\n FadeIn(topology_text, shift=DOWN)\n )\n self.wait(0.5)\n \n # Element 2: Compact topological spaces as bubbles\n self.play(\n FadeOut(algebra_text),\n FadeOut(topology_text)\n )\n \n compact_spaces_text = Text(\"Compact Topological Spaces\", font_size=28).to_edge(UP)\n self.play(Write(compact_spaces_text))\n \n # Create four circles representing compact spaces\n bubbles = VGroup(*[\n Circle(radius=0.3, color=BLUE, fill_opacity=0.3).shift(\n RIGHT * 1.5 * i - 2.25 * RIGHT\n ) for i in range(4)\n ])\n \n # Label each compact space\n bubble_labels = VGroup(*[\n Text(f\"X{i+1}\", font_size=20).move_to(bubbles[i])\n for i in range(4)\n ])\n \n self.play(\n Create(bubbles),\n Write(bubble_labels)\n )\n self.wait(1)\n \n # Element 3: Infinite product space visualization\n product_text = Text(\"Product Space\", font_size=28)\n self.play(\n FadeOut(compact_spaces_text),\n Write(product_text)\n )\n self.play(product_text.animate.to_edge(UP))\n \n # Rearrange the spaces into a grid to represent a product\n self.play(\n bubbles.animate.arrange_in_grid(2, 2, buff=0.5).move_to(ORIGIN)\n )\n self.play(FadeOut(bubble_labels))\n \n # Display the product notation\n product_formula = Text(\"∏ Xi for all i in I\", font_size=24).next_to(bubbles, DOWN, buff=0.5)\n self.play(Write(product_formula))\n self.wait(1)\n \n # Element 4: Zorn's Lemma visualization\n self.play(\n FadeOut(product_text),\n FadeOut(product_formula)\n )\n \n zorns_title = Text(\"Zorn's Lemma\", font_size=28).to_edge(UP)\n zorns_desc = Text(\"Every chain has an upper bound\", font_size=22).next_to(zorns_title, DOWN)\n \n self.play(\n Write(zorns_title),\n Write(zorns_desc)\n )\n \n # Arrow pointing to the product space\n arrow = Arrow(zorns_desc.get_bottom() + DOWN * 0.2, bubbles.get_center() + UP * 0.5, buff=0.2, color=YELLOW)\n self.play(GrowArrow(arrow))\n self.wait(1)\n \n # Element 5: Finite subcovers\n self.play(\n FadeOut(zorns_title),\n FadeOut(zorns_desc),\n FadeOut(arrow)\n )\n \n subcovers_text = Text(\"Finite Subcovers\", font_size=28).to_edge(UP)\n self.play(Write(subcovers_text))\n \n # Create colored rectangles to highlight subsets of the product space\n # Calculate positions manually for top-left and bottom-right quadrants\n top_left_pos = (bubbles[0].get_center() + bubbles[1].get_center()) / 2\n bottom_right_pos = (bubbles[2].get_center() + bubbles[3].get_center()) / 2\n \n rect1 = Rectangle(\n width=1.5, \n height=1.5, \n color=RED, \n fill_opacity=0.2\n ).move_to(top_left_pos)\n \n rect2 = Rectangle(\n width=1.5, \n height=1.5, \n color=GREEN, \n fill_opacity=0.2\n ).move_to(bottom_right_pos)\n \n self.play(Create(rect1))\n self.wait(0.5)\n self.play(Create(rect2))\n self.wait(1)\n \n # Element 6: Transformation to a single compact space\n self.play(\n FadeOut(subcovers_text),\n FadeOut(rect1),\n FadeOut(rect2)\n )\n \n result_text = Text(\"Compact Product Space\", font_size=28).to_edge(UP)\n self.play(Write(result_text))\n \n # Transform the grid of bubbles into a single large bubble\n big_bubble = Circle(radius=1.5, color=PURPLE, fill_opacity=0.3)\n self.play(Transform(bubbles, big_bubble))\n self.wait(1)\n \n # Tychonoff's Theorem\n self.play(\n FadeOut(result_text),\n FadeOut(bubbles)\n )\n \n tychonoff_title = Text(\"Tychonoff's Theorem\", font_size=28).to_edge(UP)\n tychonoff_formula = Text(\"Product of compact spaces is compact\", font_size=24)\n \n self.play(\n Write(tychonoff_title),\n Write(tychonoff_formula)\n )\n self.wait(1)\n \n # Conclusion: Zorn's Lemma helps prove Tychonoff's Theorem\n self.play(\n FadeOut(tychonoff_title),\n FadeOut(tychonoff_formula)\n )\n \n conclusion = Text(\"Zorn's Lemma enables us to prove\\nTychonoff's Theorem by handling\\ninfinite products of compact spaces\", \n font_size=28, line_spacing=1)\n \n self.play(Write(conclusion))\n self.wait(2)\n self.play(FadeOut(conclusion))\n```", "rejected": "```python\nfrom manim import *\n\nclass ZornsLemmaTychonoffTheorem(Scene):\n def construct(self):\n # Introduction scene - Title\n title = Text(\"Tying Topology: Zorn's Lemma & Tychonoff's Theorem\", font_size=32)\n self.play(Write(title))\n self.wait(1)\n self.play(FadeOut(title))\n \n # Element 1: Visualizing abstract algebra and topology symbols\n algebra_text = Text(\"Abstract Algebra\", font_size=28).shift(UP)\n topology_text = Text(\"Topology\", font_size=28).shift(DOWN)\n \n self.play(\n FadeIn(algebra_text, shift=UP),\n FadeIn(topology_text, shift=DOWN)\n )\n self.wait(0.5)\n \n # Element 2: Compact topological spaces as bubbles\n self.play(\n FadeOut(algebra_text),\n FadeOut(topology_text)\n )\n \n compact_spaces_text = Text(\"Compact Topological Spaces\", font_size=28).to_edge(UP)\n self.play(Write(compact_spaces_text))\n \n # Create four circles representing compact spaces\n bubbles = VGroup(*[\n Circle(radius=0.3, color=BLUE, fill_opacity=0.3).shift(\n RIGHT * 1.5 * i - 2.25 * RIGHT\n ) for i in range(4)\n ])\n \n # Label each compact space\n bubble_labels = VGroup(*[\n Text(f\"X{i+1}\", font_size=20).move_to(bubbles[i])\n for i in range(4)\n ])\n \n self.play(\n ShowCreation(bubbles),\n Write(bubble_labels)\n )\n self.wait(1)\n \n # Element 3: Infinite product space visualization\n product_text = Text(\"Product Space\", font_size=28)\n self.play(\n FadeOut(compact_spaces_text),\n Write(product_text)\n )\n self.play(product_text.animate.to_edge(UP))\n \n # Rearrange the spaces into a grid to represent a product\n self.play(\n bubbles.animate.arrange_in_grid(2, 2, buff=0.5).move_to(ORIGIN)\n )\n self.play(FadeOut(bubble_labels))\n \n # Display the product notation\n product_formula = Text(\"∏ Xi for all i in I\", font_size=24).next_to(bubbles, DOWN, buff=0.5)\n self.play(Write(product_formula))\n self.wait(1)\n \n # Element 4: Zorn's Lemma visualization\n self.play(\n FadeOut(product_text),\n FadeOut(product_formula)\n )\n \n zorns_title = Text(\"Zorn's Lemma\", font_size=28).to_edge(UP)\n zorns_desc = Text(\"Every chain has an upper bound\", font_size=22).next_to(zorns_title, DOWN)\n \n self.play(\n Write(zorns_title),\n Write(zorns_desc)\n )\n \n # Arrow pointing to the product space\n arrow = Arrow(zorns_desc.get_bottom() + DOWN * 0.2, bubbles.get_center() + UP * 0.5, buff=0.2, color=YELLOW)\n self.play(GrowArrow(arrow))\n self.wait(1)\n \n # Element 5: Finite subcovers\n self.play(\n FadeOut(zorns_title),\n FadeOut(zorns_desc),\n FadeOut(arrow)\n )\n \n subcovers_text = Text(\"Finite Subcovers\", font_size=28).to_edge(UP)\n self.play(Write(subcovers_text))\n \n # Create colored rectangles to highlight subsets of the product space\n # Calculate positions manually for top-left and bottom-right quadrants\n top_left_pos = (bubbles[0].get_center() + bubbles[1].get_center()) / 2\n bottom_right_pos = (bubbles[2].get_center() + bubbles[3].get_center()) / 2\n \n rect1 = Rectangle(\n width=1.5, \n height=1.5, \n color=RED, \n fill_opacity=0.2\n ).move_to(top_left_pos)\n \n rect2 = Rectangle(\n width=1.5, \n height=1.5, \n color=GREEN, \n fill_opacity=0.2\n ).move_to(bottom_right_pos)\n \n self.play(Create(rect1))\n self.wait(0.5)\n self.play(Create(rect2))\n self.wait(1)\n \n # Element 6: Transformation to a single compact space\n self.play(\n FadeOut(subcovers_text),\n FadeOut(rect1),\n FadeOut(rect2)\n )\n \n result_text = Text(\"Compact Product Space\", font_size=28).to_edge(UP)\n self.play(Write(result_text))\n \n # Transform the grid of bubbles into a single large bubble\n big_bubble = Circle(radius=1.5, color=PURPLE, fill_opacity=0.3)\n self.play(Transform(bubbles, big_bubble))\n self.wait(1)\n \n # Tychonoff's Theorem\n self.play(\n FadeOut(result_text),\n FadeOut(bubbles)\n )\n \n tychonoff_title = Text(\"Tychonoff's Theorem\", font_size=28).to_edge(UP)\n tychonoff_formula = Text(\"Product of compact spaces is compact\", font_size=24)\n \n self.play(\n Write(tychonoff_title),\n Write(tychonoff_formula)\n )\n self.wait(1)\n \n # Conclusion: Zorn's Lemma helps prove Tychonoff's Theorem\n self.play(\n FadeOut(tychonoff_title),\n FadeOut(tychonoff_formula)\n )\n \n conclusion = Text(\"Zorn's Lemma enables us to prove\\nTychonoff's Theorem by handling\\ninfinite products of compact spaces\", \n font_size=28, line_spacing=1)\n \n self.play(Write(conclusion))\n self.wait(2)\n self.play(FadeOut(conclusion))\n```", "category": "legacy_api_hallucination", "source": "synthetic_hard_neg:nabin2004/manim-sft-10k"} +{"system": "You are an expert Manim Community Edition (ManimCE v0.19+) Python developer and mathematical animator. Given a user request, first plan the spatial layout, coordinate bounds, timing, and pedagogical flow inside ... tags (when reasoning is helpful), and then output a complete, runnable, self-contained ManimCE Python script using `from manim import *`. Never use deprecated ManimGL (`manimlib`) methods like `ShowCreation`, `TexMobject`, `TextMobject`, or `axes.get_graph`; always use modern ManimCE APIs (`Create`, `MathTex`, `Tex`, `Text`, `axes.plot`) and prevent visual overlap using `.to_edge()`, `.next_to()`, and `FadeOut`.", "prompt": "I'm exploring affine transformations. Show a 2D grid of feature points, then apply scale (zoom) and translate (shift) as an affine transform, with before/after frames and a small matrix decomposition visualization explaining how the transform is composed.", "chosen": "```python\nfrom manim import *\nfrom manim_voiceover import VoiceoverScene\nfrom manim_voiceover.services.gtts import GTTSService\n\n\nclass AffineTransformationScene(VoiceoverScene):\n def construct(self):\n self.set_speech_service(\n GTTSService(voice=\"alba\", cache_dir=\"voiceover_cache\")\n )\n \n # Title Section\n with self.voiceover(text=\"Imagine you're trying to reshape an object while keeping its essential structure intact. How do you stretch, compress, rotate, or translate without distorting your image? Welcome to the world of affine transformations!\") as tracker:\n title = Text(\"Affine Transformations\", font_size=48, color=BLUE)\n subtitle = Text(\"in Geometry\", font_size=32, color=YELLOW)\n subtitle.next_to(title, DOWN)\n title_group = VGroup(title, subtitle)\n title_group.center()\n \n self.play(Write(title), run_time=tracker.duration * 0.6)\n self.play(FadeIn(subtitle), run_time=tracker.duration * 0.4)\n \n self.wait(0.5)\n \n # Clear and move to definition\n self.play(FadeOut(title_group))\n \n # Definition Section\n with self.voiceover(text=\"An affine transformation is a combination of a linear transformation followed by a translation. It preserves lines and parallelism, making it essential in geometry, computer graphics, and image processing.\") as tracker:\n definition_title = Text(\"What is an Affine Transformation?\", font_size=36, color=GREEN)\n definition_title.to_edge(UP, buff=0.5)\n \n definition_text = VGroup(\n Text(\"- A transformation that preserves:\", font_size=24),\n Text(\" - Lines and straightness\", font_size=22),\n Text(\" - Parallelism\", font_size=22),\n Text(\" - Ratios of distances\", font_size=22),\n Text(\"- Combines linear transformation + translation\", font_size=24)\n ).arrange(DOWN, aligned_edge=LEFT, buff=0.3)\n definition_text.next_to(definition_title, DOWN, buff=0.5)\n \n self.play(Write(definition_title), run_time=tracker.duration * 0.3)\n self.play(FadeIn(definition_text), run_time=tracker.duration * 0.7)\n \n self.wait(0.5)\n self.play(FadeOut(definition_title), FadeOut(definition_text))\n \n # The Formula Section\n with self.voiceover(text=\"The mathematical formula for an affine transformation is T of x equals A times x plus b. Here, A is a matrix representing the linear transformation, and b is a translation vector.\") as tracker:\n formula_title = Text(\"The Affine Transformation Formula\", font_size=36, color=BLUE)\n formula_title.to_edge(UP, buff=0.5)\n \n # Main formula - simplified\n formula = MathTex(r\"T(x) = Ax + b\", font_size=48)\n formula.next_to(formula_title, DOWN, buff=0.8)\n \n # Explanation\n explanation = VGroup(\n Text(\"A = Linear transformation matrix\", font_size=26),\n Text(\"x = Input vector\", font_size=26),\n Text(\"b = Translation vector\", font_size=26)\n ).arrange(DOWN, buff=0.3)\n explanation.next_to(formula, DOWN, buff=0.8)\n \n self.play(Write(formula_title), run_time=tracker.duration * 0.2)\n self.play(Write(formula), run_time=tracker.duration * 0.4)\n self.play(FadeIn(explanation), run_time=tracker.duration * 0.4)\n \n self.wait(0.5)\n self.play(FadeOut(formula_title), FadeOut(formula), FadeOut(explanation))\n \n # Matrix Representation\n with self.voiceover(text=\"In two dimensions, the matrix A has the form a, b; c, d. This matrix can represent scaling, rotation, shearing, or any combination of these operations.\") as tracker:\n matrix_title = Text(\"Matrix Representation\", font_size=36, color=GREEN)\n matrix_title.to_edge(UP, buff=0.5)\n \n matrix = MathTex(r\"A = [[a, b], [c, d]]\", font_size=40)\n matrix.next_to(matrix_title, DOWN, buff=0.8)\n \n # 2D transformation equation - simplified\n transform_eq = MathTex(r\"[x', y'] = A[x, y] + [bx, by]\", font_size=36)\n transform_eq.next_to(matrix, DOWN, buff=0.8)\n \n self.play(Write(matrix_title), run_time=tracker.duration * 0.2)\n self.play(Write(matrix), run_time=tracker.duration * 0.4)\n self.play(Write(transform_eq), run_time=tracker.duration * 0.4)\n \n self.wait(0.5)\n self.play(FadeOut(matrix_title), FadeOut(matrix), FadeOut(transform_eq))\n \n # Types of Affine Transformations\n with self.voiceover(text=\"There are four fundamental types of affine transformations: translation, which moves objects; scaling, which stretches or compresses; rotation, which turns objects; and shearing, which slants them.\") as tracker:\n types_title = Text(\"Types of Affine Transformations\", font_size=36, color=BLUE)\n types_title.to_edge(UP, buff=0.3)\n \n # Create four transformation types in a 2x2 grid\n translations = VGroup(\n VGroup(\n Text(\"Translation\", font_size=24, color=YELLOW),\n MathTex(r\"[[1, 0], [0, 1]]\", font_size=28),\n Text(\"+ shift\", font_size=20)\n ).arrange(DOWN, buff=0.2),\n VGroup(\n Text(\"Scaling\", font_size=24, color=RED),\n MathTex(r\"[[sx, 0], [0, sy]]\", font_size=28),\n Text(\"stretch/compress\", font_size=20)\n ).arrange(DOWN, buff=0.2),\n VGroup(\n Text(\"Rotation\", font_size=24, color=GREEN),\n MathTex(r\"[[cos, -sin], [sin, cos]]\", font_size=22),\n Text(\"turn\", font_size=20)\n ).arrange(DOWN, buff=0.2),\n VGroup(\n Text(\"Shearing\", font_size=24, color=PURPLE),\n MathTex(r\"[[1, k], [0, 1]]\", font_size=28),\n Text(\"slant\", font_size=20)\n ).arrange(DOWN, buff=0.2)\n ).arrange_in_grid(rows=2, cols=2, buff=1.0)\n types_group = VGroup(types_title, translations)\n types_group.center()\n types_title.to_edge(UP, buff=0.3)\n \n self.play(Write(types_title), run_time=tracker.duration * 0.2)\n for trans in translations:\n self.play(FadeIn(trans), run_time=tracker.duration * 0.2)\n \n self.wait(0.5)\n self.play(FadeOut(types_group))\n \n # Demonstration with a square\n with self.voiceover(text=\"Let us see these transformations in action. We will apply different affine transformations to a square and observe how it changes.\") as tracker:\n demo_title = Text(\"Transformation Demonstration\", font_size=36, color=BLUE)\n demo_title.to_edge(UP, buff=0.3)\n self.play(Write(demo_title), run_time=tracker.duration * 0.3)\n \n # Create original square\n square = Square(side_length=1.5, color=WHITE, fill_opacity=0.3)\n square.shift(LEFT * 3)\n \n label_orig = Text(\"Original\", font_size=20)\n label_orig.next_to(square, DOWN)\n \n self.play(Create(square), Write(label_orig), run_time=tracker.duration * 0.35)\n \n # Scaling transformation\n square_scaled = Square(side_length=1.5, color=RED, fill_opacity=0.3)\n square_scaled.stretch(1.5, 0) # Scale x by 1.5\n square_scaled.stretch(0.8, 1) # Scale y by 0.8\n square_scaled.shift(RIGHT * 0.5)\n \n label_scaled = Text(\"Scaled\", font_size=20, color=RED)\n label_scaled.next_to(square_scaled, DOWN)\n \n self.play(\n TransformFromCopy(square, square_scaled),\n Write(label_scaled),\n run_time=tracker.duration * 0.35\n )\n \n self.wait(0.5)\n \n # Continue with rotation and translation\n with self.voiceover(text=\"Now watch as we rotate the square by 45 degrees and then translate it to a new position.\") as tracker:\n # Rotation\n square_rotated = Square(side_length=1.5, color=GREEN, fill_opacity=0.3)\n square_rotated.rotate(PI/4)\n square_rotated.shift(RIGHT * 3)\n \n label_rotated = Text(\"Rotated\", font_size=20, color=GREEN)\n label_rotated.next_to(square_rotated, DOWN)\n \n self.play(\n TransformFromCopy(square, square_rotated),\n Write(label_rotated),\n run_time=tracker.duration * 0.5\n )\n \n # Translation (move original to new position)\n square_translated = Square(side_length=1.5, color=YELLOW, fill_opacity=0.3)\n square_translated.shift(RIGHT * 3 + UP * 2)\n \n label_translated = Text(\"Translated\", font_size=20, color=YELLOW)\n label_translated.next_to(square_translated, DOWN)\n \n self.play(\n TransformFromCopy(square, square_translated),\n Write(label_translated),\n run_time=tracker.duration * 0.5\n )\n \n self.wait(0.5)\n self.play(\n FadeOut(demo_title), FadeOut(square), FadeOut(label_orig),\n FadeOut(square_scaled), FadeOut(label_scaled),\n FadeOut(square_rotated), FadeOut(label_rotated),\n FadeOut(square_translated), FadeOut(label_translated)\n )\n \n # Key Properties Summary\n with self.voiceover(text=\"Key properties of affine transformations include: they preserve straight lines, parallelism is maintained, the origin may not stay fixed, and ratios of lengths along parallel lines are preserved.\") as tracker:\n summary_title = Text(\"Key Properties\", font_size=36, color=GREEN)\n summary_title.to_edge(UP, buff=0.5)\n \n properties = VGroup(\n Text(\"Preserves straight lines\", font_size=26),\n Text(\"Preserves parallelism\", font_size=26),\n Text(\"Origin may move (unlike linear)\", font_size=26),\n Text(\"Preserves ratios of lengths on parallel lines\", font_size=26),\n Text(\"Composition of affines is affine\", font_size=26)\n ).arrange(DOWN, aligned_edge=LEFT, buff=0.4)\n properties.next_to(summary_title, DOWN, buff=0.6)\n \n # Add a box around the properties\n box = SurroundingRectangle(properties, buff=0.3, color=YELLOW)\n \n self.play(Write(summary_title), run_time=tracker.duration * 0.2)\n self.play(FadeIn(properties), Create(box), run_time=tracker.duration * 0.8)\n \n self.wait(0.5)\n self.play(FadeOut(summary_title), FadeOut(properties), FadeOut(box))\n \n # Applications\n with self.voiceover(text=\"Affine transformations have wide applications in computer graphics for image manipulation, in robotics for coordinate transformations, in physics for changing reference frames, and in data science for normalization.\") as tracker:\n apps_title = Text(\"Applications\", font_size=36, color=BLUE)\n apps_title.to_edge(UP, buff=0.5)\n \n applications = VGroup(\n Text(\"- Computer Graphics: Image manipulation\", font_size=24),\n Text(\"- Robotics: Coordinate transformations\", font_size=24),\n Text(\"- Physics: Reference frame changes\", font_size=24),\n Text(\"- Data Science: Data normalization\", font_size=24),\n Text(\"- Computer Vision: Image registration\", font_size=24)\n ).arrange(DOWN, aligned_edge=LEFT, buff=0.35)\n applications.next_to(apps_title, DOWN, buff=0.6)\n \n self.play(Write(apps_title), run_time=tracker.duration * 0.2)\n self.play(FadeIn(applications), run_time=tracker.duration * 0.8)\n \n self.wait(0.5)\n self.play(FadeOut(apps_title), FadeOut(applications))\n \n # Final Summary\n with self.voiceover(text=\"To summarize: affine transformations combine linear transformations with translations. They preserve lines and parallelism while allowing scaling, rotation, shearing, and translation. The formula T of x equals A x plus b captures this elegant mathematical concept.\") as tracker:\n final_title = Text(\"Summary\", font_size=40, color=YELLOW)\n final_title.to_edge(UP, buff=0.5)\n \n final_formula = MathTex(r\"T(x) = Ax + b\", font_size=44)\n final_formula.next_to(final_title, DOWN, buff=0.6)\n \n key_points = VGroup(\n Text(\"Linear transformation + Translation\", font_size=26),\n Text(\"Preserves lines and parallelism\", font_size=26),\n Text(\"Fundamental in geometry and graphics\", font_size=26)\n ).arrange(DOWN, buff=0.3)\n key_points.next_to(final_formula, DOWN, buff=0.6)\n \n self.play(Write(final_title), run_time=tracker.duration * 0.2)\n self.play(Write(final_formula), run_time=tracker.duration * 0.4)\n self.play(FadeIn(key_points), run_time=tracker.duration * 0.4)\n \n self.wait(1)\n self.play(FadeOut(final_title), FadeOut(final_formula), FadeOut(key_points))\n \n # End screen\n end_text = Text(\"Thank you for learning!\", font_size=40, color=BLUE)\n end_text2 = Text(\"Affine Transformations in Geometry\", font_size=28, color=WHITE)\n end_group = VGroup(end_text, end_text2).arrange(DOWN, buff=0.5)\n end_group.center()\n \n self.play(Write(end_group))\n self.wait(2)\n self.play(FadeOut(end_group))\n```", "rejected": "```python\nfrom manim import *\n\nclass AffineTransformationScene(Scene):\n\n def construct(self):\n title = Text('Affine Transformations', font_size=48, color=BLUE)\n subtitle = Text('in Geometry', font_size=32, color=YELLOW)\n subtitle.next_to(title, DOWN)\n title_group = VGroup(title, subtitle)\n title_group.center()\n self.play(Write(title), run_time=2.0 * 0.6)\n self.play(FadeIn(subtitle), run_time=2.0 * 0.4)\n self.wait(0.5)\n self.play(FadeOut(title_group))\n definition_title = Text('What is an Affine Transformation?', font_size=36, color=GREEN)\n definition_title.to_edge(UP, buff=0.5)\n definition_text = VGroup(Text('- A transformation that preserves:', font_size=24), Text(' - Lines and straightness', font_size=22), Text(' - Parallelism', font_size=22), Text(' - Ratios of distances', font_size=22), Text('- Combines linear transformation + translation', font_size=24)).arrange(DOWN, aligned_edge=LEFT, buff=0.3)\n definition_text.next_to(definition_title, DOWN, buff=0.5)\n self.play(Write(definition_title), run_time=2.0 * 0.3)\n self.play(FadeIn(definition_text), run_time=2.0 * 0.7)\n self.wait(0.5)\n self.play(FadeOut(definition_title), FadeOut(definition_text))\n formula_title = Text('The Affine Transformation Formula', font_size=36, color=BLUE)\n formula_title.to_edge(UP, buff=0.5)\n formula = MathTex('T(x) = Ax + b', font_size=48)\n formula.next_to(formula_title, DOWN, buff=0.8)\n explanation = VGroup(Text('A = Linear transformation matrix', font_size=26), Text('x = Input vector', font_size=26), Text('b = Translation vector', font_size=26)).arrange(DOWN, buff=0.3)\n explanation.next_to(formula, DOWN, buff=0.8)\n self.play(Write(formula_title), run_time=2.0 * 0.2)\n self.play(Write(formula), run_time=2.0 * 0.4)\n self.play(FadeIn(explanation), run_time=2.0 * 0.4)\n self.wait(0.5)\n self.play(FadeOut(formula_title), FadeOut(formula), FadeOut(explanation))\n matrix_title = Text('Matrix Representation', font_size=36, color=GREEN)\n matrix_title.to_edge(UP, buff=0.5)\n matrix = MathTex('A = [[a, b], [c, d]]', font_size=40)\n matrix.next_to(matrix_title, DOWN, buff=0.8)\n transform_eq = MathTex(\"[x', y'] = A[x, y] + [bx, by]\", font_size=36)\n transform_eq.next_to(matrix, DOWN, buff=0.8)\n self.play(Write(matrix_title), run_time=2.0 * 0.2)\n self.play(Write(matrix), run_time=2.0 * 0.4)\n self.play(Write(transform_eq), run_time=2.0 * 0.4)\n self.wait(0.5)\n self.play(FadeOut(matrix_title), FadeOut(matrix), FadeOut(transform_eq))\n types_title = Text('Types of Affine Transformations', font_size=36, color=BLUE)\n types_title.to_edge(UP, buff=0.3)\n translations = VGroup(VGroup(Text('Translation', font_size=24, color=YELLOW), MathTex('[[1, 0], [0, 1]]', font_size=28), Text('+ shift', font_size=20)).arrange(DOWN, buff=0.2), VGroup(Text('Scaling', font_size=24, color=RED), MathTex('[[sx, 0], [0, sy]]', font_size=28), Text('stretch/compress', font_size=20)).arrange(DOWN, buff=0.2), VGroup(Text('Rotation', font_size=24, color=GREEN), MathTex('[[cos, -sin], [sin, cos]]', font_size=22), Text('turn', font_size=20)).arrange(DOWN, buff=0.2), VGroup(Text('Shearing', font_size=24, color=PURPLE), MathTex('[[1, k], [0, 1]]', font_size=28), Text('slant', font_size=20)).arrange(DOWN, buff=0.2)).arrange_in_grid(rows=2, cols=2, buff=1.0)\n types_group = VGroup(types_title, translations)\n types_group.center()\n types_title.to_edge(UP, buff=0.3)\n self.play(Write(types_title), run_time=2.0 * 0.2)\n for trans in translations:\n self.play(FadeIn(trans), run_time=2.0 * 0.2)\n self.wait(0.5)\n self.play(FadeOut(types_group))\n demo_title = Text('Transformation Demonstration', font_size=36, color=BLUE)\n demo_title.to_edge(UP, buff=0.3)\n self.play(Write(demo_title), run_time=2.0 * 0.3)\n square = Square(side_length=1.5, color=WHITE, fill_opacity=0.3)\n square.shift(LEFT * 3)\n label_orig = Text('Original', font_size=20)\n label_orig.next_to(square, DOWN)\n self.play(Create(square), Write(label_orig), run_time=2.0 * 0.35)\n square_scaled = Square(side_length=1.5, color=RED, fill_opacity=0.3)\n square_scaled.stretch(1.5, 0)\n square_scaled.stretch(0.8, 1)\n square_scaled.shift(RIGHT * 0.5)\n label_scaled = Text('Scaled', font_size=20, color=RED)\n label_scaled.next_to(square_scaled, DOWN)\n self.play(TransformFromCopy(square, square_scaled), Write(label_scaled), run_time=2.0 * 0.35)\n self.wait(0.5)\n square_rotated = Square(side_length=1.5, color=GREEN, fill_opacity=0.3)\n square_rotated.rotate(PI / 4)\n square_rotated.shift(RIGHT * 3)\n label_rotated = Text('Rotated', font_size=20, color=GREEN)\n label_rotated.next_to(square_rotated, DOWN)\n self.play(TransformFromCopy(square, square_rotated), Write(label_rotated), run_time=2.0 * 0.5)\n square_translated = Square(side_length=1.5, color=YELLOW, fill_opacity=0.3)\n square_translated.shift(RIGHT * 3 + UP * 2)\n label_translated = Text('Translated', font_size=20, color=YELLOW)\n label_translated.next_to(square_translated, DOWN)\n self.play(TransformFromCopy(square, square_translated), Write(label_translated), run_time=2.0 * 0.5)\n self.wait(0.5)\n self.play(FadeOut(demo_title), FadeOut(square), FadeOut(label_orig), FadeOut(square_scaled), FadeOut(label_scaled), FadeOut(square_rotated), FadeOut(label_rotated), FadeOut(square_translated), FadeOut(label_translated))\n summary_title = Text('Key Properties', font_size=36, color=GREEN)\n summary_title.to_edge(UP, buff=0.5)\n properties = VGroup(Text('Preserves straight lines', font_size=26), Text('Preserves parallelism', font_size=26), Text('Origin may move (unlike linear)', font_size=26), Text('Preserves ratios of lengths on parallel lines', font_size=26), Text('Composition of affines is affine', font_size=26)).arrange(DOWN, aligned_edge=LEFT, buff=0.4)\n properties.next_to(summary_title, DOWN, buff=0.6)\n box = SurroundingRectangle(properties, buff=0.3, color=YELLOW)\n self.play(Write(summary_title), run_time=2.0 * 0.2)\n self.play(FadeIn(properties), Create(box), run_time=2.0 * 0.8)\n self.wait(0.5)\n self.play(FadeOut(summary_title), FadeOut(properties), FadeOut(box))\n apps_title = Text('Applications', font_size=36, color=BLUE)\n apps_title.to_edge(UP, buff=0.5)\n applications = VGroup(Text('- Computer Graphics: Image manipulation', font_size=24), Text('- Robotics: Coordinate transformations', font_size=24), Text('- Physics: Reference frame changes', font_size=24), Text('- Data Science: Data normalization', font_size=24), Text('- Computer Vision: Image registration', font_size=24)).arrange(DOWN, aligned_edge=LEFT, buff=0.35)\n applications.next_to(apps_title, DOWN, buff=0.6)\n self.play(Write(apps_title), run_time=2.0 * 0.2)\n self.play(FadeIn(applications), run_time=2.0 * 0.8)\n self.wait(0.5)\n self.play(FadeOut(apps_title), FadeOut(applications))\n final_title = Text('Summary', font_size=40, color=YELLOW)\n final_title.to_edge(UP, buff=0.5)\n final_formula = MathTex('T(x) = Ax + b', font_size=44)\n final_formula.next_to(final_title, DOWN, buff=0.6)\n key_points = VGroup(Text('Linear transformation + Translation', font_size=26), Text('Preserves lines and parallelism', font_size=26), Text('Fundamental in geometry and graphics', font_size=26)).arrange(DOWN, buff=0.3)\n key_points.next_to(final_formula, DOWN, buff=0.6)\n self.play(Write(final_title), run_time=2.0 * 0.2)\n self.play(Write(final_formula), run_time=2.0 * 0.4)\n self.play(FadeIn(key_points), run_time=2.0 * 0.4)\n self.wait(1)\n self.play(FadeOut(final_title), FadeOut(final_formula), FadeOut(key_points))\n end_text = Text('Thank you for learning!', font_size=40, color=BLUE)\n end_text2 = Text('Affine Transformations in Geometry', font_size=28, color=WHITE)\n end_group = VGroup(end_text, end_text2).arrange(DOWN, buff=0.5)\n end_group.center()\n self.play(Write(end_group))\n self.wait(2)\n self.play(FadeOut(end_group))\n```", "category": "narrated_pedagogical_preference", "source": "nabin2004/manim-narrated-dpo-400"} +{"system": "You are an expert Manim Community Edition (ManimCE v0.19+) Python developer and mathematical animator. Given a user request, first plan the spatial layout, coordinate bounds, timing, and pedagogical flow inside ... tags (when reasoning is helpful), and then output a complete, runnable, self-contained ManimCE Python script using `from manim import *`. Never use deprecated ManimGL (`manimlib`) methods like `ShowCreation`, `TexMobject`, `TextMobject`, or `axes.get_graph`; always use modern ManimCE APIs (`Create`, `MathTex`, `Tex`, `Text`, `axes.plot`) and prevent visual overlap using `.to_edge()`, `.next_to()`, and `FadeOut`.", "prompt": "I'm teaching an undergrad ML course and want a vivid visualization of hook behavior in neural nets: animate a forward hook that logs activations and a backward hook that records gradients. Show a small module with a couple of layers, a forward pass highlighting activations, then backprop tracing gradient flow. I'd like two scenes with clean side annotations and a live counter of hook calls.", "chosen": "```python\nfrom manim import *\n\nclass HookBehaviorInNeuralNetworks(Scene):\n\n def construct(self):\n title = Text('Hook Behavior in Neural Networks', font_size=40, color=BLUE)\n title.to_edge(UP, buff=0.5)\n self.play(Write(title), run_time=2.0)\n subtitle = Text('Why do some weights get stuck while others shift?', font_size=24, color=GRAY)\n subtitle.next_to(title, DOWN, buff=0.3)\n self.play(FadeIn(subtitle), run_time=2.0)\n self.wait(0.5)\n self.play(FadeOut(subtitle), run_time=2.0 * 0.5)\n input_layer = VGroup(*[Circle(radius=0.25, color=BLUE, fill_opacity=0.3) for _ in range(3)])\n hidden_layer = VGroup(*[Circle(radius=0.25, color=GREEN, fill_opacity=0.3) for _ in range(4)])\n output_layer = VGroup(*[Circle(radius=0.25, color=RED, fill_opacity=0.3) for _ in range(2)])\n input_layer.arrange(DOWN, buff=0.6)\n hidden_layer.arrange(DOWN, buff=0.5)\n output_layer.arrange(DOWN, buff=0.8)\n input_layer.shift(LEFT * 4)\n hidden_layer.shift(LEFT * 1)\n output_layer.shift(RIGHT * 2)\n input_label = Text('Input', font_size=20, color=BLUE).next_to(input_layer, LEFT)\n hidden_label = Text('Hidden', font_size=20, color=GREEN).next_to(hidden_layer, UP, buff=0.3)\n output_label = Text('Output', font_size=20, color=RED).next_to(output_layer, RIGHT)\n self.play(FadeOut(title), Create(input_layer), Create(hidden_layer), Create(output_layer), Write(input_label), Write(hidden_label), Write(output_label), run_time=2.0 * 0.8)\n weights_ih = VGroup()\n for inp in input_layer:\n for hid in hidden_layer:\n line = Line(inp.get_right(), hid.get_left(), color=YELLOW, stroke_width=1.5)\n weights_ih.add(line)\n weights_ho = VGroup()\n for hid in hidden_layer:\n for out in output_layer:\n line = Line(hid.get_right(), out.get_left(), color=ORANGE, stroke_width=1.5)\n weights_ho.add(line)\n self.play(Create(weights_ih), Create(weights_ho), run_time=2.0)\n network_group = VGroup(input_layer, hidden_layer, output_layer, weights_ih, weights_ho, input_label, hidden_label, output_label)\n stuck_weights = VGroup(*weights_ih[:4])\n shifting_weights = VGroup(*weights_ih[4:8])\n self.play(stuck_weights.animate.set_color(RED).set_stroke_width(3), shifting_weights.animate.set_color(YELLOW).set_stroke_width(4), run_time=2.0 * 0.7)\n hook_text = Text('Hooked Weights', font_size=24, color=RED)\n hook_text.next_to(network_group, DOWN, buff=0.5)\n self.play(Write(hook_text), run_time=2.0 * 0.6)\n self.wait(2.0 * 0.4)\n self.play(FadeOut(network_group), FadeOut(hook_text), run_time=2.0 * 0.3)\n axes = Axes(x_range=[-3, 3, 1], y_range=[0, 1.5, 0.5], axis_config={'include_tip': False}, x_length=6, y_length=3)\n axes.to_edge(LEFT, buff=0.8)\n x_label = Text('Weight Value', font_size=18).next_to(axes.x_axis, DOWN)\n y_label = Text('Density', font_size=18).next_to(axes.y_axis, LEFT).rotate(90 * DEGREES)\n normal_curve = axes.plot(lambda x: np.exp(-x ** 2), color=GREEN, stroke_width=3)\n self.play(Create(axes), Write(x_label), Write(y_label), run_time=2.0 * 0.4)\n self.play(Create(normal_curve), run_time=2.0 * 0.3)\n hooked_curve = axes.plot(lambda x: 0.3 + 0.7 * x ** 2 / (1 + x ** 2), color=RED, stroke_width=3)\n self.play(Transform(normal_curve, hooked_curve), run_time=2.0 * 0.7)\n dist_label = Text('Hooked Distribution', font_size=22, color=RED)\n dist_label.next_to(axes, UP)\n self.play(Write(dist_label), run_time=2.0)\n self.play(FadeOut(axes), FadeOut(x_label), FadeOut(y_label), FadeOut(normal_curve), FadeOut(dist_label), run_time=2.0 * 0.3)\n bad_init_box = Rectangle(width=3, height=3.5, color=RED)\n good_init_box = Rectangle(width=3, height=3.5, color=GREEN)\n bad_init_box.shift(LEFT * 2)\n good_init_box.shift(RIGHT * 2)\n bad_label = Text('Poor Init', font_size=20, color=RED).next_to(bad_init_box, UP, buff=0.2)\n good_label = Text('Proper Init', font_size=20, color=GREEN).next_to(good_init_box, UP, buff=0.2)\n self.play(Create(bad_init_box), Create(good_init_box), Write(bad_label), Write(good_label), run_time=2.0 * 0.7)\n bad_lines = VGroup()\n for i in range(8):\n start = bad_init_box.get_center() + LEFT * 1 + UP * (1.2 - i * 0.35)\n end = bad_init_box.get_center() + RIGHT * 1 + UP * (1.2 - i * 0.35) + DOWN * 0.3 * (i % 3)\n line = Line(start, end, color=RED, stroke_width=2)\n bad_lines.add(line)\n self.play(Create(bad_lines), run_time=2.0)\n good_lines = VGroup()\n for i in range(8):\n start = good_init_box.get_center() + LEFT * 1 + UP * (1.2 - i * 0.35)\n end = good_init_box.get_center() + RIGHT * 1 + UP * (1.2 - i * 0.35)\n line = Line(start, end, color=GREEN, stroke_width=2)\n good_lines.add(line)\n self.play(Create(good_lines), run_time=2.0)\n self.play(FadeOut(bad_init_box), FadeOut(good_init_box), FadeOut(bad_label), FadeOut(good_label), FadeOut(bad_lines), FadeOut(good_lines), run_time=2.0 * 0.5)\n takeaway1 = Text('1. Weight distribution affects training', font_size=24, color=WHITE)\n takeaway1.to_edge(UP, buff=1)\n self.play(Write(takeaway1), run_time=2.0)\n takeaway2 = Text('2. U-shaped distribution = Hook behavior', font_size=24, color=WHITE)\n takeaway2.next_to(takeaway1, DOWN, buff=0.5)\n self.play(Write(takeaway2), run_time=2.0)\n takeaway3 = Text('3. Use Xavier or He initialization', font_size=24, color=WHITE)\n takeaway3.next_to(takeaway2, DOWN, buff=0.5)\n self.play(Write(takeaway3), run_time=2.0)\n takeaway4 = Text('4. Monitor weights during training', font_size=24, color=WHITE)\n takeaway4.next_to(takeaway3, DOWN, buff=0.5)\n self.play(Write(takeaway4), run_time=2.0)\n final_text = Text('Happy Training!', font_size=36, color=BLUE)\n final_text.next_to(takeaway4, DOWN, buff=0.8)\n self.play(Write(final_text), run_time=2.0)\n self.wait(1)\n```", "rejected": "```python\nfrom manim import *\n\nclass HookBehaviorInNeuralNetworks(Scene):\n\n def construct(self):\n title = Text('Hook Behavior in Neural Networks', font_size=40, color=BLUE)\n title.to_edge(UP, buff=0.5)\n self.play(Write(title), run_time=2.0)\n subtitle = Text('Why do some weights get stuck while others shift?', font_size=24, color=GRAY)\n subtitle.next_to(title, DOWN, buff=0.3)\n self.play(FadeIn(subtitle), run_time=2.0)\n self.wait(0.5)\n self.play(FadeOut(subtitle), run_time=2.0 * 0.5)\n input_layer = VGroup(*[Circle(radius=0.25, color=BLUE, fill_opacity=0.3) for _ in range(3)])\n hidden_layer = VGroup(*[Circle(radius=0.25, color=GREEN, fill_opacity=0.3) for _ in range(4)])\n output_layer = VGroup(*[Circle(radius=0.25, color=RED, fill_opacity=0.3) for _ in range(2)])\n input_layer.arrange(DOWN, buff=0.6)\n hidden_layer.arrange(DOWN, buff=0.5)\n output_layer.arrange(DOWN, buff=0.8)\n input_layer.shift(LEFT * 4)\n hidden_layer.shift(LEFT * 1)\n output_layer.shift(RIGHT * 2)\n input_label = Text('Input', font_size=20, color=BLUE).next_to(input_layer, LEFT)\n hidden_label = Text('Hidden', font_size=20, color=GREEN).next_to(hidden_layer, UP, buff=0.3)\n output_label = Text('Output', font_size=20, color=RED).next_to(output_layer, RIGHT)\n self.play(FadeOut(title), Create(input_layer), Create(hidden_layer), Create(output_layer), Write(input_label), Write(hidden_label), Write(output_label), run_time=2.0 * 0.8)\n weights_ih = VGroup()\n for inp in input_layer:\n for hid in hidden_layer:\n line = Line(inp.get_right(), hid.get_left(), color=YELLOW, stroke_width=1.5)\n weights_ih.add(line)\n weights_ho = VGroup()\n for hid in hidden_layer:\n for out in output_layer:\n line = Line(hid.get_right(), out.get_left(), color=ORANGE, stroke_width=1.5)\n weights_ho.add(line)\n self.play(Create(weights_ih), Create(weights_ho), run_time=2.0)\n network_group = VGroup(input_layer, hidden_layer, output_layer, weights_ih, weights_ho, input_label, hidden_label, output_label)\n stuck_weights = VGroup(*weights_ih[:4])\n shifting_weights = VGroup(*weights_ih[4:8])\n self.play(stuck_weights.animate.set_color(RED).set_stroke_width(3), shifting_weights.animate.set_color(YELLOW).set_stroke_width(4), run_time=2.0 * 0.7)\n hook_text = Text('Hooked Weights', font_size=24, color=RED)\n hook_text.next_to(network_group, DOWN, buff=0.5)\n self.play(Write(hook_text), run_time=2.0 * 0.6)\n self.wait(2.0 * 0.4)\n self.play(FadeOut(network_group), FadeOut(hook_text), run_time=2.0 * 0.3)\n axes = Axes(axis_color=BLUE, x_range=[-3, 3, 1], y_range=[0, 1.5, 0.5], axis_config={'include_tip': False}, x_length=6, y_length=3)\n axes.to_edge(LEFT, buff=0.8)\n x_label = Text('Weight Value', font_size=18).next_to(axes.x_axis, DOWN)\n y_label = Text('Density', font_size=18).next_to(axes.y_axis, LEFT).rotate(90 * DEGREES)\n normal_curve = axes.plot(lambda x: np.exp(-x ** 2), color=GREEN, stroke_width=3)\n self.play(Create(axes), Write(x_label), Write(y_label), run_time=2.0 * 0.4)\n self.play(Create(normal_curve), run_time=2.0 * 0.3)\n hooked_curve = axes.plot(lambda x: 0.3 + 0.7 * x ** 2 / (1 + x ** 2), color=RED, stroke_width=3)\n self.play(Transform(normal_curve, hooked_curve), run_time=2.0 * 0.7)\n dist_label = Text('Hooked Distribution', font_size=22, color=RED)\n dist_label.next_to(axes, UP)\n self.play(Write(dist_label), run_time=2.0)\n self.play(FadeOut(axes), FadeOut(x_label), FadeOut(y_label), FadeOut(normal_curve), FadeOut(dist_label), run_time=2.0 * 0.3)\n bad_init_box = Rectangle(width=3, height=3.5, color=RED)\n good_init_box = Rectangle(width=3, height=3.5, color=GREEN)\n bad_init_box.shift(LEFT * 2)\n good_init_box.shift(RIGHT * 2)\n bad_label = Text('Poor Init', font_size=20, color=RED).next_to(bad_init_box, UP, buff=0.2)\n good_label = Text('Proper Init', font_size=20, color=GREEN).next_to(good_init_box, UP, buff=0.2)\n self.play(Create(bad_init_box), Create(good_init_box), Write(bad_label), Write(good_label), run_time=2.0 * 0.7)\n bad_lines = VGroup()\n for i in range(8):\n start = bad_init_box.get_center() + LEFT * 1 + UP * (1.2 - i * 0.35)\n end = bad_init_box.get_center() + RIGHT * 1 + UP * (1.2 - i * 0.35) + DOWN * 0.3 * (i % 3)\n line = Line(start, end, color=RED, stroke_width=2)\n bad_lines.add(line)\n self.play(Create(bad_lines), run_time=2.0)\n good_lines = VGroup()\n for i in range(8):\n start = good_init_box.get_center() + LEFT * 1 + UP * (1.2 - i * 0.35)\n end = good_init_box.get_center() + RIGHT * 1 + UP * (1.2 - i * 0.35)\n line = Line(start, end, color=GREEN, stroke_width=2)\n good_lines.add(line)\n self.play(Create(good_lines), run_time=2.0)\n self.play(FadeOut(bad_init_box), FadeOut(good_init_box), FadeOut(bad_label), FadeOut(good_label), FadeOut(bad_lines), FadeOut(good_lines), run_time=2.0 * 0.5)\n takeaway1 = Text('1. Weight distribution affects training', font_size=24, color=WHITE)\n takeaway1.to_edge(UP, buff=1)\n self.play(Write(takeaway1), run_time=2.0)\n takeaway2 = Text('2. U-shaped distribution = Hook behavior', font_size=24, color=WHITE)\n takeaway2.next_to(takeaway1, DOWN, buff=0.5)\n self.play(Write(takeaway2), run_time=2.0)\n takeaway3 = Text('3. Use Xavier or He initialization', font_size=24, color=WHITE)\n takeaway3.next_to(takeaway2, DOWN, buff=0.5)\n self.play(Write(takeaway3), run_time=2.0)\n takeaway4 = Text('4. Monitor weights during training', font_size=24, color=WHITE)\n takeaway4.next_to(takeaway3, DOWN, buff=0.5)\n self.play(Write(takeaway4), run_time=2.0)\n final_text = Text('Happy Training!', font_size=36, color=BLUE)\n final_text.next_to(takeaway4, DOWN, buff=0.8)\n self.play(Write(final_text), run_time=2.0)\n self.wait(1)\n```", "category": "invalid_axes_kwarg", "source": "synthetic_hard_neg:nabin2004/AOS-Manim-SFT"} +{"system": "You are an expert Manim Community Edition (ManimCE v0.19+) Python developer and mathematical animator. Given a user request, first plan the spatial layout, coordinate bounds, timing, and pedagogical flow inside ... tags (when reasoning is helpful), and then output a complete, runnable, self-contained ManimCE Python script using `from manim import *`. Never use deprecated ManimGL (`manimlib`) methods like `ShowCreation`, `TexMobject`, `TextMobject`, or `axes.get_graph`; always use modern ManimCE APIs (`Create`, `MathTex`, `Tex`, `Text`, `axes.plot`) and prevent visual overlap using `.to_edge()`, `.next_to()`, and `FadeOut`.", "prompt": "I'm teaching undergrads about debugging neural nets. Create an animation where a breakpoint pauses the forward pass mid-multiplication, displays the current layer outputs as a diagram of activations, and shows how gradients would flow if resumed. Include a pane with the call stack and paused tensors, then resume action that reveals updated outputs and subsequent layers. Use a clear color scheme to emphasize the paused state.", "chosen": "```python\nfrom manim import *\nfrom manim_voiceover import VoiceoverScene\nfrom manim_voiceover.services.gtts import GTTSService\n\nclass DebuggingNNScene(VoiceoverScene):\n def construct(self):\n # [SETUP]\n # [LAYOUT]\n self.set_speech_service(GTTSService(transcription_model=\"base\"))\n \n # [BEAT 1 | sync: PAUSE]\n with self.voiceover(text=\"When debugging a neural network, we can set a breakpoint to pause the forward pass. This freezes the computation mid-multiplication.\") as tracker:\n title = Text(\"Debugging Neural Networks\", font_size=36, color=BLUE)\n self.fit_in_frame(title)\n title.to_edge(UP)\n \n layers = VGroup(*[\n VGroup(*[Dot(color=BLUE) for _ in range(3)]).arrange(DOWN)\n for _ in range(3)\n ]).arrange(RIGHT, buff=1.5).shift(UP * 0.5)\n \n pause_icon = Square(side_length=0.5, color=RED, fill_opacity=0.8)\n pause_icon.add(Line(UP*0.15, DOWN*0.15, color=WHITE, stroke_width=4).shift(LEFT*0.1))\n pause_icon.add(Line(UP*0.15, DOWN*0.15, color=WHITE, stroke_width=4).shift(RIGHT*0.1))\n pause_icon.move_to(layers[1])\n \n self.wait_until_bookmark(\"PAUSE\")\n self.play(Write(title), Create(layers), Create(pause_icon), run_time=tracker.duration)\n \n with self.voiceover(text=\"The debugger displays the call stack and the paused tensors. We can inspect the exact activation values before resuming the action.\") as tracker:\n call_stack = VGroup(\n Text(\"forward()\", font_size=16, font=\"Monospace\"),\n Text(\" layer_2(x)\", font_size=16, font=\"Monospace\"),\n Text(\" matmul()\", font_size=16, font=\"Monospace\", color=RED)\n ).arrange(DOWN, aligned_edge=LEFT).to_edge(LEFT).shift(DOWN)\n \n tensor_box = Rectangle(width=2, height=1.5, color=YELLOW).to_edge(RIGHT).shift(DOWN)\n tensor_label = Text(\"Tensor [4, 64]\", font_size=16).move_to(tensor_box)\n \n self.wait_until_bookmark(\"TENSORS\")\n self.play(Write(call_stack), Create(tensor_box), Write(tensor_label), run_time=tracker.duration)\n self.wait(1)\n\n def fit_in_frame(self, mob: Mobject, w_frac: float = 0.9, h_frac: float = 0.9) -> Mobject:\n max_w = config.frame_width * w_frac\n max_h = config.frame_height * h_frac\n if mob.width > max_w:\n mob.width = max_w\n if mob.height > max_h:\n mob.height = max_h\n return mob\n```", "rejected": "```python\nfrom manim import *\nfrom manim_voiceover import VoiceoverScene\nfrom manim_voiceover.services.gtts import GTTSService\n\nclass DebuggingNNScene(VoiceoverScene):\n def construct(self):\n # [SETUP]\n # [LAYOUT]\n self.set_speech_service(GTTSService(transcription_model=\"base\"))\n \n # [BEAT 1 | sync: PAUSE]\n with self.voiceover(text=\"When debugging a neural network, we can set a breakpoint to pause the forward pass. This freezes the computation mid-multiplication.\") as tracker:\n title = Text(\"Debugging Neural Networks\", font_size=36, color=BLUE)\n self.fit_in_frame(title)\n title.to_edge(UP)\n \n layers = VGroup(*[\n VGroup(*[Dot(color=BLUE) for _ in range(3)]).arrange(DOWN)\n for _ in range(3)\n ]).arrange(RIGHT, buff=1.5).shift(UP * 0.5)\n \n pause_icon = Square(side_length=0.5, color=RED, fill_opacity=0.8)\n pause_icon.add(Line(UP*0.15, DOWN*0.15, color=WHITE, stroke_width=4).shift(LEFT*0.1))\n pause_icon.add(Line(UP*0.15, DOWN*0.15, color=WHITE, stroke_width=4).shift(RIGHT*0.1))\n pause_icon.move_to(layers[1])\n \n self.wait_until_bookmark(\"PAUSE\")\n self.play(Write(title), ShowCreation(layers), Create(pause_icon), run_time=tracker.duration)\n \n with self.voiceover(text=\"The debugger displays the call stack and the paused tensors. We can inspect the exact activation values before resuming the action.\") as tracker:\n call_stack = VGroup(\n Text(\"forward()\", font_size=16, font=\"Monospace\"),\n Text(\" layer_2(x)\", font_size=16, font=\"Monospace\"),\n Text(\" matmul()\", font_size=16, font=\"Monospace\", color=RED)\n ).arrange(DOWN, aligned_edge=LEFT).to_edge(LEFT).shift(DOWN)\n \n tensor_box = Rectangle(width=2, height=1.5, color=YELLOW).to_edge(RIGHT).shift(DOWN)\n tensor_label = Text(\"Tensor [4, 64]\", font_size=16).move_to(tensor_box)\n \n self.wait_until_bookmark(\"TENSORS\")\n self.play(Write(call_stack), Create(tensor_box), Write(tensor_label), run_time=tracker.duration)\n self.wait(1)\n\n def fit_in_frame(self, mob: Mobject, w_frac: float = 0.9, h_frac: float = 0.9) -> Mobject:\n max_w = config.frame_width * w_frac\n max_h = config.frame_height * h_frac\n if mob.width > max_w:\n mob.width = max_w\n if mob.height > max_h:\n mob.height = max_h\n return mob\n```", "category": "legacy_api_hallucination", "source": "synthetic_hard_neg:nabin2004/qwen3-8b-manimator-gold-sft"} +{"system": "You are an expert Manim Community Edition (ManimCE v0.19+) Python developer and mathematical animator. Given a user request, first plan the spatial layout, coordinate bounds, timing, and pedagogical flow inside ... tags (when reasoning is helpful), and then output a complete, runnable, self-contained ManimCE Python script using `from manim import *`. Never use deprecated ManimGL (`manimlib`) methods like `ShowCreation`, `TexMobject`, `TextMobject`, or `axes.get_graph`; always use modern ManimCE APIs (`Create`, `MathTex`, `Tex`, `Text`, `axes.plot`) and prevent visual overlap using `.to_edge()`, `.next_to()`, and `FadeOut`.", "prompt": "I'm teaching probability-inspired NLP and want a parallel visualization of two bigram models trained on different datasets. Start both from the same initial character and let each model sample next characters, showing two diverging strings over time. Plot the probability mass flowing through the bigram table as the strings grow, with color-coded traces for each model. End with a short discussion on dataset bias and how it steers the trajectories differently.", "chosen": "```python\nfrom manim import *\n\nclass ProbabilityNLP(Scene):\n\n def construct(self):\n title = Text('Probability Inspired NLP', font_size=48, color=BLUE)\n subtitle = Text('Where Statistics Meets Language', font_size=28, color=GRAY)\n title_group = VGroup(title, subtitle).arrange(DOWN, buff=0.5)\n self.play(Write(title), run_time=2.0 * 0.6)\n self.play(FadeIn(subtitle), run_time=2.0 * 0.4)\n self.wait(0.5)\n self.play(title_group.animate.scale(0.5).to_corner(UL), run_time=2.0)\n sentence = Text('\"The cat sat on the ...\"', font_size=32, color=WHITE)\n sentence.move_to(UP * 1.5)\n words = ['mat', 'chair', 'floor', 'roof', 'table']\n word_cloud = VGroup()\n colors = [YELLOW, GREEN, ORANGE, PINK, TEAL]\n for i, word in enumerate(words):\n w = Text(word, font_size=24 + (5 - i) * 4, color=colors[i])\n angle = i / len(words) * TAU\n w.move_to([2.5 * np.cos(angle), -1 + 0.8 * np.sin(angle), 0])\n word_cloud.add(w)\n self.play(Write(sentence), run_time=2.0 * 0.5)\n self.play(FadeIn(word_cloud), run_time=2.0 * 0.5)\n self.wait(0.3)\n highlight_box = SurroundingRectangle(word_cloud[0], color=YELLOW, buff=0.2)\n self.play(Create(highlight_box), run_time=2.0 * 0.5)\n self.play(FadeOut(highlight_box), run_time=2.0 * 0.5)\n self.play(FadeOut(sentence), FadeOut(word_cloud))\n formula = MathTex('P(W|C) = ', '\\\\frac{P(C|W) \\\\cdot P(W)}{P(C)}', font_size=42)\n formula.move_to(UP * 0.5)\n label_w = Text('Word', font_size=20, color=YELLOW).next_to(formula[0][1], DOWN, buff=0.3)\n label_c = Text('Context', font_size=20, color=GREEN).next_to(formula[0][3], DOWN, buff=0.3)\n self.play(Write(formula[0]), run_time=2.0 * 0.5)\n self.play(FadeIn(label_w), FadeIn(label_c), run_time=2.0 * 0.3)\n self.wait(0.3)\n self.play(Write(formula[1]), run_time=2.0)\n self.wait(0.3)\n likelihood = SurroundingRectangle(formula[1][0:5], color=BLUE, buff=0.1)\n prior = SurroundingRectangle(formula[1][6:9], color=GREEN, buff=0.1)\n evidence = SurroundingRectangle(formula[1][10:13], color=ORANGE, buff=0.1)\n self.play(Create(likelihood), run_time=2.0 * 0.3)\n self.play(Transform(likelihood, prior), run_time=2.0 * 0.3)\n self.play(Transform(likelihood, evidence), run_time=2.0 * 0.3)\n self.play(FadeOut(likelihood), run_time=2.0 * 0.1)\n self.play(FadeOut(formula), FadeOut(label_w), FadeOut(label_c))\n ngram_title = Text('N-gram Language Models', font_size=36, color=BLUE)\n ngram_title.to_edge(UP, buff=0.8)\n self.play(Write(ngram_title), run_time=2.0)\n unigram = Text('[The]', font_size=28, color=YELLOW)\n bigram = Text('[The cat]', font_size=28, color=GREEN)\n trigram = Text('[The cat sat]', font_size=28, color=ORANGE)\n ngram_group = VGroup(unigram, bigram, trigram).arrange(RIGHT, buff=1.5)\n ngram_group.move_to(UP * 0.5)\n labels = VGroup(Text('Unigram (N=1)', font_size=18, color=GRAY).next_to(unigram, DOWN, buff=0.4), Text('Bigram (N=2)', font_size=18, color=GRAY).next_to(bigram, DOWN, buff=0.4), Text('Trigram (N=3)', font_size=18, color=GRAY).next_to(trigram, DOWN, buff=0.4))\n self.play(Write(unigram), FadeIn(labels[0]), run_time=2.0 * 0.3)\n self.play(Write(bigram), FadeIn(labels[1]), run_time=2.0 * 0.3)\n self.play(Write(trigram), FadeIn(labels[2]), run_time=2.0 * 0.4)\n self.wait(0.3)\n self.play(FadeOut(unigram), FadeOut(bigram), FadeOut(labels))\n bigram_formula = MathTex('P(w_i | w_{i-1}) = ', '\\\\frac{\\\\text{Count}(w_{i-1}, w_i)}{\\\\text{Count}(w_{i-1})}', font_size=36)\n bigram_formula.move_to(UP * 0.5)\n explanation_line1 = Text('How often do these words', font_size=18, color=GRAY)\n explanation_line2 = Text('appear together', font_size=18, color=GRAY)\n explanation = VGroup(explanation_line1, explanation_line2).arrange(DOWN, buff=0.1)\n explanation.next_to(bigram_formula, DOWN, buff=0.6)\n self.play(Write(bigram_formula), run_time=2.0 * 0.6)\n self.play(FadeIn(explanation), run_time=2.0 * 0.4)\n self.wait(0.3)\n self.play(FadeOut(bigram_formula), FadeOut(explanation), FadeOut(trigram))\n context_box = Rectangle(height=1, width=2.5, color=BLUE)\n context_text = Text('The cat', font_size=24, color=WHITE)\n context_group = VGroup(context_box, context_text)\n context_group.move_to(LEFT * 3)\n arrow = Arrow(LEFT * 1.5, RIGHT * 1, color=YELLOW)\n self.play(Create(context_group), run_time=2.0 * 0.5)\n self.play(Create(arrow), run_time=2.0 * 0.5)\n outcomes = VGroup()\n words_next = ['sat', 'jumped', 'slept']\n probs = [0.6, 0.2, 0.2]\n colors_prob = [GREEN, YELLOW, ORANGE]\n for i, (word, prob, color) in enumerate(zip(words_next, probs, colors_prob)):\n bar = Rectangle(height=prob * 4, width=0.8, color=color, fill_opacity=0.7)\n label = Text(word, font_size=20, color=WHITE).next_to(bar, DOWN, buff=0.3)\n pct = Text(f'{int(prob * 100)}%', font_size=18, color=color).next_to(bar, UP, buff=0.2)\n group = VGroup(bar, label, pct)\n outcomes.add(group)\n outcomes.arrange(RIGHT, buff=0.5)\n outcomes.move_to(RIGHT * 2.5)\n self.play(FadeIn(outcomes), run_time=2.0)\n self.wait(0.3)\n self.play(FadeOut(context_group), FadeOut(arrow), FadeOut(outcomes), FadeOut(ngram_title))\n bayes_title = Text('Bayesian Inference in NLP', font_size=36, color=BLUE)\n bayes_title.to_edge(UP, buff=0.8)\n self.play(Write(bayes_title), run_time=2.0)\n spam_formula = MathTex('P(\\\\text{Spam} | \\\\text{Words}) = ', '\\\\frac{P(\\\\text{Words} | \\\\text{Spam}) \\\\cdot P(\\\\text{Spam})}{P(\\\\text{Words})}', font_size=32)\n spam_formula.move_to(UP * 0.5)\n self.play(Write(spam_formula), run_time=2.0)\n self.wait(0.3)\n self.play(FadeOut(spam_formula))\n applications_left = VGroup(Text('• Autocorrect', font_size=22), Text('• Machine Translation', font_size=22)).arrange(DOWN, buff=0.4, aligned_edge=LEFT)\n applications_right = VGroup(Text('• Speech Recognition', font_size=22), Text('• Sentiment Analysis', font_size=22)).arrange(DOWN, buff=0.4, aligned_edge=LEFT)\n applications = VGroup(applications_left, applications_right).arrange(RIGHT, buff=1.5)\n applications.move_to(DOWN * 0.5)\n app_box = SurroundingRectangle(applications, color=GREEN, buff=0.4, corner_radius=0.2)\n app_label = Text('Real-World Applications', font_size=20, color=GREEN).next_to(app_box, UP, buff=0.2)\n self.play(FadeIn(applications), run_time=2.0 * 0.6)\n self.play(Create(app_box), FadeIn(app_label), run_time=2.0 * 0.4)\n self.wait(0.3)\n self.play(FadeOut(applications), FadeOut(app_box), FadeOut(app_label), FadeOut(bayes_title))\n summary_title = Text('Learning Outcomes', font_size=36, color=BLUE)\n summary_title.to_edge(UP, buff=0.8)\n self.play(Write(summary_title), run_time=2.0)\n outcome1 = Text('1. Recognize how probabilistic models', font_size=22)\n outcome1_cont = Text(' improve language understanding', font_size=22)\n o1_group = VGroup(outcome1, outcome1_cont).arrange(DOWN, aligned_edge=LEFT)\n o1_group.move_to(UP * 1)\n self.play(Write(o1_group), run_time=2.0)\n outcome2 = Text('2. Identify NLP applications in', font_size=22)\n outcome2_cont = Text(' real-world scenarios', font_size=22)\n o2_group = VGroup(outcome2, outcome2_cont).arrange(DOWN, aligned_edge=LEFT)\n o2_group.move_to(UP * 0)\n self.play(Write(o2_group), run_time=2.0)\n outcome3 = Text('3. Analyze effectiveness of different', font_size=22)\n outcome3_cont = Text(' NLP algorithms', font_size=22)\n o3_group = VGroup(outcome3, outcome3_cont).arrange(DOWN, aligned_edge=LEFT)\n o3_group.move_to(DOWN * 1)\n self.play(Write(o3_group), run_time=2.0)\n self.wait(0.5)\n self.play(FadeOut(o1_group), FadeOut(o2_group), FadeOut(o3_group), FadeOut(summary_title), run_time=2.0 * 0.5)\n final_text = Text('Probability + Language = NLP', font_size=40, color=BLUE)\n final_sub = Text('Unlocking the Power of AI', font_size=28, color=GRAY)\n final_group = VGroup(final_text, final_sub).arrange(DOWN, buff=0.5)\n self.play(Write(final_group), run_time=2.0 * 0.5)\n self.wait(1)\n self.play(FadeOut(final_group))\n```", "rejected": "```python\nfrom manim import *\n\nclass ProbabilityNLP(Scene):\n\n def construct(self):\n title = Text('Probability Inspired NLP', font_size=48, color=BLUE)\n subtitle = Text('Where Statistics Meets Language', font_size=28, color=GRAY)\n title_group = VGroup(title, subtitle).arrange(DOWN, buff=0.5)\n self.play(Write(title), run_time=2.0 * 0.6)\n self.play(FadeIn(subtitle), run_time=2.0 * 0.4)\n self.wait(0.5)\n self.play(title_group.animate.scale(0.5).to_corner(UL), run_time=2.0)\n sentence = Text('\"The cat sat on the ...\"', font_size=32, color=WHITE)\n sentence.move_to(UP * 1.5)\n words = ['mat', 'chair', 'floor', 'roof', 'table']\n word_cloud = VGroup()\n colors = [YELLOW, GREEN, ORANGE, PINK, TEAL]\n for i, word in enumerate(words):\n w = Text(word, font_size=24 + (5 - i) * 4, color=colors[i])\n angle = i / len(words) * TAU\n w.move_to([2.5 * np.cos(angle), -1 + 0.8 * np.sin(angle), 0])\n word_cloud.add(w)\n self.play(Write(sentence), run_time=2.0 * 0.5)\n self.play(FadeIn(word_cloud), run_time=2.0 * 0.5)\n self.wait(0.3)\n highlight_box = SurroundingRectangle(word_cloud[0], color=YELLOW, buff=0.2)\n self.play(ShowCreation(highlight_box), run_time=2.0 * 0.5)\n self.play(FadeOut(highlight_box), run_time=2.0 * 0.5)\n self.play(FadeOut(sentence), FadeOut(word_cloud))\n formula = TexMobject('P(W|C) = ', '\\\\frac{P(C|W) \\\\cdot P(W)}{P(C)}', font_size=42)\n formula.move_to(UP * 0.5)\n label_w = Text('Word', font_size=20, color=YELLOW).next_to(formula[0][1], DOWN, buff=0.3)\n label_c = Text('Context', font_size=20, color=GREEN).next_to(formula[0][3], DOWN, buff=0.3)\n self.play(Write(formula[0]), run_time=2.0 * 0.5)\n self.play(FadeIn(label_w), FadeIn(label_c), run_time=2.0 * 0.3)\n self.wait(0.3)\n self.play(Write(formula[1]), run_time=2.0)\n self.wait(0.3)\n likelihood = SurroundingRectangle(formula[1][0:5], color=BLUE, buff=0.1)\n prior = SurroundingRectangle(formula[1][6:9], color=GREEN, buff=0.1)\n evidence = SurroundingRectangle(formula[1][10:13], color=ORANGE, buff=0.1)\n self.play(Create(likelihood), run_time=2.0 * 0.3)\n self.play(Transform(likelihood, prior), run_time=2.0 * 0.3)\n self.play(Transform(likelihood, evidence), run_time=2.0 * 0.3)\n self.play(FadeOut(likelihood), run_time=2.0 * 0.1)\n self.play(FadeOut(formula), FadeOut(label_w), FadeOut(label_c))\n ngram_title = Text('N-gram Language Models', font_size=36, color=BLUE)\n ngram_title.to_edge(UP, buff=0.8)\n self.play(Write(ngram_title), run_time=2.0)\n unigram = Text('[The]', font_size=28, color=YELLOW)\n bigram = Text('[The cat]', font_size=28, color=GREEN)\n trigram = Text('[The cat sat]', font_size=28, color=ORANGE)\n ngram_group = VGroup(unigram, bigram, trigram).arrange(RIGHT, buff=1.5)\n ngram_group.move_to(UP * 0.5)\n labels = VGroup(Text('Unigram (N=1)', font_size=18, color=GRAY).next_to(unigram, DOWN, buff=0.4), Text('Bigram (N=2)', font_size=18, color=GRAY).next_to(bigram, DOWN, buff=0.4), Text('Trigram (N=3)', font_size=18, color=GRAY).next_to(trigram, DOWN, buff=0.4))\n self.play(Write(unigram), FadeIn(labels[0]), run_time=2.0 * 0.3)\n self.play(Write(bigram), FadeIn(labels[1]), run_time=2.0 * 0.3)\n self.play(Write(trigram), FadeIn(labels[2]), run_time=2.0 * 0.4)\n self.wait(0.3)\n self.play(FadeOut(unigram), FadeOut(bigram), FadeOut(labels))\n bigram_formula = MathTex('P(w_i | w_{i-1}) = ', '\\\\frac{\\\\text{Count}(w_{i-1}, w_i)}{\\\\text{Count}(w_{i-1})}', font_size=36)\n bigram_formula.move_to(UP * 0.5)\n explanation_line1 = Text('How often do these words', font_size=18, color=GRAY)\n explanation_line2 = Text('appear together', font_size=18, color=GRAY)\n explanation = VGroup(explanation_line1, explanation_line2).arrange(DOWN, buff=0.1)\n explanation.next_to(bigram_formula, DOWN, buff=0.6)\n self.play(Write(bigram_formula), run_time=2.0 * 0.6)\n self.play(FadeIn(explanation), run_time=2.0 * 0.4)\n self.wait(0.3)\n self.play(FadeOut(bigram_formula), FadeOut(explanation), FadeOut(trigram))\n context_box = Rectangle(height=1, width=2.5, color=BLUE)\n context_text = Text('The cat', font_size=24, color=WHITE)\n context_group = VGroup(context_box, context_text)\n context_group.move_to(LEFT * 3)\n arrow = Arrow(LEFT * 1.5, RIGHT * 1, color=YELLOW)\n self.play(Create(context_group), run_time=2.0 * 0.5)\n self.play(Create(arrow), run_time=2.0 * 0.5)\n outcomes = VGroup()\n words_next = ['sat', 'jumped', 'slept']\n probs = [0.6, 0.2, 0.2]\n colors_prob = [GREEN, YELLOW, ORANGE]\n for i, (word, prob, color) in enumerate(zip(words_next, probs, colors_prob)):\n bar = Rectangle(height=prob * 4, width=0.8, color=color, fill_opacity=0.7)\n label = Text(word, font_size=20, color=WHITE).next_to(bar, DOWN, buff=0.3)\n pct = Text(f'{int(prob * 100)}%', font_size=18, color=color).next_to(bar, UP, buff=0.2)\n group = VGroup(bar, label, pct)\n outcomes.add(group)\n outcomes.arrange(RIGHT, buff=0.5)\n outcomes.move_to(RIGHT * 2.5)\n self.play(FadeIn(outcomes), run_time=2.0)\n self.wait(0.3)\n self.play(FadeOut(context_group), FadeOut(arrow), FadeOut(outcomes), FadeOut(ngram_title))\n bayes_title = Text('Bayesian Inference in NLP', font_size=36, color=BLUE)\n bayes_title.to_edge(UP, buff=0.8)\n self.play(Write(bayes_title), run_time=2.0)\n spam_formula = MathTex('P(\\\\text{Spam} | \\\\text{Words}) = ', '\\\\frac{P(\\\\text{Words} | \\\\text{Spam}) \\\\cdot P(\\\\text{Spam})}{P(\\\\text{Words})}', font_size=32)\n spam_formula.move_to(UP * 0.5)\n self.play(Write(spam_formula), run_time=2.0)\n self.wait(0.3)\n self.play(FadeOut(spam_formula))\n applications_left = VGroup(Text('• Autocorrect', font_size=22), Text('• Machine Translation', font_size=22)).arrange(DOWN, buff=0.4, aligned_edge=LEFT)\n applications_right = VGroup(Text('• Speech Recognition', font_size=22), Text('• Sentiment Analysis', font_size=22)).arrange(DOWN, buff=0.4, aligned_edge=LEFT)\n applications = VGroup(applications_left, applications_right).arrange(RIGHT, buff=1.5)\n applications.move_to(DOWN * 0.5)\n app_box = SurroundingRectangle(applications, color=GREEN, buff=0.4, corner_radius=0.2)\n app_label = Text('Real-World Applications', font_size=20, color=GREEN).next_to(app_box, UP, buff=0.2)\n self.play(FadeIn(applications), run_time=2.0 * 0.6)\n self.play(Create(app_box), FadeIn(app_label), run_time=2.0 * 0.4)\n self.wait(0.3)\n self.play(FadeOut(applications), FadeOut(app_box), FadeOut(app_label), FadeOut(bayes_title))\n summary_title = Text('Learning Outcomes', font_size=36, color=BLUE)\n summary_title.to_edge(UP, buff=0.8)\n self.play(Write(summary_title), run_time=2.0)\n outcome1 = Text('1. Recognize how probabilistic models', font_size=22)\n outcome1_cont = Text(' improve language understanding', font_size=22)\n o1_group = VGroup(outcome1, outcome1_cont).arrange(DOWN, aligned_edge=LEFT)\n o1_group.move_to(UP * 1)\n self.play(Write(o1_group), run_time=2.0)\n outcome2 = Text('2. Identify NLP applications in', font_size=22)\n outcome2_cont = Text(' real-world scenarios', font_size=22)\n o2_group = VGroup(outcome2, outcome2_cont).arrange(DOWN, aligned_edge=LEFT)\n o2_group.move_to(UP * 0)\n self.play(Write(o2_group), run_time=2.0)\n outcome3 = Text('3. Analyze effectiveness of different', font_size=22)\n outcome3_cont = Text(' NLP algorithms', font_size=22)\n o3_group = VGroup(outcome3, outcome3_cont).arrange(DOWN, aligned_edge=LEFT)\n o3_group.move_to(DOWN * 1)\n self.play(Write(o3_group), run_time=2.0)\n self.wait(0.5)\n self.play(FadeOut(o1_group), FadeOut(o2_group), FadeOut(o3_group), FadeOut(summary_title), run_time=2.0 * 0.5)\n final_text = Text('Probability + Language = NLP', font_size=40, color=BLUE)\n final_sub = Text('Unlocking the Power of AI', font_size=28, color=GRAY)\n final_group = VGroup(final_text, final_sub).arrange(DOWN, buff=0.5)\n self.play(Write(final_group), run_time=2.0 * 0.5)\n self.wait(1)\n self.play(FadeOut(final_group))\n```", "category": "legacy_api_hallucination", "source": "synthetic_hard_neg:nabin2004/AOS-Manim-SFT"} +{"system": "You are an expert Manim Community Edition (ManimCE v0.19+) Python developer and mathematical animator. Given a user request, first plan the spatial layout, coordinate bounds, timing, and pedagogical flow inside ... tags (when reasoning is helpful), and then output a complete, runnable, self-contained ManimCE Python script using `from manim import *`. Never use deprecated ManimGL (`manimlib`) methods like `ShowCreation`, `TexMobject`, `TextMobject`, or `axes.get_graph`; always use modern ManimCE APIs (`Create`, `MathTex`, `Tex`, `Text`, `axes.plot`) and prevent visual overlap using `.to_edge()`, `.next_to()`, and `FadeOut`.", "prompt": "Create a 20-second Manim scene that applies a matrix transform to a polygon on a number plane. Trace the path of one vertex as the shape shears and stretches, and show the matrix beside the plane.", "chosen": "```python\nfrom manim import *\n\nclass MatrixTransformPathEcho(Scene):\n def construct(self):\n title = Text(\"A Matrix Moves Every Point Together\", font_size=36).to_edge(UP)\n plane = NumberPlane(x_range=[-5, 5, 1], y_range=[-4, 4, 1], background_line_style={\"stroke_opacity\": 0.35})\n shape = Polygon(LEFT + DOWN, LEFT + UP, RIGHT * 0.6 + UP * 0.4, RIGHT + DOWN * 0.8, color=TEAL_D, fill_opacity=0.18).shift(LEFT * 1.2)\n probe = Dot(shape.get_vertices()[0], color=YELLOW, radius=0.08)\n path = TracedPath(probe.get_center, stroke_color=YELLOW_D, stroke_width=4)\n vector_arrow = always_redraw(lambda: Arrow(ORIGIN, probe.get_center(), buff=0.0, color=YELLOW_D, stroke_width=5, max_tip_length_to_length_ratio=0.18))\n matrix_tex = MathTex(r\"A = \\begin{bmatrix}1.2 & 0.5\\\\-0.2 & 1.1\\end{bmatrix}\", color=BLUE_D).to_corner(UR).shift(DOWN * 0.5)\n caption_a = Text(\"The matrix changes the whole shape in one step.\", font_size=26, color=GRAY_D).to_edge(DOWN)\n caption_b = Text(\"Tracing one corner makes the transformation easier to read.\", font_size=26, color=GRAY_D).to_edge(DOWN)\n group = VGroup(shape, probe)\n\n self.play(FadeIn(title), Create(plane), FadeIn(shape), FadeIn(matrix_tex), run_time=4)\n self.add(path, vector_arrow)\n self.play(FadeIn(caption_a), run_time=2)\n self.play(ApplyMatrix([[1.2, 0.5], [-0.2, 1.1]], group), run_time=5)\n self.play(ReplacementTransform(caption_a, caption_b), run_time=2)\n self.play(ApplyMatrix([[0.9, -0.3], [0.25, 1.05]], group), run_time=5)\n self.wait(2)\n```", "rejected": "```python\nfrom manim import *\n\nclass MatrixTransformPathEcho(Scene):\n def construct(self):\n title = Text(\"A Matrix Moves Every Point Together\", font_size=36)\n plane = NumberPlane(x_range=[-5, 5, 1], y_range=[-4, 4, 1], background_line_style={\"stroke_opacity\": 0.35})\n shape = Polygon(LEFT + DOWN, LEFT + UP, RIGHT * 0.6 + UP * 0.4, RIGHT + DOWN * 0.8, color=TEAL_D, fill_opacity=0.18)\n probe = Dot(shape.get_vertices()[0], color=YELLOW, radius=0.08)\n path = TracedPath(probe.get_center, stroke_color=YELLOW_D, stroke_width=4)\n vector_arrow = always_redraw(lambda: Arrow(ORIGIN, probe.get_center(), buff=0.0, color=YELLOW_D, stroke_width=5, max_tip_length_to_length_ratio=0.18))\n matrix_tex = MathTex(r\"A = \\begin{bmatrix}1.2 & 0.5\\\\-0.2 & 1.1\\end{bmatrix}\", color=BLUE_D).shift(DOWN * 0.5)\n caption_a = Text(\"The matrix changes the whole shape in one step.\", font_size=26, color=GRAY_D).to_edge(DOWN)\n caption_b = Text(\"Tracing one corner makes the transformation easier to read.\", font_size=26, color=GRAY_D).to_edge(DOWN)\n group = VGroup(shape, probe)\n\n self.play(FadeIn(title), Create(plane), FadeIn(shape), FadeIn(matrix_tex), run_time=4)\n self.add(path, vector_arrow)\n self.play(FadeIn(caption_a), run_time=2)\n self.play(ApplyMatrix([[1.2, 0.5], [-0.2, 1.1]], group), run_time=5)\n self.play(ReplacementTransform(caption_a, caption_b), run_time=2)\n self.play(ApplyMatrix([[0.9, -0.3], [0.25, 1.05]], group), run_time=5)\n self.wait(2)\n```", "category": "spatial_layout_overlap", "source": "synthetic_hard_neg:sebastianboehler/autoresearch-manim"} +{"system": "You are an expert Manim Community Edition (ManimCE v0.19+) Python developer and mathematical animator. Given a user request, first plan the spatial layout, coordinate bounds, timing, and pedagogical flow inside ... tags (when reasoning is helpful), and then output a complete, runnable, self-contained ManimCE Python script using `from manim import *`. Never use deprecated ManimGL (`manimlib`) methods like `ShowCreation`, `TexMobject`, `TextMobject`, or `axes.get_graph`; always use modern ManimCE APIs (`Create`, `MathTex`, `Tex`, `Text`, `axes.plot`) and prevent visual overlap using `.to_edge()`, `.next_to()`, and `FadeOut`.", "prompt": "I'm learning data structures and want a visual of merge sort's divide-and-conquer process. Illustrate the recursive splitting into halves and the merging steps with real-time comparisons and stable merges. Show subarrays as color-coded bars, with a timeline highlighting each merge operation until a fully sorted array emerges. Include a brief walkthrough of the recursion tree and a quick contrast to quicksort for intuition. I’d like the pacing to emphasize the cost of merging and memory usage via a compact visual footprint.", "chosen": "```python\nfrom manim import *\nfrom manim_voiceover import VoiceoverScene\nfrom manim_voiceover.services.gtts import GTTSService\n\nclass MergeSortDivideAndConquer(VoiceoverScene):\n def construct(self):\n self.set_speech_service(\n GTTSService(voice=\"alba\", cache_dir=\"voiceover_cache\")\n )\n \n # Title\n with self.voiceover(text=\"Welcome! Today we'll explore Merge Sort, a classic divide and conquer algorithm.\") as tracker:\n title = Text(\"Merge Sort: Divide and Conquer\", font_size=36)\n title.to_edge(UP, buff=0.5)\n self.play(Write(title), run_time=tracker.duration)\n \n # Intro analogy\n with self.voiceover(text=\"Imagine organizing a messy stack of papers. Instead of sorting everything at once, you split them into smaller piles, sort each pile, and merge them together. That's Merge Sort!\") as tracker:\n analogy = Text(\"Split → Sort → Merge\", font_size=28, color=BLUE)\n analogy.next_to(title, DOWN, buff=0.8)\n self.play(Write(analogy), run_time=tracker.duration * 0.8)\n self.wait(0.5)\n \n # Clear analogy to focus on the algorithm\n self.play(FadeOut(analogy))\n \n # Create initial unsorted array\n values = [38, 27, 43, 3, 9, 82, 10]\n \n with self.voiceover(text=\"Here's our unsorted array with seven elements.\") as tracker:\n initial_array = self.create_array(values, color=RED)\n initial_array.move_to(ORIGIN)\n self.play(FadeIn(initial_array), run_time=tracker.duration)\n self.wait(0.3)\n \n # Phase 1: DIVIDE\n with self.voiceover(text=\"Merge Sort works in three phases. First: DIVIDE. We recursively split the array in half until we have single elements.\") as tracker:\n divide_label = Text(\"PHASE 1: DIVIDE\", font_size=24, color=YELLOW)\n divide_label.to_edge(LEFT, buff=0.5)\n divide_label.shift(UP * 2)\n self.play(Write(divide_label), run_time=tracker.duration * 0.5)\n \n # First split\n with self.voiceover(text=\"We split the array into two halves. Left half: 38, 27, 43. Right half: 3, 9, 82, 10.\") as tracker:\n left_half_1 = self.create_array([38, 27, 43], color=BLUE)\n right_half_1 = self.create_array([3, 9, 82, 10], color=GREEN)\n left_half_1.move_to(LEFT * 3 + UP * 0.5)\n right_half_1.move_to(RIGHT * 2.5 + UP * 0.5)\n \n self.play(\n TransformFromCopy(initial_array[0:3], left_half_1),\n TransformFromCopy(initial_array[3:7], right_half_1),\n run_time=tracker.duration * 0.8\n )\n # Draw split arrows\n arrow_left = Arrow(initial_array.get_bottom(), left_half_1.get_top(), buff=0.2, color=YELLOW)\n arrow_right = Arrow(initial_array.get_bottom(), right_half_1.get_top(), buff=0.2, color=YELLOW)\n self.play(Create(arrow_left), Create(arrow_right), run_time=0.5)\n \n self.wait(0.3)\n \n # Second level split - left side\n with self.voiceover(text=\"The left half splits further. 38, 27 becomes one group, and 43 stands alone.\") as tracker:\n left_2a = self.create_array([38, 27], color=BLUE_E)\n left_2b = self.create_array([43], color=BLUE_D)\n left_2a.move_to(LEFT * 4.5 + DOWN * 1.5)\n left_2b.move_to(LEFT * 2 + DOWN * 1.5)\n \n self.play(\n TransformFromCopy(left_half_1[0:2], left_2a),\n TransformFromCopy(left_half_1[2:3], left_2b),\n run_time=tracker.duration * 0.8\n )\n \n # Second level split - right side\n with self.voiceover(text=\"The right half splits into 3, 9 and 82, 10.\") as tracker:\n right_2a = self.create_array([3, 9], color=GREEN_E)\n right_2b = self.create_array([82, 10], color=GREEN_D)\n right_2a.move_to(RIGHT * 1 + DOWN * 1.5)\n right_2b.move_to(RIGHT * 4 + DOWN * 1.5)\n \n self.play(\n TransformFromCopy(right_half_1[0:2], right_2a),\n TransformFromCopy(right_half_1[2:4], right_2b),\n run_time=tracker.duration * 0.8\n )\n \n self.wait(0.3)\n \n # Third level - individual elements\n with self.voiceover(text=\"Finally, we split until every element stands alone. Now each single element is technically sorted.\") as tracker:\n singles = []\n single_values = [38, 27, 43, 3, 9, 82, 10]\n positions = [\n LEFT * 5 + DOWN * 3,\n LEFT * 4 + DOWN * 3,\n LEFT * 2 + DOWN * 3,\n RIGHT * 0.5 + DOWN * 3,\n RIGHT * 1.5 + DOWN * 3,\n RIGHT * 3.5 + DOWN * 3,\n RIGHT * 4.5 + DOWN * 3,\n ]\n \n for i, (val, pos) in enumerate(zip(single_values, positions)):\n single = self.create_array([val], color=GRAY, scale=0.6)\n single.move_to(pos)\n singles.append(single)\n \n # Animate splits\n self.play(\n TransformFromCopy(left_2a[0:1], singles[0]),\n TransformFromCopy(left_2a[1:2], singles[1]),\n TransformFromCopy(left_2b, singles[2]),\n TransformFromCopy(right_2a[0:1], singles[3]),\n TransformFromCopy(right_2a[1:2], singles[4]),\n TransformFromCopy(right_2b[0:1], singles[5]),\n TransformFromCopy(right_2b[1:2], singles[6]),\n run_time=tracker.duration * 0.7\n )\n \n self.wait(0.3)\n \n # Phase 2: CONQUER (MERGE)\n with self.voiceover(text=\"Phase two: CONQUER. We merge these single elements back together, but in sorted order.\") as tracker:\n # Fade out divide label, show merge label\n merge_label = Text(\"PHASE 2: MERGE\", font_size=24, color=GREEN)\n merge_label.to_edge(LEFT, buff=0.5)\n merge_label.shift(UP * 2)\n self.play(FadeOut(divide_label), Write(merge_label), run_time=tracker.duration * 0.5)\n \n # First merge - 38 and 27\n with self.voiceover(text=\"We compare 38 and 27. 27 is smaller, so it comes first. Result: 27, 38.\") as tracker:\n merged_1 = self.create_array([27, 38], color=BLUE_E)\n merged_1.move_to(LEFT * 4.25 + DOWN * 1.5)\n \n self.play(\n FadeOut(singles[0]),\n FadeOut(singles[1]),\n FadeIn(merged_1),\n run_time=tracker.duration * 0.7\n )\n # Highlight the comparison\n highlight = SurroundingRectangle(merged_1, color=YELLOW, buff=0.1)\n self.play(Create(highlight), run_time=0.3)\n self.play(FadeOut(highlight), run_time=0.2)\n \n # 43 stays alone\n with self.voiceover(text=\"43 is already alone and sorted.\") as tracker:\n self.play(singles[2].animate.set_color(BLUE_D), run_time=tracker.duration * 0.5)\n \n # Merge 3 and 9\n with self.voiceover(text=\"Comparing 3 and 9: 3 comes first. Result: 3, 9.\") as tracker:\n merged_2 = self.create_array([3, 9], color=GREEN_E)\n merged_2.move_to(RIGHT * 1 + DOWN * 1.5)\n \n self.play(\n FadeOut(singles[3]),\n FadeOut(singles[4]),\n FadeIn(merged_2),\n run_time=tracker.duration * 0.7\n )\n \n # Merge 82 and 10\n with self.voiceover(text=\"Comparing 82 and 10: 10 comes first. Result: 10, 82.\") as tracker:\n merged_3 = self.create_array([10, 82], color=GREEN_D)\n merged_3.move_to(RIGHT * 3.75 + DOWN * 1.5)\n \n self.play(\n FadeOut(singles[5]),\n FadeOut(singles[6]),\n FadeIn(merged_3),\n run_time=tracker.duration * 0.7\n )\n \n self.wait(0.3)\n \n # Second level merge - left side: merge [27,38] and [43]\n with self.voiceover(text=\"Now we merge 27, 38 with 43. We compare: 27 is smallest, then 38, then 43. Result: 27, 38, 43.\") as tracker:\n merged_left = self.create_array([27, 38, 43], color=BLUE)\n merged_left.move_to(LEFT * 3 + UP * 0.5)\n \n self.play(\n FadeOut(merged_1),\n FadeOut(singles[2]),\n FadeIn(merged_left),\n run_time=tracker.duration * 0.7\n )\n \n # Second level merge - right side: merge [3,9] and [10,82]\n with self.voiceover(text=\"Merging 3, 9 with 10, 82. Comparing heads: 3, then 9, then 10, then 82. Result: 3, 9, 10, 82.\") as tracker:\n merged_right = self.create_array([3, 9, 10, 82], color=GREEN)\n merged_right.move_to(RIGHT * 2.5 + UP * 0.5)\n \n self.play(\n FadeOut(merged_2),\n FadeOut(merged_3),\n FadeIn(merged_right),\n run_time=tracker.duration * 0.7\n )\n \n self.wait(0.3)\n \n # Final merge\n with self.voiceover(text=\"Final merge! Combining 27, 38, 43 with 3, 9, 10, 82. We repeatedly take the smallest element from the front of each array.\") as tracker:\n final_array = self.create_array([3, 9, 10, 27, 38, 43, 82], color=GREEN_B)\n final_array.move_to(ORIGIN)\n \n self.play(\n FadeOut(merged_left),\n FadeOut(merged_right),\n FadeIn(final_array),\n run_time=tracker.duration * 0.7\n )\n \n self.wait(0.3)\n \n # Success!\n with self.voiceover(text=\"And there it is! Our array is fully sorted: 3, 9, 10, 27, 38, 43, 82.\") as tracker:\n # Highlight the final sorted array\n success_box = SurroundingRectangle(final_array, color=GOLD, buff=0.15)\n self.play(Create(success_box), run_time=tracker.duration * 0.5)\n \n # Key takeaways\n self.play(FadeOut(merge_label), FadeOut(title), FadeOut(success_box))\n \n with self.voiceover(text=\"Merge Sort has a time complexity of n log n in all cases. The divide phase takes log n levels, and each merge processes all n elements.\") as tracker:\n takeaway_title = Text(\"Key Takeaways\", font_size=30, color=YELLOW)\n takeaway_title.to_edge(UP, buff=0.5)\n \n takeaways = VGroup(\n Text(\"• Divide: Split array in half recursively\", font_size=22),\n Text(\"• Conquer: Merge sorted subarrays\", font_size=22),\n Text(\"• Time Complexity: O(n log n)\", font_size=22),\n Text(\"• Stable: Maintains relative order\", font_size=22),\n ).arrange(DOWN, aligned_edge=LEFT, buff=0.4)\n takeaways.next_to(takeaway_title, DOWN, buff=0.6)\n \n self.play(Write(takeaway_title), run_time=tracker.duration * 0.3)\n for item in takeaways:\n self.play(Write(item), run_time=0.4)\n \n self.wait(0.5)\n \n with self.voiceover(text=\"Merge Sort is efficient, stable, and a perfect example of divide and conquer in action. Thanks for watching!\") as tracker:\n thanks = Text(\"Thanks for learning!\", font_size=28, color=BLUE)\n thanks.move_to(DOWN * 2)\n self.play(Write(thanks), run_time=tracker.duration * 0.7)\n \n self.wait(1)\n \n def create_array(self, values, color=WHITE, scale=1.0):\n \"\"\"Create a visual array of rectangles with numbers.\"\"\"\n squares = VGroup()\n for val in values:\n square = Square(side_length=0.7 * scale, stroke_color=color, fill_color=color, fill_opacity=0.2)\n num = Text(str(val), font_size=20 * scale)\n num.move_to(square.get_center())\n cell = VGroup(square, num)\n squares.add(cell)\n \n squares.arrange(RIGHT, buff=0.05)\n return squares\n```", "rejected": "```python\nfrom manim import *\nfrom manim_voiceover import VoiceoverScene\nfrom manim_voiceover.services.gtts import GTTSService\n\nclass MergeSortDivideAndConquer(VoiceoverScene):\n def construct(self):\n self.set_speech_service(\n GTTSService(voice=\"alba\", cache_dir=\"voiceover_cache\")\n )\n \n # Title\n with self.voiceover(text=\"Welcome! Today we'll explore Merge Sort, a classic divide and conquer algorithm.\") as tracker:\n title = Text(\"Merge Sort: Divide and Conquer\", font_size=36)\n title.to_edge(UP, buff=0.5)\n self.play(Write(title), run_time=tracker.duration)\n \n # Intro analogy\n with self.voiceover(text=\"Imagine organizing a messy stack of papers. Instead of sorting everything at once, you split them into smaller piles, sort each pile, and merge them together. That's Merge Sort!\") as tracker:\n analogy = Text(\"Split → Sort → Merge\", font_size=28, color=BLUE)\n analogy.next_to(title, DOWN, buff=0.8)\n self.play(Write(analogy), run_time=tracker.duration * 0.8)\n self.wait(0.5)\n \n # Clear analogy to focus on the algorithm\n self.play(FadeOut(analogy))\n \n # Create initial unsorted array\n values = [38, 27, 43, 3, 9, 82, 10]\n \n with self.voiceover(text=\"Here's our unsorted array with seven elements.\") as tracker:\n initial_array = self.create_array(values, color=RED)\n initial_array.move_to(ORIGIN)\n self.play(FadeIn(initial_array), run_time=tracker.duration)\n self.wait(0.3)\n \n # Phase 1: DIVIDE\n with self.voiceover(text=\"Merge Sort works in three phases. First: DIVIDE. We recursively split the array in half until we have single elements.\") as tracker:\n divide_label = Text(\"PHASE 1: DIVIDE\", font_size=24, color=YELLOW)\n divide_label.to_edge(LEFT, buff=0.5)\n divide_label.shift(UP * 2)\n self.play(Write(divide_label), run_time=tracker.duration * 0.5)\n \n # First split\n with self.voiceover(text=\"We split the array into two halves. Left half: 38, 27, 43. Right half: 3, 9, 82, 10.\") as tracker:\n left_half_1 = self.create_array([38, 27, 43], color=BLUE)\n right_half_1 = self.create_array([3, 9, 82, 10], color=GREEN)\n left_half_1.move_to(LEFT * 3 + UP * 0.5)\n right_half_1.move_to(RIGHT * 2.5 + UP * 0.5)\n \n self.play(\n TransformFromCopy(initial_array[0:3], left_half_1),\n TransformFromCopy(initial_array[3:7], right_half_1),\n run_time=tracker.duration * 0.8\n )\n # Draw split arrows\n arrow_left = Arrow(initial_array.get_bottom(), left_half_1.get_top(), buff=0.2, color=YELLOW)\n arrow_right = Arrow(initial_array.get_bottom(), right_half_1.get_top(), buff=0.2, color=YELLOW)\n self.play(ShowCreation(arrow_left), Create(arrow_right), run_time=0.5)\n \n self.wait(0.3)\n \n # Second level split - left side\n with self.voiceover(text=\"The left half splits further. 38, 27 becomes one group, and 43 stands alone.\") as tracker:\n left_2a = self.create_array([38, 27], color=BLUE_E)\n left_2b = self.create_array([43], color=BLUE_D)\n left_2a.move_to(LEFT * 4.5 + DOWN * 1.5)\n left_2b.move_to(LEFT * 2 + DOWN * 1.5)\n \n self.play(\n TransformFromCopy(left_half_1[0:2], left_2a),\n TransformFromCopy(left_half_1[2:3], left_2b),\n run_time=tracker.duration * 0.8\n )\n \n # Second level split - right side\n with self.voiceover(text=\"The right half splits into 3, 9 and 82, 10.\") as tracker:\n right_2a = self.create_array([3, 9], color=GREEN_E)\n right_2b = self.create_array([82, 10], color=GREEN_D)\n right_2a.move_to(RIGHT * 1 + DOWN * 1.5)\n right_2b.move_to(RIGHT * 4 + DOWN * 1.5)\n \n self.play(\n TransformFromCopy(right_half_1[0:2], right_2a),\n TransformFromCopy(right_half_1[2:4], right_2b),\n run_time=tracker.duration * 0.8\n )\n \n self.wait(0.3)\n \n # Third level - individual elements\n with self.voiceover(text=\"Finally, we split until every element stands alone. Now each single element is technically sorted.\") as tracker:\n singles = []\n single_values = [38, 27, 43, 3, 9, 82, 10]\n positions = [\n LEFT * 5 + DOWN * 3,\n LEFT * 4 + DOWN * 3,\n LEFT * 2 + DOWN * 3,\n RIGHT * 0.5 + DOWN * 3,\n RIGHT * 1.5 + DOWN * 3,\n RIGHT * 3.5 + DOWN * 3,\n RIGHT * 4.5 + DOWN * 3,\n ]\n \n for i, (val, pos) in enumerate(zip(single_values, positions)):\n single = self.create_array([val], color=GRAY, scale=0.6)\n single.move_to(pos)\n singles.append(single)\n \n # Animate splits\n self.play(\n TransformFromCopy(left_2a[0:1], singles[0]),\n TransformFromCopy(left_2a[1:2], singles[1]),\n TransformFromCopy(left_2b, singles[2]),\n TransformFromCopy(right_2a[0:1], singles[3]),\n TransformFromCopy(right_2a[1:2], singles[4]),\n TransformFromCopy(right_2b[0:1], singles[5]),\n TransformFromCopy(right_2b[1:2], singles[6]),\n run_time=tracker.duration * 0.7\n )\n \n self.wait(0.3)\n \n # Phase 2: CONQUER (MERGE)\n with self.voiceover(text=\"Phase two: CONQUER. We merge these single elements back together, but in sorted order.\") as tracker:\n # Fade out divide label, show merge label\n merge_label = Text(\"PHASE 2: MERGE\", font_size=24, color=GREEN)\n merge_label.to_edge(LEFT, buff=0.5)\n merge_label.shift(UP * 2)\n self.play(FadeOut(divide_label), Write(merge_label), run_time=tracker.duration * 0.5)\n \n # First merge - 38 and 27\n with self.voiceover(text=\"We compare 38 and 27. 27 is smaller, so it comes first. Result: 27, 38.\") as tracker:\n merged_1 = self.create_array([27, 38], color=BLUE_E)\n merged_1.move_to(LEFT * 4.25 + DOWN * 1.5)\n \n self.play(\n FadeOut(singles[0]),\n FadeOut(singles[1]),\n FadeIn(merged_1),\n run_time=tracker.duration * 0.7\n )\n # Highlight the comparison\n highlight = SurroundingRectangle(merged_1, color=YELLOW, buff=0.1)\n self.play(Create(highlight), run_time=0.3)\n self.play(FadeOut(highlight), run_time=0.2)\n \n # 43 stays alone\n with self.voiceover(text=\"43 is already alone and sorted.\") as tracker:\n self.play(singles[2].animate.set_color(BLUE_D), run_time=tracker.duration * 0.5)\n \n # Merge 3 and 9\n with self.voiceover(text=\"Comparing 3 and 9: 3 comes first. Result: 3, 9.\") as tracker:\n merged_2 = self.create_array([3, 9], color=GREEN_E)\n merged_2.move_to(RIGHT * 1 + DOWN * 1.5)\n \n self.play(\n FadeOut(singles[3]),\n FadeOut(singles[4]),\n FadeIn(merged_2),\n run_time=tracker.duration * 0.7\n )\n \n # Merge 82 and 10\n with self.voiceover(text=\"Comparing 82 and 10: 10 comes first. Result: 10, 82.\") as tracker:\n merged_3 = self.create_array([10, 82], color=GREEN_D)\n merged_3.move_to(RIGHT * 3.75 + DOWN * 1.5)\n \n self.play(\n FadeOut(singles[5]),\n FadeOut(singles[6]),\n FadeIn(merged_3),\n run_time=tracker.duration * 0.7\n )\n \n self.wait(0.3)\n \n # Second level merge - left side: merge [27,38] and [43]\n with self.voiceover(text=\"Now we merge 27, 38 with 43. We compare: 27 is smallest, then 38, then 43. Result: 27, 38, 43.\") as tracker:\n merged_left = self.create_array([27, 38, 43], color=BLUE)\n merged_left.move_to(LEFT * 3 + UP * 0.5)\n \n self.play(\n FadeOut(merged_1),\n FadeOut(singles[2]),\n FadeIn(merged_left),\n run_time=tracker.duration * 0.7\n )\n \n # Second level merge - right side: merge [3,9] and [10,82]\n with self.voiceover(text=\"Merging 3, 9 with 10, 82. Comparing heads: 3, then 9, then 10, then 82. Result: 3, 9, 10, 82.\") as tracker:\n merged_right = self.create_array([3, 9, 10, 82], color=GREEN)\n merged_right.move_to(RIGHT * 2.5 + UP * 0.5)\n \n self.play(\n FadeOut(merged_2),\n FadeOut(merged_3),\n FadeIn(merged_right),\n run_time=tracker.duration * 0.7\n )\n \n self.wait(0.3)\n \n # Final merge\n with self.voiceover(text=\"Final merge! Combining 27, 38, 43 with 3, 9, 10, 82. We repeatedly take the smallest element from the front of each array.\") as tracker:\n final_array = self.create_array([3, 9, 10, 27, 38, 43, 82], color=GREEN_B)\n final_array.move_to(ORIGIN)\n \n self.play(\n FadeOut(merged_left),\n FadeOut(merged_right),\n FadeIn(final_array),\n run_time=tracker.duration * 0.7\n )\n \n self.wait(0.3)\n \n # Success!\n with self.voiceover(text=\"And there it is! Our array is fully sorted: 3, 9, 10, 27, 38, 43, 82.\") as tracker:\n # Highlight the final sorted array\n success_box = SurroundingRectangle(final_array, color=GOLD, buff=0.15)\n self.play(Create(success_box), run_time=tracker.duration * 0.5)\n \n # Key takeaways\n self.play(FadeOut(merge_label), FadeOut(title), FadeOut(success_box))\n \n with self.voiceover(text=\"Merge Sort has a time complexity of n log n in all cases. The divide phase takes log n levels, and each merge processes all n elements.\") as tracker:\n takeaway_title = Text(\"Key Takeaways\", font_size=30, color=YELLOW)\n takeaway_title.to_edge(UP, buff=0.5)\n \n takeaways = VGroup(\n Text(\"• Divide: Split array in half recursively\", font_size=22),\n Text(\"• Conquer: Merge sorted subarrays\", font_size=22),\n Text(\"• Time Complexity: O(n log n)\", font_size=22),\n Text(\"• Stable: Maintains relative order\", font_size=22),\n ).arrange(DOWN, aligned_edge=LEFT, buff=0.4)\n takeaways.next_to(takeaway_title, DOWN, buff=0.6)\n \n self.play(Write(takeaway_title), run_time=tracker.duration * 0.3)\n for item in takeaways:\n self.play(Write(item), run_time=0.4)\n \n self.wait(0.5)\n \n with self.voiceover(text=\"Merge Sort is efficient, stable, and a perfect example of divide and conquer in action. Thanks for watching!\") as tracker:\n thanks = Text(\"Thanks for learning!\", font_size=28, color=BLUE)\n thanks.move_to(DOWN * 2)\n self.play(Write(thanks), run_time=tracker.duration * 0.7)\n \n self.wait(1)\n \n def create_array(self, values, color=WHITE, scale=1.0):\n \"\"\"Create a visual array of rectangles with numbers.\"\"\"\n squares = VGroup()\n for val in values:\n square = Square(side_length=0.7 * scale, stroke_color=color, fill_color=color, fill_opacity=0.2)\n num = Text(str(val), font_size=20 * scale)\n num.move_to(square.get_center())\n cell = VGroup(square, num)\n squares.add(cell)\n \n squares.arrange(RIGHT, buff=0.05)\n return squares\n```", "category": "legacy_api_hallucination", "source": "synthetic_hard_neg:nabin2004/AOS-Narrated-Manim-400"} +{"system": "You are an expert Manim Community Edition (ManimCE v0.19+) Python developer and mathematical animator. Given a user request, first plan the spatial layout, coordinate bounds, timing, and pedagogical flow inside ... tags (when reasoning is helpful), and then output a complete, runnable, self-contained ManimCE Python script using `from manim import *`. Never use deprecated ManimGL (`manimlib`) methods like `ShowCreation`, `TexMobject`, `TextMobject`, or `axes.get_graph`; always use modern ManimCE APIs (`Create`, `MathTex`, `Tex`, `Text`, `axes.plot`) and prevent visual overlap using `.to_edge()`, `.next_to()`, and `FadeOut`.", "prompt": "You are a Manim expert. Please convert the Markdown lecture notes into executable Manim CE v0.19.0 code that displays content in English. The page layout must be clear, with no overlapping elements, and you must not output any explanatory or descriptive text outside the code. Pay special attention to avoiding common errors such as LaTeX syntax issues and index out-of-range errors, and ensure the code can run directly. The Markdown lecture notes are as follows:\n\n# 4. Visualization of Curl, Vorticity, and Vortex Structures", "chosen": "```python\nfrom manim import *\nfrom manim import config\nText.set_default(font='SimHei')\n\nclass CurlAndVorticity(Scene):\n\n def construct(self):\n title = Tex('\\\\textbf{4. Visualization of Curl, Vorticity, and Vortex Structures}', font_size=36)\n title.to_edge(UP, buff=0.4)\n self.play(Write(title))\n self.wait(1)\n def_group = VGroup()\n curl_def = MathTex('\\\\text{Curl: } \\\\nabla \\\\times \\\\mathbf{F} = \\\\left( \\\\frac{\\\\partial F_y}{\\\\partial x} - \\\\frac{\\\\partial F_x}{\\\\partial y} \\\\right) \\\\mathbf{k} \\\\text{ (in 2D)}', font_size=36)\n vort_def = MathTex('\\\\text{Vorticity: } \\\\vec{\\\\omega} = \\\\nabla \\\\times \\\\vec{v}', font_size=36)\n desc = Text('Vorticity represents the local spinning motion (rotation) of a fluid.', font_size=28, color=BLUE)\n def_group.add(curl_def, vort_def, desc).arrange(DOWN, buff=0.6)\n self.play(FadeIn(def_group, shift=UP))\n self.wait(3)\n self.play(FadeOut(def_group))\n paddle = VGroup(Line(LEFT * 0.3, RIGHT * 0.3), Line(DOWN * 0.3, UP * 0.3)).set_color(RED).set_stroke(width=6)\n uniform_label = Text('Uniform Flow (Zero Curl)', font_size=32, color=YELLOW).next_to(title, DOWN, buff=0.2)\n\n def uniform_func(pos):\n return np.array([2.0, 0.0, 0.0])\n uniform_vf = ArrowVectorField(uniform_func, x_range=[-6, 6, 1], y_range=[-2, 2, 1])\n self.play(Write(uniform_label))\n self.play(FadeIn(uniform_vf))\n self.wait(1)\n paddle.move_to(LEFT * 4)\n paddle_desc = Text('Paddle translates but does NOT rotate (Zero Vorticity)', font_size=24).to_edge(DOWN, buff=0.5)\n self.play(FadeIn(paddle), Write(paddle_desc))\n self.play(paddle.animate.move_to(RIGHT * 4), run_time=4, rate_func=linear)\n self.wait(1)\n self.play(FadeOut(uniform_vf), FadeOut(uniform_label), FadeOut(paddle), FadeOut(paddle_desc))\n rot_label = Text('Rigid Body Rotation (Constant Positive Curl)', font_size=32, color=YELLOW).next_to(title, DOWN, buff=0.2)\n\n def rot_func(pos):\n x, y, z = pos\n return np.array([-y, x, 0]) * 0.4\n rot_vf = ArrowVectorField(rot_func, x_range=[-6, 6, 1], y_range=[-2, 2, 1])\n self.play(Write(rot_label))\n self.play(FadeIn(rot_vf))\n self.wait(1)\n paddle.move_to(ORIGIN)\n paddle_desc2 = Text('Paddle rotates on its own axis -> Positive Curl', font_size=24).to_edge(DOWN, buff=0.5)\n self.play(FadeIn(paddle), Write(paddle_desc2))\n self.play(Rotate(paddle, angle=2 * PI, run_time=3, rate_func=linear))\n self.play(paddle.animate.move_to(RIGHT * 3 + UP * 1))\n self.play(Rotate(paddle, angle=2 * PI, run_time=3, rate_func=linear))\n self.wait(1)\n self.play(FadeOut(rot_vf), FadeOut(rot_label), FadeOut(paddle), FadeOut(paddle_desc2))\n vortex_label = Text('Irrotational Vortex Structure', font_size=32, color=YELLOW).next_to(title, DOWN, buff=0.2)\n\n def vortex_func(pos):\n x, y, z = pos\n r2 = x ** 2 + y ** 2\n if r2 < 0.2:\n return np.array([0.0, 0.0, 0.0])\n else:\n pass\n vec = np.array([-y, x, 0]) * (1.5 / r2)\n mag = np.linalg.norm(vec)\n if mag > 1.5:\n vec = vec / mag * 1.5\n else:\n pass\n return vec\n vortex_vf = ArrowVectorField(vortex_func, x_range=[-6, 6, 1], y_range=[-2, 2, 1])\n self.play(Write(vortex_label))\n self.play(FadeIn(vortex_vf))\n self.wait(1)\n paddle.move_to(RIGHT * 2.5)\n paddle_desc3 = Text('Paddle revolves but maintains orientation -> Zero Local Curl', font_size=24).to_edge(DOWN, buff=0.5)\n self.play(FadeIn(paddle), Write(paddle_desc3))\n circle_path = Circle(radius=2.5).move_to(ORIGIN)\n self.play(MoveAlongPath(paddle, circle_path), run_time=5, rate_func=linear)\n self.wait(1)\n center_dot = Dot(color=RED, radius=0.1)\n singularity_label = Text('Singularity at origin\\n(Infinite curl)', font_size=20, color=RED).next_to(center_dot, UP, buff=0.2)\n self.play(FadeIn(center_dot), Write(singularity_label))\n self.wait(3)\n self.play(*[FadeOut(mob) for mob in self.mobjects])\n```", "rejected": "```python\nfrom manim import *\nfrom manim import config\nText.set_default(font='SimHei')\n\nclass CurlAndVorticity(Scene):\n\n def construct(self):\n title = Tex('\\\\textbf{4. Visualization of Curl, Vorticity, and Vortex Structures}', font_size=36)\n title.to_edge(UP, buff=0.4)\n self.play(Write(title))\n self.wait(1)\n def_group = VGroup()\n curl_def = TexMobject('\\\\text{Curl: } \\\\nabla \\\\times \\\\mathbf{F} = \\\\left( \\\\frac{\\\\partial F_y}{\\\\partial x} - \\\\frac{\\\\partial F_x}{\\\\partial y} \\\\right) \\\\mathbf{k} \\\\text{ (in 2D)}', font_size=36)\n vort_def = MathTex('\\\\text{Vorticity: } \\\\vec{\\\\omega} = \\\\nabla \\\\times \\\\vec{v}', font_size=36)\n desc = Text('Vorticity represents the local spinning motion (rotation) of a fluid.', font_size=28, color=BLUE)\n def_group.add(curl_def, vort_def, desc).arrange(DOWN, buff=0.6)\n self.play(FadeIn(def_group, shift=UP))\n self.wait(3)\n self.play(FadeOut(def_group))\n paddle = VGroup(Line(LEFT * 0.3, RIGHT * 0.3), Line(DOWN * 0.3, UP * 0.3)).set_color(RED).set_stroke(width=6)\n uniform_label = Text('Uniform Flow (Zero Curl)', font_size=32, color=YELLOW).next_to(title, DOWN, buff=0.2)\n\n def uniform_func(pos):\n return np.array([2.0, 0.0, 0.0])\n uniform_vf = ArrowVectorField(uniform_func, x_range=[-6, 6, 1], y_range=[-2, 2, 1])\n self.play(Write(uniform_label))\n self.play(FadeIn(uniform_vf))\n self.wait(1)\n paddle.move_to(LEFT * 4)\n paddle_desc = Text('Paddle translates but does NOT rotate (Zero Vorticity)', font_size=24).to_edge(DOWN, buff=0.5)\n self.play(FadeIn(paddle), Write(paddle_desc))\n self.play(paddle.animate.move_to(RIGHT * 4), run_time=4, rate_func=linear)\n self.wait(1)\n self.play(FadeOut(uniform_vf), FadeOut(uniform_label), FadeOut(paddle), FadeOut(paddle_desc))\n rot_label = Text('Rigid Body Rotation (Constant Positive Curl)', font_size=32, color=YELLOW).next_to(title, DOWN, buff=0.2)\n\n def rot_func(pos):\n x, y, z = pos\n return np.array([-y, x, 0]) * 0.4\n rot_vf = ArrowVectorField(rot_func, x_range=[-6, 6, 1], y_range=[-2, 2, 1])\n self.play(Write(rot_label))\n self.play(FadeIn(rot_vf))\n self.wait(1)\n paddle.move_to(ORIGIN)\n paddle_desc2 = Text('Paddle rotates on its own axis -> Positive Curl', font_size=24).to_edge(DOWN, buff=0.5)\n self.play(FadeIn(paddle), Write(paddle_desc2))\n self.play(Rotate(paddle, angle=2 * PI, run_time=3, rate_func=linear))\n self.play(paddle.animate.move_to(RIGHT * 3 + UP * 1))\n self.play(Rotate(paddle, angle=2 * PI, run_time=3, rate_func=linear))\n self.wait(1)\n self.play(FadeOut(rot_vf), FadeOut(rot_label), FadeOut(paddle), FadeOut(paddle_desc2))\n vortex_label = Text('Irrotational Vortex Structure', font_size=32, color=YELLOW).next_to(title, DOWN, buff=0.2)\n\n def vortex_func(pos):\n x, y, z = pos\n r2 = x ** 2 + y ** 2\n if r2 < 0.2:\n return np.array([0.0, 0.0, 0.0])\n else:\n pass\n vec = np.array([-y, x, 0]) * (1.5 / r2)\n mag = np.linalg.norm(vec)\n if mag > 1.5:\n vec = vec / mag * 1.5\n else:\n pass\n return vec\n vortex_vf = ArrowVectorField(vortex_func, x_range=[-6, 6, 1], y_range=[-2, 2, 1])\n self.play(Write(vortex_label))\n self.play(FadeIn(vortex_vf))\n self.wait(1)\n paddle.move_to(RIGHT * 2.5)\n paddle_desc3 = Text('Paddle revolves but maintains orientation -> Zero Local Curl', font_size=24).to_edge(DOWN, buff=0.5)\n self.play(FadeIn(paddle), Write(paddle_desc3))\n circle_path = Circle(radius=2.5).move_to(ORIGIN)\n self.play(MoveAlongPath(paddle, circle_path), run_time=5, rate_func=linear)\n self.wait(1)\n center_dot = Dot(color=RED, radius=0.1)\n singularity_label = Text('Singularity at origin\\n(Infinite curl)', font_size=20, color=RED).next_to(center_dot, UP, buff=0.2)\n self.play(FadeIn(center_dot), Write(singularity_label))\n self.wait(3)\n self.play(*[FadeOut(mob) for mob in self.mobjects])\n```", "category": "legacy_api_hallucination", "source": "synthetic_hard_neg:nabin2004/manim-sft-10k"} +{"system": "You are an expert Manim Community Edition (ManimCE v0.19+) Python developer and mathematical animator. Given a user request, first plan the spatial layout, coordinate bounds, timing, and pedagogical flow inside ... tags (when reasoning is helpful), and then output a complete, runnable, self-contained ManimCE Python script using `from manim import *`. Never use deprecated ManimGL (`manimlib`) methods like `ShowCreation`, `TexMobject`, `TextMobject`, or `axes.get_graph`; always use modern ManimCE APIs (`Create`, `MathTex`, `Tex`, `Text`, `axes.plot`) and prevent visual overlap using `.to_edge()`, `.next_to()`, and `FadeOut`.", "prompt": "You are a Manim expert. Please convert the Markdown lecture notes into executable Manim CE v0.19.0 code that displays content in English. The page layout must be clear, with no overlapping elements, and you must not output any explanatory or descriptive text outside the code. Pay special attention to avoiding common errors such as LaTeX syntax issues and index out-of-range errors, and ensure the code can run directly. The Markdown lecture notes are as follows:\n\n#### JPEG2000 Overview\n\n##### Wavelet Transform\nUses the Discrete Wavelet Transform (DWT) instead of DCT.\n\n##### Improved Features\nEliminates the $8 \\times 8$ blocking effect, supports Region of Interest (ROI) coding, and offers higher compression efficiency.\n\n##### Use Cases\nDigital cinema, medical imaging, geographic information systems.\n\n\nContextual location of this section (from highest to current level):\n# Lesson 15: Image Compression\n## Main Topics\n### JPEG Compression Standard\n", "chosen": "```python\nfrom manim import *\nfrom manim import config\nText.set_default(font='SimHei')\n\nclass JPEG2000Overview(Scene):\n\n def construct(self):\n\n def create_bullet_item(*text_lines, font_size=28):\n bullet = Tex('$\\\\bullet$', font_size=font_size)\n lines = VGroup(*[Tex(line, font_size=font_size) for line in text_lines])\n lines.arrange(DOWN, aligned_edge=LEFT, buff=0.1)\n item = VGroup(bullet, lines).arrange(RIGHT, aligned_edge=UP, buff=0.2)\n return item\n header = Text('Lesson 15: Image Compression > JPEG Compression Standard', font_size=18, color=GRAY_B)\n header.to_corner(UL)\n title = Text('JPEG2000 Overview', font_size=44, weight=BOLD, color=GOLD)\n title.center().to_edge(UP, buff=0.8)\n s1_title = Text('Wavelet Transform', font_size=32, color=BLUE_C)\n s1_content = create_bullet_item('Uses the Discrete Wavelet Transform (DWT) instead of DCT.')\n s1 = VGroup(s1_title, s1_content).arrange(DOWN, aligned_edge=LEFT, buff=0.2)\n s1_content.shift(RIGHT * 0.5)\n s2_title = Text('Improved Features', font_size=32, color=BLUE_C)\n s2_content = create_bullet_item('Eliminates the $8 \\\\times 8$ blocking effect, supports Region of', 'Interest (ROI) coding, and offers higher compression efficiency.')\n s2 = VGroup(s2_title, s2_content).arrange(DOWN, aligned_edge=LEFT, buff=0.2)\n s2_content.shift(RIGHT * 0.5)\n s3_title = Text('Use Cases', font_size=32, color=BLUE_C)\n s3_content = create_bullet_item('Digital cinema, medical imaging, geographic information systems.')\n s3 = VGroup(s3_title, s3_content).arrange(DOWN, aligned_edge=LEFT, buff=0.2)\n s3_content.shift(RIGHT * 0.5)\n sections = VGroup(s1, s2, s3).arrange(DOWN, aligned_edge=LEFT, buff=0.6)\n sections.next_to(title, DOWN, buff=0.6)\n sections.to_edge(LEFT, buff=1.0)\n self.play(FadeIn(header))\n self.play(Write(title))\n self.wait(0.5)\n for sec in sections:\n self.play(FadeIn(sec[0], shift=RIGHT * 0.3))\n self.play(FadeIn(sec[1], shift=UP * 0.2))\n self.wait(0.5)\n else:\n pass\n self.wait(2)\n```", "rejected": "```python\nfrom manim import *\nfrom manim import config\nText.set_default(font='SimHei')\n\nclass JPEG2000Overview(Scene):\n\n def construct(self):\n\n def create_bullet_item(*text_lines, font_size=28):\n bullet = Tex('$\\\\bullet$', font_size=font_size)\n lines = VGroup(*[Tex(line, font_size=font_size) for line in text_lines])\n lines.arrange(DOWN, aligned_edge=LEFT, buff=0.1)\n item = VGroup(bullet, lines).arrange(RIGHT, aligned_edge=UP, buff=0.2)\n return item\n header = Text('Lesson 15: Image Compression > JPEG Compression Standard', font_size=18, color=GRAY_B)\n header\n title = Text('JPEG2000 Overview', font_size=44, weight=BOLD, color=GOLD)\n title.center()\n s1_title = Text('Wavelet Transform', font_size=32, color=BLUE_C)\n s1_content = create_bullet_item('Uses the Discrete Wavelet Transform (DWT) instead of DCT.')\n s1 = VGroup(s1_title, s1_content).arrange(DOWN, aligned_edge=LEFT, buff=0.2)\n s1_content\n s2_title = Text('Improved Features', font_size=32, color=BLUE_C)\n s2_content = create_bullet_item('Eliminates the $8 \\\\times 8$ blocking effect, supports Region of', 'Interest (ROI) coding, and offers higher compression efficiency.')\n s2 = VGroup(s2_title, s2_content).arrange(DOWN, aligned_edge=LEFT, buff=0.2)\n s2_content.shift(RIGHT * 0.5)\n s3_title = Text('Use Cases', font_size=32, color=BLUE_C)\n s3_content = create_bullet_item('Digital cinema, medical imaging, geographic information systems.')\n s3 = VGroup(s3_title, s3_content).arrange(DOWN, aligned_edge=LEFT, buff=0.2)\n s3_content.shift(RIGHT * 0.5)\n sections = VGroup(s1, s2, s3).arrange(DOWN, aligned_edge=LEFT, buff=0.6)\n sections.next_to(title, DOWN, buff=0.6)\n sections.to_edge(LEFT, buff=1.0)\n self.play(FadeIn(header))\n self.play(Write(title))\n self.wait(0.5)\n for sec in sections:\n self.play(FadeIn(sec[0], shift=RIGHT * 0.3))\n self.play(FadeIn(sec[1], shift=UP * 0.2))\n self.wait(0.5)\n else:\n pass\n self.wait(2)\n```", "category": "spatial_layout_overlap", "source": "synthetic_hard_neg:nabin2004/manim-sft-10k"} +{"system": "You are an expert Manim Community Edition (ManimCE v0.19+) Python developer and mathematical animator. Given a user request, first plan the spatial layout, coordinate bounds, timing, and pedagogical flow inside ... tags (when reasoning is helpful), and then output a complete, runnable, self-contained ManimCE Python script using `from manim import *`. Never use deprecated ManimGL (`manimlib`) methods like `ShowCreation`, `TexMobject`, `TextMobject`, or `axes.get_graph`; always use modern ManimCE APIs (`Create`, `MathTex`, `Tex`, `Text`, `axes.plot`) and prevent visual overlap using `.to_edge()`, `.next_to()`, and `FadeOut`.", "prompt": "I'm teaching an undergrad ML class and want to illustrate numerical stability in softmax. Show a vector of logits, then subtract the maximum before exponentiating, visualizing the shift of the curve downward and the identical probabilities computed; include a comparison of before/after and a note on why max subtraction avoids overflow.", "chosen": "```python\nfrom manim import *\nfrom manim_voiceover import VoiceoverScene\nfrom manim_voiceover.services.gtts import GTTSService\n\nclass NumericalStabilitySoftmaxScene(VoiceoverScene):\n def construct(self):\n self.set_speech_service(\n GTTSService(voice=\"alba\", cache_dir=\"voiceover_cache\")\n )\n\n # ========== TITLE ==========\n title = Text(\"Numerical Stability in Softmax\", font_size=44, color=BLUE)\n subtitle = Text(\"A simple fix for numerical overflow\", font_size=26, color=WHITE)\n subtitle.next_to(title, DOWN, buff=0.25)\n title_group = VGroup(title, subtitle)\n\n with self.voiceover(\n text=\"Imagine training a neural network and hitting exploding gradients or numerical inconsistencies. What if one simple adjustment to the softmax function could prevent these problems?\"\n ) as tracker:\n self.play(FadeIn(title_group), run_time=tracker.duration)\n\n # Move title to top\n with self.voiceover(text=\"Welcome to numerical stability in softmax.\") as tracker:\n self.play(\n title.animate.scale(0.55).to_edge(UP, buff=0.4),\n FadeOut(subtitle),\n run_time=tracker.duration\n )\n title = title # keep reference after animate\n\n # ========== NAIVE SOFTMAX FORMULA ==========\n softmax_formula = MathTex(\n r\"\\text{softmax}(x_i) = \\frac{e^{x_i}}{\\sum_{j} e^{x_j}}\",\n font_size=38\n )\n softmax_formula.next_to(title, DOWN, buff=0.6)\n\n with self.voiceover(\n text=\"The softmax function converts logits into probabilities. The naive formula exponentiates each input and divides by the sum of all exponentials.\"\n ) as tracker:\n self.play(Write(softmax_formula), run_time=tracker.duration)\n\n # ========== THE PROBLEM ==========\n problem_title = Text(\"The Problem: Overflow\", font_size=30, color=RED)\n problem_title.next_to(softmax_formula, DOWN, buff=0.7)\n\n example_logits = MathTex(r\"\\text{logits} = [1000,\\ 1001,\\ 1002]\", font_size=28)\n example_logits.next_to(problem_title, DOWN, buff=0.35)\n\n overflow_arrow = Arrow(\n example_logits.get_bottom(),\n example_logits.get_bottom() + DOWN * 0.9,\n color=RED,\n buff=0.1\n )\n overflow_text = Text(\"e^1000 → Infinity!\", font_size=26, color=RED)\n overflow_text.next_to(overflow_arrow, DOWN, buff=0.1)\n\n with self.voiceover(\n text=\"But here is the catch. When logits are large, say one thousand or more, computing e to that power causes numerical overflow. Your model produces infinity and crashes.\"\n ) as tracker:\n self.play(FadeIn(problem_title), run_time=tracker.duration * 0.25)\n self.play(Write(example_logits), run_time=tracker.duration * 0.25)\n self.play(GrowArrow(overflow_arrow), run_time=tracker.duration * 0.2)\n self.play(FadeIn(overflow_text), run_time=tracker.duration * 0.3)\n\n # ========== THE FIX ==========\n self.play(\n FadeOut(problem_title),\n FadeOut(example_logits),\n FadeOut(overflow_arrow),\n FadeOut(overflow_text),\n run_time=0.4\n )\n\n solution_title = Text(\"The Fix: Subtract the Maximum\", font_size=30, color=GREEN)\n solution_title.next_to(softmax_formula, DOWN, buff=0.7)\n\n shift_formula = MathTex(r\"x'_i = x_i - \\max_j(x_j)\", font_size=34)\n shift_formula.next_to(solution_title, DOWN, buff=0.4)\n\n with self.voiceover(\n text=\"The trick is simple. Subtract the maximum logit from every logit before applying the exponential.\"\n ) as tracker:\n self.play(FadeIn(solution_title), run_time=tracker.duration * 0.4)\n self.play(Write(shift_formula), run_time=tracker.duration * 0.6)\n\n # ========== WHY IT WORKS ==========\n explain_tex = MathTex(r\"e^{x_i - c} = e^{x_i} \\cdot e^{-c}\", font_size=30)\n explain_tex.next_to(shift_formula, DOWN, buff=0.55)\n\n explain_text = Text(\n \"Factor cancels in numerator and denominator\",\n font_size=24,\n color=YELLOW\n )\n explain_text.next_to(explain_tex, DOWN, buff=0.3)\n\n with self.voiceover(\n text=\"Mathematically, subtracting a constant from every exponent just multiplies numerator and denominator by the same constant. Since it appears in every term, the probabilities remain unchanged.\"\n ) as tracker:\n self.play(Write(explain_tex), run_time=tracker.duration * 0.5)\n self.play(FadeIn(explain_text), run_time=tracker.duration * 0.5)\n\n # ========== STABLE FORMULA ==========\n self.play(\n FadeOut(solution_title),\n FadeOut(shift_formula),\n FadeOut(explain_tex),\n FadeOut(explain_text),\n run_time=0.4\n )\n\n stable_formula = MathTex(\n r\"\\text{softmax}(x_i) = \\frac{e^{x_i - \\max(x)}}{\\sum_{j} e^{x_j - \\max(x)}}\",\n font_size=36\n )\n stable_formula.move_to(softmax_formula.get_center())\n\n with self.voiceover(\n text=\"This gives us the numerically stable version of softmax. Every exponent is now less than or equal to zero, so overflow is impossible.\"\n ) as tracker:\n self.play(ReplacementTransform(softmax_formula, stable_formula), run_time=tracker.duration)\n\n # ========== NAIVE VS STABLE COMPARISON ==========\n self.play(FadeOut(stable_formula), run_time=0.3)\n\n naive_box = Rectangle(width=2.6, height=2.0, color=RED)\n stable_box = Rectangle(width=2.6, height=2.0, color=GREEN)\n\n naive_title = Text(\"Naive\", font_size=24, color=RED)\n stable_title = Text(\"Stable\", font_size=24, color=GREEN)\n\n naive_title.move_to(naive_box.get_top() + DOWN * 0.22)\n stable_title.move_to(stable_box.get_top() + DOWN * 0.22)\n\n naive_col = VGroup(naive_box, naive_title)\n stable_col = VGroup(stable_box, stable_title)\n comparison = VGroup(naive_col, stable_col).arrange(RIGHT, buff=0.8)\n comparison.next_to(title, DOWN, buff=0.85)\n\n naive_content = VGroup(\n MathTex(r\"[1000, 1001, 1002]\", font_size=20),\n MathTex(r\"e^{1000} \\to \\infty\", font_size=20, color=RED),\n Text(\"Overflow!\", font_size=22, color=RED)\n ).arrange(DOWN, buff=0.18)\n naive_content.move_to(naive_box.get_center())\n\n stable_content = VGroup(\n MathTex(r\"\\text{shift: } [0, 1, 2]\", font_size=20),\n MathTex(r\"[0.09, 0.24, 0.67]\", font_size=20, color=GREEN),\n Text(\"Valid probs\", font_size=22, color=GREEN)\n ).arrange(DOWN, buff=0.18)\n stable_content.move_to(stable_box.get_center())\n\n with self.voiceover(\n text=\"Compare naive and stable approaches. With logits around one thousand, naive softmax overflows and crashes. The stable version shifts inputs so the largest value becomes zero, then produces valid probabilities safely.\"\n ) as tracker:\n self.play(\n Create(naive_box),\n Create(stable_box),\n FadeIn(naive_title),\n FadeIn(stable_title),\n run_time=tracker.duration * 0.4\n )\n self.play(\n FadeIn(naive_content),\n FadeIn(stable_content),\n run_time=tracker.duration * 0.6\n )\n\n # ========== KEY TAKEAWAYS ==========\n self.play(\n FadeOut(comparison),\n FadeOut(naive_content),\n FadeOut(stable_content),\n run_time=0.4\n )\n\n takeaway_title = Text(\"Key Takeaways\", font_size=32, color=BLUE)\n takeaway_title.next_to(title, DOWN, buff=0.6)\n\n t1 = Text(\"• Naive softmax overflows with large logits\", font_size=24)\n t2 = Text(\"• Subtracting max does not change probabilities\", font_size=24)\n t3 = Text(\"• Always use the stable version in practice\", font_size=24)\n\n takeaways = VGroup(t1, t2, t3).arrange(DOWN, aligned_edge=LEFT, buff=0.35)\n takeaways.next_to(takeaway_title, DOWN, buff=0.4)\n\n with self.voiceover(\n text=\"Here are your key takeaways. First, naive softmax can overflow with large logits. Second, subtracting the maximum does not change the final probabilities. Third, always use the numerically stable version in practice.\"\n ) as tracker:\n self.play(FadeIn(takeaway_title), run_time=tracker.duration * 0.15)\n self.play(FadeIn(t1), run_time=tracker.duration * 0.25)\n self.play(FadeIn(t2), run_time=tracker.duration * 0.25)\n self.play(FadeIn(t3), run_time=tracker.duration * 0.35)\n\n with self.voiceover(text=\"Stable softmax keeps your model safe.\") as tracker:\n self.wait(tracker.duration)\n```", "rejected": "```python\nfrom manim import *\nfrom manim_voiceover import VoiceoverScene\nfrom manim_voiceover.services.gtts import GTTSService\n\nclass NumericalStabilitySoftmaxScene(VoiceoverScene):\n def construct(self):\n self.set_speech_service(\n GTTSService(voice=\"alba\", cache_dir=\"voiceover_cache\")\n )\n\n # ========== TITLE ==========\n title = Text(\"Numerical Stability in Softmax\", font_size=44, color=BLUE)\n subtitle = Text(\"A simple fix for numerical overflow\", font_size=26, color=WHITE)\n subtitle\n title_group = VGroup(title, subtitle)\n\n with self.voiceover(\n text=\"Imagine training a neural network and hitting exploding gradients or numerical inconsistencies. What if one simple adjustment to the softmax function could prevent these problems?\"\n ) as tracker:\n self.play(FadeIn(title_group), run_time=tracker.duration)\n\n # Move title to top\n with self.voiceover(text=\"Welcome to numerical stability in softmax.\") as tracker:\n self.play(\n title.animate.scale(0.55),\n FadeOut(subtitle),\n run_time=tracker.duration\n )\n title = title # keep reference after animate\n\n # ========== NAIVE SOFTMAX FORMULA ==========\n softmax_formula = MathTex(\n r\"\\text{softmax}(x_i) = \\frac{e^{x_i}}{\\sum_{j} e^{x_j}}\",\n font_size=38\n )\n softmax_formula\n\n with self.voiceover(\n text=\"The softmax function converts logits into probabilities. The naive formula exponentiates each input and divides by the sum of all exponentials.\"\n ) as tracker:\n self.play(Write(softmax_formula), run_time=tracker.duration)\n\n # ========== THE PROBLEM ==========\n problem_title = Text(\"The Problem: Overflow\", font_size=30, color=RED)\n problem_title.next_to(softmax_formula, DOWN, buff=0.7)\n\n example_logits = MathTex(r\"\\text{logits} = [1000,\\ 1001,\\ 1002]\", font_size=28)\n example_logits.next_to(problem_title, DOWN, buff=0.35)\n\n overflow_arrow = Arrow(\n example_logits.get_bottom(),\n example_logits.get_bottom() + DOWN * 0.9,\n color=RED,\n buff=0.1\n )\n overflow_text = Text(\"e^1000 → Infinity!\", font_size=26, color=RED)\n overflow_text.next_to(overflow_arrow, DOWN, buff=0.1)\n\n with self.voiceover(\n text=\"But here is the catch. When logits are large, say one thousand or more, computing e to that power causes numerical overflow. Your model produces infinity and crashes.\"\n ) as tracker:\n self.play(FadeIn(problem_title), run_time=tracker.duration * 0.25)\n self.play(Write(example_logits), run_time=tracker.duration * 0.25)\n self.play(GrowArrow(overflow_arrow), run_time=tracker.duration * 0.2)\n self.play(FadeIn(overflow_text), run_time=tracker.duration * 0.3)\n\n # ========== THE FIX ==========\n self.play(\n FadeOut(problem_title),\n FadeOut(example_logits),\n FadeOut(overflow_arrow),\n FadeOut(overflow_text),\n run_time=0.4\n )\n\n solution_title = Text(\"The Fix: Subtract the Maximum\", font_size=30, color=GREEN)\n solution_title.next_to(softmax_formula, DOWN, buff=0.7)\n\n shift_formula = MathTex(r\"x'_i = x_i - \\max_j(x_j)\", font_size=34)\n shift_formula.next_to(solution_title, DOWN, buff=0.4)\n\n with self.voiceover(\n text=\"The trick is simple. Subtract the maximum logit from every logit before applying the exponential.\"\n ) as tracker:\n self.play(FadeIn(solution_title), run_time=tracker.duration * 0.4)\n self.play(Write(shift_formula), run_time=tracker.duration * 0.6)\n\n # ========== WHY IT WORKS ==========\n explain_tex = MathTex(r\"e^{x_i - c} = e^{x_i} \\cdot e^{-c}\", font_size=30)\n explain_tex.next_to(shift_formula, DOWN, buff=0.55)\n\n explain_text = Text(\n \"Factor cancels in numerator and denominator\",\n font_size=24,\n color=YELLOW\n )\n explain_text.next_to(explain_tex, DOWN, buff=0.3)\n\n with self.voiceover(\n text=\"Mathematically, subtracting a constant from every exponent just multiplies numerator and denominator by the same constant. Since it appears in every term, the probabilities remain unchanged.\"\n ) as tracker:\n self.play(Write(explain_tex), run_time=tracker.duration * 0.5)\n self.play(FadeIn(explain_text), run_time=tracker.duration * 0.5)\n\n # ========== STABLE FORMULA ==========\n self.play(\n FadeOut(solution_title),\n FadeOut(shift_formula),\n FadeOut(explain_tex),\n FadeOut(explain_text),\n run_time=0.4\n )\n\n stable_formula = MathTex(\n r\"\\text{softmax}(x_i) = \\frac{e^{x_i - \\max(x)}}{\\sum_{j} e^{x_j - \\max(x)}}\",\n font_size=36\n )\n stable_formula.move_to(softmax_formula.get_center())\n\n with self.voiceover(\n text=\"This gives us the numerically stable version of softmax. Every exponent is now less than or equal to zero, so overflow is impossible.\"\n ) as tracker:\n self.play(ReplacementTransform(softmax_formula, stable_formula), run_time=tracker.duration)\n\n # ========== NAIVE VS STABLE COMPARISON ==========\n self.play(FadeOut(stable_formula), run_time=0.3)\n\n naive_box = Rectangle(width=2.6, height=2.0, color=RED)\n stable_box = Rectangle(width=2.6, height=2.0, color=GREEN)\n\n naive_title = Text(\"Naive\", font_size=24, color=RED)\n stable_title = Text(\"Stable\", font_size=24, color=GREEN)\n\n naive_title.move_to(naive_box.get_top() + DOWN * 0.22)\n stable_title.move_to(stable_box.get_top() + DOWN * 0.22)\n\n naive_col = VGroup(naive_box, naive_title)\n stable_col = VGroup(stable_box, stable_title)\n comparison = VGroup(naive_col, stable_col).arrange(RIGHT, buff=0.8)\n comparison.next_to(title, DOWN, buff=0.85)\n\n naive_content = VGroup(\n MathTex(r\"[1000, 1001, 1002]\", font_size=20),\n MathTex(r\"e^{1000} \\to \\infty\", font_size=20, color=RED),\n Text(\"Overflow!\", font_size=22, color=RED)\n ).arrange(DOWN, buff=0.18)\n naive_content.move_to(naive_box.get_center())\n\n stable_content = VGroup(\n MathTex(r\"\\text{shift: } [0, 1, 2]\", font_size=20),\n MathTex(r\"[0.09, 0.24, 0.67]\", font_size=20, color=GREEN),\n Text(\"Valid probs\", font_size=22, color=GREEN)\n ).arrange(DOWN, buff=0.18)\n stable_content.move_to(stable_box.get_center())\n\n with self.voiceover(\n text=\"Compare naive and stable approaches. With logits around one thousand, naive softmax overflows and crashes. The stable version shifts inputs so the largest value becomes zero, then produces valid probabilities safely.\"\n ) as tracker:\n self.play(\n Create(naive_box),\n Create(stable_box),\n FadeIn(naive_title),\n FadeIn(stable_title),\n run_time=tracker.duration * 0.4\n )\n self.play(\n FadeIn(naive_content),\n FadeIn(stable_content),\n run_time=tracker.duration * 0.6\n )\n\n # ========== KEY TAKEAWAYS ==========\n self.play(\n FadeOut(comparison),\n FadeOut(naive_content),\n FadeOut(stable_content),\n run_time=0.4\n )\n\n takeaway_title = Text(\"Key Takeaways\", font_size=32, color=BLUE)\n takeaway_title.next_to(title, DOWN, buff=0.6)\n\n t1 = Text(\"• Naive softmax overflows with large logits\", font_size=24)\n t2 = Text(\"• Subtracting max does not change probabilities\", font_size=24)\n t3 = Text(\"• Always use the stable version in practice\", font_size=24)\n\n takeaways = VGroup(t1, t2, t3).arrange(DOWN, aligned_edge=LEFT, buff=0.35)\n takeaways.next_to(takeaway_title, DOWN, buff=0.4)\n\n with self.voiceover(\n text=\"Here are your key takeaways. First, naive softmax can overflow with large logits. Second, subtracting the maximum does not change the final probabilities. Third, always use the numerically stable version in practice.\"\n ) as tracker:\n self.play(FadeIn(takeaway_title), run_time=tracker.duration * 0.15)\n self.play(FadeIn(t1), run_time=tracker.duration * 0.25)\n self.play(FadeIn(t2), run_time=tracker.duration * 0.25)\n self.play(FadeIn(t3), run_time=tracker.duration * 0.35)\n\n with self.voiceover(text=\"Stable softmax keeps your model safe.\") as tracker:\n self.wait(tracker.duration)\n```", "category": "spatial_layout_overlap", "source": "synthetic_hard_neg:nabin2004/AOS-Narrated-Manim-400"} +{"system": "You are an expert Manim Community Edition (ManimCE v0.19+) Python developer and mathematical animator. Given a user request, first plan the spatial layout, coordinate bounds, timing, and pedagogical flow inside ... tags (when reasoning is helpful), and then output a complete, runnable, self-contained ManimCE Python script using `from manim import *`. Never use deprecated ManimGL (`manimlib`) methods like `ShowCreation`, `TexMobject`, `TextMobject`, or `axes.get_graph`; always use modern ManimCE APIs (`Create`, `MathTex`, `Tex`, `Text`, `axes.plot`) and prevent visual overlap using `.to_edge()`, `.next_to()`, and `FadeOut`.", "prompt": "The following Manim CE scene failed to compile. Truncated traceback:\n\nTypeError: Mobject.__init__() got an unexpected keyword argument 'max_magnitude'\n\nFix the code. Return a complete working scene. Do not keep the invalid constructor kwargs or Unicode subscripts.\n\n```python\nfrom manim import *\n\nclass IntersectionTheoryScene(Scene):\n def construct(self):\n bad = ArrowVectorField(lambda p: p, max_magnitude=2)\n # Introduction\n title = Text(\"Seeing Intersections Multiplied\", font_size=36)\n subtitle = Text(\"Intersection Theory in Algebraic Geometry\", font_size=24)\n subtitle.next_to(title, DOWN)\n \n # Show title and subtitle\n self.play(Write(title))\n self.play(Write(subtitle))\n self.wait(1)\n self.play(FadeOut(title), FadeOut(subtitle))\n \n # Create coordinate axes\n axes = Axes(\n x_range=[-3, 3, 1],\n y_range=[-2, 6, 1],\n x_length=6,\n y_length=6,\n axis_config={\"color\": BLUE}\n )\n \n # Label axes\n x_label = Text(\"x\", font_size=20).next_to(axes.x_axis, RIGHT)\n y_label = Text(\"y\", font_size=20).next_to(axes.y_axis, UP)\n \n self.play(Create(axes), Write(x_label), Write(y_label))\n \n # PART 1: Simple Intersection (Multiplicity = 1)\n # Create parabola y = x^2\n parabola = axes.plot(lambda x: x**2, x_range=[-2, 2], color=BLUE)\n parabola_label = Text(\"y = x^2\", font_size=20).next_to(parabola, UR)\n \n # Create line y = x + 1\n line = axes.plot(lambda x: x + 1, x_range=[-2, 2], color=RED)\n line_label = Text(\"y = x + 1\", font_size=20).next_to(line, RIGHT)\n \n # Display curves\n self.play(Create(parabola), Write(parabola_label))\n self.play(Create(line), Write(line_label))\n \n # Highlight intersection at (1, 2)\n intersection_point = axes.coords_to_point(1, 2)\n intersection_dot = Dot(intersection_point, color=YELLOW)\n mult_label = Text(\"Multiplicity = 1\", font_size=16).next_to(intersection_dot, UP)\n \n self.play(Create(intersection_dot), Write(mult_label))\n \n # Show explanation\n explanation1 = Text(\"When curves cross cleanly, multiplicity = 1\", font_size=24)\n explanation1.to_edge(DOWN)\n self.play(Write(explanation1))\n self.wait(2)\n \n # Clean up for next part\n self.play(\n FadeOut(line), \n FadeOut(line_label), \n FadeOut(intersection_dot),\n FadeOut(mult_label),\n FadeOut(explanation1)\n )\n \n # PART 2: Tangent Intersection (Multiplicity = 2)\n # Create horizontal line y = 0.1 (near-tangent to parabola at origin for better visibility)\n tangent_line = axes.plot(lambda x: 0.1, x_range=[-2, 2], color=GREEN)\n tangent_label = Text(\"y = 0 (tangent)\", font_size=20).next_to(tangent_line, RIGHT)\n \n self.play(Create(tangent_line), Write(tangent_label))\n \n # Highlight tangent point at origin (0, 0)\n tangent_point = axes.coords_to_point(0, 0)\n tangent_dot = Dot(tangent_point, color=YELLOW)\n mult2_label = Text(\"Multiplicity = 2\", font_size=16).next_to(tangent_dot, UP)\n \n self.play(Create(tangent_dot), Write(mult2_label))\n \n # Show explanation\n explanation2 = Text(\"When curves are tangent, multiplicity > 1\", font_size=24)\n explanation2.to_edge(DOWN)\n self.play(Write(explanation2))\n self.wait(2)\n \n # Conclusion\n self.play(\n FadeOut(parabola),\n FadeOut(parabola_label),\n FadeOut(tangent_line),\n FadeOut(tangent_label),\n FadeOut(tangent_dot),\n FadeOut(mult2_label),\n FadeOut(explanation2),\n FadeOut(axes),\n FadeOut(x_label),\n FadeOut(y_label)\n )\n \n # Final message\n conclusion = Text(\"Understanding multiplicity reveals\\nthe depth of geometric intersections\", font_size=32)\n \n self.play(Write(conclusion))\n self.wait(2)\n self.play(FadeOut(conclusion))\n```", "chosen": "```python\nfrom manim import *\n\nclass IntersectionTheoryScene(Scene):\n def construct(self):\n # Introduction\n title = Text(\"Seeing Intersections Multiplied\", font_size=36)\n subtitle = Text(\"Intersection Theory in Algebraic Geometry\", font_size=24)\n subtitle.next_to(title, DOWN)\n \n # Show title and subtitle\n self.play(Write(title))\n self.play(Write(subtitle))\n self.wait(1)\n self.play(FadeOut(title), FadeOut(subtitle))\n \n # Create coordinate axes\n axes = Axes(\n x_range=[-3, 3, 1],\n y_range=[-2, 6, 1],\n x_length=6,\n y_length=6,\n axis_config={\"color\": BLUE}\n )\n \n # Label axes\n x_label = Text(\"x\", font_size=20).next_to(axes.x_axis, RIGHT)\n y_label = Text(\"y\", font_size=20).next_to(axes.y_axis, UP)\n \n self.play(Create(axes), Write(x_label), Write(y_label))\n \n # PART 1: Simple Intersection (Multiplicity = 1)\n # Create parabola y = x^2\n parabola = axes.plot(lambda x: x**2, x_range=[-2, 2], color=BLUE)\n parabola_label = Text(\"y = x^2\", font_size=20).next_to(parabola, UR)\n \n # Create line y = x + 1\n line = axes.plot(lambda x: x + 1, x_range=[-2, 2], color=RED)\n line_label = Text(\"y = x + 1\", font_size=20).next_to(line, RIGHT)\n \n # Display curves\n self.play(Create(parabola), Write(parabola_label))\n self.play(Create(line), Write(line_label))\n \n # Highlight intersection at (1, 2)\n intersection_point = axes.coords_to_point(1, 2)\n intersection_dot = Dot(intersection_point, color=YELLOW)\n mult_label = Text(\"Multiplicity = 1\", font_size=16).next_to(intersection_dot, UP)\n \n self.play(Create(intersection_dot), Write(mult_label))\n \n # Show explanation\n explanation1 = Text(\"When curves cross cleanly, multiplicity = 1\", font_size=24)\n explanation1.to_edge(DOWN)\n self.play(Write(explanation1))\n self.wait(2)\n \n # Clean up for next part\n self.play(\n FadeOut(line), \n FadeOut(line_label), \n FadeOut(intersection_dot),\n FadeOut(mult_label),\n FadeOut(explanation1)\n )\n \n # PART 2: Tangent Intersection (Multiplicity = 2)\n # Create horizontal line y = 0.1 (near-tangent to parabola at origin for better visibility)\n tangent_line = axes.plot(lambda x: 0.1, x_range=[-2, 2], color=GREEN)\n tangent_label = Text(\"y = 0 (tangent)\", font_size=20).next_to(tangent_line, RIGHT)\n \n self.play(Create(tangent_line), Write(tangent_label))\n \n # Highlight tangent point at origin (0, 0)\n tangent_point = axes.coords_to_point(0, 0)\n tangent_dot = Dot(tangent_point, color=YELLOW)\n mult2_label = Text(\"Multiplicity = 2\", font_size=16).next_to(tangent_dot, UP)\n \n self.play(Create(tangent_dot), Write(mult2_label))\n \n # Show explanation\n explanation2 = Text(\"When curves are tangent, multiplicity > 1\", font_size=24)\n explanation2.to_edge(DOWN)\n self.play(Write(explanation2))\n self.wait(2)\n \n # Conclusion\n self.play(\n FadeOut(parabola),\n FadeOut(parabola_label),\n FadeOut(tangent_line),\n FadeOut(tangent_label),\n FadeOut(tangent_dot),\n FadeOut(mult2_label),\n FadeOut(explanation2),\n FadeOut(axes),\n FadeOut(x_label),\n FadeOut(y_label)\n )\n \n # Final message\n conclusion = Text(\"Understanding multiplicity reveals\\nthe depth of geometric intersections\", font_size=32)\n \n self.play(Write(conclusion))\n self.wait(2)\n self.play(FadeOut(conclusion))\n```", "rejected": "```python\nfrom manim import *\n\nclass IntersectionTheoryScene(Scene):\n def construct(self):\n # Introduction\n title = Text(\"Seeing Intersections Multiplied\", font_size=36)\n subtitle = Text(\"Intersection Theory in Algebraic Geometry\", font_size=24)\n subtitle.next_to(title, DOWN)\n \n # Show title and subtitle\n self.play(Write(title))\n self.play(Write(subtitle))\n self.wait(1)\n self.play(FadeOut(title), FadeOut(subtitle))\n \n # Create coordinate axes\n axes = Axes(\n x_range=[-3, 3, 1],\n y_range=[-2, 6, 1],\n x_length=6,\n y_length=6,\n axis_config={\"color\": BLUE}\n )\n \n # Label axes\n x_label = Text(\"x\", font_size=20).next_to(axes.x_axis, RIGHT)\n y_label = Text(\"y\", font_size=20).next_to(axes.y_axis, UP)\n \n self.play(ShowCreation(axes), Write(x_label), Write(y_label))\n \n # PART 1: Simple Intersection (Multiplicity = 1)\n # Create parabola y = x^2\n parabola = axes.get_graph(lambda x: x**2, x_range=[-2, 2], color=BLUE)\n parabola_label = Text(\"y = x^2\", font_size=20).next_to(parabola, UR)\n \n # Create line y = x + 1\n line = axes.plot(lambda x: x + 1, x_range=[-2, 2], color=RED)\n line_label = Text(\"y = x + 1\", font_size=20).next_to(line, RIGHT)\n \n # Display curves\n self.play(Create(parabola), Write(parabola_label))\n self.play(Create(line), Write(line_label))\n \n # Highlight intersection at (1, 2)\n intersection_point = axes.coords_to_point(1, 2)\n intersection_dot = Dot(intersection_point, color=YELLOW)\n mult_label = Text(\"Multiplicity = 1\", font_size=16).next_to(intersection_dot, UP)\n \n self.play(Create(intersection_dot), Write(mult_label))\n \n # Show explanation\n explanation1 = Text(\"When curves cross cleanly, multiplicity = 1\", font_size=24)\n explanation1.to_edge(DOWN)\n self.play(Write(explanation1))\n self.wait(2)\n \n # Clean up for next part\n self.play(\n FadeOut(line), \n FadeOut(line_label), \n FadeOut(intersection_dot),\n FadeOut(mult_label),\n FadeOut(explanation1)\n )\n \n # PART 2: Tangent Intersection (Multiplicity = 2)\n # Create horizontal line y = 0.1 (near-tangent to parabola at origin for better visibility)\n tangent_line = axes.plot(lambda x: 0.1, x_range=[-2, 2], color=GREEN)\n tangent_label = Text(\"y = 0 (tangent)\", font_size=20).next_to(tangent_line, RIGHT)\n \n self.play(Create(tangent_line), Write(tangent_label))\n \n # Highlight tangent point at origin (0, 0)\n tangent_point = axes.coords_to_point(0, 0)\n tangent_dot = Dot(tangent_point, color=YELLOW)\n mult2_label = Text(\"Multiplicity = 2\", font_size=16).next_to(tangent_dot, UP)\n \n self.play(Create(tangent_dot), Write(mult2_label))\n \n # Show explanation\n explanation2 = Text(\"When curves are tangent, multiplicity > 1\", font_size=24)\n explanation2.to_edge(DOWN)\n self.play(Write(explanation2))\n self.wait(2)\n \n # Conclusion\n self.play(\n FadeOut(parabola),\n FadeOut(parabola_label),\n FadeOut(tangent_line),\n FadeOut(tangent_label),\n FadeOut(tangent_dot),\n FadeOut(mult2_label),\n FadeOut(explanation2),\n FadeOut(axes),\n FadeOut(x_label),\n FadeOut(y_label)\n )\n \n # Final message\n conclusion = Text(\"Understanding multiplicity reveals\\nthe depth of geometric intersections\", font_size=32)\n \n self.play(Write(conclusion))\n self.wait(2)\n self.play(FadeOut(conclusion))\n```", "category": "legacy_api_hallucination", "source": "synthetic_hard_neg:nabin2004/manim-sft-10k"} +{"system": "You are an expert Manim Community Edition (ManimCE v0.19+) Python developer and mathematical animator. Given a user request, first plan the spatial layout, coordinate bounds, timing, and pedagogical flow inside ... tags (when reasoning is helpful), and then output a complete, runnable, self-contained ManimCE Python script using `from manim import *`. Never use deprecated ManimGL (`manimlib`) methods like `ShowCreation`, `TexMobject`, `TextMobject`, or `axes.get_graph`; always use modern ManimCE APIs (`Create`, `MathTex`, `Tex`, `Text`, `axes.plot`) and prevent visual overlap using `.to_edge()`, `.next_to()`, and `FadeOut`.", "prompt": "You are a Manim expert. Please convert the Markdown lecture notes into executable Manim CE v0.19.0 code that displays content in English. The page layout must be clear, with no overlapping elements, and you must not output any explanatory or descriptive text outside the code. Pay special attention to avoiding common errors such as LaTeX syntax issues and index out-of-range errors, and ensure the code can run directly. The Markdown lecture notes are as follows:\n\n#### Chebyshev I Filter\n##### Characteristics of Chebyshev I Filter\nIt has an equiripple characteristic in the passband and a monotonic decrease in the stopband.\n##### Equiripple Characteristic\nThe ideal characteristic is approximated using Chebyshev polynomials $T_N(x)$, sacrificing flatness in the passband for a steeper transition band.\n##### Design Method\n$$ |H_a(j\\Omega)|^2 = \\frac{1}{1 + \\epsilon^2 T_N^2(\\frac{\\Omega}{\\Omega_p})} $$\nwhere $\\epsilon$ controls the ripple size.\n##### Comparison with Butterworth\nUnder the same specifications, the order of a Chebyshev filter is usually lower than that of a Butterworth filter, but it has more severe phase nonlinearity.\n\n\nThe context location of this section (from highest to current level):\n# Digital Filter Design (I)\n## Main Content\n### Analog Filter Design\n", "chosen": "```python\nfrom manim import *\nfrom manim import config\nText.set_default(font='SimHei')\n\nclass ChebyshevFilter(Scene):\n\n def construct(self):\n context = Tex('Digital Filter Design (I) $\\\\triangleright$ Analog Filter Design', font_size=24, color=GRAY)\n context.to_corner(UL)\n self.add(context)\n title = Title('Chebyshev I Filter')\n self.play(Write(title))\n section1_title = Tex('Characteristics \\\\& Equiripple Property', color=BLUE).scale(0.9)\n section1_title.next_to(title, DOWN, buff=0.5).to_edge(LEFT, buff=1)\n blist1 = BulletedList('Equiripple characteristic in the passband.', 'Monotonic decrease in the stopband.', 'Approximated using Chebyshev polynomials $T_N(x)$.', 'Sacrifices passband flatness for a steeper transition band.', font_size=36)\n blist1.next_to(section1_title, DOWN, buff=0.5).align_to(section1_title, LEFT)\n self.play(FadeIn(section1_title, shift=RIGHT))\n self.play(Write(blist1), run_time=4)\n self.wait(2)\n self.play(FadeOut(section1_title), FadeOut(blist1))\n section2_title = Tex('Design Method', color=BLUE).scale(0.9)\n section2_title.next_to(title, DOWN, buff=0.5).to_edge(LEFT, buff=1)\n formula = MathTex('|H_a(j\\\\Omega)|^2 = \\\\frac{1}{1 + \\\\epsilon^2 T_N^2\\\\left(\\\\frac{\\\\Omega}{\\\\Omega_p}\\\\right)}').scale(1.2)\n formula.move_to(ORIGIN)\n desc = Tex('where $\\\\epsilon$ controls the ripple size.', font_size=36)\n desc.next_to(formula, DOWN, buff=0.8)\n self.play(FadeIn(section2_title, shift=RIGHT))\n self.play(Write(formula))\n self.play(FadeIn(desc, shift=UP))\n self.wait(2)\n self.play(FadeOut(section2_title), FadeOut(formula), FadeOut(desc))\n section3_title = Tex('Comparison with Butterworth', color=BLUE).scale(0.9)\n section3_title.next_to(title, DOWN, buff=0.5).to_edge(LEFT, buff=1)\n blist3 = BulletedList('Under the same specifications, the order is usually lower.', 'Has more severe phase nonlinearity.', font_size=36)\n blist3.next_to(section3_title, DOWN, buff=0.5).align_to(section3_title, LEFT)\n self.play(FadeIn(section3_title, shift=RIGHT))\n self.play(Write(blist3), run_time=2)\n self.wait(3)\n self.play(FadeOut(Group(*self.mobjects)))\n```", "rejected": "```python\nfrom manim import *\nfrom manim import config\nText.set_default(font='SimHei')\n\nclass ChebyshevFilter(Scene):\n\n def construct(self):\n context = Tex('Digital Filter Design (I) $\\\\triangleright$ Analog Filter Design', font_size=24, color=GRAY)\n context\n self.add(context)\n title = Title('Chebyshev I Filter')\n self.play(Write(title))\n section1_title = Tex('Characteristics \\\\& Equiripple Property', color=BLUE).scale(0.9)\n section1_title\n blist1 = BulletedList('Equiripple characteristic in the passband.', 'Monotonic decrease in the stopband.', 'Approximated using Chebyshev polynomials $T_N(x)$.', 'Sacrifices passband flatness for a steeper transition band.', font_size=36)\n blist1.next_to(section1_title, DOWN, buff=0.5).align_to(section1_title, LEFT)\n self.play(FadeIn(section1_title, shift=RIGHT))\n self.play(Write(blist1), run_time=4)\n self.wait(2)\n self.play(FadeOut(section1_title), FadeOut(blist1))\n section2_title = Tex('Design Method', color=BLUE).scale(0.9)\n section2_title.next_to(title, DOWN, buff=0.5).to_edge(LEFT, buff=1)\n formula = MathTex('|H_a(j\\\\Omega)|^2 = \\\\frac{1}{1 + \\\\epsilon^2 T_N^2\\\\left(\\\\frac{\\\\Omega}{\\\\Omega_p}\\\\right)}').scale(1.2)\n formula.move_to(ORIGIN)\n desc = Tex('where $\\\\epsilon$ controls the ripple size.', font_size=36)\n desc.next_to(formula, DOWN, buff=0.8)\n self.play(FadeIn(section2_title, shift=RIGHT))\n self.play(Write(formula))\n self.play(FadeIn(desc, shift=UP))\n self.wait(2)\n self.play(FadeOut(section2_title), FadeOut(formula), FadeOut(desc))\n section3_title = Tex('Comparison with Butterworth', color=BLUE).scale(0.9)\n section3_title.next_to(title, DOWN, buff=0.5).to_edge(LEFT, buff=1)\n blist3 = BulletedList('Under the same specifications, the order is usually lower.', 'Has more severe phase nonlinearity.', font_size=36)\n blist3.next_to(section3_title, DOWN, buff=0.5).align_to(section3_title, LEFT)\n self.play(FadeIn(section3_title, shift=RIGHT))\n self.play(Write(blist3), run_time=2)\n self.wait(3)\n self.play(FadeOut(Group(*self.mobjects)))\n```", "category": "spatial_layout_overlap", "source": "synthetic_hard_neg:nabin2004/manim-sft-10k"} +{"system": "You are an expert Manim Community Edition (ManimCE v0.19+) Python developer and mathematical animator. Given a user request, first plan the spatial layout, coordinate bounds, timing, and pedagogical flow inside ... tags (when reasoning is helpful), and then output a complete, runnable, self-contained ManimCE Python script using `from manim import *`. Never use deprecated ManimGL (`manimlib`) methods like `ShowCreation`, `TexMobject`, `TextMobject`, or `axes.get_graph`; always use modern ManimCE APIs (`Create`, `MathTex`, `Tex`, `Text`, `axes.plot`) and prevent visual overlap using `.to_edge()`, `.next_to()`, and `FadeOut`.", "prompt": "I'm teaching a course on numerical stability in neural nets and want to visualize log_softmax on a vector, emphasizing the max-subtraction trick and how it prevents overflow.", "chosen": "```python\nfrom manim import *\nfrom manim_voiceover import VoiceoverScene\nfrom manim_voiceover.services.gtts import GTTSService\n\nclass NumericalStabilityBoard(VoiceoverScene):\n def construct(self):\n self.set_speech_service(\n GTTSService(voice=\"alba\", cache_dir=\"voiceover_cache\")\n )\n \n # ============ TITLE SECTION ============\n title = Text(\"Numerical Stability in Neural Networks\", font_size=44, color=BLUE)\n subtitle = Text(\"Why Precision Matters in Deep Learning\", font_size=28, color=GRAY)\n subtitle.next_to(title, DOWN, buff=0.3)\n title_group = VGroup(title, subtitle)\n \n with self.voiceover(\n text=\"Have you ever wondered why some neural networks perform flawlessly while others fail spectacularly? The answer often lies in numerical stability.\"\n ) as tracker:\n self.play(Write(title), run_time=tracker.duration * 0.6)\n self.play(FadeIn(subtitle), run_time=tracker.duration * 0.4)\n \n with self.voiceover(\n text=\"In this lecture, you will find out why maintaining numerical stability is vital for training deep learning models and how small errors can lead to catastrophic outcomes.\"\n ) as tracker:\n self.wait(tracker.duration)\n \n self.play(FadeOut(title_group))\n \n # ============ WHAT IS NUMERICAL STABILITY ============\n stability_title = Text(\"What is Numerical Stability?\", font_size=36, color=BLUE)\n stability_title.to_edge(UP, buff=0.5)\n \n with self.voiceover(\n text=\"Numerical stability refers to how errors propagate through computations. A numerically stable algorithm ensures that small changes in input don't cause large changes in output.\"\n ) as tracker:\n self.play(Write(stability_title), run_time=tracker.duration * 0.4)\n \n # Create visual representation of stable vs unstable\n stable_box = Rectangle(width=3, height=2, color=GREEN, fill_opacity=0.2)\n unstable_box = Rectangle(width=3, height=2, color=RED, fill_opacity=0.2)\n \n stable_label = Text(\"Stable\", font_size=24, color=GREEN)\n unstable_label = Text(\"Unstable\", font_size=24, color=RED)\n \n stable_box.shift(LEFT * 3)\n unstable_box.shift(RIGHT * 3)\n stable_label.move_to(stable_box.get_center())\n unstable_label.move_to(unstable_box.get_center())\n \n stable_group = VGroup(stable_box, stable_label)\n unstable_group = VGroup(unstable_box, unstable_label)\n \n # Input arrows\n small_input = MathTex(r\"\\text{small } \\\\ \\epsilon\", font_size=20)\n small_input.next_to(stable_box, LEFT, buff=0.5)\n \n large_input = MathTex(r\"\\text{small } \\\\ \\epsilon\", font_size=20)\n large_input.next_to(unstable_box, LEFT, buff=0.5)\n \n with self.voiceover(\n text=\"In a stable system, small input perturbations lead to small output changes.\"\n ) as tracker:\n self.play(Create(stable_group), run_time=tracker.duration * 0.5)\n self.play(FadeIn(small_input), run_time=tracker.duration * 0.25)\n arrow1 = Arrow(small_input.get_right(), stable_box.get_left(), buff=0.1, color=GREEN)\n self.play(Create(arrow1), run_time=tracker.duration * 0.25)\n \n # Output for stable\n small_output = MathTex(r\"\\text{small } \\\\ \\Delta\", font_size=20)\n small_output.next_to(stable_box, RIGHT, buff=0.5)\n arrow2 = Arrow(stable_box.get_right(), small_output.get_left(), buff=0.1, color=GREEN)\n \n with self.voiceover(\n text=\"But in an unstable system, the same small errors can explode into catastrophic failures.\"\n ) as tracker:\n self.play(Create(unstable_group), run_time=tracker.duration * 0.3)\n self.play(FadeIn(large_input), run_time=tracker.duration * 0.2)\n arrow3 = Arrow(large_input.get_right(), unstable_box.get_left(), buff=0.1, color=RED)\n self.play(Create(arrow3), run_time=tracker.duration * 0.2)\n \n large_output = MathTex(r\"\\text{HUGE } \\\\ \\Delta!\", font_size=24, color=RED)\n large_output.next_to(unstable_box, RIGHT, buff=0.5)\n arrow4 = Arrow(unstable_box.get_right(), large_output.get_left(), buff=0.1, color=RED)\n self.play(FadeIn(large_output), Create(arrow4), run_time=tracker.duration * 0.3)\n \n self.play(FadeIn(small_output), Create(arrow2))\n \n with self.voiceover(\n text=\"This is especially critical in neural networks where we chain thousands of operations together.\"\n ) as tracker:\n self.wait(tracker.duration)\n \n self.play(FadeOut(stability_title, stable_group, unstable_group, \n small_input, large_input, small_output, large_output,\n arrow1, arrow2, arrow3, arrow4))\n \n # ============ COMMON SOURCES OF INSTABILITY ============\n causes_title = Text(\"Common Sources of Instability\", font_size=36, color=BLUE)\n causes_title.to_edge(UP, buff=0.5)\n \n with self.voiceover(\n text=\"Let's explore the most common sources of numerical instability in neural networks.\"\n ) as tracker:\n self.play(Write(causes_title), run_time=tracker.duration)\n \n # Create 2x2 grid of causes\n causes = [\n (\"Overflow\", \"Values become too large\", RED),\n (\"Underflow\", \"Values become too small\", ORANGE),\n (\"Vanishing Gradients\", \"Gradients approach zero\", YELLOW),\n (\"Exploding Gradients\", \"Gradients grow exponentially\", PURPLE)\n ]\n \n cause_boxes = VGroup()\n for i, (name, desc, color) in enumerate(causes):\n box = RoundedRectangle(width=5.5, height=1.5, color=color, fill_opacity=0.15, corner_radius=0.2)\n title_text = Text(name, font_size=22, color=color, weight=BOLD)\n desc_text = Text(desc, font_size=18, color=WHITE)\n title_text.move_to(box.get_center() + UP * 0.3)\n desc_text.move_to(box.get_center() + DOWN * 0.3)\n group = VGroup(box, title_text, desc_text)\n cause_boxes.add(group)\n \n cause_boxes.arrange_in_grid(rows=2, cols=2, buff=0.4)\n cause_boxes.move_to(ORIGIN)\n \n with self.voiceover(\n text=\"First, overflow occurs when activations or weights grow beyond representable limits.\"\n ) as tracker:\n self.play(FadeIn(cause_boxes[0]), run_time=tracker.duration)\n \n with self.voiceover(\n text=\"Underflow is the opposite, where values become so small they round to zero.\"\n ) as tracker:\n self.play(FadeIn(cause_boxes[1]), run_time=tracker.duration)\n \n with self.voiceover(\n text=\"Vanishing gradients happen when derivatives become nearly zero, stopping learning in early layers.\"\n ) as tracker:\n self.play(FadeIn(cause_boxes[2]), run_time=tracker.duration)\n \n with self.voiceover(\n text=\"Exploding gradients cause weights to update by huge amounts, making training unstable.\"\n ) as tracker:\n self.play(FadeIn(cause_boxes[3]), run_time=tracker.duration)\n \n self.play(FadeOut(causes_title, cause_boxes))\n \n # ============ MATHEMATICAL EXPLANATION ============\n math_title = Text(\"The Mathematics Behind Instability\", font_size=36, color=BLUE)\n math_title.to_edge(UP, buff=0.5)\n \n with self.voiceover(\n text=\"Mathematically, instability often appears in the forward and backward passes.\"\n ) as tracker:\n self.play(Write(math_title), run_time=tracker.duration)\n \n # Forward pass equation\n forward_eq = MathTex(\n r\"z^{[l]} = W^{[l]} a^{[l-1]} + b^{[l]}\",\n font_size=32\n )\n forward_eq.shift(UP * 1.5)\n \n activation_eq = MathTex(\n r\"a^{[l]} = \\sigma(z^{[l]})\",\n font_size=32\n )\n activation_eq.next_to(forward_eq, DOWN, buff=0.5)\n \n with self.voiceover(\n text=\"In the forward pass, we compute pre-activations z by multiplying weights with previous activations.\"\n ) as tracker:\n self.play(Write(forward_eq), run_time=tracker.duration * 0.6)\n \n with self.voiceover(\n text=\"Then apply an activation function sigma. If weights are large, z can explode layer by layer.\"\n ) as tracker:\n self.play(Write(activation_eq), run_time=tracker.duration * 0.6)\n \n # Gradient descent update\n self.play(FadeOut(forward_eq, activation_eq))\n \n grad_eq = MathTex(\n r\"\\theta_{new} = \\theta_{old} - \\eta \\nabla_{\\theta} L\",\n font_size=32\n )\n grad_eq.shift(UP * 0.5)\n \n with self.voiceover(\n text=\"During backpropagation, we use gradient descent to update parameters. The gradient of the loss with respect to weights must be stable.\"\n ) as tracker:\n self.play(Write(grad_eq), run_time=tracker.duration * 0.7)\n \n chain_rule = MathTex(\n r\"\\frac{\\partial L}{\\partial W^{[l]}} = \\frac{\\partial L}{\\partial a^{[L]}} \\cdot \\prod_{k=l+1}^{L} \\frac{\\partial a^{[k]}}{\\partial z^{[k]}} W^{[k]}\",\n font_size=26\n )\n chain_rule.next_to(grad_eq, DOWN, buff=0.8)\n \n with self.voiceover(\n text=\"Through the chain rule, gradients depend on products of Jacobian matrices across all layers. If any eigenvalue exceeds one, gradients explode.\"\n ) as tracker:\n self.play(Write(chain_rule), run_time=tracker.duration)\n \n self.play(FadeOut(math_title, grad_eq, chain_rule))\n \n # ============ STRATEGIES FOR STABILITY ============\n strategies_title = Text(\"Strategies for Numerical Stability\", font_size=36, color=BLUE)\n strategies_title.to_edge(UP, buff=0.5)\n \n with self.voiceover(\n text=\"Now let's discuss proven strategies to maintain numerical stability in your neural networks.\"\n ) as tracker:\n self.play(Write(strategies_title), run_time=tracker.duration)\n \n # Strategy boxes in two columns\n left_strategies = VGroup()\n right_strategies = VGroup()\n \n strategies_left = [\n (\"Weight Initialization\", \"Xavier, He init\", GREEN),\n (\"Activation Functions\", \"ReLU, Leaky ReLU, GELU\", TEAL)\n ]\n strategies_right = [\n (\"Batch Normalization\", \"Normalize activations\", BLUE),\n (\"Gradient Clipping\", \"Cap gradient magnitude\", PURPLE)\n ]\n \n for name, desc, color in strategies_left:\n box = RoundedRectangle(width=5, height=1.3, color=color, fill_opacity=0.15, corner_radius=0.15)\n name_text = Text(name, font_size=20, color=color, weight=BOLD)\n desc_text = Text(desc, font_size=16, color=WHITE)\n name_text.move_to(box.get_center() + UP * 0.25)\n desc_text.move_to(box.get_center() + DOWN * 0.25)\n group = VGroup(box, name_text, desc_text)\n left_strategies.add(group)\n \n for name, desc, color in strategies_right:\n box = RoundedRectangle(width=5, height=1.3, color=color, fill_opacity=0.15, corner_radius=0.15)\n name_text = Text(name, font_size=20, color=color, weight=BOLD)\n desc_text = Text(desc, font_size=16, color=WHITE)\n name_text.move_to(box.get_center() + UP * 0.25)\n desc_text.move_to(box.get_center() + DOWN * 0.25)\n group = VGroup(box, name_text, desc_text)\n right_strategies.add(group)\n \n left_strategies.arrange(DOWN, buff=0.3)\n right_strategies.arrange(DOWN, buff=0.3)\n \n left_strategies.shift(LEFT * 3 + DOWN * 0.5)\n right_strategies.shift(RIGHT * 3 + DOWN * 0.5)\n \n all_strategies = VGroup(left_strategies, right_strategies)\n \n with self.voiceover(\n text=\"First, proper weight initialization using Xavier or He methods keeps initial activations in a healthy range.\"\n ) as tracker:\n self.play(FadeIn(left_strategies[0]), run_time=tracker.duration)\n \n with self.voiceover(\n text=\"Choosing the right activation function matters. ReLU and its variants prevent vanishing gradients better than sigmoid.\"\n ) as tracker:\n self.play(FadeIn(left_strategies[1]), run_time=tracker.duration)\n \n with self.voiceover(\n text=\"Batch normalization normalizes layer inputs, dramatically improving training stability and speed.\"\n ) as tracker:\n self.play(FadeIn(right_strategies[0]), run_time=tracker.duration)\n \n with self.voiceover(\n text=\"Gradient clipping caps the maximum gradient magnitude, preventing explosive updates during training.\"\n ) as tracker:\n self.play(FadeIn(right_strategies[1]), run_time=tracker.duration)\n \n self.play(FadeOut(strategies_title, all_strategies))\n \n # ============ SUMMARY ============\n summary_title = Text(\"Key Takeaways\", font_size=36, color=BLUE)\n summary_title.to_edge(UP, buff=0.5)\n \n with self.voiceover(\n text=\"Let's summarize what we've learned about numerical stability.\"\n ) as tracker:\n self.play(Write(summary_title), run_time=tracker.duration)\n \n takeaways = VGroup()\n takeaway_texts = [\n \"• Avoid overflow and underflow by monitoring activations\",\n \"• Use proper weight initialization techniques\",\n \"• Choose activation functions that prevent vanishing gradients\",\n \"• Apply batch normalization for stable training\",\n \"• Implement gradient clipping to prevent explosions\"\n ]\n \n for text in takeaway_texts:\n t = Text(text, font_size=22, color=WHITE)\n takeaways.add(t)\n \n takeaways.arrange(DOWN, buff=0.35, aligned_edge=LEFT)\n takeaways.move_to(ORIGIN)\n \n for i, takeaway in enumerate(takeaways):\n with self.voiceover(\n text=takeaway_texts[i].replace(\"• \", \"\").replace(\"by monitoring\", \". Monitor\").replace(\"techniques\", \"\").replace(\"for stable training\", \"\").replace(\"to prevent explosions\", \"\")\n ) as tracker:\n self.play(FadeIn(takeaway), run_time=tracker.duration)\n \n with self.voiceover(\n text=\"By applying these strategies, you will train more stable and reliable neural networks. Thank you for watching!\"\n ) as tracker:\n self.wait(tracker.duration * 0.5)\n \n self.play(FadeOut(summary_title, takeaways))\n \n # Final screen\n final_text = Text(\"Questions?\", font_size=48, color=BLUE)\n with self.voiceover(text=\"Any questions?\") as tracker:\n self.play(Write(final_text), run_time=tracker.duration)\n \n self.wait(1)\n```", "rejected": "```python\nfrom manim import *\n\nclass NumericalStabilityBoard(Scene):\n\n def construct(self):\n title = Text('Numerical Stability in Neural Networks', font_size=44, color=BLUE)\n subtitle = Text('Why Precision Matters in Deep Learning', font_size=28, color=GRAY)\n subtitle.next_to(title, DOWN, buff=0.3)\n title_group = VGroup(title, subtitle)\n self.play(Write(title), run_time=2.0 * 0.6)\n self.play(FadeIn(subtitle), run_time=2.0 * 0.4)\n self.wait(2.0)\n self.play(FadeOut(title_group))\n stability_title = Text('What is Numerical Stability?', font_size=36, color=BLUE)\n stability_title.to_edge(UP, buff=0.5)\n self.play(Write(stability_title), run_time=2.0 * 0.4)\n stable_box = Rectangle(width=3, height=2, color=GREEN, fill_opacity=0.2)\n unstable_box = Rectangle(width=3, height=2, color=RED, fill_opacity=0.2)\n stable_label = Text('Stable', font_size=24, color=GREEN)\n unstable_label = Text('Unstable', font_size=24, color=RED)\n stable_box.shift(LEFT * 3)\n unstable_box.shift(RIGHT * 3)\n stable_label.move_to(stable_box.get_center())\n unstable_label.move_to(unstable_box.get_center())\n stable_group = VGroup(stable_box, stable_label)\n unstable_group = VGroup(unstable_box, unstable_label)\n small_input = MathTex('\\\\text{small } \\\\\\\\ \\\\epsilon', font_size=20)\n small_input.next_to(stable_box, LEFT, buff=0.5)\n large_input = MathTex('\\\\text{small } \\\\\\\\ \\\\epsilon', font_size=20)\n large_input.next_to(unstable_box, LEFT, buff=0.5)\n self.play(Create(stable_group), run_time=2.0 * 0.5)\n self.play(FadeIn(small_input), run_time=2.0 * 0.25)\n arrow1 = Arrow(small_input.get_right(), stable_box.get_left(), buff=0.1, color=GREEN)\n self.play(Create(arrow1), run_time=2.0 * 0.25)\n small_output = MathTex('\\\\text{small } \\\\\\\\ \\\\Delta', font_size=20)\n small_output.next_to(stable_box, RIGHT, buff=0.5)\n arrow2 = Arrow(stable_box.get_right(), small_output.get_left(), buff=0.1, color=GREEN)\n self.play(Create(unstable_group), run_time=2.0 * 0.3)\n self.play(FadeIn(large_input), run_time=2.0 * 0.2)\n arrow3 = Arrow(large_input.get_right(), unstable_box.get_left(), buff=0.1, color=RED)\n self.play(Create(arrow3), run_time=2.0 * 0.2)\n large_output = MathTex('\\\\text{HUGE } \\\\\\\\ \\\\Delta!', font_size=24, color=RED)\n large_output.next_to(unstable_box, RIGHT, buff=0.5)\n arrow4 = Arrow(unstable_box.get_right(), large_output.get_left(), buff=0.1, color=RED)\n self.play(FadeIn(large_output), Create(arrow4), run_time=2.0 * 0.3)\n self.play(FadeIn(small_output), Create(arrow2))\n self.wait(2.0)\n self.play(FadeOut(stability_title, stable_group, unstable_group, small_input, large_input, small_output, large_output, arrow1, arrow2, arrow3, arrow4))\n causes_title = Text('Common Sources of Instability', font_size=36, color=BLUE)\n causes_title.to_edge(UP, buff=0.5)\n self.play(Write(causes_title), run_time=2.0)\n causes = [('Overflow', 'Values become too large', RED), ('Underflow', 'Values become too small', ORANGE), ('Vanishing Gradients', 'Gradients approach zero', YELLOW), ('Exploding Gradients', 'Gradients grow exponentially', PURPLE)]\n cause_boxes = VGroup()\n for i, (name, desc, color) in enumerate(causes):\n box = RoundedRectangle(width=5.5, height=1.5, color=color, fill_opacity=0.15, corner_radius=0.2)\n title_text = Text(name, font_size=22, color=color, weight=BOLD)\n desc_text = Text(desc, font_size=18, color=WHITE)\n title_text.move_to(box.get_center() + UP * 0.3)\n desc_text.move_to(box.get_center() + DOWN * 0.3)\n group = VGroup(box, title_text, desc_text)\n cause_boxes.add(group)\n cause_boxes.arrange_in_grid(rows=2, cols=2, buff=0.4)\n cause_boxes.move_to(ORIGIN)\n self.play(FadeIn(cause_boxes[0]), run_time=2.0)\n self.play(FadeIn(cause_boxes[1]), run_time=2.0)\n self.play(FadeIn(cause_boxes[2]), run_time=2.0)\n self.play(FadeIn(cause_boxes[3]), run_time=2.0)\n self.play(FadeOut(causes_title, cause_boxes))\n math_title = Text('The Mathematics Behind Instability', font_size=36, color=BLUE)\n math_title.to_edge(UP, buff=0.5)\n self.play(Write(math_title), run_time=2.0)\n forward_eq = MathTex('z^{[l]} = W^{[l]} a^{[l-1]} + b^{[l]}', font_size=32)\n forward_eq.shift(UP * 1.5)\n activation_eq = MathTex('a^{[l]} = \\\\sigma(z^{[l]})', font_size=32)\n activation_eq.next_to(forward_eq, DOWN, buff=0.5)\n self.play(Write(forward_eq), run_time=2.0 * 0.6)\n self.play(Write(activation_eq), run_time=2.0 * 0.6)\n self.play(FadeOut(forward_eq, activation_eq))\n grad_eq = MathTex('\\\\theta_{new} = \\\\theta_{old} - \\\\eta \\\\nabla_{\\\\theta} L', font_size=32)\n grad_eq.shift(UP * 0.5)\n self.play(Write(grad_eq), run_time=2.0 * 0.7)\n chain_rule = MathTex('\\\\frac{\\\\partial L}{\\\\partial W^{[l]}} = \\\\frac{\\\\partial L}{\\\\partial a^{[L]}} \\\\cdot \\\\prod_{k=l+1}^{L} \\\\frac{\\\\partial a^{[k]}}{\\\\partial z^{[k]}} W^{[k]}', font_size=26)\n chain_rule.next_to(grad_eq, DOWN, buff=0.8)\n self.play(Write(chain_rule), run_time=2.0)\n self.play(FadeOut(math_title, grad_eq, chain_rule))\n strategies_title = Text('Strategies for Numerical Stability', font_size=36, color=BLUE)\n strategies_title.to_edge(UP, buff=0.5)\n self.play(Write(strategies_title), run_time=2.0)\n left_strategies = VGroup()\n right_strategies = VGroup()\n strategies_left = [('Weight Initialization', 'Xavier, He init', GREEN), ('Activation Functions', 'ReLU, Leaky ReLU, GELU', TEAL)]\n strategies_right = [('Batch Normalization', 'Normalize activations', BLUE), ('Gradient Clipping', 'Cap gradient magnitude', PURPLE)]\n for name, desc, color in strategies_left:\n box = RoundedRectangle(width=5, height=1.3, color=color, fill_opacity=0.15, corner_radius=0.15)\n name_text = Text(name, font_size=20, color=color, weight=BOLD)\n desc_text = Text(desc, font_size=16, color=WHITE)\n name_text.move_to(box.get_center() + UP * 0.25)\n desc_text.move_to(box.get_center() + DOWN * 0.25)\n group = VGroup(box, name_text, desc_text)\n left_strategies.add(group)\n for name, desc, color in strategies_right:\n box = RoundedRectangle(width=5, height=1.3, color=color, fill_opacity=0.15, corner_radius=0.15)\n name_text = Text(name, font_size=20, color=color, weight=BOLD)\n desc_text = Text(desc, font_size=16, color=WHITE)\n name_text.move_to(box.get_center() + UP * 0.25)\n desc_text.move_to(box.get_center() + DOWN * 0.25)\n group = VGroup(box, name_text, desc_text)\n right_strategies.add(group)\n left_strategies.arrange(DOWN, buff=0.3)\n right_strategies.arrange(DOWN, buff=0.3)\n left_strategies.shift(LEFT * 3 + DOWN * 0.5)\n right_strategies.shift(RIGHT * 3 + DOWN * 0.5)\n all_strategies = VGroup(left_strategies, right_strategies)\n self.play(FadeIn(left_strategies[0]), run_time=2.0)\n self.play(FadeIn(left_strategies[1]), run_time=2.0)\n self.play(FadeIn(right_strategies[0]), run_time=2.0)\n self.play(FadeIn(right_strategies[1]), run_time=2.0)\n self.play(FadeOut(strategies_title, all_strategies))\n summary_title = Text('Key Takeaways', font_size=36, color=BLUE)\n summary_title.to_edge(UP, buff=0.5)\n self.play(Write(summary_title), run_time=2.0)\n takeaways = VGroup()\n takeaway_texts = ['• Avoid overflow and underflow by monitoring activations', '• Use proper weight initialization techniques', '• Choose activation functions that prevent vanishing gradients', '• Apply batch normalization for stable training', '• Implement gradient clipping to prevent explosions']\n for text in takeaway_texts:\n t = Text(text, font_size=22, color=WHITE)\n takeaways.add(t)\n takeaways.arrange(DOWN, buff=0.35, aligned_edge=LEFT)\n takeaways.move_to(ORIGIN)\n for i, takeaway in enumerate(takeaways):\n self.play(FadeIn(takeaway), run_time=2.0)\n self.wait(2.0 * 0.5)\n self.play(FadeOut(summary_title, takeaways))\n final_text = Text('Questions?', font_size=48, color=BLUE)\n self.play(Write(final_text), run_time=2.0)\n self.wait(1)\n```", "category": "narrated_pedagogical_preference", "source": "nabin2004/manim-narrated-dpo-400"} +{"system": "You are an expert Manim Community Edition (ManimCE v0.19+) Python developer and mathematical animator. Given a user request, first plan the spatial layout, coordinate bounds, timing, and pedagogical flow inside ... tags (when reasoning is helpful), and then output a complete, runnable, self-contained ManimCE Python script using `from manim import *`. Never use deprecated ManimGL (`manimlib`) methods like `ShowCreation`, `TexMobject`, `TextMobject`, or `axes.get_graph`; always use modern ManimCE APIs (`Create`, `MathTex`, `Tex`, `Text`, `axes.plot`) and prevent visual overlap using `.to_edge()`, `.next_to()`, and `FadeOut`.", "prompt": "I'm learning vector calculus and want intuition for curl as rotation.\nAnimate a 3D vector field with a color map that encodes local rotation, plus a small loop illustrating circulation and the line integral.\nShow a side-by-side visualization of the curl scalar field and how Stokes' theorem relates the loop integral to the surface integral.\nInclude a rotating stack of grid planes to visualize how curl emerges from local twisting.", "chosen": "```python\nfrom manim import *\nfrom manim_voiceover import VoiceoverScene\nfrom manim_voiceover.services.gtts import GTTSService\n\nclass CurlIntuitionScene(VoiceoverScene):\n def construct(self):\n self.set_speech_service(\n GTTSService(voice=\"alba\", cache_dir=\"voiceover_cache\")\n )\n \n # --- 1. TITLE ---\n title = Text(\"Curl Intuition in Vector Calculus\", font_size=40, color=BLUE)\n subtitle = Text(\"Measuring Rotation in Vector Fields\", font_size=24, color=GRAY)\n title_group = VGroup(title, subtitle).arrange(DOWN, buff=0.3)\n \n with self.voiceover(text=\"\"\"\n Imagine you're standing near a river and you notice the water swirling around in a circular motion. \n Have you ever wondered how we mathematically describe that swirling motion? \n That's where curl comes in. In this lecture, you're going to dive into the concept of curl in vector calculus, \n understanding how it measures the rotation of a vector field.\n \"\"\") as tracker:\n self.play(Write(title), run_time=1.5)\n self.play(FadeIn(subtitle), run_time=1.0)\n self.wait(tracker.duration - 2.5)\n \n self.play(FadeOut(title_group))\n \n # --- 2. MATHEMATICAL DEFINITION ---\n def_label = MathTex(r\"\\text{curl}(\\mathbf{F}) = \\nabla \\times \\mathbf{F}\", font_size=36)\n def_label.to_edge(UP, buff=0.5)\n \n f_def = MathTex(r\"\\mathbf{F} = (P, Q, R)\", font_size=32)\n f_def.next_to(def_label, DOWN, buff=0.4)\n \n with self.voiceover(text=\"\"\"\n Let's start with the definition. The curl of a vector field F is written as del cross F. \n If F has components P, Q, and R, then curl measures how much the field rotates at each point.\n \"\"\") as tracker:\n self.play(Write(def_label), run_time=tracker.duration * 0.4)\n self.play(Write(f_def), run_time=tracker.duration * 0.4)\n self.wait(tracker.duration * 0.2)\n \n # Show determinant form\n curl_det = MathTex(\n r\"\\nabla \\times \\mathbf{F} = \\begin{vmatrix} \\mathbf{i} & \\mathbf{j} & \\mathbf{k} \\\\ \\frac{\\partial}{\\partial x} & \\frac{\\partial}{\\partial y} & \\frac{\\partial}{\\partial z} \\\\ P & Q & R \\end{vmatrix}\",\n font_size=28\n )\n curl_det.next_to(f_def, DOWN, buff=0.4)\n curl_det.scale_to_fit_width(12)\n \n with self.voiceover(text=\"\"\"\n We can compute this using the determinant of a matrix with unit vectors, partial derivatives, and the components of F.\n \"\"\") as tracker:\n self.play(Write(curl_det), run_time=tracker.duration)\n \n self.wait(0.5)\n \n # Fade definition and move to example\n self.play(\n FadeOut(def_label),\n FadeOut(f_def),\n FadeOut(curl_det),\n )\n \n # --- 3. VISUAL EXAMPLE: ROTATING VECTOR FIELD ---\n # Define a 2D rotating field: F = (-y, x)\n axes = Axes(\n x_range=[-3, 3, 1],\n y_range=[-3, 3, 1],\n x_length=6,\n y_length=6,\n axis_config={\"include_tip\": True, \"numbers_to_exclude\": []},\n )\n axes.to_edge(LEFT, buff=0.5)\n axes.shift(RIGHT * 0.5)\n \n def rotating_field(pos):\n x, y = pos[:2]\n return np.array([-y, x, 0])\n \n def rotating_color(point):\n x, y = point[:2]\n return np.linalg.norm(np.array([x, y])) / 3.0\n \n vector_field = ArrowVectorField(\n rotating_field,\n x_range=[-2.5, 2.5, 0.5],\n y_range=[-2.5, 2.5, 0.5],\n color_scheme=rotating_color,\n length_func=lambda norm: 0.25 * sigmoid(norm),\n vector_config={\"stroke_width\": 2},\n )\n vector_field.match_width(axes)\n vector_field.match_height(axes)\n vector_field.move_to(axes.get_center())\n \n field_label = MathTex(r\"\\mathbf{F} = (-y,\\; x)\", font_size=28, color=YELLOW)\n field_label.next_to(axes, UP, buff=0.2)\n \n with self.voiceover(text=\"\"\"\n Let's look at a concrete example. Consider the vector field F equals negative y comma x.\n If you look at the arrows, they all point in a perfect circular pattern around the origin.\n \"\"\") as tracker:\n self.play(Create(axes), run_time=1.5)\n self.play(Write(field_label), run_time=1.0)\n self.play(FadeIn(vector_field), run_time=tracker.duration - 2.5)\n \n # --- 4. STREAMLINES / FLOW FIELD ---\n stream_lines = StreamLines(\n rotating_field,\n x_range=[-2.5, 2.5, 0.3],\n y_range=[-2.5, 2.5, 0.3],\n stroke_width=1.5,\n opacity=0.6,\n )\n stream_lines.match_width(axes)\n stream_lines.match_height(axes)\n stream_lines.move_to(axes.get_center())\n \n with self.voiceover(text=\"\"\"\n The streamlines trace the flow of particles in this field. Notice how every path curves around the center.\n This behavior is exactly what curl captures.\n \"\"\") as tracker:\n self.play(FadeIn(stream_lines), run_time=1.0)\n stream_lines.start_animation(warm_up=True, flow_speed=1.5)\n self.wait(tracker.duration - 1.0)\n stream_lines.end_animation()\n \n # --- 5. CURL CALCULATION FOR THIS FIELD ---\n # Move axes/field to left half\n self.play(\n axes.animate.scale(0.85).to_edge(LEFT, buff=0.3),\n vector_field.animate.scale(0.85).to_edge(LEFT, buff=0.3),\n stream_lines.animate.scale(0.85).to_edge(LEFT, buff=0.3),\n field_label.animate.scale(0.85).to_edge(LEFT, buff=0.3).shift(UP * 3 + RIGHT * 1.5),\n )\n \n calc_title = MathTex(r\"\\text{Curl of } \\mathbf{F} = (-y, x, 0)\", font_size=28, color=BLUE)\n calc_title.to_edge(UP, buff=0.3).shift(RIGHT * 2.5)\n \n step1 = MathTex(r\"\\nabla \\times \\mathbf{F} = \\left( \\frac{\\partial R}{\\partial y} - \\frac{\\partial Q}{\\partial z},\\; \\frac{\\partial P}{\\partial z} - \\frac{\\partial R}{\\partial x},\\; \\frac{\\partial Q}{\\partial x} - \\frac{\\partial P}{\\partial y} \\right)\", font_size=22)\n step1.next_to(calc_title, DOWN, buff=0.3)\n step1.shift(RIGHT * 2)\n \n with self.voiceover(text=\"\"\"\n Now let's compute the curl of this field. We take the cross product of del with F.\n The components involve differences of partial derivatives.\n \"\"\") as tracker:\n self.play(Write(calc_title), run_time=1.0)\n self.play(Write(step1), run_time=tracker.duration - 1.0)\n \n step2 = MathTex(r\"P = -y,\\; Q = x,\\; R = 0\", font_size=22)\n step2.next_to(step1, DOWN, buff=0.3)\n \n step3 = MathTex(r\"\\frac{\\partial Q}{\\partial x} = 1, \\quad \\frac{\\partial P}{\\partial y} = -1\", font_size=22)\n step3.next_to(step2, DOWN, buff=0.3)\n \n with self.voiceover(text=\"\"\"\n Here P equals negative y, Q equals x, and R equals zero.\n The key derivatives are partial Q over partial x equals one, \n and partial P over partial y equals negative one.\n \"\"\") as tracker:\n self.play(Write(step2), run_time=tracker.duration * 0.4)\n self.play(Write(step3), run_time=tracker.duration * 0.4)\n self.wait(tracker.duration * 0.2)\n \n step4 = MathTex(r\"\\nabla \\times \\mathbf{F} = (0,\\; 0,\\; 1 - (-1)) = (0,\\; 0,\\; 2)\", font_size=24, color=GREEN)\n step4.next_to(step3, DOWN, buff=0.3)\n \n with self.voiceover(text=\"\"\"\n So the curl evaluates to zero, zero, two. This means the rotation is entirely in the z direction, \n pointing out of the screen with magnitude two. Everywhere in the plane, the swirl is identical.\n \"\"\") as tracker:\n self.play(Write(step4), run_time=tracker.duration)\n \n # --- 6. PADDLE WHEEL INTUITION ---\n # Create a small paddle wheel at center\n paddle = VGroup()\n paddle_center = Dot(ORIGIN, radius=0.08, color=RED)\n blade1 = Line(ORIGIN, UP * 0.4, stroke_width=3, color=RED)\n blade2 = Line(ORIGIN, DOWN * 0.4, stroke_width=3, color=RED)\n blade3 = Line(ORIGIN, LEFT * 0.4, stroke_width=3, color=RED)\n blade4 = Line(ORIGIN, RIGHT * 0.4, stroke_width=3, color=RED)\n paddle.add(paddle_center, blade1, blade2, blade3, blade4)\n paddle.scale(0.85)\n # Position paddle in the vector field center\n paddle.move_to(axes.get_center())\n \n curl_text = MathTex(r\"\\text{curl} = 2\\,\\mathbf{k}\", font_size=22, color=GREEN)\n curl_text.next_to(paddle, RIGHT, buff=0.1).shift(UP * 0.5)\n \n with self.voiceover(text=\"\"\"\n To build physical intuition, picture a tiny paddle wheel dropped into the flow.\n Because the field pushes harder on one side than the other, the wheel spins.\n The curl tells you exactly how fast it would rotate.\n \"\"\") as tracker:\n self.play(FadeIn(paddle), run_time=1.0)\n # Rotate paddle\n self.play(Rotate(paddle, angle=PI, run_time=2.0, rate_func=linear))\n self.play(Write(curl_text), run_time=1.0)\n \n # --- 7. SUMMARY TAKEAWAYS ---\n # Clear lower right and show takeaways\n self.play(\n FadeOut(calc_title),\n FadeOut(step1),\n FadeOut(step2),\n FadeOut(step3),\n FadeOut(step4),\n FadeOut(paddle),\n FadeOut(curl_text),\n )\n \n # Move field to center-ish, make smaller\n self.play(\n axes.animate.scale(0.7).shift(DOWN * 0.5 + LEFT * 1),\n vector_field.animate.scale(0.7).shift(DOWN * 0.5 + LEFT * 1),\n stream_lines.animate.scale(0.7).shift(DOWN * 0.5 + LEFT * 1),\n field_label.animate.scale(0.7).shift(DOWN * 0.5 + LEFT * 2),\n )\n \n takeaways_title = Text(\"Key Takeaways\", font_size=28, color=BLUE)\n takeaways_title.to_edge(UP, buff=0.3).shift(RIGHT * 2.5)\n \n t1 = Tex(r\"$\\bullet$ Curl measures \\textbf{local rotation} of a vector field.\", font_size=22)\n t2 = Tex(r\"$\\bullet$ It is computed as $\\nabla \\times \\mathbf{F}$.\", font_size=22)\n t3 = Tex(r\"$\\bullet$ In fluid flow, curl tells how fast a paddle wheel would spin.\", font_size=22)\n t4 = Tex(r\"$\\bullet$ A non-zero curl means the field has ``swirl'' at that point.\", font_size=22)\n \n takeaways = VGroup(t1, t2, t3, t4).arrange(DOWN, aligned_edge=LEFT, buff=0.3)\n takeaways.next_to(takeaways_title, DOWN, buff=0.3)\n takeaways.shift(RIGHT * 2)\n \n with self.voiceover(text=\"\"\"\n Let's summarize the key takeaways. First, curl measures local rotation in a vector field.\n Second, it is computed as del cross F. Third, in fluid flow, curl tells you how fast a paddle wheel would spin.\n Finally, a non-zero curl means the field has swirl at that point.\n \"\"\") as tracker:\n self.play(Write(takeaways_title), run_time=1.0)\n self.play(Write(t1), run_time=1.0)\n self.play(Write(t2), run_time=1.0)\n self.play(Write(t3), run_time=1.0)\n self.play(Write(t4), run_time=1.0)\n self.wait(max(0, tracker.duration - 5.0))\n \n self.wait(1)\n self.play(\n FadeOut(takeaways_title), FadeOut(takeaways),\n FadeOut(axes), FadeOut(vector_field), FadeOut(stream_lines), FadeOut(field_label),\n )\n \n # --- 8. CLOSING ---\n closing = Text(\"Curl captures the swirl!\", font_size=36, color=BLUE)\n with self.voiceover(text=\"\"\"\n Curl captures the swirl. Now you have the intuition and the formula to analyze rotation \n in any vector field you encounter.\n \"\"\") as tracker:\n self.play(Write(closing), run_time=tracker.duration)\n \n self.wait(2)\n self.play(FadeOut(closing))\n```", "rejected": "```python\nfrom manim import *\n\nclass CurlIntuitionScene(Scene):\n\n def construct(self):\n title = Text('Curl Intuition in Vector Calculus', font_size=40, color=BLUE)\n subtitle = Text('Measuring Rotation in Vector Fields', font_size=24, color=GRAY)\n title_group = VGroup(title, subtitle).arrange(DOWN, buff=0.3)\n self.play(Write(title), run_time=1.5)\n self.play(FadeIn(subtitle), run_time=1.0)\n self.wait(2.0 - 2.5)\n self.play(FadeOut(title_group))\n def_label = MathTex('\\\\text{curl}(\\\\mathbf{F}) = \\\\nabla \\\\times \\\\mathbf{F}', font_size=36)\n def_label.to_edge(UP, buff=0.5)\n f_def = MathTex('\\\\mathbf{F} = (P, Q, R)', font_size=32)\n f_def.next_to(def_label, DOWN, buff=0.4)\n self.play(Write(def_label), run_time=2.0 * 0.4)\n self.play(Write(f_def), run_time=2.0 * 0.4)\n self.wait(2.0 * 0.2)\n curl_det = MathTex('\\\\nabla \\\\times \\\\mathbf{F} = \\\\begin{vmatrix} \\\\mathbf{i} & \\\\mathbf{j} & \\\\mathbf{k} \\\\\\\\ \\\\frac{\\\\partial}{\\\\partial x} & \\\\frac{\\\\partial}{\\\\partial y} & \\\\frac{\\\\partial}{\\\\partial z} \\\\\\\\ P & Q & R \\\\end{vmatrix}', font_size=28)\n curl_det.next_to(f_def, DOWN, buff=0.4)\n curl_det.scale_to_fit_width(12)\n self.play(Write(curl_det), run_time=2.0)\n self.wait(0.5)\n self.play(FadeOut(def_label), FadeOut(f_def), FadeOut(curl_det))\n axes = Axes(x_range=[-3, 3, 1], y_range=[-3, 3, 1], x_length=6, y_length=6, axis_config={'include_tip': True, 'numbers_to_exclude': []})\n axes.to_edge(LEFT, buff=0.5)\n axes.shift(RIGHT * 0.5)\n\n def rotating_field(pos):\n x, y = pos[:2]\n return np.array([-y, x, 0])\n\n def rotating_color(point):\n x, y = point[:2]\n return np.linalg.norm(np.array([x, y])) / 3.0\n vector_field = ArrowVectorField(rotating_field, x_range=[-2.5, 2.5, 0.5], y_range=[-2.5, 2.5, 0.5], color_scheme=rotating_color, length_func=lambda norm: 0.25 * sigmoid(norm), vector_config={'stroke_width': 2})\n vector_field.match_width(axes)\n vector_field.match_height(axes)\n vector_field.move_to(axes.get_center())\n field_label = MathTex('\\\\mathbf{F} = (-y,\\\\; x)', font_size=28, color=YELLOW)\n field_label.next_to(axes, UP, buff=0.2)\n self.play(Create(axes), run_time=1.5)\n self.play(Write(field_label), run_time=1.0)\n self.play(FadeIn(vector_field), run_time=2.0 - 2.5)\n stream_lines = StreamLines(rotating_field, x_range=[-2.5, 2.5, 0.3], y_range=[-2.5, 2.5, 0.3], stroke_width=1.5, opacity=0.6)\n stream_lines.match_width(axes)\n stream_lines.match_height(axes)\n stream_lines.move_to(axes.get_center())\n self.play(FadeIn(stream_lines), run_time=1.0)\n stream_lines.start_animation(warm_up=True, flow_speed=1.5)\n self.wait(2.0 - 1.0)\n stream_lines.end_animation()\n self.play(axes.animate.scale(0.85).to_edge(LEFT, buff=0.3), vector_field.animate.scale(0.85).to_edge(LEFT, buff=0.3), stream_lines.animate.scale(0.85).to_edge(LEFT, buff=0.3), field_label.animate.scale(0.85).to_edge(LEFT, buff=0.3).shift(UP * 3 + RIGHT * 1.5))\n calc_title = MathTex('\\\\text{Curl of } \\\\mathbf{F} = (-y, x, 0)', font_size=28, color=BLUE)\n calc_title.to_edge(UP, buff=0.3).shift(RIGHT * 2.5)\n step1 = MathTex('\\\\nabla \\\\times \\\\mathbf{F} = \\\\left( \\\\frac{\\\\partial R}{\\\\partial y} - \\\\frac{\\\\partial Q}{\\\\partial z},\\\\; \\\\frac{\\\\partial P}{\\\\partial z} - \\\\frac{\\\\partial R}{\\\\partial x},\\\\; \\\\frac{\\\\partial Q}{\\\\partial x} - \\\\frac{\\\\partial P}{\\\\partial y} \\\\right)', font_size=22)\n step1.next_to(calc_title, DOWN, buff=0.3)\n step1.shift(RIGHT * 2)\n self.play(Write(calc_title), run_time=1.0)\n self.play(Write(step1), run_time=2.0 - 1.0)\n step2 = MathTex('P = -y,\\\\; Q = x,\\\\; R = 0', font_size=22)\n step2.next_to(step1, DOWN, buff=0.3)\n step3 = MathTex('\\\\frac{\\\\partial Q}{\\\\partial x} = 1, \\\\quad \\\\frac{\\\\partial P}{\\\\partial y} = -1', font_size=22)\n step3.next_to(step2, DOWN, buff=0.3)\n self.play(Write(step2), run_time=2.0 * 0.4)\n self.play(Write(step3), run_time=2.0 * 0.4)\n self.wait(2.0 * 0.2)\n step4 = MathTex('\\\\nabla \\\\times \\\\mathbf{F} = (0,\\\\; 0,\\\\; 1 - (-1)) = (0,\\\\; 0,\\\\; 2)', font_size=24, color=GREEN)\n step4.next_to(step3, DOWN, buff=0.3)\n self.play(Write(step4), run_time=2.0)\n paddle = VGroup()\n paddle_center = Dot(ORIGIN, radius=0.08, color=RED)\n blade1 = Line(ORIGIN, UP * 0.4, stroke_width=3, color=RED)\n blade2 = Line(ORIGIN, DOWN * 0.4, stroke_width=3, color=RED)\n blade3 = Line(ORIGIN, LEFT * 0.4, stroke_width=3, color=RED)\n blade4 = Line(ORIGIN, RIGHT * 0.4, stroke_width=3, color=RED)\n paddle.add(paddle_center, blade1, blade2, blade3, blade4)\n paddle.scale(0.85)\n paddle.move_to(axes.get_center())\n curl_text = MathTex('\\\\text{curl} = 2\\\\,\\\\mathbf{k}', font_size=22, color=GREEN)\n curl_text.next_to(paddle, RIGHT, buff=0.1).shift(UP * 0.5)\n self.play(FadeIn(paddle), run_time=1.0)\n self.play(Rotate(paddle, angle=PI, run_time=2.0, rate_func=linear))\n self.play(Write(curl_text), run_time=1.0)\n self.play(FadeOut(calc_title), FadeOut(step1), FadeOut(step2), FadeOut(step3), FadeOut(step4), FadeOut(paddle), FadeOut(curl_text))\n self.play(axes.animate.scale(0.7).shift(DOWN * 0.5 + LEFT * 1), vector_field.animate.scale(0.7).shift(DOWN * 0.5 + LEFT * 1), stream_lines.animate.scale(0.7).shift(DOWN * 0.5 + LEFT * 1), field_label.animate.scale(0.7).shift(DOWN * 0.5 + LEFT * 2))\n takeaways_title = Text('Key Takeaways', font_size=28, color=BLUE)\n takeaways_title.to_edge(UP, buff=0.3).shift(RIGHT * 2.5)\n t1 = Tex('$\\\\bullet$ Curl measures \\\\textbf{local rotation} of a vector field.', font_size=22)\n t2 = Tex('$\\\\bullet$ It is computed as $\\\\nabla \\\\times \\\\mathbf{F}$.', font_size=22)\n t3 = Tex('$\\\\bullet$ In fluid flow, curl tells how fast a paddle wheel would spin.', font_size=22)\n t4 = Tex(\"$\\\\bullet$ A non-zero curl means the field has ``swirl'' at that point.\", font_size=22)\n takeaways = VGroup(t1, t2, t3, t4).arrange(DOWN, aligned_edge=LEFT, buff=0.3)\n takeaways.next_to(takeaways_title, DOWN, buff=0.3)\n takeaways.shift(RIGHT * 2)\n self.play(Write(takeaways_title), run_time=1.0)\n self.play(Write(t1), run_time=1.0)\n self.play(Write(t2), run_time=1.0)\n self.play(Write(t3), run_time=1.0)\n self.play(Write(t4), run_time=1.0)\n self.wait(max(0, 2.0 - 5.0))\n self.wait(1)\n self.play(FadeOut(takeaways_title), FadeOut(takeaways), FadeOut(axes), FadeOut(vector_field), FadeOut(stream_lines), FadeOut(field_label))\n closing = Text('Curl captures the swirl!', font_size=36, color=BLUE)\n self.play(Write(closing), run_time=2.0)\n self.wait(2)\n self.play(FadeOut(closing))\n```", "category": "narrated_pedagogical_preference", "source": "nabin2004/manim-narrated-dpo-400"} +{"system": "You are an expert Manim Community Edition (ManimCE v0.19+) Python developer and mathematical animator. Given a user request, first plan the spatial layout, coordinate bounds, timing, and pedagogical flow inside ... tags (when reasoning is helpful), and then output a complete, runnable, self-contained ManimCE Python script using `from manim import *`. Never use deprecated ManimGL (`manimlib`) methods like `ShowCreation`, `TexMobject`, `TextMobject`, or `axes.get_graph`; always use modern ManimCE APIs (`Create`, `MathTex`, `Tex`, `Text`, `axes.plot`) and prevent visual overlap using `.to_edge()`, `.next_to()`, and `FadeOut`.", "prompt": "The following Manim CE scene failed to compile. Truncated traceback:\n\nTypeError: Animation only works on Mobjects\n\nFix the code. Return a complete working scene. Do not keep the invalid constructor kwargs or Unicode subscripts.\n\n```python\nfrom manim import *\n\nclass SetMembershipVisualization(Scene):\n def construct(self):\n self.play(1.5)\n # Introduction\n title = Text(\"Visualizing Set Membership in Zermelo-Fraenkel Theory\", font_size=24)\n self.play(Write(title))\n self.wait(1)\n self.play(FadeOut(title))\n \n # Key Concept 1: Sets as regions\n universe = Rectangle(width=8, height=5, color=WHITE)\n universe_label = Text(\"Universe of Mathematical Objects\", font_size=20).next_to(universe, UP)\n \n self.play(Create(universe), Write(universe_label))\n self.wait(1)\n \n # Key Concept 2: Venn diagram with 3 sets\n concept2 = Text(\"Visualizing Set Membership\", font_size=24).to_edge(UP)\n self.play(Write(concept2), FadeOut(universe_label))\n \n # Create Venn diagram circles\n circle_A = Circle(radius=1.5, color=BLUE_C).move_to(LEFT*1.5)\n circle_B = Circle(radius=1.5, color=RED_C).move_to(RIGHT*1.5)\n circle_C = Circle(radius=1.5, color=GREEN_C).move_to(DOWN*1.5)\n \n label_A = Text(\"A: Whole Numbers\", font_size=20).next_to(circle_A, UP)\n label_B = Text(\"B: Prime Numbers\", font_size=20).next_to(circle_B, UP)\n label_C = Text(\"C: Even Numbers\", font_size=20).next_to(circle_C, DOWN)\n \n venn_group = VGroup(circle_A, circle_B, circle_C, label_A, label_B, label_C)\n \n self.play(\n FadeOut(universe),\n Create(circle_A), Write(label_A),\n Create(circle_B), Write(label_B),\n Create(circle_C), Write(label_C)\n )\n self.wait(1)\n \n # Show numbers in sets\n number_2 = Text(\"2\", font_size=24).move_to(LEFT*0.5)\n number_3 = Text(\"3\", font_size=24).move_to(LEFT*2+DOWN*0.5)\n number_4 = Text(\"4\", font_size=24).move_to(LEFT*0.5+DOWN)\n number_5 = Text(\"5\", font_size=24).move_to(RIGHT*2+UP*0.5)\n \n numbers_group = VGroup(number_2, number_3, number_4, number_5)\n self.play(FadeIn(numbers_group))\n self.wait(1)\n \n # Highlight the number 2\n highlight_circle = Circle(radius=0.3, color=YELLOW).move_to(LEFT*0.5)\n self.play(Create(highlight_circle))\n \n highlight_text = Text(\"2 is whole, prime, and even!\", font_size=24).to_edge(DOWN)\n self.play(Write(highlight_text))\n self.wait(1)\n \n # Equations with Text\n self.play(FadeOut(highlight_text))\n equation1 = Text(\"For all x: (x in A and x in B => x in A∩B)\", font_size=20).to_edge(DOWN)\n self.play(Write(equation1))\n self.wait(1)\n \n equation2 = Text(\"x in A => x in A∪B\", font_size=20).to_edge(DOWN)\n self.play(Transform(equation1, equation2))\n self.wait(1)\n \n # Key Insight\n insight_text = Text(\"Venn diagrams clarify set membership\", font_size=24).to_edge(DOWN)\n self.play(FadeOut(equation1), Write(insight_text))\n self.wait(1)\n \n # Conclusion\n self.play(\n FadeOut(venn_group),\n FadeOut(numbers_group),\n FadeOut(highlight_circle),\n FadeOut(concept2),\n FadeOut(insight_text)\n )\n \n conclusion = Text(\"Venn diagrams help us visualize abstract set theory\", font_size=24)\n self.play(Write(conclusion))\n self.wait(2)\n```", "chosen": "```python\nfrom manim import *\n\nclass SetMembershipVisualization(Scene):\n def construct(self):\n # Introduction\n title = Text(\"Visualizing Set Membership in Zermelo-Fraenkel Theory\", font_size=24)\n self.play(Write(title))\n self.wait(1)\n self.play(FadeOut(title))\n \n # Key Concept 1: Sets as regions\n universe = Rectangle(width=8, height=5, color=WHITE)\n universe_label = Text(\"Universe of Mathematical Objects\", font_size=20).next_to(universe, UP)\n \n self.play(Create(universe), Write(universe_label))\n self.wait(1)\n \n # Key Concept 2: Venn diagram with 3 sets\n concept2 = Text(\"Visualizing Set Membership\", font_size=24).to_edge(UP)\n self.play(Write(concept2), FadeOut(universe_label))\n \n # Create Venn diagram circles\n circle_A = Circle(radius=1.5, color=BLUE_C).move_to(LEFT*1.5)\n circle_B = Circle(radius=1.5, color=RED_C).move_to(RIGHT*1.5)\n circle_C = Circle(radius=1.5, color=GREEN_C).move_to(DOWN*1.5)\n \n label_A = Text(\"A: Whole Numbers\", font_size=20).next_to(circle_A, UP)\n label_B = Text(\"B: Prime Numbers\", font_size=20).next_to(circle_B, UP)\n label_C = Text(\"C: Even Numbers\", font_size=20).next_to(circle_C, DOWN)\n \n venn_group = VGroup(circle_A, circle_B, circle_C, label_A, label_B, label_C)\n \n self.play(\n FadeOut(universe),\n Create(circle_A), Write(label_A),\n Create(circle_B), Write(label_B),\n Create(circle_C), Write(label_C)\n )\n self.wait(1)\n \n # Show numbers in sets\n number_2 = Text(\"2\", font_size=24).move_to(LEFT*0.5)\n number_3 = Text(\"3\", font_size=24).move_to(LEFT*2+DOWN*0.5)\n number_4 = Text(\"4\", font_size=24).move_to(LEFT*0.5+DOWN)\n number_5 = Text(\"5\", font_size=24).move_to(RIGHT*2+UP*0.5)\n \n numbers_group = VGroup(number_2, number_3, number_4, number_5)\n self.play(FadeIn(numbers_group))\n self.wait(1)\n \n # Highlight the number 2\n highlight_circle = Circle(radius=0.3, color=YELLOW).move_to(LEFT*0.5)\n self.play(Create(highlight_circle))\n \n highlight_text = Text(\"2 is whole, prime, and even!\", font_size=24).to_edge(DOWN)\n self.play(Write(highlight_text))\n self.wait(1)\n \n # Equations with Text\n self.play(FadeOut(highlight_text))\n equation1 = Text(\"For all x: (x in A and x in B => x in A∩B)\", font_size=20).to_edge(DOWN)\n self.play(Write(equation1))\n self.wait(1)\n \n equation2 = Text(\"x in A => x in A∪B\", font_size=20).to_edge(DOWN)\n self.play(Transform(equation1, equation2))\n self.wait(1)\n \n # Key Insight\n insight_text = Text(\"Venn diagrams clarify set membership\", font_size=24).to_edge(DOWN)\n self.play(FadeOut(equation1), Write(insight_text))\n self.wait(1)\n \n # Conclusion\n self.play(\n FadeOut(venn_group),\n FadeOut(numbers_group),\n FadeOut(highlight_circle),\n FadeOut(concept2),\n FadeOut(insight_text)\n )\n \n conclusion = Text(\"Venn diagrams help us visualize abstract set theory\", font_size=24)\n self.play(Write(conclusion))\n self.wait(2)\n```", "rejected": "```python\nfrom manim import *\n\nclass SetMembershipVisualization(Scene):\n def construct(self):\n # Introduction\n title = Text(\"Visualizing Set Membership in Zermelo-Fraenkel Theory\", font_size=24)\n self.play(Write(title))\n self.wait(1)\n self.play(FadeOut(title))\n \n # Key Concept 1: Sets as regions\n universe = Rectangle(width=8, height=5, color=WHITE)\n universe_label = Text(\"Universe of Mathematical Objects\", font_size=20)\n \n self.play(Create(universe), Write(universe_label))\n self.wait(1)\n \n # Key Concept 2: Venn diagram with 3 sets\n concept2 = Text(\"Visualizing Set Membership\", font_size=24)\n self.play(Write(concept2), FadeOut(universe_label))\n \n # Create Venn diagram circles\n circle_A = Circle(radius=1.5, color=BLUE_C).move_to(LEFT*1.5)\n circle_B = Circle(radius=1.5, color=RED_C).move_to(RIGHT*1.5)\n circle_C = Circle(radius=1.5, color=GREEN_C).move_to(DOWN*1.5)\n \n label_A = Text(\"A: Whole Numbers\", font_size=20)\n label_B = Text(\"B: Prime Numbers\", font_size=20).next_to(circle_B, UP)\n label_C = Text(\"C: Even Numbers\", font_size=20).next_to(circle_C, DOWN)\n \n venn_group = VGroup(circle_A, circle_B, circle_C, label_A, label_B, label_C)\n \n self.play(\n FadeOut(universe),\n Create(circle_A), Write(label_A),\n Create(circle_B), Write(label_B),\n Create(circle_C), Write(label_C)\n )\n self.wait(1)\n \n # Show numbers in sets\n number_2 = Text(\"2\", font_size=24).move_to(LEFT*0.5)\n number_3 = Text(\"3\", font_size=24).move_to(LEFT*2+DOWN*0.5)\n number_4 = Text(\"4\", font_size=24).move_to(LEFT*0.5+DOWN)\n number_5 = Text(\"5\", font_size=24).move_to(RIGHT*2+UP*0.5)\n \n numbers_group = VGroup(number_2, number_3, number_4, number_5)\n self.play(FadeIn(numbers_group))\n self.wait(1)\n \n # Highlight the number 2\n highlight_circle = Circle(radius=0.3, color=YELLOW).move_to(LEFT*0.5)\n self.play(Create(highlight_circle))\n \n highlight_text = Text(\"2 is whole, prime, and even!\", font_size=24).to_edge(DOWN)\n self.play(Write(highlight_text))\n self.wait(1)\n \n # Equations with Text\n self.play(FadeOut(highlight_text))\n equation1 = Text(\"For all x: (x in A and x in B => x in A∩B)\", font_size=20).to_edge(DOWN)\n self.play(Write(equation1))\n self.wait(1)\n \n equation2 = Text(\"x in A => x in A∪B\", font_size=20).to_edge(DOWN)\n self.play(Transform(equation1, equation2))\n self.wait(1)\n \n # Key Insight\n insight_text = Text(\"Venn diagrams clarify set membership\", font_size=24).to_edge(DOWN)\n self.play(FadeOut(equation1), Write(insight_text))\n self.wait(1)\n \n # Conclusion\n self.play(\n FadeOut(venn_group),\n FadeOut(numbers_group),\n FadeOut(highlight_circle),\n FadeOut(concept2),\n FadeOut(insight_text)\n )\n \n conclusion = Text(\"Venn diagrams help us visualize abstract set theory\", font_size=24)\n self.play(Write(conclusion))\n self.wait(2)\n```", "category": "spatial_layout_overlap", "source": "synthetic_hard_neg:nabin2004/manim-sft-10k"} +{"system": "You are an expert Manim Community Edition (ManimCE v0.19+) Python developer and mathematical animator. Given a user request, first plan the spatial layout, coordinate bounds, timing, and pedagogical flow inside ... tags (when reasoning is helpful), and then output a complete, runnable, self-contained ManimCE Python script using `from manim import *`. Never use deprecated ManimGL (`manimlib`) methods like `ShowCreation`, `TexMobject`, `TextMobject`, or `axes.get_graph`; always use modern ManimCE APIs (`Create`, `MathTex`, `Tex`, `Text`, `axes.plot`) and prevent visual overlap using `.to_edge()`, `.next_to()`, and `FadeOut`.", "prompt": "You are a Manim expert. Please convert the Markdown lecture notes into executable Manim CE v0.19.0 code that displays content in English. The page layout must be clear, with no overlapping elements, and you must not output any explanatory or descriptive text outside the code. Pay special attention to avoiding common errors such as LaTeX syntax issues and index out-of-range errors, and ensure the code can run directly. The Markdown lecture notes are as follows:\n\n### Cross-validation\nA more robust model evaluation method compared to a single split.\n\n#### K-fold, Leave-One-Out, Hold-out\n* Choose an appropriate validation strategy based on data size and computational resources (e.g., use LOOCV for small samples).\n\n#### Assess Model Generalization, Aid in Model Selection\n* Use validation set performance to guide hyperparameter selection and avoid test set information leakage.\n\n\nContextual location of this section (from highest to current level):\n# Machine Learning Course - Detailed Outline for Lecture 6 (Model Training Essentials, 90 minutes)\n## Model Selection and Generalization Ability (15 minutes)\n", "chosen": "```python\nfrom manim import *\nfrom manim import config\nText.set_default(font='SimHei')\n\nclass CrossValidation(Scene):\n\n def construct(self):\n title = Text('Cross-validation', font_size=44, weight=BOLD)\n title.to_edge(UP, buff=0.5)\n subtitle = Text('A more robust model evaluation method compared to a single split.', font_size=28, color=BLUE)\n subtitle.next_to(title, DOWN, buff=0.3)\n p1 = Text('• K-fold, Leave-One-Out, Hold-out', font_size=28, weight=BOLD)\n sp1 = Text(' - Choose an appropriate validation strategy based on data size and\\n computational resources (e.g., use LOOCV for small samples).', font_size=24, color=LIGHT_GREY)\n p2 = Text('• Assess Model Generalization, Aid in Model Selection', font_size=28, weight=BOLD)\n sp2 = Text(' - Use validation set performance to guide hyperparameter selection\\n and avoid test set information leakage.', font_size=24, color=LIGHT_GREY)\n text_group = VGroup(p1, sp1, p2, sp2).arrange(DOWN, aligned_edge=LEFT, buff=0.3)\n text_group.next_to(subtitle, DOWN, buff=0.6).to_edge(LEFT, buff=1.0)\n self.play(Write(title))\n self.play(FadeIn(subtitle))\n self.play(Write(p1))\n self.play(FadeIn(sp1))\n self.play(Write(p2))\n self.play(FadeIn(sp2))\n self.wait(1)\n boxes = VGroup(*[Rectangle(height=0.6, width=1.8, fill_opacity=0.8, fill_color=BLUE, stroke_color=WHITE) for _ in range(5)]).arrange(RIGHT, buff=0.1)\n labels = VGroup(*[Text(f'Fold {i + 1}', font_size=20) for i in range(5)])\n for box, label in zip(boxes, labels):\n label.move_to(box.get_center())\n else:\n pass\n fold_group = VGroup(boxes, labels)\n train_legend = VGroup(Rectangle(height=0.3, width=0.3, fill_opacity=0.8, fill_color=BLUE), Text('Training', font_size=20)).arrange(RIGHT, buff=0.2)\n val_legend = VGroup(Rectangle(height=0.3, width=0.3, fill_opacity=0.8, fill_color=RED), Text('Validation', font_size=20)).arrange(RIGHT, buff=0.2)\n legend = VGroup(train_legend, val_legend).arrange(RIGHT, buff=0.8)\n visual_group = VGroup(legend, fold_group).arrange(DOWN, buff=0.4)\n visual_group.next_to(text_group, DOWN, buff=0.6)\n self.play(FadeIn(visual_group))\n self.wait(0.5)\n for i in range(5):\n self.play(boxes[i].animate.set_fill(RED), run_time=0.4)\n self.wait(0.4)\n self.play(boxes[i].animate.set_fill(BLUE), run_time=0.4)\n else:\n pass\n self.wait(2)\n self.play(FadeOut(Group(*self.mobjects)))\n```", "rejected": "```python\nfrom manim import *\nfrom manim import config\nText.set_default(font='SimHei')\n\nclass CrossValidation(Scene):\n\n def construct(self):\n title = Text('Cross-validation', font_size=44, weight=BOLD)\n title\n subtitle = Text('A more robust model evaluation method compared to a single split.', font_size=28, color=BLUE)\n subtitle\n p1 = Text('• K-fold, Leave-One-Out, Hold-out', font_size=28, weight=BOLD)\n sp1 = Text(' - Choose an appropriate validation strategy based on data size and\\n computational resources (e.g., use LOOCV for small samples).', font_size=24, color=LIGHT_GREY)\n p2 = Text('• Assess Model Generalization, Aid in Model Selection', font_size=28, weight=BOLD)\n sp2 = Text(' - Use validation set performance to guide hyperparameter selection\\n and avoid test set information leakage.', font_size=24, color=LIGHT_GREY)\n text_group = VGroup(p1, sp1, p2, sp2).arrange(DOWN, aligned_edge=LEFT, buff=0.3)\n text_group.to_edge(LEFT, buff=1.0)\n self.play(Write(title))\n self.play(FadeIn(subtitle))\n self.play(Write(p1))\n self.play(FadeIn(sp1))\n self.play(Write(p2))\n self.play(FadeIn(sp2))\n self.wait(1)\n boxes = VGroup(*[Rectangle(height=0.6, width=1.8, fill_opacity=0.8, fill_color=BLUE, stroke_color=WHITE) for _ in range(5)]).arrange(RIGHT, buff=0.1)\n labels = VGroup(*[Text(f'Fold {i + 1}', font_size=20) for i in range(5)])\n for box, label in zip(boxes, labels):\n label.move_to(box.get_center())\n else:\n pass\n fold_group = VGroup(boxes, labels)\n train_legend = VGroup(Rectangle(height=0.3, width=0.3, fill_opacity=0.8, fill_color=BLUE), Text('Training', font_size=20)).arrange(RIGHT, buff=0.2)\n val_legend = VGroup(Rectangle(height=0.3, width=0.3, fill_opacity=0.8, fill_color=RED), Text('Validation', font_size=20)).arrange(RIGHT, buff=0.2)\n legend = VGroup(train_legend, val_legend).arrange(RIGHT, buff=0.8)\n visual_group = VGroup(legend, fold_group).arrange(DOWN, buff=0.4)\n visual_group.next_to(text_group, DOWN, buff=0.6)\n self.play(FadeIn(visual_group))\n self.wait(0.5)\n for i in range(5):\n self.play(boxes[i].animate.set_fill(RED), run_time=0.4)\n self.wait(0.4)\n self.play(boxes[i].animate.set_fill(BLUE), run_time=0.4)\n else:\n pass\n self.wait(2)\n self.play(FadeOut(Group(*self.mobjects)))\n```", "category": "spatial_layout_overlap", "source": "synthetic_hard_neg:nabin2004/manim-sft-10k"} +{"system": "You are an expert Manim Community Edition (ManimCE v0.19+) Python developer and mathematical animator. Given a user request, first plan the spatial layout, coordinate bounds, timing, and pedagogical flow inside ... tags (when reasoning is helpful), and then output a complete, runnable, self-contained ManimCE Python script using `from manim import *`. Never use deprecated ManimGL (`manimlib`) methods like `ShowCreation`, `TexMobject`, `TextMobject`, or `axes.get_graph`; always use modern ManimCE APIs (`Create`, `MathTex`, `Tex`, `Text`, `axes.plot`) and prevent visual overlap using `.to_edge()`, `.next_to()`, and `FadeOut`.", "prompt": "I'm exploring dilated convolutions and want a visualization where the dilation concept is shown as a spring pulling filter taps apart, illustrating effective receptive field growth.", "chosen": "```python\nfrom manim import *\n\nclass DilatedConvolutionsScene(Scene):\n\n def construct(self):\n title = Text('Dilated Convolutions & Receptive Fields', font_size=36)\n title.to_edge(UP, buff=0.5)\n subtitle = Text('Expanding Context Without Adding Parameters', font_size=24, color=BLUE)\n subtitle.next_to(title, DOWN, buff=0.3)\n self.play(Write(title), Write(subtitle), run_time=2.0)\n self.wait(0.5)\n self.play(FadeOut(title), FadeOut(subtitle))\n grid_size = 7\n input_grid = VGroup()\n squares = {}\n for i in range(grid_size):\n for j in range(grid_size):\n square = Square(side_length=0.5, stroke_width=1)\n square.move_to([j * 0.55 - grid_size * 0.275, i * 0.55 - grid_size * 0.275, 0])\n square.set_fill(DARK_GRAY, opacity=0.3)\n input_grid.add(square)\n squares[i, j] = square\n input_label = Text('Input Image', font_size=20)\n input_label.next_to(input_grid, DOWN, buff=0.3)\n conv_title = Text('Standard 3x3 Convolution', font_size=28)\n conv_title.to_edge(UP, buff=0.3)\n self.play(Write(conv_title), Create(input_grid), Write(input_label), run_time=2.0 * 0.5)\n kernel_positions = [(2, 2), (2, 3), (3, 3), (3, 4)]\n for idx, (ci, cj) in enumerate(kernel_positions):\n highlighted = VGroup()\n for di in range(3):\n for dj in range(3):\n ni, nj = (ci + di - 1, cj + dj - 1)\n if (ni, nj) in squares:\n highlight = squares[ni, nj].copy()\n highlight.set_fill(YELLOW, opacity=0.7)\n highlighted.add(highlight)\n if idx == 0:\n self.play(FadeIn(highlighted), run_time=2.0 * 0.125)\n else:\n self.play(Transform(prev_highlighted, highlighted), run_time=2.0 * 0.125)\n prev_highlighted = highlighted\n if idx < len(kernel_positions) - 1:\n self.wait(0.1)\n self.play(FadeOut(prev_highlighted))\n new_title = Text('Dilated Convolution (Dilation = 2)', font_size=28)\n new_title.to_edge(UP, buff=0.3)\n self.play(ReplacementTransform(conv_title, new_title), run_time=2.0 * 0.3)\n conv_title = new_title\n dilated_highlighted = VGroup()\n center_i, center_j = (3, 3)\n for di in [-1, 0, 1]:\n for dj in [-1, 0, 1]:\n actual_i = center_i + di * 2\n actual_j = center_j + dj * 2\n if (actual_i, actual_j) in squares:\n highlight = squares[actual_i, actual_j].copy()\n highlight.set_fill(GREEN, opacity=0.8)\n dilated_highlighted.add(highlight)\n kernel_outline = Rectangle(width=0.5 + 4 * 0.55, height=0.5 + 4 * 0.55, stroke_color=RED, stroke_width=3)\n kernel_outline.move_to(squares[center_i, center_j])\n self.play(FadeIn(dilated_highlighted), Create(kernel_outline), run_time=2.0 * 0.7)\n self.play(FadeOut(input_grid), FadeOut(input_label), FadeOut(dilated_highlighted), FadeOut(kernel_outline), run_time=2.0 * 0.2)\n standard_group = VGroup()\n std_title = Text('Standard Conv', font_size=20, color=BLUE)\n std_title.move_to([-3.5, 2, 0])\n standard_group.add(std_title)\n std_grid = VGroup()\n for i in range(3):\n for j in range(3):\n sq = Square(side_length=0.6, stroke_width=2)\n sq.move_to([-4.5 + j * 0.65, 0.5 - i * 0.65, 0])\n sq.set_fill(YELLOW, opacity=0.6)\n std_grid.add(sq)\n standard_group.add(std_grid)\n std_rf = Text('Receptive Field: 3x3', font_size=18)\n std_rf.next_to(std_grid, DOWN, buff=0.3)\n standard_group.add(std_rf)\n std_params = Text('Parameters: 9', font_size=18, color=GREEN)\n std_params.next_to(std_rf, DOWN, buff=0.2)\n standard_group.add(std_params)\n dilated_group = VGroup()\n dil_title = Text('Dilated Conv (d=2)', font_size=20, color=GREEN)\n dil_title.move_to([3.5, 2, 0])\n dilated_group.add(dil_title)\n dil_grid = VGroup()\n for i in range(7):\n for j in range(7):\n sq = Square(side_length=0.35, stroke_width=1)\n sq.move_to([1.5 + j * 0.4, 1.5 - i * 0.4, 0])\n if i % 2 == 1 and j % 2 == 1:\n sq.set_fill(GREEN, opacity=0.8)\n else:\n sq.set_fill(DARK_GRAY, opacity=0.2)\n dil_grid.add(sq)\n dilated_group.add(dil_grid)\n dil_rf = Text('Receptive Field: 7x7', font_size=18)\n dil_rf.next_to(dil_grid, DOWN, buff=0.3)\n dilated_group.add(dil_rf)\n dil_params = Text('Parameters: 9', font_size=18, color=GREEN)\n dil_params.next_to(dil_rf, DOWN, buff=0.2)\n dilated_group.add(dil_params)\n arrow = Arrow(std_grid.get_right() + RIGHT * 0.3, dil_grid.get_left() + LEFT * 0.3, buff=0.2, color=YELLOW)\n arrow_label = Text('Same params!', font_size=16, color=YELLOW)\n arrow_label.next_to(arrow, UP, buff=0.1)\n self.play(ReplacementTransform(conv_title, Text('Comparison: Standard vs Dilated', font_size=26).to_edge(UP, buff=0.3)), FadeIn(standard_group), FadeIn(dilated_group), run_time=2.0 * 0.6)\n self.play(Create(arrow), Write(arrow_label), run_time=2.0 * 0.2)\n self.wait(0.5)\n self.play(*[FadeOut(mob) for mob in self.mobjects])\n formula_title = Text('Receptive Field Formula', font_size=28)\n formula_title.to_edge(UP, buff=0.5)\n formula = MathTex('R = k + (k - 1) \\\\times (d - 1)', font_size=40)\n formula.move_to([0, 1, 0])\n legend = VGroup()\n r_text = MathTex('R = \\\\text{Receptive Field Size}', font_size=24)\n k_text = MathTex('k = \\\\text{Kernel Size}', font_size=24)\n d_text = MathTex('d = \\\\text{Dilation Factor}', font_size=24)\n r_text.to_edge(LEFT, buff=1)\n r_text.shift(DOWN * 0.5)\n k_text.next_to(r_text, DOWN, buff=0.3, aligned_edge=LEFT)\n d_text.next_to(k_text, DOWN, buff=0.3, aligned_edge=LEFT)\n legend.add(r_text, k_text, d_text)\n self.play(Write(formula_title), run_time=2.0 * 0.2)\n self.play(Write(formula), run_time=2.0 * 0.4)\n self.play(Write(legend), run_time=2.0 * 0.4)\n example_title = Text('Example Calculation', font_size=24)\n example_title.to_edge(RIGHT, buff=1)\n example_title.shift(UP * 1.5)\n calc1 = MathTex('k=3, d=2:', font_size=22)\n calc1.next_to(example_title, DOWN, buff=0.4)\n calc2 = MathTex('R = 3 + (3-1) \\\\times (2-1)', font_size=22)\n calc2.next_to(calc1, DOWN, buff=0.3)\n calc3 = MathTex('R = 3 + 2 \\\\times 1 = 5', font_size=22)\n calc3.next_to(calc2, DOWN, buff=0.3)\n calc4 = MathTex('\\\\text{RF} = 5 \\\\times 5 = 25 \\\\text{ pixels}', font_size=22, color=GREEN)\n calc4.next_to(calc3, DOWN, buff=0.3)\n example_group = VGroup(example_title, calc1, calc2, calc3, calc4)\n self.play(Write(example_group), run_time=2.0 * 0.6)\n growth_title = Text('Receptive Field Growth', font_size=20)\n growth_title.move_to([0, -1.5, 0])\n self.play(Write(growth_title), run_time=2.0 * 0.1)\n rf_group = VGroup()\n d1_grid = VGroup()\n for i in range(3):\n for j in range(3):\n sq = Square(side_length=0.25, stroke_width=1)\n sq.move_to([-3 + j * 0.28, -2.5 - i * 0.28, 0])\n sq.set_fill(BLUE, opacity=0.6)\n d1_grid.add(sq)\n d1_label = Text('d=1: 3x3', font_size=14)\n d1_label.next_to(d1_grid, DOWN, buff=0.1)\n rf_group.add(d1_grid, d1_label)\n d2_grid = VGroup()\n for i in range(5):\n for j in range(5):\n sq = Square(side_length=0.25, stroke_width=1)\n sq.move_to([0 + j * 0.28, -2.3 - i * 0.28, 0])\n if i % 2 == 0 and j % 2 == 0:\n sq.set_fill(GREEN, opacity=0.8)\n else:\n sq.set_fill(DARK_GRAY, opacity=0.2)\n d2_grid.add(sq)\n d2_label = Text('d=2: 5x5', font_size=14)\n d2_label.next_to(d2_grid, DOWN, buff=0.1)\n rf_group.add(d2_grid, d2_label)\n d3_grid = VGroup()\n for i in range(7):\n for j in range(7):\n sq = Square(side_length=0.25, stroke_width=1)\n sq.move_to([3 + j * 0.28, -2.1 - i * 0.28, 0])\n if i % 3 == 0 and j % 3 == 0:\n sq.set_fill(RED, opacity=0.8)\n else:\n sq.set_fill(DARK_GRAY, opacity=0.2)\n d3_grid.add(sq)\n d3_label = Text('d=3: 7x7', font_size=14)\n d3_label.next_to(d3_grid, DOWN, buff=0.1)\n rf_group.add(d3_grid, d3_label)\n self.play(FadeIn(rf_group), run_time=2.0 * 0.3)\n self.wait(0.5)\n self.play(*[FadeOut(mob) for mob in self.mobjects])\n app_title = Text('Applications of Dilated Convolutions', font_size=28)\n app_title.to_edge(UP, buff=0.5)\n left_col = VGroup()\n right_col = VGroup()\n seg_icon = VGroup()\n seg_box = Rectangle(width=2, height=1.2, stroke_color=BLUE, fill_color=BLUE, fill_opacity=0.2)\n seg_text1 = Text('Semantic', font_size=18)\n seg_text2 = Text('Segmentation', font_size=18)\n seg_text1.move_to([seg_box.get_center()[0], seg_box.get_center()[1] + 0.15, 0])\n seg_text2.move_to([seg_box.get_center()[0], seg_box.get_center()[1] - 0.15, 0])\n seg_icon.add(seg_box, seg_text1, seg_text2)\n wavenet_icon = VGroup()\n wave_box = Rectangle(width=2, height=1.2, stroke_color=GREEN, fill_color=GREEN, fill_opacity=0.2)\n wave_text1 = Text('WaveNet', font_size=18)\n wave_text2 = Text('Speech Synthesis', font_size=18)\n wave_text1.move_to([wave_box.get_center()[0], wave_box.get_center()[1] + 0.15, 0])\n wave_text2.move_to([wave_box.get_center()[0], wave_box.get_center()[1] - 0.15, 0])\n wavenet_icon.add(wave_box, wave_text1, wave_text2)\n ts_icon = VGroup()\n ts_box = Rectangle(width=2, height=1.2, stroke_color=YELLOW, fill_color=YELLOW, fill_opacity=0.2)\n ts_text1 = Text('Time Series', font_size=18)\n ts_text2 = Text('Forecasting', font_size=18)\n ts_text1.move_to([ts_box.get_center()[0], ts_box.get_center()[1] + 0.15, 0])\n ts_text2.move_to([ts_box.get_center()[0], ts_box.get_center()[1] - 0.15, 0])\n ts_icon.add(ts_box, ts_text1, ts_text2)\n audio_icon = VGroup()\n audio_box = Rectangle(width=2, height=1.2, stroke_color=RED, fill_color=RED, fill_opacity=0.2)\n audio_text1 = Text('Audio', font_size=18)\n audio_text2 = Text('Processing', font_size=18)\n audio_text1.move_to([audio_box.get_center()[0], audio_box.get_center()[1] + 0.15, 0])\n audio_text2.move_to([audio_box.get_center()[0], audio_box.get_center()[1] - 0.15, 0])\n audio_icon.add(audio_box, audio_text1, audio_text2)\n left_col.add(seg_icon, ts_icon)\n left_col.arrange(DOWN, buff=0.5)\n left_col.move_to([-2.5, 0, 0])\n right_col.add(wavenet_icon, audio_icon)\n right_col.arrange(DOWN, buff=0.5)\n right_col.move_to([2.5, 0, 0])\n self.play(Write(app_title), run_time=2.0 * 0.2)\n self.play(FadeIn(left_col), FadeIn(right_col), run_time=2.0 * 0.8)\n self.play(FadeOut(left_col), FadeOut(right_col), run_time=2.0 * 0.1)\n takeaways_title = Text('Key Takeaways', font_size=28)\n takeaways_title.to_edge(UP, buff=0.5)\n takeaways = VGroup()\n p1 = Text('- Dilated convolutions expand receptive field', font_size=20)\n p2 = Text(' without adding parameters', font_size=20)\n p3 = Text(\"- Use dilation factor 'd' to create gaps\", font_size=20)\n p4 = Text(' between kernel elements', font_size=20)\n p5 = Text('- Formula: R = k + (k-1) x (d-1)', font_size=20)\n p6 = Text('- Essential for semantic segmentation,', font_size=20)\n p7 = Text(' speech synthesis, and long-range modeling', font_size=20)\n takeaways.add(p1, p2, p3, p4, p5, p6, p7)\n takeaways.arrange(DOWN, buff=0.2, aligned_edge=LEFT)\n takeaways.move_to([0, -0.5, 0])\n box = SurroundingRectangle(takeaways, buff=0.3, corner_radius=0.1)\n box.set_stroke(WHITE, width=2)\n self.play(ReplacementTransform(app_title, takeaways_title), Write(takeaways), Create(box), run_time=2.0 * 0.9)\n closing = Text('Happy Learning!', font_size=32, color=YELLOW)\n closing.move_to([0, -2.5, 0])\n self.play(Write(closing), run_time=2.0)\n self.wait(1)\n```", "rejected": "```python\nfrom manim import *\n\nclass DilatedConvolutionsScene(Scene):\n\n def construct(self):\n title = Text('Dilated Convolutions & Receptive Fields', font_size=36)\n title\n subtitle = Text('Expanding Context Without Adding Parameters', font_size=24, color=BLUE)\n subtitle\n self.play(Write(title), Write(subtitle), run_time=2.0)\n self.wait(0.5)\n self.play(FadeOut(title), FadeOut(subtitle))\n grid_size = 7\n input_grid = VGroup()\n squares = {}\n for i in range(grid_size):\n for j in range(grid_size):\n square = Square(side_length=0.5, stroke_width=1)\n square.move_to([j * 0.55 - grid_size * 0.275, i * 0.55 - grid_size * 0.275, 0])\n square.set_fill(DARK_GRAY, opacity=0.3)\n input_grid.add(square)\n squares[i, j] = square\n input_label = Text('Input Image', font_size=20)\n input_label\n conv_title = Text('Standard 3x3 Convolution', font_size=28)\n conv_title.to_edge(UP, buff=0.3)\n self.play(Write(conv_title), Create(input_grid), Write(input_label), run_time=2.0 * 0.5)\n kernel_positions = [(2, 2), (2, 3), (3, 3), (3, 4)]\n for idx, (ci, cj) in enumerate(kernel_positions):\n highlighted = VGroup()\n for di in range(3):\n for dj in range(3):\n ni, nj = (ci + di - 1, cj + dj - 1)\n if (ni, nj) in squares:\n highlight = squares[ni, nj].copy()\n highlight.set_fill(YELLOW, opacity=0.7)\n highlighted.add(highlight)\n if idx == 0:\n self.play(FadeIn(highlighted), run_time=2.0 * 0.125)\n else:\n self.play(Transform(prev_highlighted, highlighted), run_time=2.0 * 0.125)\n prev_highlighted = highlighted\n if idx < len(kernel_positions) - 1:\n self.wait(0.1)\n self.play(FadeOut(prev_highlighted))\n new_title = Text('Dilated Convolution (Dilation = 2)', font_size=28)\n new_title.to_edge(UP, buff=0.3)\n self.play(ReplacementTransform(conv_title, new_title), run_time=2.0 * 0.3)\n conv_title = new_title\n dilated_highlighted = VGroup()\n center_i, center_j = (3, 3)\n for di in [-1, 0, 1]:\n for dj in [-1, 0, 1]:\n actual_i = center_i + di * 2\n actual_j = center_j + dj * 2\n if (actual_i, actual_j) in squares:\n highlight = squares[actual_i, actual_j].copy()\n highlight.set_fill(GREEN, opacity=0.8)\n dilated_highlighted.add(highlight)\n kernel_outline = Rectangle(width=0.5 + 4 * 0.55, height=0.5 + 4 * 0.55, stroke_color=RED, stroke_width=3)\n kernel_outline.move_to(squares[center_i, center_j])\n self.play(FadeIn(dilated_highlighted), Create(kernel_outline), run_time=2.0 * 0.7)\n self.play(FadeOut(input_grid), FadeOut(input_label), FadeOut(dilated_highlighted), FadeOut(kernel_outline), run_time=2.0 * 0.2)\n standard_group = VGroup()\n std_title = Text('Standard Conv', font_size=20, color=BLUE)\n std_title.move_to([-3.5, 2, 0])\n standard_group.add(std_title)\n std_grid = VGroup()\n for i in range(3):\n for j in range(3):\n sq = Square(side_length=0.6, stroke_width=2)\n sq.move_to([-4.5 + j * 0.65, 0.5 - i * 0.65, 0])\n sq.set_fill(YELLOW, opacity=0.6)\n std_grid.add(sq)\n standard_group.add(std_grid)\n std_rf = Text('Receptive Field: 3x3', font_size=18)\n std_rf.next_to(std_grid, DOWN, buff=0.3)\n standard_group.add(std_rf)\n std_params = Text('Parameters: 9', font_size=18, color=GREEN)\n std_params.next_to(std_rf, DOWN, buff=0.2)\n standard_group.add(std_params)\n dilated_group = VGroup()\n dil_title = Text('Dilated Conv (d=2)', font_size=20, color=GREEN)\n dil_title.move_to([3.5, 2, 0])\n dilated_group.add(dil_title)\n dil_grid = VGroup()\n for i in range(7):\n for j in range(7):\n sq = Square(side_length=0.35, stroke_width=1)\n sq.move_to([1.5 + j * 0.4, 1.5 - i * 0.4, 0])\n if i % 2 == 1 and j % 2 == 1:\n sq.set_fill(GREEN, opacity=0.8)\n else:\n sq.set_fill(DARK_GRAY, opacity=0.2)\n dil_grid.add(sq)\n dilated_group.add(dil_grid)\n dil_rf = Text('Receptive Field: 7x7', font_size=18)\n dil_rf.next_to(dil_grid, DOWN, buff=0.3)\n dilated_group.add(dil_rf)\n dil_params = Text('Parameters: 9', font_size=18, color=GREEN)\n dil_params.next_to(dil_rf, DOWN, buff=0.2)\n dilated_group.add(dil_params)\n arrow = Arrow(std_grid.get_right() + RIGHT * 0.3, dil_grid.get_left() + LEFT * 0.3, buff=0.2, color=YELLOW)\n arrow_label = Text('Same params!', font_size=16, color=YELLOW)\n arrow_label.next_to(arrow, UP, buff=0.1)\n self.play(ReplacementTransform(conv_title, Text('Comparison: Standard vs Dilated', font_size=26).to_edge(UP, buff=0.3)), FadeIn(standard_group), FadeIn(dilated_group), run_time=2.0 * 0.6)\n self.play(Create(arrow), Write(arrow_label), run_time=2.0 * 0.2)\n self.wait(0.5)\n self.play(*[FadeOut(mob) for mob in self.mobjects])\n formula_title = Text('Receptive Field Formula', font_size=28)\n formula_title.to_edge(UP, buff=0.5)\n formula = MathTex('R = k + (k - 1) \\\\times (d - 1)', font_size=40)\n formula.move_to([0, 1, 0])\n legend = VGroup()\n r_text = MathTex('R = \\\\text{Receptive Field Size}', font_size=24)\n k_text = MathTex('k = \\\\text{Kernel Size}', font_size=24)\n d_text = MathTex('d = \\\\text{Dilation Factor}', font_size=24)\n r_text.to_edge(LEFT, buff=1)\n r_text.shift(DOWN * 0.5)\n k_text.next_to(r_text, DOWN, buff=0.3, aligned_edge=LEFT)\n d_text.next_to(k_text, DOWN, buff=0.3, aligned_edge=LEFT)\n legend.add(r_text, k_text, d_text)\n self.play(Write(formula_title), run_time=2.0 * 0.2)\n self.play(Write(formula), run_time=2.0 * 0.4)\n self.play(Write(legend), run_time=2.0 * 0.4)\n example_title = Text('Example Calculation', font_size=24)\n example_title.to_edge(RIGHT, buff=1)\n example_title.shift(UP * 1.5)\n calc1 = MathTex('k=3, d=2:', font_size=22)\n calc1.next_to(example_title, DOWN, buff=0.4)\n calc2 = MathTex('R = 3 + (3-1) \\\\times (2-1)', font_size=22)\n calc2.next_to(calc1, DOWN, buff=0.3)\n calc3 = MathTex('R = 3 + 2 \\\\times 1 = 5', font_size=22)\n calc3.next_to(calc2, DOWN, buff=0.3)\n calc4 = MathTex('\\\\text{RF} = 5 \\\\times 5 = 25 \\\\text{ pixels}', font_size=22, color=GREEN)\n calc4.next_to(calc3, DOWN, buff=0.3)\n example_group = VGroup(example_title, calc1, calc2, calc3, calc4)\n self.play(Write(example_group), run_time=2.0 * 0.6)\n growth_title = Text('Receptive Field Growth', font_size=20)\n growth_title.move_to([0, -1.5, 0])\n self.play(Write(growth_title), run_time=2.0 * 0.1)\n rf_group = VGroup()\n d1_grid = VGroup()\n for i in range(3):\n for j in range(3):\n sq = Square(side_length=0.25, stroke_width=1)\n sq.move_to([-3 + j * 0.28, -2.5 - i * 0.28, 0])\n sq.set_fill(BLUE, opacity=0.6)\n d1_grid.add(sq)\n d1_label = Text('d=1: 3x3', font_size=14)\n d1_label.next_to(d1_grid, DOWN, buff=0.1)\n rf_group.add(d1_grid, d1_label)\n d2_grid = VGroup()\n for i in range(5):\n for j in range(5):\n sq = Square(side_length=0.25, stroke_width=1)\n sq.move_to([0 + j * 0.28, -2.3 - i * 0.28, 0])\n if i % 2 == 0 and j % 2 == 0:\n sq.set_fill(GREEN, opacity=0.8)\n else:\n sq.set_fill(DARK_GRAY, opacity=0.2)\n d2_grid.add(sq)\n d2_label = Text('d=2: 5x5', font_size=14)\n d2_label.next_to(d2_grid, DOWN, buff=0.1)\n rf_group.add(d2_grid, d2_label)\n d3_grid = VGroup()\n for i in range(7):\n for j in range(7):\n sq = Square(side_length=0.25, stroke_width=1)\n sq.move_to([3 + j * 0.28, -2.1 - i * 0.28, 0])\n if i % 3 == 0 and j % 3 == 0:\n sq.set_fill(RED, opacity=0.8)\n else:\n sq.set_fill(DARK_GRAY, opacity=0.2)\n d3_grid.add(sq)\n d3_label = Text('d=3: 7x7', font_size=14)\n d3_label.next_to(d3_grid, DOWN, buff=0.1)\n rf_group.add(d3_grid, d3_label)\n self.play(FadeIn(rf_group), run_time=2.0 * 0.3)\n self.wait(0.5)\n self.play(*[FadeOut(mob) for mob in self.mobjects])\n app_title = Text('Applications of Dilated Convolutions', font_size=28)\n app_title.to_edge(UP, buff=0.5)\n left_col = VGroup()\n right_col = VGroup()\n seg_icon = VGroup()\n seg_box = Rectangle(width=2, height=1.2, stroke_color=BLUE, fill_color=BLUE, fill_opacity=0.2)\n seg_text1 = Text('Semantic', font_size=18)\n seg_text2 = Text('Segmentation', font_size=18)\n seg_text1.move_to([seg_box.get_center()[0], seg_box.get_center()[1] + 0.15, 0])\n seg_text2.move_to([seg_box.get_center()[0], seg_box.get_center()[1] - 0.15, 0])\n seg_icon.add(seg_box, seg_text1, seg_text2)\n wavenet_icon = VGroup()\n wave_box = Rectangle(width=2, height=1.2, stroke_color=GREEN, fill_color=GREEN, fill_opacity=0.2)\n wave_text1 = Text('WaveNet', font_size=18)\n wave_text2 = Text('Speech Synthesis', font_size=18)\n wave_text1.move_to([wave_box.get_center()[0], wave_box.get_center()[1] + 0.15, 0])\n wave_text2.move_to([wave_box.get_center()[0], wave_box.get_center()[1] - 0.15, 0])\n wavenet_icon.add(wave_box, wave_text1, wave_text2)\n ts_icon = VGroup()\n ts_box = Rectangle(width=2, height=1.2, stroke_color=YELLOW, fill_color=YELLOW, fill_opacity=0.2)\n ts_text1 = Text('Time Series', font_size=18)\n ts_text2 = Text('Forecasting', font_size=18)\n ts_text1.move_to([ts_box.get_center()[0], ts_box.get_center()[1] + 0.15, 0])\n ts_text2.move_to([ts_box.get_center()[0], ts_box.get_center()[1] - 0.15, 0])\n ts_icon.add(ts_box, ts_text1, ts_text2)\n audio_icon = VGroup()\n audio_box = Rectangle(width=2, height=1.2, stroke_color=RED, fill_color=RED, fill_opacity=0.2)\n audio_text1 = Text('Audio', font_size=18)\n audio_text2 = Text('Processing', font_size=18)\n audio_text1.move_to([audio_box.get_center()[0], audio_box.get_center()[1] + 0.15, 0])\n audio_text2.move_to([audio_box.get_center()[0], audio_box.get_center()[1] - 0.15, 0])\n audio_icon.add(audio_box, audio_text1, audio_text2)\n left_col.add(seg_icon, ts_icon)\n left_col.arrange(DOWN, buff=0.5)\n left_col.move_to([-2.5, 0, 0])\n right_col.add(wavenet_icon, audio_icon)\n right_col.arrange(DOWN, buff=0.5)\n right_col.move_to([2.5, 0, 0])\n self.play(Write(app_title), run_time=2.0 * 0.2)\n self.play(FadeIn(left_col), FadeIn(right_col), run_time=2.0 * 0.8)\n self.play(FadeOut(left_col), FadeOut(right_col), run_time=2.0 * 0.1)\n takeaways_title = Text('Key Takeaways', font_size=28)\n takeaways_title.to_edge(UP, buff=0.5)\n takeaways = VGroup()\n p1 = Text('- Dilated convolutions expand receptive field', font_size=20)\n p2 = Text(' without adding parameters', font_size=20)\n p3 = Text(\"- Use dilation factor 'd' to create gaps\", font_size=20)\n p4 = Text(' between kernel elements', font_size=20)\n p5 = Text('- Formula: R = k + (k-1) x (d-1)', font_size=20)\n p6 = Text('- Essential for semantic segmentation,', font_size=20)\n p7 = Text(' speech synthesis, and long-range modeling', font_size=20)\n takeaways.add(p1, p2, p3, p4, p5, p6, p7)\n takeaways.arrange(DOWN, buff=0.2, aligned_edge=LEFT)\n takeaways.move_to([0, -0.5, 0])\n box = SurroundingRectangle(takeaways, buff=0.3, corner_radius=0.1)\n box.set_stroke(WHITE, width=2)\n self.play(ReplacementTransform(app_title, takeaways_title), Write(takeaways), Create(box), run_time=2.0 * 0.9)\n closing = Text('Happy Learning!', font_size=32, color=YELLOW)\n closing.move_to([0, -2.5, 0])\n self.play(Write(closing), run_time=2.0)\n self.wait(1)\n```", "category": "spatial_layout_overlap", "source": "synthetic_hard_neg:nabin2004/AOS-Manim-SFT"} +{"system": "You are an expert Manim Community Edition (ManimCE v0.19+) Python developer and mathematical animator. Given a user request, first plan the spatial layout, coordinate bounds, timing, and pedagogical flow inside ... tags (when reasoning is helpful), and then output a complete, runnable, self-contained ManimCE Python script using `from manim import *`. Never use deprecated ManimGL (`manimlib`) methods like `ShowCreation`, `TexMobject`, `TextMobject`, or `axes.get_graph`; always use modern ManimCE APIs (`Create`, `MathTex`, `Tex`, `Text`, `axes.plot`) and prevent visual overlap using `.to_edge()`, `.next_to()`, and `FadeOut`.", "prompt": "I'm studying NLP and want to compare human-written text with a bigram-generated version. Create a side-by-side display with the two texts, color-coding differences at the word- or phrase-level and visually highlighting changed zones. Animate a diff pipeline that reveals where bigram generation matches or deviates, with a timeline of sentences and a scroll-through of examples. Offer a brief explanation overlay about why bigrams struggle with long-range coherence.\n\n```python\nfrom manim import *\nimport numpy as np\n\nclass AOSTrajectoryScene382(Scene):\n def construct(self):\n # Create a side-by-side comparison of human-written text vs. bigram-generated text, color-coding differences.\n title = Title(\"Create a side-by-side comparison of huma\")\n ax = Axes(x_range=[-3, 3, 1], y_range=[-1, 5, 1], x_length=6, y_length=4)\n curve = ax.plot(lambda x: 1 / (1 + np.exp(-x)), color=BLUE)\n label = MathTex(r'\\sigma(x) = \\frac{1}{1 + e^{-x}}').to_corner(UR)\n dot = Dot(ax.c2p(0, 0.5), color=RED)\n self.play(Write(title), Create(ax), Create(curve), Write(label), FadeIn(dot))\n self.play(dot.animate.move_to(ax.c2p(2, 1 / (1 + np.exp(-2)))), run_time=2)\n self.wait(1)\n```", "chosen": "```python\nfrom manim import *\nfrom manim_voiceover import VoiceoverScene\nfrom manim_voiceover.services.gtts import GTTSService\n\nMARGIN = 0.5\n\nclass AOSTrajectoryScene382(VoiceoverScene):\n def fit_in_frame(self, mob: Mobject, w_frac=0.9, h_frac=0.9) -> Mobject:\n max_w = config.frame_width * w_frac\n max_h = config.frame_height * h_frac\n if mob.width > max_w: mob.width = max_w\n if mob.height > max_h: mob.height = max_h\n return mob\n\n def construct(self):\n self.set_speech_service(GTTSService(transcription_model=\"base\"))\n \n # [SETUP]\n human_words = [\"The\", \"quick\", \"brown\", \"fox\", \"jumps\", \"over\", \"the\", \"lazy\", \"dog\"]\n bigram_words = [\"The\", \"quick\", \"brown\", \"cat\", \"sleeps\", \"on\", \"the\", \"lazy\", \"mat\"]\n \n human_text = VGroup()\n bigram_text = VGroup()\n for h_w, b_w in zip(human_words, bigram_words):\n color = GREEN if h_w == b_w else RED\n human_text.add(Text(h_w, font_size=24, color=color))\n bigram_text.add(Text(b_w, font_size=24, color=color))\n \n human_text.arrange(DOWN, aligned_edge=LEFT, buff=0.3).to_edge(LEFT, buff=1.5)\n bigram_text.arrange(DOWN, aligned_edge=LEFT, buff=0.3).to_edge(RIGHT, buff=1.5)\n \n # [LAYOUT]\n title = Title(\"Human vs Bigram Text\")\n human_label = Text(\"Human\", font_size=20, color=WHITE).next_to(human_text, UP, buff=0.5)\n bigram_label = Text(\"Bigram\", font_size=20, color=WHITE).next_to(bigram_text, UP, buff=0.5)\n \n self.add(self.fit_in_frame(title), self.fit_in_frame(VGroup(human_text, human_label, bigram_text, bigram_label)))\n \n # [UPDATER]\n # None needed\n \n # [BEAT 1 | sync: b1]\n with self.voiceover(text=\"Comparing human text with bigram-generated text reveals coherence issues. We display both sequences side-by-side, highlighting matching words in green and deviations in red.\") as t:\n self.wait_until_bookmark(\"b1\")\n self.play(Write(human_label), Write(bigram_label), FadeIn(human_text), FadeIn(bigram_text), run_time=2)\n self.wait(1)\n \n # [BEAT 2 | sync: b2]\n with self.voiceover(text=\" Bigrams struggle with long-range dependencies, often losing the original meaning after a few words.\") as t:\n self.wait_until_bookmark(\"b2\")\n self.wait(2)\n \n self.wait(1)\n```", "rejected": "```python\nfrom manim import *\nfrom manim_voiceover import VoiceoverScene\nfrom manim_voiceover.services.gtts import GTTSService\n\nMARGIN = 0.5\n\nclass AOSTrajectoryScene382(VoiceoverScene):\n def fit_in_frame(self, mob: Mobject, w_frac=0.9, h_frac=0.9) -> Mobject:\n max_w = config.frame_width * w_frac\n max_h = config.frame_height * h_frac\n if mob.width > max_w: mob.width = max_w\n if mob.height > max_h: mob.height = max_h\n return mob\n\n def construct(self):\n self.set_speech_service(GTTSService(transcription_model=\"base\"))\n \n # [SETUP]\n human_words = [\"The\", \"quick\", \"brown\", \"fox\", \"jumps\", \"over\", \"the\", \"lazy\", \"dog\"]\n bigram_words = [\"The\", \"quick\", \"brown\", \"cat\", \"sleeps\", \"on\", \"the\", \"lazy\", \"mat\"]\n \n human_text = VGroup()\n bigram_text = VGroup()\n for h_w, b_w in zip(human_words, bigram_words):\n color = GREEN if h_w == b_w else RED\n human_text.add(Text(h_w, font_size=24, color=color))\n bigram_text.add(Text(b_w, font_size=24, color=color))\n \n human_text.arrange(DOWN, aligned_edge=LEFT, buff=0.3)\n bigram_text.arrange(DOWN, aligned_edge=LEFT, buff=0.3)\n \n # [LAYOUT]\n title = Title(\"Human vs Bigram Text\")\n human_label = Text(\"Human\", font_size=20, color=WHITE)\n bigram_label = Text(\"Bigram\", font_size=20, color=WHITE).next_to(bigram_text, UP, buff=0.5)\n \n self.add(self.fit_in_frame(title), self.fit_in_frame(VGroup(human_text, human_label, bigram_text, bigram_label)))\n \n # [UPDATER]\n # None needed\n \n # [BEAT 1 | sync: b1]\n with self.voiceover(text=\"Comparing human text with bigram-generated text reveals coherence issues. We display both sequences side-by-side, highlighting matching words in green and deviations in red.\") as t:\n self.wait_until_bookmark(\"b1\")\n self.play(Write(human_label), Write(bigram_label), FadeIn(human_text), FadeIn(bigram_text), run_time=2)\n self.wait(1)\n \n # [BEAT 2 | sync: b2]\n with self.voiceover(text=\" Bigrams struggle with long-range dependencies, often losing the original meaning after a few words.\") as t:\n self.wait_until_bookmark(\"b2\")\n self.wait(2)\n \n self.wait(1)\n```", "category": "spatial_layout_overlap", "source": "synthetic_hard_neg:nabin2004/qwen3-8b-manimator-gold-sft"} +{"system": "You are an expert Manim Community Edition (ManimCE v0.19+) Python developer and mathematical animator. Given a user request, first plan the spatial layout, coordinate bounds, timing, and pedagogical flow inside ... tags (when reasoning is helpful), and then output a complete, runnable, self-contained ManimCE Python script using `from manim import *`. Never use deprecated ManimGL (`manimlib`) methods like `ShowCreation`, `TexMobject`, `TextMobject`, or `axes.get_graph`; always use modern ManimCE APIs (`Create`, `MathTex`, `Tex`, `Text`, `axes.plot`) and prevent visual overlap using `.to_edge()`, `.next_to()`, and `FadeOut`.", "prompt": "The following Manim CE scene failed to compile. Truncated traceback:\n\nAttributeError: VGroup object has no attribute 'c2p'\n\nFix the code. Return a complete working scene. Do not keep the invalid constructor kwargs or Unicode subscripts.\n\n```python\nfrom manim import *\n\nclass AreaUnderCurveExample(Scene):\n def construct(self):\n axes_group = VGroup(NumberLine(), NumberLine())\n p = axes_group.c2p(1, 0)\n # Define the function and its graph\n f = lambda x: 0.1 * x ** 2\n graph = FunctionGraph(f, x_range=[0, 10])\n area = graph.get_area(x_range=[2, 8], color=BLUE, opacity=0.5)\n\n # Display function and area under curve\n self.play(Create(graph), run_time=2)\n self.play(FadeIn(area, scale=0.3), run_time=2)\n self.wait(1)\n\n # Show area calculation\n problem = MathTex(r\"\\int_2^8 0.1x^2 \\,dx\")\n self.play(Write(problem))\n self.wait(1)\n\n # Explanation for the area under the curve\n explanation = Text(\"Area between 2 and 8\", font_size=24).next_to(area, UP)\n self.play(Write(explanation))\n self.wait(2)\n\n # Calculate the area\n integral_calculation = MathTex(r\"= \\left[\\frac{0.1}{3}x^3\\right]_2^8\")\n self.play(Transform(problem, integral_calculation))\n self.wait(1)\n\n final_answer = MathTex(r\"= \\frac{0.1}{3}(8^3 - 2^3)\", r\"= \\frac{0.1}{3}(512 - 8)\", r\"= \\frac{0.1}{3}(504)\", r\"= 16.8\")\n self.play(ReplacementTransform(integral_calculation, final_answer))\n self.wait(1)\n\n # Conclude\n self.clear()\n self.wait(1)\n self.play(Write(final_answer))\n self.wait(1)\n```", "chosen": "```python\nfrom manim import *\n\nclass AreaUnderCurveExample(Scene):\n def construct(self):\n # Define the function and its graph\n f = lambda x: 0.1 * x ** 2\n graph = FunctionGraph(f, x_range=[0, 10])\n area = graph.get_area(x_range=[2, 8], color=BLUE, opacity=0.5)\n\n # Display function and area under curve\n self.play(Create(graph), run_time=2)\n self.play(FadeIn(area, scale=0.3), run_time=2)\n self.wait(1)\n\n # Show area calculation\n problem = MathTex(r\"\\int_2^8 0.1x^2 \\,dx\")\n self.play(Write(problem))\n self.wait(1)\n\n # Explanation for the area under the curve\n explanation = Text(\"Area between 2 and 8\", font_size=24).next_to(area, UP)\n self.play(Write(explanation))\n self.wait(2)\n\n # Calculate the area\n integral_calculation = MathTex(r\"= \\left[\\frac{0.1}{3}x^3\\right]_2^8\")\n self.play(Transform(problem, integral_calculation))\n self.wait(1)\n\n final_answer = MathTex(r\"= \\frac{0.1}{3}(8^3 - 2^3)\", r\"= \\frac{0.1}{3}(512 - 8)\", r\"= \\frac{0.1}{3}(504)\", r\"= 16.8\")\n self.play(ReplacementTransform(integral_calculation, final_answer))\n self.wait(1)\n\n # Conclude\n self.clear()\n self.wait(1)\n self.play(Write(final_answer))\n self.wait(1)\n```", "rejected": "```python\nfrom manim import *\n\nclass AreaUnderCurveExample(Scene):\n def construct(self):\n # Define the function and its graph\n f = lambda x: 0.1 * x ** 2\n graph = FunctionGraph(f, x_range=[0, 10])\n area = graph.get_area(x_range=[2, 8], color=BLUE, opacity=0.5)\n\n # Display function and area under curve\n self.play(ShowCreation(graph), run_time=2)\n self.play(FadeIn(area, scale=0.3), run_time=2)\n self.wait(1)\n\n # Show area calculation\n problem = TexMobject(r\"\\int_2^8 0.1x^2 \\,dx\")\n self.play(Write(problem))\n self.wait(1)\n\n # Explanation for the area under the curve\n explanation = Text(\"Area between 2 and 8\", font_size=24).next_to(area, UP)\n self.play(Write(explanation))\n self.wait(2)\n\n # Calculate the area\n integral_calculation = MathTex(r\"= \\left[\\frac{0.1}{3}x^3\\right]_2^8\")\n self.play(Transform(problem, integral_calculation))\n self.wait(1)\n\n final_answer = MathTex(r\"= \\frac{0.1}{3}(8^3 - 2^3)\", r\"= \\frac{0.1}{3}(512 - 8)\", r\"= \\frac{0.1}{3}(504)\", r\"= 16.8\")\n self.play(ReplacementTransform(integral_calculation, final_answer))\n self.wait(1)\n\n # Conclude\n self.clear()\n self.wait(1)\n self.play(Write(final_answer))\n self.wait(1)\n```", "category": "legacy_api_hallucination", "source": "synthetic_hard_neg:nabin2004/manim-sft-10k"} +{"system": "You are an expert Manim Community Edition (ManimCE v0.19+) Python developer and mathematical animator. Given a user request, first plan the spatial layout, coordinate bounds, timing, and pedagogical flow inside ... tags (when reasoning is helpful), and then output a complete, runnable, self-contained ManimCE Python script using `from manim import *`. Never use deprecated ManimGL (`manimlib`) methods like `ShowCreation`, `TexMobject`, `TextMobject`, or `axes.get_graph`; always use modern ManimCE APIs (`Create`, `MathTex`, `Tex`, `Text`, `axes.plot`) and prevent visual overlap using `.to_edge()`, `.next_to()`, and `FadeOut`.", "prompt": "Create a 20-second Manim scene that explains a Jacobian as a local linear map. Show a point on a plane, a small input arrow, transform the formula with matching LaTeX, display a 2x2 matrix, and then show the output arrow produced by that local linearization.", "chosen": "```python\nfrom manim import *\n\nclass TransformMatchingJacobianStory(Scene):\n def construct(self):\n title = Text(\"Jacobian = local linear map\", font_size=34).to_edge(UP)\n plane = NumberPlane(x_range=[-3, 3, 1], y_range=[-2, 2, 1], background_line_style={\"stroke_opacity\": 0.24}).shift(LEFT * 1.7)\n base = Dot(plane.c2p(0.8, 0.5), color=YELLOW_D)\n input_vec = Arrow(base.get_center(), base.get_center() + RIGHT * 0.9 + UP * 0.35, buff=0, color=BLUE_D)\n output_vec = Arrow(base.get_center(), base.get_center() + RIGHT * 0.55 + UP * 0.95, buff=0, color=GREEN_D)\n input_label = MathTex(r\"d\\vec{x}\", color=BLUE_D).next_to(input_vec, DOWN, buff=0.12)\n output_label = MathTex(r\"J d\\vec{x}\", color=GREEN_D).next_to(output_vec, RIGHT, buff=0.12)\n\n formula_a = MathTex(r\"f(\\vec{x}+d\\vec{x}) \\approx f(\\vec{x}) + J d\\vec{x}\", font_size=34).to_edge(DOWN)\n formula_b = MathTex(r\"d\\vec{y} = J d\\vec{x}\", font_size=38).to_edge(DOWN)\n matrix = Matrix([[\"1.2\", \"-0.4\"], [\"0.5\", \"0.9\"]]).scale(0.72).to_edge(RIGHT).shift(UP * 0.35)\n matrix_title = Text(\"local matrix\", font_size=24, color=WHITE).next_to(matrix, UP, buff=0.2)\n box = SurroundingRectangle(matrix, color=GREEN_D, buff=0.18)\n\n self.play(FadeIn(title), Create(plane), FadeIn(base), run_time=3)\n self.play(GrowArrow(input_vec), FadeIn(input_label), FadeIn(formula_a), run_time=3)\n self.play(TransformMatchingTex(formula_a, formula_b), FadeIn(matrix), FadeIn(matrix_title), run_time=3)\n self.play(Create(box), TransformFromCopy(input_vec, output_vec), FadeIn(output_label), run_time=4)\n self.play(Indicate(matrix, color=GREEN_A), Indicate(output_vec, color=GREEN_A), run_time=3)\n self.wait(2)\n```", "rejected": "```python\nfrom manim import *\n\nclass TransformMatchingJacobianStory(Scene):\n def construct(self):\n title = Text(\"Jacobian = local linear map\", font_size=34)\n plane = NumberPlane(x_range=[-3, 3, 1], y_range=[-2, 2, 1], background_line_style={\"stroke_opacity\": 0.24})\n base = Dot(plane.c2p(0.8, 0.5), color=YELLOW_D)\n input_vec = Arrow(base.get_center(), base.get_center() + RIGHT * 0.9 + UP * 0.35, buff=0, color=BLUE_D)\n output_vec = Arrow(base.get_center(), base.get_center() + RIGHT * 0.55 + UP * 0.95, buff=0, color=GREEN_D)\n input_label = MathTex(r\"d\\vec{x}\", color=BLUE_D)\n output_label = MathTex(r\"J d\\vec{x}\", color=GREEN_D).next_to(output_vec, RIGHT, buff=0.12)\n\n formula_a = MathTex(r\"f(\\vec{x}+d\\vec{x}) \\approx f(\\vec{x}) + J d\\vec{x}\", font_size=34).to_edge(DOWN)\n formula_b = MathTex(r\"d\\vec{y} = J d\\vec{x}\", font_size=38).to_edge(DOWN)\n matrix = Matrix([[\"1.2\", \"-0.4\"], [\"0.5\", \"0.9\"]]).scale(0.72).to_edge(RIGHT).shift(UP * 0.35)\n matrix_title = Text(\"local matrix\", font_size=24, color=WHITE).next_to(matrix, UP, buff=0.2)\n box = SurroundingRectangle(matrix, color=GREEN_D, buff=0.18)\n\n self.play(FadeIn(title), Create(plane), FadeIn(base), run_time=3)\n self.play(GrowArrow(input_vec), FadeIn(input_label), FadeIn(formula_a), run_time=3)\n self.play(TransformMatchingTex(formula_a, formula_b), FadeIn(matrix), FadeIn(matrix_title), run_time=3)\n self.play(Create(box), TransformFromCopy(input_vec, output_vec), FadeIn(output_label), run_time=4)\n self.play(Indicate(matrix, color=GREEN_A), Indicate(output_vec, color=GREEN_A), run_time=3)\n self.wait(2)\n```", "category": "spatial_layout_overlap", "source": "synthetic_hard_neg:sebastianboehler/autoresearch-manim"} +{"system": "You are an expert Manim Community Edition (ManimCE v0.19+) Python developer and mathematical animator. Given a user request, first plan the spatial layout, coordinate bounds, timing, and pedagogical flow inside ... tags (when reasoning is helpful), and then output a complete, runnable, self-contained ManimCE Python script using `from manim import *`. Never use deprecated ManimGL (`manimlib`) methods like `ShowCreation`, `TexMobject`, `TextMobject`, or `axes.get_graph`; always use modern ManimCE APIs (`Create`, `MathTex`, `Tex`, `Text`, `axes.plot`) and prevent visual overlap using `.to_edge()`, `.next_to()`, and `FadeOut`.", "prompt": "The following Manim CE scene failed to compile. Truncated traceback:\n\nTypeError: Mobject.__init__() got an unexpected keyword argument 'max_magnitude'\n\nFix the code. Return a complete working scene. Do not keep the invalid constructor kwargs or Unicode subscripts.\n\n```python\nfrom manim import *\nfrom manim import config\nText.set_default(font='SimHei')\n\nclass DiscreteTimeImpulseResponse(Scene):\n\n def construct(self):\n bad = ArrowVectorField(lambda p: p, max_magnitude=2)\n title = Tex('\\\\textbf{Discrete Time:} ', '$h[n]=\\\\mathcal{T}\\\\{\\\\delta[n]\\\\}$', font_size=48)\n title[1].set_color(YELLOW)\n title.to_edge(UP)\n sys_box = Rectangle(width=2.8, height=1.6, color=BLUE)\n sys_box.move_to(UP * 0.5)\n sys_text = MathTex('\\\\mathcal{T}', font_size=48).move_to(sys_box.get_center())\n sys_group = VGroup(sys_box, sys_text)\n arrow_in = Arrow(start=LEFT * 5.5 + UP * 0.5, end=sys_box.get_left(), buff=0.1, color=WHITE)\n arrow_out = Arrow(start=sys_box.get_right(), end=RIGHT * 5.5 + UP * 0.5, buff=0.1, color=WHITE)\n input_label = MathTex('\\\\delta[n]', font_size=40, color=YELLOW).next_to(arrow_in, UP, buff=0.2)\n output_label = MathTex('h[n]', font_size=40, color=GREEN).next_to(arrow_out, UP, buff=0.2)\n\n def create_mini_stem(data, color):\n group = VGroup()\n axis = Line(LEFT * 1.2, RIGHT * 1.2, color=GREY)\n group.add(axis)\n for i, y in enumerate(data):\n x_pos = -0.8 + i * 0.53\n base_pt = axis.get_center() + RIGHT * x_pos\n if y != 0:\n stem = Line(base_pt, base_pt + UP * y, color=color)\n dot = Dot(stem.get_end(), color=color, radius=0.06)\n group.add(stem, dot)\n else:\n dot = Dot(base_pt, color=color, radius=0.06)\n group.add(dot)\n else:\n pass\n return group\n in_stems = create_mini_stem([0, 1.2, 0, 0], YELLOW)\n in_stems.next_to(arrow_in, DOWN, buff=0.5)\n out_stems = create_mini_stem([0, 0.9, 0.6, 0.3], GREEN)\n out_stems.next_to(arrow_out, DOWN, buff=0.5)\n out_stems.align_to(in_stems, DOWN)\n desc = Tex('In the discrete case, the response of the system to the \\\\\\\\', 'unit impulse sequence ', '$\\\\delta[n]$', ' also contains all the \\\\\\\\', 'dynamic information', ' about the system.', font_size=36)\n desc.set_color_by_tex('unit impulse sequence', YELLOW)\n desc.set_color_by_tex('\\\\delta[n]', YELLOW)\n desc.set_color_by_tex('dynamic information', GREEN)\n desc.to_edge(DOWN, buff=0.8)\n self.play(Write(title))\n self.wait(0.5)\n self.play(Create(sys_box), Write(sys_text))\n self.wait(0.5)\n self.play(GrowArrow(arrow_in), Write(input_label))\n self.play(Create(in_stems))\n self.wait(0.5)\n self.play(GrowArrow(arrow_out), Write(output_label))\n self.play(Create(out_stems))\n self.wait(0.5)\n self.play(Write(desc))\n self.wait(2)\n```", "chosen": "```python\nfrom manim import *\nfrom manim import config\nText.set_default(font='SimHei')\n\nclass DiscreteTimeImpulseResponse(Scene):\n\n def construct(self):\n title = Tex('\\\\textbf{Discrete Time:} ', '$h[n]=\\\\mathcal{T}\\\\{\\\\delta[n]\\\\}$', font_size=48)\n title[1].set_color(YELLOW)\n title.to_edge(UP)\n sys_box = Rectangle(width=2.8, height=1.6, color=BLUE)\n sys_box.move_to(UP * 0.5)\n sys_text = MathTex('\\\\mathcal{T}', font_size=48).move_to(sys_box.get_center())\n sys_group = VGroup(sys_box, sys_text)\n arrow_in = Arrow(start=LEFT * 5.5 + UP * 0.5, end=sys_box.get_left(), buff=0.1, color=WHITE)\n arrow_out = Arrow(start=sys_box.get_right(), end=RIGHT * 5.5 + UP * 0.5, buff=0.1, color=WHITE)\n input_label = MathTex('\\\\delta[n]', font_size=40, color=YELLOW).next_to(arrow_in, UP, buff=0.2)\n output_label = MathTex('h[n]', font_size=40, color=GREEN).next_to(arrow_out, UP, buff=0.2)\n\n def create_mini_stem(data, color):\n group = VGroup()\n axis = Line(LEFT * 1.2, RIGHT * 1.2, color=GREY)\n group.add(axis)\n for i, y in enumerate(data):\n x_pos = -0.8 + i * 0.53\n base_pt = axis.get_center() + RIGHT * x_pos\n if y != 0:\n stem = Line(base_pt, base_pt + UP * y, color=color)\n dot = Dot(stem.get_end(), color=color, radius=0.06)\n group.add(stem, dot)\n else:\n dot = Dot(base_pt, color=color, radius=0.06)\n group.add(dot)\n else:\n pass\n return group\n in_stems = create_mini_stem([0, 1.2, 0, 0], YELLOW)\n in_stems.next_to(arrow_in, DOWN, buff=0.5)\n out_stems = create_mini_stem([0, 0.9, 0.6, 0.3], GREEN)\n out_stems.next_to(arrow_out, DOWN, buff=0.5)\n out_stems.align_to(in_stems, DOWN)\n desc = Tex('In the discrete case, the response of the system to the \\\\\\\\', 'unit impulse sequence ', '$\\\\delta[n]$', ' also contains all the \\\\\\\\', 'dynamic information', ' about the system.', font_size=36)\n desc.set_color_by_tex('unit impulse sequence', YELLOW)\n desc.set_color_by_tex('\\\\delta[n]', YELLOW)\n desc.set_color_by_tex('dynamic information', GREEN)\n desc.to_edge(DOWN, buff=0.8)\n self.play(Write(title))\n self.wait(0.5)\n self.play(Create(sys_box), Write(sys_text))\n self.wait(0.5)\n self.play(GrowArrow(arrow_in), Write(input_label))\n self.play(Create(in_stems))\n self.wait(0.5)\n self.play(GrowArrow(arrow_out), Write(output_label))\n self.play(Create(out_stems))\n self.wait(0.5)\n self.play(Write(desc))\n self.wait(2)\n```", "rejected": "```python\nfrom manim import *\nfrom manim import config\nText.set_default(font='SimHei')\n\nclass DiscreteTimeImpulseResponse(Scene):\n\n def construct(self):\n title = Tex('\\\\textbf{Discrete Time:} ', '$h[n]=\\\\mathcal{T}\\\\{\\\\delta[n]\\\\}$', font_size=48)\n title[1].set_color(YELLOW)\n title.to_edge(UP)\n sys_box = Rectangle(width=2.8, height=1.6, color=BLUE)\n sys_box.move_to(UP * 0.5)\n sys_text = TexMobject('\\\\mathcal{T}', font_size=48).move_to(sys_box.get_center())\n sys_group = VGroup(sys_box, sys_text)\n arrow_in = Arrow(start=LEFT * 5.5 + UP * 0.5, end=sys_box.get_left(), buff=0.1, color=WHITE)\n arrow_out = Arrow(start=sys_box.get_right(), end=RIGHT * 5.5 + UP * 0.5, buff=0.1, color=WHITE)\n input_label = MathTex('\\\\delta[n]', font_size=40, color=YELLOW).next_to(arrow_in, UP, buff=0.2)\n output_label = MathTex('h[n]', font_size=40, color=GREEN).next_to(arrow_out, UP, buff=0.2)\n\n def create_mini_stem(data, color):\n group = VGroup()\n axis = Line(LEFT * 1.2, RIGHT * 1.2, color=GREY)\n group.add(axis)\n for i, y in enumerate(data):\n x_pos = -0.8 + i * 0.53\n base_pt = axis.get_center() + RIGHT * x_pos\n if y != 0:\n stem = Line(base_pt, base_pt + UP * y, color=color)\n dot = Dot(stem.get_end(), color=color, radius=0.06)\n group.add(stem, dot)\n else:\n dot = Dot(base_pt, color=color, radius=0.06)\n group.add(dot)\n else:\n pass\n return group\n in_stems = create_mini_stem([0, 1.2, 0, 0], YELLOW)\n in_stems.next_to(arrow_in, DOWN, buff=0.5)\n out_stems = create_mini_stem([0, 0.9, 0.6, 0.3], GREEN)\n out_stems.next_to(arrow_out, DOWN, buff=0.5)\n out_stems.align_to(in_stems, DOWN)\n desc = Tex('In the discrete case, the response of the system to the \\\\\\\\', 'unit impulse sequence ', '$\\\\delta[n]$', ' also contains all the \\\\\\\\', 'dynamic information', ' about the system.', font_size=36)\n desc.set_color_by_tex('unit impulse sequence', YELLOW)\n desc.set_color_by_tex('\\\\delta[n]', YELLOW)\n desc.set_color_by_tex('dynamic information', GREEN)\n desc.to_edge(DOWN, buff=0.8)\n self.play(Write(title))\n self.wait(0.5)\n self.play(ShowCreation(sys_box), Write(sys_text))\n self.wait(0.5)\n self.play(GrowArrow(arrow_in), Write(input_label))\n self.play(Create(in_stems))\n self.wait(0.5)\n self.play(GrowArrow(arrow_out), Write(output_label))\n self.play(Create(out_stems))\n self.wait(0.5)\n self.play(Write(desc))\n self.wait(2)\n```", "category": "legacy_api_hallucination", "source": "synthetic_hard_neg:nabin2004/manim-sft-10k"} +{"system": "You are an expert Manim Community Edition (ManimCE v0.19+) Python developer and mathematical animator. Given a user request, first plan the spatial layout, coordinate bounds, timing, and pedagogical flow inside ... tags (when reasoning is helpful), and then output a complete, runnable, self-contained ManimCE Python script using `from manim import *`. Never use deprecated ManimGL (`manimlib`) methods like `ShowCreation`, `TexMobject`, `TextMobject`, or `axes.get_graph`; always use modern ManimCE APIs (`Create`, `MathTex`, `Tex`, `Text`, `axes.plot`) and prevent visual overlap using `.to_edge()`, `.next_to()`, and `FadeOut`.", "prompt": "Create a Manim animation for a classroom-style educational video about averages and their limitations. The video should be in 16:9 format.\n\nStart with a title screen displaying \"Understanding Averages\" in large text. Then introduce the question \"What is an average?\" centered on the screen.\n\nNext, show a simple dataset visualization. Display two rows of numbers representing income data from two different countries. Country A: 20,000, 30,000, 40,000, 50,000, 60,000 and Country B: 10,000, 15,000, 50,000, 85,000, 90,000. Calculate and highlight the average for each country, showing that both equal 40,000.\n\nThen reveal the answer definition: \"An average is a single value that represents the central tendency of a set of data.\"\n\nNext, demonstrate the limitation by showing the same two datasets again, this time with visual bars of different heights to represent the distribution. Show how Country A has fairly evenly distributed income while Country B has extreme disparities, despite having identical averages.\n\nAdd explanatory text: \"Averages can be misleading because they don't show variations or disparities within the data.\" Include a visual representation comparing equal averages with unequal distributions.\n\nConclude with a key takeaway message: \"While averages are useful tools, they should be interpreted with caution and combined with other statistical measures for a complete picture.\"\n\nUse contrasting colors, clear labeling, and smooth transitions between sections. Keep text readable and animations at a natural pace suitable for classroom learning.", "chosen": "```python\nfrom manim import *\nimport numpy as np\n\nclass AverageLesson(Scene):\n def construct(self):\n # --- Section 1: Title & Introduction ---\n # Timing: ~8 seconds\n \n title = Text(\"Understanding Averages\", font_size=54, color=WHITE)\n title.to_edge(UP, buff=1.0)\n \n question = Text(\"What is an average?\", font_size=42, color=\"#4a9eff\")\n question.next_to(title, DOWN, buff=1.0)\n \n self.play(Write(title), run_time=1.5)\n self.play(FadeIn(question, shift=UP), run_time=1.5)\n self.wait(2.0)\n \n self.play(\n FadeOut(title),\n FadeOut(question),\n run_time=1.0\n )\n\n # --- Section 2: The Data Sets ---\n # Timing: ~25 seconds\n\n # Headers\n header_a = Text(\"Country A Income\", font_size=32, color=\"#4a9eff\")\n header_b = Text(\"Country B Income\", font_size=32, color=\"#e8945e\")\n \n # Position headers\n header_a.move_to([-3.5, 2.5, 0])\n header_b.move_to([3.5, 2.5, 0])\n \n self.play(Write(header_a), Write(header_b), run_time=1.5)\n\n # Data values\n vals_a = [20000, 30000, 40000, 50000, 60000]\n vals_b = [10000, 15000, 50000, 85000, 90000]\n \n # Formatting helper\n def format_num(n):\n return \"{:,}\".format(n)\n\n # Create VGroups for lists\n list_a = VGroup(*[Text(format_num(n), font_size=28) for n in vals_a])\n list_b = VGroup(*[Text(format_num(n), font_size=28) for n in vals_b])\n \n # Arrange vertically\n list_a.arrange(DOWN, buff=0.3)\n list_b.arrange(DOWN, buff=0.3)\n \n # Position below headers\n list_a.next_to(header_a, DOWN, buff=0.5)\n list_b.next_to(header_b, DOWN, buff=0.5)\n \n self.play(\n FadeIn(list_a, shift=DOWN),\n FadeIn(list_b, shift=DOWN),\n run_time=2.0\n )\n self.wait(1.0)\n\n # Calculation Text\n avg_text_a = MathTex(r\"\\text{Average} = 40,000\", color=\"#4a9eff\", font_size=36)\n avg_text_b = MathTex(r\"\\text{Average} = 40,000\", color=\"#e8945e\", font_size=36)\n \n avg_text_a.next_to(list_a, DOWN, buff=0.5)\n avg_text_b.next_to(list_b, DOWN, buff=0.5)\n \n # Highlight box for averages\n box_a = SurroundingRectangle(avg_text_a, color=\"#4a9eff\", buff=0.15)\n box_b = SurroundingRectangle(avg_text_b, color=\"#e8945e\", buff=0.15)\n\n self.play(Write(avg_text_a), Write(avg_text_b), run_time=2.0)\n self.play(Create(box_a), Create(box_b), run_time=1.0)\n self.wait(2.0)\n \n # Clean up for definition\n self.play(\n *[FadeOut(m) for m in [header_a, header_b, list_a, list_b, avg_text_a, avg_text_b, box_a, box_b]],\n run_time=1.0\n )\n\n # --- Section 3: Definition ---\n # Timing: ~12 seconds\n\n def_title = Text(\"Definition\", font_size=40, color=\"#6ba76e\")\n def_title.to_edge(UP, buff=1.0)\n \n def_text = Text(\n \"An average is a single value that represents\\n\"\n \"the central tendency of a set of data.\",\n font_size=32,\n line_spacing=1.2,\n t2c={\"central tendency\": \"#6ba76e\"}\n )\n def_text.move_to(ORIGIN)\n \n self.play(FadeIn(def_title, shift=UP), run_time=1.0)\n self.play(Write(def_text), run_time=3.0)\n self.wait(3.0)\n \n self.play(FadeOut(def_title), FadeOut(def_text), run_time=1.0)\n\n # --- Section 4: Visual Limitations (Bar Charts) ---\n # Timing: ~30 seconds\n\n # Re-establish headers\n header_a.move_to([-3.5, 3, 0])\n header_b.move_to([3.5, 3, 0])\n \n self.play(FadeIn(header_a), FadeIn(header_b), run_time=1.0)\n\n # Axes setup\n axis_width = 5\n max_height = 4.0\n max_val = 100000\n \n # Helper to create bars\n def create_bars(values, color, center_x):\n bars = VGroup()\n bar_width = 0.6\n spacing = 0.2\n total_width = len(values) * bar_width + (len(values)-1) * spacing\n start_x = center_x - total_width / 2 + bar_width / 2\n \n for i, val in enumerate(values):\n h = (val / max_val) * max_height\n bar = Rectangle(width=bar_width, height=h, color=color, fill_opacity=0.8)\n bar.move_to([start_x + i*(bar_width+spacing), -2 + h/2, 0]) # Base at y = -2\n bars.add(bar)\n \n base_line = Line(\n start=[center_x - 3, -2, 0],\n end=[center_x + 3, -2, 0],\n color=GREY\n )\n return bars, base_line\n\n bars_a, line_a = create_bars(vals_a, \"#4a9eff\", -3.5)\n bars_b, line_b = create_bars(vals_b, \"#e8945e\", 3.5)\n \n self.play(Create(line_a), Create(line_b), run_time=1.0)\n self.play(GrowFromEdge(bars_a, DOWN), GrowFromEdge(bars_b, DOWN), run_time=2.0)\n \n # Average Line (40k)\n avg_h = (40000 / max_val) * max_height\n avg_y = -2 + avg_h\n \n dashed_line = DashedLine(\n start=[-6.5, avg_y, 0],\n end=[6.5, avg_y, 0],\n color=\"#6ba76e\"\n )\n \n avg_label = Text(\"Average: 40,000\", font_size=24, color=\"#6ba76e\")\n avg_label.next_to(dashed_line, UP, buff=0.1)\n avg_label.to_edge(RIGHT, buff=1.0)\n \n self.play(Create(dashed_line), Write(avg_label), run_time=1.5)\n \n # Explanation text\n explanation = Text(\n \"Same Average, Different Distribution\",\n font_size=36,\n color=WHITE\n )\n explanation.to_edge(UP, buff=1.5)\n \n # Background box for text readability if needed, but safe zone is clear\n self.play(FadeIn(explanation), run_time=1.0)\n \n # Highlight disparity in B (Scale animation)\n # We animate the bars of B to emphasize height difference\n self.play(\n bars_b.animate.set_color(RED),\n run_time=1.0\n )\n self.wait(2.0)\n \n # Revert color\n self.play(bars_b.animate.set_color(\"#e8945e\"), run_time=1.0)\n \n # Variation text\n variation_text = Text(\n \"Averages hide variation!\",\n font_size=32,\n color=RED\n )\n variation_text.next_to(explanation, DOWN, buff=0.3)\n self.play(Write(variation_text), run_time=1.0)\n self.wait(2.0)\n\n # Cleanup\n self.play(\n FadeOut(bars_a), FadeOut(bars_b),\n FadeOut(line_a), FadeOut(line_b),\n FadeOut(dashed_line), FadeOut(avg_label),\n FadeOut(header_a), FadeOut(header_b),\n FadeOut(explanation), FadeOut(variation_text),\n run_time=1.0\n )\n\n # --- Section 5: Conclusion ---\n # Timing: ~10 seconds\n\n takeaway_title = Text(\"Key Takeaway\", font_size=48, color=\"#6ba76e\")\n takeaway_title.to_edge(UP, buff=1.0)\n \n takeaway_body = Text(\n \"While averages are useful, they should be\\n\"\n \"interpreted with caution and combined with\\n\"\n \"other statistical measures.\",\n font_size=32,\n line_spacing=1.5,\n t2c={\"caution\": RED, \"other statistical measures\": \"#4a9eff\"}\n )\n takeaway_body.next_to(takeaway_title, DOWN, buff=1.0)\n \n self.play(Write(takeaway_title), run_time=1.0)\n self.play(FadeIn(takeaway_body, shift=UP), run_time=2.0)\n \n # Final pause\n self.wait(3.0)\n```", "rejected": "```python\nfrom manim import *\nimport numpy as np\n\nclass AverageLesson(Scene):\n def construct(self):\n # --- Section 1: Title & Introduction ---\n # Timing: ~8 seconds\n \n title = Text(\"Understanding Averages\", font_size=54, color=WHITE)\n title\n \n question = Text(\"What is an average?\", font_size=42, color=\"#4a9eff\")\n question\n \n self.play(Write(title), run_time=1.5)\n self.play(FadeIn(question, shift=UP), run_time=1.5)\n self.wait(2.0)\n \n self.play(\n FadeOut(title),\n FadeOut(question),\n run_time=1.0\n )\n\n # --- Section 2: The Data Sets ---\n # Timing: ~25 seconds\n\n # Headers\n header_a = Text(\"Country A Income\", font_size=32, color=\"#4a9eff\")\n header_b = Text(\"Country B Income\", font_size=32, color=\"#e8945e\")\n \n # Position headers\n header_a.move_to([-3.5, 2.5, 0])\n header_b.move_to([3.5, 2.5, 0])\n \n self.play(Write(header_a), Write(header_b), run_time=1.5)\n\n # Data values\n vals_a = [20000, 30000, 40000, 50000, 60000]\n vals_b = [10000, 15000, 50000, 85000, 90000]\n \n # Formatting helper\n def format_num(n):\n return \"{:,}\".format(n)\n\n # Create VGroups for lists\n list_a = VGroup(*[Text(format_num(n), font_size=28) for n in vals_a])\n list_b = VGroup(*[Text(format_num(n), font_size=28) for n in vals_b])\n \n # Arrange vertically\n list_a.arrange(DOWN, buff=0.3)\n list_b.arrange(DOWN, buff=0.3)\n \n # Position below headers\n list_a\n list_b.next_to(header_b, DOWN, buff=0.5)\n \n self.play(\n FadeIn(list_a, shift=DOWN),\n FadeIn(list_b, shift=DOWN),\n run_time=2.0\n )\n self.wait(1.0)\n\n # Calculation Text\n avg_text_a = MathTex(r\"\\text{Average} = 40,000\", color=\"#4a9eff\", font_size=36)\n avg_text_b = MathTex(r\"\\text{Average} = 40,000\", color=\"#e8945e\", font_size=36)\n \n avg_text_a.next_to(list_a, DOWN, buff=0.5)\n avg_text_b.next_to(list_b, DOWN, buff=0.5)\n \n # Highlight box for averages\n box_a = SurroundingRectangle(avg_text_a, color=\"#4a9eff\", buff=0.15)\n box_b = SurroundingRectangle(avg_text_b, color=\"#e8945e\", buff=0.15)\n\n self.play(Write(avg_text_a), Write(avg_text_b), run_time=2.0)\n self.play(Create(box_a), Create(box_b), run_time=1.0)\n self.wait(2.0)\n \n # Clean up for definition\n self.play(\n *[FadeOut(m) for m in [header_a, header_b, list_a, list_b, avg_text_a, avg_text_b, box_a, box_b]],\n run_time=1.0\n )\n\n # --- Section 3: Definition ---\n # Timing: ~12 seconds\n\n def_title = Text(\"Definition\", font_size=40, color=\"#6ba76e\")\n def_title.to_edge(UP, buff=1.0)\n \n def_text = Text(\n \"An average is a single value that represents\\n\"\n \"the central tendency of a set of data.\",\n font_size=32,\n line_spacing=1.2,\n t2c={\"central tendency\": \"#6ba76e\"}\n )\n def_text.move_to(ORIGIN)\n \n self.play(FadeIn(def_title, shift=UP), run_time=1.0)\n self.play(Write(def_text), run_time=3.0)\n self.wait(3.0)\n \n self.play(FadeOut(def_title), FadeOut(def_text), run_time=1.0)\n\n # --- Section 4: Visual Limitations (Bar Charts) ---\n # Timing: ~30 seconds\n\n # Re-establish headers\n header_a.move_to([-3.5, 3, 0])\n header_b.move_to([3.5, 3, 0])\n \n self.play(FadeIn(header_a), FadeIn(header_b), run_time=1.0)\n\n # Axes setup\n axis_width = 5\n max_height = 4.0\n max_val = 100000\n \n # Helper to create bars\n def create_bars(values, color, center_x):\n bars = VGroup()\n bar_width = 0.6\n spacing = 0.2\n total_width = len(values) * bar_width + (len(values)-1) * spacing\n start_x = center_x - total_width / 2 + bar_width / 2\n \n for i, val in enumerate(values):\n h = (val / max_val) * max_height\n bar = Rectangle(width=bar_width, height=h, color=color, fill_opacity=0.8)\n bar.move_to([start_x + i*(bar_width+spacing), -2 + h/2, 0]) # Base at y = -2\n bars.add(bar)\n \n base_line = Line(\n start=[center_x - 3, -2, 0],\n end=[center_x + 3, -2, 0],\n color=GREY\n )\n return bars, base_line\n\n bars_a, line_a = create_bars(vals_a, \"#4a9eff\", -3.5)\n bars_b, line_b = create_bars(vals_b, \"#e8945e\", 3.5)\n \n self.play(Create(line_a), Create(line_b), run_time=1.0)\n self.play(GrowFromEdge(bars_a, DOWN), GrowFromEdge(bars_b, DOWN), run_time=2.0)\n \n # Average Line (40k)\n avg_h = (40000 / max_val) * max_height\n avg_y = -2 + avg_h\n \n dashed_line = DashedLine(\n start=[-6.5, avg_y, 0],\n end=[6.5, avg_y, 0],\n color=\"#6ba76e\"\n )\n \n avg_label = Text(\"Average: 40,000\", font_size=24, color=\"#6ba76e\")\n avg_label.next_to(dashed_line, UP, buff=0.1)\n avg_label.to_edge(RIGHT, buff=1.0)\n \n self.play(Create(dashed_line), Write(avg_label), run_time=1.5)\n \n # Explanation text\n explanation = Text(\n \"Same Average, Different Distribution\",\n font_size=36,\n color=WHITE\n )\n explanation.to_edge(UP, buff=1.5)\n \n # Background box for text readability if needed, but safe zone is clear\n self.play(FadeIn(explanation), run_time=1.0)\n \n # Highlight disparity in B (Scale animation)\n # We animate the bars of B to emphasize height difference\n self.play(\n bars_b.animate.set_color(RED),\n run_time=1.0\n )\n self.wait(2.0)\n \n # Revert color\n self.play(bars_b.animate.set_color(\"#e8945e\"), run_time=1.0)\n \n # Variation text\n variation_text = Text(\n \"Averages hide variation!\",\n font_size=32,\n color=RED\n )\n variation_text.next_to(explanation, DOWN, buff=0.3)\n self.play(Write(variation_text), run_time=1.0)\n self.wait(2.0)\n\n # Cleanup\n self.play(\n FadeOut(bars_a), FadeOut(bars_b),\n FadeOut(line_a), FadeOut(line_b),\n FadeOut(dashed_line), FadeOut(avg_label),\n FadeOut(header_a), FadeOut(header_b),\n FadeOut(explanation), FadeOut(variation_text),\n run_time=1.0\n )\n\n # --- Section 5: Conclusion ---\n # Timing: ~10 seconds\n\n takeaway_title = Text(\"Key Takeaway\", font_size=48, color=\"#6ba76e\")\n takeaway_title.to_edge(UP, buff=1.0)\n \n takeaway_body = Text(\n \"While averages are useful, they should be\\n\"\n \"interpreted with caution and combined with\\n\"\n \"other statistical measures.\",\n font_size=32,\n line_spacing=1.5,\n t2c={\"caution\": RED, \"other statistical measures\": \"#4a9eff\"}\n )\n takeaway_body.next_to(takeaway_title, DOWN, buff=1.0)\n \n self.play(Write(takeaway_title), run_time=1.0)\n self.play(FadeIn(takeaway_body, shift=UP), run_time=2.0)\n \n # Final pause\n self.wait(3.0)\n```", "category": "spatial_layout_overlap", "source": "synthetic_hard_neg:nabin2004/manim-sft-10k"} +{"system": "You are an expert Manim Community Edition (ManimCE v0.19+) Python developer and mathematical animator. Given a user request, first plan the spatial layout, coordinate bounds, timing, and pedagogical flow inside ... tags (when reasoning is helpful), and then output a complete, runnable, self-contained ManimCE Python script using `from manim import *`. Never use deprecated ManimGL (`manimlib`) methods like `ShowCreation`, `TexMobject`, `TextMobject`, or `axes.get_graph`; always use modern ManimCE APIs (`Create`, `MathTex`, `Tex`, `Text`, `axes.plot`) and prevent visual overlap using `.to_edge()`, `.next_to()`, and `FadeOut`.", "prompt": "I'm studying NLP and want to compare human-written text with a bigram-generated version. Create a side-by-side display with the two texts, color-coding differences at the word- or phrase-level and visually highlighting changed zones. Animate a diff pipeline that reveals where bigram generation matches or deviates, with a timeline of sentences and a scroll-through of examples. Offer a brief explanation overlay about why bigrams struggle with long-range coherence.", "chosen": "```python\nfrom manim import *\nfrom manim_voiceover import VoiceoverScene\nfrom manim_voiceover.services.gtts import GTTSService\n\nclass NLPBigramComparison(VoiceoverScene):\n def construct(self):\n self.set_speech_service(\n GTTSService(voice=\"alba\", cache_dir=\"voiceover_cache\")\n )\n \n # Title\n title = Text(\"NLP Text Comparison Using Bigrams\", font_size=36, color=BLUE)\n title.to_edge(UP, buff=0.5)\n \n with self.voiceover(text=\"Have you ever wondered how search engines match queries with relevant documents? Imagine you have two sentences that seem different at first glance, yet they share similar meanings. Today, we'll explore the concept of bigrams and how they can help us compare texts more effectively.\") as tracker:\n self.play(Write(title), run_time=tracker.duration)\n \n self.wait(0.5)\n \n # Section 1: What are Bigrams?\n section1 = Text(\"1. What are Bigrams?\", font_size=28, color=YELLOW)\n section1.next_to(title, DOWN, buff=0.8)\n \n with self.voiceover(text=\"First, let's understand what bigrams are. A bigram is simply a pair of consecutive words in a text.\") as tracker:\n self.play(Write(section1), run_time=tracker.duration)\n \n # Example sentence\n sentence = Text('\"The quick brown fox jumps\"', font_size=24, color=WHITE)\n sentence.next_to(section1, DOWN, buff=0.6)\n \n with self.voiceover(text=\"Take this sentence as an example.\") as tracker:\n self.play(Write(sentence), run_time=tracker.duration)\n \n self.wait(0.3)\n \n # Show bigram extraction\n bigram_explanation = Text(\"Bigrams = consecutive word pairs\", font_size=22, color=GRAY)\n bigram_explanation.next_to(sentence, DOWN, buff=0.5)\n \n with self.voiceover(text=\"To extract bigrams, we slide a window of two words across the sentence.\") as tracker:\n self.play(Write(bigram_explanation), run_time=tracker.duration)\n \n # Create bigram boxes\n words = [\"The\", \"quick\", \"brown\", \"fox\", \"jumps\"]\n word_group = VGroup(*[Text(w, font_size=20) for w in words])\n word_group.arrange(RIGHT, buff=0.4)\n word_group.next_to(bigram_explanation, DOWN, buff=0.5)\n \n with self.voiceover(text=\"Here are the individual words.\") as tracker:\n self.play(Write(word_group), run_time=tracker.duration)\n \n # Show bigrams with highlighting\n bigrams = [\n (\"The quick\", 0, 1),\n (\"quick brown\", 1, 2),\n (\"brown fox\", 2, 3),\n (\"fox jumps\", 3, 4)\n ]\n \n bigram_texts = VGroup()\n for i, (bg, _, _) in enumerate(bigrams):\n t = Text(f'\"{bg}\"', font_size=18, color=GREEN)\n bigram_texts.add(t)\n bigram_texts.arrange(RIGHT, buff=0.3)\n bigram_texts.next_to(word_group, DOWN, buff=0.6)\n \n with self.voiceover(text=\"Now, let's extract the bigrams. The first bigram is 'The quick', then 'quick brown', followed by 'brown fox', and finally 'fox jumps'.\") as tracker:\n for i, (bg_text, start_idx, end_idx) in enumerate(bigrams):\n # Highlight words\n rect = SurroundingRectangle(\n VGroup(word_group[start_idx], word_group[end_idx]),\n color=YELLOW,\n buff=0.1\n )\n self.play(Create(rect), run_time=0.4)\n self.play(Write(bigram_texts[i]), run_time=0.4)\n self.play(FadeOut(rect), run_time=0.2)\n \n self.wait(0.5)\n \n # Clear for next section\n with self.voiceover(text=\"Bigrams capture local word relationships and are fundamental in natural language processing.\") as tracker:\n self.play(\n FadeOut(section1),\n FadeOut(sentence),\n FadeOut(bigram_explanation),\n FadeOut(word_group),\n FadeOut(bigram_texts),\n run_time=tracker.duration\n )\n \n # Section 2: Comparing Texts with Bigrams\n section2 = Text(\"2. Comparing Texts Using Bigrams\", font_size=28, color=YELLOW)\n section2.next_to(title, DOWN, buff=0.8)\n \n with self.voiceover(text=\"Now, let's see how we can use bigrams to compare two texts and measure their similarity.\") as tracker:\n self.play(Write(section2), run_time=tracker.duration)\n \n # Two example sentences\n text1_label = Text(\"Text A:\", font_size=20, color=BLUE)\n text1_content = Text('\"Machine learning is fascinating\"', font_size=20)\n text1_group = VGroup(text1_label, text1_content).arrange(RIGHT, buff=0.3)\n text1_group.next_to(section2, DOWN, buff=0.6)\n \n text2_label = Text(\"Text B:\", font_size=20, color=RED)\n text2_content = Text('\"Machine learning is interesting\"', font_size=20)\n text2_group = VGroup(text2_label, text2_content).arrange(RIGHT, buff=0.3)\n text2_group.next_to(text1_group, DOWN, buff=0.4)\n \n with self.voiceover(text=\"Consider these two sentences. Text A says 'Machine learning is fascinating', while Text B says 'Machine learning is interesting'.\") as tracker:\n self.play(Write(text1_group), run_time=tracker.duration * 0.5)\n self.play(Write(text2_group), run_time=tracker.duration * 0.5)\n \n self.wait(0.3)\n \n # Extract bigrams for both\n bigrams_title = Text(\"Extracted Bigrams:\", font_size=22, color=GRAY)\n bigrams_title.next_to(text2_group, DOWN, buff=0.6)\n \n with self.voiceover(text=\"Let's extract the bigrams from both texts.\") as tracker:\n self.play(Write(bigrams_title), run_time=tracker.duration)\n \n # Text A bigrams\n bg1_label = Text(\"A:\", font_size=18, color=BLUE)\n bg1_list = Text('[\"Machine learning\", \"learning is\", \"is fascinating\"]', font_size=18)\n bg1_group = VGroup(bg1_label, bg1_list).arrange(RIGHT, buff=0.2)\n bg1_group.next_to(bigrams_title, DOWN, buff=0.4)\n \n # Text B bigrams \n bg2_label = Text(\"B:\", font_size=18, color=RED)\n bg2_list = Text('[\"Machine learning\", \"learning is\", \"is interesting\"]', font_size=18)\n bg2_group = VGroup(bg2_label, bg2_list).arrange(RIGHT, buff=0.2)\n bg2_group.next_to(bg1_group, DOWN, buff=0.3)\n \n with self.voiceover(text=\"Text A produces three bigrams: 'Machine learning', 'learning is', and 'is fascinating'. Text B produces: 'Machine learning', 'learning is', and 'is interesting'.\") as tracker:\n self.play(Write(bg1_group), run_time=tracker.duration * 0.5)\n self.play(Write(bg2_group), run_time=tracker.duration * 0.5)\n \n self.wait(0.3)\n \n # Show overlap\n overlap_title = Text(\"Common Bigrams (Overlap):\", font_size=22, color=GREEN)\n overlap_title.next_to(bg2_group, DOWN, buff=0.6)\n \n overlap_list = Text('[\"Machine learning\", \"learning is\"]', font_size=20, color=GREEN)\n overlap_list.next_to(overlap_title, DOWN, buff=0.3)\n \n with self.voiceover(text=\"Notice that two bigrams are shared between both texts: 'Machine learning' and 'learning is'. These common bigrams indicate textual similarity.\") as tracker:\n self.play(Write(overlap_title), run_time=tracker.duration * 0.5)\n self.play(Write(overlap_list), run_time=tracker.duration * 0.5)\n \n self.wait(0.5)\n \n # Clear for similarity calculation\n to_fade = [section2, text1_group, text2_group, bigrams_title, bg1_group, bg2_group, overlap_title, overlap_list]\n \n # Section 3: Similarity Score\n section3 = Text(\"3. Calculating Similarity Score\", font_size=28, color=YELLOW)\n section3.next_to(title, DOWN, buff=0.8)\n \n with self.voiceover(text=\"We can quantify this similarity using a simple formula.\") as tracker:\n self.play(*[FadeOut(obj) for obj in to_fade], run_time=0.5)\n self.play(Write(section3), run_time=tracker.duration)\n \n # Formula using plain text instead of MathTex with \text\n formula_label = Text(\"Similarity Formula:\", font_size=24, color=WHITE)\n formula_label.next_to(section3, DOWN, buff=0.6)\n \n # Use a visual representation instead of complex LaTeX\n formula = Text(\"Common Bigrams / Total Unique Bigrams\", font_size=26, color=GREEN)\n formula.next_to(formula_label, DOWN, buff=0.4)\n \n with self.voiceover(text=\"The similarity score equals the number of common bigrams divided by the total unique bigrams across both texts.\") as tracker:\n self.play(Write(formula_label), run_time=tracker.duration * 0.3)\n self.play(Write(formula), run_time=tracker.duration * 0.7)\n \n self.wait(0.3)\n \n # Calculation example\n calc_text = Text(\"For our example:\", font_size=22, color=GRAY)\n calc_text.next_to(formula, DOWN, buff=0.6)\n \n calc_detail = Text(\"2 common / 4 total = 0.5 = 50%\", font_size=26, color=GREEN)\n calc_detail.next_to(calc_text, DOWN, buff=0.4)\n \n with self.voiceover(text=\"In our example, there are 2 common bigrams out of 4 unique bigrams total, giving us a similarity score of 50 percent.\") as tracker:\n self.play(Write(calc_text), run_time=tracker.duration * 0.4)\n self.play(Write(calc_detail), run_time=tracker.duration * 0.6)\n \n self.wait(0.5)\n \n # Clear for applications\n self.play(\n FadeOut(section3),\n FadeOut(formula_label),\n FadeOut(formula),\n FadeOut(calc_text),\n FadeOut(calc_detail),\n run_time=0.5\n )\n \n # Section 4: Applications\n section4 = Text(\"4. Real-World Applications\", font_size=28, color=YELLOW)\n section4.next_to(title, DOWN, buff=0.8)\n \n with self.voiceover(text=\"Bigram comparison has many practical applications in natural language processing.\") as tracker:\n self.play(Write(section4), run_time=tracker.duration)\n \n # Applications list - two columns\n apps_col1 = VGroup(\n Text(\"• Search Engines\", font_size=20),\n Text(\"• Plagiarism Detection\", font_size=20),\n Text(\"• Document Clustering\", font_size=20),\n ).arrange(DOWN, buff=0.3, aligned_edge=LEFT)\n \n apps_col2 = VGroup(\n Text(\"• Spam Filtering\", font_size=20),\n Text(\"• Text Classification\", font_size=20),\n Text(\"• Recommendation Systems\", font_size=20),\n ).arrange(DOWN, buff=0.3, aligned_edge=LEFT)\n \n apps_group = VGroup(apps_col1, apps_col2).arrange(RIGHT, buff=1.5)\n apps_group.next_to(section4, DOWN, buff=0.6)\n \n with self.voiceover(text=\"These include search engines for matching queries to documents, plagiarism detection to find copied content, document clustering for organizing similar texts, spam filtering, text classification, and recommendation systems.\") as tracker:\n self.play(Write(apps_group), run_time=tracker.duration)\n \n self.wait(0.5)\n \n # Summary box\n summary_box = Rectangle(width=11, height=2.2, color=BLUE, fill_opacity=0.1)\n summary_box.to_edge(DOWN, buff=0.5)\n \n summary_title = Text(\"Key Takeaways\", font_size=22, color=BLUE)\n summary_title.next_to(summary_box, UP, buff=0.1)\n \n takeaways = VGroup(\n Text(\"1. Bigrams capture consecutive word pairs in text\", font_size=18),\n Text(\"2. Text similarity = overlap of bigrams / total unique bigrams\", font_size=18),\n Text(\"3. Bigram comparison is fast and effective for NLP tasks\", font_size=18)\n ).arrange(DOWN, buff=0.2)\n takeaways.move_to(summary_box.get_center())\n \n with self.voiceover(text=\"To summarize: bigrams capture consecutive word pairs, text similarity is calculated as the overlap divided by total unique bigrams, and bigram comparison provides a fast and effective method for various NLP tasks.\") as tracker:\n self.play(\n Create(summary_box),\n Write(summary_title),\n Write(takeaways),\n run_time=tracker.duration\n )\n \n self.wait(1)\n \n # End\n with self.voiceover(text=\"Thank you for watching. Now you understand how to use bigrams for comparing texts in NLP.\") as tracker:\n self.play(\n FadeOut(title),\n FadeOut(section4),\n FadeOut(apps_group),\n FadeOut(summary_box),\n FadeOut(summary_title),\n FadeOut(takeaways),\n run_time=tracker.duration\n )\n \n self.wait(0.5)\n```", "rejected": "```python\nfrom manim import *\n\nclass NLPBigramComparison(Scene):\n\n def construct(self):\n title = Text('NLP Text Comparison Using Bigrams', font_size=36, color=BLUE)\n title.to_edge(UP, buff=0.5)\n self.play(Write(title), run_time=2.0)\n self.wait(0.5)\n section1 = Text('1. What are Bigrams?', font_size=28, color=YELLOW)\n section1.next_to(title, DOWN, buff=0.8)\n self.play(Write(section1), run_time=2.0)\n sentence = Text('\"The quick brown fox jumps\"', font_size=24, color=WHITE)\n sentence.next_to(section1, DOWN, buff=0.6)\n self.play(Write(sentence), run_time=2.0)\n self.wait(0.3)\n bigram_explanation = Text('Bigrams = consecutive word pairs', font_size=22, color=GRAY)\n bigram_explanation.next_to(sentence, DOWN, buff=0.5)\n self.play(Write(bigram_explanation), run_time=2.0)\n words = ['The', 'quick', 'brown', 'fox', 'jumps']\n word_group = VGroup(*[Text(w, font_size=20) for w in words])\n word_group.arrange(RIGHT, buff=0.4)\n word_group.next_to(bigram_explanation, DOWN, buff=0.5)\n self.play(Write(word_group), run_time=2.0)\n bigrams = [('The quick', 0, 1), ('quick brown', 1, 2), ('brown fox', 2, 3), ('fox jumps', 3, 4)]\n bigram_texts = VGroup()\n for i, (bg, _, _) in enumerate(bigrams):\n t = Text(f'\"{bg}\"', font_size=18, color=GREEN)\n bigram_texts.add(t)\n bigram_texts.arrange(RIGHT, buff=0.3)\n bigram_texts.next_to(word_group, DOWN, buff=0.6)\n for i, (bg_text, start_idx, end_idx) in enumerate(bigrams):\n rect = SurroundingRectangle(VGroup(word_group[start_idx], word_group[end_idx]), color=YELLOW, buff=0.1)\n self.play(Create(rect), run_time=0.4)\n self.play(Write(bigram_texts[i]), run_time=0.4)\n self.play(FadeOut(rect), run_time=0.2)\n self.wait(0.5)\n self.play(FadeOut(section1), FadeOut(sentence), FadeOut(bigram_explanation), FadeOut(word_group), FadeOut(bigram_texts), run_time=2.0)\n section2 = Text('2. Comparing Texts Using Bigrams', font_size=28, color=YELLOW)\n section2.next_to(title, DOWN, buff=0.8)\n self.play(Write(section2), run_time=2.0)\n text1_label = Text('Text A:', font_size=20, color=BLUE)\n text1_content = Text('\"Machine learning is fascinating\"', font_size=20)\n text1_group = VGroup(text1_label, text1_content).arrange(RIGHT, buff=0.3)\n text1_group.next_to(section2, DOWN, buff=0.6)\n text2_label = Text('Text B:', font_size=20, color=RED)\n text2_content = Text('\"Machine learning is interesting\"', font_size=20)\n text2_group = VGroup(text2_label, text2_content).arrange(RIGHT, buff=0.3)\n text2_group.next_to(text1_group, DOWN, buff=0.4)\n self.play(Write(text1_group), run_time=2.0 * 0.5)\n self.play(Write(text2_group), run_time=2.0 * 0.5)\n self.wait(0.3)\n bigrams_title = Text('Extracted Bigrams:', font_size=22, color=GRAY)\n bigrams_title.next_to(text2_group, DOWN, buff=0.6)\n self.play(Write(bigrams_title), run_time=2.0)\n bg1_label = Text('A:', font_size=18, color=BLUE)\n bg1_list = Text('[\"Machine learning\", \"learning is\", \"is fascinating\"]', font_size=18)\n bg1_group = VGroup(bg1_label, bg1_list).arrange(RIGHT, buff=0.2)\n bg1_group.next_to(bigrams_title, DOWN, buff=0.4)\n bg2_label = Text('B:', font_size=18, color=RED)\n bg2_list = Text('[\"Machine learning\", \"learning is\", \"is interesting\"]', font_size=18)\n bg2_group = VGroup(bg2_label, bg2_list).arrange(RIGHT, buff=0.2)\n bg2_group.next_to(bg1_group, DOWN, buff=0.3)\n self.play(Write(bg1_group), run_time=2.0 * 0.5)\n self.play(Write(bg2_group), run_time=2.0 * 0.5)\n self.wait(0.3)\n overlap_title = Text('Common Bigrams (Overlap):', font_size=22, color=GREEN)\n overlap_title.next_to(bg2_group, DOWN, buff=0.6)\n overlap_list = Text('[\"Machine learning\", \"learning is\"]', font_size=20, color=GREEN)\n overlap_list.next_to(overlap_title, DOWN, buff=0.3)\n self.play(Write(overlap_title), run_time=2.0 * 0.5)\n self.play(Write(overlap_list), run_time=2.0 * 0.5)\n self.wait(0.5)\n to_fade = [section2, text1_group, text2_group, bigrams_title, bg1_group, bg2_group, overlap_title, overlap_list]\n section3 = Text('3. Calculating Similarity Score', font_size=28, color=YELLOW)\n section3.next_to(title, DOWN, buff=0.8)\n self.play(*[FadeOut(obj) for obj in to_fade], run_time=0.5)\n self.play(Write(section3), run_time=2.0)\n formula_label = Text('Similarity Formula:', font_size=24, color=WHITE)\n formula_label.next_to(section3, DOWN, buff=0.6)\n formula = Text('Common Bigrams / Total Unique Bigrams', font_size=26, color=GREEN)\n formula.next_to(formula_label, DOWN, buff=0.4)\n self.play(Write(formula_label), run_time=2.0 * 0.3)\n self.play(Write(formula), run_time=2.0 * 0.7)\n self.wait(0.3)\n calc_text = Text('For our example:', font_size=22, color=GRAY)\n calc_text.next_to(formula, DOWN, buff=0.6)\n calc_detail = Text('2 common / 4 total = 0.5 = 50%', font_size=26, color=GREEN)\n calc_detail.next_to(calc_text, DOWN, buff=0.4)\n self.play(Write(calc_text), run_time=2.0 * 0.4)\n self.play(Write(calc_detail), run_time=2.0 * 0.6)\n self.wait(0.5)\n self.play(FadeOut(section3), FadeOut(formula_label), FadeOut(formula), FadeOut(calc_text), FadeOut(calc_detail), run_time=0.5)\n section4 = Text('4. Real-World Applications', font_size=28, color=YELLOW)\n section4.next_to(title, DOWN, buff=0.8)\n self.play(Write(section4), run_time=2.0)\n apps_col1 = VGroup(Text('• Search Engines', font_size=20), Text('• Plagiarism Detection', font_size=20), Text('• Document Clustering', font_size=20)).arrange(DOWN, buff=0.3, aligned_edge=LEFT)\n apps_col2 = VGroup(Text('• Spam Filtering', font_size=20), Text('• Text Classification', font_size=20), Text('• Recommendation Systems', font_size=20)).arrange(DOWN, buff=0.3, aligned_edge=LEFT)\n apps_group = VGroup(apps_col1, apps_col2).arrange(RIGHT, buff=1.5)\n apps_group.next_to(section4, DOWN, buff=0.6)\n self.play(Write(apps_group), run_time=2.0)\n self.wait(0.5)\n summary_box = Rectangle(width=11, height=2.2, color=BLUE, fill_opacity=0.1)\n summary_box.to_edge(DOWN, buff=0.5)\n summary_title = Text('Key Takeaways', font_size=22, color=BLUE)\n summary_title.next_to(summary_box, UP, buff=0.1)\n takeaways = VGroup(Text('1. Bigrams capture consecutive word pairs in text', font_size=18), Text('2. Text similarity = overlap of bigrams / total unique bigrams', font_size=18), Text('3. Bigram comparison is fast and effective for NLP tasks', font_size=18)).arrange(DOWN, buff=0.2)\n takeaways.move_to(summary_box.get_center())\n self.play(Create(summary_box), Write(summary_title), Write(takeaways), run_time=2.0)\n self.wait(1)\n self.play(FadeOut(title), FadeOut(section4), FadeOut(apps_group), FadeOut(summary_box), FadeOut(summary_title), FadeOut(takeaways), run_time=2.0)\n self.wait(0.5)\n```", "category": "narrated_pedagogical_preference", "source": "nabin2004/manim-narrated-dpo-400"} +{"system": "You are an expert Manim Community Edition (ManimCE v0.19+) Python developer and mathematical animator. Given a user request, first plan the spatial layout, coordinate bounds, timing, and pedagogical flow inside ... tags (when reasoning is helpful), and then output a complete, runnable, self-contained ManimCE Python script using `from manim import *`. Never use deprecated ManimGL (`manimlib`) methods like `ShowCreation`, `TexMobject`, `TextMobject`, or `axes.get_graph`; always use modern ManimCE APIs (`Create`, `MathTex`, `Tex`, `Text`, `axes.plot`) and prevent visual overlap using `.to_edge()`, `.next_to()`, and `FadeOut`.", "prompt": "I would like an animated video that explains the process of integrating \\(\\sin(x)\\) from \\(0\\) to \\(\\pi\\), including the use of trigonometric identities and the evaluation of the definite integral, with the final answer displayed at the end. Can you create an animation that writes out the problem, provides a brief written explanation of the steps involved in solving it, shows the integration step where the trigonometric identity is used, and then evaluates the definite integral with the final solution appearing at the end? Please also make sure there is enough time for viewers to follow along with each step before moving on to the next.", "chosen": "```python\nfrom manim import *\n\nclass AreaUnderCurveExample(Scene):\n def construct(self):\n # Displaying the function and the area problem\n function = MathTex(r\"f(x) = x^2\")\n area_question = MathTex(r\"\\int_0^2 x^2 \\,dx\", color=YELLOW)\n self.play(Write(function))\n self.wait(1)\n self.play(Write(area_question))\n self.wait(1)\n\n # Drawing the graph\n graph = FunctionGraph(lambda x: x**2, x_range=[0, 2], color=WHITE)\n self.play(Create(graph))\n self.wait(1)\n\n # Filling the area under the graph\n area = graph.get_riemann_rectangles(x_range=[0, 2], dx=0.1)\n self.play(FadeIn(area))\n self.wait(2)\n\n # Explanation of Area Computation\n explanation1 = Text(\"The area under curve is the integral result\", font_size=24).to_edge(UP)\n self.play(FadeIn(explanation1))\n self.wait(2)\n\n # Computing the area\n area_computation = MathTex(r\"= \\left[\\frac{x^3}{3}\\right]_0^2\")\n self.play(Write(area_computation))\n self.wait(2)\n\n # Showing the final result\n final_result = MathTex(r\"= \\left[\\frac{2^3}{3}\\right] - \\left[\\frac{0^3}{3}\\right]\")\n self.play(Transform(area_computation, final_result))\n self.wait(1)\n\n # Simplifying the result\n simplified_result = MathTex(r\"= \\frac{8}{3}\")\n self.play(Transform(area_computation, simplified_result))\n self.wait(1)\n\n # Clear the scene and conclude\n self.play(FadeOut(graph), FadeOut(area), FadeOut(function), FadeOut(area_question), FadeOut(explanation1))\n self.wait(1)\n self.play(Write(simplified_result))\n self.wait(1)\n```", "rejected": "```python\nfrom manim import *\n\nclass AreaUnderCurveExample(Scene):\n def construct(self):\n # Displaying the function and the area problem\n function = TexMobject(r\"f(x) = x^2\")\n area_question = MathTex(r\"\\int_0^2 x^2 \\,dx\", color=YELLOW)\n self.play(Write(function))\n self.wait(1)\n self.play(Write(area_question))\n self.wait(1)\n\n # Drawing the graph\n graph = FunctionGraph(lambda x: x**2, x_range=[0, 2], color=WHITE)\n self.play(ShowCreation(graph))\n self.wait(1)\n\n # Filling the area under the graph\n area = graph.get_riemann_rectangles(x_range=[0, 2], dx=0.1)\n self.play(FadeIn(area))\n self.wait(2)\n\n # Explanation of Area Computation\n explanation1 = Text(\"The area under curve is the integral result\", font_size=24).to_edge(UP)\n self.play(FadeIn(explanation1))\n self.wait(2)\n\n # Computing the area\n area_computation = MathTex(r\"= \\left[\\frac{x^3}{3}\\right]_0^2\")\n self.play(Write(area_computation))\n self.wait(2)\n\n # Showing the final result\n final_result = MathTex(r\"= \\left[\\frac{2^3}{3}\\right] - \\left[\\frac{0^3}{3}\\right]\")\n self.play(Transform(area_computation, final_result))\n self.wait(1)\n\n # Simplifying the result\n simplified_result = MathTex(r\"= \\frac{8}{3}\")\n self.play(Transform(area_computation, simplified_result))\n self.wait(1)\n\n # Clear the scene and conclude\n self.play(FadeOut(graph), FadeOut(area), FadeOut(function), FadeOut(area_question), FadeOut(explanation1))\n self.wait(1)\n self.play(Write(simplified_result))\n self.wait(1)\n```", "category": "legacy_api_hallucination", "source": "synthetic_hard_neg:nabin2004/manim-sft-10k"} +{"system": "You are an expert Manim Community Edition (ManimCE v0.19+) Python developer and mathematical animator. Given a user request, first plan the spatial layout, coordinate bounds, timing, and pedagogical flow inside ... tags (when reasoning is helpful), and then output a complete, runnable, self-contained ManimCE Python script using `from manim import *`. Never use deprecated ManimGL (`manimlib`) methods like `ShowCreation`, `TexMobject`, `TextMobject`, or `axes.get_graph`; always use modern ManimCE APIs (`Create`, `MathTex`, `Tex`, `Text`, `axes.plot`) and prevent visual overlap using `.to_edge()`, `.next_to()`, and `FadeOut`.", "prompt": "Create an interactive Manim CE animation demonstrating: Cycloid Generation with TracedPath and rolling circle. Use updaters and ValueTracker.\n\n```python\nfrom manim import *\nimport numpy as np\n\nclass DynamicScene385(Scene):\n def construct(self):\n ground = Line(LEFT * 4 + DOWN * 1.5, RIGHT * 4 + DOWN * 1.5, color=GREY)\n r = 0.8\n theta = ValueTracker(0.0)\n \n wheel = always_redraw(lambda: Circle(radius=r, color=WHITE).move_to(\n LEFT * 3 + RIGHT * (r * theta.get_value()) + DOWN * (1.5 - r)\n ))\n dot = always_redraw(lambda: Dot(\n wheel.get_center() + np.array([-r * np.sin(theta.get_value()), -r * np.cos(theta.get_value()), 0]),\n color=RED, radius=0.08\n ))\n trail = TracedPath(dot.get_center, stroke_color=YELLOW, stroke_width=3)\n \n self.add(ground, trail, wheel, dot)\n self.play(theta.animate.set_value(2 * PI * 1.2), run_time=4, rate_func=linear)\n self.wait(1)\n```", "chosen": "```python\nfrom manim import *\nfrom manim_voiceover import VoiceoverScene\nfrom manim_voiceover.services.gtts import GTTSService\nimport numpy as np\n\nMARGIN = 0.5\n\nclass DynamicScene385(VoiceoverScene):\n def fit_in_frame(self, mob: Mobject, w_frac=0.9, h_frac=0.9) -> Mobject:\n max_w = config.frame_width * w_frac\n max_h = config.frame_height * h_frac\n if mob.width > max_w: mob.width = max_w\n if mob.height > max_h: mob.height = max_h\n return mob\n\n def construct(self):\n self.set_speech_service(GTTSService(transcription_model=\"base\"))\n \n # [SETUP]\n r = 1.0\n ground_y = -2\n theta_tracker = ValueTracker(0.0)\n \n # [LAYOUT]\n ground = Line(LEFT * 6 + DOWN * 2, RIGHT * 6 + DOWN * 2, color=GREY)\n self.add(self.fit_in_frame(ground))\n \n eq_x = MathTex(r\"x = r(\\theta - \\sin\\theta)\", color=BLUE).to_corner(UR, buff=MARGIN)\n eq_y = MathTex(r\"y = r(1 - \\cos\\theta)\", color=RED).next_to(eq_x, DOWN, aligned_edge=LEFT)\n \n # [UPDATER]\n def get_wheel():\n theta = theta_tracker.get_value()\n center_x = -5 + r * theta\n center_y = ground_y + r\n return Circle(radius=r, color=WHITE, fill_opacity=0.1).move_to(np.array([center_x, center_y, 0]))\n \n wheel = always_redraw(get_wheel)\n \n def get_dot():\n theta = theta_tracker.get_value()\n center_x = -5 + r * theta\n center_y = ground_y + r\n px = center_x - r * np.sin(theta)\n py = center_y - r * np.cos(theta)\n return Dot(np.array([px, py, 0]), color=RED, radius=0.1)\n \n dot = always_redraw(get_dot)\n \n trail = TracedPath(dot.get_center, stroke_color=YELLOW, stroke_width=3)\n \n self.add(wheel, trail, dot)\n \n # [BEAT 1 | sync: b1]\n with self.voiceover(text=\"Let's look at the cycloid from another perspective. The horizontal position depends on the rotation angle minus the sine of the angle.\") as t:\n self.wait_until_bookmark(\"b1\")\n self.play(Write(eq_x), run_time=2)\n self.play(theta_tracker.animate.set_value(2 * PI), run_time=3, rate_func=linear)\n self.wait(1)\n \n # [BEAT 2 | sync: b2]\n with self.voiceover(text=\" The vertical position oscillates with the cosine of the angle, creating the characteristic arches.\") as t:\n self.wait_until_bookmark(\"b2\")\n self.play(Write(eq_y), run_time=2)\n self.play(theta_tracker.animate.set_value(4 * PI), run_time=3, rate_func=linear)\n \n self.wait(1)\n```", "rejected": "```python\nfrom manim import *\nfrom manim_voiceover import VoiceoverScene\nfrom manim_voiceover.services.gtts import GTTSService\nimport numpy as np\n\nMARGIN = 0.5\n\nclass DynamicScene385(VoiceoverScene):\n def fit_in_frame(self, mob: Mobject, w_frac=0.9, h_frac=0.9) -> Mobject:\n max_w = config.frame_width * w_frac\n max_h = config.frame_height * h_frac\n if mob.width > max_w: mob.width = max_w\n if mob.height > max_h: mob.height = max_h\n return mob\n\n def construct(self):\n self.set_speech_service(GTTSService(transcription_model=\"base\"))\n \n # [SETUP]\n r = 1.0\n ground_y = -2\n theta_tracker = ValueTracker(0.0)\n \n # [LAYOUT]\n ground = Line(LEFT * 6 + DOWN * 2, RIGHT * 6 + DOWN * 2, color=GREY)\n self.add(self.fit_in_frame(ground))\n \n eq_x = TexMobject(r\"x = r(\\theta - \\sin\\theta)\", color=BLUE).to_corner(UR, buff=MARGIN)\n eq_y = MathTex(r\"y = r(1 - \\cos\\theta)\", color=RED).next_to(eq_x, DOWN, aligned_edge=LEFT)\n \n # [UPDATER]\n def get_wheel():\n theta = theta_tracker.get_value()\n center_x = -5 + r * theta\n center_y = ground_y + r\n return Circle(radius=r, color=WHITE, fill_opacity=0.1).move_to(np.array([center_x, center_y, 0]))\n \n wheel = always_redraw(get_wheel)\n \n def get_dot():\n theta = theta_tracker.get_value()\n center_x = -5 + r * theta\n center_y = ground_y + r\n px = center_x - r * np.sin(theta)\n py = center_y - r * np.cos(theta)\n return Dot(np.array([px, py, 0]), color=RED, radius=0.1)\n \n dot = always_redraw(get_dot)\n \n trail = TracedPath(dot.get_center, stroke_color=YELLOW, stroke_width=3)\n \n self.add(wheel, trail, dot)\n \n # [BEAT 1 | sync: b1]\n with self.voiceover(text=\"Let's look at the cycloid from another perspective. The horizontal position depends on the rotation angle minus the sine of the angle.\") as t:\n self.wait_until_bookmark(\"b1\")\n self.play(Write(eq_x), run_time=2)\n self.play(theta_tracker.animate.set_value(2 * PI), run_time=3, rate_func=linear)\n self.wait(1)\n \n # [BEAT 2 | sync: b2]\n with self.voiceover(text=\" The vertical position oscillates with the cosine of the angle, creating the characteristic arches.\") as t:\n self.wait_until_bookmark(\"b2\")\n self.play(Write(eq_y), run_time=2)\n self.play(theta_tracker.animate.set_value(4 * PI), run_time=3, rate_func=linear)\n \n self.wait(1)\n```", "category": "legacy_api_hallucination", "source": "synthetic_hard_neg:nabin2004/qwen3-8b-manimator-gold-sft"} +{"system": "You are an expert Manim Community Edition (ManimCE v0.19+) Python developer and mathematical animator. Given a user request, first plan the spatial layout, coordinate bounds, timing, and pedagogical flow inside ... tags (when reasoning is helpful), and then output a complete, runnable, self-contained ManimCE Python script using `from manim import *`. Never use deprecated ManimGL (`manimlib`) methods like `ShowCreation`, `TexMobject`, `TextMobject`, or `axes.get_graph`; always use modern ManimCE APIs (`Create`, `MathTex`, `Tex`, `Text`, `axes.plot`) and prevent visual overlap using `.to_edge()`, `.next_to()`, and `FadeOut`.", "prompt": "Construct a clean Manim CE scene initializing TangentLine with verified keyword arguments. Ensure no deprecated ManimGL arguments (like element_color, max_value, or max_magnitude) are used.\n\n```python\nfrom manim import *\nimport numpy as np\n\nclass ApiValidTangentLine381(Scene):\n def construct(self):\n obj = TangentLine(Circle(radius=1.5), alpha=0.25, length=3, color=YELLOW)\n obj.set_color(YELLOW)\n self.play(Create(obj))\n self.wait(1)\n```", "chosen": "```python\nfrom manim import *\nfrom manim_voiceover import VoiceoverScene\nfrom manim_voiceover.services.gtts import GTTSService\nimport numpy as np\n\nMARGIN = 0.5\n\nclass ApiValidTangentLineScene(VoiceoverScene):\n def fit_in_frame(self, mob: Mobject, w_frac=0.9, h_frac=0.9) -> Mobject:\n max_w = config.frame_width * w_frac\n max_h = config.frame_height * h_frac\n if mob.width > max_w:\n mob.width = max_w\n if mob.height > max_h:\n mob.height = max_h\n return mob\n\n def construct(self):\n self.set_speech_service(GTTSService(transcription_model=\"base\"))\n \n # [SETUP]\n title = Title(\"TangentLine Initialization\", buff=MARGIN)\n circle = Circle(radius=1.5, color=BLUE).shift(DOWN * 0.5)\n obj = TangentLine(circle, alpha=0.25, length=3, color=YELLOW)\n \n # [LAYOUT]\n main_group = self.fit_in_frame(VGroup(title, circle, obj))\n self.add(main_group)\n \n # [UPDATER]\n # None\n \n # [BEAT 1 | sync: b1]\n with self.voiceover(text=\"We initialize a TangentLine on a circle. \") as t_voice:\n self.wait_until_bookmark(\"b1\")\n self.play(Create(circle), run_time=1.5)\n \n # [BEAT 2 | sync: b2]\n with self.voiceover(text=\"The tangent line is drawn at the specified alpha parameter along the curve. \") as t_voice:\n self.wait_until_bookmark(\"b2\")\n self.play(Create(obj), run_time=1.5)\n self.wait(1)\n```", "rejected": "```python\nfrom manim import *\nfrom manim_voiceover import VoiceoverScene\nfrom manim_voiceover.services.gtts import GTTSService\nimport numpy as np\n\nMARGIN = 0.5\n\nclass ApiValidTangentLineScene(VoiceoverScene):\n def fit_in_frame(self, mob: Mobject, w_frac=0.9, h_frac=0.9) -> Mobject:\n max_w = config.frame_width * w_frac\n max_h = config.frame_height * h_frac\n if mob.width > max_w:\n mob.width = max_w\n if mob.height > max_h:\n mob.height = max_h\n return mob\n\n def construct(self):\n self.set_speech_service(GTTSService(transcription_model=\"base\"))\n \n # [SETUP]\n title = Title(\"TangentLine Initialization\", buff=MARGIN)\n circle = Circle(radius=1.5, color=BLUE).shift(DOWN * 0.5)\n obj = TangentLine(circle, alpha=0.25, length=3, color=YELLOW)\n \n # [LAYOUT]\n main_group = self.fit_in_frame(VGroup(title, circle, obj))\n self.add(main_group)\n \n # [UPDATER]\n # None\n \n # [BEAT 1 | sync: b1]\n with self.voiceover(text=\"We initialize a TangentLine on a circle. \") as t_voice:\n self.wait_until_bookmark(\"b1\")\n self.play(ShowCreation(circle), run_time=1.5)\n \n # [BEAT 2 | sync: b2]\n with self.voiceover(text=\"The tangent line is drawn at the specified alpha parameter along the curve. \") as t_voice:\n self.wait_until_bookmark(\"b2\")\n self.play(Create(obj), run_time=1.5)\n self.wait(1)\n```", "category": "legacy_api_hallucination", "source": "synthetic_hard_neg:nabin2004/qwen3-8b-manimator-gold-sft"} +{"system": "You are an expert Manim Community Edition (ManimCE v0.19+) Python developer and mathematical animator. Given a user request, first plan the spatial layout, coordinate bounds, timing, and pedagogical flow inside ... tags (when reasoning is helpful), and then output a complete, runnable, self-contained ManimCE Python script using `from manim import *`. Never use deprecated ManimGL (`manimlib`) methods like `ShowCreation`, `TexMobject`, `TextMobject`, or `axes.get_graph`; always use modern ManimCE APIs (`Create`, `MathTex`, `Tex`, `Text`, `axes.plot`) and prevent visual overlap using `.to_edge()`, `.next_to()`, and `FadeOut`.", "prompt": "I'm teaching an undergrad ML course and want a vivid visualization of Softplus and its variants. Show how the curve changes with parameters like beta and offset, compare with ReLU, and illustrate gradient flow during a simple backprop step on a tiny network.", "chosen": "```python\nfrom manim import *\nimport numpy as np\n\nclass ComparisonScene(Scene):\n\n def construct(self):\n title = Text('Softplus Variants and ReLU Comparison', font_size=36, color=BLUE)\n subtitle = Text('Activation Functions in Neural Networks', font_size=24, color=GRAY)\n subtitle.next_to(title, DOWN)\n self.play(Write(title), run_time=2.0 * 0.6)\n self.play(Write(subtitle), run_time=2.0 * 0.4)\n self.wait(0.5)\n self.play(FadeOut(title), FadeOut(subtitle))\n softplus_formula = MathTex('f(x) = \\\\ln(1 + e^x)', font_size=40, color=BLUE)\n softplus_label = Text('Softplus Function', font_size=28, color=BLUE)\n softplus_label.next_to(softplus_formula, UP, buff=0.5)\n self.play(Write(softplus_label), run_time=2.0 * 0.3)\n self.play(Write(softplus_formula), run_time=2.0 * 0.7)\n self.wait(0.5)\n self.play(FadeOut(softplus_label), FadeOut(softplus_formula))\n axes1 = Axes(x_range=[-5, 5, 1], y_range=[-0.5, 5, 1], x_length=8, y_length=5, axis_config={'include_tip': True})\n axes1_labels = axes1.get_axis_labels(x_label='x', y_label='f(x)')\n\n def softplus_func(x):\n return np.log(1 + np.exp(x))\n softplus_graph = axes1.plot(softplus_func, x_range=[-5, 5], color=BLUE, stroke_width=3)\n softplus_name = Text('Softplus', font_size=20, color=BLUE).next_to(axes1, UP)\n self.play(Create(axes1), Write(axes1_labels), run_time=2.0 * 0.4)\n self.play(Create(softplus_graph), Write(softplus_name), run_time=2.0 * 0.6)\n self.wait(0.5)\n self.play(FadeOut(axes1), FadeOut(axes1_labels), FadeOut(softplus_graph), FadeOut(softplus_name))\n relu_formula = MathTex('f(x) = \\\\max(0, x)', font_size=40, color=RED)\n relu_label = Text('ReLU Function', font_size=28, color=RED)\n relu_label.next_to(relu_formula, UP, buff=0.5)\n self.play(Write(relu_label), run_time=2.0 * 0.3)\n self.play(Write(relu_formula), run_time=2.0 * 0.7)\n self.wait(0.5)\n self.play(FadeOut(relu_label), FadeOut(relu_formula))\n axes2 = Axes(x_range=[-5, 5, 1], y_range=[-0.5, 5, 1], x_length=8, y_length=5, axis_config={'include_tip': True})\n axes2_labels = axes2.get_axis_labels(x_label='x', y_label='f(x)')\n\n def relu_func(x):\n return max(0, x)\n relu_graph = axes2.plot(relu_func, x_range=[-5, 5], color=RED, stroke_width=3)\n relu_name = Text('ReLU', font_size=20, color=RED).next_to(axes2, UP)\n self.play(Create(axes2), Write(axes2_labels), run_time=2.0 * 0.4)\n self.play(Create(relu_graph), Write(relu_name), run_time=2.0 * 0.6)\n self.wait(0.5)\n self.play(FadeOut(axes2), FadeOut(axes2_labels), FadeOut(relu_graph), FadeOut(relu_name))\n axes3 = Axes(x_range=[-5, 5, 1], y_range=[-0.5, 5, 1], x_length=10, y_length=6, axis_config={'include_tip': True})\n axes3_labels = axes3.get_axis_labels(x_label='x', y_label='f(x)')\n softplus_graph2 = axes3.plot(softplus_func, x_range=[-5, 5], color=BLUE, stroke_width=3)\n relu_graph2 = axes3.plot(relu_func, x_range=[-5, 5], color=RED, stroke_width=3)\n softplus_legend = MathTex('\\\\ln(1+e^x)', font_size=20, color=BLUE)\n relu_legend = MathTex('\\\\max(0,x)', font_size=20, color=RED)\n legend_group = VGroup(softplus_legend, relu_legend)\n legend_group.arrange(DOWN, aligned_edge=LEFT)\n legend_group.to_corner(UR, buff=0.5)\n corner_dot = Dot(axes3.c2p(0, 0), color=RED, radius=0.08)\n self.play(Create(axes3), Write(axes3_labels), run_time=2.0 * 0.3)\n self.play(Create(softplus_graph2), Create(relu_graph2), run_time=2.0 * 0.5)\n self.play(Write(legend_group), FadeIn(corner_dot), run_time=2.0 * 0.2)\n self.wait(0.5)\n self.play(FadeOut(axes3), FadeOut(axes3_labels), FadeOut(softplus_graph2), FadeOut(relu_graph2), FadeOut(legend_group), FadeOut(corner_dot))\n deriv_softplus = MathTex(\"f'(x) = \\\\frac{1}{1 + e^{-x}} = \\\\sigma(x)\", font_size=36, color=BLUE)\n deriv_label1 = Text('Softplus Derivative (Sigmoid)', font_size=24, color=BLUE)\n deriv_label1.next_to(deriv_softplus, UP, buff=0.5)\n self.play(Write(deriv_label1), run_time=2.0 * 0.3)\n self.play(Write(deriv_softplus), run_time=2.0 * 0.7)\n self.wait(0.3)\n self.play(FadeOut(deriv_label1), FadeOut(deriv_softplus))\n deriv_relu = MathTex(\"f'(x) = \\\\begin{cases} 0 & x < 0 \\\\\\\\ 1 & x > 0 \\\\\\\\ \\\\text{undefined} & x = 0 \\\\end{cases}\", font_size=36, color=RED)\n deriv_label2 = Text('ReLU Derivative', font_size=24, color=RED)\n deriv_label2.next_to(deriv_relu, UP, buff=0.5)\n self.play(Write(deriv_label2), run_time=2.0 * 0.3)\n self.play(Write(deriv_relu), run_time=2.0 * 0.7)\n self.wait(0.3)\n self.play(FadeOut(deriv_label2), FadeOut(deriv_relu))\n softplus_title = Text('Softplus', font_size=28, color=BLUE)\n sp_pros = VGroup(Text('✓ Smooth everywhere', font_size=20, color=GREEN), Text('✓ Differentiable everywhere', font_size=20, color=GREEN), Text('✓ No sharp corners', font_size=20, color=GREEN))\n sp_cons = VGroup(Text('✗ Computationally expensive', font_size=20, color=RED_D), Text('✗ Vanishing gradients (x << 0)', font_size=20, color=RED_D), Text('✗ Outputs never exactly zero', font_size=20, color=RED_D))\n sp_pros.arrange(DOWN, aligned_edge=LEFT, buff=0.2)\n sp_cons.arrange(DOWN, aligned_edge=LEFT, buff=0.2)\n sp_column = VGroup(softplus_title, sp_pros, sp_cons)\n sp_column.arrange(DOWN, buff=0.3)\n sp_pros.align_to(softplus_title, LEFT)\n sp_cons.align_to(softplus_title, LEFT)\n self.play(Write(softplus_title), run_time=2.0 * 0.2)\n self.play(Write(sp_pros), run_time=2.0 * 0.4)\n self.play(Write(sp_cons), run_time=2.0 * 0.4)\n self.wait(0.3)\n self.play(FadeOut(sp_column))\n relu_title = Text('ReLU', font_size=28, color=RED)\n relu_pros = VGroup(Text('✓ Computationally efficient', font_size=20, color=GREEN), Text('✓ Sparse activation', font_size=20, color=GREEN), Text('✓ No vanishing gradient (x > 0)', font_size=20, color=GREEN))\n relu_cons = VGroup(Text('✗ Dying ReLU problem', font_size=20, color=RED_D), Text('✗ Not differentiable at zero', font_size=20, color=RED_D), Text('✗ No negative outputs', font_size=20, color=RED_D))\n relu_pros.arrange(DOWN, aligned_edge=LEFT, buff=0.2)\n relu_cons.arrange(DOWN, aligned_edge=LEFT, buff=0.2)\n relu_column = VGroup(relu_title, relu_pros, relu_cons)\n relu_column.arrange(DOWN, buff=0.3)\n relu_pros.align_to(relu_title, LEFT)\n relu_cons.align_to(relu_title, LEFT)\n self.play(Write(relu_title), run_time=2.0 * 0.2)\n self.play(Write(relu_pros), run_time=2.0 * 0.4)\n self.play(Write(relu_cons), run_time=2.0 * 0.4)\n self.wait(0.3)\n self.play(FadeOut(relu_column))\n variants_title = Text('Popular Variants', font_size=32, color=PURPLE)\n variants = VGroup(MathTex('\\\\text{Leaky ReLU: } \\\\max(\\\\alpha x, x)', font_size=24), MathTex('\\\\text{ELU: } \\\\begin{cases} x & x \\\\geq 0 \\\\\\\\ \\\\alpha(e^x - 1) & x < 0 \\\\end{cases}', font_size=24), MathTex('\\\\text{Swish: } x \\\\cdot \\\\sigma(x)', font_size=24), MathTex('\\\\text{GELU: } x \\\\cdot \\\\Phi(x)', font_size=24))\n variants.arrange(DOWN, buff=0.4)\n variants_title.next_to(variants, UP, buff=0.5)\n self.play(Write(variants_title), run_time=2.0 * 0.2)\n for v in variants:\n self.play(Write(v), run_time=2.0 * 0.2)\n self.wait(0.5)\n self.play(FadeOut(variants_title), FadeOut(variants))\n summary_title = Text('Summary', font_size=36, color=YELLOW)\n outcomes = VGroup(Text('• Identify Softplus and ReLU functions', font_size=22), Text('• Describe Softplus variants effects', font_size=22), Text('• Determine which to use and when', font_size=22))\n outcomes.arrange(DOWN, buff=0.4, aligned_edge=LEFT)\n summary_box = SurroundingRectangle(outcomes, buff=0.5, color=YELLOW)\n summary_title.next_to(summary_box, UP, buff=0.3)\n self.play(Write(summary_title), Create(summary_box), run_time=2.0 * 0.3)\n self.play(Write(outcomes), run_time=2.0 * 0.7)\n self.wait(1)\n self.play(FadeOut(summary_title), FadeOut(summary_box), FadeOut(outcomes))\n self.wait(0.5)\n```", "rejected": "```python\nfrom manim import *\nimport numpy as np\n\nclass ComparisonScene(Scene):\n\n def construct(self):\n title = Text('Softplus Variants and ReLU Comparison', font_size=36, color=BLUE)\n subtitle = Text('Activation Functions in Neural Networks', font_size=24, color=GRAY)\n subtitle\n self.play(Write(title), run_time=2.0 * 0.6)\n self.play(Write(subtitle), run_time=2.0 * 0.4)\n self.wait(0.5)\n self.play(FadeOut(title), FadeOut(subtitle))\n softplus_formula = MathTex('f(x) = \\\\ln(1 + e^x)', font_size=40, color=BLUE)\n softplus_label = Text('Softplus Function', font_size=28, color=BLUE)\n softplus_label\n self.play(Write(softplus_label), run_time=2.0 * 0.3)\n self.play(Write(softplus_formula), run_time=2.0 * 0.7)\n self.wait(0.5)\n self.play(FadeOut(softplus_label), FadeOut(softplus_formula))\n axes1 = Axes(x_range=[-5, 5, 1], y_range=[-0.5, 5, 1], x_length=8, y_length=5, axis_config={'include_tip': True})\n axes1_labels = axes1.get_axis_labels(x_label='x', y_label='f(x)')\n\n def softplus_func(x):\n return np.log(1 + np.exp(x))\n softplus_graph = axes1.plot(softplus_func, x_range=[-5, 5], color=BLUE, stroke_width=3)\n softplus_name = Text('Softplus', font_size=20, color=BLUE)\n self.play(Create(axes1), Write(axes1_labels), run_time=2.0 * 0.4)\n self.play(Create(softplus_graph), Write(softplus_name), run_time=2.0 * 0.6)\n self.wait(0.5)\n self.play(FadeOut(axes1), FadeOut(axes1_labels), FadeOut(softplus_graph), FadeOut(softplus_name))\n relu_formula = MathTex('f(x) = \\\\max(0, x)', font_size=40, color=RED)\n relu_label = Text('ReLU Function', font_size=28, color=RED)\n relu_label.next_to(relu_formula, UP, buff=0.5)\n self.play(Write(relu_label), run_time=2.0 * 0.3)\n self.play(Write(relu_formula), run_time=2.0 * 0.7)\n self.wait(0.5)\n self.play(FadeOut(relu_label), FadeOut(relu_formula))\n axes2 = Axes(x_range=[-5, 5, 1], y_range=[-0.5, 5, 1], x_length=8, y_length=5, axis_config={'include_tip': True})\n axes2_labels = axes2.get_axis_labels(x_label='x', y_label='f(x)')\n\n def relu_func(x):\n return max(0, x)\n relu_graph = axes2.plot(relu_func, x_range=[-5, 5], color=RED, stroke_width=3)\n relu_name = Text('ReLU', font_size=20, color=RED).next_to(axes2, UP)\n self.play(Create(axes2), Write(axes2_labels), run_time=2.0 * 0.4)\n self.play(Create(relu_graph), Write(relu_name), run_time=2.0 * 0.6)\n self.wait(0.5)\n self.play(FadeOut(axes2), FadeOut(axes2_labels), FadeOut(relu_graph), FadeOut(relu_name))\n axes3 = Axes(x_range=[-5, 5, 1], y_range=[-0.5, 5, 1], x_length=10, y_length=6, axis_config={'include_tip': True})\n axes3_labels = axes3.get_axis_labels(x_label='x', y_label='f(x)')\n softplus_graph2 = axes3.plot(softplus_func, x_range=[-5, 5], color=BLUE, stroke_width=3)\n relu_graph2 = axes3.plot(relu_func, x_range=[-5, 5], color=RED, stroke_width=3)\n softplus_legend = MathTex('\\\\ln(1+e^x)', font_size=20, color=BLUE)\n relu_legend = MathTex('\\\\max(0,x)', font_size=20, color=RED)\n legend_group = VGroup(softplus_legend, relu_legend)\n legend_group.arrange(DOWN, aligned_edge=LEFT)\n legend_group.to_corner(UR, buff=0.5)\n corner_dot = Dot(axes3.c2p(0, 0), color=RED, radius=0.08)\n self.play(Create(axes3), Write(axes3_labels), run_time=2.0 * 0.3)\n self.play(Create(softplus_graph2), Create(relu_graph2), run_time=2.0 * 0.5)\n self.play(Write(legend_group), FadeIn(corner_dot), run_time=2.0 * 0.2)\n self.wait(0.5)\n self.play(FadeOut(axes3), FadeOut(axes3_labels), FadeOut(softplus_graph2), FadeOut(relu_graph2), FadeOut(legend_group), FadeOut(corner_dot))\n deriv_softplus = MathTex(\"f'(x) = \\\\frac{1}{1 + e^{-x}} = \\\\sigma(x)\", font_size=36, color=BLUE)\n deriv_label1 = Text('Softplus Derivative (Sigmoid)', font_size=24, color=BLUE)\n deriv_label1.next_to(deriv_softplus, UP, buff=0.5)\n self.play(Write(deriv_label1), run_time=2.0 * 0.3)\n self.play(Write(deriv_softplus), run_time=2.0 * 0.7)\n self.wait(0.3)\n self.play(FadeOut(deriv_label1), FadeOut(deriv_softplus))\n deriv_relu = MathTex(\"f'(x) = \\\\begin{cases} 0 & x < 0 \\\\\\\\ 1 & x > 0 \\\\\\\\ \\\\text{undefined} & x = 0 \\\\end{cases}\", font_size=36, color=RED)\n deriv_label2 = Text('ReLU Derivative', font_size=24, color=RED)\n deriv_label2.next_to(deriv_relu, UP, buff=0.5)\n self.play(Write(deriv_label2), run_time=2.0 * 0.3)\n self.play(Write(deriv_relu), run_time=2.0 * 0.7)\n self.wait(0.3)\n self.play(FadeOut(deriv_label2), FadeOut(deriv_relu))\n softplus_title = Text('Softplus', font_size=28, color=BLUE)\n sp_pros = VGroup(Text('✓ Smooth everywhere', font_size=20, color=GREEN), Text('✓ Differentiable everywhere', font_size=20, color=GREEN), Text('✓ No sharp corners', font_size=20, color=GREEN))\n sp_cons = VGroup(Text('✗ Computationally expensive', font_size=20, color=RED_D), Text('✗ Vanishing gradients (x << 0)', font_size=20, color=RED_D), Text('✗ Outputs never exactly zero', font_size=20, color=RED_D))\n sp_pros.arrange(DOWN, aligned_edge=LEFT, buff=0.2)\n sp_cons.arrange(DOWN, aligned_edge=LEFT, buff=0.2)\n sp_column = VGroup(softplus_title, sp_pros, sp_cons)\n sp_column.arrange(DOWN, buff=0.3)\n sp_pros.align_to(softplus_title, LEFT)\n sp_cons.align_to(softplus_title, LEFT)\n self.play(Write(softplus_title), run_time=2.0 * 0.2)\n self.play(Write(sp_pros), run_time=2.0 * 0.4)\n self.play(Write(sp_cons), run_time=2.0 * 0.4)\n self.wait(0.3)\n self.play(FadeOut(sp_column))\n relu_title = Text('ReLU', font_size=28, color=RED)\n relu_pros = VGroup(Text('✓ Computationally efficient', font_size=20, color=GREEN), Text('✓ Sparse activation', font_size=20, color=GREEN), Text('✓ No vanishing gradient (x > 0)', font_size=20, color=GREEN))\n relu_cons = VGroup(Text('✗ Dying ReLU problem', font_size=20, color=RED_D), Text('✗ Not differentiable at zero', font_size=20, color=RED_D), Text('✗ No negative outputs', font_size=20, color=RED_D))\n relu_pros.arrange(DOWN, aligned_edge=LEFT, buff=0.2)\n relu_cons.arrange(DOWN, aligned_edge=LEFT, buff=0.2)\n relu_column = VGroup(relu_title, relu_pros, relu_cons)\n relu_column.arrange(DOWN, buff=0.3)\n relu_pros.align_to(relu_title, LEFT)\n relu_cons.align_to(relu_title, LEFT)\n self.play(Write(relu_title), run_time=2.0 * 0.2)\n self.play(Write(relu_pros), run_time=2.0 * 0.4)\n self.play(Write(relu_cons), run_time=2.0 * 0.4)\n self.wait(0.3)\n self.play(FadeOut(relu_column))\n variants_title = Text('Popular Variants', font_size=32, color=PURPLE)\n variants = VGroup(MathTex('\\\\text{Leaky ReLU: } \\\\max(\\\\alpha x, x)', font_size=24), MathTex('\\\\text{ELU: } \\\\begin{cases} x & x \\\\geq 0 \\\\\\\\ \\\\alpha(e^x - 1) & x < 0 \\\\end{cases}', font_size=24), MathTex('\\\\text{Swish: } x \\\\cdot \\\\sigma(x)', font_size=24), MathTex('\\\\text{GELU: } x \\\\cdot \\\\Phi(x)', font_size=24))\n variants.arrange(DOWN, buff=0.4)\n variants_title.next_to(variants, UP, buff=0.5)\n self.play(Write(variants_title), run_time=2.0 * 0.2)\n for v in variants:\n self.play(Write(v), run_time=2.0 * 0.2)\n self.wait(0.5)\n self.play(FadeOut(variants_title), FadeOut(variants))\n summary_title = Text('Summary', font_size=36, color=YELLOW)\n outcomes = VGroup(Text('• Identify Softplus and ReLU functions', font_size=22), Text('• Describe Softplus variants effects', font_size=22), Text('• Determine which to use and when', font_size=22))\n outcomes.arrange(DOWN, buff=0.4, aligned_edge=LEFT)\n summary_box = SurroundingRectangle(outcomes, buff=0.5, color=YELLOW)\n summary_title.next_to(summary_box, UP, buff=0.3)\n self.play(Write(summary_title), Create(summary_box), run_time=2.0 * 0.3)\n self.play(Write(outcomes), run_time=2.0 * 0.7)\n self.wait(1)\n self.play(FadeOut(summary_title), FadeOut(summary_box), FadeOut(outcomes))\n self.wait(0.5)\n```", "category": "spatial_layout_overlap", "source": "synthetic_hard_neg:nabin2004/AOS-Manim-SFT"} +{"system": "You are an expert Manim Community Edition (ManimCE v0.19+) Python developer and mathematical animator. Given a user request, first plan the spatial layout, coordinate bounds, timing, and pedagogical flow inside ... tags (when reasoning is helpful), and then output a complete, runnable, self-contained ManimCE Python script using `from manim import *`. Never use deprecated ManimGL (`manimlib`) methods like `ShowCreation`, `TexMobject`, `TextMobject`, or `axes.get_graph`; always use modern ManimCE APIs (`Create`, `MathTex`, `Tex`, `Text`, `axes.plot`) and prevent visual overlap using `.to_edge()`, `.next_to()`, and `FadeOut`.", "prompt": "I'm studying sequence models and need to see padding strategy for causal convolutions. Visualize left padding to maintain sequence length, showing input sequences, padded zeros, and the resulting feature map. Include a timeline of how padding decisions affect prediction alignment, with a bonus: compare with no padding.", "chosen": "```python\nfrom manim import *\nfrom manim_voiceover import VoiceoverScene\nfrom manim_voiceover.services.gtts import GTTSService\n\nclass CausalPaddingStrategies(VoiceoverScene):\n def construct(self):\n self.set_speech_service(\n GTTSService(voice=\"alba\", cache_dir=\"voiceover_cache\")\n )\n\n # ===== Title =====\n title = Text(\"Padding Strategies for Causal Convolutions\", font_size=34)\n subtitle = Text(\"Preserving Temporal Structure\", font_size=24, color=BLUE)\n title_group = VGroup(title, subtitle).arrange(DOWN, buff=0.3).move_to(ORIGIN)\n\n with self.voiceover(text=\"Have you ever wondered how we can apply convolution operations to time series data without losing the temporal structure and integrity of the sequences? Let's unlock the secrets of causal convolutions and explore the vital role of padding strategies in preserving this essential order!\") as tracker:\n self.play(Write(title), run_time=tracker.duration * 0.5)\n self.play(Write(subtitle), run_time=tracker.duration * 0.5)\n\n self.wait(0.3)\n\n with self.voiceover(text=\"First, let's understand what makes a convolution causal.\") as tracker:\n self.play(FadeOut(title_group), run_time=tracker.duration)\n\n # ===== Input sequence =====\n in_positions = [LEFT * 1.6 + RIGHT * i * 0.8 for i in range(5)]\n input_boxes = VGroup(*[Square(side_length=0.6).move_to(p) for p in in_positions])\n input_labels = VGroup(*[MathTex(f\"x_{{{i+1}}}\", font_size=22).move_to(p) for i, p in enumerate(in_positions)])\n\n with self.voiceover(text=\"Here is an input sequence with five elements.\") as tracker:\n self.play(Create(input_boxes), Write(input_labels), run_time=tracker.duration)\n\n # ===== Kernel =====\n k_positions = [LEFT * 0.8 + RIGHT * i * 0.8 for i in range(3)]\n kernel_boxes = VGroup(*[Square(side_length=0.6, color=YELLOW, fill_opacity=0.3).move_to(p) for p in k_positions])\n kernel_labels = VGroup(*[MathTex(f\"w_{{{i+1}}}\", font_size=22, color=YELLOW).move_to(p) for i, p in enumerate(k_positions)])\n kernel_group = VGroup(kernel_boxes, kernel_labels)\n kernel_group.shift(DOWN * 1.2)\n\n with self.voiceover(text=\"A convolutional kernel of size three slides over the sequence to produce outputs.\") as tracker:\n self.play(Create(kernel_boxes), Write(kernel_labels), run_time=tracker.duration)\n\n # ===== Causal property =====\n with self.voiceover(text=\"In a causal convolution, the output at time t must never depend on future inputs. The kernel can only use the present and the past.\") as tracker:\n self.play(\n input_boxes[2].animate.set_fill(RED, opacity=0.3),\n input_boxes[3].animate.set_fill(RED, opacity=0.3),\n input_boxes[4].animate.set_fill(RED, opacity=0.3),\n run_time=tracker.duration * 0.5\n )\n brace = Brace(input_boxes[2:5], DOWN, color=RED)\n brace_text = Text(\"Future (forbidden)\", font_size=18, color=RED).next_to(brace, DOWN, buff=0.1)\n self.play(GrowFromCenter(brace), Write(brace_text), run_time=tracker.duration * 0.5)\n\n self.wait(0.3)\n self.play(\n FadeOut(brace), FadeOut(brace_text),\n input_boxes[2].animate.set_fill(opacity=0),\n input_boxes[3].animate.set_fill(opacity=0),\n input_boxes[4].animate.set_fill(opacity=0)\n )\n\n # ===== Valid (No) Padding =====\n valid_text = Text(\"Valid Padding (No Padding)\", font_size=26).to_edge(UP)\n with self.voiceover(text=\"Let's first examine valid padding, which means no padding at all.\") as tracker:\n self.play(Write(valid_text), run_time=tracker.duration)\n\n outputs_valid = VGroup()\n for step in range(3):\n if step == 0:\n target_x = input_boxes[0].get_center()[0]\n current_x = kernel_boxes[0].get_center()[0]\n with self.voiceover(text=\"The kernel starts where it first fits completely.\") as tracker:\n self.play(kernel_group.animate.shift(RIGHT * (target_x - current_x)), run_time=tracker.duration)\n else:\n with self.voiceover(text=\"Slide right.\") as tracker:\n self.play(kernel_group.animate.shift(RIGHT * 0.8), run_time=tracker.duration)\n\n out_x = input_boxes[step + 2].get_center()[0]\n out_y = -2.5\n out_box = Square(side_length=0.6, color=GREEN, fill_opacity=0.2).move_to([out_x, out_y, 0])\n out_label = MathTex(f\"y_{{{step+1}}}\", font_size=22, color=GREEN).move_to([out_x, out_y, 0])\n self.play(Create(out_box), Write(out_label), run_time=0.35)\n outputs_valid.add(VGroup(out_box, out_label))\n\n shift_arrow = Arrow(outputs_valid[0][0].get_top(), input_boxes[2].get_bottom(), color=GRAY, buff=0.1)\n shift_text = Text(\"Aligned with x3\", font_size=18, color=GRAY).next_to(shift_arrow, RIGHT)\n\n with self.voiceover(text=\"The output shrinks to length three, and worse, y1 aligns with input x3, causing a temporal shift.\") as tracker:\n self.play(Create(shift_arrow), Write(shift_text), run_time=tracker.duration)\n\n self.wait(0.3)\n self.play(FadeOut(shift_arrow), FadeOut(shift_text), FadeOut(outputs_valid), FadeOut(valid_text))\n\n # ===== Causal Padding =====\n causal_text = Text(\"Causal Padding\", font_size=26, color=BLUE).to_edge(UP)\n with self.voiceover(text=\"To fix this, we use causal padding by adding zeros only to the left.\") as tracker:\n self.play(Write(causal_text), run_time=tracker.duration)\n\n pad_positions = [LEFT * 1.6 - RIGHT * 0.8 * (i + 1) for i in range(2)]\n pad_boxes = VGroup(*[Square(side_length=0.6, color=GRAY, fill_opacity=0.2).move_to(p) for p in pad_positions])\n pad_labels = VGroup(*[MathTex(\"0\", font_size=22, color=GRAY).move_to(p) for p in pad_positions])\n\n with self.voiceover(text=\"For a kernel of size three, we pad with exactly two zeros on the left.\") as tracker:\n self.play(FadeIn(pad_boxes), Write(pad_labels), run_time=tracker.duration)\n\n first_pad_x = pad_positions[0][0]\n current_kernel_x = kernel_boxes[0].get_center()[0]\n with self.voiceover(text=\"The kernel now starts before the first real input, using the padded zeros.\") as tracker:\n self.play(kernel_group.animate.shift(RIGHT * (first_pad_x - current_kernel_x)), run_time=tracker.duration)\n\n outputs_causal = VGroup()\n for step in range(5):\n if step > 0:\n with self.voiceover(text=f\"Slide to compute output {step+1}.\") as tracker:\n self.play(kernel_group.animate.shift(RIGHT * 0.8), run_time=tracker.duration)\n\n out_x = input_boxes[step].get_center()[0]\n out_y = -2.5\n out_box = Square(side_length=0.6, color=GREEN, fill_opacity=0.2).move_to([out_x, out_y, 0])\n out_label = MathTex(f\"y_{{{step+1}}}\", font_size=22, color=GREEN).move_to([out_x, out_y, 0])\n self.play(Create(out_box), Write(out_label), run_time=0.35)\n outputs_causal.add(VGroup(out_box, out_label))\n\n align_arrows = VGroup()\n for i in range(5):\n a = Arrow(input_boxes[i].get_bottom(), outputs_causal[i][0].get_top(), color=BLUE, buff=0.1, stroke_width=1.5)\n align_arrows.add(a)\n\n with self.voiceover(text=\"Now the output has the same length as the input, and each y_t aligns vertically with x_t. The temporal structure is perfectly preserved.\") as tracker:\n self.play(Create(align_arrows), run_time=tracker.duration)\n\n self.wait(0.3)\n self.play(FadeOut(align_arrows))\n\n # ===== Summary =====\n self.play(FadeOut(input_boxes), FadeOut(input_labels), FadeOut(pad_boxes), FadeOut(pad_labels), FadeOut(kernel_group), FadeOut(outputs_causal), FadeOut(causal_text))\n\n summary_title = Text(\"Key Takeaways\", font_size=32)\n summary_title.to_edge(UP)\n self.play(Write(summary_title))\n\n items = VGroup(\n Text(\"• Causal convolutions prevent future information leakage.\", font_size=22),\n Text(\"• Valid padding shrinks sequences and causes time shifts.\", font_size=22),\n Text(\"• Causal padding adds zeros only to the left.\", font_size=22),\n Text(\"• Output length matches input length.\", font_size=22),\n ).arrange(DOWN, aligned_edge=LEFT, buff=0.35).next_to(summary_title, DOWN, buff=0.4)\n\n with self.voiceover(text=\"To summarize: causal convolutions prevent any leakage from future time steps. Valid padding shrinks the sequence and causes misalignment. Causal padding adds zeros only on the left, so the output length equals the input length while temporal causality is preserved.\") as tracker:\n self.play(Write(items), run_time=tracker.duration)\n\n self.wait(0.5)\n self.play(FadeOut(summary_title), FadeOut(items))\n```", "rejected": "```python\nfrom manim import *\nfrom manim_voiceover import VoiceoverScene\nfrom manim_voiceover.services.gtts import GTTSService\n\nclass CausalPaddingStrategies(VoiceoverScene):\n def construct(self):\n self.set_speech_service(\n GTTSService(voice=\"alba\", cache_dir=\"voiceover_cache\")\n )\n\n # ===== Title =====\n title = Text(\"Padding Strategies for Causal Convolutions\", font_size=34)\n subtitle = Text(\"Preserving Temporal Structure\", font_size=24, color=BLUE)\n title_group = VGroup(title, subtitle).arrange(DOWN, buff=0.3).move_to(ORIGIN)\n\n with self.voiceover(text=\"Have you ever wondered how we can apply convolution operations to time series data without losing the temporal structure and integrity of the sequences? Let's unlock the secrets of causal convolutions and explore the vital role of padding strategies in preserving this essential order!\") as tracker:\n self.play(Write(title), run_time=tracker.duration * 0.5)\n self.play(Write(subtitle), run_time=tracker.duration * 0.5)\n\n self.wait(0.3)\n\n with self.voiceover(text=\"First, let's understand what makes a convolution causal.\") as tracker:\n self.play(FadeOut(title_group), run_time=tracker.duration)\n\n # ===== Input sequence =====\n in_positions = [LEFT * 1.6 + RIGHT * i * 0.8 for i in range(5)]\n input_boxes = VGroup(*[Square(side_length=0.6).move_to(p) for p in in_positions])\n input_labels = VGroup(*[MathTex(f\"x_{{{i+1}}}\", font_size=22).move_to(p) for i, p in enumerate(in_positions)])\n\n with self.voiceover(text=\"Here is an input sequence with five elements.\") as tracker:\n self.play(Create(input_boxes), Write(input_labels), run_time=tracker.duration)\n\n # ===== Kernel =====\n k_positions = [LEFT * 0.8 + RIGHT * i * 0.8 for i in range(3)]\n kernel_boxes = VGroup(*[Square(side_length=0.6, color=YELLOW, fill_opacity=0.3).move_to(p) for p in k_positions])\n kernel_labels = VGroup(*[MathTex(f\"w_{{{i+1}}}\", font_size=22, color=YELLOW).move_to(p) for i, p in enumerate(k_positions)])\n kernel_group = VGroup(kernel_boxes, kernel_labels)\n kernel_group\n\n with self.voiceover(text=\"A convolutional kernel of size three slides over the sequence to produce outputs.\") as tracker:\n self.play(Create(kernel_boxes), Write(kernel_labels), run_time=tracker.duration)\n\n # ===== Causal property =====\n with self.voiceover(text=\"In a causal convolution, the output at time t must never depend on future inputs. The kernel can only use the present and the past.\") as tracker:\n self.play(\n input_boxes[2].animate.set_fill(RED, opacity=0.3),\n input_boxes[3].animate.set_fill(RED, opacity=0.3),\n input_boxes[4].animate.set_fill(RED, opacity=0.3),\n run_time=tracker.duration * 0.5\n )\n brace = Brace(input_boxes[2:5], DOWN, color=RED)\n brace_text = Text(\"Future (forbidden)\", font_size=18, color=RED)\n self.play(GrowFromCenter(brace), Write(brace_text), run_time=tracker.duration * 0.5)\n\n self.wait(0.3)\n self.play(\n FadeOut(brace), FadeOut(brace_text),\n input_boxes[2].animate.set_fill(opacity=0),\n input_boxes[3].animate.set_fill(opacity=0),\n input_boxes[4].animate.set_fill(opacity=0)\n )\n\n # ===== Valid (No) Padding =====\n valid_text = Text(\"Valid Padding (No Padding)\", font_size=26)\n with self.voiceover(text=\"Let's first examine valid padding, which means no padding at all.\") as tracker:\n self.play(Write(valid_text), run_time=tracker.duration)\n\n outputs_valid = VGroup()\n for step in range(3):\n if step == 0:\n target_x = input_boxes[0].get_center()[0]\n current_x = kernel_boxes[0].get_center()[0]\n with self.voiceover(text=\"The kernel starts where it first fits completely.\") as tracker:\n self.play(kernel_group.animate.shift(RIGHT * (target_x - current_x)), run_time=tracker.duration)\n else:\n with self.voiceover(text=\"Slide right.\") as tracker:\n self.play(kernel_group.animate.shift(RIGHT * 0.8), run_time=tracker.duration)\n\n out_x = input_boxes[step + 2].get_center()[0]\n out_y = -2.5\n out_box = Square(side_length=0.6, color=GREEN, fill_opacity=0.2).move_to([out_x, out_y, 0])\n out_label = MathTex(f\"y_{{{step+1}}}\", font_size=22, color=GREEN).move_to([out_x, out_y, 0])\n self.play(Create(out_box), Write(out_label), run_time=0.35)\n outputs_valid.add(VGroup(out_box, out_label))\n\n shift_arrow = Arrow(outputs_valid[0][0].get_top(), input_boxes[2].get_bottom(), color=GRAY, buff=0.1)\n shift_text = Text(\"Aligned with x3\", font_size=18, color=GRAY).next_to(shift_arrow, RIGHT)\n\n with self.voiceover(text=\"The output shrinks to length three, and worse, y1 aligns with input x3, causing a temporal shift.\") as tracker:\n self.play(Create(shift_arrow), Write(shift_text), run_time=tracker.duration)\n\n self.wait(0.3)\n self.play(FadeOut(shift_arrow), FadeOut(shift_text), FadeOut(outputs_valid), FadeOut(valid_text))\n\n # ===== Causal Padding =====\n causal_text = Text(\"Causal Padding\", font_size=26, color=BLUE).to_edge(UP)\n with self.voiceover(text=\"To fix this, we use causal padding by adding zeros only to the left.\") as tracker:\n self.play(Write(causal_text), run_time=tracker.duration)\n\n pad_positions = [LEFT * 1.6 - RIGHT * 0.8 * (i + 1) for i in range(2)]\n pad_boxes = VGroup(*[Square(side_length=0.6, color=GRAY, fill_opacity=0.2).move_to(p) for p in pad_positions])\n pad_labels = VGroup(*[MathTex(\"0\", font_size=22, color=GRAY).move_to(p) for p in pad_positions])\n\n with self.voiceover(text=\"For a kernel of size three, we pad with exactly two zeros on the left.\") as tracker:\n self.play(FadeIn(pad_boxes), Write(pad_labels), run_time=tracker.duration)\n\n first_pad_x = pad_positions[0][0]\n current_kernel_x = kernel_boxes[0].get_center()[0]\n with self.voiceover(text=\"The kernel now starts before the first real input, using the padded zeros.\") as tracker:\n self.play(kernel_group.animate.shift(RIGHT * (first_pad_x - current_kernel_x)), run_time=tracker.duration)\n\n outputs_causal = VGroup()\n for step in range(5):\n if step > 0:\n with self.voiceover(text=f\"Slide to compute output {step+1}.\") as tracker:\n self.play(kernel_group.animate.shift(RIGHT * 0.8), run_time=tracker.duration)\n\n out_x = input_boxes[step].get_center()[0]\n out_y = -2.5\n out_box = Square(side_length=0.6, color=GREEN, fill_opacity=0.2).move_to([out_x, out_y, 0])\n out_label = MathTex(f\"y_{{{step+1}}}\", font_size=22, color=GREEN).move_to([out_x, out_y, 0])\n self.play(Create(out_box), Write(out_label), run_time=0.35)\n outputs_causal.add(VGroup(out_box, out_label))\n\n align_arrows = VGroup()\n for i in range(5):\n a = Arrow(input_boxes[i].get_bottom(), outputs_causal[i][0].get_top(), color=BLUE, buff=0.1, stroke_width=1.5)\n align_arrows.add(a)\n\n with self.voiceover(text=\"Now the output has the same length as the input, and each y_t aligns vertically with x_t. The temporal structure is perfectly preserved.\") as tracker:\n self.play(Create(align_arrows), run_time=tracker.duration)\n\n self.wait(0.3)\n self.play(FadeOut(align_arrows))\n\n # ===== Summary =====\n self.play(FadeOut(input_boxes), FadeOut(input_labels), FadeOut(pad_boxes), FadeOut(pad_labels), FadeOut(kernel_group), FadeOut(outputs_causal), FadeOut(causal_text))\n\n summary_title = Text(\"Key Takeaways\", font_size=32)\n summary_title.to_edge(UP)\n self.play(Write(summary_title))\n\n items = VGroup(\n Text(\"• Causal convolutions prevent future information leakage.\", font_size=22),\n Text(\"• Valid padding shrinks sequences and causes time shifts.\", font_size=22),\n Text(\"• Causal padding adds zeros only to the left.\", font_size=22),\n Text(\"• Output length matches input length.\", font_size=22),\n ).arrange(DOWN, aligned_edge=LEFT, buff=0.35).next_to(summary_title, DOWN, buff=0.4)\n\n with self.voiceover(text=\"To summarize: causal convolutions prevent any leakage from future time steps. Valid padding shrinks the sequence and causes misalignment. Causal padding adds zeros only on the left, so the output length equals the input length while temporal causality is preserved.\") as tracker:\n self.play(Write(items), run_time=tracker.duration)\n\n self.wait(0.5)\n self.play(FadeOut(summary_title), FadeOut(items))\n```", "category": "spatial_layout_overlap", "source": "synthetic_hard_neg:nabin2004/AOS-Narrated-Manim-400"} +{"system": "You are an expert Manim Community Edition (ManimCE v0.19+) Python developer and mathematical animator. Given a user request, first plan the spatial layout, coordinate bounds, timing, and pedagogical flow inside ... tags (when reasoning is helpful), and then output a complete, runnable, self-contained ManimCE Python script using `from manim import *`. Never use deprecated ManimGL (`manimlib`) methods like `ShowCreation`, `TexMobject`, `TextMobject`, or `axes.get_graph`; always use modern ManimCE APIs (`Create`, `MathTex`, `Tex`, `Text`, `axes.plot`) and prevent visual overlap using `.to_edge()`, `.next_to()`, and `FadeOut`.", "prompt": "Create an educational ManimCE animation on 'Hensel's Lemma' (From Mod 3 to Mod 9: Lifting Roots with Hensel's Lemma): How can Hensel's Lemma be used to lift the roots of the polynomial x^2 - 2x + 1 from mod 3 to mod 9, and what does the visualization tell us about continuity in modular arithmetic?\nVisual style guidance: Vibrant and immersive style with soft pastel colors, transitioning between visual elements fluently, akin to illustration on a projective plane. The focus is on the elegance and continuity of transformations, using spiral patterns and number ecosystems to convey mathematical essence.", "chosen": "```python\nfrom manim import *\n\nclass HenselsLemmaScene(Scene):\n def construct(self):\n # Title\n title = Text(\"From Mod 3 to Mod 9: Lifting Roots with Hensel's Lemma\", font_size=36)\n self.play(Write(title))\n self.wait(1)\n self.play(title.animate.scale(0.7).to_edge(UP))\n \n # Introduce the polynomial\n poly_eq = MathTex(\"x^2 - 2x + 1 \\\\equiv 0 \\\\pmod{3}\")\n self.play(Write(poly_eq))\n self.wait(1)\n \n # Factor the polynomial\n factored_eq = MathTex(\"(x-1)^2 \\\\equiv 0 \\\\pmod{3}\")\n self.play(Transform(poly_eq, factored_eq))\n self.wait(1)\n \n # Show the root\n root_text = Text(\"Root: x = 1\", font_size=30)\n self.play(\n poly_eq.animate.shift(UP),\n Write(root_text.shift(DOWN))\n )\n self.wait(1)\n \n # Clear for next section\n self.play(FadeOut(poly_eq), FadeOut(root_text))\n \n # Visualize mod 3 and mod 9\n mod3_circle = Circle(radius=1.5, color=BLUE)\n mod3_circle.shift(LEFT*3)\n mod3_label = Text(\"mod 3\").next_to(mod3_circle, DOWN)\n \n mod9_circle = Circle(radius=1.5, color=RED)\n mod9_circle.shift(RIGHT*3)\n mod9_label = Text(\"mod 9\").next_to(mod9_circle, DOWN)\n \n self.play(\n Create(mod3_circle), Write(mod3_label),\n Create(mod9_circle), Write(mod9_label)\n )\n \n # Show derivative\n derivative = MathTex(\"f'(x) = 2x - 2\").to_edge(UP, buff=1.5)\n self.play(Write(derivative))\n self.wait(1)\n \n # Root in mod 3\n mod3_root = Dot(mod3_circle.get_center(), color=YELLOW)\n mod3_root_label = Text(\"x=1\", font_size=24).next_to(mod3_root, UP)\n \n self.play(FadeIn(mod3_root), Write(mod3_root_label))\n \n # Lifting arrow\n lift_arrow = Arrow(mod3_circle.get_right(), mod9_circle.get_left(), buff=0.1)\n lift_text = Text(\"Hensel's Lemma\", font_size=20).next_to(lift_arrow, UP)\n \n self.play(Create(lift_arrow), Write(lift_text))\n \n # Root in mod 9\n mod9_root = Dot(mod9_circle.get_center(), color=YELLOW)\n mod9_root_label = Text(\"x=1\", font_size=24).next_to(mod9_root, UP)\n \n self.play(FadeIn(mod9_root), Write(mod9_root_label))\n self.wait(1)\n \n # Conclusion\n conclusion = Text(\"Hensel's Lemma reveals continuity in modular arithmetic\", font_size=30)\n conclusion.scale(0.8) # Scale down to ensure it fits on screen\n \n self.play(\n FadeOut(mod3_circle), FadeOut(mod9_circle),\n FadeOut(mod3_label), FadeOut(mod9_label),\n FadeOut(mod3_root), FadeOut(mod9_root),\n FadeOut(mod3_root_label), FadeOut(mod9_root_label),\n FadeOut(lift_arrow), FadeOut(lift_text),\n FadeOut(derivative),\n FadeOut(title),\n Write(conclusion)\n )\n self.wait(2)\n```", "rejected": "```python\nfrom manim import *\n\nclass HenselsLemmaScene(Scene):\n def construct(self):\n # Title\n title = Text(\"From Mod 3 to Mod 9: Lifting Roots with Hensel's Lemma\", font_size=36)\n self.play(Write(title))\n self.wait(1)\n self.play(title.animate.scale(0.7))\n \n # Introduce the polynomial\n poly_eq = MathTex(\"x^2 - 2x + 1 \\\\equiv 0 \\\\pmod{3}\")\n self.play(Write(poly_eq))\n self.wait(1)\n \n # Factor the polynomial\n factored_eq = MathTex(\"(x-1)^2 \\\\equiv 0 \\\\pmod{3}\")\n self.play(Transform(poly_eq, factored_eq))\n self.wait(1)\n \n # Show the root\n root_text = Text(\"Root: x = 1\", font_size=30)\n self.play(\n poly_eq.animate,\n Write(root_text)\n )\n self.wait(1)\n \n # Clear for next section\n self.play(FadeOut(poly_eq), FadeOut(root_text))\n \n # Visualize mod 3 and mod 9\n mod3_circle = Circle(radius=1.5, color=BLUE)\n mod3_circle.shift(LEFT*3)\n mod3_label = Text(\"mod 3\").next_to(mod3_circle, DOWN)\n \n mod9_circle = Circle(radius=1.5, color=RED)\n mod9_circle.shift(RIGHT*3)\n mod9_label = Text(\"mod 9\").next_to(mod9_circle, DOWN)\n \n self.play(\n Create(mod3_circle), Write(mod3_label),\n Create(mod9_circle), Write(mod9_label)\n )\n \n # Show derivative\n derivative = MathTex(\"f'(x) = 2x - 2\").to_edge(UP, buff=1.5)\n self.play(Write(derivative))\n self.wait(1)\n \n # Root in mod 3\n mod3_root = Dot(mod3_circle.get_center(), color=YELLOW)\n mod3_root_label = Text(\"x=1\", font_size=24).next_to(mod3_root, UP)\n \n self.play(FadeIn(mod3_root), Write(mod3_root_label))\n \n # Lifting arrow\n lift_arrow = Arrow(mod3_circle.get_right(), mod9_circle.get_left(), buff=0.1)\n lift_text = Text(\"Hensel's Lemma\", font_size=20).next_to(lift_arrow, UP)\n \n self.play(Create(lift_arrow), Write(lift_text))\n \n # Root in mod 9\n mod9_root = Dot(mod9_circle.get_center(), color=YELLOW)\n mod9_root_label = Text(\"x=1\", font_size=24).next_to(mod9_root, UP)\n \n self.play(FadeIn(mod9_root), Write(mod9_root_label))\n self.wait(1)\n \n # Conclusion\n conclusion = Text(\"Hensel's Lemma reveals continuity in modular arithmetic\", font_size=30)\n conclusion.scale(0.8) # Scale down to ensure it fits on screen\n \n self.play(\n FadeOut(mod3_circle), FadeOut(mod9_circle),\n FadeOut(mod3_label), FadeOut(mod9_label),\n FadeOut(mod3_root), FadeOut(mod9_root),\n FadeOut(mod3_root_label), FadeOut(mod9_root_label),\n FadeOut(lift_arrow), FadeOut(lift_text),\n FadeOut(derivative),\n FadeOut(title),\n Write(conclusion)\n )\n self.wait(2)\n```", "category": "spatial_layout_overlap", "source": "synthetic_hard_neg:bespokelabs/bespoke-manim"} +{"system": "You are an expert Manim Community Edition (ManimCE v0.19+) Python developer and mathematical animator. Given a user request, first plan the spatial layout, coordinate bounds, timing, and pedagogical flow inside ... tags (when reasoning is helpful), and then output a complete, runnable, self-contained ManimCE Python script using `from manim import *`. Never use deprecated ManimGL (`manimlib`) methods like `ShowCreation`, `TexMobject`, `TextMobject`, or `axes.get_graph`; always use modern ManimCE APIs (`Create`, `MathTex`, `Tex`, `Text`, `axes.plot`) and prevent visual overlap using `.to_edge()`, `.next_to()`, and `FadeOut`.", "prompt": "I'm teaching undergrads calculus and want a vivid visualization of the derivative as a limit of secant slopes.\nPlot f(x) and, for a fixed x0, a family of secant lines through (x0, f(x0)) and (x0+h, f(x0+h)) with h shrinking to 0.\nShow the slopes converging to f'(x0) and draw the tangent line at x0 with that slope; include the limit expression and a zoom on x0 to highlight the convergence.", "chosen": "```python\nfrom manim import Scene, Text, MathTex, Axes, Dot, Line, DashedLine, FunctionGraph, Write, Create, FadeIn, FadeOut, Transform, Indicate, SurroundingRectangle\nfrom manim import UP, DOWN, LEFT, RIGHT, UR, DR, DL, UL, YELLOW, BLUE, GREEN, RED, ORANGE, WHITE\nfrom manim_voiceover import VoiceoverScene\nfrom manim_voiceover.services.gtts import GTTSService\n\nclass DerivativeAsLimitScene(VoiceoverScene):\n def construct(self):\n self.set_speech_service(\n GTTSService(voice=\"alba\", cache_dir=\"voiceover_cache\")\n )\n \n # ==================== SECTION 1: INTRODUCTION ====================\n with self.voiceover(text=\"Have you ever wondered how slopes of curves work?\") as tracker:\n title = Text(\"Derivative as Limit of Secant Slopes\", font_size=36)\n subtitle = Text(\"Understanding the foundation of calculus\", font_size=24, color=BLUE)\n title.to_edge(UP, buff=0.5)\n subtitle.next_to(title, DOWN, buff=0.3)\n self.play(Write(title), Write(subtitle), run_time=tracker.duration)\n \n self.wait(0.3)\n \n with self.voiceover(text=\"We know the slope of a straight line. But how do we find the slope of a curve?\") as tracker:\n # Fade out title\n self.play(FadeOut(title), FadeOut(subtitle), run_time=0.5)\n \n # Create straight line vs curve comparison\n line = Line(LEFT * 3 + DOWN, RIGHT * 3 + UP, color=GREEN)\n curve = FunctionGraph(lambda x: x**2 / 3, x_range=[-3, 3], color=YELLOW)\n \n line_label = Text(\"Straight line: easy slope!\", font_size=20, color=GREEN).next_to(line, UP)\n curve_label = Text(\"Curve: how do we measure slope?\", font_size=20, color=YELLOW).next_to(curve, DOWN)\n \n self.play(Create(line), Write(line_label), run_time=tracker.duration * 0.5)\n self.play(Create(curve), Write(curve_label), run_time=tracker.duration * 0.5)\n \n self.wait(0.3)\n \n with self.voiceover(text=\"The answer lies in derivatives, and specifically, in the concept of secant slopes.\") as tracker:\n self.play(FadeOut(line), FadeOut(line_label), FadeOut(curve_label), run_time=0.5)\n # Keep the curve for next section\n \n # ==================== SECTION 2: SECANT LINE CONCEPT ====================\n with self.voiceover(text=\"A secant line cuts through a curve at two points.\") as tracker:\n # Use parabola as our example function\n axes = Axes(\n x_range=[-1, 4, 1],\n y_range=[-1, 5, 1],\n x_length=6,\n y_length=4,\n axis_config={\"include_tip\": True, \"numbers_to_exclude\": []},\n ).to_edge(DOWN, buff=0.5)\n \n axes_labels = axes.get_axis_labels(x_label=\"x\", y_label=\"f(x)\")\n \n parabola = axes.plot(lambda x: x**2 / 2, x_range=[0, 3], color=YELLOW)\n func_label = MathTex(r\"f(x) = \\frac{x^2}{2}\", font_size=24).to_corner(UR)\n \n self.play(Create(axes), Write(axes_labels), run_time=0.5)\n self.play(Create(parabola), Write(func_label), run_time=tracker.duration - 0.5)\n \n self.wait(0.3)\n \n with self.voiceover(text=\"Let's pick a point x, and another point x plus h.\") as tracker:\n x_val = 1.5\n h_val = 1.0\n \n # Points on curve\n point_p = axes.c2p(x_val, (x_val**2)/2)\n point_q = axes.c2p(x_val + h_val, ((x_val + h_val)**2)/2)\n \n dot_p = Dot(point_p, color=RED, radius=0.08)\n dot_q = Dot(point_q, color=BLUE, radius=0.08)\n \n label_p = MathTex(r\"P(x, f(x))\", font_size=20, color=RED).next_to(dot_p, LEFT, buff=0.2)\n label_q = MathTex(r\"Q(x+h, f(x+h))\", font_size=20, color=BLUE).next_to(dot_q, RIGHT, buff=0.2)\n \n self.play(FadeIn(dot_p), Write(label_p), run_time=tracker.duration * 0.5)\n self.play(FadeIn(dot_q), Write(label_q), run_time=tracker.duration * 0.5)\n \n self.wait(0.3)\n \n with self.voiceover(text=\"The secant line connects these two points.\") as tracker:\n secant_line = Line(dot_p.get_center(), dot_q.get_center(), color=GREEN, stroke_width=3)\n secant_label = Text(\"Secant line\", font_size=18, color=GREEN).next_to(secant_line, UP, buff=0.1)\n \n self.play(Create(secant_line), Write(secant_label), run_time=tracker.duration)\n \n self.wait(0.3)\n \n # ==================== SECTION 3: SLOPE FORMULA ====================\n with self.voiceover(text=\"The slope of this secant line is rise over run.\") as tracker:\n # Rise and run lines\n run_line = DashedLine(dot_p.get_center(), axes.c2p(x_val + h_val, (x_val**2)/2), color=WHITE, dash_length=0.1)\n rise_line = DashedLine(axes.c2p(x_val + h_val, (x_val**2)/2), dot_q.get_center(), color=WHITE, dash_length=0.1)\n \n run_label = MathTex(r\"h\", font_size=20).next_to(run_line, DOWN, buff=0.1)\n rise_label = MathTex(r\"f(x+h) - f(x)\", font_size=18).next_to(rise_line, RIGHT, buff=0.1)\n \n self.play(Create(run_line), Write(run_label), run_time=tracker.duration * 0.5)\n self.play(Create(rise_line), Write(rise_label), run_time=tracker.duration * 0.5)\n \n self.wait(0.3)\n \n with self.voiceover(text=\"So the slope equals f of x plus h, minus f of x, all divided by h.\") as tracker:\n # Clear some space and show formula\n self.play(\n FadeOut(run_line), FadeOut(rise_line), FadeOut(run_label), FadeOut(rise_label),\n FadeOut(secant_label),\n run_time=0.3\n )\n \n slope_formula = MathTex(r\"m_{\\text{secant}} = \\frac{f(x+h) - f(x)}{h}\", font_size=28)\n slope_formula.to_edge(UP, buff=0.5)\n \n self.play(Write(slope_formula), run_time=tracker.duration)\n \n self.wait(0.3)\n \n # ==================== SECTION 4: THE LIMIT CONCEPT ====================\n with self.voiceover(text=\"Now, what happens as h gets smaller and smaller?\") as tracker:\n self.play(FadeOut(slope_formula), run_time=0.3)\n \n # Animate h getting smaller\n h_values = [0.8, 0.5, 0.3, 0.15, 0.05]\n prev_dot_q = dot_q\n prev_secant = secant_line\n \n for i, new_h in enumerate(h_values):\n new_q_point = axes.c2p(x_val + new_h, ((x_val + new_h)**2)/2)\n new_dot_q = Dot(new_q_point, color=BLUE, radius=0.08)\n new_secant = Line(dot_p.get_center(), new_q_point, color=GREEN, stroke_width=3)\n \n run_time = 0.4 if i < len(h_values) - 1 else 0.8\n self.play(\n Transform(prev_dot_q, new_dot_q),\n Transform(prev_secant, new_secant),\n run_time=run_time\n )\n \n self.wait(0.3)\n \n with self.voiceover(text=\"As h approaches zero, the secant line approaches the tangent line at point P.\") as tracker:\n # Draw the tangent line\n # For f(x) = x^2/2, f'(x) = x, so at x=1.5, slope = 1.5\n tangent_slope = x_val\n tangent_line = axes.plot(lambda t: (tangent_slope * (t - x_val)) + (x_val**2)/2, \n x_range=[0.5, 2.5], color=ORANGE, stroke_width=4)\n tangent_label = Text(\"Tangent line\", font_size=18, color=ORANGE).next_to(tangent_line, UR, buff=0.1)\n \n self.play(\n Create(tangent_line),\n Write(tangent_label),\n run_time=tracker.duration\n )\n \n self.wait(0.3)\n \n with self.voiceover(text=\"And the slope of the secant approaches the slope of the tangent.\") as tracker:\n # Flash the tangent line\n self.play(Indicate(tangent_line, scale_factor=1.02), run_time=tracker.duration)\n \n self.wait(0.3)\n \n # ==================== SECTION 5: THE DERIVATIVE FORMULA ====================\n with self.voiceover(text=\"This leads us to the definition of the derivative.\") as tracker:\n # Clear most objects, keep axes and curve\n self.play(\n FadeOut(prev_dot_q), FadeOut(prev_secant), FadeOut(label_p), FadeOut(label_q),\n FadeOut(tangent_line), FadeOut(tangent_label), FadeOut(dot_p),\n run_time=0.5\n )\n \n limit_formula = MathTex(\n r\"f'(x) = \\lim_{h \\to 0} \\frac{f(x+h) - f(x)}{h}\",\n font_size=36\n )\n limit_formula.to_edge(UP, buff=1)\n \n self.play(Write(limit_formula), run_time=tracker.duration)\n \n self.wait(0.3)\n \n with self.voiceover(text=\"The derivative is the limit of the secant slope, as h approaches zero.\") as tracker:\n # Highlight parts of formula\n box = SurroundingRectangle(limit_formula, buff=0.2, color=YELLOW)\n self.play(Create(box), run_time=tracker.duration * 0.5)\n self.play(FadeOut(box), run_time=tracker.duration * 0.5)\n \n self.wait(0.3)\n \n # ==================== SECTION 6: KEY TAKEAWAYS ====================\n with self.voiceover(text=\"Let's review what we've learned.\") as tracker:\n self.play(\n FadeOut(limit_formula), FadeOut(axes), FadeOut(axes_labels),\n FadeOut(parabola), FadeOut(func_label),\n run_time=0.5\n )\n \n takeaway_title = Text(\"Key Takeaways\", font_size=32, color=YELLOW)\n takeaway_title.to_edge(UP, buff=0.8)\n self.play(Write(takeaway_title), run_time=tracker.duration - 0.5)\n \n self.wait(0.3)\n \n with self.voiceover(text=\"First, a secant line cuts a curve at two points.\") as tracker:\n point1 = Text(\"- Secant line connects two points on a curve\", font_size=22)\n point1.next_to(takeaway_title, DOWN, buff=0.6)\n self.play(Write(point1), run_time=tracker.duration)\n \n self.wait(0.3)\n \n with self.voiceover(text=\"Second, its slope is f of x plus h minus f of x, over h.\") as tracker:\n point2 = Text(\"- Secant slope = (f(x+h) - f(x)) / h\", font_size=22)\n point2.next_to(point1, DOWN, buff=0.4)\n self.play(Write(point2), run_time=tracker.duration)\n \n self.wait(0.3)\n \n with self.voiceover(text=\"Third, as h approaches zero, the secant becomes the tangent.\") as tracker:\n point3 = Text(\"- As h approaches 0, secant becomes tangent\", font_size=22)\n point3.next_to(point2, DOWN, buff=0.4)\n self.play(Write(point3), run_time=tracker.duration)\n \n self.wait(0.3)\n \n with self.voiceover(text=\"And finally, the derivative is exactly this limit.\") as tracker:\n point4 = Text(\"- Derivative f'(x) = limit of secant slope\", font_size=22)\n point4.next_to(point3, DOWN, buff=0.4)\n self.play(Write(point4), run_time=tracker.duration)\n \n self.wait(0.3)\n \n with self.voiceover(text=\"This fundamental concept connects geometry to calculus, letting us find instantaneous rates of change.\") as tracker:\n final_formula = MathTex(r\"f'(x) = \\lim_{h \\to 0} \\frac{f(x+h) - f(x)}{h}\", font_size=28, color=BLUE)\n final_formula.next_to(point4, DOWN, buff=0.6)\n self.play(Write(final_formula), run_time=tracker.duration)\n \n self.wait(1)\n \n with self.voiceover(text=\"Thanks for watching!\") as tracker:\n self.play(FadeOut(takeaway_title), FadeOut(point1), FadeOut(point2), \n FadeOut(point3), FadeOut(point4), FadeOut(final_formula),\n run_time=tracker.duration)\n \n self.wait(0.5)\n```", "rejected": "```python\nfrom manim import Scene, Text, MathTex, Axes, Dot, Line, DashedLine, FunctionGraph, Write, Create, FadeIn, FadeOut, Transform, Indicate, SurroundingRectangle\nfrom manim import UP, DOWN, LEFT, RIGHT, UR, DR, DL, UL, YELLOW, BLUE, GREEN, RED, ORANGE, WHITE\nfrom manim_voiceover import VoiceoverScene\nfrom manim_voiceover.services.gtts import GTTSService\n\nclass DerivativeAsLimitScene(VoiceoverScene):\n def construct(self):\n self.set_speech_service(\n GTTSService(voice=\"alba\", cache_dir=\"voiceover_cache\")\n )\n \n # ==================== SECTION 1: INTRODUCTION ====================\n with self.voiceover(text=\"Have you ever wondered how slopes of curves work?\") as tracker:\n title = Text(\"Derivative as Limit of Secant Slopes\", font_size=36)\n subtitle = Text(\"Understanding the foundation of calculus\", font_size=24, color=BLUE)\n title.to_edge(UP, buff=0.5)\n subtitle.next_to(title, DOWN, buff=0.3)\n self.play(Write(title), Write(subtitle), run_time=tracker.duration)\n \n self.wait(0.3)\n \n with self.voiceover(text=\"We know the slope of a straight line. But how do we find the slope of a curve?\") as tracker:\n # Fade out title\n self.play(FadeOut(title), FadeOut(subtitle), run_time=0.5)\n \n # Create straight line vs curve comparison\n line = Line(LEFT * 3 + DOWN, RIGHT * 3 + UP, color=GREEN)\n curve = FunctionGraph(lambda x: x**2 / 3, x_range=[-3, 3], color=YELLOW)\n \n line_label = Text(\"Straight line: easy slope!\", font_size=20, color=GREEN).next_to(line, UP)\n curve_label = Text(\"Curve: how do we measure slope?\", font_size=20, color=YELLOW).next_to(curve, DOWN)\n \n self.play(Create(line), Write(line_label), run_time=tracker.duration * 0.5)\n self.play(Create(curve), Write(curve_label), run_time=tracker.duration * 0.5)\n \n self.wait(0.3)\n \n with self.voiceover(text=\"The answer lies in derivatives, and specifically, in the concept of secant slopes.\") as tracker:\n self.play(FadeOut(line), FadeOut(line_label), FadeOut(curve_label), run_time=0.5)\n # Keep the curve for next section\n \n # ==================== SECTION 2: SECANT LINE CONCEPT ====================\n with self.voiceover(text=\"A secant line cuts through a curve at two points.\") as tracker:\n # Use parabola as our example function\n axes = Axes(axis_color=BLUE, \n x_range=[-1, 4, 1],\n y_range=[-1, 5, 1],\n x_length=6,\n y_length=4,\n axis_config={\"include_tip\": True, \"numbers_to_exclude\": []},\n ).to_edge(DOWN, buff=0.5)\n \n axes_labels = axes.get_axis_labels(x_label=\"x\", y_label=\"f(x)\")\n \n parabola = axes.plot(lambda x: x**2 / 2, x_range=[0, 3], color=YELLOW)\n func_label = MathTex(r\"f(x) = \\frac{x^2}{2}\", font_size=24).to_corner(UR)\n \n self.play(Create(axes), Write(axes_labels), run_time=0.5)\n self.play(Create(parabola), Write(func_label), run_time=tracker.duration - 0.5)\n \n self.wait(0.3)\n \n with self.voiceover(text=\"Let's pick a point x, and another point x plus h.\") as tracker:\n x_val = 1.5\n h_val = 1.0\n \n # Points on curve\n point_p = axes.c2p(x_val, (x_val**2)/2)\n point_q = axes.c2p(x_val + h_val, ((x_val + h_val)**2)/2)\n \n dot_p = Dot(point_p, color=RED, radius=0.08)\n dot_q = Dot(point_q, color=BLUE, radius=0.08)\n \n label_p = MathTex(r\"P(x, f(x))\", font_size=20, color=RED).next_to(dot_p, LEFT, buff=0.2)\n label_q = MathTex(r\"Q(x+h, f(x+h))\", font_size=20, color=BLUE).next_to(dot_q, RIGHT, buff=0.2)\n \n self.play(FadeIn(dot_p), Write(label_p), run_time=tracker.duration * 0.5)\n self.play(FadeIn(dot_q), Write(label_q), run_time=tracker.duration * 0.5)\n \n self.wait(0.3)\n \n with self.voiceover(text=\"The secant line connects these two points.\") as tracker:\n secant_line = Line(dot_p.get_center(), dot_q.get_center(), color=GREEN, stroke_width=3)\n secant_label = Text(\"Secant line\", font_size=18, color=GREEN).next_to(secant_line, UP, buff=0.1)\n \n self.play(Create(secant_line), Write(secant_label), run_time=tracker.duration)\n \n self.wait(0.3)\n \n # ==================== SECTION 3: SLOPE FORMULA ====================\n with self.voiceover(text=\"The slope of this secant line is rise over run.\") as tracker:\n # Rise and run lines\n run_line = DashedLine(dot_p.get_center(), axes.c2p(x_val + h_val, (x_val**2)/2), color=WHITE, dash_length=0.1)\n rise_line = DashedLine(axes.c2p(x_val + h_val, (x_val**2)/2), dot_q.get_center(), color=WHITE, dash_length=0.1)\n \n run_label = MathTex(r\"h\", font_size=20).next_to(run_line, DOWN, buff=0.1)\n rise_label = MathTex(r\"f(x+h) - f(x)\", font_size=18).next_to(rise_line, RIGHT, buff=0.1)\n \n self.play(Create(run_line), Write(run_label), run_time=tracker.duration * 0.5)\n self.play(Create(rise_line), Write(rise_label), run_time=tracker.duration * 0.5)\n \n self.wait(0.3)\n \n with self.voiceover(text=\"So the slope equals f of x plus h, minus f of x, all divided by h.\") as tracker:\n # Clear some space and show formula\n self.play(\n FadeOut(run_line), FadeOut(rise_line), FadeOut(run_label), FadeOut(rise_label),\n FadeOut(secant_label),\n run_time=0.3\n )\n \n slope_formula = MathTex(r\"m_{\\text{secant}} = \\frac{f(x+h) - f(x)}{h}\", font_size=28)\n slope_formula.to_edge(UP, buff=0.5)\n \n self.play(Write(slope_formula), run_time=tracker.duration)\n \n self.wait(0.3)\n \n # ==================== SECTION 4: THE LIMIT CONCEPT ====================\n with self.voiceover(text=\"Now, what happens as h gets smaller and smaller?\") as tracker:\n self.play(FadeOut(slope_formula), run_time=0.3)\n \n # Animate h getting smaller\n h_values = [0.8, 0.5, 0.3, 0.15, 0.05]\n prev_dot_q = dot_q\n prev_secant = secant_line\n \n for i, new_h in enumerate(h_values):\n new_q_point = axes.c2p(x_val + new_h, ((x_val + new_h)**2)/2)\n new_dot_q = Dot(new_q_point, color=BLUE, radius=0.08)\n new_secant = Line(dot_p.get_center(), new_q_point, color=GREEN, stroke_width=3)\n \n run_time = 0.4 if i < len(h_values) - 1 else 0.8\n self.play(\n Transform(prev_dot_q, new_dot_q),\n Transform(prev_secant, new_secant),\n run_time=run_time\n )\n \n self.wait(0.3)\n \n with self.voiceover(text=\"As h approaches zero, the secant line approaches the tangent line at point P.\") as tracker:\n # Draw the tangent line\n # For f(x) = x^2/2, f'(x) = x, so at x=1.5, slope = 1.5\n tangent_slope = x_val\n tangent_line = axes.plot(lambda t: (tangent_slope * (t - x_val)) + (x_val**2)/2, \n x_range=[0.5, 2.5], color=ORANGE, stroke_width=4)\n tangent_label = Text(\"Tangent line\", font_size=18, color=ORANGE).next_to(tangent_line, UR, buff=0.1)\n \n self.play(\n Create(tangent_line),\n Write(tangent_label),\n run_time=tracker.duration\n )\n \n self.wait(0.3)\n \n with self.voiceover(text=\"And the slope of the secant approaches the slope of the tangent.\") as tracker:\n # Flash the tangent line\n self.play(Indicate(tangent_line, scale_factor=1.02), run_time=tracker.duration)\n \n self.wait(0.3)\n \n # ==================== SECTION 5: THE DERIVATIVE FORMULA ====================\n with self.voiceover(text=\"This leads us to the definition of the derivative.\") as tracker:\n # Clear most objects, keep axes and curve\n self.play(\n FadeOut(prev_dot_q), FadeOut(prev_secant), FadeOut(label_p), FadeOut(label_q),\n FadeOut(tangent_line), FadeOut(tangent_label), FadeOut(dot_p),\n run_time=0.5\n )\n \n limit_formula = MathTex(\n r\"f'(x) = \\lim_{h \\to 0} \\frac{f(x+h) - f(x)}{h}\",\n font_size=36\n )\n limit_formula.to_edge(UP, buff=1)\n \n self.play(Write(limit_formula), run_time=tracker.duration)\n \n self.wait(0.3)\n \n with self.voiceover(text=\"The derivative is the limit of the secant slope, as h approaches zero.\") as tracker:\n # Highlight parts of formula\n box = SurroundingRectangle(limit_formula, buff=0.2, color=YELLOW)\n self.play(Create(box), run_time=tracker.duration * 0.5)\n self.play(FadeOut(box), run_time=tracker.duration * 0.5)\n \n self.wait(0.3)\n \n # ==================== SECTION 6: KEY TAKEAWAYS ====================\n with self.voiceover(text=\"Let's review what we've learned.\") as tracker:\n self.play(\n FadeOut(limit_formula), FadeOut(axes), FadeOut(axes_labels),\n FadeOut(parabola), FadeOut(func_label),\n run_time=0.5\n )\n \n takeaway_title = Text(\"Key Takeaways\", font_size=32, color=YELLOW)\n takeaway_title.to_edge(UP, buff=0.8)\n self.play(Write(takeaway_title), run_time=tracker.duration - 0.5)\n \n self.wait(0.3)\n \n with self.voiceover(text=\"First, a secant line cuts a curve at two points.\") as tracker:\n point1 = Text(\"- Secant line connects two points on a curve\", font_size=22)\n point1.next_to(takeaway_title, DOWN, buff=0.6)\n self.play(Write(point1), run_time=tracker.duration)\n \n self.wait(0.3)\n \n with self.voiceover(text=\"Second, its slope is f of x plus h minus f of x, over h.\") as tracker:\n point2 = Text(\"- Secant slope = (f(x+h) - f(x)) / h\", font_size=22)\n point2.next_to(point1, DOWN, buff=0.4)\n self.play(Write(point2), run_time=tracker.duration)\n \n self.wait(0.3)\n \n with self.voiceover(text=\"Third, as h approaches zero, the secant becomes the tangent.\") as tracker:\n point3 = Text(\"- As h approaches 0, secant becomes tangent\", font_size=22)\n point3.next_to(point2, DOWN, buff=0.4)\n self.play(Write(point3), run_time=tracker.duration)\n \n self.wait(0.3)\n \n with self.voiceover(text=\"And finally, the derivative is exactly this limit.\") as tracker:\n point4 = Text(\"- Derivative f'(x) = limit of secant slope\", font_size=22)\n point4.next_to(point3, DOWN, buff=0.4)\n self.play(Write(point4), run_time=tracker.duration)\n \n self.wait(0.3)\n \n with self.voiceover(text=\"This fundamental concept connects geometry to calculus, letting us find instantaneous rates of change.\") as tracker:\n final_formula = MathTex(r\"f'(x) = \\lim_{h \\to 0} \\frac{f(x+h) - f(x)}{h}\", font_size=28, color=BLUE)\n final_formula.next_to(point4, DOWN, buff=0.6)\n self.play(Write(final_formula), run_time=tracker.duration)\n \n self.wait(1)\n \n with self.voiceover(text=\"Thanks for watching!\") as tracker:\n self.play(FadeOut(takeaway_title), FadeOut(point1), FadeOut(point2), \n FadeOut(point3), FadeOut(point4), FadeOut(final_formula),\n run_time=tracker.duration)\n \n self.wait(0.5)\n```", "category": "invalid_axes_kwarg", "source": "synthetic_hard_neg:nabin2004/AOS-Narrated-Manim-400"} +{"system": "You are an expert Manim Community Edition (ManimCE v0.19+) Python developer and mathematical animator. Given a user request, first plan the spatial layout, coordinate bounds, timing, and pedagogical flow inside ... tags (when reasoning is helpful), and then output a complete, runnable, self-contained ManimCE Python script using `from manim import *`. Never use deprecated ManimGL (`manimlib`) methods like `ShowCreation`, `TexMobject`, `TextMobject`, or `axes.get_graph`; always use modern ManimCE APIs (`Create`, `MathTex`, `Tex`, `Text`, `axes.plot`) and prevent visual overlap using `.to_edge()`, `.next_to()`, and `FadeOut`.", "prompt": "Display a coordinate grid with labeled axes, where the x-axis ranges from 0 to 10 and the y-axis uses a logarithmic scale. A curve representing the function \\( y = x^2 \\) is plotted from just above 0 to 10. The graph visually demonstrates how the quadratic function behaves when the vertical axis is scaled logarithmically.", "chosen": "```python\nfrom manim import *\n\nclass LogScalingExample(Scene):\n def construct(self):\n ax = Axes(\n x_range=[0, 10, 1],\n y_range=[-2, 6, 1],\n tips=False,\n axis_config={\"include_numbers\": True},\n y_axis_config={\"scaling\": LogBase(custom_labels=True)},\n )\n\n # x_min must be > 0 because log is undefined at 0.\n graph = ax.plot(lambda x: x ** 2, x_range=[0.001, 10], use_smoothing=False)\n self.add(ax, graph)\n```", "rejected": "```python\nfrom manim import *\n\nclass LogScalingExample(Scene):\n def construct(self):\n ax = Axes(axis_color=BLUE, \n x_range=[0, 10, 1],\n y_range=[-2, 6, 1],\n tips=False,\n axis_config={\"include_numbers\": True},\n y_axis_config={\"scaling\": LogBase(custom_labels=True)},\n )\n\n # x_min must be > 0 because log is undefined at 0.\n graph = ax.plot(lambda x: x ** 2, x_range=[0.001, 10], use_smoothing=False)\n self.add(ax, graph)\n```", "category": "invalid_axes_kwarg", "source": "synthetic_hard_neg:SuienR/ManimBench-v1"} +{"system": "You are an expert Manim Community Edition (ManimCE v0.19+) Python developer and mathematical animator. Given a user request, first plan the spatial layout, coordinate bounds, timing, and pedagogical flow inside ... tags (when reasoning is helpful), and then output a complete, runnable, self-contained ManimCE Python script using `from manim import *`. Never use deprecated ManimGL (`manimlib`) methods like `ShowCreation`, `TexMobject`, `TextMobject`, or `axes.get_graph`; always use modern ManimCE APIs (`Create`, `MathTex`, `Tex`, `Text`, `axes.plot`) and prevent visual overlap using `.to_edge()`, `.next_to()`, and `FadeOut`.", "prompt": "I'm learning about Xavier initialization and want a visual that shows backward pass gradient variance staying constant across layers, depicted as equal-height bars.\nShow an initialization stage, then a backward pass where variances propagate and remain balanced, with colors highlighting variance retention.\nInclude a mode where mis-specified variance causes shrinking or exploding bars to illustrate failure and how Xavier prevents that.\nAdd small annotations tying variance to layer width and activation nonlinearity.", "chosen": "```python\nfrom manim import *\n\nclass XavierInitialization(Scene):\n\n def construct(self):\n title = Text('Xavier Initialization and Gradient Variance', font_size=34)\n title.to_edge(UP, buff=0.4)\n self.play(Write(title), run_time=2.0)\n subtitle = Text('Weight Initialization Matters', font_size=26)\n subtitle.next_to(title, DOWN, buff=0.3)\n self.play(Write(subtitle), run_time=2.0)\n self.wait(0.3)\n self.play(FadeOut(subtitle))\n layer_label = Text('Fully Connected Layer', font_size=24)\n layer_label.next_to(title, DOWN, buff=0.3)\n left_nodes = VGroup(*[Circle(radius=0.12, color=BLUE, fill_opacity=0.8) for _ in range(4)])\n left_nodes.arrange(DOWN, buff=0.35)\n left_nodes.shift(LEFT * 2.2 + DOWN * 0.2)\n right_nodes = VGroup(*[Circle(radius=0.12, color=GREEN, fill_opacity=0.8) for _ in range(3)])\n right_nodes.arrange(DOWN, buff=0.35)\n right_nodes.shift(RIGHT * 2.2 + DOWN * 0.2)\n edges = VGroup()\n for ln in left_nodes:\n for rn in right_nodes:\n edge = Line(ln.get_center(), rn.get_center(), stroke_width=1.2, color=GRAY_C)\n edges.add(edge)\n network = VGroup(left_nodes, right_nodes, edges)\n self.play(Write(layer_label), Create(network), run_time=2.0)\n xavier_formula = MathTex('\\\\text{Var}(W)', '=', '\\\\frac{6}{\\\\text{fan\\\\_in} + \\\\text{fan\\\\_out}}', font_size=36)\n xavier_formula.next_to(network, DOWN, buff=0.5)\n self.play(Write(xavier_formula), run_time=2.0)\n highlight_box = SurroundingRectangle(xavier_formula, color=YELLOW, buff=0.15)\n self.play(Create(highlight_box), run_time=2.0)\n self.play(FadeOut(highlight_box), FadeOut(network), FadeOut(layer_label))\n self.play(xavier_formula.animate.to_edge(UP, buff=0.5))\n grad_formula = MathTex('\\\\text{Var}(\\\\nabla)', '=', 'a^2', '\\\\cdot', '\\\\text{Var}(W)', font_size=36)\n grad_formula.next_to(xavier_formula, DOWN, buff=0.7)\n self.play(Write(grad_formula), run_time=2.0)\n arrow = Arrow(xavier_formula.get_bottom(), grad_formula.get_top(), buff=0.25, color=YELLOW)\n self.play(Create(arrow), run_time=2.0 * 0.5)\n self.play(arrow.animate.set_color(GREEN), run_time=2.0 * 0.5)\n self.wait(0.3)\n self.play(FadeOut(xavier_formula), FadeOut(grad_formula), FadeOut(arrow))\n takeaway_title = Text('Key Takeaways', font_size=30)\n takeaway_title.to_edge(UP, buff=0.4)\n points = VGroup(Text('• Xavier init stabilizes signal variance', font_size=22), Text('• It balances fan in and fan out', font_size=22), Text('• Controls gradient variance', font_size=22), Text('• Prevents vanishing and exploding gradients', font_size=22)).arrange(DOWN, aligned_edge=LEFT, buff=0.3)\n points.next_to(takeaway_title, DOWN, buff=0.45)\n self.play(Write(takeaway_title), run_time=2.0 * 0.3)\n self.play(Write(points), run_time=2.0 * 0.7)\n self.wait(1)\n```", "rejected": "```python\nfrom manim import *\n\nclass XavierInitialization(Scene):\n\n def construct(self):\n title = Text('Xavier Initialization and Gradient Variance', font_size=34)\n title\n self.play(Write(title), run_time=2.0)\n subtitle = Text('Weight Initialization Matters', font_size=26)\n subtitle\n self.play(Write(subtitle), run_time=2.0)\n self.wait(0.3)\n self.play(FadeOut(subtitle))\n layer_label = Text('Fully Connected Layer', font_size=24)\n layer_label\n left_nodes = VGroup(*[Circle(radius=0.12, color=BLUE, fill_opacity=0.8) for _ in range(4)])\n left_nodes.arrange(DOWN, buff=0.35)\n left_nodes.shift(LEFT * 2.2 + DOWN * 0.2)\n right_nodes = VGroup(*[Circle(radius=0.12, color=GREEN, fill_opacity=0.8) for _ in range(3)])\n right_nodes.arrange(DOWN, buff=0.35)\n right_nodes.shift(RIGHT * 2.2 + DOWN * 0.2)\n edges = VGroup()\n for ln in left_nodes:\n for rn in right_nodes:\n edge = Line(ln.get_center(), rn.get_center(), stroke_width=1.2, color=GRAY_C)\n edges.add(edge)\n network = VGroup(left_nodes, right_nodes, edges)\n self.play(Write(layer_label), Create(network), run_time=2.0)\n xavier_formula = MathTex('\\\\text{Var}(W)', '=', '\\\\frac{6}{\\\\text{fan\\\\_in} + \\\\text{fan\\\\_out}}', font_size=36)\n xavier_formula.next_to(network, DOWN, buff=0.5)\n self.play(Write(xavier_formula), run_time=2.0)\n highlight_box = SurroundingRectangle(xavier_formula, color=YELLOW, buff=0.15)\n self.play(Create(highlight_box), run_time=2.0)\n self.play(FadeOut(highlight_box), FadeOut(network), FadeOut(layer_label))\n self.play(xavier_formula.animate.to_edge(UP, buff=0.5))\n grad_formula = MathTex('\\\\text{Var}(\\\\nabla)', '=', 'a^2', '\\\\cdot', '\\\\text{Var}(W)', font_size=36)\n grad_formula.next_to(xavier_formula, DOWN, buff=0.7)\n self.play(Write(grad_formula), run_time=2.0)\n arrow = Arrow(xavier_formula.get_bottom(), grad_formula.get_top(), buff=0.25, color=YELLOW)\n self.play(Create(arrow), run_time=2.0 * 0.5)\n self.play(arrow.animate.set_color(GREEN), run_time=2.0 * 0.5)\n self.wait(0.3)\n self.play(FadeOut(xavier_formula), FadeOut(grad_formula), FadeOut(arrow))\n takeaway_title = Text('Key Takeaways', font_size=30)\n takeaway_title.to_edge(UP, buff=0.4)\n points = VGroup(Text('• Xavier init stabilizes signal variance', font_size=22), Text('• It balances fan in and fan out', font_size=22), Text('• Controls gradient variance', font_size=22), Text('• Prevents vanishing and exploding gradients', font_size=22)).arrange(DOWN, aligned_edge=LEFT, buff=0.3)\n points.next_to(takeaway_title, DOWN, buff=0.45)\n self.play(Write(takeaway_title), run_time=2.0 * 0.3)\n self.play(Write(points), run_time=2.0 * 0.7)\n self.wait(1)\n```", "category": "spatial_layout_overlap", "source": "synthetic_hard_neg:nabin2004/AOS-Manim-SFT"}