By Frank Nimphius
Chatbot support for multiple languages is a worldwide requirement. Almost every country has the need to support foreign languages, be it for immigrants, refugees, tourists, or even employees crossing borders on a daily basis for their jobs.
According to the Linguistic Society of America article “How Many Languages Are There in the World?” by Stephen R. Anderson, almost 7,000 languages are spoken in the world. Although no bot needs to support all languages, building multilanguage bots is a challenge for developers, especially if they’re not familiar with all the languages for which they need to implement support.
In case you were hoping, artificial intelligence alone does not build you a multilanguage bot. Multilanguage support needs to be implemented by design with tools and best practices.
This article explains an approach to building multilanguage bots with the Oracle Intelligent Bots feature of Oracle Mobile Cloud Enterprise as well as the configurations and options available.
In the hands-on instructions, you are going to create an internationalized pizza bot that accepts input messages in the user language and displays labels, prompts, and response messages in the user language.
Multilanguage Support in Oracle Intelligent Bots
Broadly speaking, there are two approaches for building bots that understand different languages:
As of today, Oracle Intelligent Bots has superior support for the English language—it knows how to handle the English received by the language-processing engine best. From a development perspective, creating bots in English is more likely to give better results. As such, Oracle Intelligent Bots’ approach to multilanguage chatbot applications is to build single-base-language bots in English and use translation services and resource bundles to support foreign languages.
With this approach, response messages as well as labels and prompts are either autotranslated to the detected user language or reference language-specific strings in resource bundles. From a bot user’s perspective, the bot appears as a native language bot.
Getting Started
To follow the hands-on instructions in this article, you need access to Oracle Mobile Cloud Enterprise, which is available as a free trial.
The download for this article contains a bot you need to import to your Oracle Intelligent Bots instance to complete the hands-on steps for this article. To import the bot, download the zip file containing the starter bot and then do the following:
Figure 1: Oracle Mobile Cloud Enterprise with Oracle Intelligent Bots selected
Signing Up for Google Translation Service
Oracle Intelligent Bots supports translation services from Microsoft and Google. This article uses the Google translation service—for which you need a Google account and a credential key to access the translation service API—to translate bot conversations. The following steps assume that you have a Google account.
Figure 2: Figure 2: Google dialog box for creating a credential key
Note that Google translation service is not free of charge. If, however, translation is the only Google paid API or service you use, the free credits you have from your account will keep you going for a very long time.
Adding the Translation Service to Your Bot Instance
To use a translation service in Oracle Intelligent Bots, you need to register the service and the credential key in your Oracle Intelligent Bots instance. To do this, first navigate back to the Oracle Intelligent Bots dashboard.
https://translation.googleapis.com/language/translate/v2
Running the Sample Bot
Before adding translations, let’s run the sample bot to see its current functionality and ability to understand foreign languages.
What you just did: The sample bot is designed and trained in English, which means that all intents and utterances are provided in English. Testing the bot with an English sentence works fine and produces a menu from which you can choose a pizza. Testing the bot with a language other than English, such as French or German, fails. So what you just did was prove that the bot works but that it does not understand foreign languages.
Enabling Autotranslation
The quickest route to enabling the bot to handle languages other than English is to enable autotranslation for everything in the bot. And this is what you will do next.
context: variables: iResult: "nlpresult" pizzaType: "PizzaType" pizzaSize: "PizzaSize" orderNumber: "NUMBER" cancelOrderYesNo: "YesNo" pizzaMenu: "string" cardsRangeStart: "int" autoTranslate: "boolean"Note: Check the spelling, and note the uppercase T in autoTranslate.
Figure 3: Creating and configuring a setVariable state and component
enableAutoTranslation: component: "System.SetVariable" properties: variable: "autoTranslate" value: true
getIntent: component: "System.Intent" properties: variable: "iResult" translate: true confidenceThreshold: 0.7 transitions: actions: Order Pizza: "startOrder" Cancel Pizza: "cancelOrder" Show Menu: "startOrder" Welcome: "welcome" unresolvedIntent: "unresolved"
Figure 4: Pizza menu understanding French and translating to French
What you just did: It may feel like you didn’t do much, but you actually achieved a lot. In configuring a translation service for Oracle Intelligent Bots and enabling autotranslation for the pizza bot, you created a multilanguage bot that understands foreign language input and displays messages in the language detected for a user.
Using Resource Bundles
Although autotranslation and translation services usually do a good job of translating user input and bot messages, they may not do it perfectly every time. To ensure reasonably good bot responses or to preserve business terminology from translation, you can use resource bundles.
Resource bundles are key-value pairs in which the value is the message string to display to the user. Message strings may be provided for each language supported by the bot to control the wording, tone, and voice of the bot response.
For example, in German, users can be addressed as Sie or du. Du is less formal and may be used by bots that are more casual, such as the pizza bot in this example. For formal business bots, you would use Sie. Resource bundles can help ensure that the right form of address is used.
In the following hands-on instructions, you are going to change the printOrder state message from "Your order (#15687) of a ${pizzaType.value} pizza, size ${pizzaSize.value} is complete" to use a resource bundle instead. The German response returned by the resource bundle will use du instead of Sie to ensure a more casual tone for the pizza bot.
Your order (#15687) of a {0} pizza, size {1} is completeNote: The {0} and {1} characters are placeholders that enable you to pass values into the sentence.
Die Bestellung (Nr. 15687) deiner Pizza {0}, in der Größe {1}, kann abgeholt werden
Ta commande (N° 15687) pour une {1} pizza {0} est prêteNote: In the French message, the placeholders {1} and {0} are in a different order than for English and German. Please pay attention to this detail.
variables: iResult: "nlpresult" pizzaType: "PizzaType" pizzaSize: "PizzaSize" orderNumber: "NUMBER" cancelOrderYesNo: "YesNo" pizzaMenu: "string" cardsRangeStart: "int" autoTranslate: "boolean" rb: "resourcebundle"Note the rb context variable at the end of the variables block (in bold).
${rb('printOrderMsg', '${pizzaType.value}', '${pizzaSize.value}')}The text property should look like it does in Figure 5.
Figure 5: printOrder state after change to use resource bundles
askSize: component: "System.List" properties: prompt: "What size do you like your pizza in?" options: "${pizzaSize.type.enumValues}" variable: "pizzaSize" translate: false nlpResultVariable: "iResult"
What you just did: In this part of the hands-on steps, you used a resource bundle to control the bot response message for German and French when printing the order. The English bundle, which also is the default, is used for all languages for which you did not define a language-specific bundle and—of course—for English.
Note: Setting the translate property on the System.Output component of the printOrder state to true will autotranslate the printed message to the user language. In this case, if a resource bundle translated the output message, no autotranslation will be performed. If, however, you try a language for which you don’t have a resource bundle defined, the output message will be autotranslated to the user language.
Additional Considerations
As you’ve seen in this article, autotranslation enables you to build a multilanguage bot from a single base language. In Oracle Intelligent Bots, this base language is English. To control the tone, wording, and voice in bot responses and labels displayed to the user, you use resource bundles. So a first design decision for your bot is when to use resource bundles and when to use autotranslated strings.
A second design decision is to be clear about the languages your bot should support. There are strategies and techniques to limit support to a controlled set of languages. How to do this is documented in “Building Single-Base-Language Chatbots with Oracle Intelligent Bots.”
A third consideration is to plan testing. You should be aware that natural language understanding (intents, utterances, and entities) in Oracle Intelligent Bots is defined and trained in English. This means that when testing your bot, you should try typical sentences used in the foreign language. If the input fails, check with the translation service how the sentence string got translated to English. Then add the English string to the utterances and retrain the bot so it will understand the string the next time.
For example, it is common in German to ask “Kann ich die Karte sehen” to see the menu. Karte is a casual synonym for Speisekarte. If you add this sentence into the message field of the tester and run it, the bot response would be that it cannot understand the request. The reason is that Google translates “Kann ich die Karte sehen” as “Can I see the map.” This refers to a cartographic map and not a menu. However, knowing this and adding “Can I see the map” to the utterances will help solve the problem without any harm or side effect to the behavior of the bot.
A fourth thing to consider is that no multilanguage bot will work perfectly the first time you use it. “Blind testing,” however, can help you improve the quality of your bot. Ask users who speak the language you support through a translation service to try your bot. The users should not know how the bot was developed and what they need to pay attention to (thus “blind”) but should simply be asked to try to work it out.
Conclusion
Artificial intelligence alone doesn’t build you a multilanguage bot. In reality, developing and supporting bots in multiple languages is hard. An easier way to build multilanguage bots is to use a single base language for designing bots and a translation service for supporting non-base-language languages. This article briefly showed you how to use the Google translation service with Oracle Intelligent Bots to create a multilanguage version of the pizza bot featured in previous Oracle Magazine articles.
Next Steps
TRY Oracle Mobile Cloud Enterprise and Oracle Intelligent Bots.
LEARN more about building single-base-language chatbots.
LEARN more about Oracle Mobile Cloud Enterprise and Oracle Intelligent Bots.
DOWNLOAD the bots for this article
OracleMagazine-OnlinePizzaBot3 (starter).
OracleMagazine-OnlinePizzaBot3 (final).
Photography by Panuwat Phimpha, Shutterstock