Model Architecture
Key Design: Candidate Isolation
Candidate isolation is achieved through custom attention masking that prevents candidates from attending to each other while still allowing them to attend to user and history context.Why Candidate Isolation Matters
Without isolation, the model could:- Score candidates differently based on which other items are in the batch
- Create inconsistent rankings across different batch compositions
- Make A/B testing and experimentation unreliable
- Cause unexpected behavior when batch sizes or sampling strategies change
Forward Pass Implementation
Here’s how the ranking model processes inputs:recsys_model.py:439-474
Input Embedding Construction
The model combines multiple feature types into input embeddings:1. User Embedding
recsys_model.py:79-119
2. History Embeddings
History embeddings combine:- Post hashes (multiple per position)
- Author hashes (multiple per position)
- Action embeddings (multi-hot vector of engagement types)
- Product surface (e.g., Home, Search, Profile)
recsys_model.py:122-182
3. Candidate Embeddings
Similar to history, but without action embeddings (since we’re predicting actions):recsys_model.py:185-242
Multi-Action Prediction
The model predicts multiple engagement types simultaneously:- Like probability
- Repost probability
- Reply probability
- Click probability
- Negative feedback probability
- etc.
Hash-Based Feature Encoding
Phoenix uses multiple hash functions for embedding lookup:Why Multiple Hash Functions?
Why Multiple Hash Functions?
Multiple hash functions reduce hash collisions and provide richer representations:
- Each feature (user, post, author) is hashed multiple times
- Each hash produces a separate embedding lookup
- Embeddings are concatenated and projected to the final dimension
Hash Configuration
Hash Configuration
recsys_model.py:32-38Handling Padding
Handling Padding
Hash value
0 is reserved for padding. The padding mask is computed by checking if the first hash is non-zero:Model Configuration
recsys_model.py:245-261
Key Differences from Retrieval
Retrieval
- Two separate towers
- User tower only
- Output: normalized embeddings
- Objective: similarity search
Ranking
- Single joint model
- User + history + candidates
- Output: action logits
- Objective: engagement prediction
Next Steps
Architecture Details
Deep dive into attention masking implementation
Retrieval Model
Learn about the two-tower retrieval stage