Adeel Javed - Internet of Things

Pi - The Personal Assistant (Raspberry Pi + IBM® Watson) - Part 2

This tutorial is the second in series on developing a Personal Assistant (Pi) using Raspberry Pi and IBM® Watson. Pi will take a picture of an object placed in front of it, classify the picture, provide classification with a score and play the results back to the user.

Note: All tutorials in this series are independent of each other, they simply use the same concepts.

Learning Objectives

At the end of this tutorial you will be able to:

  • Play audio on Raspberry Pi using Java
  • Take pictures from Raspberry Pi Camera using Java
  • Invoke Watson's Visual Recognition service from Java
  • Invoke Watson's Text to Speech service from Java

Hardware

Raspberry Pi 3 (RPi3) Model B, Raspberry Pi Camera, Speaker (optional)

Software

Java 8, IBM® Bluemix, JRPiCam Library

Design

This section provides a high-level design of how Pi - The Personal Assistant will recognize objects. When you run the code from a terminal a new interaction is started and following activities happen.

  • Pi greets the user
  • Pi waits for 3 seconds
  • Pi takes a picture of object placed in front of the camera
  • Pi invokes Watson Visual Recognition service, passes the PNG file as input
  • IF Watson is able to classify the image THEN
    • Pi creates a response based on results
    • Pi invokes Watson Text to Speech service
    • Pi plays the response back to user
  • ELSE Pi says "Sorry, I could not recognize the object"

CodifyThings - Pi - Personal Assistant - Raspberry Pi - IBM Watson

IBM® Watson Setup

Step 1: Signup for Bluemix.

Step 2: Login to Bluemix, you will be redirected to the Console.

CodifyThings - Pi - Personal Assistant - Raspberry Pi - IBM Watson

Step 3: Click on Watson.

Step 4: Click on Get started now! + to create a new service.

CodifyThings - Pi - Personal Assistant - Raspberry Pi - IBM Watson

Step 5: From all Watson services, click on Visual Recognition service.

CodifyThings - Pi - Personal Assistant - Raspberry Pi - IBM Watson

Step 6: Enter Service name and Credentials name (or leave as-is). You can leave the service unbound and select a Pricing Plan that suits you. Click on Create.

CodifyThings - Pi - Personal Assistant - Raspberry Pi - IBM Watson

Step 7: Your Visual Recognition service is ready for use.

CodifyThings - Pi - Personal Assistant - Raspberry Pi - IBM Watson

Step 8: Go back to Catalog > Watson and click on + to create Text to Speech service.

Step 9: From all Watson services, click on Text to Speech service.

CodifyThings - Pi - Personal Assistant - Raspberry Pi - IBM Watson

Step 10: Enter Service name and Credentials name (or leave as-is). You can leave the service unbound and select a Pricing Plan that suits you. Click on Create.

CodifyThings - Pi - Personal Assistant - Raspberry Pi - IBM Watson

Step 11: Your Text to Speech service is ready for use.

CodifyThings - Pi - Personal Assistant - Raspberry Pi - IBM Watson

 

 

Raspberry Pi Setup

Step 1: Download the code from Github repository.

Step 2: Latest versions of Raspberry Pi comes pre-installed with Java, so you only need to download required dependencies.

Step 3: Open the Constants.java file in com.codifythings.personalassistant package and copy-paste credentials from Watson services that you created.

Step 4: Run the main class com.codifythings.personalassistant.PersonalAssistant.

Final Product

Next Steps

This wraps up the tutorial. There are quite a few enhancements that you can make to this module e.g. build a robot that finds specific objects or a security camera that only records when there is a person in the vicinity.

Citations


Adeel Javed - Internet of Things

Pi - The Personal Assistant (Raspberry Pi + IBM® Watson) - Part 1

This tutorial is the first in series on developing a Personal Assistant (Pi) using Raspberry Pi and IBM® Watson. Pi will listen to your commands, analyze the command to see if you are asking about the weather or not if you are then it will search for weather data and playback the response.

Learning Objectives

At the end of this tutorial you will be able to:

  • Record and play audio on Raspberry Pi using Java
  • Invoke Watson's Speech to Text service from Java
  • Invoke Watson's Text to Speech service from Java
  • Invoke Watson's Natural Language Classifier service from Java
  • Fetch weather data from Forecast.io

