def compute_forward(model, critic, seqs_x, eval=False, normalization=1.0, norm_by_words=False):
    '\n    :type model: nn.Module\n\n    :type critic: NMTCriterion\n    '
    x_inp = seqs_x[:, :(- 1)].contiguous()
    x_label = seqs_x[:, 1:].contiguous()
    words_norm = x_label.ne(PAD).float().sum(1)
    if (not eval):
        model.train()
        critic.train()
        with torch.enable_grad():
            log_probs = model(x_inp)
            loss = critic(inputs=log_probs, labels=x_label, reduce=False, normalization=normalization)
            if norm_by_words:
                loss = loss.div(words_norm).sum()
            else:
                loss = loss.sum()
        torch.autograd.backward(loss)
        return loss.item()
    else:
        model.eval()
        critic.eval()
        with torch.no_grad():
            log_probs = model(x_inp)
            loss = critic(inputs=log_probs, labels=x_label, normalization=normalization, reduce=True)
        return loss.item()
:type model: nn.Module

:type critic: NMTCriterion
def compute_forward(model, critic, seqs_x, eval=False, normalization=1.0, norm_by_words=False):
    '\n    :type model: nn.Module\n\n    :type critic: NMTCriterion\n    '
    x_inp = seqs_x[:, :(- 1)].contiguous()
    x_label = seqs_x[:, 1:].contiguous()
    words_norm = x_label.ne(PAD).float().sum(1)
    if (not eval):
        model.train()
        critic.train()
        with torch.enable_grad():
            log_probs = model(x_inp)
            loss = critic(inputs=log_probs, labels=x_label, reduce=False, normalization=normalization)
            if norm_by_words:
                loss = loss.div(words_norm).sum()
            else:
                loss = loss.sum()
        torch.autograd.backward(loss)
        return loss.item()
    else:
        model.eval()
        critic.eval()
        with torch.no_grad():
            log_probs = model(x_inp)
            loss = critic(inputs=log_probs, labels=x_label, normalization=normalization, reduce=True)
        return loss.item()