Wednesday, 29 March 2017

Using IBM Bluemix Watson APIs to Optimise my CV (Resume)

I kept seeing adverts for IBM Bluemix popping up on my social media feeds and online adverts so I thought I'd take a look and see what it was all about.  You can sign up an account and get 30 days access for free so that was all good for a home hobbyist like me!

So what is Bluemix?  Here's a snippet from the IBM Bluemix website:

The IBM Bluemix cloud platform helps you solve real problems and drive business value with applications, infrastructure and services.


So it does what it says on the tin really.  A bunch of cloud based capabilities that lets you do interesting stuff!  So what interesting stuff to do with this?   Creating an account (free for 30 days - no payment card required) and browsing the Bluemix catalogue my eye was drawn to the Watson APIs.  Watson was made famous through winning the US Jeopardy gameshow and there's a bunch of exciting artificial intelligence capabilities like Natural Language Understanding and Personality Insights you can use.

As a starting point I decided to play with the "Tone Analyzer" API, the description of which is as follows:

People show various tones, such as joy, sadness, anger, and agreeableness, in daily communications. Such tones can impact the effectiveness of communication in different contexts. Tone Analyzer leverages cognitive linguistic analysis to identify a variety of tones at both the sentence and document level. This insight can then used to refine and improve communications.

At the moment I'm updating my CV (resume for you good people in the USA) and I'm told that when faced with an avalanche of CVs, recruiters will sometimes only ready the very first "personal profile" section of the document to make their initial decision.  Additionally recruiters are more-and-more using AI tools to filter CVs.  I thought that if I could use the tone analyser to optimise that first section of my CV then this would be a good use of Bluemix.

To use the API you simply click "Create" and get some credentials to access the API.  IBM provide a lot of guidance as to how to use the API and provide SDKs for languages like Python and node.js.  I decided to use curl as all I wanted to do was throw some text at the API and see the result.

So here's a curl command to access the API:

curl -v -u "username":"password" -H "Content-Type: text/plain" -d "Some text" "https://gateway.watsonplatform.net/tone-analyzer/api/v3/tone?version=2016-05-19"

(Replace username and password with the ones you are provided by Bluemix).

