Dynamics CRM – Prediction based routing

Imagine a day at work of a front desk staff who is handling the support mailbox or reception of any mid-size organisation. It is not uncommon for them to receive hundreds, if not thousands of email and phone enquires everyday.

If this organisation happens to be using Dynamics CRM, then every enquiry is usually handled as below

  1. Read the description of the enquiry
  2. Understand
  3. Determine what team/department the query belongs to
  4. If there are multiple members in that team, then find who is best suited to answer it
  5. Assign it to that person

Move to the next enquiry. Repeat 1 to 5 above…. hundreds of times.

Now imagine the time spent on every enquiry to perform steps 1 to 5. A fair guess – it can easily take 10 minutes to grasp, digest and route the query.

Realistically, for most queries there is often a support rep matching ritual, back and forth, something like

Hey, who do you think this should go to?

Oh sorry! so it was meant for Helen, no worries I can assign to her

Have you worked on this kind of stuff earlier?

When will you get free to look at it, customer needs an answer today

 

Capture

Courtesy: http://www.glasbergen.com

We have already spent 20 minutes and the ticket has not even landed on the support rep’s desk yet !!

Well – time is money. If we can find a solution to save this time, its a great return on investment.

Supercharge your Tier 1 Support

Through this blog series, I will try to explore a solution to this problem using Machine Learning. We will automate steps 1 to 5, full automation.

A machine algorithm will predict

  • Which team does this query belongs to?
  • Which agent will get free first and which agent is best-skilled to answer this query

And machine would not take 20 minutes to decide, it will take 20 seconds

 

Scenario

Let us layout a scenario

A big advisory firm that uses Dynamics CRM  offers many kinds of services to its clients. They have professional advisors on their team who can answer queries across of the range, no matter if they are tax enquires, investment or even medical.

Each team – tax, investment and medical has a range of support reps available to handle enquires.

Traditionally, Tier 1 staff created support cases upon receiving customer enquires and assigned them to the relevant support rep by following steps 1 to 5 described at the start.

Upon assignment, Support Rep gives an ETA before working on the query and system tracks how time support rep actually spent.

We will also track some other parameters which we can be leveraged by the ML engine.

 

 

Machine Learning Algorithm

The Machine Learning approach will tackle this situation as shown below

1. ML engine will train itself by synthesising content and correlating parameters that belong to a category

2. ML engine will be deployed as a web service (compiled model) to be consumed by Dynamics CRM

3. It will start predicting what category the enquiry is after reading, tokenising and tagging the content

4. Once it has known the category, it will then find who is best suited to answer the query using parameters like

  • Which customer support rep will be the earliest to get free to look at this
  • Which customer support rep is generally good at these kinds of queries

 

Techniques

We will see and the use the following machine learning techniques to build the smarts

  • Tokenisation & Semantic Analytics using Natural Language Processing
  • Support Vector Machines
  • Inverse Document Frequency (TF-IDF)

 

See you in the next post

Dynamics CRM – Find similar customers using Machine Learning

In the previous blog, we used Machine Learning inside Dynamics CRM to add value to our customer records by getting a quick health check of how customers are doing based some measurable data points. We used supervised learning, a technique that involves training your machine first, and then deriving your predictions based on the trained model. In this blog, we will use another technique – unsupervised learning. This technique is often used to determine similarity between records, categorise them into clusters and other scenarios which involve correlation of records. We will use unsupervised learning to solve a shortcoming that had existed in Dynamics CRM for a decade i.e. to match (and detect duplicates) records based on a semantic match.

 

This is a very common requirement in Dynamics CRM when you need to cleanse your data and get rid of duplicates with similar sounding names. CRM does have a duplicate detection wizard but that doesn’t address this problem because it cannot do fuzzy match or a semantic match. I have seen many situations where hundreds (even thousands) of records are distributed among various team members for them to fix by identifying duplicates manually. Sounds familiar?

Capture

Courtesy – boredportal.com

 

Let us put some intelligence in Dynamics CRM to save us from the wrath of the painful manual work.

 

