Guest User

Untitled

a guest
Jun 21st, 2018
115
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.42 KB | None | 0 0
  1. import torch
  2. import torch.nn as nn
  3. from torch.autograd import Variable
  4.  
  5. affine = nn.Linear(10, 10)
  6. # A linear mapping to a random vector... just for quick demo purposes
  7. x = Variable(torch.randn(100, 10))
  8. y = Variable(torch.randn(100, 10))
  9.  
  10. weird_loss = torch.mean(torch.exp(affine.weight))
  11. mse_loss = nn.MSELoss()
  12. pred_loss = mse_loss(affine(x), y)
  13. net_loss = pred_loss + weird_loss
  14. net_loss.backward()
  15. # should work just fine!
Add Comment
Please, Sign In to add comment