Created
August 15, 2018 00:20
-
-
Save wanchaol/3ee979cd1fa3e6bbcac03af53430c84a to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
In [1]: import torch | |
In [2]: input = torch.tensor([[0.2, -0.2, 0.07]], requires_grad=True) | |
...: target = torch.tensor([[0, 0, 1]]) | |
...: outputs = torch.nn.functional.multilabel_margin_loss(input, target) | |
...: | |
...: | |
In [3]: outputs | |
Out[3]: tensor(1.0033, grad_fn=<MultilabelMarginLossBackward>) | |
In [4]: grads = torch.autograd.grad(outputs, input, create_graph=True, allow_unused=True) | |
In [5]: grads | |
Out[5]: (tensor([[-0.6667, -0.3333, 1.0000]], grad_fn=<Error>),) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment