题解|Log Softmax函数的实现
Log Softmax函数的实现
https://www.nowcoder.com/practice/a8a0934f25f04c7e97d64d3e1b77219a?tpId=377&tags=&title=&difficulty=0&judgeStatus=0&rp=0&sourceUrl=%2Fexam%2Foj
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)))