本文整理汇总了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()
示例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()
示例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()
示例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