X releases the original “For You” recommendation algorithm code: a practical guide to running Twitter accounts with algorithms

ChainNewsAbmedia

Elon Musk (Elon Musk) announced on X on May 15 that the latest X algorithm has been released to GitHub. According to the xAI-publicly available xai-org/x-algorithm repository on GitHub, the focus of this release is the core recommendation system that powers the “For You” feed on the X platform. The system combines on-platform content from accounts the user has already followed with off-platform content mined from a global content pool via machine learning, and then hands everything over to a Grok-based transformer model for ranking.

The project uses the Apache 2.0 license and is mainly written in Rust and Python; as of the time of querying, GitHub shows about 21k stars and 3,800 forks.

For You recommendation architecture: Thunder finds followed content, Phoenix mines off-platform content

According to the repository documentation, X’s For You feed is mainly composed of two types of candidate content sources.

First is on-platform content, handled by the Thunder module. Thunder is an in-memory post storage area and a real-time data ingestion pipeline. It consumes posts from Kafka to build and delete events, tracks all users’ recent posts, and provides content candidates from their followed accounts to requesters. The documentation emphasizes that Thunder can provide on-platform content candidates with sub-millisecond queries without needing to query external databases.

Second is off-platform content, handled by Phoenix Retrieval. Phoenix finds posts from the global content pool that users may be interested in but that are not from followed accounts. Its retrieval stage uses a Two-Tower Model: the User Tower encodes user features and interaction history into vectors, the Candidate Tower encodes candidate posts into vectors, and then uses dot-product similarity to find the most relevant content.

These candidate contents then enter the Home Mixer, the orchestration layer of the For You feed. Home Mixer is responsible for querying the user’s context, retrieving candidate content, filling in post and author data, filtering out ineligible content, calling the ranking model, applying score adjustments, and finally selecting the posts to display on the user’s For You page. The documentation also states that Home Mixer exposes a ScoredPostsService gRPC endpoint to return ranked posts for specific users.

Grok architecture as the core of the recommendation system

The most closely watched aspect this time is that X’s recommendation system clearly has Grok integrated.

The GitHub README states that the content in the For You feed is ranked by Phoenix, which is a Grok-based transformer model. Phoenix predicts the probability of interactions each post may generate, and then combines these prediction values using weighted aggregation to produce a final score. The documentation also notes that the transformer implementation in this repository is ported from xAI’s open-source Grok-1 and adjusted for recommendation scenarios, such as adding custom input embeddings and using an attention mask to isolate candidates.

But this does not mean X has fully released the entire production environment model. Phoenix’s README clearly says that this release is a mini version; production uses a larger model with more layers and wider embeddings. At the same time, the publicly released checkpoint is a snapshot frozen at a point in time from a continuous training process, while production Phoenix continues to be trained using real-time data.

May 15 update: executable end-to-end inference, mini Phoenix model, ad-mixing system

According to the GitHub update notes, the May 15 version added several key components.

First is the end-to-end inference pipeline. The new phoenix/run_pipeline.py replaces the previously separate run_ranker.py and run_retrieval.py. It can use a single entry point to connect the “retrieval → ranking” flow, using exported checkpoints to simulate how the two stages are combined in production.

Second is the pre-trained model artifact. The released mini Phoenix model is distributed via Git LFS. The documentation says it contains 256-dimensional embeddings, 4 attention heads, 2 transformer layers, and is about 3GB, allowing developers to perform out-of-the-box inference without having to train the model themselves. Phoenix’s README also notes that the public demo corpus is a dataset of motion-themed posts with about 537k entries from a 6-hour time window, used to demonstrate the retrieval stage.

In addition, the repository also added the Grox content-understanding pipeline for content understanding tasks such as spam detection, post-category classification, and PTOS policy enforcement. At the same time, it added Home Mixer’s ad-mixing system, responsible for ad insertion and placement in the feed, and includes brand safety tracking.

Ranking model predicts 15 interaction types at once—more than a single “relevance” score

Phoenix’s ranking model doesn’t just output a single abstract “relevance” score; it predicts the probability of multiple interaction behaviors at the same time.

According to the documentation, the model predicts 15 behaviors, including favorite, reply, repost, quote, click, profile click, video view, photo expand, share, dwell, follow author, as well as not interested, block author, mute author, report, etc.

Then the Weighted Scorer combines these interaction probabilities with weights into the final score. Positive behaviors such as liking, reposting, and sharing are given positive weights, while negative behaviors such as blocking, muting, and reporting are given negative weights, pushing down content the user is likely not to like.

After the model’s scores are computed, the system applies additional adjustments. For example, the Author Diversity Scorer reduces scores for repeated authors to maintain feed diversity; the OON Scorer adjusts out-of-network content—that is, content from accounts not followed by the user.

