Bird
Raised Fist0

Two-Tower Model for Retrieval - User and Item Towers

SYSTEM-DESIGNhardInterview freq: very_high
Choose your preparation mode6 modes available
▶
Execution Trace
Step 1/6
User Features

User features vector [0.5, 0.3, 0.2] is input to the User Tower.

🎯 Understanding feature vector representation is crucial for model input.
user_features = np.array([0.5, 0.3, 0.2])
user_embedding = user_tower(user_features)
Item Features

Item features vector [0.4, 0.6, 0.1] is input to the Item Tower.

🎯 Item features must be preprocessed similarly to user features.
item_features = np.array([0.4, 0.6, 0.1])
item_embedding = item_tower(item_features)
User Tower

User embedding generated: [0.7, 0.2, 0.1].

🎯 User tower transforms features into a latent space representation.
user_embedding = user_tower(user_features)
Item Tower

Item embedding generated: [0.6, 0.3, 0.2].

🎯 Item tower similarly transforms item features.
item_embedding = item_tower(item_features)
Dot Product

Similarity score calculated: 0.65.

🎯 Dot product measures similarity in the latent space.
similarity_score = np.dot(user_embedding, item_embedding)
Ranking and Recommendation

Items ranked based on similarity scores for recommendation.

🎯 Final ranking is crucial for effective recommendations.
ranked_items = rank_items(similarity_score)
📊
Diagram
Diagram
┌───────────────┐     ┌───────────────┐
│ User Features │     │ Item Features │
└──────┬────────┘     └──────┬────────┘
       │                     │
       ▼                     ▼
┌───────────────┐     ┌───────────────┐
│ User Tower    │     │ Item Tower    │
└──────┬────────┘     └──────┬────────┘
       │                     │
       ▼                     ▼
┌───────────────────────────────┐
│ Dot Product for Similarity    │
└──────────────┬────────────────┘
               │
               ▼
┌───────────────────────────────┐
│ Ranking and Recommendation    │
└───────────────────────────────┘
  • User Features: Input data for user tower
  • Item Features: Input data for item tower
  • User Tower: Processes user features
  • Item Tower: Processes item features
  • Dot Product: Computes similarity between user and item
🔑
Key Moments
▲
Q: Why are separate towers used for user and item features?
A: Separate towers allow for independent feature processing, capturing unique patterns in user and item data.
Q: How does the dot product contribute to the recommendation process?
A: The dot product computes similarity in the latent space, crucial for ranking items based on user preferences.
Q: What is the significance of the latent space representation?
A: Latent space representation captures complex feature interactions, enabling effective similarity computation.

The Two-Tower Model for retrieval in recommendation systems processes user and item features separately through dedicated towers. Each tower transforms its input features into a latent space representation. The outputs are then combined using a dot product to compute similarity scores, which are used to rank items for recommendation. This architecture allows for capturing complex interactions in the data, improving the relevance of recommendations.

Primary Focus

✓ ML pipeline from data ingestion to serving

Practice

(1/5)
1. In the context of a feed ranking system for social media platforms, which component is primarily responsible for determining the order of posts shown to a user?
easy
A. Ranking algorithm
B. Feature extraction module
C. Data ingestion pipeline
D. User interface

Solution

  1. Step 1: Identify the role of each component

    The ranking algorithm is responsible for determining the order of posts based on relevance and user preferences.
  2. Step 2: Eliminate wrong options

    Data ingestion pipeline collects data, feature extraction module processes features, and user interface displays the results but does not determine order.
  3. Final Answer:

    Option A -> Option A
  4. Quick Check:

    Ranking algorithm orders posts. [OK]
Hint: Ranking algorithm orders posts. [OK]
Common Mistakes:
2. In a spam detection system, which feature is most likely to be effective in identifying spam emails?
easy
A. Email length
B. Presence of certain keywords
C. Sender's email domain
D. Time of day email was sent

Solution

  1. Step 1: Identify effective features for spam detection

    Keywords like 'free', 'win', or 'prize' are often used in spam emails.
  2. Step 2: Eliminate less effective features

    Email length (A) and time of day (D) are not strong indicators of spam. Sender's domain (C) can be spoofed.
  3. Final Answer:

    Option B -> Option B
  4. Quick Check:

    Keywords often signal spam. [OK]
Hint: Keywords often signal spam. [OK]
Common Mistakes:
3. As a recommendation system scales to 10x the user base, which component is most likely to fail first in maintaining diversity and freshness?
hard
A. Diversity re-ranking layer
B. User profiling module
C. Content ingestion pipeline
D. Collaborative filtering engine

Solution

  1. Step 1: Analyze scalability challenges

    The diversity re-ranking layer may struggle to maintain performance under increased load.
  2. Step 2: Eliminate wrong options

    User profiling (A) and content ingestion (C) are less directly impacted by user scale. Collaborative filtering (D) may slow down but doesn't directly affect diversity.
  3. Final Answer:

    Option A -> Option A
  4. Quick Check:

    Diversity re-ranking struggles with scale [OK]
Hint: Diversity re-ranking struggles with scale [OK]
Common Mistakes:
4. At 10x data scale in a fine-tuning pipeline using SFT, RLHF, and DPO, which component is most likely to become a bottleneck first?
hard
A. Data Preprocessing Optimization (DPO)
B. Supervised Fine-Tuning (SFT)
C. Reinforcement Learning from Human Feedback (RLHF)
D. Model Deployment Infrastructure

Solution

  1. Step 1: Analyze the impact of scaling on each component

    DPO involves handling and optimizing large volumes of data, which can become a bottleneck as data scales.
  2. Step 2: Eliminate wrong options

    B: SFT scales with model size, not data volume. C: RLHF is more about feedback processing, not data volume. D: Deployment infrastructure is affected by model size, not data volume.
  3. Final Answer:

    Option A -> Option A
  4. Quick Check:

    DPO bottlenecks with data scale. [OK]
Hint: DPO bottlenecks with data scale. [OK]
Common Mistakes:
5. As the number of users and items increases in a session-based recommendation system, which component is likely to become a bottleneck first?
hard
A. Model training time
B. Data storage capacity
C. Real-time inference latency
D. Feature extraction pipeline

Solution

  1. Step 1: Consider scaling impacts

    Real-time inference latency often becomes a bottleneck as the system scales, due to increased computational demands.
  2. Step 2: Eliminate less likely bottlenecks

    Model training time and data storage can be managed with batch processing and scalable storage solutions; feature extraction is typically pre-computed.
  3. Final Answer:

    Option C -> Option C
  4. Quick Check:

    Inference latency scales poorly. [OK]
Hint: Inference latency scales poorly. [OK]
Common Mistakes:
Recommended

Ready to prove it?

Pass the test and this pattern moves unknown strong while earning +1 Grip toward your certificate.

10 questions~5 mineasy hard