def __predict_sentence(self, src_batch):
     dialogue = EncoderDecoderModelForwardSlack(self.parameter)
     src_vocab = Vocabulary.load(self.model_name + '.srcvocab')
     trg_vocab = Vocabulary.load(self.model_name + '.trgvocab')
     model = EncoderDecoder.load_spec(self.model_name + '.spec')
     serializers.load_hdf5(dialogue.model + '.weights', model)
     hyp_batch = dialogue.forward(src_batch, None, src_vocab, trg_vocab, model, False, self.generation_limit)
     return hyp_batch
Пример #2
0
 def __predict_sentence(self, src_batch):
     dialogue = EncoderDecoderModelForwardSlack(self.parameter)
     src_vocab = Vocabulary.load(self.model_name + '.srcvocab')
     trg_vocab = Vocabulary.load(self.model_name + '.trgvocab')
     model = EncoderDecoder.load_spec(self.model_name + '.spec')
     serializers.load_hdf5(dialogue.model + '.weights', model)
     hyp_batch = dialogue.forward(src_batch, None, src_vocab, trg_vocab,
                                  model, False, self.generation_limit)
     return hyp_batch
 def __judge_print(self):
     if len(self.data) >= 1 and "text" in self.data[0]:
         print(self.data[0]["text"])
         if "chainer:" in self.data[0]["text"]:
             # input sentence
             src_batch = self.__input_sentence()
             #predict
             hyp_batch = self.__predict_sentence(src_batch)
             #show predict word
             word = ''.join(hyp_batch[0]).replace("</s>", "")
             print(self.sc.api_call("chat.postMessage", user=self.usr, channel = self.chan, text = word))
         if "chainer_train" in self.data[0]["text"]:
             self.__setting_parameter()
             model = EncoderDecoder.load_spec(self.model_name + '.spec')
             dialogue = EncoderDecoderModelForwardSlack(self.parameter)
             serializers.load_hdf5(dialogue.model + '.weights', model)
             dialogue.encdec = model
             dialogue.word2vecFlag = False
             dialogue.train()
Пример #4
0
 def __judge_print(self):
     if len(self.data) >= 1 and "text" in self.data[0]:
         print(self.data[0]["text"])
         if "chainer:" in self.data[0]["text"]:
             # input sentence
             src_batch = self.__input_sentence()
             #predict
             hyp_batch = self.__predict_sentence(src_batch)
             #show predict word
             word = ''.join(hyp_batch[0]).replace("</s>", "")
             print(
                 self.sc.api_call("chat.postMessage",
                                  user=self.usr,
                                  channel=self.chan,
                                  text=word))
         if "chainer_train" in self.data[0]["text"]:
             self.__setting_parameter()
             model = EncoderDecoder.load_spec(self.model_name + '.spec')
             dialogue = EncoderDecoderModelForwardSlack(self.parameter)
             serializers.load_hdf5(dialogue.model + '.weights', model)
             dialogue.encdec = model
             dialogue.word2vecFlag = False
             dialogue.train()