(model, tgt_vocab, opt, train=True)
return compute
This returns user-defined LossCompute object, which is used to
    compute loss in train/validate process. You can implement your
    own *LossCompute class, by subclassing LossComputeBase.
This returns user-defined LossCompute object, which is used to
    compute loss in train/validate process. You can implement your
    own *LossCompute class, by subclassing LossComputeBase.
This returns user - defined LossCompute object which is used to compute loss in train / validate process . You can implement your own * LossCompute class by subclassing LossComputeBase .
def build_loss_compute(model, tgt_vocab, opt, train=True):
    """
    This returns user-defined LossCompute object, which is used to
    compute loss in train/validate process. You can implement your
    own *LossCompute class, by subclassing LossComputeBase.
    """
    device = torch.device("cuda" if onmt.utils.misc.use_gpu(opt) else "cpu")

    if opt.copy_attn:
        compute = onmt.modules.CopyGeneratorLossCompute(
            model.generator, tgt_vocab, opt.copy_attn_force,
            opt.copy_loss_by_seqlength)
    else:
        compute = NMTLossCompute(
            model.generator, tgt_vocab,
            label_smoothing=opt.label_smoothing if train else 0.0)
    compute.to(device)

    return compute
def build_loss_compute ( model , tgt_vocab , opt , train = True ) : device = torch . device ( "cuda" if onmt . utils . misc . use_gpu ( opt ) else "cpu" ) if opt . copy_attn : compute = onmt . modules . CopyGeneratorLossCompute ( model . generator , tgt_vocab , opt . copy_attn_force , opt . copy_loss_by_seqlength ) else : compute = NMTLossCompute ( model . generator , tgt_vocab , label_smoothing = opt . label_smoothing if train else 0.0 ) compute . to ( device ) return compute