Keras 3 API文档 / 层 API / 激活层 / Softmax层

Softmax 层

[源代码]

Softmax

keras.layers.Softmax(axis=-1, **kwargs)

Softmax 激活层。

公式

exp_x = exp(x - max(x))
f(x) = exp_x / sum(exp_x)

示例

>>> softmax_layer = keras.layers.Softmax()
>>> input = np.array([1.0, 2.0, 1.0])
>>> result = softmax_layer(input)
>>> result
[0.21194157, 0.5761169, 0.21194157]

参数

  • axis: 整型,或整型列表,Softmax 归一化应用的轴。
  • **kwargs:基础层关键字参数,例如 namedtype

调用参数

  • inputs: Softmax 层的输入(logits)。
  • mask: 与 inputs 形状相同的布尔掩码。掩码指定1表示保留,0表示屏蔽。默认为 None

返回

Softmax 处理后的输出,形状与 inputs 相同。