AWS Machine Learning Blog

Omnichannel personalization with Amazon Personalize

As the touchpoints customers use to engage with brands move to an increasingly complex mixture of digital and real-life interactions, you’re faced with the daunting task of delighting your customers with personalized experiences that hit the mark across these channels. Customer expectations are evolving as well. Today’s customers quickly lose patience with brands that can’t seamlessly support transitioning experiences between mobile, web, email, SMS, call centers, and in-person engagements.

Amazon Personalize applies machine learning (ML) algorithms to produce personalized recommenders, also known as campaigns, that understand a user’s preferences over time while also adapting to a user’s evolving interests in real time. This powerful tool helps you deliver truly personalized customer experiences. However, putting Amazon Personalize to work across channels requires a thoughtful approach to the architecture and tools you use to power these experiences.

This post shows you how to integrate Amazon Personalize into a sample full-stack eCommerce application that delivers personalized recommendations across three common channels: web and mobile application, messaging, and conversational. A combination of a decoupled microservice architecture and a few AWS Lambda functions allow you to use Amazon Personalize campaigns and track customer intent across these channels. The following diagram illustrates this solution.

 

Overview of solution

This solution is available as part of the Retail Demo Store GitHub repo. The project deploys a full-stack eCommerce sample web application into your AWS account that demonstrates how to provide omnichannel personalization across web, mobile, messaging, and conversational channels. The application, as shown across multiple device types below, represents a typical eCommerce/retail use case that you can use as a model for many other industries.

The following diagram illustrates the relevant portions of the architecture for this post. The post explores how to deliver personalized recommendations from a single Amazon Personalize deployment across three different communication channels. An often subtle yet crucial requirement of true omnichannel user experiences, and what allows you to use shared Amazon Personalize campaigns in this use case, is being able to identify the same logical user across all channels. Indeed, one of the most powerful features of Amazon Personalize is being able to adapt to evolving user intent in real time. The following architecture achieves that by extending real-time recommendations across multiple channels.

The primary channel that most companies use to engage with their customers is through mobile and web applications. For this channel, depicted in 1, 2, and 3 in the preceding diagram, the mobile or web application sends clickstream events to Amazon Personalize to enable real-time recommendations and retrieves personalized product recommendations from a RESTful microservice hosted in Amazon Elastic Container Service (Amazon ECS). This microservice calls Amazon Personalize to get product recommendations for the current user and transforms the recommended item IDs into rich product information from a product catalog microservice. The response is a representation suitable for rendering in the user interface.

Another channel commonly used by companies, shown as 4, 5, 6 in the diagram, is outbound messaging such as email, SMS, and direct message. For messaging, the Retail Demo Store uses Amazon Pinpoint to segment users based on their behavior and traits and build dynamic messaging campaigns to target users. It also uses ML model integration in Amazon Pinpoint to retrieve personalized recommendations from Amazon Personalize. This allows you to send targeted messages that contain recommendations personalized to each user based on their current interests.

The conversational channel includes chat and voice interfaces built into an application or external conversational tools such as Alexa, Facebook Messenger, Slack, and Twilio. Although this post focuses on a chatbot interface in the web application, as shown in 7 and 8, you can easily extend it to other conversational tools.

Walkthrough

This post walks you through deploying the Retail Demo Store project to your AWS account and highlights the relevant code and configuration that enables the personalized omnichannel user experiences.

You complete the following steps:

  • Deploy the Retail Demo Store project to your AWS account using the supplied AWS CloudFormation templates (25–30 minutes)
  • Build Amazon Personalize campaigns to provide personalized recommendations across all three channels (2 hours)
  • Examine the personalized user experiences in the Retail Demo Store’s web application
  • Enable personalized product recommendations through outbound messaging in Amazon Pinpoint (1 hour)
  • Enable personalized product recommendations through a conversational interface in Amazon Lex (30 minutes)
  • Clean up resources

Prerequisites

For this walkthrough, you need the following prerequisites:

  • An AWS account
  • A user in your AWS account with the necessary privileges to deploy the project

Step 1: Deploying the Retail Demo Store to your AWS account

From the following table, choose Launch Stack in the Region of your choice. This list of Regions doesn’t represent all possible Regions where you can deploy the project, just the Regions currently configured for deployment.

Region Launch
US East (N. Virginia)
US West (Oregon)
Europe (Ireland)

Accept all the default template parameter values and launch the template. The deployment of the project’s resources takes 25–30 minutes.

Step 2: Building Amazon Personalize campaigns

