Skip to main content

Overview

Candidate isolation is a critical design pattern in the Phoenix ranking transformer that ensures candidates cannot attend to each other during inference. This architectural choice guarantees that the score for a candidate depends only on the user context, not on which other candidates happen to be in the batch.

The Problem

In a standard transformer, every position can attend to every other position (subject to causal masking). For recommendation systems, this creates a problem:
  • If candidate A can attend to candidate B, then A’s score depends on B being in the batch
  • Scores become inconsistent across different batches
  • Caching becomes impossible since scores change based on batch composition
  • The model learns spurious correlations between co-occurring items rather than true user preferences

The Solution: Custom Attention Masking

Phoenix solves this by implementing a specialized attention mask in the make_recsys_attn_mask function that enforces candidate isolation:
phoenix/grok.py

Attention Mask Structure

The mask creates three distinct regions:
Key Insight: The bottom-right block is diagonal-only, meaning each candidate can only attend to itself (self-attention) but not to other candidates.

Sequence Structure

The input sequence to the transformer is structured as:
The candidate_start_offset parameter marks the boundary between history and candidates:
phoenix/grok.py

Benefits

1. Consistent Scoring

Each candidate receives the same score regardless of which other candidates are in the batch:

2. Cacheability

Since scores are stable, you can:
  • Pre-compute scores for candidates offline
  • Cache scores for frequently shown candidates
  • Incrementally score new candidates without rescoring everything

3. Scalability

The model can score candidates in parallel without dependencies:

4. Interpretability

Scores reflect true user-candidate relevance, not spurious batch effects:
  • Easier to debug model behavior
  • A/B tests are more reliable
  • Score distributions are stable over time

Implementation in Phoenix

The Phoenix ranking model applies candidate isolation automatically when candidate_start_offset is provided:
phoenix/recsys_model.py

Testing

The implementation includes comprehensive tests to verify the attention mask structure:
phoenix/test_recsys_model.py
See the full test suite in /workspace/source/phoenix/test_recsys_model.py for all edge cases.

Hash-based Embeddings

Learn how Phoenix uses multiple hash functions for feature embeddings

Multi-action Prediction

Understand how the model predicts multiple engagement types simultaneously