Tutorial: create or update a chatbot for ARI#

🏁 Goal of this tutorial

By the end of this tutorial, you will know how to create a simple chatbot and run different chatbots using ROS

Pre-requisites#

Step 1: creating a new RASA model#

Let’s create a new RASA model for the Spanish language, so the robot can converse both in English and Spanish. We also want the robot to understand, in Spanish, “what is the capital of Germany?”.

First of all create a new RASA model directory, or if prefered, make a copy of the existing English chatbot. To make it easier, you can copy the folder to your machine from the robot. The new chatbot folder name should comply with the i18n language standard, e.g. es for Spanish.

scp -r pal@ari-0c:/home/pal/.pal/chatbot_cfg/rasa_chatbot_chitchat/en en/

cp -r en/ es/

You can directly translate all the English content of the data/ folder to Spanish, if you wish the chatbot to be exactly the same as in English. But as we want to add a new question for the robot, we need to do more modifications.

As described in Dialogue management, each language model has a series of skills, for example:

  • ari_chitchat: about general questions

  • ari_diagnostics: to ask about robot specific diagnostics questions

The question you want to ask may not fit either category. In this case, you can add a new skill, geography, so that in the future you can add futher similar questions for the robot.

Copy the same structure:

cp -r es/ari_chitchat es/geography

Inside the data/ folder, update tne nlu.yml to include example ways to ask the question. Similar to chitchat, it is recommended to group all questions together, so whenever asks a geography related question the robot always replies. Intent name could be: geography/germany

version: "3.1"
nlu:
- intent: geography/germany
  examples: |
    - cuál es la capital de Alemania?
    - capital de Alemania?

Update domain.yml by declaring the intent and example responses. As we are generalizing intent name it is enough to declare it once as geography.

It is important that the response follows the structure of utter_INTENT_NAME. It is recommended that intent and response names are language-independent.

version: '3.1'
intents:
- geography
    is_retrieval_intent: true
responses:
  utter_geography/germany:
    - text: La capital es Berlin!
    - text: Berlin es la ciudad capital

Finally set-up the rule.yml so whenever a geography intent is detected, its respective response is given:

version: "3.1"

rules:

- rule: response to geography question
  steps:
  - intent: geography
  - action: utter_geography

You have completed the main chatbot, now it is time to train it! For this pass the newly created chatbot back to the robot with:

scp -r es/ pal@ari-0c:/home/pal/.pal/chatbot_cfg/rasa_chatbot_chitchat

Step 2: Train the new RASA model#

There are two ways to train the new model.

  1. Modify the chatbot_config.yaml to train the default language model on boot.

ssh pal@ari-0c

vi /home/pal/.pal/chatbot_cfg/chatbot_config.yaml
chatbot_module: pal_chatbot_rasa.chatbot_rasa
chatbot_name: rasa
params:
  default_language: es_ES #set it to Spanish
  train_on_boot: True #indicate True so it trains the default language on boot
  1. Use the ROS action /train_chatbot. From inside the robot:

rostopic pub /train_chatbot/goal chatbot_msgs/ChatbotTrainActionGoal "header:
  seq: 0
  stamp:
    secs: 0
    nsecs: 0
  frame_id: ''
goal_id:
  stamp:
    secs: 0
    nsecs: 0
  id: ''
goal:
  lang: 'es_ES'"

Monitor the ROS action result to know when the training has completed. You can verify by checking that a new model has been created in /home/pal/.pal/chatbot_cfg/rasa_chatbot_chitchat/es/models/es.tar.gz.

Step 3: Change the RASA chatbot language#

If previously the chatbot was in English, change it to Spanish language so it loads the latest model, using the /manage_chatbot ROS action.

rostopic pub /manage_chatbot/goal chatbot_msgs/ChatbotServerActionGoal "header:
  seq: 0
  stamp:
    secs: 0
    nsecs: 0
  frame_id: ''
goal_id:
  stamp:
    secs: 0
    nsecs: 0
  id: ''
goal:
  language: 'es_ES'"

Note it takes some time to load a new model, monitor again the ROS action result to make sure when it has finalized loading.

Confirm that currently the Spanish chatbot is running by calling the /active_chatbot ROS service:

rosservice call /active_chatbot "{}"
bot_name: 'es'

Step 4: Test your chatbot#

Test the new chatbot by speaking to the robot and asking the questions you have included. The robot should say the expected responses. Remember to make sure the Speech Recognizer is running in Spanish. As explained in How-to: Automatic Speech Recognition (ASR) on ARI, you can change the language with:

rostopic pub /start_asr/goal hri_msgs/StartASRActionGoal "header:
  seq: 0
  stamp:
    secs: 0
    nsecs: 0
  frame_id: ''
goal_id:
  stamp:
    secs: 0
    nsecs: 0
  id: ''
goal:
  language: 'es_ES'"

If you wish to test the chatbot separately from the speech recognition, you can publish the expected input:

rostopic pub /humans/voices/anonymous_speaker/speech hri_msgs/LiveSpeech "header:
  seq: 0
  stamp:
    secs: 0
    nsecs: 0
  frame_id: ''
incremental: ''
final: 'capital de Alemania?'
confidence: 0.0"

The text-to-speech output can be monitored with:

rostopic echo /tts/goal

Next steps#