抱歉,如果我的英语感觉笨拙,这不是我的母语
我正在使用Python 3.11.3
我使用chatterbot模块编写了一个对话聊天机器人。到目前为止,它工作得很好,但一个大问题是,它将像“你叫什么名字”/“你叫什么名字”或“你在做什么”/“你在做什么”这样的句子视为两个不同的句子,我也必须对这些问题做出回应,否则聊天机器人将无法理解该问题
有什么方法可以让聊天机器人将类似的句子视为相同的吗? 我的代码:
from chatterbot import ChatBot
from chatterbot.trainers import ChatterBotCorpusTrainer
from chatterbot.response_selection import get_random_response
my_bot = ChatBot(name='Bot', read_only=True,
response_selection_method=get_random_response,
logic_adapters=[
{
'import_path': 'chatterbot.logic.SpecificResponseAdapter',
'input_text': 'empty',
'output_text': ''
},
{
'import_path': 'chatterbot.logic.BestMatch',
'default_response': 'i honestly have no idea how to respond to that',
'maximum_similarity_threshold': 0.7
},
{
'import_path': 'chatterbot.logic.MathematicalEvaluation'
}
], preprocessors=[
'chatterbot.preprocessors.clean_whitespace',
'chatterbot.preprocessors.unescape_html',
'chatterbot.preprocessors.convert_to_ascii'
]
)
while True:
user_input = input('Me: ')
if user_input.lower() == 'quit':
break
else:
bot_response = my_bot.get_response(user_input)
print(bot_response)
除了在网上寻找解决方案之外,我还没有真正尝试过任何东西(我是编码新手)
我在这方面并不熟练,但我认为你可以使用像 difflib 这样的模块,你可以在其中检查单个单词或整个句子,以查看字符是否相同的比率。
编辑:我刚刚注意到你已经由chatterbot预先实现了这个,所以否则我不知道。