Subscribe

Share

Application Development

Parlez-Vous Français? Your Bot Does.

Build multilanguage bots with Oracle Intelligent Bots.

By Frank Nimphius

July/August 2018

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:

  • Native language bots use a single language for utterances, entities, prompts, titles, descriptions, and labels. To support multiple languages, you create multiple separate bots, each using a language-specific natural-language-processing engine for the intent resolution and entity extraction that you train and test with language-specific utterances. Building native language bots is a viable approach if there are not too many languages to support with a bot and if developers have the required languages in their skill portfolios.
  • Single-base-language bots serve multiple languages from a single base language for natural language understanding and entity extraction as well as for designing prompts, titles, descriptions, and labels during development. A translation service is used at runtime to detect and translate foreign language user input into the base language for intent resolution and entity extraction. Single-base-language bots are suitable if a bot needs to support a larger set of 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:

  1. Open a browser, and access the Oracle Mobile Cloud Enterprise home page.
  2. Authenticate with the user credentials you defined when you provisioned the cloud service.
  3. Click the hamburger icon in the upper left to open the Oracle Mobile Cloud Enterprise menu.
  4. Click the Bots menu item (shown in Figure 1), which opens the Oracle Intelligent Bots dashboard in a separate browser window or tab.

    chatbots figure 1

    Figure 1: Oracle Mobile Cloud Enterprise with Oracle Intelligent Bots selected

  5. Click the Import Bot button in the upper right of the dashboard.
  6. In the opened dialog box, navigate to the location to which you extracted the downloaded zip file.
  7. Select the OracleMagazineOnlinePizzaBot3.zip import file, and click Open.
  8. Close the upload confirmation dialog box, by clicking the X at the right side.
  9. Keep the browser window open.

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.

  1. Open a new browser window or tab.
  2. Go to the Google developer page to request a credential key, using your Google account username and password.
  3. On the Google APIs & Services dashboard, click the ENABLE APIS AND SERVICES link and select the Cloud Translation API option.
  4. Back in the dashboard, select the Credentials menu option to create a credential key. From the list shown in Figure 2, select the API key option. When the key is displayed in the opened dialog box, click Close to get back to the dashboard.

    chatbots figure 2

    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.

  1. In the Oracle Intelligent Bots dashboard, select the menu icon () in the upper right corner and choose Translation Services.
  2. Click the + Service button and choose Google for Service Type. Enter the following REST URL in the Base URL field:
    https://translation.googleapis.com/language/translate/v2 
    
  3. Copy and paste your Google credential key from the Google developer website into the Authorization Token field, and click Save.

Running the Sample Bot

