def batch_top1(predicted, true):
  """ Compute the accuracies for a batch of predictions and answers """
  _, predicted_index = predicted.max(dim=1, keepdim=True)
  return true.gather(dim=1, index=predicted_index).clamp(max=1)