我读了一本书,书名为“用Python构建聊天机器人:使用自然语言处理和机器学习”,书名是Sumit,并遵循了在那里编写的代码。然后我看了一个例子代码如何在网上训练对话,但是后来我发现这个代码被废弃了。这是代码:
from __future__ import absolute_import
from __future__ import division
from __future__ import print_function
from __future__ import unicode_literals
import logging
from rasa_core import utils, train
from rasa_core.training import online
from rasa_core.interpreter import NaturalLanguageInterpreter
logger = logging.getLogger(__name__)
def train_agent(interpreter):
return train.train_dialog_model(domain_file="horoscope_domain.yml",
stories_file="data/stories.md", output_path="models/dialog", nlu_model_path=interpreter,
endpoints="endpoints.yml", max_history=2, kwargs={"batch_size": 50,"epochs": 200,
"max_training_samples": 300 })
if __name__ == '__main__':
utils.configure_colored_logging(loglevel="DEBUG")
nlu_model_path = "./models/nlu/default/horoscopebot" interpreter =
NaturalLanguageInterpreter.create(nlu_model_path) agent = train_agent(interpreter)
online.serve_agent(agent)结果是
ImportError:无法从“rasa_core.training”导入名称“online”
请帮我看看最新版本的代码是什么样子。当我检查时,我使用rasa nlu 0.15.1版本。
非常感谢你的帮助。
发布于 2020-12-14 20:00:40
我强烈建议您使用最新版本,即2.0.#版本。
自从您使用的版本以来,Rasa已经从python库发展为python应用程序,并具有强大的命令行接口。
现在,您可以从命令行使用以下命令对机器人进行培训:
rasa train您可以使用以下命令测试机器人:
rasa test你用命令跟机器人说话:
rasa shell如果您确实喜欢使用Rasa作为库,您可以在使用Rasa与木星笔记本文档中找到培训、测试和聊天的方法。
https://stackoverflow.com/questions/65252540
复制相似问题