python-2.7 - 如何在Python中刷新chatterbot机器人的训练?

标签 python-2.7 chatbot chatterbot

我使用chatterbot库和python制作了一个简单的聊天机器人。我训练它的方式是,我让它读取一些包含聊天示例的文本文件,然后它学习如何根据这些训练示例回复消息。我面临的问题是 - 即使我删除训练文本文件的内容并运行应用程序,聊天机器人的行为方式仍然与以前相同,即它的内存不会刷新。我尝试启动一个新文件并复制粘贴相同的代码并更改程序的名称,但它仍然没有帮助。我该如何解决这个问题?以下是引用代码:

from chatterbot.trainers import ListTrainer
from chatterbot import ChatBot
from chatterbot.trainers import ChatterBotCorpusTrainer

import os

bot = ChatBot('trialBot')

bot.set_trainer(ListTrainer)

#directory containing training text files
mainDir = 'C:\\Users\\xyz\\Desktop\\trainfiles\\'

for _file in os .listdir(mainDir):
    chats = open(mainDir + _file, 'r').readlines()
    bot.train(chats)


while True:
    request = raw_input('You: ')
    response = bot.get_response(request)

    print('Bot: ' + str(response))

最佳答案

听起来您可能想要使用内存数据库,以便仅在聊天机器人运行时保留内容。

bot = ChatBot(
    'trialBot',
    database_uri=None
)

database_uri设置为None将导致聊天机器人使用存储在内存中的Sqlite数据库,因此存储训练它所用的知识。因此,每次运行程序时您都会有一个新的数据库可供使用。

关于python-2.7 - 如何在Python中刷新chatterbot机器人的训练?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54443934/

相关文章:

python - 如何使用opencv(python),simplecv或pil进行图像拼接?

linux - 找不到 snap7 库 - linux

python - 异常 : Cannot find PyQt5 plugin directories when using Pyinstaller despite PyQt5 not even being used

python - ERROR : Could not build wheels for preshed, Thinc,blis,这是安装基于 pyproject.toml 的项目所必需的

python - 在 python 3.x 中使用聊天机器人时出现错误

python - np.empty 与 np.zeros 的速度

c# - 如何在 C# 中使用 Dialogflow 的知识库

database - 为聊天机器人数据选择 IBM DB

python - 问题 azure 测试聊天机器人 "Error while finding module specification for ' aiohttp.web' (ModuleNotFoundError : No module named 'aiohttp' )

Python包安装错误-找不到py_compiler msvc