Applying cross entropy loss on one-hot targets - PyTorch ...
https://discuss.pytorch.org/t/applying-cross-entropy-loss-on-one-hot...30.06.2020 · I searched the pytorch doc and I found that we can’t apply cross-entropy loss on one hot except in the following way: out = torch.FloatTensor([[0.05, 0.9, 0.05], [0.05, 0.05, 0.9], [0.9, 0.05, 0.05]]) y1 = torch.FloatTensor([[0, 1, 0], [0, 0, 1], [1, 0, 0]]) _, targets = y1.max(dim=0) loss = nn.CrossEntropyLoss()(out, Variable(targets))