Before adding translations, let’s run the sample bot to see its current functionality and ability to understand foreign languages.

  1. Open the browser window or tab with the Oracle Intelligent Bots dashboard in it.
  2. If you already have existing bots defined in your environment, chances are good that you won’t immediately spot the downloaded bot. To find the bot, type OracleMagazine into the Filter field above the green New Bot + icon.
  3. Click the OracleMagazineOnlinePizzaBot3 bot to open it.
  4. Click Train (at the top right of the screen). Before you click it, Train should show an exclamation point, because the bot is not yet trained after the download and import. After you click Train, a dialog box appears confirming that the bot is trained. Training the model is required for the bot to understand free text input.
    Note: You cannot import two bots with the same name. If you need to import the starter bot more than once or if you share an Oracle Intelligent Bots instance, rename any previous imports of the starter bot before importing the new bot. You can rename a bot by opening it, clicking the settings icon (), renaming the bot, and exiting the bot.
  5. Run the embedded bot tester by clicking the tester icon () in the upper right.
  6. Type Hi into the Message field, and click Send.
  7. Type Show me the menu into the Message field, and click Send.
  8. Choose a pizza, and complete the order process.
  9. Click the Reset button, at the top right of the embedded bot tester.
  10. Type Montrez moi le menu, and click Send.
  11. The bot should reply with Sorry, I did not understand the request. Please try again.
  12. Click Reset.
  13. Close the tester window by clicking the tester icon.

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.

  1. Click the settings icon () in the left menu.
  2. On the General tab, change the Translation Service select list value from None to Google.
  3. Click the flow icon () in the same menu to open the dialog flow. The dialog flow is defined in OBotML, a markup language for defining bot conversation flows.
  4. Create a new context variable autotranslate of type "boolean" in the Context -> Variable section:
    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.
  5. Click the green + Components button at the top of the dialog flow.
  6. Select Variables in the opened Select a Component Type dialog box.
  7. Click the Set variable menu item.
  8. Select initializeMenu from the Insert After select box, and toggle the Remove Comments button on (as shown in Figure 3).

    chatbots figure 3

    Figure 3: Creating and configuring a setVariable state and component

  9. Click Apply.
  10. In the dialog flow editor, change the name of the added setVariable state to enableAutoTranslation and set the variable property to "autotranslate" and the value property to true.
      enableAutoTranslation:
        component: "System.SetVariable"
        properties:
          variable: "autoTranslate"
          value: true
    
  11. Ensure that the enableAutoTranslation state was added above the setCardsRange state. If not, move it by copying and pasting the enableAutoTranslation state.
  12. Click the Validate link in the blue menu bar on top. If validation fails, verify the indentation and syntax. The enableAutoTranslation label should be indented exactly the same as the setCardsRangeStart label below.
  13. Click the green + Components button.
  14. Select Language from the opened Select a Component Type dialog box.
  15. Click the Detect language menu item.
  16. Ensure that Remove Comments is still enabled, and select enableAutoTranslation from the Insert After select list.
  17. Navigate to the getIntent state, below setCardsRangeState. Add a translate property under the variable property as highlighted in the code:
    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" 
    
  18. Run the embedded bot tester by clicking on the tester () icon.
  19. Type Bonjour into the Message field, and click Send.
  20. Type Montrez moi le menu into the Message field, and click Send.
  21. You should see a bot response as shown in Figure 4.

    chatbots figure 4

    Figure 4: Pizza menu understanding French and translating to French

  22. Choose a pizza, and then complete the order process.
  23. Try to memorize the printed order output, because this is what you are going to customize in a next set of steps.
  24. Click Reset.
  25. Now type Hallo in the Message field and click Send to test German.
  26. Type Kann ich bitte die Speisekarte sehen to get the menu in German.
  27. Choose a pizza, and complete the order process.
  28. Try to memorize the printed order output, because this is what you are going to customize in a next set of steps.
  29. Click Reset.
  30. Click the tester icon () to close the tester.

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.

  1. Select the Resource Bundles menu item () from the left menu to open the resource bundles designer page.
  2. Click the green + Bundle button.
  3. The first entry is a key and a message string for the default language, English.
  4. Enter printOrderMsg as a value of the Key field. The value must be unique and is used in all translation bundles.
  5. In the Text field, enter
    Your order (#15687) of a {0} pizza, size {1} is complete
    
    Note: The {0} and {1} characters are placeholders that enable you to pass values into the sentence.
  6. Click the Create Entry button.
    Note: You just created a first message bundle string. In a real bot project, you would now add more messages for the default language by clicking the + Key button.
  7. Click the + Language button to create a translation. Enter printOrderMsg in the Key field in the Create Entry dialog box.
  8. Enter de in the Language field.
  9. In the Text field, enter
    Die Bestellung (Nr. 15687) deiner Pizza {0}, in der Größe {1}, kann abgeholt werden
    
  10. Click the Create Entry button.
  11. Click the + Language button a second time to add a French translation. Enter printOrderMsg in the Key field in the Create Entry dialog box.
  12. Enter fr, for French, in the Language field.
  13. In the Text field, enter
    Ta commande (N° 15687) pour une {1} pizza {0} est prête
    
    Note: 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.
  14. Click Create Entry.
  15. Click the flow icon () to open the dialog flow.
  16. Create a new context variable rb of type "resourcebundle" at the end of Context -> Variables. The variables section should now look like this:
      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).
  17. Navigate to the printOrder state (which should be on line 157 or close to it), and change the text property value to
    ${rb('printOrderMsg', '${pizzaType.value}', '${pizzaSize.value}')}
    
    The text property should look like it does in Figure 5.

    chatbots figure 5

    Figure 5: printOrder state after change to use resource bundles

  18. Insert an additional property translate below the keepTurn property, and set its value to false.
  19. Navigate to the askSize state (which should be on line 149 or close to it).
  20. Insert a new property translate with a value of false into the System.List component properties. See the code fragment below with the translate property highlighted in bold:
      askSize:
        component: "System.List"
          properties:
            prompt: "What size do you like your pizza in?"
            options: "${pizzaSize.type.enumValues}"     
            variable: "pizzaSize"
            translate: false
            nlpResultVariable: "iResult"    
    
  21. Click the tester icon ().
  22. In the Message field, enter Kann ich bitte die Speisekarte sehen, and click Send.
    Note: The pizza bot enables you to ask for the menu directly, without saying “Hallo” up front. Of course, starting your bot conversation with “Hallo” does still work.
  23. Choose a pizza and then a pizza size.
    Note: The pizza size now shows in English (small, medium, large). This is because you set the translate property to false. For this sample, “small,” “medium,” and “large” are considered business terms that should not be translated.
  24. Note the different output message compared to the autotranslated message before.
  25. Reset the tester, by clicking the Reset button.
  26. Type Montrez moi le menu into the Message field, and click Send.
  27. Choose a pizza and a pizza size.
  28. Again, note the changed output message for French compared to the autotranslated version earlier.
  29. Reset the tester, by clicking Reset.
  30. Finally, enter Show me the menu into the Message field and click Send. This works as before, but it also uses the resource bundle to print the order.

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