def forward_and_adapt(x, criterion, model, optimizer):
    """Forward and adapt model on batch of data.
    Measure entropy of the model prediction, take gradients, and update params.
    """
    # forward
    outputs = model(x)
    # adapt
    loss = criterion(outputs)
    loss.backward()
    optimizer.step()
    optimizer.zero_grad()
    return outputs