python - 加载组件 rasa 失败
问题描述
我正在使用 rasa 作为 python 库。这是我的目录结构
chat-bot/
bots/
models/
rasa/
my-model.tar.gz
rasa_bot.py
projects/
rasa/
actions/
components/
data_processing.py
data/
nlu.yml
stories.yml
config.yml
domain.yml
这是我的方式config.yml
language: en
pipeline:
- name: components.data_processing.DataProcessingComponent
- name: WhitespaceTokenizer
- name: CountVectorsFeaturizer
这就是我训练模型的方式
rasa train --fixed-model-name my-model --out ../../bots/models/rasa/
这rasa_bot.py
就是我加载模型的方式
model = RasaBot.__get_model("my-model.tar.gz")
# get the agent from model and action server
ACTION_ENDPOINT = os.getenv('ACTION_ENDPOINT')
agent = Agent.load(
model,
action_endpoint=EndpointConfig(ACTION_ENDPOINT)
)
和__get_model
方法
@staticmethod
def __get_model(modelName):
MODEL_LOCATION = os.environ.get('MODEL_LOCATION')
return '{}/{}'.format(MODEL_LOCATION, modelName)
但这显示了这个错误
Failed to load the component 'components.data_processing.DataProcessingComponent'. Failed to find module 'components.data_processing'. Either your pipeline configuration contains an error or the module you are trying to import is broken (e.g. the module is trying to import a package that is not installed). Traceback (most recent call last):
File "c:\chat-bot\env37\lib\site-packages\rasa\nlu\registry.py", line 121, in get_component_class
return rasa.shared.utils.common.class_from_module_path(component_name)
File "c:\chat-bot\env37\lib\site-packages\rasa\shared\utils\common.py", line 37, in class_from_module_path
m = importlib.import_module(module_name)
File "C:\Users\sgarg\AppData\Local\Programs\Python\Python37\lib\importlib\__init__.py", line 127, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 1006, in _gcd_import
File "<frozen importlib._bootstrap>", line 983, in _find_and_load
File "<frozen importlib._bootstrap>", line 953, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
File "<frozen importlib._bootstrap>", line 1006, in _gcd_import
File "<frozen importlib._bootstrap>", line 983, in _find_and_load
File "<frozen importlib._bootstrap>", line 965, in _find_and_load_unlocked
ModuleNotFoundError: No module named 'components'
解决方案
你能在你的文件夹中添加一个空__init__.py
文件吗?components
这样,该文件夹就会被检测为 Python 模块。
请注意,我假设您正在从此处rasa train
的文件夹运行命令。projects/rasa
推荐阅读
- java - 如下图数据文件的相对路径是什么?
- javascript - 在javascript中填充二维数组中的缺失值
- javascript - 带有 Javascript 提交的 Html 表单有时不记录信息
- python - 如何根据另一个功能的成功或失败来执行一个功能?
- php - 当验证错误不适用于错误时,也会弹出验证错误
- python-3.x - 如何在 Spacy 中使用神经核函数
- angular - Angular PrimeNG如何通过单击输入字段而不是按钮来获取选项列表?
- typescript - 打字稿对数字类型的每个对象的键应用算术运算
- python - 归一化图像返回 --->OverflowError: cannot convert float infinity to integer
- r - 有没有办法指定轴的上限范围?