DEV Community

Cover image for Amazon Personalize: Build Recommendation Systems Without ML
Tanseer for AWS Community Builders

Posted on

Amazon Personalize: Build Recommendation Systems Without ML

The recommendation technology behind Amazon.com, packaged as a service you can use without a data science team. Stop four in the AWS Hidden Gems series.

About this series

Most AWS learning stops after EC2, S3, IAM, and Lambda. But AWS has over two hundred services, and many of the most useful ones rarely appear in tutorials.

AWS Hidden Gems covers those underrated services you shouldn't ignore. Each article picks one, then explains why it exists, what it does, where it fits, and how to set it up from the console. Know the four basics above and you can follow along. Everything else gets explained as it comes up.

Today's service: Amazon Personalize

"Customers who bought this also bought" and "recommended for you" feel simple as a user, but they run on serious machine learning. Amazon Personalize gives you that same recommendation technology as a managed service. You bring your data, it trains a private model, and your app asks it what to show each user.

Why does this service exist?

Good recommendations need machine learning, and building an ML recommender from scratch is a long road. You need data scientists, pipelines to clean and prepare data, model training and tuning, and infrastructure to serve predictions in real time as users browse. Most teams cannot staff that.

Personalize packages the recommendation systems Amazon developed over decades. It handles the data preparation, model training, and real time serving. You never see the algorithms or the servers. You give it your interaction history, and it gives you recommendations through an API.

What is Amazon Personalize?

Personalize is a managed recommendation service. A recommendation system predicts what a user is most likely to want next, based on their behavior and the behavior of similar users.

You give it three kinds of data:

  • Interactions: the events that happened, like a user viewing, clicking, or buying an item. This is the most important data.
  • Items: details about the things you recommend, like category or price.
  • Users: details about your users, like age group or location. From that, Personalize can power several things: personalized recommendations for each user, similar items to something a user is viewing, and a personalized reordering of a list you already have. It keeps recommendations fresh by taking in new activity as it happens, so suggestions shift as a user browses.

What Personalize does not do is give good results without enough data. It needs a reasonable history of interactions to learn from, so it suits products that already have some usage.

A real world problem

A streaming video app has a growing catalog and a home screen that shows the same popular titles to everyone. Users scroll past them because nothing feels relevant to their taste.

The team wants a "recommended for you" row that reflects what each person actually watches. Building that with in house machine learning would take months and specialists they do not have.

With Personalize, they upload their viewing history, choose a recommendation type, let it train, and call it from the app to fill that row per user. The home screen starts reflecting real taste, and watch time goes up.

Real world use cases

  • Streaming services build personalized "recommended for you" rows from viewing history
  • Online stores show product recommendations and "you might also like" suggestions
  • News and content sites reorder articles to match each reader's interests
  • Marketplaces surface relevant listings instead of the same popular few
  • Apps personalize search results and category pages per user
  • Marketing teams pick the most relevant items to feature in an email to each customer The pattern is showing each user the items they are most likely to want, drawn from their own behavior.

Where it fits in AWS

Your interaction data usually starts in your app's database or event stream. You export it as a CSV file into S3, and Personalize imports it to train. Your app sends live events to Personalize as users act, and calls it for recommendations when rendering a screen.

flowchart LR
    A[App activity: views, clicks, buys] --> B[CSV in S3]
    B -->|Import| C[Personalize trains a model]
    C --> D[Deployed recommender]
    E[Your app] -->|Get recommendations for a user| D
    E -->|Send new events| C
Enter fullscreen mode Exit fullscreen mode

Personalize is the recommendation engine. S3 carries the training data in, and your app talks to the trained model over an API.

How the workflow runs

You start by creating a dataset group, a container for your data. You import your interactions data, and optionally items and users, from a CSV in S3. You pick a recipe, which is the algorithm for your goal, such as recommendations for a user or similar items. Personalize trains a model on your data, which takes a while. Once trained, you deploy it so your app can query it, then call it for recommendations in real time. As users keep acting, you send those events back so the model stays current.

