TWML (Twitter Machine Learning)
TWML is one of X’s machine learning frameworks, built on TensorFlow v1. While largely deprecated, it remains in active use for training the Earlybird light ranking models that power X’s search-based candidate retrieval.Overview
TWML (Twitter Machine Learning) was X’s original machine learning framework, providing abstractions on top of TensorFlow to simplify model training and deployment. While most ML efforts have migrated to newer frameworks, TWML continues to serve a critical role in the recommendation pipeline.Current Usage
TWML is exclusively used for training Earlybird light ranking models:Light Ranker Training
Located in:
src/python/twitter/deepbird/projects/timelines/scripts/models/earlybird/The light ranker is a critical component that pre-filters candidates from the search index before heavy ranking.Core Component: DataRecordTrainer
TheDataRecordTrainer class contains the core training logic for TWML models:
Light Ranker Training Pipeline
The light ranker training process follows these steps:1
Data Collection
Gather user engagement signals from production logs:
- Tweet clicks
- Video watch time
- Favorites (likes)
- Retweets
- Quote tweets
- Replies
2
Feature Engineering
Extract features from DataRecords:
3
Model Training
Train using the DataRecordTrainer:
4
Model Export
Export trained model for serving in Earlybird search index
5
Deployment
Deploy model to production Earlybird instances for real-time scoring
DataRecord Format
TWML uses a proprietary DataRecord format for training data:- Efficient storage of sparse features
- Support for multi-task learning (multiple labels)
- Optimized for TensorFlow v1 input pipelines
Integration with Ranking Pipeline
TWML-trained light ranker models integrate into the recommendation pipeline:Light Ranker Model Architecture
The light ranker uses a relatively simple architecture optimized for low latency:Training Objectives
The light ranker optimizes for multiple engagement signals:- Primary Objective
- Secondary Objectives
- Combined Loss
Tweet Click PredictionThe primary label is whether the user clicked on a tweet:
Key Features
DataRecord Format
Efficient sparse feature representation optimized for large-scale training
Multi-Task Learning
Support for multiple training objectives (clicks, engagement, watch time)
TensorFlow v1
Built on TensorFlow 1.x with familiar training APIs
Production Proven
Battle-tested on billions of training examples at X scale
Limitations
Migration Path
For new models, X has migrated to modern frameworks:1
Heavy Ranker
Uses PyTorch with more sophisticated architecturesSee:
the-algorithm-ml/projects/home/recap/2
Other Models
New models use PyTorch, JAX, or TensorFlow 2.x
3
Light Ranker Migration
Eventually, light ranker training will migrate away from TWML
File Locations
Learn More
Ranking Systems
Learn how light ranker fits into the overall ranking pipeline
Candidate Generation
Understand the candidate sourcing that feeds the light ranker