pytorch
transformer从入门到入门
记录问题
展开
-
关于softmax和log_softmax区别与联系
softmax的缺点:Softmax是指数标准化函数,又称为归一化指数函数,将多个神经元的输出,映射到 (0,1) 范围内,并且归一化保证和为1,从而使得多分类的概率之和也刚好为1。其公式如下:试想最后一层的输出向量有三个单元Z=[z1=3、z2=1、z3=-3], 此时做softmax,exp(z1)=20、exp(z2)=2.7、exp(z3)=0.05, 根据公式得到各个单元的概率 :exp(z1)/∑exp(zi)=0.88 、exp(z1)/∑exp(zi)=0.12、exp(z1)/∑ex原创 2021-11-22 15:31:28 · 1216 阅读 · 0 评论 -
torch.gather()函数
作用:收集输入的特定维度指定位置的数值函数定义:torch.gather(input, dim, index, *, sparse_grad=False, out=None) → Tensor参数: input (Tensor) – the source tensor dim (int) – the axis along which to index index (LongTensor) – the indices of elements to gather理解例子:原创 2021-10-25 22:20:45 · 189 阅读 · 0 评论