Last active
August 30, 2019 01:39
-
-
Save yaroslavvb/703f815e6a3e400a7926ff90e6f9c820 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
d = 3 | |
q = torch.rand(d) | |
q /= q.sum() # empirical distribution (soft labels) | |
theta = torch.randn(d, requires_grad=True) | |
p = F.softmax(theta, dim=0) | |
loss = -torch.sum(q*torch.log(p)) | |
g = p - q | |
H = torch.diag(p) - outer(p) | |
torch.allclose(H, hessian(loss, theta)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment