Education Draft

Transformers

From a maze to a sequence of moves.

A Transformer learns patterns in sequences. Those sequences can represent words, pixels, or a route through a maze. These small experiments are trained from scratch so the inputs, predictions, and mistakes are easier to inspect.

01 / Maze → moves

One token. One move.

The encoder reads the complete maze. The decoder uses that representation and its previous tokens to predict UP, DOWN, LEFT, RIGHT, or END. Step through a recorded run and watch the route take shape.

Animated replay of the Transformer solving an 11 by 11 maze, showing each generated move, the growing blue route, and token probabilities.
A complete recorded run: 31 moves, then END. Seed 1000003, checkpoint at 7,000 updates. Open GIF

Recorded inference from the local 11×11 checkpoint (7,000 updates). The browser replays model outputs; it does not run a Transformer. Playback starts paused.

See the original Python viewerActual Python viewer: an 11 by 11 maze solved with 31 moves followed by END, alongside final token probabilities.

Seed 1000003: 31 moves followed by END. This is one successful example.

01 / Encode

Read the grid

Wall, floor, start, and goal become cell tokens with row and column positions.

02 / Decode

Predict a move

Attention connects the maze representation with the moves generated so far.

03 / Repeat

Continue to END

Each prediction becomes input for the next step. Mistakes can lead into walls or end a route early.

Breadth-first search supplies training targets. During inference, the model chooses moves without search fallback or wall masking. Larger-maze generalization is not established.

Run the live Python demo & read the training notes ↗

02 / Screen history → paddle moves

Pong, ten moves ahead.

Four recent screen matrices go in. Ten paddle actions come out. An encoder reads the numeric history; an autoregressive decoder predicts a queue of STAY, UP, and DOWN tokens. Each player executes all ten moves before asking the model for another sequence.

Cinematic highlights from actual Transformer-versus-Transformer Pong matches. Numbered circles show pending paddle positions, side panels show ten-action queues, and a fading trail shows the ball’s past motion.
The newer cinematic cut: 6 minutes 10.6 seconds, with 32 rallies selected from 12 actual Transformer-versus-Transformer matches. Edge saves, long exchanges, and point endings include half-speed moments, scene cards, and black fades between cuts. Open GIF (56.3 MB)

Numbered circles mark pending paddle-center positions; overlapping predictions show only the earliest visible move. The ball’s fading trail shows past motion. This is an edited highlight reel, not a continuous match or performance evaluation.

01 / Observe

Read four frames

Each 24×32 matrix marks empty cells, walls, paddles, and the ball. The right player sees a mirrored view.

02 / Predict

Generate ten actions

The encoder runs once per refill. The decoder generates the complete action sequence before any of those moves execute.

03 / Execute

Finish the queue

The player runs all ten moves without corrections, then reads the latest history. Scoring a point does not clear pending moves.

Trained from scratch by imitating scripted teachers. During play, the learned players receive no coordinates, velocities, or expert fallback. This is imitation learning; the recorded match is not reinforcement-learning self-play.

Run Pong & explore the model and training notes ↗

03 / Board history → a ten-move plan

Snake: close calls and escapes.

An encoder-decoder Transformer reads two recent 20×20 board matrices and generates ten moves: FORWARD, LEFT, or RIGHT, relative to the snake’s heading. It commits to the whole queue before reading the board again—even after eating food.

Edited highlights of actual Snake model play: a 20 by 20 board, food, the snake, and a ten-move action queue with the executing move highlighted, and numbered prediction circles on the board. Clips include edge pickups, tight escapes, and crashes.
The newer 5-minute-30-second extended cut: 28 scenes include 14 tight escapes, seven edge pickups, and seven endings. Numbered circles show pending predicted moves; black fades mark cuts. These are selected highlights from actual games. Open GIF (42.3 MB)
01 / Observe

Read the board history

Two numeric boards encode walls, body, food, and the head’s direction. The model does not receive future food locations.

02 / Plan

Rank allowed moves

A geometry mask and short search restrict candidate moves during generation. The Transformer ranks the allowed actions to form a ten-move queue.

03 / Execute

Follow the whole queue

Pending moves run without per-tick correction or early replanning. New food does not clear the plan; death ends the episode.

Trained from scratch by imitating a search-based teacher. The planner conservatively treats visible body cells as occupied for the entire plan. It can still enter body traps; the animation includes failures as well as escapes.

Run Snake & read the implementation notes ↗

04 / Text → pixels

A description becomes an image.

The colored stick-figure model reads English and generates a 48×48 image one palette pixel at a time. Compare the held-out target with two generated samples for each prompt.

Two held-out English pose prompts, each with a target colored stick figure and two generated samples. The samples show missing, disconnected, or misplaced limbs.
Left: target. Middle and right: generated samples. Recorded at update 4,000; these examples show errors in pose and limb connectivity.

Training images come from a renderer; inference predicts pixels directly. Held-out deep-bend poses with a raised left arm remain unreliable in the later model too.

Explore the image experiments ↗

05 / English → French

English → French

An encoder reads English subword tokens. A decoder attends to that representation and predicts French tokens one at a time. The repository walks through tokenization, masks, training, and common mistakes in this small educational translator.

16.65M parameters / trained from scratch

Choose an English sentence

Hello.

English input tokens

Hello · .

French model output

Bonjour.

Bonjour · . · EOS

Recorded translation from the local checkpoint.

Choose one of five recorded examples, then press Play or Step. This demo replays actual greedy decoding from the local checkpoint; it does not translate new text in the browser. ␠ means a space: ␠is reads as “ is”. EOS ends the sequence.

These examples are demonstrations, not a translation-quality evaluation. This small educational model can make mistakes.

Open the translation walkthrough ↗

Independent educational experiments supported by PseudoConscious Inc.