簡體   English   中英

如何使用“Chatterbot”模塊在 Python 中訓練我的聊天機器人

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

我正在嘗試使用 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

提前感謝<3

我仍在學習圖書館的進出,並嘗試做類似的事情,所以會分享我的想法。

我希望我的機器人對一個語句有多個可能的答案,所以我允許對一個語句/響應進行多次培訓。 反過來,機器人在未來選擇對陳述的響應時,將對可接受的響應設置置信度閾值,然后從這些響應中隨機選擇。
我還計划引入各種強化,其中可以多次重新訓練確定的好的陳述/響應,以增加從隨機響應中選擇它的機會。
我確實檢查了該庫為語句/響應生成的數據庫,並且對同一語句/響應的多次訓練實際上確實生成了多個條目。
在我的 model 中,沒有要刪除/覆蓋的“壞”響應,只是將更好的響應添加到池中,看看會產生什么。

所有這一切仍在進行中。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM