Skip to main content

提升AI的理解能力 - 使用LUIS工具以及模式提升预测精度

分类:  Azure认知服务 标签:  #Azure #人工智能 #LUIS #语言理解(LUIS) 发布于: 2023-06-10 20:57:46

我们在前面的两章里讨论如何通过自定义意向以及通过意向定义实体,然后训练意向和实体模型从而通过Azure自然语言服务确定用户言语的分类以及数据的提取,但是有时候未必有这么准确,这个时候除了添加更多的言语实例,更详细的实体模型分解之外,还可以通过本节的两个工具提高准确度。

使用LUIS的终结点短语审核

Luis提供一个工具Review Endpoint Utterances, 这个工具在登录到LUIS之后,可以从菜单BUILD -> Review Endpoint Utterances使用该工具,这个工具主要是展现用户请求终结点时所使用的短语,同时后面配有我们意向的分类,和每项意向的评分,可以通过人工查看审核用户的输入,选择正确的意向分类,如下图:


使用模板改进预测

另外一种方式即使用模板来改进预测。需要注意的是模板仅仅是为了提高意向预测的,并不是为了实体数据提取。为了说明这个情况,我们使用一个现成的实例,请从这里下载项目的json文件:https://github.com/Azure-Samples/cognitive-services-sample-data-files/blob/master/luis/apps/tutorial-fix-unsure-predictions.json?raw=true

导入新的项目

登录到LUIS中之后,在New App菜单旁边按如下图操作:


然后在出现的对话框中选择刚刚下载的json文件


创建了新的luis app之后,我们先来观察一下这个实例,首先需要说明的是,这个实例是一个关于HR领域的实例


为了说明问题,我们需要添加两个新的意向,主要是为了查询组织架构

创建新意向OrgChart-Manager

创建新意向OrgChart-Manager, 并添加如下的实例短语

OrgChart-Manager实例短语
Who is John W. Smith the subordinate of?
Who does John W. Smith report to?
Who is John W. Smith's manager?
Who does Jill Jones directly report to?
Who is Jill Jones supervisor?

创建新意向OrgChart-Reports

创建新意向OrgChart-Reports, 并添加如下实例短语

OrgChart-Reports实例短语
Who are John W. Smith's subordinates?
Who reports to John W. Smith?
Who does John W. Smith manage?
Who are Jill Jones direct reports?
Who does Jill Jones supervise?

我们注意观察一下这两个新的意向的实例短语,会发现这两个实例短语的语法,单词,有大多相近的地方,这样对于预测就会有不少问题。

我们训练模型,然后发布,进行测试,就会有如下的发现:
访问https://YOUR-CUSTOM-SUBDOMAIN.api.cognitive.microsoft.com/luis/prediction/v3.0/apps/APP-ID/slots/production/predict?subscription-key=KEY-ID&verbose=true&show-all-intents=true&log=true&query=YOUR_QUERY_HERE

YOUR_QUERY_HERE替换成Who is the boss of Jill Jones?, 会有如下的结果:

{
    "query": "Who is the boss of Jill Jones?",
    "prediction": {
        "topIntent": "OrgChart-Manager",
        "intents": {
            "OrgChart-Manager": {
                "score": 0.326605469
            },
            "OrgChart-Reports": {
                "score": 0.127583548
            },
            "EmployeeFeedback": {
                "score": 0.0299124215
            },
            "MoveEmployee": {
                "score": 0.01159851
            },
            "GetJobInformation": {
                "score": 0.0104600191
            },
            "ApplyForJob": {
                "score": 0.007508645
            },
            "Utilities.StartOver": {
                "score": 0.00359402061
            },
            "Utilities.Stop": {
                "score": 0.00336530479
            },
            "FindForm": {
                "score": 0.002653719
            },
            "Utilities.Cancel": {
                "score": 0.00263288687
            },
            "None": {
                "score": 0.00238638581
            },
            "Utilities.Help": {
                "score": 0.00226386427
            },
            "Utilities.Confirm": {
                "score": 0.00211663754
            }
        },

可以看到第一意向预测得分非常低,而且第一,第二意向的得分相差并不远。这说明预测结果不够准确。

添加意向OrgChart-Manager模式。

登录到LUIS , 选择BUILD, 然后选择improve app performance , 再选择Patterns, 然后选择意向OrgChart-Manager, 添加如下的模板言语:


OrgChart-Manager 模板言语
Who is {EmployeeListEntity} the subordinate of[?]
Who does {EmployeeListEntity} report to[?]
Who is {EmployeeListEntity}['s] manager[?]
Who does {EmployeeListEntity} directly report to[?]
Who is {EmployeeListEntity}['s] supervisor[?]
Who is the boss of {EmployeeListEntity}[?]

模板言语非常简单,只有两个模式,一个是{} 这里引用我们定义的实体,这里的EmployeeListEntity是我们在项目中已经定义好的实体。[] 表示其中的内容是可选的。

添加意向OrgChart-Reports的模式

和上述的操作是一致的,添加如下的模板言语

OrgChart-Reports模板言语
Who are {EmployeeListEntity}['s] subordinates[?]
Who reports to {EmployeeListEntity}[?]
Who does {EmployeeListEntity} manage[?]
Who are {EmployeeListEntity} direct reports[?]
Who does {EmployeeListEntity} supervise[?]
Who does {EmployeeListEntity} boss[?]

添加完成后,重新训练,然后发布,再次测试:


这次可以看到预测的结果高达99.9%

本节简要的介绍就到这里结束了,如果你需要了解更多,也可以直接仔细的研究一下微软官方的文档:https://docs.microsoft.com/zh-cn/azure/cognitive-services/luis/luis-tutorial-pattern