SHARE
TWEET

Untitled

a guest Jun 18th, 2019 48 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. losses = []
  2. loss_function = nn.NLLLoss()
  3. model = LeModel(len(vocab))
  4. optimizer = optim.SGD(model.parameters(), lr=0.001)
  5.  
  6. for epoch in tqdm(range(1), leave=False):
  7.     total_loss = 0
  8.     for context, target in tqdm(data, leave=False):
  9.         model.zero_grad()
  10.        
  11.         predictions = model(x_train)
  12.         loss = loss_function(predictions, y_train, dtype=torch.long))
  13.  
  14.         loss.backward()
  15.         optimizer.step()
  16.  
  17.         total_loss += loss.item()
  18.     print("%s: %s" % (epoch, loss.item()))
  19.  
  20.     losses.append(total_loss)
  21.     torch.save(model.state_dict(), "model.torch")
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top