Esempio n. 1
0
def main():
    parser = CmdParser(version='%seq2seq chatbot V1.0')
    parser.add_option("-t",
                      "--type",
                      action="store",
                      type="string",
                      dest="type",
                      default="pre_treat",
                      help="execute type, pre_treat/train/chat")
    (options, args) = parser.parse_args()

    if options.type == 'train':
        chatter = get_chatter(execute_type=options.type)
        chatter.train(chatter.checkpoint,
                      dict_fn=_config.seq2seq_dict_fn,
                      data_fn=_config.lccc_tokenized_data,
                      max_train_data_size=_config.seq2seq_max_train_data_size)
    elif options.type == 'chat':
        chatter = get_chatter(options.type)
        print("Agent: 你好!结束聊天请输入ESC。")
        while True:
            req = input("User: "******"ESC":
                print("Agent: 再见!")
                exit(0)
            response = chatter.respond(req=req)
            print("Agent: ", response)
    elif options.type == 'pre_treat':
        preprocess_raw_lccc_data(raw_data=_config.lccc_data,
                                 tokenized_data=_config.lccc_tokenized_data)
        # preprocess_raw_data(raw_data=_config.resource_data, tokenized_data=_config.tokenized_data)
    else:
        parser.error(msg='')
Esempio n. 2
0
def main():
    parser = CmdParser(version='%seq2seq chatbot V1.0')
    parser.add_option("-t",
                      "--type",
                      action="store",
                      type="string",
                      dest="type",
                      default="pre_treat",
                      help="execute type, pre_treat/train/chat")
    (options, args) = parser.parse_args()

    if options.type == 'train':
        chatter = get_chatter(execute_type=options.type,
                              batch_size=get_config.BATCH_SIZE,
                              embedding_dim=get_config.seq2seq_embedding_dim,
                              units=get_config.seq2seq_units,
                              dropout=get_config.seq2seq_dropout,
                              checkpoint_dir=get_config.seq2seq_checkpoint,
                              beam_size=get_config.beam_size,
                              vocab_size=get_config.seq2seq_vocab_size,
                              dict_fn=get_config.seq2seq_dict_fn,
                              max_length=get_config.seq2seq_max_length,
                              start_sign=get_config.start_sign,
                              end_sign=get_config.end_sign)
        chatter.train(
            epochs=get_config.epochs,
            data_fn=get_config.lccc_tokenized_data,
            max_train_data_size=get_config.seq2seq_max_train_data_size)
    elif options.type == 'chat':
        print('待完善')
        chatter = get_chatter(execute_type=options.type,
                              batch_size=get_config.BATCH_SIZE,
                              embedding_dim=get_config.seq2seq_embedding_dim,
                              units=get_config.seq2seq_units,
                              dropout=get_config.seq2seq_dropout,
                              checkpoint_dir=get_config.seq2seq_checkpoint,
                              beam_size=get_config.beam_size,
                              vocab_size=get_config.seq2seq_vocab_size,
                              dict_fn=get_config.seq2seq_dict_fn,
                              max_length=get_config.seq2seq_max_length,
                              start_sign=get_config.start_sign,
                              end_sign=get_config.end_sign)
        print("Agent: 你好!结束聊天请输入ESC。")
        while True:
            req = input("User: "******"ESC":
                print("Agent: 再见!")
                exit(0)
            response = chatter.respond(req=req)
            print("Agent: ", response)
    elif options.type == 'pre_treat':
        preprocess_raw_lccc_data(raw_data=get_config.lccc_data,
                                 tokenized_data=get_config.lccc_tokenized_data)
    else:
        parser.error(msg='')