You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Rasa实体提取故障求助:词意查询机器人实体返回空数组问题

Rasa聊天机器人实体提取返回空数组[]的排查方案

核心问题概述

需创建一款聊天机器人,实现从用户消息中提取单词作为实体,传入词典后返回对应词义。当前实体值无法提取,返回结果为空数组[],已尝试解决数周,请求协助排查。

系统环境信息:

  • Rasa Version: 3.6.13
  • Minimum Compatible Version: 3.5.0
  • Rasa SDK Version: 3.6.2
  • Python Version: 3.10.0
  • Operating System: Windows-10-10.0.19045-SP0

逐步排查要点

1. 验证NLU训练数据格式

检查nlu.yml中的实体标注是否符合Rasa 3.x规范,确保实体标签与后续配置一致,标注格式正确:

nlu:
- intent: ask_word_meaning
  examples: |
    - What is the meaning of [apple](word)
    - Explain [happiness](word) to me
    - Define [computer](word)

需保证标注的单词被正确包裹在[](实体名)结构中,且实体名(如word)统一。

2. 检查域文件(domain.yml)配置

确认domain.yml中正确声明了实体、意图及槽位映射:

intents:
  - ask_word_meaning

entities:
  - word

slots:
  word:
    type: text
    influence_conversation: false
    mappings:
    - type: from_entity
      entity: word

确保实体名称与训练数据标注一致,槽位映射逻辑指向正确的实体。

3. 确认管道(config.yml)实体提取组件

Rasa 3.x需通过指定组件实现实体提取,检查config.yml中是否包含有效提取组件并开启实体识别:

pipeline:
- name: WhitespaceTokenizer
- name: RegexFeaturizer
- name: LexicalSyntacticFeaturizer
- name: CountVectorsFeaturizer
- name: CountVectorsFeaturizer
  analyzer: char_wb
  min_ngram: 1
  max_ngram: 4
- name: DIETClassifier
  epochs: 100
  entity_recognition: true  # 必须开启实体识别
- name: EntitySynonymMapper

重点确认DIETClassifier的entity_recognition参数设为true,若使用其他提取器(如CRFEntityExtractor),需保证配置正确。

4. 训练与测试流程验证

  • 执行rasa train命令,确认训练过程无报错,若存在训练数据不足的警告,需补充更多标注示例;
  • 使用rasa shell nlu进行交互式测试,输入测试语句(如"What is the meaning of apple"),查看返回结果中的entities字段,确认实体是否被正确提取;
  • 若训练后模型未更新,可尝试删除models目录后重新训练。

5. 自定义动作逻辑排查

若实体提取后需在自定义动作中处理,检查动作代码中获取实体的方式是否正确:

from rasa_sdk import Tracker, Action
from rasa_sdk.executor import CollectingDispatcher

class ActionGetMeaning(Action):
    def name(self) -> str:
        return "action_get_meaning"

    def run(self, dispatcher: CollectingDispatcher,
            tracker: Tracker,
            domain: dict) -> list:
        # 获取最新实体值
        word_entity = next(tracker.get_latest_entity_values("word"), None)
        if word_entity:
            # 调用词典查询逻辑
            meaning = get_dict_meaning(word_entity)
            dispatcher.utter_message(text=f"The meaning of {word_entity} is {meaning}")
        else:
            dispatcher.utter_message(text="Please specify a word.")
        return []

确保代码中引用的实体名称与域文件、训练数据中的名称完全一致(大小写敏感)。

6. 数据一致性检查

训练数据的实体标签、域文件的实体名称、自定义动作的实体引用三者必须完全一致,避免因拼写、大小写差异导致实体匹配失败。

内容的提问来源于stack exchange,提问作者Attiqa

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.06 20:02:27