题解|softmax激活函数实现
softmax激活函数实现
https://www.nowcoder.com/practice/438e5a90131b42a9b2caa0484cf6cf0b?tpId=377&tags=&title=&difficulty=0&judgeStatus=0&rp=0&sourceUrl=%2Fexam%2Foj
softmax激活函数实现(Softmax Activation Function Implementation)是神经网络中的最常见的激活函数之一。 softmax函数其公式为
标准代码如下
def softmax(scores: list[float]) -> list[float]:
exp_scores = [math.exp(score) for score in scores]
sum_exp_scores = sum(exp_scores)
probabilities = [round(score / sum_exp_scores, 4) for score in exp_scores]
return probabilities