def top_preds(preds, labels, k=5):
    """
    Top 1 and top k precision

    :param preds: Softmax output tensor with probabilities
    :param labels: Labels in batch
    :param k: top k precision, default top5
    :return:
    """
    correct = 0
    topk = 0
    for i in range(len(labels)):
        classes = (-preds[i]).argsort()
        if classes[0] == labels[i]:
            correct += 1
        for c in classes[:k]:
            if c == labels[i]:
                topk += 1
                break
    return correct / len(labels), topk / len(labels)