Example #1
0
        "lr": 0.01,
        "hidden_dim": 10,
        # "dropout": 0.5,
    }
    model = AttRCNN(param)
    model.fit(train_x, train_y, test_x, test_y, 2, 32, save_best=False)
    model.param["lr"] = 0.003
    model.fit(train_x, train_y, test_x, test_y, 4, 64, save_best=False)
    # model.save("test")
    # x = FastText.load(str(MODEL_PATH / "intent" / "test.FastText"))
    s = [
        "你真是可爱阿", "你很喜欢学习哦", "我再也不想理你了", "吃饭没", "明天会下雨马", "你哥哥是谁", "你有哥哥么",
        "弟弟是谁", "我想买手机", "我是你主人", "我可以给你打分吗,评价"
    ]
    from chatbot.preprocessing.text import cut

    for i in s:
        print(
            i,
            label.reverse_one(
                model.infer(
                    np.array(vocab.transform_one(cut(i), max_length=10)))[0]))
    from chatbot.evaluate.plot import plot_attention_1d
    idx = 1200
    att = model.get_attention(
        torch.tensor(
            np.array(vocab.transform_one(train_x[idx],
                                         max_length=10)).reshape(-1, 10)))
    print(label.reverse_one(model.infer(train_x[idx])[0]))
    plot_attention_1d([vocab.reverse_one(train_x[idx]).split(" ")],
                      att.detach().numpy())
Example #2
0
    train_x = np.array(vocab.transform(train_x, max_length=10))
    test_x = np.array(vocab.transform(test_x, max_length=10))
    train_y = np.array(label.transform(train_y))
    test_y = np.array(label.transform(test_y))

    textCNN_param = {
        "vocab_size": len(vocab),
        "embed_dim": 60,
        "class_num": len(label),
        "kernel_num": 16,
        "kernel_size": [3, 4, 5],
        "dropout": 0.5,
        "lr": 0.01
    }
    model = TextCNN(textCNN_param)
    # new_model = TextCNN(textCNN_param)
    # new_model.load_state_dict(torch.load("/home/zhouzr/project/Task-Oriented-Chatbot/chatbot/results/intent/TextCNN_epoch_4_step_100_acc_0.9881.params.pkl"))
    model.fit(train_x, train_y, test_x, test_y, 1, 64, save_best=False)

    s = [
        "你真是可爱阿", "你很喜欢学习哦", "我再也不想理你了", "吃饭没", "明天会下雨马", "你哥哥是谁", "你有哥哥么",
        "弟弟是谁", "我想买手机", "我是你主人"
    ]
    from chatbot.preprocessing.text import cut
    for i in s:
        print(
            i,
            label.reverse_one(
                model.infer(
                    np.array(vocab.transform_one(cut(i), max_length=10)))[0]))