Watson Assistant: Identifying Languages

Omar Megawer
IBM watsonx Assistant
4 min readFeb 7, 2019

One of the user behaviors that you might notice when your virtual assistant is live in production, is that users sometimes try to ask questions in a different language which your assistant doesn’t recognize.

This behavior might be because the user thinks it can answer in multiple languages (you might be offering different assistants for each language) or just trying to trick your bot. What will happen is that your assistant will fail to answer or even give an irrelevant response (makes it look stupid).

With the help of Watson Language Translator service and Cloud Functions to help integrate both services, you can identify the language in which the user asked his/her question and be able to decide accordingly. Whether to refuse to respond but acknowledge that the user is speaking in a different language or point the user to another assistant to help.

Cloud Functions

To do this, you will first need to deploy a Watson Language Translator service from IBM Cloud and Cloud Functions.

Cloud Functions offers various packages to help you integrate as fast as possible with the available Watson services. You can install the Watson Language Translator package easily by following these steps.

1 — Start Creating
2 — Install Packages
3 — Watson
4 — Language Translator
5 — Install

If you successfully completed these steps, you will be able to see the installed packages on your Actions page.

The Language Translator package comes with different actions that you can use in other scenarios, but to correct the user behavior noticed you can use the ‘identify’ action.

This action will expect the following parameters to be able to identify a language. You can check the service’s API documentation here.

iam_apikey refers to the service credentials generated when you deployed the Watson Language Translator service from IBM Cloud

Watson Assistant

Now from Watson Assistant’s side, you will need to connect to the installed Cloud Functions action. To do that you need to get the Cloud Functions API key and paste it in Watson Assistant.

You might also want to take a note of your namespace to add it later on

Next, add your credentials to Watson Assistant…

For simplicity, I added the credentials to the Welcome node, but you can choose to add it to your application layer so that it is stored securely

This part is up to your design, but as an example I will add a node to check if the text sent by the user is in English or not.

This node will call the Cloud Functions action whenever the user sends a message

The next node will then check the response stored in “$result_variable” and make sure if the text is in English or not.

Now your virtual assistant will be able to identify the language of the user’s input as follows.

You can make it look a lot smarter by being able to identify the language of the user’s input

It all goes back to your conversational design and how you want to tackle this behavior. This is the Watson Assistant Skill I used for this tutorial.

--

--