Connect 4 Probes
TL;DR
A model trained to predict legal moves in Connect uses a linear representation of each column's height; intervening on them causes the model to change its choices. Adding the END token makes the model store linear representations of the board state. Reposi.
Motivation
A while ago I read the Othello GPT p [1] and decided to reproduce it. The authors train a model to predict legal moves in Oth. They further probe its activations to see whether it has a representation of world models—in this case, the state of the board. Their results show that the model tracks the state of the board and uses it in its computation in a way that affects the accuracy.
Instead of conducting the experiment on Othello, I decided to play around with Connect 4. This choice was pretty arbitrary; I wanted to reproduce it on a game that is neither complex nor very primitive.
Setup
The game is standard Connect 4: 6×7 board; discs drop to the lowest empty cell; player who first gets 4 discs in a row (vertically, horizontally, diagonally) wins.
Data
The training dataset comprises uniformly random legal moves. There are 5,000,000 games, generated as 50 shards of 100,000 (seeds 0–49). The first 10,000 games are held out for validation and the rest (4,990,000) games are used for training. Games have 21.3 moves on average; 8 at minimum.
I generate 100,000 games for the probing dataset. I further prune the games that were present in the training dataset. 2.4% of them were pruned, so this leaves us with 97,600 games.
Each game is a sequence with length 44 and vocabulary of 10 tokens. The vocabulary consists of columns 0–6, BOS, END, and PAD. I have two slightly different variations for the sequence: the base sequence is written as BOS c1 c2 … PAD PAD; the end sequence is written the same but with END token after the last move. In both variations, PAD tokens are ignored in the loss function.
Model
We have two models that are trained on two different sequences. A base model, however, is the same: a standard GPT-style decoder with 8 layers, 8 heads, and 512-dimensional hidden space. The total size is 25.3M parameters, which is on par with the Othello-GPT's parameters. Both models are trained on a single NVIDIA L40S on Modal. Each model's top-predicted moves are legal in 100% of the validation games.
Probing
Base sequence
I'm probing the model trained on base sequences for column heights. Given that base sequences only need to predict legal moves, it is reasonable to assume that it does not need to store anything that requires prediction of a win. For instance, if the model sees a sequence BOS 0 0 0 0 0 0 0 …, it is clear at the position 7 that the first column is full, hence picking that column is not valid.
The probes are trained on 5,000 games which I split 80/20 by games, i.e 4,000 and 1,000 for training and validation, respectively. Training split has 90,525 training positions; validation split has 22,918 positions. I trained 9 probes on embeddings and activations after each of the blocks. Activations are standardized per layer using training set's mean and standard deviation.
Results
We can observe a disparency between the accuracy of full/empty and in-between heights. Although the accuracy of in-between heights at the first layer matches full/empty ones, it drops significantly after. Contrasted with full/empty height probes, it seems reasonable that it isn't a priority for the model to store the specifics of heights.
Interventions
I intervened at the BOS position by steering the direction of the target column towards the full height. Pushing it at 1:1 of the activations size drops the probability of the target column down to zero.
Then I've intervened at random but legal positions where the target column is still not full which yields a similar picture.
I also checked whether this direction holds in the opposite direction. I picked full columns and then added the opposite direction. The noteable thing here is that it requires a larger push compared to the interventions above.
End sequence
I probe both models for the board state, similar to the Othello paper. The accuracy of the probe is highest for the END sequence model when using the mine/theirs setup with the average of 83%. Interestingly, if we scope the accuracy to include only horizontal, vertical, and diagonal lines, then it rises up to 92%.