def loss_batch(model, loss_func, x, y, opt=None):
    """
    The function to perform backpropagation
    :param model: Training model
    :param loss_func: Function to calculate training loss
    :param x: Feature in train dataset
    :param y: Labels in train dataset
    :param opt: Optimizer
    :return: Loss per epoch, length of the features
    """
    loss = loss_func(model(x), y)

    if opt is not None:
        loss.backward()
        opt.step()
        opt.zero_grad()

    return loss.item(), len(x)