Amazon lex matching Intents which are not similar at all - amazon-web-services

I have created an intent in lex called MinimumAgeIntent.
MinimumAgeIntent has 2 utterances:
1. what is the age limit
2. what is the minimum age a patient needs to be to partake in the study
When I type in the question "where is the capital of turkey" it is matching the minimum age intent. Why is this? What is going on it doesn't make any sense.
In the first picture you can see that it is returning the response as if it matches the minimum age intent.
In the second picture you can see the lambda logs which shows the intent in the request.

Lex maps intent not just for the utterances given, but instead it takes those as an example and try to match for similar user inputs. In your case this might have happened because of the utterances you have given for MinimumAgeIntent and other intents. When Lex try to map the intent based on the user input, it sees MinimumAgeIntent as the closest match.
Somethings which you can try
Use non-conflicting utterances for intents. And add different varieties of it such that it covers the user intention in general. Add at least 5 to 10 utterances for each intent.
Use slots appropriately and validate its value on your code.
Lex always gives the inputTranscript so you can validate it on your code. May be not the best idea, but still you can check for mandatory words (prefer validating slots), In your case "age" for MinimumAgeIntent. And respond back with an appropriate response.
Add another intent like InvalidUserInput and add common user inputs that the bot wont support and respond with a proper error message. Be very careful with this, do not do this unless you know what you are doing and there is no other way.

Related

Dialogflow: Respond based on values and other conditional responses

