Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions qanta/guesser/dan.py
Original file line number Diff line number Diff line change
Expand Up @@ -466,7 +466,7 @@ def run_epoch(self, iterator: Iterator):

out = self.model(input_dict, lengths_dict, qanta_ids)
_, preds = torch.max(out, 1)
accuracy = torch.mean(torch.eq(preds, page).float()).data[0]
accuracy = torch.mean(torch.eq(preds, page).float()).cpu().data
batch_loss = self.criterion(out, page)
if is_train:
batch_loss.backward()
Expand All @@ -476,7 +476,7 @@ def run_epoch(self, iterator: Iterator):
self.optimizer.step()

batch_accuracies.append(accuracy)
batch_losses.append(batch_loss.data[0])
batch_losses.append(batch_loss.cpu().data)

epoch_end = time.time()

Expand Down
4 changes: 2 additions & 2 deletions qanta/guesser/elmo.py
Original file line number Diff line number Diff line change
Expand Up @@ -193,14 +193,14 @@ def run_epoch(self, batches, train=True):
self.model.zero_grad()
out = self.model(x_batch.cuda(), length_batch.cuda())
_, preds = torch.max(out, 1)
accuracy = torch.mean(torch.eq(preds, y_batch).float()).data[0]
accuracy = torch.mean(torch.eq(preds, y_batch).float()).cpu().data
batch_loss = self.criterion(out, y_batch)
if train:
batch_loss.backward()
torch.nn.utils.clip_grad_norm(self.model.parameters(), 0.25)
self.optimizer.step()
batch_accuracies.append(accuracy)
batch_losses.append(batch_loss.data[0])
batch_losses.append(batch_loss.cpu().data)
epoch_end = time.time()

return np.mean(batch_accuracies), np.mean(batch_losses), epoch_end - epoch_start
Expand Down
4 changes: 2 additions & 2 deletions qanta/guesser/rnn.py
Original file line number Diff line number Diff line change
Expand Up @@ -346,7 +346,7 @@ def run_epoch(self, iterator: Iterator):

out, hidden = self.model(text, lengths, hidden_init, qanta_ids)
_, preds = torch.max(out, 1)
accuracy = torch.mean(torch.eq(preds, page).float()).data[0]
accuracy = torch.mean(torch.eq(preds, page).float()).cpu().data
batch_loss = self.criterion(out, page)
if is_train:
batch_loss.backward()
Expand All @@ -356,7 +356,7 @@ def run_epoch(self, iterator: Iterator):
self.optimizer.step()

batch_accuracies.append(accuracy)
batch_losses.append(batch_loss.data[0])
batch_losses.append(batch_loss.cpu().data)

epoch_end = time.time()

Expand Down