检测rasa_nlu中的同义词

问题描述 投票:0回答:2

我有一个rasa_nlu的工作安装,在macOS High Sierra上运行Python 3.6.5。我能够让示例教程正常工作。我在使用同义词时遇到了麻烦。

这是我的培训文件first-model.md的相关部分。

## intent:select
- what is the [max](operator) rating?

## synonym:max
- best
- highest
- maximum

现在,rasa_nlu正确地检测了诸如what is the max rating?之类的问题的意图和实体

{'intent': {'name': 'select', 'confidence': 0.9542820453643799},
 'entities': [{'start': 12,
   'end': 15,
   'value': 'max',
   'entity': 'operator',
   'confidence': 0.8146240434922525,
   'extractor': 'ner_crf'}],
 'intent_ranking': [{'name': 'select', 'confidence': 0.9542820453643799},
  {'name': 'identity', 'confidence': 0.036332450807094574}],
 'text': 'what is the max rating?'}

但是,当我在问题中使用同义词时,它不会检测到实体。例如,what is the best rating?

{'intent': {'name': 'select', 'confidence': 0.9382177591323853},
 'entities': [],
 'intent_ranking': [{'name': 'select', 'confidence': 0.9382177591323853},
  {'name': 'identity', 'confidence': 0.10226328670978546}],
 'text': 'what is the best rating?'}

没有同义词的骰子。我和spacy_sklearntensorflow_embedding一起尝试了这个,看到了类似的结果。

非常感谢任何指针。

干杯。

更新:Per @ Caleb的建议如下,我将培训更新为:

## intent:select
- what is the [max](operator) rating?
- what is the [highest](operator:max) rating?
- what is the [maximum](operator:max) rating?
- what is the [best](operator:max) rating?

虽然它改善了这种情况,但它并没有完全解决问题。现在系统返回每个同义词(例如highestmaximumbest)作为实体值而不是实际值(max)。例如,如果我问what is the best rating?,我希望max作为实体值,而不是best。不幸的是,系统返回best

{'intent': {'name': 'select', 'confidence': 0.9736428260803223},
 'entities': [{'start': 12,
   'end': 16,
   'value': 'best',
   'entity': 'operator',
   'confidence': 0.9105035376516767,
   'extractor': 'ner_crf'}],
 'intent_ranking': [{'name': 'select', 'confidence': 0.9736428260803223},
  {'name': 'identity', 'confidence': 0.0}],
 'text': 'what is the best rating?'}
python rasa-nlu
2个回答
1
投票

我偶然发现了一个适用于我的用例的组合。

  1. 使用json格式代替markdown作为训练数据(例如见下文)
  2. 使用spacy_sklearn管道而不是tensorflow_embedding(例如见下文)

我确信有一个很好的解释为什么这个组合有效,而其他人没有,但我还没有处理。或者,也许还需要其他配置才能使其他组合正常工作。

干杯。

这是训练数据的JSON版本。

{
    "rasa_nlu_data": {
        "common_examples": [
              {
                "text": "what is the best rating?",
                "intent": "select",
                "entities": [
                  {
                    "start": 12,
                    "end": 16,
                    "value": "max",
                    "entity": "operator"
                  }
                ]
              },
              {
                "text": "what is the max rating?",
                "intent": "select",
                "entities": [
                  {
                    "start": 12,
                    "end": 15,
                    "value": "max",
                    "entity": "operator"
                  }
                ]
              },
              {
                "text": "what is the highest rating?",
                "intent": "select",
                "entities": [
                  {
                    "start": 12,
                    "end": 19,
                    "value": "max",
                    "entity": "operator"
                  }
                ]
              }
        ],
        "regex_features" : [],
        "entity_synonyms": [
            {
                "entity": "operator",
                "value": "max",
                "synonyms": ["maximum", "most", "highest", "biggest", "best"]
            }
        ]
    }
}

这是我使用的管道(感谢@Caleb建议也包括它)。

language: "en_core_web_md"
pipeline: "spacy_sklearn"

0
投票

请参阅文档this page上的注释。

请注意,使用上述格式添加同义词并不能改善模型对这些实体的分类。必须先对实体进行适当分类,然后才能将其替换为同义词值。

这意味着您需要在训练数据中包含其他一些单词,以便实体分类器学会将这些单词正确地分类为该实体。一旦单词被正确分类,那么同义词可以启动并对其进行标准化。

也可以使用基于单个意图示例和实体/同义词列表的chatito等工具。但要小心,因为如果对单个句子结构使用太多示例,使用这样的模板会导致过度拟合。

© www.soinside.com 2019 - 2024. All rights reserved.