The margin the dynamic program already had
Assumes: A modulation and a borrowing are one number apart · A key-finder that keeps the order
A modulation and a borrowing are one number apart is the ninth rung of this ladder, and it ends by naming the thing every rung above it has thrown away.
Every rung of this ladder produces a single best reading, and the interesting passages in the repertoire are the ones where two readings are nearly equally good. The machinery for that already exists inside the model — a dynamic program that finds a best path has, by construction, the scores of every other path.
It does, and the reason is worth stating precisely because it is what makes this rung free. A Viterbi decoder over key-and-degree states computes, at every bar, the best score into every one of its states. Run the same recursion backwards and it also has the best score onward from every state. Adding the two gives the best complete path through any state at any bar — including the states the winning path did not use.
So the margin between the best reading and the best reading in some other key is not an extra computation. It has been sitting in the array since the eighth rung, unprinted.
What the number is, and what a bit means here
The model’s scores are log probabilities, so a difference of scores is a log ratio and dividing by the natural log of two puts it in bits. One bit means the runner-up reading is half as probable as the winner under the model; three bits means an eighth as probable.
That is a unit worth having because it is the same unit the tonal-expectation ladder now works in, and because it is interpretable without knowing anything about the model’s internals. A reading with a margin of four bits is a reading nobody would argue about. A reading with a margin of a tenth of a bit is the model saying either.
The threshold drawn is one bit, and it is a convention rather than a finding — there is no measurement of how large a margin has to be before a listener stops hearing two readings. What the figure can say is which bars are near the line, and it turns out to be a lot of them.
The passage built to be ambiguous
The strongest test of a margin is a passage constructed so that it should be small, and the progression ladder built one: a body of chords diatonic to C ended by a ii–V–I in G, which is a bag of notes saying one key and an ordered pair saying another.
Run the margin on it and every bar is inside a bit. The mean is seven tenths of a bit, and the weakest bar is at two hundredths — the model is very nearly indifferent between C and G for the whole eleven bars, and it says so.
That is exactly the behaviour a margin is for. The ninth rung’s reading of the same passage names one key with the same confidence it names a key in an unambiguous one, because a best path is a best path. The margin distinguishes the two cases without any change to the model.
A margin of exactly zero, and what it means
There is a third case and it produces a number that looks like a bug and is not.
A passage that alternates two keys symmetrically — four bars of I–IV–V–I in C, four of the same in G, repeated — has a margin of exactly zero at every bar. Not small: zero, to every digit the arithmetic carries.
The reason is a symmetry rather than a failure. The passage is invariant under transposing every chord by a fifth and swapping the blocks, so a reading in C and its transposition into G are the same path with the same score. The model is not undecided because the evidence is weak; it is undecided because the two hypotheses are indistinguishable by construction, and a model that reported a preference between them would be reporting an artefact of tie-breaking.
That is a useful thing for a margin to be able to say, and it is a class of case the ladder has met before without a way to name it. Two keys at once is about a passage a bag of notes cannot read; this is a passage a path cannot read, and the margin is what distinguishes “the model chose” from “the model tied”.
What a reading without a margin conceals
It is worth being blunt about what the nine rungs above this one have been doing, because the omission is a general one rather than a slip.
Every key-finding figure in this collection prints a key per bar. A reader looking at one has no way to tell a bar the model is certain about from a bar it flipped a coin on, and the two look identical — a coloured cell with a letter in it. That is not a small presentational matter: the whole of the ladder’s argument about modulation is an argument about where a reading changes, and a reading that changes at a bar where the margin was already at a hundredth of a bit has not changed its mind, it has drifted.
The same criticism applies to the ninth rung’s own headline. It found the key-change cost at which a modulation reading flips to a borrowing reading, which is a real and interesting sweep — and the margin says that in the neighbourhood of the flip both readings are within a fraction of a bit of each other for many bars either side, so the flip is a boundary in a flat landscape rather than a ridge.
That does not undo the finding. It qualifies it in the direction the finding itself was pointing: the ninth rung’s whole point is that a modulation and a set of borrowings are one number apart, and the margin says how thin the ground under that number is.
Where the margin is largest
The wide margins are as informative as the narrow ones and they fall somewhere specific.
A bar is read confidently when its chord is diatonic to one key and awkward in every other, and when its neighbours agree. In practice that means bars with the rarer degrees in them: a leading-note triad or a chord containing a raised note pins a key far harder than a tonic does, because a tonic triad is diatonic to three keys and a dominant seventh to one.
So the margin is a measure of how much work each bar is doing, and it is largest on chords that a listener would also name as the ones that establish the key. That is a piece of agreement between the model and ordinary analysis which the reading alone cannot express, because the reading names the same key on the informative bars and the uninformative ones.
Which computation produced the numbers
The model is sequenceKeyReading’s own: twelve keys times seven degrees — eighty-four states, which is what the eighth rung built and what 7,056 transitions is the square of — with transitions weighted by the root-motion table and a fixed cost for changing key, and emissions the overlap between the observed chord and each degree’s triad.
The margin adds a backward pass. The forward array holds the best score into every state at every bar, including that bar’s emission; the backward array holds the best score onward from every state, excluding it. Their sum is the best complete path through that state. Taking the maximum over the seven degrees of a key gives the best path through that key at that bar, and the gap between the top two keys is the margin.
The cost is one more pass of the same size as the first, so the whole apparatus is twice the work of the reading it annotates. Nothing is approximated: these are exact best-path scores, not samples or bounds.
The key-change cost is the ninth rung’s own free parameter and it is the thing the margins are most sensitive to. A larger cost makes the model reluctant to modulate, which widens every margin; a smaller one narrows them all. That rung swept it and found where the reading flips between a modulation and a set of borrowings, and the same sweep would move every number here.
A margin is not a probability
There is a temptation to read these bits as a posterior and it should be resisted, because the arithmetic is a maximum rather than a sum.
The margin compares the best path through one key with the best path through another. A proper posterior over keys would sum over all paths through each — which is a different recursion, the same size, and gives a different and generally smaller separation, because a key with many nearly-good readings accumulates probability that its single best path does not show.
The distinction matters most exactly where the margins are small. A bar whose best C reading beats its best G reading by a tenth of a bit might have a hundred nearly-equal G readings and one C reading, in which case a summed posterior would prefer G. Nothing here would notice.
Both recursions are available and this collection has only ever written the maximising one, in every model it has — the boundary detector, the key-finder, the segmenter. That is a habit rather than a decision, and it is the sort of habit worth naming: a best answer is easier to draw than a distribution, and a collection that draws its results will drift toward models that have a best answer.
The summed version, run
Replacing the two maxima with log-sum-exp is one operator in each pass and changes nothing else — same emissions, same root-motion weights, same key cost — so the prediction three paragraphs above is checkable rather than rhetorical. It is right, and it is right by more than it claimed.
| passage | best-path margin | summed margin | bars where the two name a different key |
|---|---|---|---|
| thirty-two-bar song | 1.14 bits mean, 13 of 32 under a bit | 0.19, all 32 under a bit | 8 |
| the constructed conflict | 0.70 mean, weakest 0.016 | 0.020 mean | 5 of 11 |
| the alternation | exactly 0 at every bar | 0.05 mean | 8 of 16 |
The separation collapses, as predicted: a factor of six on the song and a factor of thirty-five on the constructed conflict, and every bar of every passage falls inside a bit. So the thirteen ambiguous bars the hero figure marks are thirty-two once the rivals are counted rather than out-argued.
And the different key does win, often. A quarter of the song’s bars and nearly half the conflict’s are named differently by the two recursions — the case the paragraph above describes as something nothing here would notice is not a corner, it is the normal state of a passage this model reads.
One thing the prediction did not reach is worth more than either. The winner’s posterior probability never exceeds 17.7 per cent, on any bar of any of the three passages, against 8.3 for a blind guess among twelve. The model’s actual belief in the key it names is about twice chance everywhere, and it is that flat on the thirty-two-bar song as much as on the passage built to confuse it. Four bits of best-path margin looked like certainty and was a statement about one path.
The zero also has to be re-read. The alternation’s exact tie is a tie between best paths; summed, the two keys separate slightly and the reading flips at half the bars, because the number of nearly-good paths through each key is not the same even where the best ones match exactly. The symmetry the earlier section names is a symmetry of the maximum, not of the model.
None of this makes the max-product margin wrong, and it is worth being precise about what it is instead. It answers the question how much better is the best reading in this key than the best reading in any other, which is a real question and the one an analyst asks when comparing two written-out analyses. The summed margin answers how much of the model’s belief sits in this key, which is the question a reader assumes is being answered when a figure prints a key with a number beside it. Two questions, one figure, and the ladder has been drawing the first while its prose has been claiming the second.
Where the model stops
A margin is a property of the model, not of the music. Everything above says how confident this decoder is, and its confidence is manufactured out of an ordinal root-motion table, an overlap emission and one asserted cost. A different decoder would give different margins on the same passage and neither would be wrong.
The alphabet is diatonic triads. A passage with a secondary dominant in it has a chord the model can only match partially in any key, so its margin is small everywhere for a reason that has nothing to do with ambiguity.
Nothing here knows about a bar’s weight. A margin is computed per bar and every bar counts the same, when where a chord falls in the metre is most of what decides how much it establishes.
And the margin is over keys, not over readings. Two readings that name the same key at every bar but different degrees — a passage read as I–vi–IV–V or as III–i–VI–VII in the relative minor — do not appear as a margin at all, because the maximum is taken over degrees before the keys are compared. That is a deliberate choice and it hides a real ambiguity: the relative major and minor share a scale, and parallel and relative are two different maps is the essay about how differently they behave.
What the picture cannot show
It cannot show a listener’s uncertainty. A margin in bits is a statement about a decoder’s posterior, and there is no measurement here connecting it to what a listener experiences. How much evidence a modulation needs is the ladder’s own attempt at the listener’s side, and it is measured in chords rather than in bits.
Nor can it show which rival. The figure reports the gap to the best rival and names it, and a bar with three near-equal readings looks the same as one with two. The full distribution over the twelve is computed and one number is printed.
And it cannot show where the ambiguity is resolved. A margin is a property of a bar given the whole passage, because it uses the backward pass — so a bar early in a passage is annotated with evidence that arrives later, which is not what a listener has. A causal margin, using only the forward pass, is a different and equally computable quantity, and the two would differ exactly where the resolution happens.
Whose music, and when
The thirty-two-bar song is a twentieth-century popular form and the scheme this collection carries is a standard one. Its margins are wide through the A sections and narrow at the bridge, which is where the harmony moves — and that is the model agreeing with an analysis nobody would dispute.
The constructed conflict is a common-practice cliché: a passage that sits in a key and ends on a cadence in the dominant is what the first half of nearly every binary form does. Its margin is small everywhere, and it should be: the ambiguity between modulated to the dominant and ended on the dominant is not a defect of a model, it is the thing the form is made of, and a reading printed without a margin conceals that the question was ever open.
Where this ladder goes next
Ten rungs. Keys are neighbours and the map is computed; the key plan is the form; three distance measures disagree; a modulation takes a measurable number of chords; the circle is a circle and the map is not; two keys at once; two keys in alternation; a model that keeps the order; the number that decides which reading it gives; and now what the reading is worth.
What is owed after this is the causal version. Every margin above uses the whole passage, forward and backward, which is a reading a listener cannot have — and the difference between the two-sided margin and the forward-only one is precisely how much of a bar’s certainty comes from what has not happened yet. Both passes exist; subtracting them is one line; and the quantity that comes out is the size of the retrospective element in tonal hearing, which this ladder has assumed at every rung and never measured.
Part 10 of 21
One essay in the series on Key-relations. The essays either side of this one:
What links here
Essays that reach for this one mid-argument — the half of a link its own author cannot write down, the 8 sharing most with it of 9.
What this makes readable
Essays that declare this one a prerequisite.
The objects named here
The third way in, after the field and the series: the things themselves, and every essay that touches each one.
AmbiguityInformationKey colourKey-findingModulationProgressionSegmentationTonal function
- A count and a correlation key-finding, progression, segmentation
- A fourth decision, and two that were never made key-finding, progression, segmentation
- The alternation a key-finder cannot follow ambiguity, key-finding, modulation
- The cadence as evidence key-finding, progression, tonal function
- The ceiling is thirteen bars with names key-finding, modulation, tonal function
- Three decisions that constrain each other ambiguity, key-finding, segmentation