【问题标题】:Multi-intent natural language processing and classification多意图自然语言处理和分类
【发布时间】:2019-09-27 14:22:03
【问题描述】:

所以,我正在制作自己的家庭助理,并且正在尝试制作一个多意图分类系统。但是,我找不到将用户所说的查询拆分为查询中多个不同意图的方法。

例如:

I have my data for one of my intents (same format for all) 

{"intent_name": "music.off" , "examples": ["turn off the music" , "kill 
the music" , "cut the music"]}

用户所说的查询将是:

'dim the lights, cut the music and play Black Mirror on tv'

我想将句子拆分成他们各自的意图,例如:

['dim the lights', 'cut the music', 'play black mirror on tv']

但是,我不能只在句子上使用re.split,并以and, 作为分隔符来分割,就好像用户要求:

'turn the lights off in the living room, dining room, kitchen and bedroom'

这将被分成

['turn the lights off in the living room', 'kitchen', 'dining room', 'bedroom']

这对我的意图检测不可用

这是我的问题,提前谢谢你

更新

好的,所以我的代码已经到此为止了,它可以从我的数据中获取示例并根据我的意愿识别内部的不同意图,但是它不会将原始查询的部分拆分为它们各自的意图,而只是匹配。

import nltk
import spacy
import os
import json
#import difflib
#import substring
#import re
#from fuzzysearch import find_near_matches
#from fuzzywuzzy import process

text = "dim the lights, shut down the music and play White Collar"

commands = []

def get_matches():

    for root, dirs, files in os.walk("./data"):  

        for filename in files:

            f = open(f"./data/{filename}" , "r")
            file_ = f.read()
            data = json.loads(file_)

            choices.append(data["examples"])

        for set_ in choices:

            command = process.extract(text, set_ , limit=1)

            commands.append(command)

    print(f"all commands : {commands}")

这返回 [('dim the lights') , ('turn off the music') , ('play Black Mirror')] 这是正确的意图,但我无法知道查询的哪个部分与每个意图相关 - 这是主要问题

我的数据如下,现在很简单,直到我想出一个方法:

play.json

{"intent_name": "play.device" , "examples" : ["play Black Mirror" , "play Netflix on tv" , "can you please stream Stranger Things"]}


music.json

{"intent_name": "music.off" , "examples": ["turn off the music" , "cut the music" , "kill the music"]}


lights.json

{"intent_name": "lights.dim" , "examples" : ["dim the lights" , "turn down the lights" , "lower the brightness"]}

【问题讨论】:

  • 听起来部分是标记化问题。你会为此使用spacynltk。会比打电话给split 更好。您需要有一些关系才能将意图映射到单个项目。
  • 你是什么意思,关系?

标签: python nlp python-3.6 natural-language-processing


【解决方案1】:

您的问题似乎混合了两个问题:

  1. 单个查询中的多个独立意图(例如shut down the music and play White Collar
  2. 多个(使用表单填充框架)在一个意图中(例如turn the lights off in the living room bedroom and kitchen)。

这些问题完全不同。然而,两者都可以表述为词标记问题(类似于 POS 标记)并通过机器学习解决(例如 CRF 或 bi-LSTM 在预训练词嵌入上,预测每个词的标签)。

可以使用 BIO 表示法创建每个单词的意图标签,例如

shut   B-music_off
down   I-music_off
the    I-music_off
music  I-music_off
and    O
play   B-tv_on
White  I-tv_on
Collar I-tv_on

turn    B-light_off
the     I-light-off
lights  I-light-off 
off     I-light-off
in      I-light-off
the     I-light-off
living  I-light-off
room    I-light-off
bedroom I-light-off
and     I-light-off
kitchen I-light-off

模型会读取句子并预测标签。它应该接受至少数百个例子的训练——你必须生成或挖掘它们。

使用在此类标签上训练的模型拆分意图后,您将获得与每个唯一意图相对应的短文本。然后对于每个短文本,您需要运行第二个分段,寻找插槽。例如。关于光的句子可以表示为

turn    B-action
the     I-action
lights  I-action
off     I-action
in      O
the     B-place
living  I-place
room    I-place
bedroom B-place
and     O
kitchen B-place   

现在 BIO 标记很重要:the B-place 标签将 bedroomthe living room 分开。

原则上,两种分割都可以由一个分层的端到端模型执行(如果需要,可以使用谷歌语义解析),但我觉得两个更简单的标记器也可以工作。

【讨论】:

  • 感谢大卫如此清晰的介绍。是否需要用 BIO 表示法标记每个句子,以便在自定义数据集上训练模型?是否有一些用于在自定义数据集上创建模型的开源实现!
猜你喜欢
  • 2013-06-04
  • 1970-01-01
  • 2013-01-21
  • 2015-07-23
  • 2020-10-09
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多