def loss_validation(model, critic, valid_iterator):
    '\n    :type model: Transformer\n\n    :type critic: NMTCriterion\n\n    :type valid_iterator: DataIterator\n    '
    n_sents = 0
    n_tokens = 0.0
    sum_loss = 0.0
    valid_iter = valid_iterator.build_generator()
    for batch in valid_iter:
        (_, seqs_x) = batch
        n_sents += len(seqs_x)
        n_tokens += sum((len(s) for s in seqs_x))
        x = prepare_data(seqs_x, cuda=GlobalNames.USE_GPU)
        loss = compute_forward(model=model, critic=critic, seqs_x=x, eval=True)
        if np.isnan(loss):
            WARN('NaN detected!')
        sum_loss += float(loss)
    return float((sum_loss / n_sents))
:type model: Transformer

:type critic: NMTCriterion

:type valid_iterator: DataIterator
def loss_validation(model, critic, valid_iterator):
    '\n    :type model: Transformer\n\n    :type critic: NMTCriterion\n\n    :type valid_iterator: DataIterator\n    '
    n_sents = 0
    n_tokens = 0.0
    sum_loss = 0.0
    valid_iter = valid_iterator.build_generator()
    for batch in valid_iter:
        (_, seqs_x) = batch
        n_sents += len(seqs_x)
        n_tokens += sum((len(s) for s in seqs_x))
        x = prepare_data(seqs_x, cuda=GlobalNames.USE_GPU)
        loss = compute_forward(model=model, critic=critic, seqs_x=x, eval=True)
        if np.isnan(loss):
            WARN('NaN detected!')
        sum_loss += float(loss)
    return float((sum_loss / n_sents))