Create personalized experiences for your apps, bots and websites with Azure Personalizer - Part 3
Tags: azure, machinelearning, ai, tutorial
Published: 2023-01-10 12:51:14

Personalization in customer service is the practice of tailoring interactions with customers to their individual needs and preferences. This can be achieved through the use of customer data and technology such as machine learning and artificial intelligence.

One way that personalization can be used in customer service is to provide tailored responses to customer inquiries. For example, a customer service agent can use information about a customer's previous interactions and purchases to provide more personalized and relevant answers to their questions. This can help to improve the customer's overall experience and make them feel valued and respected.

Another way that personalization can be used in customer service is to provide personalized recommendations and suggestions to customers. For example, a customer service agent can use information about a customer's interests and preferences to recommend products or services that they might be interested in. This can help to increase customer satisfaction and loyalty, as well as boost sales and revenue.

Personalization can also be used to improve the efficiency of customer service operations. By using customer data and technology, customer service agents can more easily and quickly access the information they need to resolve customer issues. This can help to reduce response times and improve overall customer satisfaction.

So far, I've already written two parts on Azure Personalizer. The <a href="https://www.arafattehsin.com/reinforcement-learning-in-apps-bots-websites-with-azure-personalizer-part-1/">first one</a> talks about building your own library. The <a href="https://www.arafattehsin.com/reinforcement-learning-in-apps-bots-websites-with-azure-personalizer-part-2/">second one</a> talks about building a simulator for your learning loop. This will help you train your model ahead of production deployment. This is going to be my last post on this topic. In this post, we're going to see how we make use of Azure Personalizer into a chat bot.
<h3>What do we need?</h3>
As we're going to use the Azure Personalizer into a chat bot, we have to choose the right platform for that. Whilst there are many options in the market, I decided to go with the Microsoft Power Platform. There were two reasons to choose this platform over others.

One is that Power Platform allows you to easily create a chat bot using Power Virtual Agents (PVA) and integrate the Azure Personalizer APIs using Power Automate. Both without any code, even with the custom connector 🤘. The second reason is the <a href="https://www.arafattehsin.com/power-virtual-agents-get-the-biggest-update-ever/">recent update</a> we witnessed about the Power Virtual Agents around unified authoring canvas. I was quite excited about it so thought to use it in one of our bots.

It totally depends upon you as how you want to secure Power Platform environment. It can be your sandbox, your trial instance or also a Developer Plan. I have got a M365 Developer Plan and I will be using that. My complete solution (Custom Connector + Power Virtual Agents) is available on my usual <a href="https://github.com/arafattehsin/CognitiveRocket/tree/master/AI-For-Every-Developer/Demos/Personalizer">GitHub repo</a> for the <a href="https://www.arafattehsin.com/tag/ai-for-every-developer/" target="_blank" rel="noopener">AI for Every Developer</a> series. You can play with it.
<h2>The YUM Bot</h2>
The overall idea is to create a Power Virtual Agents bot for the customers to suggest the best dessert based upon the <code>occasion</code> and <code>variety</code>. This best action will be delivered by the Personalizer API via Power Automate and displayed it as an Adaptive Card back to the customer / user.

<img class="aligncenter size-large wp-image-31662" src="https://www.arafattehsin.com/wp-content/uploads/2022/12/Highlevel-architecture-1024x393.png" alt="High Level Architecture for Personalised Chatbot" width="1020" height="391" />
<h2>Custom Connector</h2>
In our previous posts, we worked on the library well as the simulator based on .NET and how you can easily use Personalizer SDK to train your learning loop. This time, we're going to use a Personalizer endpoint to interact with the service. Initially, I looked at the Power Automate to find out if there was any connector available for Azure Personalizer. Unfortunately, I did not find one, so I thought to create a custom connector with the name of <strong>Azure Personalizer (Community)</strong>. If that's something new to you then you may want to check out some of our awesome Microsoft Business Applications MVPs on YouTube. They've explained this topic quite well.

Azure Personalizer (Community) connector has got two actions, <code>Rank</code> and <code>Reward</code>. It needs an API key of your Personalizer resource in the Azure to create the valid connection.
<h3>Rank Action</h3>
This action expects the same inputs as it receives from our .NET library i.e. <code>Context Features</code>, <code>Actions</code>, <code>EventId</code> and more. I've kept it as generalised as possible and that's why, all you have to do is to switch the layout of the input to entire array and paste your JSON.
<blockquote>Our <a href="https://www.arafattehsin.com/reinforcement-learning-in-apps-bots-websites-with-azure-personalizer-part-1/">first post</a> about Azure Personalizer has all the details about Rank and Reward API. Both of the actions are dependent upon the same API.</blockquote>
<img class="aligncenter size-full wp-image-31664" src="https://www.arafattehsin.com/wp-content/uploads/2022/12/rank-action.png" alt="Rank Action Request" width="662" height="708" />

&nbsp;

It sends back the <code>eventId</code> and the best action in the form of <code>rewardActionId</code>

<img class="aligncenter size-full wp-image-31665" src="https://www.arafattehsin.com/wp-content/uploads/2022/12/rank-action-response.png" alt="Rank Action Response" width="639" height="280" />

