python - Rasa:如何为自定义组件提供超参数?
问题描述
我正在创建一个自定义组件以将其添加到 Rasa NLU 管道中。为此,我觉得有必要通过管道配置添加参数/超参数,就像我们为“WhitespaceTokenizer”这样的内置管道添加参数/超参数,如下所示。
pipeline:
- name: "WhitespaceTokenizer"
intent_split_symbol: "_"
上述管道将“intent_split_symbol”作为“WhitespaceTokenizer”的超参数。同样,我想为我的管道提供超参数。
例如。
pipeline:
- name: "MyCustomComponent"
model: "en_user_convo"
如何在“MyCustomComponent”自定义组件中提供“model”超参数?
解决方案
您可以使用与预定义组件相同的方式为您的组件定义配置,例如
- name: "MyCustomComponent"
param1: "test"
param2: "second param"
你的组件的构造函数应该接受一个字典作为参数:
from rasa.nlu.components import Component
class MyCustomComponent(Component):
def __init__(self, component_config: Optional[Dict[Text, Any]] = None) -> None:
if component_config is not None:
param1 = component_config.get("param1")
# ...
super().__init__(component_config)
# Rest of the component implementation
# ...
那有意义吗?
推荐阅读
- database - 如何从代理表中删除记录(毒液解决方案)?
- python - 如何在 matplotlib 中更新 y 轴
- connection - VMWare:与远程计算机的连接失败
- python - 如何用Python编程绘制wifi信道图
- android - 如何询问“允许访问您设备上的照片、媒体和文件?” 在 Android 11 上(在 android studio 中)?
- gradle - 在 graph.getAllTasks().last() 上加载 intellij 中的 Gradle 更改,出现错误“无法从空列表访问 last() 元素”
- ios - 如何在 SwiftUI 中单击菜单项时隐藏浮动菜单
- macos - docker-compose 有时在 mac 中给出“错误:没有这样的容器”
- javascript - 使用 Chrome-DevTools 的 NODEJS 中的内存泄漏 - 获取导致内存泄漏和应用程序崩溃的变量?
- reactjs - 数组减速器正在连接。不加总和。反应的上下文