the-algorithm README

The project's README from github.com/twitter/the-algorithm. As one markdown file: README.md.

X's Recommendation Algorithm

X's Recommendation Algorithm is a set of services and jobs that are responsible for serving feeds of posts and other content across all X product surfaces (e.g. For You Timeline, Search, Explore, Notifications). For an introduction to how the algorithm works, please refer to our engineering blog.

Architecture

Product surfaces at X are built on a shared set of data, models, and software frameworks. The shared components included in this repository are listed below:

Type Component Description
Data tweetypie Core service that handles the reading and writing of post data.
unified-user-actions Real-time stream of user actions on X.
user-signal-service Centralized platform to retrieve explicit (e.g. likes, replies) and implicit (e.g. profile visits, tweet clicks) user signals.
Model SimClusters Community detection and sparse embeddings into those communities.
TwHIN Dense knowledge graph embeddings for Users and Posts.
trust-and-safety-models Models for detecting NSFW or abusive content.
real-graph Model to predict the likelihood of an X User interacting with another User.
tweepcred Page-Rank algorithm for calculating X User reputation.
recos-injector Streaming event processor for building input streams for GraphJet based services.
graph-feature-service Serves graph features for a directed pair of users (e.g. how many of User A's following liked posts from User B).
topic-social-proof Identifies topics related to individual posts.
representation-scorer Compute scores between pairs of entities (Users, Posts, etc.) using embedding similarity.
Software framework navi High performance, machine learning model serving written in Rust.
product-mixer Software framework for building feeds of content.
timelines-aggregation-framework Framework for generating aggregate features in batch or real time.
representation-manager Service to retrieve embeddings (i.e. SimClusers and TwHIN).
twml Legacy machine learning framework built on TensorFlow v1.

The product surfaces currently included in this repository are the For You Timeline and Recommended Notifications.

For You Timeline

The diagram below illustrates how major services and jobs interconnect to construct a For You Timeline.

The core components of the For You Timeline included in this repository are listed below:

Type Component Description
Candidate Source search-index Find and rank In-Network posts. ~50% of posts come from this candidate source.
tweet-mixer Coordination layer for fetching Out-of-Network tweet candidates from underlying compute services.
user-tweet-entity-graph (UTEG) Maintains an in memory User to Post interaction graph, and finds candidates based on traversals of this graph. This is built on the GraphJet framework. Several other GraphJet based features and candidate sources are located here.
follow-recommendation-service (FRS) Provides Users with recommendations for accounts to follow, and posts from those accounts.
Ranking light-ranker Light Ranker model used by search index (Earlybird) to rank posts.
heavy-ranker Neural network for ranking candidate posts. One of the main signals used to select timeline posts post candidate sourcing.
Post mixing & filtering home-mixer Main service used to construct and serve the Home Timeline. Built on product-mixer.
visibility-filters Responsible for filtering X content to support legal compliance, improve product quality, increase user trust, protect revenue through the use of hard-filtering, visible product treatments, and coarse-grained downranking.
timelineranker Legacy service which provides relevance-scored posts from the Earlybird Search Index and UTEG service.

The core components of Recommended Notifications included in this repository are listed below:

Type Component Description
Service pushservice Main recommendation service at X used to surface recommendations to our users via notifications.
Ranking pushservice-light-ranker Light Ranker model used by pushservice to rank posts. Bridges candidate generation and heavy ranking by pre-selecting highly-relevant candidates from the initial huge candidate pool.
pushservice-heavy-ranker Multi-task learning model to predict the probabilities that the target users will open and engage with the sent notifications.

Build and test code

We include Bazel BUILD files for most components, but not a top-level BUILD or WORKSPACE file. We plan to add a more complete build and test system in the future.

Contributing

We invite the community to submit GitHub issues and pull requests for suggestions on improving the recommendation algorithm. We are working on tools to manage these suggestions and sync changes to our internal repository. Any security concerns or issues should be routed to our official bug bounty program through HackerOne. We hope to benefit from the collective intelligence and expertise of the global community in helping us identify issues and suggest improvements, ultimately leading to a better X.

Read our blog on the open source initiative here.

the-algorithm (twitter/the-algorithm)

Searching Database…

这是什么?这是 X(原 Twitter)推荐算法的实际源代码,包含一系列用于构建和提供信息流的服务与任务,例如 For You Timeline、搜索、探索和通知。
这是一个应用,还是一组独立的服务?这是一组大约 20 个独立的后端服务、机器学习模型和共享软件框架(例如 tweetypie、SimClusters、navi、product-mixer),它们共同支撑推荐功能,而不是一个可直接安装的程序。
我该如何构建并运行完整系统?目前无法将其作为完整系统运行:大多数组件都有各自的 Bazel BUILD 文件,但没有顶层的 BUILD 或 WORKSPACE 文件把它们串联成一个可运行的整体。
不同部分分别使用哪些语言和框架?大多数服务使用 Scala/JVM 编写,机器学习服务层 navi 为追求性能采用 Rust 编写,而遗留的排序框架 twml 基于 TensorFlow v1 构建。
我能否直接从这个仓库自行部署完整的 X 推荐系统?开箱即用是不行的。这些代码公开的目的是供透明度和学习研究之用,而且仓库明确缺少完整、统一的构建和测试系统。
什么是 heavy-ranker?它为什么重要?它是一个对已召回的候选帖子进行打分的神经网络,是决定哪些帖子能进入用户 For You Timeline 的主要信号。
navi 是做什么用的?navi 是基于 Rust 的高性能模型服务框架,在生产环境中运行排序和推荐模型。
这个仓库真的包含搜索和探索功能吗?架构概览提到了搜索和探索这两个产品入口,但目前仓库中包含的组件只涵盖 For You Timeline 和推荐通知。
X 为什么要开源这些代码?X 希望社区审查这套算法、提交 issue 和 pull request,并通过其官方 HackerOne 漏洞赏金计划报告安全问题。
Creator
twitter
Size
8.2 MB
Stars
74K
Updated
CommitSep 03
Age
3y
Commits · 90 Days