用于为意图和实体(如 Alexa 自定义技能)解析文本的开源库

Open source library for parsing text for intent and entities like Alexa Custom Skills

是否有任何像 Amazon Alexa Custom Skills 一样工作的开源库,您可以在其中为其提供意图模式和示例话语以进行匹配,并且它将提供经过解析的标记化响应以及与定义中匹配的实体。

这是一个例子Alexa Custom Skill Intent schema

训练和指定如何匹配文本和映射到实体的示例话语:

AnswerIntent the answer is {Answer} 
AnswerIntent my answer is {Answer} 
AnswerIntent is it {Answer} 
AnswerIntent {Answer} is my answer AnswerOnlyIntent {Answer}

AMAZON.StartOverIntent start game 
AMAZON.StartOverIntent new game 
AMAZON.StartOverIntent start 
AMAZON.StartOverIntent start new game

另一项服务是 https://wit.ai/,它允许您配置要匹配的表达式和标记,是否有任何开源库可以提供这种级别的灵活性。

OSS解析库很多。大多数实际上比只是正则表达式的 Alexa 话语模式具有更大的灵活性。

您可以从专门针对 NLP 的库中进行选择,例如 GATE、Stanford Core NLP、OpenNLP 和 NLTK。如果您正在处理大型文档集合,那么 Apache Lucene(如果您愿意,也可以是 Solr)非常棒(尽管 GATE 也支持它们)。

对于更轻量的内容,您可以使用通用解析器生成器。有太多无法一一列举 (https://en.wikipedia.org/wiki/Comparison_of_parser_generators) but packrat parsers (http://bford.info/packrat/),例如 Antlr 性能好且易于使用。

Mycroft AI 似乎有很多项目提供的功能和程序员界面与 Amazon Alexa Custom Skills 非常相似,您可以自己托管和修改它以获得比 Alexa 语音服务更大的灵活性(但这也是有点不利,因为您必须自己扩展它)。

  • https://docs.mycroft.ai/skill.creation

  • https://mycroft.ai/projects/

    • Mycroft Core - 是一种将自然语言处理、文本到语音、语音到文本和强大的 API 结合在一起以创造强大体验的技术,让用户能够操纵他们的智能设备和物联网通过语音控制。
    • Open STT - 开源语音到文本模型(似乎他们现在正在利用其他 API,例如 Google 语音转文本、Wit.ai 和 IBM Watson)
    • Adapt Intent Parser - 将自然语言转换为机器可读的数据结构
    • Mimic Text To Speech - 文本并以高质量的语音朗读(目前只是一个提案项目,尚不可用)

如果我没听错,你想提供一个模式来匹配可能的值,并且库必须生成可能的话语列表。如果是这样,有一个 alexa-app 项目可以让您在其他功能之外执行此操作。它隶属于麻省理工学院,因此可以从那里借用所需的代码。 示例:

app.intent('sampleIntent',
    {
        "slots":{"NAME":"LITERAL","AGE":"NUMBER"}, 
        "utterances":[ "my {name is|name's} {names|NAME} and {I am|I'm} {1-100|AGE}{ years old|}" ]
    },
    function(request,response) { ... }
);

可能的表达方式:

my name is John and I am 20 years old
my name's John and I'm 40
my name's Taylor and I'm 55 years old
....

也许,你可以试试Rasa-nlu。它与 MS Luis 非常相似。您可以将文本解析为结构化数据,例如

{
"entities": [
    {
        "endIndex": null,
        "entity": "hello",
        "score": null,
        "startIndex": null,
        "type": "name"
    }
],
"intents": [
    {
        "intent": "greet",
        "score": 0.640747175086514
    },
    {
        "intent": "goodbye",
        "score": 0.2696910959582717
    },
    {
        "intent": "FindEmployeeLocation",
        "score": 0.05672220244026073
    },
    {
        "intent": "FindEmployee",
        "score": 0.032839526514953594
    }
],
"query": "hello",
"topScoringIntent": {
    "intent": "greet",
    "score": 0.640747175086514
}

您也可以使用 json 或 markdown 格式训练您的语言模型。最重要的是服务是开源的。这意味着您无需为使用它支付额外的费用。您只需设置自己的 nlu 服务器然后使用它。 https://github.com/RasaHQ/rasa_nlu