02 · Mixture of Experts
Committee or Competition
Two ways to combine several networks, and only one of them specialises.
The previous topic explained one architecture of interest which is a layer that holds a great deal of parameters and uses only a few of them on any given token. That wish is about compute, and it is how mixtures of experts are usually motivated today.
The interference problem
Nowlan and Hinton open with the difficulty in one sentence: if backpropagation is used to train a single network to perform different subtasks on different occasions, there will generally be strong interference effects which lead to slow learning and poor generalisation. Every weight is pulled by every case. Cases that need different behaviour pull in different directions, and what settles is a compromise that suits neither.
The proposal introduces a collection of distinct sub-networks, defined as the experts
The term "gating" here can be misleading, as it suggests a simple on/off switch when it is actually nothing of the sort. The gate is an ordinary neural network, usually a small multi-layer perceptron that takes the input, passes it through zero or more hidden layers, and ends in an output layer with exactly one unit per expert. In the original experiments, the gate sometimes had five or ten hidden units, and sometimes none at all, making it a single linear layer and nothing more.
The values sitting at those
Concretely, in the simplest case where the gate has no hidden layers, producing the scores is a single matrix multiplication:
is the input the gate is shown, of size . is the gate's weight matrix, with one row per expert. Row is a direction in input space, and is how far the input points along it. is the bias, one per expert.
A gate with several hidden layers
Number the layers
and the output layer, which produces the scores, is
with
The layer index is written in parentheses,
With hidden layers this is the last of several such steps, and nothing about the argument changes. What matters is that
To turn the scores into a routing decision we need them non-negative and summing to one, so they can be read as probabilities. That is exactly what the softmax function does:
The exponential makes every value positive and the denominator makes them sum to one, so the largest score becomes the largest share without any of them ever reaching zero. From the first paper onwards the
One piece of notation before we go further. A case is one training example which contains an input
Here a case is a whole training example, because that is what these networks were built to handle: one input, one target, one decision by the gate. From Compute You Can Skip onwards a case is a single token inside a sequence, and the gate makes its decision several times per example rather than once.
Two ways to combine them
Defining a multi-network architecture with a gate does not yet tell us how this mechanism should learn. Let's go through this learning process.
The committee
The standard ensemble approach is to blend the outputs via the gate and compute the error on the final prediction. Let
Look at what it does to an individual expert. The error is computed after the blend, so an expert receives gradient signals based on the committee's collective performance rather than their own. The expert is told whether the committee was right, and it is nudged by its share of that. If expert 2 is already good on this case and expert 1 is badly wrong, the loss still pulls expert 1 toward the same target, because the global loss
The competition
The alternative is to measure each expert on its own, and blend the measurements rather than the outputs. Treat each expert as predicting the mean of a Gaussian, treat the gate as supplying the mixing proportions, and take the negative log probability of the target under that mixture:
is the error on training case . is the gate's output for expert on the case . is the desired output and the output of expert . is a constant, the width of each Gaussian.
The outputs are vectors, as they are in the original paper. Since
The two expressions might look similar, but their behavior is fundamentally changed by swapping the order of operations. Instead of blending the predictions, this equation treats each expert's output as the center of its own Gaussian distribution. The inner term
By summing these independent probabilities before applying the logarithm, the loss evaluates the mixture as a whole without forcing the experts' outputs to average out. If even a single expert perfectly hits the target, the sum inside the logarithm becomes large, the overall loss drops, and the other experts are left alone rather than being dragged in to compensate. The figure below illustrates the process for each combination strategy.
It's important to highlight the gradient effect of the architectures above. The committee takes a weighted sum of outputs and then measures the error. The competition measures the error of each expert separately, takes a weighted sum of those probabilities, and then applies the logarithm. But why does this matter? Because the summation happens inside the logarithm which allows the gradients to decouple. If one expert is highly accurate, it dominates the sum, minimizing the loss for that specific case. The remaining experts aren't penalized or forced to adjust their weights to fix a residual gap. They are simply ignored for that case. This is somewhat a "true competition" in the sense that experts are rewarded for individual specialization, not for collective compromise, allowing each one of them to specialize.
Prior, posterior, and the gradient between them
The competition reading gives us a second quantity that the committee formulation does not have, before the target arrives, the gate's output
We can map this directly to our experts. The "prior"
Examples for scalar and vector outputs
The one-dimensional case. Consider a simplified one-dimensional scenario where the predictions and the target are just points on a line as the figure below shows. Before the target
which forms the exact gradient. The gate is heavily rewarded (+0.53) for the expert that was right, and penalized (-0.30, -0.23) for the two that were wrong.
The vector case. When
: The multi-dimensional space where the target and predictions exist, with representing the number of dimensions. : The covariance matrix ( ) is set to the identity matrix ( ). This is a way of stating that we treat every dimension equally and assume no correlation between them. : The likelihood function. Instead of measuring a simple scalar gap, it evaluates the probability based on spatial distance. : The multi-dimensional prediction vector generated by expert . : The Euclidean norm, representing the standard straight-line distance between the expert's prediction and the actual target.
Looking at the figure, the dashed lines represent the Euclidean distance between the expert predictions (
Log likelihood gradient
Before differentiating, we must define the likelihood of the entire training set under our mixture model, denoted as
This is exactly the objective function we defined earlier, just with the sign flipped and summed over the dataset. Maximizing
Where comes from, step by step
Let's work with a single case and drop the superscript
Write
Step 1. Differentiate the logarithm. To find the gradient with respect to
Step 2. Differentiate the softmax. Let the denominator be
Take the denominator first, because it behaves the same way whatever
so
The numerator is where we have the two cases.
Feeding those two into the quotient rule gives the two cases:
First: for the target unit (
Second: for any other unit (
Both are the same expression, written with the Kronecker delta
Step 3. Substitute and split the sum. Putting that back into step 1, the delta picks out the single term
Step 4. Recognise the marginal. The sum that is left is
and in the second term the
Step 5. Recognise Bayes. The first term is exactly the responsibility defined earlier, a prior times a likelihood over the marginal:
Substituting that back into step 4 closes the chain for a single case:
Restoring the case superscript and summing over the training set turns
It is worth seeing which step did the work. The
With the derivation complete, we can see that this is a clean learning rule. The gate trains to predict its own posterior, settling only when the prior and the posterior perfectly agree. The gradient arriving at the individual experts reveals the other half of the story. To understand this update, we differentiate the likelihood with respect to the expert's output prediction, denoted as
The familiar error term
Sparsity was never imposed
If we follow the learning dynamics to their fixed point, a clear pattern emerges. An expert that wins a case is trained on it and improves, raising its likelihood for that region of the input space. This increased likelihood raises its responsibility, which correspondingly raises the gate's prior. Consequently, after training, the gating network nearly always assigns a mixing proportion of one to a single expert per case.
Note that there's no enforcing of a sparse gate. There is no top-
While this allows a partitioned model to significantly outperform a single dense network on heterogeneous tasks, it completely fails to reduce computational cost. To compute the objective
The gate ends up nearly one-hot, but we still evaluate every expert anyway. Ultimately, this makes the mixture more expensive than the standard dense layer we started with. The specialization comes for free, but the computational savings do not. Translating this specialization into actual efficiency is the challenge of the next section.