Skip to main content

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.
Legacy Framework: TWML is no longer under active development. Much of the codebase is out of date and unused. It is maintained specifically for light ranker model training.

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

The DataRecordTrainer 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
These signals are stored in the DataRecord format.
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:
Key characteristics:
  • 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:
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

Deprecated Technology Stack
  • Built on TensorFlow v1 (no longer supported)
  • Limited model architecture flexibility
  • Lacks modern ML features (dynamic computation graphs, eager execution)
  • No active development or feature additions

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