Example 1
Arguments: [
[
[
0,
0
]
]
]
Expected result: [
[
0.5,
0.5
]
]Both logits are zero, so each token receives 1/2.
Tensor and numerical foundations · Easy
Problem 1 of 50 · Python and NumPy
Convert each row of next-token logits into probabilities. Return a matrix of identical shape, normalizing independently across the vocabulary (the last axis).
Subtract each row maximum before exponentiating so large absolute scores remain safe. Equal scores receive equal probability.
def vocabulary_softmax(logits):Arguments: [
[
[
0,
0
]
]
]
Expected result: [
[
0.5,
0.5
]
]Both logits are zero, so each token receives 1/2.
Arguments: [
[
[
1000,
1000,
1000
]
]
]
Expected result: [
[
0.3333333333333333,
0.3333333333333333,
0.3333333333333333
]
]Subtracting 1000 gives three zeros, so every probability is 1/3 without overflow.