问题描述
之前使用单一语料库进行对话,这些语料库相当无方向且充满不合理性,现在我希望使用最新版本的 chatterbot 获得很多乐趣。 我试图通过使用一组机器人来集中我的对话以提高相关性,每个机器人都使用不同的语料库进行训练,并根据对话的上下文在它们之间切换。 这个想法是合理的还是毫无意义的? 查看我的输出,我得到了很好的输入文本匹配,但没有找到合适的响应,只有置信度为 0 的随机选择。除非找到合适的响应,bestmatch,py select_response 失败。 任何人的反应都是最受欢迎的!
import os,argparsefrom chatterbot
import chatbotfrom chatterbot.trainers
import chatterbotCorpusTrainer
def bot(title,read_only = True): #,don't learn from exchanges (responses exist)
Bot = chatbot(title, #filters=["chatterbot.filters.RepetitiveResponseFilter"], logic_adapters=[{ 'import_path': 'chatterbot.logic.BestMatch', "statement_comparision_function": "chatterbot.comparisions.levenshtein_distance", "response_selection_method": "chatterbot.response_selection.get_first_response" }]) print('Training corpus',title) trainer=chatterbotCorpusTrainer(Bot) trainer.train("chatterbot.corpus.english." + title)
return Bot # trained instance
bots = {} # check what corpora available and traina a bot for each onefor item in os.listdir('C:/Python/python38/lib/site-packages/chatterbot_corpus/data/english/'): corpus = item.split('.') # of the form 'item.yml'
name = corpus[0]
bots[name]= bot(name) # add bot instance to dictionary of available bots
def exchange(input): # let's get a response to our input
# try suggested corpora to find best fit. If first corpus < theshold,try another.
# avoid random responses confidence 0
bot = bots[context]
response = bot.get_response(input)
if response.confidence < hi_threshold: # not a good answer,look elsewhere
if context != 'conversations':
response = bots['conversations'].get_response(input)
if response.confidence < lo_threshold: # not a good answer either
print('WARN: no good answer from',context,' or conversation')
print(input,response.id,response.confidence,response.text)
import logginglogging.basicConfig(level=logging.INFO) # Enable info level logging
lo_threshold,hi_threshold = .25,.65
context = 'greetings'
exchange('Good Morning')
exchange('How are you today?')
exchange('I am a human. Who are you?')
context = 'ai'
exchange('are you a robot?')
exchange('are you intelligent?')
exchange('can machines think?')
exchange('do you have emotions?')
INFO:chatterbot.chatterbot:开始搜索接近的文本匹配INFO:chatterbot.chatterbot:正在处理搜索结果INFO:chatterbot.chatterbot:找到类似的文本:早上好! 0.96INFO:chatterbot.chatterbot:找到类似文本:早安 1.0INFO:chatterbot.chatterbot:使用“早安”作为与“早安”的紧密匹配,1.0INFO:chatterbot.chatterbot:未找到响应。正在生成备用响应列表。INFO:chatterbot.chatterbot:未找到对输入的已知响应。选择随机响应。INFO:chatterbot.chatterbot:BestMatch 选择了“我住过吗?”作为信心为 0INFO 的回应:chatterbot.chatterbot:添加“早安”作为对“我是人类。你是谁?”的回应:INFO:chatterbot.chatterbot:开始搜索近距离文本 matchINFO:chatterbot.chatterbot:正在处理搜索结果信息:chatterbot.chatterbot:找到类似的文字:早上好! 0.96INFO:chatterbot.chatterbot:找到类似文本:早安 1.0INFO:chatterbot.chatterbot:使用“早安”作为与“早安”的紧密匹配,1.0INFO:chatterbot.chatterbot:未找到响应。正在生成备用响应列表。INFO:chatterbot.chatterbot:未找到对输入的已知响应。选择随机响应。INFO:chatterbot.chatterbot:BestMatch 选择“你在作弊”作为回应,置信度为 0INFO:chatterbot.chatterbot:添加“早安”作为对“早安”的回应 警告:问候或谈话没有好的回答早安问候无 0 你在作弊 信息:chatterbot.chatterbot:开始搜索相近文本匹配信息:chatterbot.chatterbot:正在处理搜索结果信息:chatterbot.chatterbot:找到类似文本:你今天好吗? 1.0INFO:chatterbot.chatterbot: 使用“你今天好吗?”与“你今天好吗?”有信心 1.0INFO:chatterbot.chatterbot:No response found.正在生成备用响应列表。INFO:chatterbot.chatterbot:未找到对输入的已知响应。选择随机响应。INFO:chatterbot.chatterbot:BestMatch 选择“不是现在,不是”。作为 0INFO 自信的回应:chatterbot.chatterbot:添加“你今天好吗?”作为对“早安”的回应信息:chatterbot.chatterbot:开始搜索接近的文本匹配INFO:chatterbot.chatterbot:处理搜索结果INFO:chatterbot.chatterbot:找到类似的文本:你今天好吗? 1.0INFO:chatterbot.chatterbot: 使用“你今天好吗?”与“你今天好吗?”有信心 1.0INFO:chatterbot.chatterbot:No response found.正在生成备用响应列表。INFO:chatterbot.chatterbot:未找到对输入的已知响应。选择随机响应。INFO:chatterbot.chatterbot:BestMatch 选择了“谢谢”。作为 0INFO 自信的回应:chatterbot.chatterbot:添加“你今天好吗?”作为对“你今天好吗?”的回应警告:问候或谈话没有好的答案,你今天好吗?问候 无 0 谢谢。INFO:chatterbot.chatterbot:开始搜索接近的文本匹配INFO:chatterbot.chatterbot:处理搜索结果INFO:chatterbot.chatterbot:找到类似的文本:人工智能是一个科学领域,它涉及构建硬件和软件复制人类思维的功能。 0.15INFO:chatterbot.chatterbot:Similar text found: 聊天机器人是一种试图模拟人类对话或“聊天”的程序。 0.21INFO:chatterbot.chatterbot:找到的相似文字:与人类非常相似,只是我们缺乏所有的情感、梦想、抱负、创造力、野心,尤其是主观性。 0.25INFO:chatterbot.chatterbot:找到类似的文字:成为人类是什么感觉? 0.39INFO:chatterbot.chatterbot:找到类似的文字:一个人。 0.47INFO:chatterbot.chatterbot:发现类似文字:我是人类。你是谁? 1.0INFO:chatterbot.chatterbot:使用“我是人类。你是谁?”与“我是人类。你是谁?”的紧密匹配。有信心 1.0INFO:chatterbot.chatterbot:No response found.正在生成备用响应列表。INFO:chatterbot.chatterbot:未找到对输入的已知响应。选择随机响应。INFO:chatterbot.chatterbot:BestMatch 选择“hal 代表什么”作为响应,信心为 0INFO:chatterbot.chatterbot:添加“我是人类。你是谁?”作为对“你今天好吗?”的回应信息:chatterbot.chatterbot:开始搜索接近的文本匹配信息:chatterbot.chatterbot:处理搜索结果INFO:chatterbot.chatterbot:找到的类似文本:人工智能是与自身相关的科学领域构建能够复制人类思维功能的硬件和软件。 0.15INFO:chatterbot.chatterbot:Similar text found: 聊天机器人是一种试图模拟人类对话或“聊天”的程序。 0.21INFO:chatterbot.chatterbot:找到的相似文字:与人类非常相似,只是我们缺乏所有的情感、梦想、抱负、创造力、野心,尤其是主观性。 0.25INFO:chatterbot.chatterbot:找到类似的文字:成为人类是什么感觉? 0.39INFO:chatterbot.chatterbot:找到类似的文字:一个人。 0.47INFO:chatterbot.chatterbot:发现类似文字:我是人类。你是谁? 1.0INFO:chatterbot.chatterbot:使用“我是人类。你是谁?”与“我是人类。你是谁?”的紧密匹配。有信心 1.0INFO:chatterbot.chatterbot:No response found.正在生成备用响应列表。INFO:chatterbot.chatterbot:未找到对输入的已知响应。选择随机响应。INFO:chatterbot.chatterbot:BestMatch 选择了“很可能,我不是。我没有那么老练。”作为 0INFO 自信的回应:chatterbot.chatterbot:添加“我是人类。你是谁?”作为对“我是人类。你是谁?”的回应 警告:从问候或谈话中没有好的答案我是一个人。你是谁?问候 无 0 很可能我不是。我没那么老练。 信息:chatterbot.chatterbot:开始搜索接近的文本匹配信息:chatterbot.chatterbot:处理搜索结果信息:chatterbot.chatterbot:找到类似的文本:你是机器人吗? 1.0INFO:chatterbot.chatterbot:使用“你是机器人吗?”与“你是机器人吗?”置信度为 1.0INFO:chatterbot.chatterbot:从 19 个最佳响应中选择响应。 回溯(最近一次调用):文件“C:\Python\python38\OurStuff\AI\AI chatbot training_example_corpus.py”,第 65 行,在交换中('你是机器人吗?') 文件“C:\Python\python38 \OurStuff\AI\AI 聊天机器人 training_example_corpus.py”,第 49 行,作为交换响应 = bot.get_response(input) 文件“C:\Python\python38\lib\site-packages\chatterbot\chatterbot.py”,第 137 行,在 get_response response = self.generate_response(input_statement,additional_response_selection_parameters) 文件“C:\Python\python38\lib\site-packages\chatterbot\chatterbot.py”,第 173 行,在 generate_response output = adapter.process(input_statement,additional_response_selection_parameters) 文件“C:\Python\python38\lib\site-packages\chatterbot\logic\best_match.py”,第 87 行,正在处理中 response = self.select_response(TypeError: 'str' object is not callable>>>
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)