Last active
May 1, 2016 11:02
-
-
Save SnowMasaya/2127770f7d0be8e0c319 to your computer and use it in GitHub Desktop.
Chainerで学習した対話用のボットをSlackで使用+Twitterから学習データを取得してファインチューニング ref: http://qiita.com/GushiSnow/items/79ca7deeb976f50126d7
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
if dec_flag: | |
if dst["weight_jy"] and child.name == "weight_xi" and self.word2vecFlag: | |
for a, b in zip(child.namedparams(), dst["weight_jy"].namedparams()): | |
b[1].data = a[1].data | |
print('Copy weight_jy') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
pip install chainer=="1.5.1" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
if dec_flag: | |
if dst["weight_jy"] and child.name == "weight_xi" and self.word2vecFlag: | |
for a, b in zip(child.namedparams(), dst["weight_jy"].namedparams()): | |
b[1].data = a[1].data | |
print('Copy weight_jy') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def __input_sentence(self): | |
#1 | |
text = self.__mecab_method(self.data[0]["text"].replace("chainer:", "")) | |
#2 | |
data = [text] | |
src_batch = [x + ["</s>"] * (self.generation_limit - len(x) + 1) for x in data] | |
return src_batch | |
def __predict_sentence(self, src_batch): | |
#1 | |
dialogue = EncoderDecoderModelForwardSlack(self.parameter) | |
#2 | |
src_vocab = Vocabulary.load(self.model_name + '.srcvocab') | |
trg_vocab = Vocabulary.load(self.model_name + '.trgvocab') | |
#3 | |
model = EncoderDecoder.load_spec(self.model_name + '.spec') | |
serializers.load_hdf5(dialogue.model + '.weights', model) | |
#4 | |
hyp_batch = dialogue.forward(src_batch, None, src_vocab, trg_vocab, model, False, self.generation_limit) | |
return hyp_batch |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#1 | |
self.__setting_parameter() | |
#2 | |
model = EncoderDecoder.load_spec(self.model_name + '.spec') | |
dialogue = EncoderDecoderModelForwardSlack(self.parameter) | |
serializers.load_hdf5(dialogue.model + '.weights', model) | |
#3 | |
dialogue.encdec = model | |
dialogue.word2vecFlag = False | |
dialogue.train() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment