# What is the best way to create a multilingual chatbot?

**URL:** https://forum.rasa.com/t/what-is-the-best-way-to-create-a-multilingual-chatbot/49430
**Category:** Rasa Open Source
**Created:** [November 23, 2021, 9:15am UTC](https://forum.rasa.com/t/what-is-the-best-way-to-create-a-multilingual-chatbot/49430 "2021-11-23T09:15:09Z")
**Posts on this page:** 18
**Page:** 1

<div class="post-metadata">

### Author: ![EvanMath](https://dub1.discourse-cdn.com/flex013/user_avatar/forum.rasa.com/evanmath/32/20580_2.png) [@EvanMath](https://forum.rasa.com/u/EvanMath)
#### Post date: [November 23, 2021, 9:15am UTC](https://forum.rasa.com/t/what-is-the-best-way-to-create-a-multilingual-chatbot/49430/1 "2021-11-23T09:15:09Z")

</div>

Hello everyone,

I am working on a project and I need to build a chatbot that will be used in three different countries, Greece, Italy, Romania. I have seen the [N26](https://www.youtube.com/watch?v=7u28QgFGDp8) video and I have also read some articles like [this](https://www.langnerd.com/multilingual-chatbot-with-rasa-and-heroku-part-2/).

I get these approaches to be different ways (if not please correct me) to develop a multilingual chatbot. But which one is better? What do you suggest? Is there any other tutorial to have a look at?

Thank you in advance.

---

<div class="post-metadata">

### Author: ![ChrisRahme](https://dub1.discourse-cdn.com/flex013/user_avatar/forum.rasa.com/chrisrahme/32/15572_2.png) [@ChrisRahme](https://forum.rasa.com/u/ChrisRahme)
#### Post date: [November 23, 2021, 12:18pm UTC](https://forum.rasa.com/t/what-is-the-best-way-to-create-a-multilingual-chatbot/49430/2 "2021-11-23T12:18:57Z")

</div>

Hello 🙂

Hope these threads will help:

- The different options you have to build a multilingual bot:
  - [Mutlilingual bot (capturing user input and intercepting bot's output for translation) - #2 by ChrisRahme](http://forum.rasa.com/t/mutlilingual-bot-capturing-user-input-and-intercepting-bots-output-for-translation/46142/2)
  - [Multilingual ChatBot - #2 by ChrisRahme](http://forum.rasa.com/t/multilingual-chatbot/46102/2)

- How to utter a response based on the language:
  - [How can i make multi language rasa chatbot having at least two languages? - #8 by ChrisRahme](http://forum.rasa.com/t/how-can-i-make-multi-language-rasa-chatbot-having-at-least-two-languages/16054/8)
  - [Is there any way to switch between two models - #8 by ChrisRahme](http://forum.rasa.com/t/is-there-any-way-to-switch-between-two-models/47913/8)

You can also take a look at my multilingual bot [here](https://github.com/ChrisRahme/fyp-chatbot/) 🙂

* * *

> [@EvanMath](#):
>
> But which one is better? What do you suggest?

It depends on your use-case:

- Do you want the bot to
  - understand all languages but reply in one? (easiest)
  - understand all languages but reply in the one specified by the user? (my approach)
  - understand all languages and reply in the detected language of the last message? (hardest)

- Would the same person usually talk in multiple languages?
  - If yes, you can insert all languages all in the same chatbot/deployment using one of the three options above
    - This saves resources but the chatbot’s files will be bloated due to all the languages and the chatbot may confuse languages

  - If no, consider having three different chatbots/deployments with a language selector on the UI to connect to these different bots
    - This is more expensive in terms of deployment but each chatbot will have a better accuracy and cleaner files

---

<div class="post-metadata">

### Author: ![EvanMath](https://dub1.discourse-cdn.com/flex013/user_avatar/forum.rasa.com/evanmath/32/20580_2.png) [@EvanMath](https://forum.rasa.com/u/EvanMath)
#### Post date: [November 23, 2021, 1:13pm UTC](https://forum.rasa.com/t/what-is-the-best-way-to-create-a-multilingual-chatbot/49430/3 "2021-11-23T13:13:00Z")

</div>

Hey @ChrisRahme, thank you for these threads. I will go through them and come back again.

---

<div class="post-metadata">

### Author: ![EvanMath](https://dub1.discourse-cdn.com/flex013/user_avatar/forum.rasa.com/evanmath/32/20580_2.png) [@EvanMath](https://forum.rasa.com/u/EvanMath)
#### Post date: [November 29, 2021, 1:29pm UTC](https://forum.rasa.com/t/what-is-the-best-way-to-create-a-multilingual-chatbot/49430/4 "2021-11-29T13:29:42Z")

</div>

Hey @ChrisRahme , I went through all these. Really helpful. I appreciate your help.

> [@ChrisRahme](#):
>
> Do you want the bot to
> 
> - understand all languages but reply in one? (easiest)
> - understand all languages but reply in the one specified by the user? (my approach)
> - understand all languages and reply in the detected language of the last message? (hardest)

I will follow your approach in this case. I have a question related to this. If users use the agent via an Android app, do you know if it is possible to let’s say the user defines once his preferred language and the app to send this choice to the agent every time the user logs in?

> [@ChrisRahme](#):
>
> Would the same person usually talk in multiple languages?
> 
> - If yes, you can insert all languages all in the same chatbot/deployment using one of the three options above
> - This saves resources but the chatbot’s files will be bloated due to all the languages and the chatbot may confuse languages
> 
> - If no, consider having three different chatbots/deployments with a language selector on the UI to connect to these different bots
> - This is more expensive in terms of deployment but each chatbot will have a better accuracy and cleaner files

Well, this is something I don’t know for sure but I assume that each user will talk only in one language. Your approach follows the first bullet from the above, correct?

One last question, in your domain file you have implemented some responses to any language and others (like faq) only in one, what is the purpose of this? My understanding is that I have to implement every response to every language I will use.

---

<div class="post-metadata">

### Author: ![ChrisRahme](https://dub1.discourse-cdn.com/flex013/user_avatar/forum.rasa.com/chrisrahme/32/15572_2.png) [@ChrisRahme](https://forum.rasa.com/u/ChrisRahme)
#### Post date: [November 29, 2021, 1:47pm UTC](https://forum.rasa.com/t/what-is-the-best-way-to-create-a-multilingual-chatbot/49430/5 "2021-11-29T13:47:15Z")

</div>

> [@EvanMath](#):
>
> If users use the agent via an Android app, do you know if it is possible to let’s say the user defines once his preferred language and the app to send this choice to the agent every time the user logs in?

Nice idea 🙂

What you could do is store that preference somewhere on the phone/device and send it via a hidden payload every time the user opens the app.

You surely have a `send()` function to send you message. At the app startup, you could send something like this:

```auto
send('/set_language{"language": "' + saved_language + '"}')

```

Of course this means you’d need to have an intent `set_language` with at least two examples with entities, and have the slot autofilled.

This could also double up as a way to let the bot start the conversation, if you do

```auto
send('/greet{"language": "' + saved_language + '"}')

```

with a rule to greet back.

* * *

> [@EvanMath](#):
>
> Your approach follows the first bullet from the above, correct?

In my country, people usually mix up 3 languages when they talk, even in a same sentence. So my approach was to first ask the user which language they want, then only reply in this language (until user asks to change it again).

But the user will still be able to understand all languages. If you take a look at [some of my bot’s NLU data](https://github.com/ChrisRahme/fyp-chatbot/blob/main/data/nlu/account_management.yml), you can see 5 languages in a same intent, sometimes all mixed up in one example.

* * *

> [@EvanMath](#):
>
> in your domain file you have implemented some responses to any language and others (like faq) only in one, what is the purpose of this? My understanding is that I have to implement every response to every language I will use.

Most responses come from the custom actions, which dispatches the message according the language slot (this can now be done without custom actions via [conditional response variations](https://rasa.com/docs/rasa/responses#conditional-response-variations)).

But, basically, not all responses are implemented because the bot is unfinished 🙂 This bot was just a proof-of-concept for a bot that is privatized by a company.

---

<div class="post-metadata">

### Author: ![EvanMath](https://dub1.discourse-cdn.com/flex013/user_avatar/forum.rasa.com/evanmath/32/20580_2.png) [@EvanMath](https://forum.rasa.com/u/EvanMath)
#### Post date: [November 29, 2021, 1:58pm UTC](https://forum.rasa.com/t/what-is-the-best-way-to-create-a-multilingual-chatbot/49430/6 "2021-11-29T13:58:08Z")

</div>

Alright, you clarified everything 😃 Once again, thank you for your help.

---

<div class="post-metadata">

### Author: ![ChrisRahme](https://dub1.discourse-cdn.com/flex013/user_avatar/forum.rasa.com/chrisrahme/32/15572_2.png) [@ChrisRahme](https://forum.rasa.com/u/ChrisRahme)
#### Post date: [November 29, 2021, 2:36pm UTC](https://forum.rasa.com/t/what-is-the-best-way-to-create-a-multilingual-chatbot/49430/7 "2021-11-29T14:36:47Z")

</div>

Glad to be of help 🙂

---

<div class="post-metadata">

### Author: ![EvanMath](https://dub1.discourse-cdn.com/flex013/user_avatar/forum.rasa.com/evanmath/32/20580_2.png) [@EvanMath](https://forum.rasa.com/u/EvanMath)
#### Post date: [December 8, 2021, 10:48am UTC](https://forum.rasa.com/t/what-is-the-best-way-to-create-a-multilingual-chatbot/49430/8 "2021-12-08T10:48:39Z")

</div>

Hey @ChrisRahme , I am coming back to this because for some reason the tracker seems to have stopped identifying the `language` entity on the very first user’s message but works fine with the buttons. The thing is that two days ago it worked just fine.

I have followed your chatbot’s implementation.

```auto
class ActionUtterGreet(Action):
    def name(self):
        return "action_utter_greet"

    def run(self, dispatcher, tracker, domain):
        announce(self, tracker)
        followup_action = "action_utter_ask_mood"
        text = get_text_from_lang(
            tracker,
            [
                "Hey there! I am your Alameda personal assistant powered by artificial intelligence.",
                "Γειά, είμαι ο προσωπικός βοηθός του Alameda."
            ]
        )

        if tracker.get_slot("language") is None or not tracker.get_slot("language"):
            followup_action = "action_utter_ask_language"

        print("\nBOT:", text)
        dispatcher.utter_message(text=text)
        return [FollowupAction(followup_action)]

```

It dispatches correctly the `text` from this function e.g. `Hey there! I am your Alameda personal assistant powered by artificial intelligence.` but when it comes here

```auto
if tracker.get_slot("language") is None or not tracker.get_slot("language"):
            followup_action = "action_utter_ask_language"

```

seems like the language isn’t being set.

Any ideas?

---

<div class="post-metadata">

### Author: ![ChrisRahme](https://dub1.discourse-cdn.com/flex013/user_avatar/forum.rasa.com/chrisrahme/32/15572_2.png) [@ChrisRahme](https://forum.rasa.com/u/ChrisRahme)
#### Post date: [December 8, 2021, 12:09pm UTC](https://forum.rasa.com/t/what-is-the-best-way-to-create-a-multilingual-chatbot/49430/9 "2021-12-08T12:09:49Z")

</div>

> [@EvanMath](#):
>
> seems like the language isn’t being set.

So it’s probably the case that the language wasn’t even set before (`get_text_from_lang()` defaults to the first entry in the list if no language was detected).

Anyway, you’re saying the entity is detected when entered via buttons, but not via text?

---

<div class="post-metadata">

### Author: ![EvanMath](https://dub1.discourse-cdn.com/flex013/user_avatar/forum.rasa.com/evanmath/32/20580_2.png) [@EvanMath](https://forum.rasa.com/u/EvanMath)
#### Post date: [December 8, 2021, 12:44pm UTC](https://forum.rasa.com/t/what-is-the-best-way-to-create-a-multilingual-chatbot/49430/10 "2021-12-08T12:44:41Z")

</div>

> [@ChrisRahme](#):
>
> Anyway, you’re saying the entity is detected when entered via buttons, but not via text?

Exactly.

> [@ChrisRahme](#):
>
> So it’s probably the case that the language wasn’t even set before (`get_text_from_lang()` defaults to the first entry in the list if no language was detected).

I agree.

---

<div class="post-metadata">

### Author: ![ChrisRahme](https://dub1.discourse-cdn.com/flex013/user_avatar/forum.rasa.com/chrisrahme/32/15572_2.png) [@ChrisRahme](https://forum.rasa.com/u/ChrisRahme)
#### Post date: [December 8, 2021, 12:55pm UTC](https://forum.rasa.com/t/what-is-the-best-way-to-create-a-multilingual-chatbot/49430/11 "2021-12-08T12:55:37Z")

</div>

> [@EvanMath](#):
>
> Exactly.

Then it’s just a regular entity recognition problem. Do you have enough examples?

Do you have synonyms (see [this](https://github.com/ChrisRahme/fyp-chatbot/blob/main/data/data.json#L163) and [this](https://rasa.com/docs/rasa/training-data-format#synonyms)) set for the languages and/or value annotation like [the following](https://github.com/ChrisRahme/fyp-chatbot/blob/main/data/nlu/languages.yml#L26)?

```yaml
- intent: set_language
  examples: |
    - change language to [english]{"entity": "language", "value": "English"}
    - plz speak [greek]{"entity": "language", "value": "Greek"}
    - Μπορείς να μιλάς [ελληνικά]{"entity": "language", "value": "Greek"}
    - change lang to [en]{"entity": "language", "value": "English"}
etc...

```

---

<div class="post-metadata">

### Author: ![EvanMath](https://dub1.discourse-cdn.com/flex013/user_avatar/forum.rasa.com/evanmath/32/20580_2.png) [@EvanMath](https://forum.rasa.com/u/EvanMath)
#### Post date: [December 8, 2021, 1:25pm UTC](https://forum.rasa.com/t/what-is-the-best-way-to-create-a-multilingual-chatbot/49430/12 "2021-12-08T13:25:00Z")

</div>

> [@ChrisRahme](#):
>
> Do you have synonyms

I haven’t created them yet.

But, I don’t understand, how does the `intent: set_language` relates to `intent: greet`?

---

<div class="post-metadata">

### Author: ![ChrisRahme](https://dub1.discourse-cdn.com/flex013/user_avatar/forum.rasa.com/chrisrahme/32/15572_2.png) [@ChrisRahme](https://forum.rasa.com/u/ChrisRahme)
#### Post date: [December 8, 2021, 6:02pm UTC](https://forum.rasa.com/t/what-is-the-best-way-to-create-a-multilingual-chatbot/49430/13 "2021-12-08T18:02:22Z")

</div>

> [@EvanMath](#):
>
> how does the `intent: set_language` relates to `intent: greet`?

`set_language` is for when the user asks to set the language, which should run `action_set_language`.

`greet` will run `action_greet`, which will greet the user back and then run `action_ask_language` **if the `language` slot is not already set**.

`action_ask_language` will ask the user to choose a language. Logically, the user will answer with the `set_language` intent, which should run `action_set_language`.

---

<div class="post-metadata">

### Author: ![EvanMath](https://dub1.discourse-cdn.com/flex013/user_avatar/forum.rasa.com/evanmath/32/20580_2.png) [@EvanMath](https://forum.rasa.com/u/EvanMath)
#### Post date: [December 8, 2021, 7:22pm UTC](https://forum.rasa.com/t/what-is-the-best-way-to-create-a-multilingual-chatbot/49430/14 "2021-12-08T19:22:49Z")

</div>

Ok, I see. Then I misunderstood the flow 😅

I thought that when the user greets in greek the agent is able to understand it and based on that to choose the corresponded answer from the custom action.

But, now I think this is not the case and the language should be set at the very beginning either the user asks for it or in the case of an app somehow the agent get informed to use a specific language, is that correct?

---

<div class="post-metadata">

### Author: ![ChrisRahme](https://dub1.discourse-cdn.com/flex013/user_avatar/forum.rasa.com/chrisrahme/32/15572_2.png) [@ChrisRahme](https://forum.rasa.com/u/ChrisRahme)
#### Post date: [December 8, 2021, 8:09pm UTC](https://forum.rasa.com/t/what-is-the-best-way-to-create-a-multilingual-chatbot/49430/15 "2021-12-08T20:09:13Z")

</div>

That’s correct 🙂

The bot does not detect the language.

> [@ChrisRahme](#):
>
> Mutlilingual bot (capturing user input and intercepting bot’s output for translation) - #2 by ChrisRahme

You went with approach #1 from that thread. If you want language detection you should go woth #2 and create a custom pipeline component that detects the language and sets the language slot on each message.

---

<div class="post-metadata">

### Author: ![EvanMath](https://dub1.discourse-cdn.com/flex013/user_avatar/forum.rasa.com/evanmath/32/20580_2.png) [@EvanMath](https://forum.rasa.com/u/EvanMath)
#### Post date: [December 8, 2021, 8:47pm UTC](https://forum.rasa.com/t/what-is-the-best-way-to-create-a-multilingual-chatbot/49430/16 "2021-12-08T20:47:53Z")

</div>

So, the `get_text_from_lang()` doesn’t make sense to keep it in the case that I don’t detect the language via the pipeline.

---

<div class="post-metadata">

### Author: ![ChrisRahme](https://dub1.discourse-cdn.com/flex013/user_avatar/forum.rasa.com/chrisrahme/32/15572_2.png) [@ChrisRahme](https://forum.rasa.com/u/ChrisRahme)
#### Post date: [December 8, 2021, 8:52pm UTC](https://forum.rasa.com/t/what-is-the-best-way-to-create-a-multilingual-chatbot/49430/17 "2021-12-08T20:52:34Z")

</div>

`get_text_from_lang()` is just a function that returns the correct output of the given list according to the `language` slot 🙂

You can keep it or do a bunch of `if language == '...'`. But anyway, you don’t need custom actions for that anymore, you can use [Conditional Response Variations](https://rasa.com/docs/rasa/responses#conditional-response-variations) instead:

```auto
responses:
  utter_greet:
    - condition:
        - type: slot
          name: language
          value: greek
      text: "Γειά, είμαι ο προσωπικός βοηθός του Alameda."
    - text: "Hey there! I am your Alameda personal assistant powered by artificial intelligence."

```

---

<div class="post-metadata">

### Author: ![EvanMath](https://dub1.discourse-cdn.com/flex013/user_avatar/forum.rasa.com/evanmath/32/20580_2.png) [@EvanMath](https://forum.rasa.com/u/EvanMath)
#### Post date: [December 8, 2021, 9:02pm UTC](https://forum.rasa.com/t/what-is-the-best-way-to-create-a-multilingual-chatbot/49430/18 "2021-12-08T21:02:23Z")

</div>

Yes this is true. I started using it. Thank you @ChrisRahme for your time.