I have $dinetype variable obtained from the user.
But I would like to give response based on what value has been set in $dinetype variable. In addition to giving responses, I also need to set relevant context. How do I do this in DialogFlow?
if($Dinetype=='dineout')
ask ('which restaurant would you like to go to?')
set_context ('awaiting-restaurant')
if($Dinetype=='takeaway')
ask ('When would you like to take away?')
set_context ('awaiting-takeaway-time')
Is it programmable at all? Or is it possible to achieve something equivalent to the above in the UI?
Edit: A much easier way has been added to handle this issue directly in Dialogflow
(Updated Solution) Follow-up Intents:
After creating an intent, you can add follow-up intents now.
Intents -> Create Intent >
[Response=Prompt For Conditional Response]
Intents -> Add Follow-up Intent -> Custom/Yes/No
Then set the training praise to a matching entity you want to conditionally respond to
  
 
OLD HACKY SOLUTION:
Late reply, but maybe someone will find this useful.
If the conditional response only needs to reference a single parameter
value, then I figured out what you can do is utilize the Entity's
"Reference Value" as the response you want to give for a particular
set of Synonyms.
So you'd have an entity that looked like this:
Then, setup your intent like this, with a response of $Dinetype:
Then the end result will look like this:
And you can make whatever follow-up intent you need from there.
Down-side is Dinetype won't be as reusable. But I still think it
beats writing a fulfillment webhook every time you need a simple
conditional response.
You can't do this in the Response section directly. The Response section is meant for fairly simple responses that don't require significant logic to process. Although you can use parameters in the response, you can't give a different response based on the value of the parameter. So you can set a response to something like
I think $Dinetype is great food.
but not
{{#if $Dinetype == "Thai"}}I think Thai food is too hot{{/if}}
or anything like that
However, you can add code that sends conditional responses and contexts by implementing a Fulfillment webhook. Although you can't do this for each Intent as part of the Intent editor screen, the Fulfillment screen includes a built-in code editor.
I found a solution to my similar problem using composite entities, which may or may not be overkill for your agent. The value assigned to a parameter associated with the (composite) entity will contain a JSON structure, if a synonym in that entity was matched.
Using the "Dot" notation, you can assign the matched sub-entity's property (similar to the reference value of a normal entity) to another parameter in the Actions and Parameters section. You can have one parameter for each sub-entity and hence, you can evaluate these parameters in your response section to select each response variants:
$Parameter_A ResponseA
$Parameter_B ResonseB
....
etc.
Clunky but works. Just have to be careful to reference the property exactly as it is defined in the composite entity.

How to define a Lex slot type(custom /built in ) that will accept any given value?

I have slot name "remark". I need a slot type which takes any value given by user to this field.
Amazon support staff have responded to similar questions in this way:
From aws dev forum:
The recommended approach for capturing free form text through a slot is to create a custom slot type, and provide enough representative sample/training data as slot values. This will allow Lex to learn from these samples, and recognize a much larger set.
So in your slot value samples, you should add single words, multiple words, and even whole sentences if that is what you expect. This lets Lex know and learn the wide range of data to fill the slot with.
The more sample values you give, the better Lex should be.
I have had the same problem, and firstly I tried to proviode wide range of training data but whenever I typed something new it never got captured correctly in the Lex.
So I created a slot without any value and unchecked the required checkbox (important). Then I enabled Lambda initialization and validation hook so that it goes to DialogCodeHook.
In the backend code, in DialogCodeHook, I grabbed the input of user from event['inputTranscript'] and assigned that value to the slot.
Hope it helps.
I have been working on lex platform for more than a year now. As per my understanding, it is not possible to capture free text as a slot. The approach to add more training data only to handle free text will make the slot (as thus the intent) greedy and have an negative impact on the overall performance of the bot.
The best alternative (in case of custom channel only) is to make use of session attributes to pass free text from the chat interface and pass a pre defined text (one of the values from slot) as input to lex; write logic in lambda to capture the free text from session attributes.
Let me know if you need more clarity.
You can use the AMAZON.AlphaNumeric inbuilt slot type

How to setup keyword detection matching for intents in Lex?

I want my bot to match the intent Help whenever user types /help followed by anything. eg /help i am unable to switch on laptop.
Here, the latter part can be anything, of any length.
I have given two slots - keyword and query.
In keyword slot I have given '/help' and for query slot I gave many random examples but even then when i test it for something new, it fails to match any intent.
Any idea how to achieve this?
Lex is a conversational engine and - in my experience - ignores all punctuation as it is not able to be spoken.
You may have to replace /help with a phrase like help me with ..., how can I ....
If you are using your own front end (as opposed to FB integration) you can consider adding an intermediary that will catch /help messages and forward the remaining on to a Lex bot that specifically handles help requests.

Parameter not supported by web service

I want to validate an opinion with you.
I have to design a web service that searches into a database of restaurants affiliated to a discount program in a specific country around a given address.
The REST call to such a webservice will look like http://server/search?country=<countryCode>&language=<languageCode>&address=<address>&zipcode=<zipcode>
The problem is that some countries do not have zipcodes or do not have them in the entire country.
Now, what would you do if the user passes such a parameter for a country that does not have zipcodes, but he/she passes a valid address?
Return 400 Bad request.
Simply igonre the zipcode parameter and return results based on the valid address
Return an error message in a specific format (e.g. JSON) stating that zipcodes are not supported for that country
Some colleagues are also favoring the following option
4. Simply return no results. And state in the documentation that the zipcode parameter is not supported. Also we have to create a webservice method which returns what fields should be displayed in the user interface.
What option do you think is best and why?
Thanks!
Well the OpenStreetMap Nomination Server returns results even if you dont know the ZIP Code and you can look at the results anyway. What if the user doesnt know the zip code but wants to find hist object?
I would try to search for that specific object anyway, especially because you said that some countries have zip codes partially.
If you simply return nothing te user doesnt know what went wrong and he wont know what to do.
That would depend on the use case. How easy is it for a user of the API to trigger that case? Is it a severe error which the user really should know how to avoid? Or is it something that is not entirely clear, where a user may know (or think he knows) a zipcode where officially there shouldn't be one? Does it come down to trial and error for the user how to retrieve correct results from your API? Is it a bad enough error that the user needs to be informed about it and that he needs to handle this on his side?
If you place this restriction in your API, consider that it will have to be clearly documented when this case is triggered, every user of the API will have to read and understand that documentation, it needs to be clear how to avoid the problem, it needs to be possible for the user to avoid the problem and every user will have to correctly implement extra code on his side to avoid this problem. Is it possible for the user to easily know which areas have zipcodes and which don't?
I think the mantra of "be flexible in what you accept, strict in what you output" applies...

How do I add comment lines to a business rule authored in Business Action Language

I am using JRules to author business rules. I want to add comments to the rules as shown in the very simple example below. I realise there is a documentation section for the rule but that is not what I require
// comments needed here
definitions
set 'an existing customer' to a customer
where the category of 'an existing customer' is "gold"
if
the city of 'an existing customer' is "London"
then
give a 5% discount to 'an existing customer'
else
// and more comments needed here
give a 10% discount to 'an existing customer'
Clearly, using the usual c++ and c# double forwardslash // will not work in the example above, so my question is how are comments added to rules in BAL.
Unfortunately you cannot add comments in rules. The rules are supposed to be self explanatory if the verbalization is good.
But you can use the documentation feature,if you want to document the business justification for each of the rules.
There is a simple workaround:
You can create 2 static virtual methods in your BOM: one commenting the conditions and one for the actions.
In the case of conditions:
Create a static method that takes a parameter String and return a boolean
Verbalize it like this "// {0}" (without quotes)
In the B2X, make it return true
Then, you can comment a condition with //"your_condition" and ...
In the previous example:
if
the city of 'an existing customer' is "London" and
// "blablabla" and
the age of 'an existing customer' is greater than 18
then ...
Since the method returns true, it won't affect the test. It has to be surrounded by "and", not "or".
In the case of actions:
Create a static method that takes a parameter String and return void
Verbalize it like this "// {0}" (without quotes)
In the B2X, add "return;"
Then, you can comment an action with //"your_action" ;
In the previous example:
else
// "and more comments needed here" ;
give a 10% discount to 'an existing customer' ;
You can do it but it means a hell lot of customization. So forget it
And it would be feasible only via browser interface, not Eclipse.
Just because you will be cheating.
How to do it:
Ready?... Steady?...
You need to recreate your own RTS (teamserver) web interface! if it sounds like too much effort then stop reading :)
Using the API, you can retrieve the rules from RTS (database) the there is (as mention in Tito's answer) a documentation attached to any rule.
So you can handle the display of your rule and add the comment accordingly.
Of course you need to find a way to position the comment correctly in the rule Line number could do the trick.
This is for the display...
Ten when you save the rule (by clicking a lovely button that you will have coded to do the actual saving) you need to remove the comments (and know where they are for the next time you want to display the rule) and save both the rule body and the documentation attached.
Sounds crazy? One client done it and I was working on this :) but we didn't modify the rule body. Almost everything but the rule body.
This will take you months, inpependently to the number of people working on it, I'm afraid.
To sum up: Can you do it, yes!
Does the implementation worth the effort? NO WAY!!!
Will this feature be available in the next version? NO! As Tito mentioned a rule should be self-explainatory.
Sorry :(