多智能自然语言处理和分类



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

例如:

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']

但是,我不能仅在句子上使用and,在句子上使用re.split作为定界符,就像用户问:

'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"]}

看来您在问题中混合了两个问题:

  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可以预测每个单词的标签(。

可以使用生物符号创建每个单词的意图标签,例如

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   

现在,生物标记hepls很多: the B-place标签将 bedroomthe living room分开。

这两种细分原则上都可以通过一个层次结构端到端模型(如果需要的话,则可以进行Google语义解析(执行,但是我觉得两个更简单的标记也可以工作。

最新更新