Apply mask softmax - PyTorch Forums
https://discuss.pytorch.org › apply-...Hi everyone, I try to implement the following function: [image] At this stage, I have e.g. a tensor [[1,0,3], [0, 1, 2], [3, 2, ...
Apply mask softmax - PyTorch Forums
discuss.pytorch.org › t › apply-mask-softmaxMar 01, 2018 · I had to implement something similar. My approach was the following (where mask is a tensor of 1s and 0s indicating the entries to be removed): def masked_softmax (vec, mask, dim=1): masked_vec = vec * mask.float () max_vec = torch.max (masked_vec, dim=dim, keepdim=True) [0] exps = torch.exp (masked_vec-max_vec) masked_exps = exps * mask.float ...
Apply mask softmax - PyTorch Forums
https://discuss.pytorch.org/t/apply-mask-softmax/1421201.03.2018 · I had to implement something similar. My approach was the following (where mask is a tensor of 1s and 0s indicating the entries to be removed): def masked_softmax (vec, mask, dim=1): masked_vec = vec * mask.float () max_vec = torch.max (masked_vec, dim=dim, keepdim=True) [0] exps = torch.exp (masked_vec-max_vec) masked_exps = exps * mask.float ...