Search

Search papers and lessons

Permutation Invariant Training

Level 4 · 12 min read

Permutation invariant training scores every way of matching a network's outputs to the true sources and keeps the best match, so a network can separate voices without being told which output is which speaker.

On this page

  • Colour = topic mix
  • Discrete math
  • Calculus
  • Probability
  • Losses & regularization
  • Sign in to see your progress

TL;DR

Permutation invariant training, or PIT, is a loss for models that output several sources at once, such as the voices in a recording of several people talking. The network has no built-in idea of which output slot should hold which speaker, so PIT compares every way of matching slots to the true sources and keeps the best one. The result is a loss that does not care about the order of the outputs.

Where you'll see it: in speech separation systems that split a mixed recording into one track per speaker, in models that track several moving objects, and in later separation networks such as Conv-TasNet.

Intuition

A panel with two chairs

Picture a radio panel with two guests and a host who records both answers. Afterwards you have two recordings, but nobody labelled which chair each guest sat in. To grade the host's separation, you must first decide which recording belongs to which guest. The natural rule is to try both seatings, measure how close each one is to the truth, and keep the seating that fits best.

A neural network that separates voices has the same problem. Its outputs are slots, and at the start of training slot 1 has no reason to hold speaker A rather than speaker B. If the loss simply compares slot 1 with speaker A's true voice, the network is told to do the wrong thing whenever its slots are assigned the other way round. The training signal becomes noise.

PIT removes the problem by letting the loss choose the matching itself. It asks: which assignment of outputs to sources makes the total error smallest? Then it trains the network to reduce that error.

flowchart LR
  A[Mixture of voices] --> B[Network]
  B --> C[Output slots 1 to S]
  C --> D[Try every matching of slots to true sources]
  D --> E[Keep the matching with the smallest total error]
  E --> F[Train on that error]

Using the mixture's spectrogram as input is common, so the network sees the sound as a picture of frequencies over time. The matching logic is independent of that choice. It only needs a per-source error.

The math

The ambiguity

Let there be SS sources, with true signals y1,…,ySy_1, \dots, y_S, and let the network produce estimates y^1,…,y^S\hat{y}_1, \dots, \hat{y}_S. Nothing in the network ties slot ss to a particular source. If the training loss is written as ∑sL(y^s,ys)\sum_s L(\hat{y}_s, y_s), it fixes one matching in advance. Any run that happens to put speaker B in slot 1 is penalised for doing the right thing. The matching the network learns is therefore arbitrary, and it can change between examples.

The permutation-invariant loss

Let P\mathcal{P} be the set of all permutations of {1,…,S}\{1, \dots, S\}, and let LL be a loss for one source, such as the Mean Squared Error between two signals. PIT defines

J=min⁡π∈P∑s=1SL(y^π(s), ys).J = \min_{\pi \in \mathcal{P}} \sum_{s=1}^{S} L\big(\hat{y}_{\pi(s)},\, y_s\big).

Here π\pi is one permutation, a rule that sends target ss to output slot π(s)\pi(s). The inner sum is the total error for that matching, and the minimum picks the matching with the smallest total. Because the minimum runs over all orderings of the outputs, the value of JJ does not change when the outputs are reordered. That is the sense in which the loss is permutation invariant.

Utterance-level versus frame-level

A recording is a sequence of frames t=1,…,Tt = 1, \dots, T. The simplest version chooses the best matching separately in each frame:

Jframe=∑tmin⁡π∑sL(y^π(s)(t), ys(t)).J_{\text{frame}} = \sum_{t} \min_{\pi} \sum_{s} L\big(\hat{y}_{\pi(s)}(t),\, y_s(t)\big).

This is cheap and it always gives the lowest total error. It fails for speech. A frame-level choice can match output 1 to speaker A in one frame and to speaker B in the next, so the separated tracks swap speakers in the middle of a sentence. The utterance-level version uses one matching for the whole recording:

Jutt=min⁡π∑t∑sL(y^π(s)(t), ys(t)).J_{\text{utt}} = \min_{\pi} \sum_{t} \sum_{s} L\big(\hat{y}_{\pi(s)}(t),\, y_s(t)\big).

The matching is decided once per utterance, so each output track keeps one speaker. This is the form that makes separation usable.

Gradients

A minimum over a finite set is locally one of its branches. Once the best matching π⋆\pi^\star is found, the gradient flows only through the outputs in π⋆\pi^\star:

∂J∂y^π⋆(s)=∂L(y^π⋆(s),ys)∂y^π⋆(s).\frac{\partial J}{\partial \hat{y}_{\pi^\star(s)}} = \frac{\partial L\big(\hat{y}_{\pi^\star(s)}, y_s\big)}{\partial \hat{y}_{\pi^\star(s)}}.