Problems Solved

 

We will solve the following problems when it comes to matching records

  • Juxtaposed word sequences e.g. it can match Manchester University to University of Manchester and Socceroos Australia to Australian Association of Socceroos
  • Takes are of little punctuation and abbreviation tidbits e.g. match Manchester University to Manchester Uni or Manchester’s Univ or Man. Utd. University
  • Covers spelling mistakes, similar sounding names e.g. match Scot’s And Christina to Scott & Kristina Corp
  • Phonetic match and verb forms e.g. match Richtie Rich to  Rishi Richest

 

 

Matching Accounts

So this is how the solution works inside Dynamics CRM.

A web resource is added to the Account form called Similar Accounts  that lists other accounts with similar names and their matching score e.g. 100 for a perfect match and 60 for partial match. The threshold can be adjusted to pick only closer results. Below are some of the screenshots from my Dynamics CRM where I have applied this algorithm. I have kept it simple as the focus is to demonstrate the matching engine rather than look and feel.

 

 

Similar Account2

 

 

Similar Account3

 

 

Similar Account4

 

Similar Account1

 

Powered by Machine Learning Algorithm

This solution is built using Python and uses a Machine Learning algorithm called Levenshtein Distance to determine the similarity between two records. I have built a package around this core Python library and integrated it with Dynamics CRM. The package is hosted as a Flask web service that communicates with Dynamics CRM using Json.  More details of the Python package are here

Dynamics CRM meets Machine Learning – Final

 

Welcome to the final post of this Dynamics CRM meets Machine Learning series where we have been discussing about using Machine Learning (ML) to interpret customer happiness by using certain cues and behaviour points based on Dynamics CRM data. If you have been following all along, you might notice that now the only remaining piece of this jigsaw puzzle is the usage of the ML insights i.e. the score of the email, inside Dynamics CRM.

 

We have already seen the ML engine and how CRM can connect to the ML web service that calculates the score of the email based on its content. Now we will focus on how to show the Happiness Index on the Contact record that will tell us about the level of satisfaction of a customer when we open their record.

 

Dynamics CRM customisations

We will be adding the following fields into CRM

Entity Field Purpose
Email sentiment This field will store the sentiment calculated by the Online Azure Machine Learning Web Service. Its value will either be 0 – Unhappy email or 4- Happy email
Contact Total Emails Total emails received from this contact
  Average Sentiment Score Average ML sentiment score based on all emails
  Happiness Index If more than 2 emails have been received then average sentiment score, otherwise 2

 

I have used rollup and calculated fields that rollup the sentiment score from emails over to the contact record.

 

Displaying Happiness Index

The happiness index is shown on the Contact form and an emoticon is displayed based on the score e.g. in the example below the Index score is 2.4 which is on the happier side, so a happy face is shown. The below screen also shows various emails based on which the score for Jim Glynn was calculated by the ML web service.

index

 

Now let us look at a slightly unhappy customer Patrick Sands. You can look at his emails on the right to determine why is he unhappy. The scores in the Sentiment column have purely been calculated by the ML web service.

image

 

Script to show emoticons

I think these graphics look cool and add a face value to your customers. If you are curious to know more about how I displayed them, below is the script. Basically there is a html page added as a web resource and I replace the image based on the score

 

<html>

<head>

 <meta charset="utf-8">

 

<script>
   1:  

   2:  function onPageLoad() 

   3: {

   4:  var happIndexString = window.parent.Xrm.Page.data.entity.attributes.get("manny_happinessindex").getValue();

   5:  

   6: if (happIndexString != null) 

   7: { 

   8: var happIndex = parseFloat(happIndexString); 

   9: if (happIndex <= 1) 

  10: { 

  11: this.imgIndex.src = "manny_1.png"; 

  12: } 

  13: else if (happIndex > 1 && happIndex <= 2) 

  14: { 

  15: this.imgIndex.src = "manny_2.png"; 

  16: } 

  17: else if (happIndex > 2 && happIndex <= 3) 

  18: {

  19:  

  20: this.imgIndex.src = "manny_3.png"; 

  21: }

  22:  

  23: else if (happIndex > 3 && happIndex <= 4) 

  24: { 

  25: this.imgIndex.src = "manny_4.png"; 

  26: }

  27:  

  28: }

  29:  }

  30:  