Before you can provide personalized product recommendations, you first need to train the ML models and provision the inference endpoints in Amazon Personalize that you need to retrieve recommendations. The CloudFormation template deployed in Step 1 includes an Amazon SageMaker notebook instance that provides a Jupyter notebook with detailed step-by-step instructions.

  1. Sign in to the AWS account where you deployed the CloudFormation template in Step 1.
  2. On the Amazon SageMaker console, choose Notebook instances.

If you don’t see the RetailDemoStore notebook instance, make sure you’re in the same Region where you deployed the project.

  1. To access the notebook instance, choose Open Jupyter or Open JupyterLab.
  2. When the Jupyter web interface is loaded for the notebook instance, choose the workshop/1-Personalization/1.1-Personalize.ipynb notebook.

The notebooks are organized in a directory structure, so you may have to choose the workshop folder to see the notebook subdirectories.

  1. When you have the 1.1-Personalize notebook open, step through the workshop by reading and executing each cell.
  2. You can choose Run from the Jupyter toolbar sequentially execute the code in the cells.

The notebook takes approximately 2 hours to complete.

Step 3: Examining storefront personalization

In Step 2, you created three Amazon Personalize campaigns. Each campaign provides recommendations for the core use cases Amazon Personalize supports. For this step, you examine the personalized user experiences for each use case.

  1. To access the Retail Demo Store web application, locate the WebURL output parameter for the CloudFormation stack deployed in Step 1.

This is the public URL to the Amazon CloudFront distribution used to serve the web application. You can find the URL on the AWS CloudFormation console by selecting the RetailDemoStore CloudFormation stack deployed in Step 1 and choosing the Outputs tab for the root template. Choose the value for the WebURL output parameter to open the web application in your browser.

  1. Create a user account in the Retail Demo Store web application by choosing Sign In and Create account.

Be sure to enter a valid mobile phone number so you can confirm your account. After you submit the signup form, you receive an SMS with a 6-digit confirmation code.

  1. Use this code to confirm your account and sign in with your user name and password.

User personalization

The first Amazon Personalize use case in this post is user personalization, such as home pages or landing pages where you want to make personalized recommendations for the current user. In the Retail Demo Store web application, you can see this use case in action on the home page view. The following screenshot shows the Inspired by your shopping trends on the Retail Demo Store home page, which displays nine product recommendations from the Amazon Personalize campaign created with the HRNN-Metadata recipe in Step 2.

Because you’re signed in as a new user with no interaction history, the campaign initially recommends popular products based on the interactions from other users. As you view individual product details, Amazon Personalize learns your preferences in real time and adjusts the recommendations accordingly. This is accomplished by sending click events to an Amazon Personalize Event Tracker using the AWS Amplify JavaScript library. For example, the following code sends a ProductViewed event to Amazon Personalize when a user (anonymous or signed in) views a product in the web application:

AmplifyAnalytics.record({
    eventType: 'ProductViewed',
    userId: userId ? userId : null,
    properties: {
         itemId: product.id
    }
}, 'AmazonPersonalize');

Related item recommendations

The next use case is related item recommendations, such as item detail pages that also recommend items similar to the currently displayed item. You can find this implementation on the product detail view in the Retail Demo Store web application. To view the detail page for a product, choose Details for that product. The Amazon Personalize campaign behind this use case was created using the SIMS recipe in Step 2. The following screenshot shows recommended related items on a product details page.

For this example, the historical interactions dataset used to create the Amazon Personalize campaign has an affinity for products across the footwear and outdoors categories. Therefore, the related item recommendations campaign accurately recommends products from both categories (fishing lures from the outdoors category and a shoe from the footwear category). A typical content filtering technique for related item recommendations would likely not detect this type of relationship.

Personalized ranking

The final use case is personalized ranking, such as reordering a curated list of items based on the current user. You can also combine it with search engines to reorder query results before displaying them to the user.

In the Retail Demo Store web application, the Personalized-Ranking campaign trained in Step 2 is implemented on the category view. In the following screenshot, a list of links representing the product categories appear at the top of the home view. Choosing one of these links displays the products in the category. The products are listed in ranked order based on the current user.

Step 4: Enabling personalized product recommendations in Amazon Pinpoint

Up to this point, you have learned how to use Amazon Personalize to create personalized user experiences in a web application. For many companies, this is as far as they take personalization. There can be several reasons for this, including the inability to integrate a personalization solution into the tools used for other channels, such as marketing and messaging, or the lack of a single user profile across channels to effectively make recommendations.

In this step, you learn how to use the Amazon Personalize campaign behind the user recommendations use case in Step 3 to provide personalized recommendations in outbound user messaging using Amazon Pinpoint. In addition to reusing the HRNN-Metadata campaign you trained earlier, you also reuse the Retail Demo Store’s Products microservice and create a Lambda function to tie it all together. Although you follow another Jupyter notebook to complete all the steps, the following Python code example from the notebook illustrates how you configure an ML recommender in Amazon Pinpoint to link Amazon Pinpoint with your HRNN-Metadata campaign and Lambda function:

import boto3

pinpoint = boto3.client('pinpoint')

pinpoint.create_recommender_configuration(
    CreateRecommenderConfiguration={
        'Attributes': {
            'Recommendations.Name': 'Product Name',
            'Recommendations.URL': 'Product Detail URL',
            'Recommendations.Category': 'Product Category',
            'Recommendations.Description': 'Product Description',
            'Recommendations.Price': 'Product Price',
            'Recommendations.ImageURL': 'Product Image URL'
        },
        'Description': 'Retail Demo Store Personalize recommender for Pinpoint',
        'Name': 'retaildemostore-recommender',
        'RecommendationProviderIdType': 'PINPOINT_USER_ID',
        'RecommendationProviderRoleArn': pinpoint_personalize_role_arn,
        'RecommendationProviderUri': personalize_campaign_arn,
        'RecommendationTransformerUri': lambda_function_arn,
        'RecommendationsPerMessage': 4
    }
)

The Attributes map defines the attributes the Lambda function returns, which you can use in the Amazon Pinpoint message template. The RecommendationProviderIdType value of PINPOINT_USER_ID is how endpoints in Amazon Pinpoint are linked to user identities in your Amazon Personalize campaign. Lastly, the RecommendationProviderUri and RecommendationTransformerUri connect Amazon Pinpoint to your Amazon Personalize campaign and Lambda function, respectively.

The detailed instructions for this step are provided in another Jupyter notebook in the Amazon SageMaker notebook instance deployed in your AWS account. If necessary, sign in to the AWS account where you deployed the CloudFormation template in Step 1.

  1. On the Amazon SageMaker console, choose Notebook instances.

If you don’t see the RetailDemoStore notebook instance, make sure you’re in the same Region where you deployed the project.

  1. To access the notebook instance, choose Open Jupyter or Open JupyterLab.
  2. After the Jupyter web interface is loaded for the notebook instance, choose the workshop/4-Messaging/4.1-Pinpoint.ipynb notebook.
  3. Step through the notebook as before.

This notebook takes about 1 hour to complete.

Step 5: Enabling personalized product recommendations in Amazon Lex

The final channel you examine in this post is a conversational interface implemented using Amazon Lex. Chatbots and voice applications are becoming increasingly popular alternatives for consumers who are looking to engage with brands using hands-free or more interactive interfaces for customer support and self-service targeted engagements, such as booking appointments and ordering products and services.

You can build bot experiences in Amazon Lex where intents, utterances, slots, and responses are static and known at design-time on the Amazon Lex console. However, integrating dynamic behavior and fulfilling more complex bot intents requires connecting a bot to business logic and other parts of an application architecture.

In this step, you create a bot that provides three intents. Two basic intents provide a greeting to users and information about the Retail Demo Store’s return policy. The third intent allows the customer to ask for product recommendations. This intent uses the following Lambda function from the GitHub repo to retrieve recommendations for the current user using the Retail Demo Store’s Recommendations microservice and HRNN-Metadata campaign. Amazon Lex returns the recommendations as response cards. The web user interface renders the response cards in the Help view alongside the chatbot widget to allow the user to view and purchase products. See the following screenshot.

The detailed instructions for this step are provided in the workshop/5-Conversational/5.1-LexChatbot.ipynb Jupyter notebook. After you open it, step through the notebook as before.

This notebook takes approximately 30 minutes to complete.

Step 6: Cleaning up

To avoid incurring future charges, delete the resources the Retail Demo Store project created by deleting the CloudFormation stack you used during deployment. For more information about the source for this post and the full Retail Demo Store project, see the GitHub repo.

Conclusion

Perfecting personalized user experiences across the applications you build and communication channels you use to engage with customers is still a work in progress. Amazon Personalize provides the algorithms and infrastructure to build and deploy accurate and scalable personalized recommenders that learn from customer intents in real time. However, putting those recommenders to work to create seamless user experiences requires planning and design in the application architectures where they are deployed. This post demonstrated how to implement omnichannel personalization across three common channels: web application, messaging, and conversational. Explore your own applications for opportunities where you can personalize customer experiences with recommendations tailored to each user using Amazon Personalize.


About the Author

James Jory is a Solutions Architect in Applied AI with AWS. He has a special interest in personalization and recommender systems and a background in eCommerce, marketing technology, and customer data analytics. In his spare time, he enjoys camping and auto racing simulation.