测试代码
import torch
num_list = [-20.0,-5.0,-1.0,-0.5, 0.0, 0.13, 0.5, 0.67, 1.0, 10.0]
for num in num_list:
logits = torch.tensor([num,0])
sigmoid_results = torch.sigmoid(logits[0])
softmax_resuots = torch.softmax(logits,0)
print(sigmoid_results,softmax_resuots)
运行结果
结论
一个数x, 和0一起,构成数组[x,0], 经过softmax,二者分别得到一个概率,分别设为softmax(x) 和softmax(0)
则有:
softmax(x) = sigmoid(x)
softmax(0) = 1- sigmoid(x)