Hardware

Raspberry Pi 3 (RPi3) Model B, Speaker, USB Mic

Software

Java 8, IBM® Bluemix, Forecast.io

Design

This section provides a high-level design of Pi - The Personal Assistant. When you run the code from a terminal a new interaction is started and following activities happen based on user command.

  • Pi greets the user
  • Pi listens to user command for 2 seconds
  • Pi creates a WAV file of user command
  • Pi invokes Watson Speech to Text service, passes the WAV file as input, the service converts it into text
  • IF user did not say anything THEN
    • Pi says "Sorry, I did not understand that", and ends the interaction
  • Pi passes the converted text to Watson Natural Language Classifier service. This service gives you the ability to train Watson. Once trained, Watson can analyze natural language text and provide a confidence level that tells you how relevant the text is to your trained data. So, instead of hard-coding a few conditions that just check if a specific word is present or not, Watson learns and then provides a confidence level.
  • IF classification confidence level is less than 50% THEN
    • Pi says "Sorry, I did not understand that", and ends the interaction
  • Pi looks up weather data from Forecast.io (for now latitude/longitude for Chicago is hard coded)
  • Pi creates a response, generates a WAV file, plays it back to the user and ends the interaction

IBM® Watson Setup

Step 1: Signup for Bluemix.

Step 2: Login to Bluemix, you will be redirected to the Console.

Step 3: Click on Watson.

Step 4: Click on Get started now! + to create a new service.

Step 5: From all Watson services, click on Speech to Text service.

Step 6: Enter Service name and Credentials name (or leave as-is). You can leave the service unbound and select a Pricing Plan that suits you. Click on Create.

Step 7: Your Speech to Text service is ready for use.

Step 8: Go back to Catalog > Watson and click on + to create Text to Speech service.

Step 9: From all Watson services, click on Text to Speech service.

Step 10: Enter Service name and Credentials name (or leave as-is). You can leave the service unbound and select a Pricing Plan that suits you. Click on Create.

Step 11: Your Text to Speech service is ready for use.

Step 12: Go back to Catalog > Watson and click on + to create Natural Language Classifier service.

Step 13: From all Watson services, click on Natural Language Classifier service.

Step 14: Enter Service name and Credentials name (or leave as-is). You can leave the service unbound and select a Pricing Plan that suits you. Click on Create.

Step 15: Your Natural Language Classifier service is ready for use.

Step 16: All required IBM® Watson services are now ready, but before you can use the Natural Language Classifier service you need to train IBM® Watson to properly classify text i.e. Speech to Text service will convert everything that the user says into text, so how do you find if it is relevant or not. Open your newly created Natural Language Classifier service and click on Manage tab. From Manage tab click on Access the beta toolkit button. This will open the toolkit (you might be required to sign in again and authorize access to your user).

Step 17: Under Classifiers click on Add training data button.

Step 18: Next click on Upload training data button from the top right menu.

Step 19: Select the CSV file that contains your training data (this application uses a slightly modified version of the file provided by IBM, you can download it from here).

Step 20: Once all training data has been imported click on Create classifier button.

Step 21: Enter a Name for your classifier and click on Create button.

Step 22: You will start seeing messages that training is in progress (this process might take a few minutes).

Step 23: Once training is complete you will see the following message, that means your Natural Language Classifier service is trained and ready to be used.

Raspberry Pi Setup

Step 1: Download the code from Github repository.

Step 2: Latest versions of Raspberry Pi comes pre-installed with Java, so you only need to download required dependencies.

Step 3: Open the Constants.java file in com.codifythings.personalassistant package and copy-paste credentials from Watson services that you created. You also need to change the classifier id that you saw in the final step of the last section.

Step 4: Run the main class com.codifythings.personalassistant.PersonalAssistant.

Final Product

Next Steps

This wraps up the tutorial. You can easily add more functionality e.g. traffic information - how long will it take me to get to the office. You simply need to train Watson for additional classifications and based on the classification perform a search.

Another future enhancement could be how this interaction gets triggered. For now, the code was manually run from the command line, but you could improve that by using a switch, a motion sensor or even facial recognition.

