Pytorch softmax: What dimension to use? | Newbedev
https://newbedev.com/pytorch-softmax-what-dimension-to-usesum = torch.sum (input, dim = 3) # input is of shape (s1, s2, s3, s4) Then you should call the softmax as: softmax (input, dim = 3) To understand easily, you can consider a 4d tensor of shape (s1, s2, s3, s4) as a 2d tensor or matrix of shape (s1*s2*s3, s4).