MCPcopy
hub / github.com/ddbourgin/numpy-ml / torch_xe_grad

Function torch_xe_grad

numpy_ml/tests/nn_torch_models.py:32–38  ·  view source on GitHub ↗
(y, z)

Source from the content-addressed store, hash-verified

30
31
32def torch_xe_grad(y, z):
33 z = torch.autograd.Variable(torch.FloatTensor(z), requires_grad=True)
34 y = torch.LongTensor(y.argmax(axis=1))
35 loss = F.cross_entropy(z, y, reduction="sum")
36 loss.backward()
37 grad = z.grad.numpy()
38 return grad
39
40
41def torch_mse_grad(y, z, act_fn):

Callers

nothing calls this directly

Calls 2

cross_entropyMethod · 0.80
backwardMethod · 0.45

Tested by

no test coverage detected