</script>

 

<title></title>

 

<meta>

 <meta>

</head>

<body 

style="margin: 0px; word-wrap: break-word;" onload="onPageLoad()">

 <img id="imgIndex" name="imgIndex" src="manny_2.png" border="0">

</body>

</html>

 

And below is the entire solution that shows plumbing on the CRM side of the fence

soln

 

Conclusion

So there you have it, a simple solution that works end to end by consuming ML web service from within Dynamics CRM that gives you some insight into the satisfaction of your customers. The algorithm, that just uses body of the email, is indeed a simple one but it can be enhanced to take into account various other parameters and behaviour points that we have discussed in Part 2. This is just tip of the iceberg, there are lot of possibilities with Machine Learning.

 

Hope you enjoyed the series. Let me know if any comments or feedback.

Dynamics CRM meets Machine Learning–Part 3

So far in this series we have covered the business problem and machine learning setup that drives the score based on the email content. We have also discussed how this approach can be extended to calculate an aggregated happiness index based on various behaviour points from within Dynamics CRM. In this instalment, let us focus on deploying the ML (machine learning) module as web service, so that it can be consumed from within Dynamics CRM.

 

Deploying the ML module as a web service

Once you have tested your module and you are happy with results of the trained model, you can deploy it as a consumable web service by clicking on the Deploy Web Service button at the bottom of the ML Studio’s Experiment screen as shown below

deploy

 

After deployment, the web service is available in the Web Services section of the Azure ML Studio. You can click on the record and view its properties. In order to connect to this service you will need an API key which can be found in the properties as shown below

api key

 

The setup of this web service for our scenario is as below

Score – 0 for unhappy email

4 for a happy email

ws

 

Consuming the ML web service from within Dynamics CRM

 

Once the service has been deployed, it can be consumed from both Javascript and server side code (e.g. a plugin or a custom workflow activity). To keep it simple we will consume it from within the JavaScript

The following script on the email form can be used to call the service and get the score. Here we are sending the body in the tweet_text parameter and retrieving the results in JSON format.

 

sendRequest: function (text) {

 

var service = 

AzureScript.getRequestObject();

 

var url = "https://ussouthcentral.services.azureml.net/workspaces/xxxxxxxxxxxxxxxxxxx/services/xxxxxxxxxxxxxxx/execute?api-version=2.0&details=true";

 var jsonObject 

=

 

{

 

"Inputs": 

{

 

"input1": 

{

 

"ColumnNames": 

[

 

"sentiment_label",

 

"tweet_text"

 

],

 

"Values": 

[

 

[

 

null,

 

text

 

]

 

]

 

}

 

},

 

"GlobalParameters": {}

 };

 var dataString = 

JSON.stringify(jsonObject);

 if (service != null) 

{

 

service.open("POST", url, 

false);

 

service.setRequestHeader("X-Requested-Width", 

"XMLHttpRequest");

 

service.setRequestHeader("Authorization", "Bearer xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx");

 

service.setRequestHeader("Accept", 

"application/json");

 

service.setRequestHeader("Content-Type", "application/json; 

charset=utf-8");

 

service.setRequestHeader("Content-Length", dataString.length);

 

service.send(dataString);

 //Recieve 

result

 var 

requestResults = eval('(' + service.responseText + ')');

 try {

 

resultSentiment = 

requestResults.Results.output1.value.Values[0][1];

 

resultProb = 

requestResults.Results.output1.value.Values[0][2];

 

return 

resultSentiment;

 

//alert(resultSentiment + " " + 

resultProb);

 

}

 catch 

(err) 

{

 

console.log('Unable to interpret 

result');

 

}

}

}

 

In the next part we will see how this score gets used within Dynamics CRM