How do I define a custom slot type that isn't a list?

◇◆丶佛笑我妖孽 提交于 2019-11-29 22:17:29
Justin at Amazon

Literals are different than other slot types in that you must provide training in the sample utterance, as mentioned in the official documentation: https://developer.amazon.com/public/solutions/alexa/alexa-skills-kit/docs/alexa-skills-kit-interaction-model-reference

Sample Utterances Syntax

Sample utterances map the phrases the user can speak to the intents you have defined. They are written as lines in a plain text file, using the following format:

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}

Note that the above format applies to all slot types except AMAZON.LITERAL. For AMAZON.LITERAL, you also need to specify a sample slot value:

IntentName  this is a sample utterance containing a {slot value|SlotName} using LITERAL

Alternatively, using Custom Slots will allow you to provide the slot after defining numerous sample custom slot values. In this scenario, you would create a new custom slot called myMemo with a type of the custom slot name, such as MY_MEMO. Your custom slot value would be populated with potential values (these are not the only values it will receive), such as:

walk the dog
eat more bacon
go to the store on the way home

We are currently developing an AI (for Alexa) which should be able to answer a wide variety of questions. It is very important that users are able to phrase complex questions which shall be analyzed in the backend. If Alexa drops them early on because of limited utterances and slot types, we can't provide such a service.

At the moment we are experimenting with the following approach. (Keep in mind that our experiment is based on German. Other languages might behave differently.)

1. Custom Slot Types per Word Class

We defined custom slot types for the following word classes:

  • interrogation (what, who, when)
  • item (cybersecurity, darknet, malware)
  • verb (is, has, can)
  • adjective (popular, inexpensive, insecure)
  • pronoun (the, he, she)

2. Sample Utterances for Sentence Structure

Then we have defined possible structures for sentences with sample utterances:

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 Analysis in Backend

Then we do an NLP analysis of the submitted words in the backend. The received data looks like this:

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

Some words might be lost, some others might be misheard. In this case, we remember topics from earlier exchanges and "fill" the missing words with these. For example: What is {it}?What is {Darknet}?

We were experimenting with a broad list of lists for slot types. But this increases the risk of mishearing something (a good example in English is write and right, luckily they are not assigned to the same word class). So we switched to a very narrow approach. The lists only contain words which can be handled by the AI and are stored in the knowledge base. For example, the list of items does not contain the words pony or unicorn. We expect this to come up with better results (less confusing answers).

Complex sentences not defined with a utterances structure are highly confusing to work with. For example, if a sentence contains more than 2 verbs (which might be necessary to build tense). But so far our approach leads to results with a good level of accuracy as long as the user behaves with some level of politeness.

But in the end: Unfortunately, at the moment, it is not possible to dictate something like a memo with an infinite amount of different words and sentence structures.

I tried another approach to this.

I created a Custom Slot Type with a list of values like this.

wordOne
wordOne wordTwo
wordOne wordTwo wordThree
wordOne wordTwo wordThree wordFour
wordOne wordTwo wordThree wordFour wordFive

You can continue the list with as long strings as you need.

My guess was that Alexa, when trying to fill slots, orientates on the amount of space seperated words in a value of a slot type, to match what it heard.

I had quite some success grabbing whole sentences in a single slot with this Custom Slot Type. Though i have never tested it on intents with more than just the slot as utterance.

But if you seperate your intent it might work. Maybe something like this.

StartMemoIntent take a memo
StartMemoIntent to take a memo
StartMemoIntent send a memo
StartMemoIntent record a memo
StartMemoIntent listen to my memo
RecordMemoIntent {memo}

You have to be careful though, it can confuse the intents if you have not enough sample utterances for your other intents.

If you put enough sample utterances, at least 7-8, with the StartMemoIntent it should have no problem taking the right one.

According to some of the comments here, I figured out you can get Alexa to recognise free form words or phrases by adding a large random list of words to the custom slot values field.

I generated mine by running;

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))

Then copy pasting those values to;

{
  "languageModel": {
    "types": [
      {
        "name": "phrase",
        "values": [values you get from above]
...

AMAZON.SearchQuery

AMAZON.SearchQuery slot type lets you capture less-predictable input that makes up the search query.

Ex:

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

More on AMAZON.SearchQuery here

There is AMAZON.LITERAL slot that passes the recognised words for the slot value with no conversion. But, its's not recommended. You cannot use AMAZON.LITERAL in a skill configured with a dialog model.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!