在rasa_nlu中检测同义词

时间:2018-08-20 15:50:54

标签: python rasa-nlu

我有一个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进行了尝试,并且看到了相似的结果。

非常感谢您提出任何建议。

干杯。

更新: 根据以下@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?'}

2 个答案:

答案 0 :(得分: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"

答案 1 :(得分:0)

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

  

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

这意味着您需要在训练数据中包括其他一些单词,以便实体分类器学习正确地将这些单词分类为该实体。正确地对单词进行分类后,同义词即可加入并对其进行规范化。

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