The other matchings do not contribute to the update. Ordinary Stochastic Gradient Descent with Backpropagation therefore trains the network without any change to the optimiser.

How many matchings

There are S!S! permutations (see Counting Principles), which grows fast:

Sources SSPermutations S!S!
22
36
424
5120
103,628,800

For the two- and three-speaker cases that are common in practice, trying every matching is cheap. It is not cheap for large SS, and the tradeoffs section returns to this.

Worked examples

Example
Tiny: two numbers, two matchings

Two sources have true values (y1,y2)=(2,1)(y_1, y_2) = (2, 1). The network outputs (y^1,y^2)=(0.9,2.1)(\hat{y}_1, \hat{y}_2) = (0.9, 2.1). Use squared error for LL.

  1. Identity matching (π\pi sends source 1 to slot 1 and source 2 to slot 2): (0.9−2)2+(2.1−1)2=1.21+1.21=2.42(0.9 - 2)^2 + (2.1 - 1)^2 = 1.21 + 1.21 = 2.42.
  2. Swapped matching (source 1 to slot 2, source 2 to slot 1): (0.9−1)2+(2.1−2)2=0.01+0.01=0.02(0.9 - 1)^2 + (2.1 - 2)^2 = 0.01 + 0.01 = 0.02.
  3. The minimum is 0.020.02, from the swapped matching. The loss is J=0.02J = 0.02.
  4. The gradient flows only through the swapped pairs. Slot 1 is pushed toward 1, and slot 2 toward 2.

Interpretation: the network did separate the two values correctly, but in the opposite order. A fixed loss would have punished it with 2.42. PIT scores it at 0.02, which is what a correct separation deserves.

Example
Standard: frame-level versus utterance-level matching

A two-speaker recording has three frames. The total error for each matching in each frame is:

FrameIdentitySwapped
10.50.9
20.80.3
30.40.6
  1. Frame-level PIT takes the best matching in each frame: frame 1 gives 0.5 (identity), frame 2 gives 0.3 (swapped), frame 3 gives 0.4 (identity). The total is 0.5+0.3+0.4=1.20.5 + 0.3 + 0.4 = 1.2.
  2. Utterance-level PIT sums each matching across frames first. Identity gives 0.5+0.8+0.4=1.70.5 + 0.8 + 0.4 = 1.7 and swapped gives 0.9+0.3+0.6=1.80.9 + 0.3 + 0.6 = 1.8. The minimum is 1.7, from identity.
  3. The frame-level total, 1.2, is lower, but it is not a consistent answer. It would train output 1 to hold speaker A in frames 1 and 3 and speaker B in frame 2.
  4. The utterance-level total, 1.7, is higher but consistent. Output 1 holds one speaker throughout.

Interpretation: the frame-level loss looks better because it is allowed to cheat. Each frame reaches its own best score by changing who each output represents, and the separated tracks become unusable. Utterance-level PIT gives up a little error to keep the tracks coherent.

Example
Standard: counting the matchings for four sources

Take four sources, so S=4S = 4.

  1. The number of matchings is 4!=4×3×2×1=244! = 4 \times 3 \times 2 \times 1 = 24.
  2. For utterance-level PIT, each matching needs a total error summed over all the frames and all four sources. That is 24 totals to compare, each a sum of 4 per-source errors per frame.
  3. Each total is a sum of 4T4T terms for an utterance of TT frames, so one minimum costs about 24⋅4T24 \cdot 4T term evaluations.
  4. Doubling the number of sources from 2 to 4 multiplies the matchings from 2 to 24, a factor of 12, while the number of sources only doubled.

Interpretation: the cost grows like S!S! rather than SS. This is manageable for a few speakers and becomes the main constraint as SS grows.

Example
Realistic: a three-speaker meeting segment

A segment of a meeting has three speakers, so there are 3!=63! = 6 matchings. Suppose the summed utterance-level errors, in arbitrary units, for the six matchings are:

Matching (output slots for speakers A, B, C)Summed error
(1, 2, 3)4.2
(1, 3, 2)3.9
(2, 1, 3)5.0
(2, 3, 1)4.6
(3, 1, 2)4.4
(3, 2, 1)4.1
  1. The minimum is 3.9, from the matching (1, 3, 2). The loss for the segment is J=3.9J = 3.9.
  2. Slot 1 is trained against speaker A, slot 3 against speaker B and slot 2 against speaker C. The gradient flows through those three pairs only.
  3. The segment is the unit of decision. Every frame of the segment uses the same matching, so slot 1 keeps speaker A from the first second to the last.

The numbers are illustrative, not measured. Interpretation: the winning matching is not the identity, and nothing in the network had to be told that. The loss found it, and the same procedure works on every segment in the training set.

Tradeoffs and failure modes

PIT is simple and general, and it works with any network that outputs one estimate per source. The costs come from the matching step itself.

