Skip to main content
LLManim

Reusable Manim components for creating LLM and Transformer explanation videos.

PyPI version PyPI Downloads Documentation Status License: MIT

A Python library of pre-built visual components, animations, and utilities for creating educational videos about Large Language Models and Transformer architectures using Manim.

Installation · Quick Start · Components · Examples · Contributing


Installation

pip install llmanim

Prerequisites

Manim requires a few system dependencies before you install:

# macOS
brew install cairo pango ffmpeg
brew install --cask mactex          # LaTeX for MathTex

# Ubuntu / Debian
sudo apt install libcairo2-dev libpango1.0-dev ffmpeg texlive-full

# Windows — install MiKTeX from https://miktex.org, then:
# pip install manim

Full Manim installation guide: docs.manim.community

Install from source

git clone https://github.com/rishabhbhartiya/LLManim.git
cd LLManim
pip install -e ".[dev]"

Quick Start

from manim import *
from llmanim.base.shapes import MatrixBox, VectorBar, TokenBox
from llmanim.base.animations import highlight_sequence, data_flow_arrow
from llmanim.base.utils import apply_dark_theme, make_attention_weights
from llmanim.tokenization.token_box import TokenRow
from llmanim.styles.colors import TOKEN_COLOR, HIGHLIGHT_COLOR

class MyTransformerScene(Scene):
    def construct(self):
        apply_dark_theme(self)

        # 1. Show a token sequence
        row = TokenRow(["the", "cat", "sat"], token_ids=[1, 2, 3])
        self.play(row.appear())

        # 2. Show an embedding matrix
        mat = MatrixBox(rows=4, cols=6, color=TOKEN_COLOR).shift(DOWN * 2)
        self.play(mat.fill_anim())

        # 3. Connect them with an animated arrow
        arrow, anim = data_flow_arrow(row, mat, label="embed")
        self.add(arrow)
        self.play(anim)

        # 4. Highlight components
        self.play(highlight_sequence(row.boxes))
        self.play(mat.highlight_row(2))
        self.wait(1)

Render it:

manim -pql my_scene.py MyTransformerScene   # fast preview
manim -pqh my_scene.py MyTransformerScene   # 1080p final

Example Videos

Five complete video scripts are included in examples/:

# File Scene Topic
1 01_what_is_a_token.py WhatIsAToken Tokenization basics
2 02_token_embeddings.py TokenEmbeddings Embedding lookup
3 03_attention_mechanism.py AttentionMechanism Q, K, V & softmax
4 04_multi_head_attention.py MultiHeadAttention Multiple attention heads
5 05_full_forward_pass.py FullForwardPass Complete forward pass

Video 1 — What is a Token?

What is a Token?

Video 2 — Token Embeddings

Token Embeddings

Video 3 — Attention Mechanism

Attention Mechanism

Video 4 — Multi-Head Attention

Multi-Head Attention

Video 5 — Full Forward Pass

Full Transformer Forward Pass
# Clone to access examples (they're not installed with pip)
git clone https://github.com/rishabhbhartiya/LLManim.git
cd LLManim

manim -pql examples/01_what_is_a_token.py WhatIsAToken     # preview
manim -pqh examples/05_full_forward_pass.py FullForwardPass # 1080p
manim -pqk examples/05_full_forward_pass.py FullForwardPass # 4K

Components

Base Shapes — llmanim.base.shapes

Class Description Key Methods
MatrixBox(rows, cols) Colored grid for weight matrices .highlight_row(r), .highlight_col(c), .fill_anim()
VectorBar(dim, values) Colored strip for embedding vectors .pulse(), .highlight_dim(i), .add_value_labels()
TokenBox(text, token_id) Rounded rectangle for a single token .highlight(), .shake(), .pop_in(), .pop_out()
LabeledBlock(label) Named rectangular block .highlight(), .expand_to(mob)
SoftmaxCurve(logits) Probability bar chart .set_temperature(T), .show_values()
MathLabel(latex) LaTeX equation label .write(), .unwrite()
ConnectionLine(srcs, tgts) Fully connected layer lines .draw(), .activate(i,j), .pulse_all()

Animations — llmanim.base.animations

Function Description
flow_through(mob, path) Animate an object along a path
matrix_multiply_anim(A, B, C, scene) Step-by-step matrix multiplication
highlight_sequence(boxes) Flash boxes one by one
attention_flow(tokens, weights) Weighted attention arrows between tokens
data_flow_arrow(A, B, label) Animated labeled arrow between mobjects
equation_reveal(terms, scene) Build an equation term by term
pulse_glow(mob) Expanding glow effect
zoom_into(mob, scene) Zoom in and back out
forward_pass_pulse(blocks) Light pulse travelling through layers

