Overview
ThePhoenixModel is a transformer-based recommendation model for ranking candidate posts. It processes user features, interaction history, and candidate posts to predict engagement actions.
Classes
PhoenixModel
A transformer-based recommendation model for ranking candidates.The underlying Grok transformer model
Model configuration including embedding size, sequence lengths, and hash config
Forward propagation data type for computation
Optional name for the model
PhoenixModelConfig
Configuration dataclass for the recommendation system model.Transformer architecture configuration
Embedding dimension size
Number of action types to predict (e.g., like, repost, reply)
Maximum length of user history sequence
Maximum number of candidate posts to rank
Optional model name
Forward propagation data type
Hash configuration for multi-hash embeddings
Size of product surface vocabulary (e.g., ForYou, Following, Search)
HashConfig
Configuration for hash-based embeddings.Number of hash functions for user embeddings
Number of hash functions for post embeddings
Number of hash functions for author embeddings
Named Tuples
RecsysBatch
Input batch for the recommendation model containing feature data (hashes, actions, product surfaces) but NOT embeddings.User hash values [B, num_user_hashes]
Post hash values for history [B, S, num_item_hashes]
Author hash values for history [B, S, num_author_hashes]
Multi-hot action vectors for history [B, S, num_actions]
Product surface indices for history [B, S]
Post hash values for candidates [B, C, num_item_hashes]
Author hash values for candidates [B, C, num_author_hashes]
Product surface indices for candidates [B, C]
RecsysEmbeddings
Container for pre-looked-up embeddings from the embedding tables.Pre-looked-up user embeddings [B, num_user_hashes, D]
Pre-looked-up post embeddings for history [B, S, num_item_hashes, D]
Pre-looked-up post embeddings for candidates [B, C, num_item_hashes, D]
Pre-looked-up author embeddings for history [B, S, num_author_hashes, D]
Pre-looked-up author embeddings for candidates [B, C, num_author_hashes, D]
RecsysModelOutput
Output of the recommendation model.Predicted logits for each candidate and action [B, num_candidates, num_actions]
Methods
__call__
Batch containing hashes, actions, and product surfaces
Pre-looked-up embeddings from embedding tables
Model output containing logits for each candidate. Shape: [B, num_candidates, num_actions]
build_inputs
Batch containing hashes, actions, and product surfaces
Pre-looked-up embeddings from embedding tables
Combined embeddings [B, 1 + history_len + num_candidates, D]
Padding mask [B, 1 + history_len + num_candidates]
Position where candidates start in the sequence
Utility Functions
block_user_reduce
Hash values [B, num_user_hashes], where 0 = invalid/padding
Looked-up embeddings [B, num_user_hashes, D]
Number of hash functions used
Embedding dimension D
Initialization scale for projection matrix
Combined user embedding [B, 1, D]
True where user is valid [B, 1]
block_history_reduce
Post hash values [B, S, num_item_hashes]
Post embeddings [B, S, num_item_hashes, D]
Author embeddings [B, S, num_author_hashes, D]
Product surface embeddings [B, S, D]
Action embeddings [B, S, D]
Number of hash functions for items
Number of hash functions for authors
Initialization scale for projection
Combined history embeddings [B, S, D]
Valid history positions [B, S]
block_candidate_reduce
Post hash values [B, C, num_item_hashes]
Post embeddings [B, C, num_item_hashes, D]
Author embeddings [B, C, num_author_hashes, D]
Product surface embeddings [B, C, D]
Number of hash functions for items
Number of hash functions for authors
Initialization scale for projection
Combined candidate embeddings [B, C, D]
Valid candidate positions [B, C]
Notes
- Hash value 0 is reserved for padding in all hash-based inputs
- The model uses multi-hash embeddings to reduce collisions in the embedding space
- Product surfaces represent different UI contexts (e.g., ForYou, Following, Search)
- Actions are represented as multi-hot vectors to capture multiple engagement signals