Gating Networks › Routing Score Computation
Language AI HandbookAll chapters Gating Networks › Routing Score ComputationOne section · Sections in this chapter3 / 11 ↓
Reading tools Definitions & inline links
Choose your expertise level to adjust how many terms are explained. Beginners see more tooltips, experts see fewer to maintain reading flow. Hover over underlined terms for instant definitions.
Article links
Make inline references clickable
Raw routing logits from the linear projection must be converted into routing weights that determine how much each expert contributes to the output. The logits can be any real number, positive or negative, and they don't have any inherent probabilistic meaning. This transformation from arbitrary scores to real weights happens through a softmax function, creating a probability distribution over experts that we can interpret and use.
Softmax Gating
The softmax function is the standard tool for converting a vector of arbitrary real numbers into a probability distribution. In the context of routing, it turns our expert logits into normalized routing weights:
where:
- : the probability of selecting expert for input
- : the raw routing score (logit) for expert
- : the exponential function applied to the logit, so the value is positive
- : the sum of exponentials across all experts, serving as the normalizing constant
Let's see what this formula does. The exponential function serves two purposes: first, it ensures all values are positive (since probabilities cannot be negative); second, it amplifies differences between logits. If one expert has a logit of 3 and another has 1, the exponential makes the first about times larger, not just 2 points higher. This amplification makes the router's preferences more decisive.
The denominator is a normalizing constant. This keeps all probabilities sum to exactly 1. This normalization is needed because we want the routing weights to stand for a proper probability distribution.


These routing probabilities stand for the router's "confidence" that expert is appropriate for input . Higher probabilities indicate stronger preference, and we can compare probabilities across experts to understand the router's relative confidence in each option.
In a soft MoE (which we introduced conceptually in the sparse models chapter), the final output would be a weighted combination of all expert outputs:
where:
- : the combined output of the MoE layer
- : the routing probability for expert
- : the output computed by expert for input
However, this soft combination requires computing all expert outputs, which defeats the purpose of sparsity. If we must run every expert for every token, we gain no computational savings from having multiple specialized experts rather than one large one.
Hard Routing with Top-K Selection
Practical MoE systems use hard routing to obtain the computational benefits of sparsity: only the top- experts (by routing probability) are computed. The next chapter covers Top-K routing in detail, but the basic idea is needed to understand how the router functions in practice.
The process works in four steps:
- Compute all routing probabilities via softmax
- Select the highest-scoring experts
- Renormalize selected probabilities to sum to 1
- Compute only those experts
For example, with 8 experts and , only 2 experts run per token. This gives roughly 75% computational savings in the expert portion of the layer. The routing weights for selected experts become:
where:
- : the renormalized weight for selected expert
- : the original softmax probability for expert
- : the set of indices corresponding to the experts with highest scores
- : the sum of probabilities for the selected experts, used as a normalizing constant
This renormalization ensures the weighted combination of selected experts produces properly scaled outputs. Without renormalization, if the two selected experts had probabilities 0.3 and 0.2, they would sum to only 0.5, effectively scaling down the output. Renormalization adjusts them to approximately 0.6 and 0.4. This keeps the output magnitude remains appropriate.



Temperature Scaling
Some implementations add temperature scaling to the softmax to give additional control over routing behavior:
where:
- : the temperature-scaled probability for expert
- : the raw routing logit
- : the temperature parameter that controls the sharpness of the distribution
- : the exponentiated scaled logit; using amplifies differences, making the distribution sharper
This concept relates to the decoding temperature we covered in Part XXVIII, where temperature controls the randomness of text generation. The principle is the same: temperature modulates how peaked or flat the probability distribution is.
Lower temperatures sharpen the distribution, pushing probability mass toward the highest-scoring expert and approaching hard assignment to a single expert. Higher temperatures soften the distribution, spreading probability more evenly and approaching uniform routing where every expert has roughly equal chance of selection.




Temperature controls the "confidence" of routing decisions across different training phases. Early in training, higher temperatures encourage exploration across experts, preventing the model from committing too strongly to particular routing patterns before it has learned enough. Later, lower temperatures can encourage more decisive routing, letting the model use the specialization it has developed.