Elon Musk

Twitter Makes Its Recommendation Algorithm Open Source — Here's How it Works

The company's coding offers insight into how tweets show up on a user's "For You" feed.

Beata Zawrzel/NurPhoto via Getty Images File photo

Twitter is giving users a peek behind the curtain as it begins the process of taking away blue check marks.

The company released code for its recommendation algorithm on GitHub (can view here and here) and posted a blog with an overview of how the algorithm works. CEO Elon Musk tweeted that the release was "most of the recommendation algorithm" and that the rest would be released in the near future. Musk's interest in the move dates back to March 24, 2022, when he posted a poll asking users whether they thought Twitter's algorithm should be open source.

There are three main stages in Home Mixer, the service that builds a user's "For You" feed, per Twitter's blog post:

  1. Fetch the best tweets from different recommendation sources in a process called candidate sourcing.
  2. Rank each tweet using a machine learning model.
  3. Apply heuristics and filters, such as filtering out tweets from users you’ve blocked, NSFW content, and tweets you’ve already seen.

Let's break down each of those steps a bit further:

What are candidate sources on Twitter?

The "For You" feed consists of a 50/50 split of In-Network and Out-of-Network candidates, though that number could vary for each user.

In-Network candidates are accounts that a user already follows. Twitter's Real Graph model is used to predict the likelihood that a user will interact with one of their In-Network accounts. The higher the Real Graph score between the user and a given In-Network account, the more likely one of its tweets will appear on the user's "For You" feed.

Out-of-Network candidates are people a user does not follow. Twitter uses Social Graph and Embedded Spaces to try and find the most relevant tweets from those accounts based on a user's engagements and numerical representation of the user's interests and tweets.

How does Twitter rank tweets for a user's "For You" feed?

After going through both groups of candidate sources, there are around 1,500 candidates for a user's "For You" feed.

Twitter takes thousands of features into account and placing labels to give each tweet a score. Likes, retweets, replies, photos and videos all boost a tweet's score, while links have a negative impact. Subscribing to Twitter Blue also adds to a candidate's reach.

At this point in the process, the algorithm no longer takes In-Network versus Out-of-Network into account. Twitter's coding specifically tracks metrics for four groups, though: Republican, Democrat, "power_user" ... and "Elon."

"This is the first time I'm seeing this," Musk said during a Twitter Spaces chat on Friday when asked about the code that follows his tweets specifically. "There’s a ton of stupid and embarrassing things being shown by making the code open source."

How do Twitter's heuristics, filters and product features work?

In an attempt to create a "balanced and diverse feed," Twitter applies heuristics and filters.

Visibility filtering takes a user's preferences into account, removing tweets from accounts a user has blocked or muted. Twitter's algorithm also aims to avoid too many consecutive tweets from one account, filter out tweets a user has already seen, lower the score of tweets where a user has provided negative feedback and making sure someone the user follows has engaged with a certain Out-of-Network candidate.

From there, Home Mixer adds in ads, follow recommendations and other non-tweet content before sending the tweets to a user's "For You" feed.

Will Twitter's recommendation algorithm change?

Musk said Twitter will update its algorithm every 24 to 48 hours based on user recommendations.

Exit mobile version