Predict customer contact intent using AI and Amazon Connect
Customers engage with businesses using a multitude of contact channels like voice, messaging, web, and social media. Each interaction includes customer identification, verification, and understanding the intent. This is followed by servicing the contact intent using either automated or live assistance. The primary customer need is expedited assistance to resolve the reason for the contact. It is therefore important to quickly understand the contact intent.
Legacy technologies limited businesses to forcing customers through menu trees to clarify their intent. The menu maze often was a reflection of the organizational structure of the business. Natural language understanding technologies (Amazon Lex) simplify this experience by enabling the customers to express the contact intent in a few words.
Another option to simplify intent capture is to use data. The contact intent is often correlated with a customer’s ongoing, or most recent set of interactions or events. For example, a retail banking customer experiencing a failed transaction at an ATM is likely to call up the contact center.
Another retail banking customer with an ongoing home loan request is likely to call about the loan status. However, it takes an ongoing domain and technical heavy-lifting to build, maintain, and adapt these patterns using rule-based systems. Rule-based approaches lack agility, and cannot scale across multiple customer interaction channels used by digital businesses. With pay-as-you-go AI/ML capabilities in the cloud, businesses can now use historical data to learn, generalize, and predict caller intents for future interactions.
In this blog post, we walk you through the steps to build an intent prediction model using Amazon Machine Learning capabilities. Customers can expect an intelligent, personalized, and faster resolution experience using this approach. Businesses can reduce technology maintenance costs, improve customer satisfaction scores, improve automation rates, and reduce agent transfer costs. We use Amazon Personalize from Amazon Connect to create this solution.
To follow along with the solution presented in this blog post, you must understand the following AWS services and features:
- Amazon Connect
- Amazon Lex
- Amazon Personalize
- AWS Lambda
- Amazon DynamoDB
- Amazon SageMaker
- AWS Identity and Access Management (IAM)
- You also need an active AWS account with the permission to create and modify Lambda functions, Amazon Personalize, Amazon S3 objects, and IAM roles.
To begin, you need an Amazon Connect instance configured for inbound and outbound calls. Claim a phone number after you create your instance. The Get Started with Amazon Connect and Create Amazon Connect contact flows documentation provide valuable background knowledge for this process.
In the preceding architecture, the following sequence of steps takes place for an incoming contact:
- A customer calls into a toll Free/DID number, which invokes an Amazon Connect contact flow.
- Amazon Connect invokes a Lambda function by passing the customer identification information within the contact flow.
- The Lambda function invokes Amazon Personalize API to retrieve the recommendation for the customer contact intent. Amazon Personalize uses a trained model using the historical contact activity data from a representative sample of callers.
- If the intent is predicted with a high confidence score, the Lambda function returns a predicted intent to Amazon Connect. The score threshold value is configurable. The contact flow in Amazon Connect prompts the caller to confirm the predicted intent.
- Otherwise, the Lambda function returns a value indicating that the model could not predict an intent for this interaction. The contact flow in Amazon Connect proceeds with the intent capture experience using either Amazon Lex (NLU), or a menu.
- Before the end of the call, the actual confirmed intent of the customer is fed back into the Amazon Personalize API. This is used for future predictions for this caller.
This blog post uses a sample dataset in the format as prescribed by Amazon Personalize. It uses two datasets (1) Users and (2) Interactions. The first step in the Amazon SageMaker notebook downloads user data formatted in the prescribed format from a publicly accessible web-location. Next, it creates the interactions data to be used for initial training.
- The Users dataset contains a required attribute USER_ID (string). It can have additional optional metadata attributes. The sample contact center dataset contains the user identifier and optional profile metadata.
- The Interactions dataset has three required attributes USER_ID (string), ITEM_ID (string), and TIMESTAMP (long). The sample contact center dataset contains historical contact activity data of the users. ITEM_ID contains the caller intent for the contact, represented as a single word string. For example, a string AC_PA encodes a contact intent related to debit card and PIN activation related for retail accounts product.
You can explore the entire dataset in the Amazon SageMaker notebook deployed in the following section. If you want to use a different dataset, the dataset schema documentation explains the format requirements for Amazon Personalize.
Setting up the Solution
Step 1: Deploy Amazon SageMaker notebook
The AWS CloudFormation template launches a SageMaker notebook instance with required IAM roles and permissions. This notebook is used to download sample data, and to train an Amazon Personalize model for the solution.
- Log in to the AWS Management Console.
- Choose the following button to launch the stack in AWS CloudFormation. Note that, the template launches resources in us-east-1 (North Virginia) Region.
- Select “I acknowledge that AWS CloudFormation might create IAM resources.”
- Choose Create stack.
- Wait until the CloudFormation stack moves from CREATE_IN_PROGRESS state to CREATE_COMPLETE state (~5 minutes).
Step 2: Train and deploy Amazon Personalize campaign
- From the AWS Management Console, open the Amazon SageMaker console.
- On the navigation bar, choose Notebook instances.
- Choose Open Jupyter to open the Jupyter web interface.
- On the Jupyter web interface, choose sourcecode.
- Click on train_personalize_with_customer_and_contact_records.ipynb to launch the Python notebook.
- On the top menu bar, choose Cells, Run All. (Note: If you click on the Run option available on the toolbar, you need to run each cell separately.)
- The notebook takes ~70 minutes to run. There are three cells that take longer than others to finish running. For these steps, you see progress indicator status (CREATE IN_PROGRESS) every minute as a console message until it reaches the final status (ACTIVE). Do not close the browser window with the notebook instance until all cells finish running.
- After the cells have finished running, copy the values of campaign_arn and tracking_id variable outputs at the bottom of the notebook.
Step 3: Deploy Lambda functions
The AWS CloudFormation template following creates two Lambda functions with required IAM roles and permissions. These functions perform Amazon Personalize API operations and expose the necessary outcomes to Amazon Connect.
- Log in to your AWS Management Console.
- Choose the following button to launch the stack in AWS CloudFormation.
- In the Parameters section, enter values for the two parameters PersonalizeCampaignARN and PersonalizeModelTrackingID copied from the notebook console earlier.
- Check all acknowledgement boxes about IAM resources and capabilities.
- Choose Create stack.
- Wait until the CloudFormation stack moves from CREATE_IN_PROGRESS state to CREATE_COMPLETE state (~5 minutes). This CloudFormation stack launches two AWS Lambda functions with required IAM roles and permissions.
- From the AWS Management Console, open the AWS Lambda console.
- Verify that you are able to see two recently deployed AWS Lambda functions named predict-ci-li-update-real-time-customer-intent and predict-ci-li-get-personalized-intent.
Step 4: Grant Amazon Connect permission to run your Lambda function
Verify that the Amazon Connect instance has permissions to access this newly created AWS Lambda function by following these steps.
- From the AWS Management Console, open the Amazon Connect console.
- Select your Amazon Connect virtual contact center instance.
- Choose Contact flows and scroll down to the AWS Lambda section.
- On the Function drop-down menu, select predict-ci-lf-get-personalized-intent function and choose +Add Lambda Function.
- Again, on the Function drop-down menu, select predict-ci-lf-update-real-time-customer-intent function and choose +Add Lambda Function.
Step 5: Import and configure the Amazon Connect contact flow
- Download the pre-built contact flow.
- From the AWS Management Console, open the Amazon Connect console.
- Select your Amazon Connect virtual contact center instance and log in.
- On the navigation bar of the Amazon Connect console, choose Routing, Contact flows
- Choose Create contact flow button at the top-right.
- On the drop-down at the top-right, select Import flow.
- Choose Select and select the PredictCustomerIntentFlow file downloaded in step 1.
- On the contact flow, find the Invoke AWS Lambda function block. Open the settings for the block by selecting the header.
- Select the Lambda function predict-ci-lf-get-personalized-intent that you granted Amazon Connect permissions in Step 4.
- Choose Save.
- Choose the header for the Invoke AWS Lambda function block (second row) and select the Lambda function predict-ci-lf-update-real-time-customer-intent.
- Choose Save.
- Save and Publish your contact flow.
The pre-built contact flow PredictCustomerIntentFlow is made up of the following key steps:
- Set the basics – logging, recording, and default voice using Amazon Polly (US-English).
- Greet the caller and prompt for identification. In this blog post, we use a 5-digit account number as an identifier.
- Invoke the predict-ci-lf-get-personalized-intent function to retrieve recommended intent prediction for this caller.
- Prompt the caller to confirm the predicted intent (high confidence score), or ask the caller to describe the contact intent.
- Invoke the predict-ci-lf-update-real-time-customer-intent function to provide a real-time update on the intent that the customer either confirmed or entered.
Step 6: Try it out
- In your Amazon Connect instance, choose the Routing icon from the navigation bar, and choose Phone numbers.
- Choose the phone number you want to associate with your new contact flow to edit.
- Choose the name of your contact flow from the Contact flow/ IVR drop-down menu, and choose Save.
- To make a test call, call the phone number you associated to the flow.
- High-Confidence prediction test call: Use a customer identifier with a recent contact history record in the dataset results in a prediction with high confidence score. Enter the 5-digit customer identifier 35739 to be presented with an intent prediction, based on a prior transaction for this user identifier in the dataset.
- Low-Confidence prediction test call: A customer identifier that is new to the dataset, or with no recent contact history results in a prediction with a low confidence score. Enter the 5-digit customer identifier 89789 to be presented with the IVR main menu. The prediction score is not sufficient to present a personalized prediction. The sample main menu provides two options (home loans, and credit cards) to bootstrap new customer interactions.
- In both scenarios, the IVR confirms and captures the actual intent of the customer. It uses this data to make predictions for subsequent calls. If you call again with the same customer identifier, you may be presented with a different intent prediction result dynamically. Amazon Personalize updates the dataset in real time, and is able to adjust the recommendations accordingly.
- This blog post uses a sample dataset injected with some activity patterns. For enterprise use cases, we recommend using customer interaction data from all available channels such as online, email, mobile in addition to the contact center. The prediction results are more accurate with interactions and event data from all contact channels consolidated together.
- Programming rules and logic can be used along with predictions. If there are strong correlations between intents on prior call and next, these can be implemented using rules. These rules if applicable for an interaction, can be prioritized before a prediction.
To avoid ongoing charges, follow these steps to clean up this deployment.
- Open the clean_up_personalize_resources.ipynb notebook provided in the sourcecode directory in the SageMaker notebook.
- On the top menu bar, choose Cells, Run All to delete the personalize artifacts, Amazon S3 objects, and buckets created by the SageMaker notebook. (Note: If you click on the Run option available on the toolbar, you need to run each cell separately.)
- To remove the associated AWS resources for this solution, delete the two CloudFormation stacks one at a time.
Predicting customer contact intent simplifies and improves customer experience. Automating the predicted intents in Amazon Connect can also result in higher self-service rates. For calls that are routed straight to an agent, it improves routing accuracy and reduces agent handoffs. There are multiple approaches to predicting customer contact intents. In this blog post, we implemented an intent prediction solution based on machine learning, using Amazon Personalize and Amazon Connect. The objective is to build a solution that can learn and generalize without hardcoding a fixed set of rules. The Amazon Personalize based approach can reduce the time it takes to implement a machine learning model from scratch.