Utilities — llmanim.base.utils

Function Description
softmax(x, temperature) Numerically stable softmax
scaled_dot_product(Q, K, V, mask) Full attention computation
causal_mask(seq_len) Upper-triangular causal mask
sinusoidal_pe(seq_len, d_model) Sinusoidal positional encoding
make_attention_weights(seq_len, n_heads) Generate demo attention weights
make_token_sequence(words) Create a demo token sequence
value_to_color(v) Map a float to a Manim color
attention_palette(weights) Color palette from attention weights
apply_dark_theme(scene) Set dark background on a Scene

Tokenization — llmanim.tokenization.token_box

Class Description
TokenRow(tokens, token_ids) A horizontal row of token boxes
TokenBox(text, token_id) Individual token visualization
SpecialTokenBox(text) Special tokens like [CLS], [SEP]
BPESequence Byte-pair encoding visualization
VocabTable Vocabulary lookup table
ContextWindowBar Context window capacity indicator

Color System

All colors are in llmanim.styles.colors:

Constant Hex Used for
TOKEN_COLOR #4CAF50 Tokens, raw input
EMBEDDING_COLOR #2196F3 Embeddings, weight matrices
ATTENTION_COLOR #9C27B0 Attention mechanisms
FFN_COLOR #FF9800 Feed-forward networks
NORM_COLOR #00BCD4 Layer normalization
OUTPUT_COLOR #F44336 Output logits
QUERY_COLOR #E91E63 Query (Q) vectors
KEY_COLOR #3F51B5 Key (K) vectors
VALUE_COLOR #009688 Value (V) vectors
HIGHLIGHT_COLOR #FFEB3B Highlights, focus
DIM_COLOR #555555 Dimmed / background elements

Project Structure

LLManim/
├── llmanim/           # Installed package (import as llmanim)
│   ├── attention/               # QKV projection, scores, output, multi-head
│   ├── base/                    # shapes.py, animations.py, utils.py
│   ├── blocks/                  # transformer_block.py
│   ├── embeddings/              # embedding_lookup.py, positional_encoding.py
│   ├── feedforward/             # ffn.py
│   ├── normalization/           # layer_norm.py
│   ├── output/                  # logits_sampling.py
│   ├── styles/                  # colors.py, constants.py, fonts.py
│   ├── tokenization/            # token_box.py
│   └── full_model.py
├── examples/                    # Standalone video scripts (not installed)
├── videos/                      # Output GIFs for all example scenes
└── tests/

Video Production Workflow

  1. Plan — write your script outline and narration
  2. Import — pick components from llmanim
  3. Sketch — plan scene layout on paper
  4. Code — build scenes incrementally, preview with -pql
  5. Render — final export with -pqh or -pqk
  6. Voiceover — record audio to match animation timing
  7. Edit — combine in your video editor of choice

Contributing

Contributions are welcome — new components, bug fixes, example videos, or docs improvements. See CONTRIBUTING.md to get started.


License

MIT © Rishabh Bhartiya


Metadata

Release files for llmanim 0.1.3

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for llmanim 0.1.3
File Size Uploaded Provenance Actions
llmanim-0.1.3.tar.gz 154.4 kB Without provenance Details for llmanim-0.1.3.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for llmanim 0.1.3
File Interpreter ABI Platform Actions
llmanim-0.1.3-py3-none-any.whl Python 3 none any Details for llmanim-0.1.3-py3-none-any.whl

Total release size: 318.2 kB

Release files / llmanim-0.1.3.tar.gz

Download URL llmanim-0.1.3.tar.gz
Size 154.4 kB
Tags Source
SHA-256 checksum
How to use checksums
4f9e81f5f969c27680b851c7b0dcac790f563805cac1fb5d370e75531d71a48c
BLAKE2b-256 checksum
How to use checksums
ae7f816a545a7c582d629557a3909a8c96f5843f51e9dd3356c6431d67f95518
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.11.14

Release files / llmanim-0.1.3-py3-none-any.whl

Download URL llmanim-0.1.3-py3-none-any.whl
Size 163.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
ff2125832a41f4d3795f6fa39a1f8c23700f4630a99bd3f7bbdebad87170b9f3
BLAKE2b-256 checksum
How to use checksums
609f63bbcb87bcf821f49ba34af4dbaf0c94643db70e368e2e1cc52d5b49c527
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.11.14

Security for llmanim 0.1.3

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page