马斯克与Twitter的渊源

近年来,Twitter已经成为全球最受欢迎的社交媒体平台之一(类比微博?),吸引了无数名人、政治家、企业家和普通用户在这里分享观点、展示自我。其中,特斯拉和SpaceX的创始人埃隆·马斯克(Elon Musk)是Twitter上最具影响力和活跃度的人物之一。他的推文往往能够引起公众广泛关注,对公司股票甚至整个行业的走向产生影响。

除了发表言论,Musk还曾多次购买twitter的股票直至成为最大股东,为了拯救twitter,或是重构twitter的“言论自由”,Musk向推特发出了收购要约,与董事会拉扯半年,终于在2022年8月正式接管Twitter。在Musk的积极推动下,Twitter开源了其推荐系统,大义上说是提升推荐算法的公平性和透明度,为全球开发者提供更多的创新与合作机会,其实是为了兑现Musk之前所提到的“言论自由”。

源码地址

Twitter系统及其算法都是模块化的,在不同的推荐场景,会有不同的服务及其任务,本文以“For You”频道举例,来描述该场景的工作原理。

系统总体架构

“For You” timeline

timeline 是一个时间线,类似微信的朋友圈,基于时间倒序的信息流,只是朋友圈信息都是自己关注的或者广告,For You是推荐给你的相关的推文,这些可能来自关注的用户,也可能来自没有关注的用户。

For You主页

系统架构图

“For You”推荐系统

一共三个模块:

  • DATA, Follow graph(社交图)、行为数据(点赞,评论,转化,点击等)、用户信息
  • FEATURES, 模型以及服务所用的特征数据,这些特征是通过模型或者图来获取的,使用在召回粗/精排以及过滤等下游处理中
  • HOME MIXERFor You Timeline 的主服务,执行推荐的整个过程,包括召回、粗精排以及重/混排等业务逻辑

推荐系统主要过程

与常用电商推荐系统类似,Twitter的推荐过程也分成候选集生成(也即召回 )、粗/精排以及重/混排三个步骤,并且都集成在上面架构图中的HOME MIXER服务中。

