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


Python models.FairseqIncrementalDecoder方法代码示例

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


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

示例1: __init__

# 需要导入模块: from fairseq import models [as 别名]
# 或者: from fairseq.models import FairseqIncrementalDecoder [as 别名]
def __init__(self, models):
        super().__init__()
        self.models_size = len(models)
        # method '__len__' is not supported in ModuleList for torch script
        self.single_model = models[0]
        self.models = nn.ModuleList(models)

        self.incremental_states = torch.jit.annotate(
            List[Dict[str, Dict[str, Optional[Tensor]]]],
            [
                torch.jit.annotate(Dict[str, Dict[str, Optional[Tensor]]], {})
                for i in range(self.models_size)
            ],
        )
        self.has_incremental: bool = False
        if all(
            hasattr(m, "decoder") and isinstance(m.decoder, FairseqIncrementalDecoder)
            for m in models
        ):
            self.has_incremental = True 
开发者ID:elbayadm,项目名称:attn2d,代码行数:22,代码来源:waitk_sequence_generator.py

示例2: __init__

# 需要导入模块: from fairseq import models [as 别名]
# 或者: from fairseq.models import FairseqIncrementalDecoder [as 别名]
def __init__(self, models):
        super().__init__()
        self.models_size = len(models)
        # method '__len__' is not supported in ModuleList for torch script
        self.single_model = models[0]
        self.models = nn.ModuleList(models)

        self.has_incremental: bool = False
        if all(
            hasattr(m, "decoder") and isinstance(m.decoder, FairseqIncrementalDecoder)
            for m in models
        ):
            self.has_incremental = True 
开发者ID:pytorch,项目名称:fairseq,代码行数:15,代码来源:sequence_generator.py

示例3: reorder_states

# 需要导入模块: from fairseq import models [as 别名]
# 或者: from fairseq.models import FairseqIncrementalDecoder [as 别名]
def reorder_states(self, new_order, incremental_states):
        if new_order is None:
            return
        for model in self.models:
            if isinstance(model.decoder, FairseqIncrementalDecoder):
                model.decoder.reorder_incremental_state(
                    incremental_states[model], new_order
                ) 
开发者ID:pytorch,项目名称:translate,代码行数:10,代码来源:competing_completed.py

示例4: _init_incremental_states

# 需要导入模块: from fairseq import models [as 别名]
# 或者: from fairseq.models import FairseqIncrementalDecoder [as 别名]
def _init_incremental_states(self, n_srcs):
        incremental_states = {}
        for src_id in range(n_srcs):
            for model_id, model in enumerate(self.models):
                if isinstance(model.decoder, FairseqIncrementalDecoder):
                    incremental_states[(src_id, model_id)] = {}
                else:
                    incremental_states[(src_id, model_id)] = None
        return incremental_states 
开发者ID:pytorch,项目名称:translate,代码行数:11,代码来源:multisource_decode.py

示例5: _encode

# 需要导入模块: from fairseq import models [as 别名]
# 或者: from fairseq.models import FairseqIncrementalDecoder [as 别名]
def _encode(self, encoder_input):
        encoder_outs = []
        incremental_states = {}
        for model in self.models:
            if not self.retain_dropout:
                model.eval()
            if isinstance(model.decoder, FairseqIncrementalDecoder):
                incremental_states[model] = {}
            else:
                incremental_states[model] = None
            encoder_out = model.encoder(*encoder_input)
            encoder_outs.append(encoder_out)
        return encoder_outs, incremental_states 
开发者ID:pytorch,项目名称:translate,代码行数:15,代码来源:beam_decode.py

示例6: __init__

# 需要导入模块: from fairseq import models [as 别名]
# 或者: from fairseq.models import FairseqIncrementalDecoder [as 别名]
def __init__(self, models):
        super().__init__()
        self.models = torch.nn.ModuleList(models)
        self.incremental_states = None
        if all(isinstance(m.decoder, FairseqIncrementalDecoder) for m in models):
            self.incremental_states = {m: {} for m in models} 
开发者ID:kakaobrain,项目名称:helo_word,代码行数:8,代码来源:sequence_generator.py


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