MLCrack

    RECOMMENDATION SYSTEMS · INTERVIEW QUESTION

    Explain two-tower models for recommendation. How are they used in production?

    🔴 advanced · Hybrid Systems

    Hint: Think about separate user and item encoders with dot-product similarity.

    Answer

    Two-tower architecture: separate neural networks encode users and items into dense embeddings. User tower: processes user features (demographics, history, context). Item tower: processes item features (metadata, content). Relevance score: dot product or cosine similarity of the two embeddings.

    Interview reasoning

    Training: contrastive learning on positive (clicked/purchased) and negative (random/hard negatives) pairs.

    Production use:

    1. Item embeddings pre-computed and indexed in ANN (FAISS, ScaNN)
    2. User embedding computed at request time
    3. ANN retrieves top-k candidates in ~ms.

    Benefits: O(1)O(1) serving per candidate, scales to billions of items.

    Limitations: limited interaction modeling (no cross-features). Solution: use two-tower for retrieval, then a cross-network ranker (e.g., DCN, DeepFM) for final ranking.

    A two-tower model encodes user/context and item information separately and trains their similarity to retrieve useful items. Item vectors can be precomputed into an ANN index; user vectors reflect recent context. A richer cross-feature ranker can then evaluate the bounded retrieved pool.

    Worked example. For ten million items, precompute their vectors; compute one query vector and retrieve hundreds before expensive ranking.

    Validation

    Measure exact and ANN recall, new-item quality, index freshness and retrieval latency; verify both towers' feature versions.

    Common pitfalls

    Separately encoded towers cannot represent every pairwise interaction. Mixed encoder/index versions can fail even when each component works independently.