import torch


def valid_batch(model, loss_func, x, y):
    """
    The function to validate correct predictions of the trained model over validation dataset
    :param model: Trained model
    :param loss_func: Loss function to calculate validation loss
    :param x: Features in validation set
    :param y: Labels in validation set
    :return: Validation loss per epoch, number of correct predictions and length of features
    """
    output = model(x)
    loss = loss_func(output, y)
    pred = torch.argmax(output, dim=1)
    correct = pred == y.view(*pred.shape)

    return loss.item(), torch.sum(correct).item(), len(x)