IBM / watson-nao-robot

Use a robot to answer queries on financial data by integrating with the IBM Watson Assistant service and IBM Watson Studio
https://developer.ibm.com/patterns/robotic-calculations-and-inference-agent
Apache License 2.0
38 stars 63 forks source link
humanoid-robot ibm-cloud ibmcode jupyter-notebook machine-intelligence nao-robot natural-language-processing natural-language-understanding node-red-flow watson-assistant watson-conversation watson-speech watson-studio

Robotic Calculations and Inference Agent

Watson Conversation is now Watson Assistant. Although some images in this code pattern may show the service as Watson Conversation, the steps and processes will still work.

There is a technological revolution taking place in the service industry with the introduction of Robots. The Robots are powered by artifical intelligence and are able to perform the roles of a waiter, customer relationship executive, cognitive assistant etc. The capabilities of the robot can be enhanced exponentially by integrating with cloud capabilities.

This code pattern demonstrates a scenario where the robot can answer queries on financial data by integrating with IBM Watson Assistant service and IBM Watson Studio. We will take you through the end to end flow of steps in building an interactive interface between NAO Robot, Watson Assistant API & Watson Studio.

When the reader has completed this code pattern, they will understand how to:

The intended audience for this code pattern are developers who want to develop a complete analytics solution on Watson Studio with a custom web user interface. This code pattern can be extended for other use cases that integrate Watson Assistant and Watson Studio to enable exchange of information and process natural language along with mining the data to generate insights. For example:

Data set used

The data set used in this code pattern is data/data.csv and originates from a Watson Analytics blog post.

Flow

architecture

  1. The user asks the questions on the dataset to the NAO Robot.
  2. The NAO Robot will convert the speech to text, and will send the text to Node-RED Flow for further processing on the cloud. The results from the processing on the cloud is returned to the NAO Robot through the Node-RED flow.
  3. Node-RED flow sends the converted text to the Watson Assistant API.
  4. The Watson Assistant API takes the text input. The text is analyzed to determine the intent based on the training provided.
  5. The context and state of the conversation is saved to the Cloudant DB to track the conversation flow of the user.
  6. The dataset for analysis is stored in the Object storage.
  7. Data file is taken as input in csv format.
  8. The Jupyter notebook receives the Watson Assistant Service API output from Node-RED using Web Sockets. The notebook processes the data based on the question and generates insights. The insights are sent back to the Node-RED flow using Web Socket.
  9. The Jupyter notebook is powered by Spark.
  10. The Node-RED flow sends the insights to NAO Robot.

Included components

Watch the Video

video

Steps

Follow these steps to setup and run this code pattern. The steps are described in detail below.

  1. Sign up for IBM Cloud
  2. Create IBM Cloud services
  3. Configure Watson Assistant Application
  4. View Watson Assistant Intents, Entities and Dialog
  5. Import the Node-RED flow
  6. Note the websocket URL
  7. Create a new Watson Studio project
  8. Create the notebook
  9. Add the data
  10. Update the notebook with service credentials
  11. Run the notebook
  12. Results sent to the Node Red Flow
  13. Update the NAO Robot Choregraphe Behaviour with service credentials and Node-RED URL
  14. Transfer the behaviour to NAO Robot

1. Sign up for IBM Cloud

Sign up for IBM Cloud. By clicking on create a free account you will get 30 days trial account.

2. Create IBM Cloud services

Create the IBM Cloud services by following the link to use the IBM Cloud UI.

3. Configure Watson Assistant application

4. View Watson Assistant Intents, Entities and Dialog

To view the conversation Intents, Entities and Dialog select the workspace and choose the Intents tab, Entities tab and Dialog tab.

Intents

Intents are purposes or goals expressed in a customer's input, such as answering a question or processing a bill payment. By recognizing the intent expressed in a customer's input, the Watson Assistant service can choose the correct dialog flow for responding to it.

intents

Entities

Entities represent a class of object or a data type that is relevant to a user's purpose. By recognizing the entities that are mentioned in the user's input, the Watson Assistant service can choose the specific actions to take to fulfill an intent.

There are two types of the entities available under the Watson Assistant. One is My entities and another is System entities. Refer below for My Entities.

entities

In this conversation two system entities have been used namely @sys-date and @sys-number. User has to switch on the button before using it.

system entities

Dialog

The dialog uses the intents and entities that are identified in the user's input, plus context from the application, to interact with the user and ultimately provide a useful response.

dialog

In this conversation, the slots feature under dialog has been used to gather multiple informations from the user. Slots for Max dialog is represented in the above image.

5. Import the Node-RED flow

Configure Watson Assistant credentials in Node-RED

Deploy the Node-RED flows by clicking on the Deploy button

First flow

Second flow

6. Note the websocket URL

The websocket URL is ws:///ws/orchestrate where the NODERED_BASE_URL is the marked portion of the URL in the above image.

Note: An example websocket URL for a Node-RED app with name myApp - ws://myApp.mybluemix.net/ws/orchestrate where myApp.mybluemix.net is the NODERED_BASE_URL. The NODERED_BASE_URL can have an additional region information say eu-gb for UK region and NODERED_BASE_URL could be myApp.eu-gb.mybluemix.net.

7. Create a new Watson Studio project

8. Create the notebook

9. Add the data

10. Update the notebook to read the data as DataFrame

Launchh the notebook and select the cell below 2. Read the Data & convert it into Dataframe section in the notebook.

Use Find and Add Data (look for the 10/01 icon) and its Files tab. You should see the file names uploaded earlier. Make sure your active cell is the empty one created earlier. Select Insert to code (below your file name). Click Insert pandas DataFrame from drop down menu.

data frame

Update the websocket URL in the notebook

In the cell below 7. Expose integration point with a websocket client, update the websocket url noted in section 5 in the start_websocket_listener function.

websocket

11. Run the notebook

When a notebook is executed, what is actually happening is that each code cell in the notebook is executed, in order, from top to bottom.

Each code cell is selectable and is preceded by a tag in the left margin. The tag format is In [x]:. Depending on the state of the notebook, the x can be:

12. Results Sent To The Node-Red Flow

The results from Watson Studio are sent to Node-RED based URL which is relayed to NAO Robot. The response time for the answer to the question is approximately 8 seconds.

Let's see a few sample responses:

User: What is the highest profit of Capri Italy in 2007?

NAO: The highest profit of Capri Italy in 2007 is 120,000.

output

13. Update the NAO Robot Choregraphe Behaviour with service credentials and Node-RED URL

NOTE: Choregraphe works only with Python 2x. Please use Python 2x for Choregraphe service.

Open the NAO robot project WatsonNaoRobot.pml. Connect to the NAO robot using the Connection -> Connect menu from Choregraphe.

Update Watson Speech to Text credentials in the Behavior

creds

Update Node-RED URL in the Behaviour

chore

14. Transfer the behaviour to NAO Robot

Save the changes to the NAO robot project (WatsonNaoRobot.pml).

transfer

Troubleshooting

See DEBUGGING.md.

License

This code pattern is licensed under the Apache Software License, Version 2. Separate third party code objects invoked within this code pattern are licensed by their respective providers pursuant to their own separate licenses. Contributions are subject to the Developer Certificate of Origin, Version 1.1 (DCO) and the Apache Software License, Version 2.

Apache Software License (ASL) FAQ