简体   繁体   English

如何使用“Chatterbot”模块在 Python 中训练我的聊天机器人

[英]How can I train my chatterbot in Python with `Chatterbot` module

I am trying to make a chatbot, using Chatterbot, and then integrating it into my Discord Bot... I have done some research and got to know that I can use the Chatterbot library easily to train my bot... But I want to do it, so that whenever an on_message event is triggered in discord.py, it would learn from that... I have tried to use the example from the GitHub repo, and tried to train it, but it did not work very well... And also, is there a way to save all the responses it learns in a file or something... The code I have tried till now, is -->我正在尝试使用 Chatterbot 制作一个聊天机器人,然后将其集成到我的 Discord Bot 中……我做了一些研究,知道我可以轻松地使用 Chatterbot 库来训练我的机器人……但我想这样做,这样每当在 discord.py 中触发 on_message 事件时,它就会从中学习...而且,有没有办法将它学到的所有响应保存在文件或其他东西中......我到目前为止尝试过的代码是-->

from chatterbot import ChatBot
from chatterbot.conversation import Statement

"""
This example shows how to create a chat bot that
will learn responses based on an additional feedback
element from the user.
"""

# Uncomment the following line to enable verbose logging
# import logging
# logging.basicConfig(level=logging.INFO)

# Create a new instance of a ChatBot
bot = ChatBot(
    'Feedback Learning Bot',
    storage_adapter='chatterbot.storage.SQLStorageAdapter'
)


def get_feedback():

    text = input()

    if 'yes' in text.lower():
        return True
    elif 'no' in text.lower():
        return False
    else:
        print('Please type either "Yes" or "No"')
        return get_feedback()


print('Type something to begin...')

# The following loop will execute each time the user enters input
while True:
    try:
        input_statement = Statement(text=input())
        response = bot.generate_response(
            input_statement
        )

        print('\n Is "{}" a coherent response to "{}"? \n'.format(
            response[0].text,
            input_statement.text
        ))
        if get_feedback() is False:
            print('please input the correct one')
            correct_response = Statement(text=input())
            bot.learn_response(correct_response, input_statement)
            print('Responses added to bot!')

    # Press ctrl-c or ctrl-d on the keyboard to exit
    except (KeyboardInterrupt, EOFError, SystemExit):
        break

Thanks in advance <3提前感谢<3

I am still learning the in's and out's of the library and trying to do something similar, so will share my thoughts.我仍在学习图书馆的进出,并尝试做类似的事情,所以会分享我的想法。

I want my bot to have multiple possible answers to a statement, so I allow multiple trainings to occur for a statement/response.我希望我的机器人对一个语句有多个可能的答案,所以我允许对一个语句/响应进行多次培训。 The bot in turn when selecting a response to a statement in the future would have a confidence threshold for acceptable responses, then pick at random from those.反过来,机器人在未来选择对陈述的响应时,将对可接受的响应设置置信度阈值,然后从这些响应中随机选择。
I also plan on introducing a reinforcement of sorts, where an identified good statement/ response can be retrained multiple times to increase the chance it would be selected from the random responses to choose from.我还计划引入各种强化,其中可以多次重新训练确定的好的陈述/响应,以增加从随机响应中选择它的机会。
I did check the database the library produces for statement/responses, and multiple trainings of the same statement/response does in fact generate multiple entries.我确实检查了该库为语句/响应生成的数据库,并且对同一语句/响应的多次训练实际上确实生成了多个条目。
In my model, there is no "bad" response to be removed/overwritten, just better responses to be added to the pool and see what comes from that.在我的 model 中,没有要删除/覆盖的“坏”响应,只是将更好的响应添加到池中,看看会产生什么。

All this is still a work in progress.所有这一切仍在进行中。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM