logits = [l for l in out.data.cpu().numpy()]
preds = [np.argsort(-l)[:10] for l in logits]
guesses = []
for i, ps in enumerate(preds):
guesses.append([])
for p in ps:
guesses[-1].append((self.i_to_ans[p], logits[i][p], probs[i][p]))
After Change
out = self.model(input_dict, lengths_dict, qnums)
probs = F.softmax(out).data.cpu().numpy()
n_examples = probs.shape[0]
preds = np.argsort(-probs, axis=1)
for i in range(n_examples):
guesses.append([])
for p in preds[i][:max_n_guesses]:
guesses[-1].append((self.i_to_ans[p], probs[i][p]))
return guesses