Candidate Source(候选集生成

候选集生成方式

候选集来自两个圈子,一个是In-Network Source,指来自关注的人,另一个是Out-of-Network Source,指来自不关注的人。

其中In-Network Source 通过Search Index服务获取的,它基于推文搜索系统 (Earlybird) 查找某个用户已经过关注人的所有推文,使用Real Graph(用户是否互动),Trust&Safety(是否安全),TweepGred(是否可信)等特征。

Out-of-Network Source通过下面三个模块获取:

  • CR Mixer,使用SimClusters、TwHIN、Trust&Safety和GraphJet特征,可以看到都是社区检测的相关特征。
  • UTEG, 为User Tweet Entity Graph的缩写,使用GraphJet特征(社交图特征)做协同过滤进行推文
  • FRS, 为follow-recommendations-service的缩写,一个给用户推荐关注的服务(Who-To-Follow ),使用GraphJet、RealGraph、SimClusters等社区发现的特征。

Heavy Ranker(粗/精排

粗排

负责粗排的有两个基于LR的模型,分别用于In-Network source的Earlybird和OUT-of-Network 的tweet排序。在In-Network的粗排中,特征及其处理如下图所示,参考the-algorithm\src\python\twitter\deepbird\projects\timelines\scripts\models\earlybird\earlybird_features.png

Earlybird用特征构建方式


精排

使用了MaskNet,论文在:https://arxiv.org/pdf/2102.07619.pdf、代码在https://github.com/twitter/the-algorithm-ml/blob/main/projects/home/recap/README.md。 这是一个多目标的神经网络,目标涵盖以下10个,然后使用加权求和计算最终得分排位排序依据,且各个目标的权重系数可以通过配置文件进行配置。

scored_tweets_model_weight_fav: The probability the user will favorite the Tweet.
scored_tweets_model_weight_retweet: The probability the user will Retweet the Tweet.
scored_tweets_model_weight_reply: The probability the user replies to the Tweet.
scored_tweets_model_weight_good_profile_click: The probability the user opens the Tweet author profile and Likes or replies to a Tweet.
scored_tweets_model_weight_video_playback50: The probability (for a video Tweet) that the user will watch at least half of the video.
scored_tweets_model_weight_reply_engaged_by_author: The probability the user replies to the Tweet and this reply is engaged by the Tweet author.
scored_tweets_model_weight_good_click: The probability the user will click into the conversation of this Tweet and reply or Like a Tweet.
scored_tweets_model_weight_good_click_v2: The probability the user will click into the conversation of this Tweet and stay there for at least 2 minutes.
scored_tweets_model_weight_negative_feedback_v2: The probability the user will react negatively (requesting "show less often" on the Tweet or author, block or mute the Tweet author).
scored_tweets_model_weight_report: The probability the user will click Report Tweet.

Heuristics & Filtering(重/混排

重排

  • Visibility Filtering: 可见性过滤,即屏蔽一些推文或者讨厌用户的推文。
  • Author Diversity: 作者多样性,避免来自同一作者的太多连续推文。
  • Content Balance: 内容平衡,上文中在社交圈和不在社交圈中的推文占比。
  • Feedback-based Fatigue: 针对用户提供的负面反馈,制定对应策略降低某些推文的分数。
  • Social Proof: 排除与推文没有二级关联的社交圈外的推文,即确保推文来自关注的人与推文互动、或关注推文的作者们。
  • Conversations: 通过将回复与原始推文串连在一起,为回复提供更多上下文展示。
  • Edited Tweets: 更新检测,确定当前设备上的推文是否过时,并发送指令以将其替换为编辑后的版本。

混排

将重排后的推文与广告啊、关注的人等一起混在一起,再推送到前端进行展示。


混排

服务的可配置化

Twitter不同版块的推荐是通过调用不同服务来实现的(比如For You版块是利用Home Mixer服务来实现的),并且这些服务是可配置化的,每个版块有不同的算法与业务逻辑,对应到不同的Pipeline,开发人员可以通过配置文件来定义各个pipeline的实现逻辑

- Candidate Generation - fetch Tweets from various Candidate Sources.
- Earlybird Search Index
- User Tweet Entity Graph
- Cr Mixer
- Follow Recommendations Service
- Feature Hydration
- Fetch the ~6000 features needed for ranking
- Scoring and Ranking using ML model
- Filters and Heuristics. For example:
- Author Diversity
- Content Balance (In network vs Out of Network)
- Feedback fatigue
- Deduplication / previously seen Tweets removal
- Visibility Filtering (blocked, muted authors/tweets, NSFW settings)
- Mixing - integrate Tweets with non-Tweet content
- Ads
- Who-to-follow modules
- Prompts
- Product Features and Serving
- Conversation Modules for replies
- Social Context
- Timeline Navigation
- Edited Tweets
- Feedback options
- Pagination and cursoring
- Observability and logging
- Client instructions and content marshalling

不同场景的服务会对应不同的pipeline,不同的pipeline对应到不同的配置文件。

- ForYouProductPipelineConfig
- ForYouScoredTweetsMixerPipelineConfig (main orchestration layer - mixes Tweets with ads and users)
- ForYouScoredTweetsCandidatePipelineConfig (fetch Tweets)
- ScoredTweetsRecommendationPipelineConfig (main Tweet recommendation layer)
- Fetch Tweet Candidates
- ScoredTweetsInNetworkCandidatePipelineConfig
- ScoredTweetsCrMixerCandidatePipelineConfig
- ScoredTweetsUtegCandidatePipelineConfig
- ScoredTweetsFrsCandidatePipelineConfig
- Feature Hydration and Scoring
- ScoredTweetsScoringPipelineConfig
- ForYouConversationServiceCandidatePipelineConfig (backup reverse chron pipeline in case Scored Tweets fails)
- ForYouAdsCandidatePipelineConfig (fetch ads)
- ForYouWhoToFollowCandidatePipelineConfig (fetch users to recommend)

重要模块/算法

模块名称作用
product-mixer构建内容源的软件框架,home-mixer便是基于product-mixer
navi用 Rust 编写的高性能机器学习模型服务。
graph-feature-service为有向用户对之间提供图特征的服务(例如,有多少个用户 A 的关注者喜欢用户 B 的推文)。
TwHIN用户和推文的密集知识图嵌入。
SimClusters社区检测和稀疏嵌入到这些社区中。
tweepcred用于计算 Twitter 用户声誉的 PageRank 算法。
trust-and-safety-models用于检测 NSFW 或有害内容的模型。
real-graph预测 Twitter 用户与另一个用户互动的可能性的模型。

总结

感谢Musk给我们开源了这个框架,让我们可以了解并学习Twitter这个社交平台背后的算法与技术,然后去芜存菁,更好的服务与酷家乐搜索推荐中的各个业务。


参考文档