Citations


Adeel Javed - How To Empower Knowledge Workers Using Cognitive BPM

How To Empower Knowledge Workers Using Cognitive BPM

Note: This article was originally published on my previous blog ProcessRamblings.com.

Throughout the lifecycle of a business process knowledge workers are required to make decisions based on their domain knowledge.

IBM® Watson™ is an artificially intelligent computer system with the capability to answer any domain related questions in a natural language.

In this article, we are going to take a look at how different IBM® Watson™ services can be used within business processes to empower knowledge workers in making better decisions.

Adeel Javed - How To Empower Knowledge Workers Using Cognitive BPM

Personality Insights

Enables deeper understanding of people’s personality characteristics, needs, and values to help engage users on their own terms

Example: This service can be utilized in processes such as New Hire. It can be used to analyze various personality characteristics of a candidate. It analyzes the input text which in our example can be candidates profile, emails or any other communication. The output will be both in natural language and visual formats as shown in diagrams below. This output can help in deciding if the candidate is a good fit for the organization or not.

Adeel Javed - How To Empower Knowledge Workers Using Cognitive BPM

Adeel Javed - How To Empower Knowledge Workers Using Cognitive BPM

Concept Insights

Explores information based on the concepts behind your input, rather than limiting investigation to findings based on traditional text matching

Example: Processes such as Talent Acquisition that currently use keyword-based search can tremendously benefit from this service. The traditional keyword-based searches might not always return the desired results because if an exact match is not found the document and in our case, a resource profile will simply be ignored. The Concept Insights service, on the other hand, looks for conceptually related items i.e. even if the input keywords do not exactly match, this service will try to find content that is related to the same concept. In our example, a resource profile might not match the exact keywords, but it will still show up in the search results even if the resource profile has different keywords or they have worked in a related area.

Adeel Javed - How To Empower Knowledge Workers Using Cognitive BPM

Tradeoff Analytics

Helps users make better choices to best meet multiple conflicting goals, combining smart visualization and recommendations for tradeoff exploration

Examples: Tradeoffs are an integral part of the decision-making process.  This service can help recommend the best possible case that meets organizational goals.

This service can be utilized in the supply chain processes for selecting best possible suppliers, sourcing low-cost parts etc. The service provides a very visual way of performing this analysis as shown in the diagram below.

Adeel Javed - How To Empower Knowledge Workers Using Cognitive BPM

Another great utility is in the patient case management where this service can help decide the best treatment options and drugs for patients.

Adeel Javed - How To Empower Knowledge Workers Using Cognitive BPM

Similarly, this service can be used in financial asset management processes to make informed decisions about choosing the best assets for investment.

Language Identification / Machine Translation

Identifies the language in which text is written

Globalize on the fly. Translate text from one language to another

Example: These are two distinct services, one that identifies which language is the input text written in, while the second one translates it. For larger organizations that operate globally, this is an essential requirement. This service just makes the whole globalization process easy by automatically translating the text.

Question And Answer

Direct responses to user inquiries fueled by primary document sources

Example: This service provides answers to questions in a natural language thus making it a great source for getting additional domain-specific information. The answers that the service returns also include Watson’s confidence level as a percentage.

The service can be used in all types of processes such as in travel and hospitality processes for finding out visa and vaccination requirements of a country or in the healthcare industry for getting more information about a disease.

Adeel Javed - How To Empower Knowledge Workers Using Cognitive BPM

Conclusion

In addition to the IBM® Watson™ services mentioned above, there are quite a few other services that are currently available, such as:

  • Concept Expansion
  • Relationship Extraction
  • Message Resonance
  • Speech to Text
  • Text to Speech
  • Visual Recognition
  • Visualization Rendering

All of these services are available on IBM® Cloud™, can be easily developed using Bluemix™ and consumed within any Business Process Management (BPM) or Case Management tool. For now, these can be used to support and empower knowledge workers in making decisions but in future, these can and will be used to automate the decision-making process.

 

References

Disclaimer: IBM® Watson™, IBM® Cloud™ and Bluemix™ are trademarks or registered trademarks of International Business Machines Corporation.

Republished/Cited