如何使用 Chatterbot(ver --0.7.4) 制作提问的 ChatBot?
How to make ChatBot that ask questions using Chatterbot(ver --0.7.4)?
使用 python 创建了一个聊天机器人,它的工作流程是我正在发送消息,根据聊天机器人的回复。
但它应该反向完成意味着聊天机器人应该首先通过 welcoming/asking 个问题开始,然后用户将回复那个。
请建议在代码中进行一些转换,以便它可以相应地工作。
提前致谢。
上面提到的代码是这样的:
from chatterbot import ChatBot
from chatterbot.trainers import ListTrainer
import os
bot = ChatBot('Bot')
bot.set_trainer(ListTrainer)
for files in os.listdir('C:/Users/Username\Desktop\chatterbot\chatterbot_corpus\data/english/'):
data = open('C:/Users/Username\Desktop\chatterbot\chatterbot_corpus\data/english/' + files, 'r').readlines()
bot.train(data)
while True:
message = input('You: ')
if message.strip() != 'Bye'.lower():
reply = bot.get_response(message)
print('ChatBot:',reply)
if message.strip() == 'Bye'.lower():
print('ChatBot: Bye')
break
我认为你应该训练你的机器人accordingly.I意味着从一个答案开始,然后将后续对话添加到训练数据中。
例如训练数据应该是这样的。
data = [
"Tony", #I started with an answer
"that's a good name",
"thank you",
"you are welcome"]
然后用静态语句开始你的对话,比如
打印("chatBot: hai, what is your name?")
我在下面添加了示例代码片段。
data = [
"Tony",
"that's a good name",
"thank you",
"you are welcome"]
bot.train(data)
print("chatbot: what is your name?")
message = input("you: ")
while True:
if message.strip() != 'Bye'.lower():
reply = bot.get_response(message)
print('ChatBot:',reply)
if message.strip() == 'Bye'.lower():
print('ChatBot: Bye')
break
message = input("you: ")
来自docs:
对于训练过程,您需要传入一个语句列表,其中每个语句的顺序基于其在给定对话中的位置。
例如,如果您要 运行 机器人进行以下训练呼叫,那么生成的聊天机器人将响应“嗨,你好!”这两个语句。和“问候!”通过说“你好”。
from chatterbot.trainers import ListTrainer
chatterbot = ChatBot("Training Example")
chatterbot.set_trainer(ListTrainer)
chatterbot.train([
"Hi there!",
"Hello",
])
chatterbot.train([
"Greetings!",
"Hello",
])
这意味着您的问题和答案的顺序很重要。
当您训练两个句子时,机器人会将第一个句子作为问题,将第二个句子作为答案。
使用 python 创建了一个聊天机器人,它的工作流程是我正在发送消息,根据聊天机器人的回复。 但它应该反向完成意味着聊天机器人应该首先通过 welcoming/asking 个问题开始,然后用户将回复那个。 请建议在代码中进行一些转换,以便它可以相应地工作。 提前致谢。
上面提到的代码是这样的:
from chatterbot import ChatBot
from chatterbot.trainers import ListTrainer
import os
bot = ChatBot('Bot')
bot.set_trainer(ListTrainer)
for files in os.listdir('C:/Users/Username\Desktop\chatterbot\chatterbot_corpus\data/english/'):
data = open('C:/Users/Username\Desktop\chatterbot\chatterbot_corpus\data/english/' + files, 'r').readlines()
bot.train(data)
while True:
message = input('You: ')
if message.strip() != 'Bye'.lower():
reply = bot.get_response(message)
print('ChatBot:',reply)
if message.strip() == 'Bye'.lower():
print('ChatBot: Bye')
break
我认为你应该训练你的机器人accordingly.I意味着从一个答案开始,然后将后续对话添加到训练数据中。
例如训练数据应该是这样的。
data = [
"Tony", #I started with an answer
"that's a good name",
"thank you",
"you are welcome"]
然后用静态语句开始你的对话,比如 打印("chatBot: hai, what is your name?") 我在下面添加了示例代码片段。
data = [
"Tony",
"that's a good name",
"thank you",
"you are welcome"]
bot.train(data)
print("chatbot: what is your name?")
message = input("you: ")
while True:
if message.strip() != 'Bye'.lower():
reply = bot.get_response(message)
print('ChatBot:',reply)
if message.strip() == 'Bye'.lower():
print('ChatBot: Bye')
break
message = input("you: ")
来自docs:
对于训练过程,您需要传入一个语句列表,其中每个语句的顺序基于其在给定对话中的位置。
例如,如果您要 运行 机器人进行以下训练呼叫,那么生成的聊天机器人将响应“嗨,你好!”这两个语句。和“问候!”通过说“你好”。
from chatterbot.trainers import ListTrainer
chatterbot = ChatBot("Training Example")
chatterbot.set_trainer(ListTrainer)
chatterbot.train([
"Hi there!",
"Hello",
])
chatterbot.train([
"Greetings!",
"Hello",
])
这意味着您的问题和答案的顺序很重要。 当您训练两个句子时,机器人会将第一个句子作为问题,将第二个句子作为答案。