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


Python model.Transformer方法代码示例

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


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

示例1: __init__

# 需要导入模块: import model [as 别名]
# 或者: from model import Transformer [as 别名]
def __init__(self, model_source, cuda=False, beam_size=3):
        self.torch = torch.cuda if cuda else torch
        self.cuda = cuda
        self.beam_size = beam_size

        if self.cuda:
            model_source = torch.load(model_source)
        else:
            model_source = torch.load(model_source, map_location=lambda storage, loc: storage)
        self.src_dict = model_source["src_dict"]
        self.tgt_dict = model_source["tgt_dict"]
        self.src_idx2word = {v: k for k, v in model_source["tgt_dict"].items()}
        self.args = args = model_source["settings"]
        model = Transformer(args)
        model.load_state_dict(model_source['model'])

        if self.cuda: model = model.cuda()
        else: model = model.cpu()
        self.model = model.eval() 
开发者ID:ne7ermore,项目名称:torch-light,代码行数:21,代码来源:transform.py

示例2: __init__

# 需要导入模块: import model [as 别名]
# 或者: from model import Transformer [as 别名]
def __init__(self, args):
        """
        :param model_dir: model dir path
        :param vocab_file: vocab file path
        """
        self.tf = import_tf(0)

        self.args = args
        self.model_dir = args.logdir
        self.vocab_file = args.vocab
        self.token2idx, self.idx2token = _load_vocab(args.vocab)

        hparams = Hparams()
        parser = hparams.parser
        self.hp = parser.parse_args()

        self.model = Transformer(self.hp)

        self._add_placeholder()
        self._init_graph() 
开发者ID:policeme,项目名称:transformer-pointer-generator,代码行数:22,代码来源:pred.py

示例3: __init__

# 需要导入模块: import model [as 别名]
# 或者: from model import Transformer [as 别名]
def __init__(self, model_source, rewrite_len=30, beam_size=4, debug=False):
        self.beam_size = beam_size
        self.rewrite_len = rewrite_len
        self.debug = debug

        model_source = torch.load(
            model_source, map_location=lambda storage, loc: storage)
        self.dict = model_source["word2idx"]
        self.idx2word = {v: k for k, v in model_source["word2idx"].items()}
        self.args = args = model_source["settings"]
        torch.manual_seed(args.seed)
        model = Transformer(args)
        model.load_state_dict(model_source['model'])
        self.model = model.eval() 
开发者ID:ne7ermore,项目名称:torch-light,代码行数:16,代码来源:predict.py

示例4: __init__

# 需要导入模块: import model [as 别名]
# 或者: from model import Transformer [as 别名]
def __init__(self, model: Transformer, beam_width: int):
        super().__init__()
        self.model = model
        self.beam_width = beam_width 
开发者ID:asyml,项目名称:texar-pytorch,代码行数:6,代码来源:transformer_main.py


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