def load_saved_model():
    if model_type == 'seq2seq':
        model = Seq2SeqIntentModel()
    else:
        model = MultiTaskIntentModel()
    model.load(args.model_path)
    return model
Exemple #2
0
 def load_model(self):
     if self.model_type == 'seq2seq':
         model = Seq2SeqIntentModel()
     else:
         model = MultiTaskIntentModel()
     model.load(self.pretrained_model)
     self.model = model
Exemple #3
0
 def load_model(self):
     with open(IntentExtractionApi.pretrained_model_info, "rb") as fp:
         model_info = pickle.load(fp)
     self.model_type = model_info["type"]
     self.word_vocab = model_info["word_vocab"]
     self.tags_vocab = {v: k for k, v in model_info["tags_vocab"].items()}
     if self.model_type == "mtl":
         self.char_vocab = model_info["char_vocab"]
         self.intent_vocab = {
             v: k
             for k, v in model_info["intent_vocab"].items()
         }
         model = MultiTaskIntentModel()
     else:
         model = Seq2SeqIntentModel()
     model.load(self.pretrained_model)
     self.model = model
Exemple #4
0
 def load_model(self):
     with open(IntentExtractionApi.pretrained_model_info, 'rb') as fp:
         model_info = pickle.load(fp)
     self.model_type = model_info['type']
     self.word_vocab = model_info['word_vocab']
     self.tags_vocab = {v: k for k, v in model_info['tags_vocab'].items()}
     if self.model_type == 'mtl':
         self.char_vocab = model_info['char_vocab']
         self.intent_vocab = {
             v: k
             for k, v in model_info['intent_vocab'].items()
         }
         model = MultiTaskIntentModel()
     else:
         model = Seq2SeqIntentModel()
     model.load(self.pretrained_model)
     self.model = model
Exemple #5
0
    # to_categorical one-hot格式化数据, 其中one_hot函数是转化nparray格式数据
    test_y = to_categorical(test_y, dataset.label_vocab_size)
    train_y = to_categorical(train_y, dataset.label_vocab_size)
    train_i = one_hot(train_i, len(dataset.intents_vocab))
    test_i = one_hot(test_i, len(dataset.intents_vocab))

    train_inputs = [train_x, train_char]
    train_outs = [train_i, train_y]

    test_inputs = [test_x, test_char]
    test_outs = [test_i, test_y]

    ######################################################################

    print('Building model')
    model = MultiTaskIntentModel(use_cudnn=args.use_cudnn)
    model.build(dataset.word_len,
                dataset.label_vocab_size,
                dataset.intent_size,
                dataset.word_vocab_size,
                dataset.char_vocab_size,
                word_emb_dims=args.token_emb_size,
                tagger_lstm_dims=args.lstm_hidden_size,
                dropout=args.tagger_dropout)

    # initialize word embedding if external model selected
    # 如果存在词向量model,就初始化词向量
    if args.embedding_model is not None:
        print('Loading external word embedding')
        embedding_model, _ = load_word_embeddings(args.embedding_model)
        embedding_mat = get_embedding_matrix(embedding_model,