Exemplo n.º 1
0
    def load(model_path, cuda=False):
        decoder_params = torch.load(model_path,
                                    map_location=lambda storage, loc: storage)
        decoder_params['args'].cuda = cuda
        # update saved args
        saved_args = decoder_params['args']
        update_args(saved_args, init_arg_parser())
        model = ParaphraseIdentificationModel(
            saved_args, decoder_params['vocab'],
            decoder_params['transition_system'])
        model.load_state_dict(decoder_params['state_dict'])

        if cuda: model = model.cuda()
        model.eval()

        return model
Exemplo n.º 2
0
    def load(cls, model_path, cuda=False):
        params = torch.load(model_path, map_location=lambda storage, loc: storage)
        vocab = params['vocab']
        transition_system = params['transition_system']
        saved_args = params['args']
        # update saved args
        update_args(saved_args, init_arg_parser())
        saved_state = params['state_dict']
        saved_args.cuda = cuda

        parser = cls(saved_args, vocab, transition_system)

        parser.load_state_dict(saved_state)

        if cuda: parser = parser.cuda()
        parser.eval()

        return parser