04Classifiers and decoders
Hidden semi-Markov models (hsmmlearn)
An HMM in which each state chooses how long to last. The natural model for spells, and the expensive one.
- Sequence
- Classical
- Duration-aware
- GPL-3.0
- Modality
- Per-frame evidence plus a duration distribution per state
- Output
- Segments, each with a state and a length
- Evidence
- Yu's survey (Artificial Intelligence, 2010)
- Code and weights
- hsmmlearn reference library, archived in 2023
- Licence
- GPL-3.0
A first-order Markov chain has no memory of how long it has been in a state. Each frame it stays with a fixed probability, so spell lengths follow a geometric distribution and the most likely duration is always the shortest. Football does not look like that. A goal kick takes a typical time. A possession under a high press has a different length profile from one in settled build-up.
A hidden semi-Markov model makes duration explicit. On entering a state the model draws a length from that state’s own duration distribution, emits that many observations, then moves on. Inference is still dynamic programming, now over states and durations together, as laid out in Yu’s survey.
hsmmlearn is a compact reference implementation of the explicit-duration model. Its repository was archived in 2023.
Where it wins
- Spells are the unit of the model, as they are the unit of spell-based metrics.
- Duration knowledge enters as a distribution, not as a blunt minimum-length filter.
- Different states get different rhythms: dead balls long, contested possessions short.
- Inference remains exact.
What it costs
- Decoding cost grows with the longest duration considered. At 25 fps a 60-second stoppage is 1,500 frames of duration to search.
- Duration distributions must come from somewhere: labels or assumptions.
- A wrong prior is destructive. Penalise short spells too hard and real one-touch possessions vanish.
- The reference library is archived and GPL-3.0. In a permissively licensed project the algorithm is reimplemented, not imported.
How it plugs into possession
As the principled upgrade to a Viterbi decode when duration errors dominate. If a decoder’s mistakes are spells of implausible length, three-frame possessions or dead balls that end too early, a semi-Markov model treats the cause where post-hoc filters treat the symptom.
Much of the benefit is available more cheaply. Minimum-duration constraints and state-specific switching costs approximate duration structure inside an ordinary Viterbi pass, at a fraction of the cost.
Our read
The right model for spells in theory. In practice, exhaust switching costs first.