我正在玩Alexa技能套件(用于Amazon Echo),并希望创建一种将意图发送到AWS Lambda函数的技能,该函数只会向我发送电子邮件。
示例话语将是这样的:
MemoIntent take a memo {myMemo}
MemoIntent to take a memo {myMemo}
MemoIntent send a memo {myMemo}
这样我就可以说“Alexa,请我的秘书拿一份备忘录,提醒我今天回家的路上去商店”然后会收到我的Lambda函数的电子邮件说:“提醒我去我今天回家的路上。“
myMemo
插槽是自由形式的 - 此时只需要一两句话就可以了,但是我没有在文档中找到很多关于如何为这样的东西编写模式的帮助。我目前最好的猜测是:
错误:您的请求出现问题:未知的广告位名称“{myMemo}”。发生在样本'MemoIntent中,在第1行上记下备忘录{myMemo}'。
我正在使用文档不鼓励的AMAZON.LITERAL插槽类型,但它也没有提供任何关于如何进行此操作的建议。而且,就像我提到的那样,它失败了。
这是失败的架构:
{
"intents": [
{
"intent": "MemoIntent",
"slots": [
{
"name": "myMemo",
"type": "AMAZON.LITERAL"
}
]
}
]
}
文字与其他插槽类型不同,因为您必须提供示例话语中的培训,如官方文档中所述:https://developer.amazon.com/public/solutions/alexa/alexa-skills-kit/docs/alexa-skills-kit-interaction-model-reference
示例话语将用户可以与您定义的意图对话的短语进行映射。它们使用以下格式在纯文本文件中写为行:
IntentName this is a sample utterance with no slots
IntentName this is a sample utterance containing a {SlotName}
IntentName this is a sample utterance containing a {SlotName} and {AnotherSlotName}
请注意,上述格式适用于除AMAZON.LITERAL之外的所有插槽类型。对于AMAZON.LITERAL,您还需要指定一个示例槽值:
IntentName this is a sample utterance containing a {slot value|SlotName} using LITERAL
或者,使用自定义插槽可以在定义大量样本自定义插槽值后提供插槽。在这种情况下,您将创建一个名为myMemo的新自定义插槽,其中包含自定义插槽名称的类型,例如MY_MEMO
。您的自定义插槽值将填充潜在值(这些值不是它将接收的唯一值),例如:
walk the dog
eat more bacon
go to the store on the way home
我们目前正在开发一个人工智能(用于Alexa),它应该能够回答各种各样的问题。用户能够说出应在后端进行分析的复杂问题非常重要。如果由于有限的话语和插槽类型,Alexa很早就放弃了它们,我们就无法提供这样的服务。
目前我们正在尝试以下方法。 (请记住,我们的实验基于德语。其他语言可能表现不同。)
1.每个Word类的自定义插槽类型
我们为以下单词类定义了自定义插槽类型:
2.句子结构的话语示例
然后我们为具有样本话语的句子定义了可能的结构:
QuestionIntent {Interrogation}
QuestionIntent {Item}
QuestionIntent {Verb}
QuestionIntent {Adjective}
QuestionIntent {Interrogation} {Verb} {Item}
QuestionIntent {Interrogation} {Verb} {Item} {Adjective}
QuestionIntent {Interrogation} {Verb} {Pronoun} {Item}
QuestionIntent {Interrogation} {Verb} {Pronoun} {Pronoun} {Item}
QuestionIntent {Interrogation} {Verb} {Pronoun} {Item} {Preposition} {Item}
QuestionIntent {Interrogation} {Verb} {Adjective} {Item}
QuestionIntent {Interrogation} {Verb} {Pronoun} {Adjective} {Item}
QuestionIntent {Interrogation} {Item} {Verb}
QuestionIntent {Interrogation} {Item} {Verb} {Adjective}
QuestionIntent {Interrogation} {Item} {Verb} {Pronoun} {Adjective}
QuestionIntent {Item} {Verb} {Interrogation}
QuestionIntent {Verb} {Item} {Verb}
QuestionIntent {Verb} {Adjective} {Item} {Verb}
3.后端的NLP分析
然后我们对后端提交的单词进行NLP分析。收到的数据如下所示:
"intent": {
"name": "QuestionIntent",
"slots": {
"Item": {
"name": "Item",
"value": "darknet"
},
"Preposition": {
"name": "Preposition"
},
"Adjective": {
"name": "Adjective"
},
"Verb": {
"name": "Verb",
"value": "is"
},
"Interrogation": {
"name": "Interrogation",
"value": "what"
},
"Pronoun": {
"name": "Pronoun",
"value": "the"
}
}
}
有些词可能会丢失,有些词可能会被误听。在这种情况下,我们会记住早期交流中的主题,并用这些来填充缺失的单词。例如:What is {it}?
⇒What is {Darknet}?
我们正在尝试广泛的插槽类型列表。但是这会增加误听事物的风险(英语中的一个很好的例子是写作和正确,幸运的是他们没有被分配到同一个词类)。所以我们转向了一种非常狭隘的方法。列表仅包含可由AI处理并存储在知识库中的单词。例如,项目列表不包含单词pony或unicorn。我们希望这会带来更好的结果(更少混淆的答案)。
没有用话语结构定义的复杂句子非常容易混淆。例如,如果一个句子包含超过2个动词(可能需要构建时态)。但到目前为止,只要用户表现出某种程度的礼貌,我们的方法就会产生具有良好准确度的结果。
但最后:不幸的是,目前,不可能用无穷无尽的单词和句子结构来管理类似备忘录的内容。
我尝试了另一种方法。
我创建了一个自定义插槽类型,其中包含这样的值列表。
wordOne
wordOne wordTwo
wordOne wordTwo wordThree
wordOne wordTwo wordThree wordFour
wordOne wordTwo wordThree wordFour wordFive
您可以根据需要使用尽可能长的字符串继续列表。
我的猜测是Alexa在尝试填充插槽时,会根据插槽类型的值来分配空间分隔的单词,以匹配它所听到的内容。
使用此自定义插槽类型,我在一个插槽中抓取了整个句子,取得了相当大的成功。虽然我从未在意图上测试它,而不仅仅是作为话语的插槽。
但如果你将你的意图分开,它可能会奏效。也许这样的事情。
StartMemoIntent take a memo
StartMemoIntent to take a memo
StartMemoIntent send a memo
StartMemoIntent record a memo
StartMemoIntent listen to my memo
RecordMemoIntent {memo}
你必须要小心,如果你的其他意图没有足够的样本话语,它可能会混淆意图。
如果您使用StartMemoIntent放置足够的样本话语(至少7-8),那么选择合适的话语应该没有问题。
根据这里的一些评论,我发现你可以通过在自定义槽值字段中添加一个大的随机单词列表来让Alexa识别自由格式的单词或短语。
我跑步生了我的;
from nltk.corpus import words
import json
words_list = words.words()[:100]
values = []
for word in words_list:
value = {}
value['id'] = None
value['name'] = {}
value['name']['value'] = word
value['name']['synonyms'] = []
values.append(value)
print(json.dumps(values))
然后将这些值复制粘贴到;
{
"languageModel": {
"types": [
{
"name": "phrase",
"values": [values you get from above]
...
AMAZON.SearchQuery
AMAZON.SearchQuery
插槽类型允许您捕获构成搜索查询的不太可预测的输入。
例如:
{
"intents": [
{
"name": "SearchIntent",
"slots": [
{
"name": "Query",
"type": "AMAZON.SearchQuery"
},
{
"name": "CityList",
"type": "AMAZON.US_CITY"
}
],
"samples": [
"search for {Query} near me",
"find out {Query}",
"search for {Query}",
"give me details about {CityList}"
]
}
]
}
更多关于AMAZON.SearchQuery
here
有AMAZON.LITERAL
插槽,传递已识别的单词的槽值,没有转换。但是,它不推荐。您不能在配置了对话框模型的技能中使用AMAZON.LITERAL
。