当前位置: 首页>>代码示例>>Python>>正文


Python onmt.modules方法代码示例

本文整理汇总了Python中onmt.modules方法的典型用法代码示例。如果您正苦于以下问题:Python onmt.modules方法的具体用法?Python onmt.modules怎么用?Python onmt.modules使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在onmt的用法示例。


在下文中一共展示了onmt.modules方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: make_loss_compute

# 需要导入模块: import onmt [as 别名]
# 或者: from onmt import modules [as 别名]
def make_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.
    """
    if opt.copy_attn:
        compute = onmt.modules.CopyGeneratorLossCompute(
            model.generator, tgt_vocab, opt.copy_attn_force,
            opt.copy_loss_by_seqlength)
    else:
        compute = onmt.Loss.NMTLossCompute(
            model.generator, tgt_vocab,
            label_smoothing=opt.label_smoothing if train else 0.0)

    if use_gpu(opt):
        compute.cuda()

    return compute 
开发者ID:xiadingZ,项目名称:video-caption-openNMT.pytorch,代码行数:21,代码来源:train.py

示例2: make_loss_compute

# 需要导入模块: import onmt [as 别名]
# 或者: from onmt import modules [as 别名]
def make_loss_compute(model, tgt_vocab, opt):
    """
    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.
    """
    if opt.copy_attn:
        compute = onmt.modules.CopyGeneratorLossCompute(
            model.generator, tgt_vocab, opt.copy_attn_force)
    else:
        compute = onmt.Loss.NMTLossCompute(
            model.generator, tgt_vocab,
            label_smoothing=opt.label_smoothing)

    if use_gpu(opt):
        compute.cuda()

    return compute 
开发者ID:abaheti95,项目名称:DC-NeuralConversation,代码行数:20,代码来源:train.py

示例3: make_loss_compute

# 需要导入模块: import onmt [as 别名]
# 或者: from onmt import modules [as 别名]
def make_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.
    """
    if opt.copy_attn:
        compute = onmt.modules.CopyGeneratorLossCompute(
            model.generator, tgt_vocab, opt.copy_attn_force,
            opt.copy_loss_by_seqlength)
    else:
        compute = onmt.Loss.NMTLossCompute(
            model.generator, tgt_vocab,
            label_smoothing=opt.label_smoothing if train else 0.0,
            train_baseline=opt.train_baseline > 0,
        )

    if use_gpu(opt):
        compute.cuda()

    return compute 
开发者ID:harvardnlp,项目名称:var-attn,代码行数:23,代码来源:train.py

示例4: make_loss_compute

# 需要导入模块: import onmt [as 别名]
# 或者: from onmt import modules [as 别名]
def make_loss_compute(model, tgt_vocab, dataset, opt):
    """
    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.
    """
    if opt.copy_attn:
        compute = onmt.modules.CopyGeneratorLossCompute(
            model.generator, tgt_vocab, dataset, opt.copy_attn_force)
    else:
        compute = onmt.Loss.NMTLossCompute(model.generator, tgt_vocab,
                                           opt.label_smoothing)

    if use_gpu(opt):
        compute.cuda()

    return compute 
开发者ID:moonlightlane,项目名称:QG-Net,代码行数:19,代码来源:train.py

示例5: make_loss_compute

# 需要导入模块: import onmt [as 别名]
# 或者: from onmt import modules [as 别名]
def make_loss_compute(model, tgt_vocab, dataset, copy_attn=False,
                      copy_attn_force=None, use_distillation_loss=False, teacher_model=None):

    """
    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.
    """

    if use_distillation_loss is True and teacher_model is None:
        raise ValueError('To compute distillation loss you have to pass the teacher model generator')

    if teacher_model is not None:
        teacher_model_generator = teacher_model.generator
    else:
        teacher_model_generator = None

    if copy_attn:
        compute = onmt.modules.CopyGeneratorLossCompute(model.generator, tgt_vocab, dataset, copy_attn_force)
    else:
        compute = onmt.Loss.NMTLossCompute(model.generator, tgt_vocab, use_distillation_loss, teacher_model_generator)

    if USE_CUDA:
        compute = compute.cuda()

    return compute 
开发者ID:antspy,项目名称:quantized_distillation,代码行数:28,代码来源:model.py


注:本文中的onmt.modules方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。