【发布时间】: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"]}
【问题讨论】:
-
听起来部分是标记化问题。你会为此使用
spacy或nltk。会比打电话给split更好。您需要有一些关系才能将意图映射到单个项目。 -
你是什么意思,关系?
标签: python nlp python-3.6 natural-language-processing