Log Softmax函数(Log Softmax)是一种常用的激活函数,是Softmax函数的对数形式,其计算公式为:

其中,是输入。 该算法是深度学习中常用的激活函数之一。

标准代码如下

def log_softmax(scores: list) -> np.ndarray:
    # Subtract the maximum value for numerical stability
    scores = scores - np.max(scores)
    return scores - np.log(np.sum(np.exp(scores)))