题目
题目链接
Log Softmax函数(Log Softmax)是一种常用的激活函数,是Softmax函数的对数形式,其计算公式为:
\[f(x) = \log \left( \frac{e^{x_i}}{\sum_{j=1}^{n} e^{x_j}} \right)
\]
其中,\(x\)是输入。
该算法是深度学习中常用的激活函数之一。
标准代码如下
def log_softmax(scores: list) -> np.ndarray:# Subtract the maximum value for numerical stabilityscores = scores - np.max(scores)return scores - np.log(np.sum(np.exp(scores)))