當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。