Convert logits into probabilities. For a one-dimensional input, normalize the full vector. For a two-dimensional input, normalize each row independently.
pi=∑jexj−mexi−mHere, xi is logit i, m is the maximum logit in the same vector or row, and pi is the resulting probability. Subtracting m prevents overflow without changing the probabilities. Return a NumPy array with the same shape as the input.
Input: x = [1, 2, 3]
Output: [0.090031, 0.244728, 0.665241]
Explanation: Subtracting 3 gives [-2, -1, 0]; exponentiating and dividing by the sum produces the probability vector.
Input: x = [[1, 2, 3], [0, 0, 0]]
Output: [[0.090031, 0.244728, 0.665241], [0.333333, 0.333333, 0.333333]]
Use np.max(x) for a vector and np.max(x, axis=1, keepdims=True) for a matrix.
Compute exp_values / exp_values.sum(...) with the same axis used for the maximum.
Sign in to take notes on this problem
Accepts: array
Convert logits into probabilities. For a one-dimensional input, normalize the full vector. For a two-dimensional input, normalize each row independently.
pi=∑jexj−mexi−mHere, xi is logit i, m is the maximum logit in the same vector or row, and pi is the resulting probability. Subtracting m prevents overflow without changing the probabilities. Return a NumPy array with the same shape as the input.
Input: x = [1, 2, 3]
Output: [0.090031, 0.244728, 0.665241]
Explanation: Subtracting 3 gives [-2, -1, 0]; exponentiating and dividing by the sum produces the probability vector.
Input: x = [[1, 2, 3], [0, 0, 0]]
Output: [[0.090031, 0.244728, 0.665241], [0.333333, 0.333333, 0.333333]]
Use np.max(x) for a vector and np.max(x, axis=1, keepdims=True) for a matrix.
Compute exp_values / exp_values.sum(...) with the same axis used for the maximum.
Sign in to take notes on this problem
Accepts: array