Gating Networks › Worked Example
Language AI HandbookAll chapters Gating Networks › Worked ExampleOne section · Sections in this chapter6 / 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
Let's trace through routing computation for a concrete example to solidify the concepts. Working through the math shows how formulas produce routing decisions. Suppose we have:
- 4 experts
- Input dimension
- An input token representation:
And a router weight matrix:
Step 1: Compute routing logits
The first step applies the linear projection to compute raw scores for each expert. We multiply the input vector by the weight matrix:
For expert 1 (first column), we compute the dot product between the input and the first column of the weight matrix:
Computing all four expert scores using the same dot product approach:
Expert 3 has the highest logit (0.52), followed by Expert 2 (0.30). Expert 1 and Expert 4 have negative scores, showing the input doesn't align well with their prototypes.
Step 2: Apply softmax
Next, we convert these raw logits to probabilities. First, compute the exponentials to ensure positive values:
Sum:
Divide each exponential by the sum to get normalized probabilities:
Notice how the exponential amplified the differences: Expert 3's logit is only 0.22 higher than Expert 2's, but its probability is about 25% higher ((0.36) vs (0.29)).
Step 3: Top-2 selection
The two highest-scoring experts are Expert 3 (0.36) and Expert 2 (0.29). These are the only experts that compute their outputs.
Renormalized weights ensure the selected experts' contributions sum to 1:
The final output is:
Only experts 2 and 3 are computed, saving roughly 50% of expert computation compared to running all four experts. Expert 3 contributes slightly more to the output due to its higher routing score.


