Loading schedule…
Loading schedule…
DiamondAI treats a game like a language. It reads the sequence of pitches and the surrounding context — count, base state, the pitcher–batter matchup, the score — and at every pitch outputs probabilities for what happens next: the pitch type, how the at-bat ends, and a live win probability. Below is exactly how it’s built, trained, and served — with honest, held-out numbers.
From a single read of the game so far, four small prediction “heads” branch off the same shared representation. They share everything the model has learned, then each answers its own question as a probability distribution.
Four-seam, sinker, cutter, slider, curve, off-speed, other.
Ball, called / swinging strike, foul, in-play, or HBP.
How the plate appearance ends — K, BB, single … HR, out.
A calibrated win chance, re-read after every single pitch.
The number on each head is how many buckets it chooses between · “P” = a single probability
It’s a decoder-only causal Transformer— the same family as a language model, but the “words” are pitches. Causal masking means each position can only see the pitches that came before it, so prediction is always honest about what was actually known at the time.
Every pitch becomes one vector: the model sums a learned embedding for each categorical field, adds a learned embedding for the specific pitcher and batter (6,208 players), and a positional embedding so it knows where in the game it is. Pre-LayerNorm blocks of attention + MLP refine that sequence; four linear heads read off the result.
The training data is a decade of MLB Statcast — pulled via pybaseball, seasons 2015–2024. Each game is sorted into true chronological order and every pitch is mapped onto a frozen vocabulary: once the buckets are locked, their ids never change, so cached sequences and checkpoints stay valid.
A pitch token is built from the things that actually shape the next one — the count, outs, base runners, strike-zone location, handedness, score difference, inning, and the two player ids. The train/validation split is deterministic by hashed game_pk, and the exact same function is reused at eval time, so the held-out set is precisely the games training never saw.
Training runs on a free Kaggle TPU v5e-8, data-parallel across all 8 cores: the batch is sharded, params are replicated, and gradients are averaged each step. AdamW with a warmup-then-cosine schedule, gradient clipping, Orbax checkpoints, and early stopping on validation loss.
The first serious run overfit — and that’s worth telling honestly, because the fix is why the model generalizes.
On 3 seasons with light dropout, validation loss diverged upward while training loss kept falling — too little data for the capacity, and a win-prob head easy to memorize game-by-game.
Validation tracked training with no divergence and auto-stopped at its minimum — best step 6000. That checkpoint produces every number on this page.
Plus early stopping (patience 5) on validation loss
As a systems-ML piece, attention is also written from scratch as a FlashAttention-style fused kernel in Pallas, JAX’s low-level TPU language. It streams keys and values in blocks with an online softmax, so the full pitch-by-pitch score matrix is never materialized. It’s checked for numerical correctness against a plain-JAX reference across 16 shapes, then its block sizes are autotuned.
Benchmarked against XLA’s own compiled attention on the TPU, it wins exactly where FlashAttention is supposed to — long context — and the lead grows with sequence length.
Honest caveat:the kernel is a standalone artifact — it isn’t wired into this model’s training, whose 256-pitch context is the short regime where XLA already wins. It’s shown as a TPU-kernel capability, validated and benchmarked honestly, not a speedup this model enjoys.
B = 4 · H = 8 · D = 64 · autotuned block sizes
Measured on the 1,225 held-out games training never saw, against a most-frequent-class baseline for each head. Where the model gains accuracy, its cross-entropy beats the baseline too.
Next-pitch type is the clearest signal— and the count alone doesn’t explain it: a count-aware baseline still sits at 33.6%, so the 17-point gain comes from the pitch sequence, the specific players, and zone history. Next-pitch outcome is intentionally modest— whether a pitch is a ball, strike, or foul is close to irreducible, and a ~2-point edge is about all that’s really there.
The win head’s raw 77.7% accuracy is flattering — it’s scored every pitch, so late-game positions where the result is nearly settled inflate it. The honest signal is calibration: across the whole probability range, an Expected Calibration Error of 0.072 means a predicted 70% really does win about 70% of the time.

On this site the model is real, not a stub. A FastAPI server loads the step-6000 checkpoint, pulls a game’s live feed from the MLB Stats API, and encodes each live pitch through the same frozen vocabulary used in training. One causal forward pass returns the next-pitch and win-probability predictions you see, cached briefly per game.
Live next-pitch-type accuracy runs around 48–56%— a touch under the 50.6% held-out figure, exactly as expected: 2026 rosters drift from the 2015–2024 training window, so more current players fall back to a generic “unknown player” embedding.
The free inference host sleeps when idle. During a cold start, the site cleanly falls back to a clearly labeled mock predictor— never a broken screen — and a badge appears bottom-left so you always know whether you’re seeing the trained model or the stub.
DiamondAI is built to capture the conditional structure of baseball: given everything that’s happened, what tends to happen next. It is deliberately not trying to beat sportsbooks — it never sees injuries, lineups, weather, or line movement. The win-probability head is here as a clean calibration target and a natural game-state readout, not as a market price.