Interactive visualizer for predictions in Hidden Markov Models.
Given a generative process defined by observable operator matrices T[observation, prev_state, next_state], we sample trajectories (with initial distribution initial). From the emitted observation of a trajectory:
- For each state
$S$ we compute the probability "Given the observations, how likely is it that I am currently in state$S$ ?", and - For each observation
$\omega$ we compute "Given the observations so far, what is the probability that the next observation will be$\omega$ ?".
These are then plotted in
Consider the Mess3 process:
In state
We write these probabilities as a tensor: Given we are currently in state state, the probability of transitioning to next_state while emitting observation obs is T[obs, state, next_state]:
T = [
[
[0.48, 0.02, 0.02], // Transition-matrix T[state, next_state]
[0.06, 0.16, 0.02], // for observation o_0
[0.06, 0.02, 0.16],
],
[
[0.16, 0.06, 0.02], // Transition-matrix T[state, next_state]
[0.02, 0.48, 0.02], // for observation o_1
[0.02, 0.06, 0.16],
],
[
[0.16, 0.02, 0.06], // Transition-matrix T[state, next_state]
[0.02, 0.16, 0.06], // for observation o_2
[0.02, 0.02, 0.48],
],
];For example, when we are in state
When the initial distribution is set to uniform (i.e. the states
If the matrices do not sum to row-stochastic-matrices, the code still functions (mostly) fine, as prediction is (mostly) just matrix multiplication. This is a Generalised Hidden Markov Model. The status badge at the bottom right shows you how ill-posed your T is.
Visualising these processes was part of the Iliad Intensive, and I decided to expand on it, add interactive sliders and a code editor, put it in a browser, and make it 3d.
These visualisations can actually be found within the residual stream of transformers trained on the Mess3 process, which sheds some light on how transformers learn. See this post for an excellent introduction that goes into far more detail than this readme, or the associated paper: Adam S. Shai, Sarah E. Marzen, Lucas Teixeira, Alexander Gietelink Oldenziel, & Paul M. Riechers. (2025). Transformers represent belief state geometry in their residual stream.
