import torch


def binary_accuracy(preds, y):
    """
    Returns accuracy per batch
    :param preds: prediction logits
    :param y: target labels
    :return: accuracy = percentage of correct predictions
    """

    # round predictions to the closest integer
    rounded_predictions = torch.round(torch.sigmoid(preds))
    correct = (rounded_predictions == y).float()
    acc = correct.sum() / len(correct)

    return acc