The response is a JSON structure that looks like this (abridged):
{"document_tone":{"tone_categories":[{"tones":[{"score":0.135461,"tone_id":"anger","tone_name":"Anger"},{"score":0.045643,"tone_id":"disgust","tone_name":"Disgust"},{"score":0.71908,"tone_id":"fear","tone_name":"Fear"},{"score":0.232038,"tone_id":"joy","tone_name":"Joy"},{"score":0.524529,"tone_id":"sadness","tone_name":"Sadness"}],"category_id":"emotion_tone","category_name":"Emotion Tone"},

The structure provides numeric values (range 0 to 1) based upon a set of analysis criteria that IBM defines as follows:

It detects three types of tones, including emotion (anger, disgust, fear, joy and sadness), social propensities (openness, conscientiousness, extroversion, agreeableness, and emotional range), and language styles (analytical, confident and tentative) from text.

Numeric values are provided for the whole piece of text you provide plus it's broken down into sentences and each sentence is analysed.  My grand plan it to pick out those attributes that I deem important for the type of job I would like to get and then "tune" the text from my CV to improve those attributes.

First I need to be able to take the JSON API response and turn it into something I could read and interpret.  I decided to use Python to analyse the JSON (because Python rocks) and use an online charting capability called Plotly to visualise the data.  I used Plotly as it has an API that I thought would be fun to learn about.

Plotly provides a REST API that you can HTTP POST to and have Plotly render a chart in your online account that you can, for example, reference in another website. Plotly provide online descriptions of the REST API here but in simple terms you specify the data to plot and some formatting parameters and Plotly does the rest for you.

Here's a example POST message body:

un=chris& key=kdfa3d& origin=plot& platform=lisp& args=[[0, 1, 2], [3, 4, 5], [1, 2, 3], [6, 6, 5]]& kwargs={"filename": "plot from api", "fileopt": "overwrite", "style": { "type": "bar" }, "traces": [1], "layout": { "title": "experimental data" }, "world_readable": true }

Here's some Python I wrote to extract data from the JSON structure and use the Plotly API, (replace Watson API response and credentials with your values):

import json
import pprint
import urllib.request
import sys

#Constants
#Baseline response  
APIResponse = 'Bluemix JSON Response Here'

PlotlyURL = "https://plot.ly/clientresp"
UserName = "username"
APIKey = "YourKey"

#Example simple arguments Strings
#NArgsString = '[["One", "Two", "Three"], [0.98, 0.87, 0.87]]'


#This is a arguments string for plotly formatting
KwargsJSON = {"filename": "plot from api",
        "fileopt": "overwrite",
        "style": {"type": "bar"},
    "traces": [0],
    "layout": {
        "title": "Less Anger!"
    },
    "world_readable": True
}

#First we extract all the data from the JSON from Watson.  Can pretty print if you want
ToneJSON = json.loads(APIResponse)
#pprint.pprint(ToneJSON)

#Initialise the sub components of the plotly argument string
XList = []
YList = []

#Itterate through the JSON structure picking up attributes and values
for MyTone in ToneJSON["document_tone"]["tone_categories"]:
  for TheTones in MyTone["tones"]: 
    #Build the x and y Python lists that we'll use for the plotly argument
    XList.append(str(TheTones["tone_name"]))
    YList.append(float(TheTones["score"]))
    
#This is the arguments string for plotly.  We need to use the .join method to make sure the arguments string is properly formatted for the x axis values
NArgsString = "[[" + ','.join('"{0}"'.format(w) for w in XList) + "], " + str(YList) + "]"

#Make sure we have " not ' around the JSON elements
NArgString = NArgsString.replace(chr(39),chr(34))

#Form the body for the HTTP POST
KwargsString = json.dumps(KwargsJSON)
PostBody = "un=" + UserName + "&" + "key=" + APIKey + "&" + "origin=plot&platform=lisp&args=" + NArgsString + "&" + "kwargs=" + KwargsString

#Encode the whole post body
PostBody = PostBody.encode('utf-8')

#Form the request
MyRequest = urllib.request.Request(PlotlyURL, data=PostBody)

try:
  #Execute the request
  wp = urllib.request.urlopen(MyRequest)
  
  #Read the response and print it for the user
  TheResponse = wp.read()
  print(str(TheResponse))

#Handle pesky errors
except urllib.error.HTTPError as e:
  print("HTTP Error caught when making request " + str(e.code) + "\n")
except urllib.error.URLError as e:
  print("URL Error caught when making request\n")

 So we're ready to analyse some text.  First I used some made up text to test how good the tone analyser API is.  Here's the text:

I am excellent at everything.  There is nothing I can not do.  Throw a challenge at me and I will succeed.  I have beaten every target ever set for me.  Employ me and you will employ a winner.

...and here's the resulting Plotly chart:


That seems about right, in particular the sky-high confidence score!

Here's my current CV profile statement:

A Solution Architect with a wide range of knowledge and experience in the Telecommunications and IT industry.  Has significant experience of leading cross-functional teams to deliver innovative solutions spanning IT, Network and TV systems.  A strong self-starter with proven analytical and problem solving skills.  Able to learn about new technologies quickly and apply this knowledge to design tasks.  Well-developed communication and presentation skills, both written and oral.

...which when analysed by Watson and charted by Plotly yields this:


So I would say that for the type of job I want I need to:

  • Reduce the anger and sadness
  • Maintain analytical
  • Have some confidence!
  • Improve conscientiousness

..but as another test of the API I analysed this version of my profile (addition in red):

A Solution Architect with a wide range of knowledge and experience in the Telecommunications and IT industry.  Has significant experience of leading cross-functional teams to deliver innovative solutions spanning IT, Network and TV systems.  A strong self-starter with proven analytical and problem solving skills.  Able to learn about new technologies quickly and apply this knowledge to design tasks.  Well-developed communication and presentation skills, both written and oral.  I’m so afraid that if I don’t get this CV right then I won’t be employed by anyone; I’m really really scared, worried and frightened about this!

Watson and Plotly yield this:


There we go!  Fear increases from negligible to ~0.7 so there's a definite correlation between text and the analysis.

Back to business.  Here's a modification to my profile to try and boost confidence:

A Solution Architect with a track record of successful delivery in the Telecommunications and IT industry.  Has significant experience of leading cross-functional teams to deliver innovative solutions spanning IT, Network and TV systems.  A strong self-starter with proven analytical and problem solving skills.  In a fast paced, ever changing technology world, is confident in his abilities to quickly learn and apply new skills.  Well-developed communication and presentation skills, both written and oral.

Watson and Plotly they say:


Bingo!

Now to up the conscientiousness.  I actually had to play with the language a lot and even then I only managed to improve it by 0.1.  Here's what I wrote:

A Solution Architect with a track record of successful delivery in the Telecommunications and IT industry.  Has significant experience of leading cross-functional teams to deliver innovative solutions spanning IT, Network and TV systems.  A strong self-starter with proven analytical and problem solving skills.  In a fast paced, ever changing technology world, is confident in his abilities to quickly learn and apply new skills.  A conscientious, reliable individual who always who sets challenging goals, forms structured plans to achieve them and follows through until the job is complete.

Which results in:

Finally to drop the anger levels as anger is never a good look!  Here's what I wrote:

A Solution Architect with a track record of successful delivery in the Telecommunications and IT industry.  Has significant experience of leading cross-functional teams to deliver innovative solutions spanning IT, Network and TV systems.  A strong self-starter with proven analytical and problem solving skills that is never happier than when working with like-minded individuals to harmoniously collaborate and solve problems.  In a fast paced, ever changing technology world, is confident in his abilities to quickly learn and apply new skills.  A conscientious, reliable individual who always who sets challenging goals, forms structured plans to achieve them and follows through until the job is complete.

The net result being:
So finally I used Plotly to compare the initial (baseline) analysis with the final text.  Here's the result:

So less anger, more joy, less sadness, more confidence and more conscientiousness so all looking good here.  However I've also dropped the analytical and openness scores which isn't so good for the type of role I'd like but I can live with that!  So now to use this for my real-life CV.  Wish me luck...