&nbsp;
<h3>Reward Action</h3>
This action expects the <code>eventId</code> and <code>reward</code> value. The reward can be anything between 0 and 1. For the simplicity, we will be sending 0 (bad) or 1 (good).

<img class="aligncenter size-full wp-image-31667" src="https://www.arafattehsin.com/wp-content/uploads/2022/12/reward-action.png" alt="Reward Action Request" width="691" height="358" />

&nbsp;
<blockquote>As the independent publisher certification process requires a good time and effort for the submission therefore, it's not my focus for now but will surely visit later.</blockquote>
<h2>Chat bot</h2>
Now, let's talk about the Power Virtual Agents. We are going to use the public preview of the latest unified authoring canvas. They have got a <a href="https://www.arafattehsin.com/power-virtual-agents-get-the-biggest-update-ever/">bunch of new features</a> and I've already covered <a href="https://www.arafattehsin.com/give-your-power-virtual-agents-a-voice-with-speech-and-telephony/">some of them</a> earlier. The idea over here is to enquire about two sets of information which is required by the Rank Action, <code>Occasion</code> and <code>Variety</code>. For the simplicity of this use case, we'll create a simple bot and switch off all the Custom Topics except Greeting. <i>It is not mandatory but just saying!</i>
<h3>Entities</h3>
After this, let's create two entities as a <code>ClosedList</code>. Start with <code>Occasion</code> and add synonyms for smart matching.

<img class="aligncenter size-full wp-image-31668" src="https://www.arafattehsin.com/wp-content/uploads/2022/12/occasion.png" alt="Occasion Entity in Power Virtual Agents" width="854" height="349" />

Do the same for Variety as well.

<img class="aligncenter size-full wp-image-31669" src="https://www.arafattehsin.com/wp-content/uploads/2022/12/variety.png" alt="Variety Entity for Power Virtual Agents" width="871" height="419" />
<h3>Topic (Book Order)</h3>
Just add at least 5 phrases to train the <code>BookOrder</code> topic. The more phrases you add, the better but 5 are also OK. As an example, you can add <em>I want to place an order. </em>

Before asking a question about the <code>Occasion</code> and <code>Variety</code>, let's add a variable and set its value as a table of items. You can do this by using the latest capabilities of PowerFx. This will be used later in our bot.

<img class="aligncenter wp-image-31670 size-full" src="https://www.arafattehsin.com/wp-content/uploads/2022/12/PowerFx-variables-PVA.gif" alt="Usage of variables with PowerFx in Power Virtual Agents" width="1524" height="932" />

Later on, just add two questions with multiple choice options to ask about the <code>Occasion</code> and <code>Variety</code> and store each of them into variables. Once we get these two values, we call our custom connector we created above, specifically Rank Action.

After its processing, we get a response in <code>eventId</code> and <code>rewardActionId</code>. Our concern is more about <code>rewardActionId</code> as this is an action (choice of a dessert) suggested by the Personalizer. So, what we do is, we create another variable and we apply <code>LookUp</code> on the table of items we created above to get the information about the specific <code>rewardActionId</code>.

The reason we do this <code>LookUp</code> and set it up in a separate variable is because we want to populate the Adaptive Card dynamically right within the Power Virtual Agents canvas <em><strong>not in Power Automate</strong>.</em>

<img class="aligncenter size-full wp-image-31672" src="https://www.arafattehsin.com/wp-content/uploads/2022/12/AdaptiveCards-PowerVirtualAgents.gif" alt="Adaptive Cards in Power Virtual Agents" width="1456" height="962" />

Customer or user can choose yes or no depending upon their preferred choice. This submission is also handled by Adaptive Cards <em>(I know it's not common yet).</em> However, the data property inside Action.Submit can only contain string to work properly for now. Otherwise, it won't send an event back to PVA and you may wonder what you did wrong. 🤷‍♂️

<code></code><img class="aligncenter size-full wp-image-31675" src="https://www.arafattehsin.com/wp-content/uploads/2022/12/Call-Reward-Action-1.png" alt="Call Reward Action" width="828" height="760" />

So that's a wrap of a bot. Now if you run it, it should behave in a similar way as this one below. Bonus takeaway for you is the proactive slot filling in Power Virtual Agents. This means that if you provide an entity's name (<code>birthday</code>, <code>meal</code> or <code>cake</code>) already in your question, it will skip that entity's question to speed up the process, automatically. Super cool, isn't it?

<img class="aligncenter size-full wp-image-31677" src="https://www.arafattehsin.com/wp-content/uploads/2022/12/PVA-demo.gif" alt="Power Virtual Agents Demo" width="800" height="474" />

In conclusion, personalization in customer service has many potential applications. It can be used to improve customer experiences, increase customer satisfaction, and improve the efficiency of customer service operations. By using customer data and technologies <span style="background-color: #ffff00;">like Azure Personalizer</span>, you can provide more personalised and relevant interactions for your customers, which can help to build stronger and more lasting relationships.

Until next time.

<em>P.S: The introductory 3 paragraphs and the conclusion except for the highlighted text of this blog post is purely written by <a href="https://chat.openai.com/">ChatGPT</a>. I could have made it better or added more of my thoughts but word on the street compelled me to keep the way it is. </em>🙂