flowchart TD
    A[Create dataset group] --> B[Import interaction data from S3]
    B --> C[Choose a recipe for your goal]
    C --> D[Personalize trains the model]
    D --> E[Deploy it for your app to query]
    E --> F[App gets recommendations per user]
Enter fullscreen mode Exit fullscreen mode

Setting it up in the AWS Console

For this you need a CSV of interactions in S3 with at least three columns: a user id, an item id, and a timestamp.

  1. Sign in to the AWS Console, search for Amazon Personalize, and open it. Check the region in the top right corner.
  2. Click Create dataset group, give it a name, and choose the custom option so you control the steps directly.
  3. Create the interactions dataset. Define a schema that matches your CSV columns (USER_ID, ITEM_ID, and TIMESTAMP), then start an import job pointing to your CSV file in S3. Personalize needs an IAM role that can read that S3 bucket, and the console can create this role for you.
  4. Wait for the import to finish, then create a solution, which is a trained model. Pick a recipe such as User-Personalization for per user recommendations. Personalize trains on your data, and this step can take a while depending on data size.
  5. When training finishes, create a campaign. A campaign is the deployed version of your model that your app calls for real time recommendations.
  6. Test it in the console. On the campaign page, enter a user id and Personalize returns a ranked list of item ids recommended for that user.
  7. To confirm the setup end to end, call the campaign from your code as shown next and check that it returns items for a real user id. Common mistakes: an import that fails almost always means the CSV columns do not match the schema you defined, so line them up exactly. If recommendations look random, the model may not have had enough interaction data, since Personalize needs a reasonable history to learn.

Using it from code

Once a campaign is deployed, getting recommendations is a single call with a user id.

import boto3

personalize = boto3.client("personalize-runtime")

response = personalize.get_recommendations(
    campaignArn="arn:aws:personalize:us-east-1:123456789012:campaign/my-campaign",
    userId="user-123",
    numResults=10,   # how many items to recommend
)

for item in response["itemList"]:
    print(item["itemId"], round(item.get("score", 0), 4))
Enter fullscreen mode Exit fullscreen mode

To send new activity so recommendations stay fresh, use the put_events call on the personalize-events client as users view or buy items.

Pricing

Item Detail
Data import Per GB of data ingested
Training Per hour of model training
Real time recommendations Per throughput unit per hour while deployed
Batch recommendations Per user or item processed in bulk jobs
Free tier First 2 months include data processing, some training hours, and recommendation capacity

The AWS AI services family

AWS AI Services
├── Personalize   recommendations and personalization
├── Rekognition   image and video understanding
├── Textract      data extraction from documents
├── Comprehend    text analysis and sentiment
├── Transcribe    speech to text
└── Lex           chatbots and voice assistants
Enter fullscreen mode Exit fullscreen mode

Like the rest of this family, Personalize hands you a hard machine learning capability through a simple API. Rekognition, from the last article, does the same for vision. Personalize does it for recommendations.

Wrapping up

Personalize turns your own usage data into recommendations, using Amazon's recommendation technology without asking you to build or understand the models. Next time a product needs "recommended for you" done well, you know the service that gets you there without a data science team.

Series progress

You are on stop four of AWS Hidden Gems.

  1. AWS Elemental MediaConvert
  2. Amazon IVS
  3. Amazon Rekognition
  4. Amazon Personalize (you are here)
  5. AWS AppSync
  6. Amazon Timestream
  7. Amazon Textract
  8. Amazon Kendra
  9. AWS DataSync
  10. AWS IoT Core Next up is AWS AppSync, the easiest way to build APIs that update in real time.

Let's connect

Questions, corrections, or want to talk through where this fits in your own project? Reach me at khantanseer43@gmail.com.

Top comments (0)