我正在尝试使用 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
答案 0 :(得分:2)
我仍在学习图书馆的内幕并尝试做一些类似的事情,所以将分享我的想法。
我希望我的机器人对一个陈述有多个可能的答案,所以我允许对一个陈述/响应进行多次训练。反过来,当机器人在未来选择对某个语句的响应时,将对可接受的响应设置一个置信度阈值,然后从中随机选择。
我还计划引入各种强化,在这种情况下,可以多次重新训练确定的好的陈述/反应,以增加从随机反应中选择它的机会。
我确实检查了库为语句/响应生成的数据库,并且同一语句/响应的多次训练实际上确实生成了多个条目。
在我的模型中,没有要删除/覆盖的“坏”响应,只有要添加到池中的更好响应,然后看看从中得到什么。
所有这些仍在进行中。