c4-33m

A tiny language model whose only language is Connect Four. 33M parameters.

Play it in your browser: https://c4-33m.pages.dev/play

Strong Connect Four players who played it called it "not perfect but very strong" and "a decent second player".

Model

  • Transformer with Granite-4-style blocks: 14 layers, width 512, 8 attention heads (4 KV heads), SwiGLU MLP, RMSNorm, RoPE
  • About 33M parameters, 128-token vocabulary, trained from random initialisation
  • This file: onepass-fp16.onnx (67 MB, fp16 weights)

Training

  • Data: about 3.5M Connect Four positions from c4_v2 and additional positions, mirrored copies included, every label from an exact solver.
  • Schedule: 13,636 steps at batch size 1024 (about 14M training sequences, roughly 2 passes over the data), Muon optimizer, learning rate 2e-3.

How to use

Input board: int64 [B, 50] β€” BOS (0), then the 6 rows from the bottom up, each as 7 cells (1 empty, 2 X, 3 O) followed by a separator (11), then the side to move (2 for X, 3 for O). X moves first.

Outputs:

  • wdl: float32 [B, 7, 3] β€” loss, draw, win for the side to move, for columns A–G (ignore full columns)
  • cells: float32 [B, 42] β€” policy over cells, index 7 * row + column, row 0 at the bottom; a column's move is the lowest empty cell in it

A simple way to pick a move: the legal column with the highest win βˆ’ loss.

import numpy as np, onnxruntime as ort

def board_tokens(moves):                      # moves: columns 0-6, e.g. "3324"
    grid = [[1] * 7 for _ in range(6)]
    heights = [0] * 7
    for i, ch in enumerate(moves):
        c = int(ch); grid[heights[c]][c] = 2 + i % 2; heights[c] += 1
    ids = [0]
    for row in grid:
        ids += row + [11]
    return ids + [2 + len(moves) % 2], heights

s = ort.InferenceSession("onepass-fp16.onnx")
ids, heights = board_tokens("3324")
wdl, cells = s.run(None, {"board": np.array([ids], dtype=np.int64)})
legal = [c for c in range(7) if heights[c] < 6]
best = max(legal, key=lambda c: wdl[0, c, 2] - wdl[0, c, 0])
print("play column", best + 1)

Limitations

  • Not a solver: it still makes mistakes, mostly in positions decided only at the very end of the game (draws, close results) and in some openings.
  • Stronger with a little search on top.

License

MIT

Downloads last month

-

Downloads are not tracked for this model. How to track
Inference Providers NEW
This model isn't deployed by any Inference Provider. πŸ™‹ Ask for provider support