SituationWhat goes wrongBetter choice
Frame-level matching on speechOutput tracks swap speakers mid-utteranceUtterance-level PIT, one matching per recording
Many sourcesS!S! matchings are too many to enumerateHungarian matching on the S×SS \times S matrix of pairwise errors (see the Hungarian algorithm below)
Fewer sources in some recordings than in othersA fixed SS forces the missing sources to be padded with silencePad with silent targets, or use a count-aware matching
Evaluation with fixed output orderA good separation looks bad because the tracks are labelled in the wrong orderScore the estimates under their best matching, as in training
Speakers at very different levelsUnnormalised squared error lets the loud source dominate the matchingA scale-invariant per-source loss such as the negative SI-SNR

The Hungarian algorithm gives a useful shortcut. Build an S×SS \times S matrix whose entry (i,s)(i, s) is the error of output ii against source ss, summed over frames for the utterance-level case. The minimum over matchings of ∑sCπ(s),s\sum_s C_{\pi(s), s} is exactly the assignment problem, and the Hungarian algorithm solves it in time that grows as S3S^3 rather than S!S!. It returns the same minimum as PIT, so this is a faster route to the same loss, not an approximation. Detection transformers use the same idea to match predicted boxes to ground-truth objects.

PIT also cannot tell the network which outputs should be silent when a source is absent, and it does not impose any order across time. Both gaps are usually closed by the design around the loss rather than by the loss itself.

History

Before deep learning, separating a mixture of voices was usually done with signal-processing assumptions, such as the sources being statistically independent. Those methods worked for a few clean cases and failed when voices overlapped or when the recording had noise. The problem that people now call the cocktail party problem, picking one voice out of many at a party, was a central example.

Supervised approaches using neural networks made progress in 2016. Deep clustering assigned each time-frequency point an embedding, and then grouped the points into speakers with a clustering step. That avoided the output-order problem, but it needed a separate clustering stage and was awkward to train end to end.

In 2017 Dong Yu, Morten Kolbæk, Zheng-Hua Tan and Jesper Jensen introduced permutation invariant training. It removed the clustering step by letting the loss pick the matching. Kolbæk and colleagues then described the utterance-level form, which fixed the speaker-switching problem and made speaker-independent separation work for recordings of two speakers. Later systems such as Conv-TasNet built on this objective.

PIT caught on because it solved the ambiguity with a few lines of code. It needed no hand-designed matching, no extra stage and no change to the training procedure, and it turned a problem that looked like it needed structure into one that standard gradient descent could solve.

Recap

A model that outputs several sources has no fixed order for its outputs, so a loss that compares slot ss with source ss gives a random training signal. PIT takes the minimum of the total error over all matchings, J=min⁡π∑sL(y^π(s),ys)J = \min_{\pi} \sum_s L(\hat{y}_{\pi(s)}, y_s), which makes the loss invariant to output order. Matching once per utterance keeps each track on one speaker. The cost grows as S!S!, which the Hungarian algorithm reduces to a cubic-time assignment with the same minimum. The objective is the basis of later separation systems such as Conv-TasNet.

Check yourself

QuestionRecall: what ambiguity does permutation invariant training remove, and how?Show answer

The outputs of a multi-source network have no fixed correspondence to the true sources, so a loss that matches slot ss to source ss penalises correct separations in the wrong order. PIT removes the ambiguity by taking the minimum of the total error over all matchings of outputs to sources, so the loss scores each separation by its best matching.

QuestionComputation: how many matchings does PIT compare for four sources, and how many summed error totals does utterance-level PIT compare for one utterance?Show answer

There are 4!=244! = 24 matchings. Utterance-level PIT sums the error of each matching across all frames, so it compares 24 totals, one per matching. The number of totals does not depend on the number of frames; the frames are summed inside each total.

QuestionWhy: why can frame-level matching give a lower loss yet produce unusable separated tracks?Show answer

Each frame picks its own best matching, so the output slots can swap speakers from one frame to the next. The loss is lower because every frame gets its best score, but the output tracks no longer each contain one speaker. Utterance-level matching forces one consistent assignment for the whole recording, which costs a little in loss and keeps the tracks coherent.

QuestionApplied: you want to separate eight sources. What is the difference between enumerating matchings and using the Hungarian algorithm, and which would you use?Show answer

Enumerating matchings means checking 8!=40,3208! = 40{,}320 permutations, each a sum of eight terms. The Hungarian algorithm works on the 8×88 \times 8 matrix of pairwise summed errors and returns the minimum over the same matchings in time that grows as the cube of the number of sources. Because the two give the same minimum for a loss that sums per-source errors, I would use the Hungarian algorithm, and I would check that the per-source loss is a sum over sources so the equivalence holds.

Sources