The Watson Personality Insights Service uses linguistic analytics to infer cognitive and social characteristics, including Big Five, Values, and Needs, based on text information created by individuals or groups. These characteristics can be used to generate actionable insights, for example in the context of psychographic segmentation. The current Watson Personality Insights Service is trained using social media status updates such as from Twitter or Facebook, though other data sets that are representative of a user might be used. The generated insights might be used as is or combined with other data to generate insights into possible purchasing behaviors, likes, dislikes, and other relevant customer interactions. It is important to note that the generated portrait is only a representation of a person based on information available from a specific context (e.g. Twitter). While there may be correlations between a customer portrait and certain observable behaviors, a generated model should never be used to evaluate psycological wellbeing of a person or to provide psycolanalysis services.
In the context of Watson Explorer, psychographic segmentation and customer portriats might prove very useful when combined with a 360 degree view of a customer or other (human) entities. Watson Explorer Application Builder already allows you to view relevant information from disparate data sources from a single web page. Adding a portrait generated by Watson Personality Insights layers insights on top of the data you already have.
The goal of this example is to demonstrate how to get started with an integration between Watson Explorer and the Watson Personality Insights service available on IBM Bluemix. By the end of the example you will have added two widgets to a Watson Explorer Application Builder application. One widget creates and displays a portraitbased on information indexed in Engine provided by an entity. A second widget demonstrates how users can generate a user portrait in real time based on a Twitter handle that is provided in the context of an entity page (simulating an in-progress user/customer interaction).
Please see the Introduction for an overview of the integration architecture, and the tools and libraries that need to be installed to create Java-based applications in Bluemix.
- An IBM Bluemix account
- Watson Explorer - Installed, configured, and running
- Application Builder proxy - Installed and configured
- A basic search application configured in Application Builder. For the purposes of this example, the example-metadata based tutorial application is sufficient.
- (Optional) Prerequisites for creating a Bluemix Ruby based application. This prerequisite is required if you would like to develop Ruby applications on your local machine.
- (Optional) A Twitter account with API access. This will be used to fetch status updates given a user's Twitter handle in one of the example widgets.
This tutorial will walk through the creation and deployment of three components.
- A basic Bluemix application exposing the Watson Personality Insights Service as a web service.
- A custom Application Builder widget that sends text from an Application Builder entity to your Bluemix Personality Insights web service.
- A custom Application Builder widget that takes a Twitter handle as input and creates a model based on a user's Twitter status updates at run time.
This section outlines the steps required to create a basic Watson Personality Insights widget in Application Builder and connect it with a custom Bluemix web service.
The example Bluemix application uses a manifest.yml
file to specify the application name, services bindings, and basic application settings. Using a manifest simplifies distribution and deployment of CloudFoundry applications (for example, Bluemix). Since the example application is written in Ruby, the code can be deployed to Bluemix as is. Ruby development tools are only required if you would like to develop and test the application locally.
If you have not already, sign in to Bluemix.
$> cf api api.ng.bluemix.net
cf login
Once you are signed in, you will need to create the Watson Personality Insights service that the example application will bind to. In this example, we're calling the service wex-personality-insights
. This name is already set in the manifest.yml
. Since services might be used by multiple applications, this name isn't ideal (a more descriptive name can improve maintainability), but it's perfectly suitable for this example.
$> cf create-service "personality_insights" "IBM Watson Personality Insights Monthly Plan" wex-personality-insights
Note that the Watson Personality Insights service is a for-free service, meaning you may be charged based on the service policies and rates. You can review these policies in the Bluemix dashboard and documentation.
Next, deploy the application to your space in the Watson Developer Cloud. If this is the first time deploying, the application will be created for you. Subsequent pushes to Bluemix will overwrite the previous instances you deployed.
$> cf push
Once the application has finished restarting, you should now be able to run a test using the simple application test runner included in the application. You can see the route that was created for your application with cf routes
. The running application URL can be determined by combining the host and domain from the routes listing. You can also find this information in the manifest.yml
file. By default the route should be wex-personality-insights.mybluemix.net
. The route is also available from your application dashboard in Bluemix. You should plan to change this to a unique route name.
The Twitter enabled widget requires a valid Twitter API token for use. Follow these steps to create a Twitter API application and update the example application code to use your Twitter API credentials.
- Sign in to https://dev.twitter.com/ using your Twitter username and password.
- Once you are logged in you can view "My applications" from the drop down menu under your profile picture in the upper right, or visit https://apps.twitter.com/ directly.
- Create a new App.
- Fill out the form and agree to Twitter's Terms of Service. A Callback URL is not required for this application.
- The next page will show a summary of your Twitter API application. Click on the "API Keys" tab.
- The
API key
andAPI secret
are what you'll need to connect your Watson Bluemix application to Twitter. Change lines 17 and 18 of application_controller.rb to reflect yourAPI key
andAPI secret
. It is not necessary to generate a Twitter access token for the integration.
set :twitter_api_key, "YOUR API KEY GOES HERE"
set :twitter_api_secret, "YOUR API SECRET GOES HERE"
At this point your Bluemix application should be able to use the Twitter API to directly download status updates with a valid Twitter handle. Push your updated application up to Bluemix using cf push
and test the newly deployed application.
Please note that the Twitter API has limits on the number of requests that can be made per hour. The example code will fail gracefully when these limits and other common API errors occur, but the responsibility for managing your Twitter API and usage is up to you. For more information on the Twitter API see https://dev.twitter.com/. The example Application Builder widget uses the excellent Twitter Gem.
This example requires that example metadata is crawled and configured for use in Application Builder. If you have not already created a basic application using the example-metadata content, see the pre-requisites for searching with Engine. The Application Builder Tutorial can be found in the Watson Explorer documentation.
This example includes two widgets. Both custom widgets require the use of the Application Builder Proxy.
To use the proxy you must update the Application Builder Proxy configuration to point to your deployed Bluemix application.
set :pi_endpoint, "http://MY_APPLICATION_ENDPOINT.mybluemix.net/pi/"
Once you have updated the Proxy, restart the Application Builder server for the changes to take effect.
The purpose of this widget is to send a single block of text to the Personality Insights service for analysis. The results of that analysis are then displayed in the Application Builder UI.
Once you have logged into the Application Builder Administration tool, follow these steps to create the custom widget and add it to the search results page.
- In the Application Builder Administration Tool, navigate to the Pages & Widgets -> Book Title page. (If you have different entities in your application, choose one that has a snippet or be prepared to modify the example widget code.)
- Create a Custom new widget.
- Set the ID of the widget to be
Watson_PI
- Set the title of the widget to be
Watson Personality Insights
- Copy and paste the code for this widget into the Type Specific Configuration.
- Click to turn "Asynchronously load content" on.
- Save the widget.
- Go back to the Book Title page
- Add the
Watson_PI
widget to the Book Title page and save the page configuration.
At this point the widget should be fully configured. To test the widget, navigate to the application and choose a Book Title entity. The example shown in the below image uses the title from "Lug Nuts!" to create the model displayed.
This simple example illustrates a basic integration. You should choose text that is relevant to a user or entity that you are modeling and you must provide enough text to generate a reliable model. See the Personality Insights documentation for more guidance on text selection and recommendations.
The "Sent Text" Personality Insights widget
The widget is fully commented if you are curious about how the code works or are interested in extending the example functionality in a new widget.
The purpose of this widget is to let users add supplementary information to the 360 degree view of the current entity. For example, if you were looking at a customer page you could ask the customer for their Twitter handle, which will then allow you to create a model that might be correlated with information available from other systems accessible from the entity page within Application Builder. For the purposes of the example, we're going to add the widget to the Home page.
Before starting the work in Application Builder, we first need to add some javascript and css styling to help with the rich visualization we are going to display. Follow these steps to add in these additional assets.
$AB_HOME refers to the home folder for the specific Application Builder installation. For example, on a default Windows installation, $AB_HOME
might be C:\Program Files\IBM\IDE\AppBuilder
- Copy the D3 javascript into the folder $AB_HOME/wlp/usr/servers/AppBuilder/apps/AppBuilder/javascripts
- Copy the Personality Insights javascript into the folder $AB_HOME/wlp/usr/servers/AppBuilder/apps/AppBuilder/javascripts
- Copy the Personality Insights css into the folder $AB_HOME/wlp/usr/servers/AppBuilder/apps/AppBuilder/stylesheets
Now we can begin the process of configuring Application Builder.
Once you have logged into the Application Builder Administration tool, follow these steps to create the custom widget and add it to the search results page.
- In the Application Builder Administration Tool, navigate to the Pages & Widgets -> Home page.
- Create a Custom new widget.
- Set the ID of the widget to be
watson_twitter_pi
- Set the title of the widget to be
Watson Personality Insight - Twitter
- Copy and paste the code for this widget into the Type Specific Configuration.
- Save the widget.
- Go back to the Home page.
- Change the layout to the two pane layout to allow for more room for the widget.
- Add the
watson_twitter_pi
widget to the largest column on the Home page and save the page configuration.
At this point the widget should be fully configured. To test the widget, navigate to the Application Builder Home page. Your widget should be visible. Try entering your Twitter handle or using the IBM Watson Twitter stream, IBMWatson
. Once you've submitted the form, your Bluemix service will fetch about 200 Twitter status updates for the provided handle. The resulting analysis from Watson will be displayed under the form in the widget.
The "Twitter Status" Personality Insights widget
The widget is fully commented if you are curious about how the code works or are interested in extending the example functionality in a new widget. One obvious extension is creating a widget that automatically fetches Tweets based on a handle stored in an entity field rather than waiting for a user to enter a Twitter user name in the browser after the fact.
These examples are intended for demonstrative purposes only. While you might be able to reuse the patterns and even parts of the code from these examples, there are several concerns that should be considered when developing a production-grade application.
- Maintainability - For the example, only the Watson Personality Insights Service is built into the Bluemix application. If this were a real application you should consider creating a single Bluemix application for all cloud based cognitive (or other) services used within Bluemix.
- Security - The example Bluemix applications are completely open and have no security.
- Scalability - This example uses only a single cloud instance with the default Bluemix application settings. In a production scenario consider how much hardware will be required and adjust the Bluemix application settings accordingly.
- Using Twitter - The Twitter API has limits in how many requests can be made to the API per hour. Consider carefully whether your required load can be met by these limits and use the appropriate API authentication mechanism and caching strategies.
- User Experience - The example widgets are only meant to demonstrate basic interaction. For a custom application using Application Builder you should carefully consider widget placement, overall look and feel, user needs, and how Watson Personality Insights can provide value to end users.
- Integration with other Analytics - By itself a model is not that interesting, but there are opportunities for generating insights with further analysis. Consider how this information might be used in conjunction with other data available in your organization and what you might show an end user in Application Builder based on your insights. For example, a user portrait might only be a means to an end and only actionable recommendations are shown in Application Builder rather than a fancy visualization.
- Performance - Rather than generating portraits from the Personality Insights service with every request, it may be worth considering caching the information (perhaps even in a Watson Content Explorer search collection) and updating only periodically instead of with every request.
- Privacy - Use common sense and best practices when requesting and collecting information from users with the intention of generating a Personality Insights portrait. In the case of publicly available Twitter data, the need is decreased, but consider carefully corporate policies and user's privacy when collecting information from them for the purpose of generating portraits to assist with psychographic segmentation.
Watson Personality Insights offers another dimension of the "360 Degree View" of a customer or other entity and starts to paint a picture of a person not just through their data but their personality and personal preferences. Here are some ideas to help get you started for how Watson Personality Insights might be fully integrated into a Watson Explorer application.
- Display a user's portrait on an entity page alongside other information relevant to that entity. For Person entities, consider using that person's Twitter or Facebook status updates. For "thing" entities such as products, consider collecting Twitter status updates based on a search for that product name or a #hashtag to generate a portrait for people who discuss that product or service.
- Perform additional analysis using the generated portraits as one of the variables under consideration, for example looking for correlations and other insights across other data within your organization, such as customer tickets or sales histories.
- Display recommendations for action based on a psychographic segmentation built using portraits generated by the Personality Insights service.
- Tailor the Application Builder UI based on the user's portrait.
- Incorporate the generated model into other entity analytics available within Application Builder.
- Index portraits so they can be searched, filtered, sorted and displayed alongside other information available in your organization.