Skip to main content

TikTok "For You" Feed

Use Case

TikTok has set itself apart from other social media platforms with its personalized "For You" feed, which delivers a stream of content that is tailored to each user's individual preferences. This means that users are more likely to see content that they find interesting, entertaining, and relevant, which in turn encourages them to spend more time on the app and interact with more content while also creating a sense of community among users by connecting them with like-minded individuals. A personalized feed is also important for TikTok from a business perspective. By delivering targeted content to users, TikTok is able to generate more accurate data on user preferences and behavior, which can be used to improve its advertising capabilities and generate more revenue. In short, a personalized feed is a crucial element of TikTok's success and is essential for both users and the platform itself. User’s spend on average 56 minutes a day on TikTok!(1) If you’re hoping to make your feed provide a similar delightful and engaging experience to your users, and realize the business benefits that go along with that, you must add personalization to it. On the surface, it seems that all you need to create a recommendation system is an events table containing the interactions between users and items (which essentially tell the system what a user likes and dislike). This is enough to get started with a simple collaborative filtering model but you’ll quickly run into major problems.

  • Why do my users always get shown the same set of items (aka stuck in a filter bubble)?
  • How do I make the experience for new users more personalized?
  • How does a new item get a chance at going viral?
  • How come it doesn’t feel like the feed is quickly changing based off my interactions?

TikTok does an amazing job of handling all these complicated challenges. They incorporates user features like what the user’s selected interests are and location and they incorporates item features like caption, hashtags, and sounds. They also do content understanding, meaning they can know the video is about snowboarding just by looking at the frames in the video. They have a perfect blend of showing content the user has previously shown interest in and showing content they think the user will want to see and discover. All of this is done incredibly quickly by leveraging powerful (and complicated) realtime infrastructure as well as session based models which provide the feeling of the feed “being alive” and “learning on the fly”.(2) If you’d like to read more about TikTok’s algorithm works, we’ve written a full blog post about it here. Shaped does many of the same things TikTok’s algorithm does and can power this use-case for you out of the box! All you need to do is tell us where you’re storing your user, item, and event data and Shaped will train a model and provide you with an endpoint to power your feed 💪.

Shaped Model Creation

First create the model.yaml file:

model.yaml
---
model:
name: post_recs
connectors:
- type: BigQuery
id: bigquery_events
location: us-east1
project_id: my_app
dataset: my_dataset
fetch:
users: |
SELECT
user_id,
country
FROM
bigquery_events.users
items: |
SELECT
post_id as item_id,
creator_id,
tags,
caption,
song_id
FROM
bigquery_events.posts
events: |
SELECT
user_id,
post_id as item_id,
created_at,
CASE
WHEN time_spent > 7 THEN TRUE
ELSE FALSE
END AS label
FROM
bigquery_events.post_views

Then use the Shaped CLI to create the model with the command:

shaped create-model --file model.yaml

Shaped Recommendations

To see a response:

shaped rank --model-name post_recs --user-id “325913”

{
"ids": [
"21772",
"20983",
"96921",
"10569",
"34599",
],
"scores": [
0.98,
0.92,
0.87,
0.85,
0.73
],
"metadata": [
{
"creator_id": "@snowrider",
"tags": [
"#snowboard",
"#snowboarding",
"#snow",
"#snowboarder",
"#snowboarders",
"#snowboardlife"
],
"caption": "BEST Day Of The Season! 🏂",
"song_id": "58313"
},
{
"creator_id": "@snownewfriends",
"tags": [
"#snow",
"#winter",
"#pow"
],
"caption": "Fresh pow 🌨 never gets old 🤤",
"song_id": "85201"
},
{
"creator_id": "winterwonderlander",
"tags": [
"#snowboardlife",
"#bluebird",
"#powderday"
],
"caption": "Bluebird powder day 🙌",
"song_id": "58313"
},
{
"creator_id": "@snowrider",
"tags": [
"#snowboard",
"#snowboarding",
"#snow",
"#snowboarder",
"#snowboarders",
"#snowboardlife"
],
"caption": "💯th day on the mountain",
"song_id": "919"
},
{
"creator_id": "@powboarder",
"tags": [
"#snowboarding",
"#winter",
"#snow"
],
"caption": "Trips like these remind me snowboarding is the best sport ever!",
"song_id": "11156"
}
]
}

(1) https://www.oberlo.com/statistics/average-time-spent-on-tiktok#:~:text=The%20average%20daily%20time%20spent,14.8%25%2C%20to%2052%20minutes

(2) https://newsroom.tiktok.com/en-us/how-tiktok-recommends-videos-for-you