chainer.functions.softmax¶
-
chainer.functions.
softmax
(x, axis=1)[source]¶ Softmax function.
This function computes its softmax along an axis. Let \(c = (c_1, c_2, \dots, c_D)\) be the slice of
x
along with the axis. For each slice \(c\), it computes the function \(f(c)\) defined as \(f(c)={\exp(c) \over \sum_{d} \exp(c_d)}\).Parameters: - x (
Variable
ornumpy.ndarray
orcupy.ndarray
) – Input variable. A \(n\)-dimensional (\(n \geq 2\)) float array. - axis (int) – The axis along which the softmax is to be computed.
Returns: Output variable. A \(n\)-dimensional (\(n \geq 2\)) float array, which is the same shape with x.
Return type: Example
>>> x = np.array([[0, 1, 2], [0, 2, 4]], 'f') >>> x array([[ 0., 1., 2.], [ 0., 2., 4.]], dtype=float32) >>> y = F.softmax(x, axis=1) >>> y.data array([[ 0.09003057, 0.24472848, 0.66524094], [ 0.01587624, 0.11731043, 0.86681336]], dtype=float32) >>> F.sum(y, axis=1).data array([ 1., 1.], dtype=float32)
- x (