This means that X’s “For You” isn’t simply pushing up the posts most likely to be liked. Instead, it breaks down and predicts multiple interaction behaviors and forms the final ordering through a weighted design. It also means the algorithm’s true value judgment isn’t only in the model itself—it also exists in the various interaction weights and post-processing rules.

Candidate isolation: post scores should not be affected by other posts in the same batch

A particularly notable item in this release is “Candidate Isolation.”

Phoenix’s README indicates that during the ranking stage, candidate posts cannot attend to each other; they can only attend to the user and its history. The purpose of this design is to ensure that the score of a single post doesn’t change depending on which other posts are placed into the same batch together. In other words, a post’s score should depend on its relationship with the user—not on which competing posts happen to be in the same batch.

This also has potential implications for creators. In the past, many community practices have speculated that posting time should avoid popular events or high-interaction posts in order to prevent being outshined by strong content in the recommendation pool. But if candidate isolation is implemented as described in the documentation, then at least at the model inference layer, a single post’s score would not directly change just because other strong posts appear in the same batch.

However, this doesn’t mean posting time is completely unimportant. Because factors in the earlier candidate recall stage—such as content freshness, the user’s online time window, filtering out already seen content, attention competition from popular events—may still affect the final exposure.

“The no human features” narrative still has controversy: besides model ranking, manual rules still exist

In its documentation, xAI claims the system has eliminated all manually designed features and most heuristic rules, relying mainly on Grok-based transformers learning relevance from user interaction sequences. The documentation also lists five core designs, including no manually designed features, candidate isolation in the ranking stage, hashed embeddings, multi-behavior prediction, and a composable pipeline architecture.

But this claim needs a more precise interpretation. Even in the same documentation, it can be seen that before entering ranking, the For You feed first goes through a large number of pre-scoring filters—for example, removing duplicate posts, posts that are too old, the user’s own posts, posts from blocked or muted accounts, muted keywords, content that has already been seen or recently appeared, and subscription content that is not eligible. After ranking, there are also post-selection filters such as deletions, spam filtering, filtering violent and graphic content, and removing duplicate conversation-thread branches.

Therefore, a more accurate way to put it should be: X’s “candidate ranking for content relevance” is mainly learned by a Grok-based transformer and no longer relies on traditional hand-crafted content features. But the entire For You feed still has a large number of product rules, filters, weights, and post-processing mechanisms. These rules also shape what users ultimately see.

Hands-on playbook: how to use the X algorithm to manage an account

In real-world practice, if creators want to “ride the algorithm” to manage an X account, the key is no longer just chasing likes or reposts; it’s about understanding that the For You system evaluates multiple interaction signals at the same time. Positive signals include time spent, clicks, replies, reposts, following authors, watching videos, and expanding photos; negative signals include not interested, muting, blocking, and reporting.

This means content can’t rely only on sensational headlines to get clicks, because if a user clicks in and then quickly scrolls away, taps not interested, or even blocks the author, it may instead reduce the performance of subsequent recommendations.

For account managers, a more effective strategy is to improve “interaction quality.” Capture attention in the first few seconds, write the body so people will stay to read, and design a conclusion that naturally invites readers to reply or share instead of forcing interactions. At the same time, because the system adjusts for author diversity, densely posting in a short period may not linearly amplify exposure; it may instead be diluted by downranking from the same author. A more reasonable approach is to control the posting cadence so each piece of content has a clear theme, sufficient information density, and a stance that can be reposted.

Finally, recommending off-platform content means an account doesn’t have to rely solely on existing followers. As long as the content can keep unknown audiences engaged, earn clicks, and attract following behavior, it has a chance to be pushed into a larger For You traffic pool. But the prerequisite is to avoid low-quality farm posts, duplicate content, and overly controversial operations—because once these behaviors trigger muting, blocking, or reporting, the algorithm’s punishment is usually heavier than the short-term traffic boost.

This article: X publicly released the original source code of the “For You” recommendation algorithm—hands-on instruction on using the algorithm to manage a Twitter account. First appeared on Lian News ABMedia.

Disclaimer: The information on this page may come from third parties and does not represent the views or opinions of Gate. The content displayed on this page is for reference only and does not constitute any financial, investment, or legal advice. Gate does not guarantee the accuracy or completeness of the information and shall not be liable for any losses arising from the use of this information. Virtual asset investments carry high risks and are subject to significant price volatility. You may lose all of your invested principal. Please fully understand the relevant risks and make prudent decisions based on your own financial situation and risk tolerance. For details, please refer to Disclaimer.
Comment
0/400
No comments