本文整理匯總了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