← TikTok Interview Insights

TikTok·Machine Learning Engineer·Technical Phone Screen·Senior

Senior
May 2026

Summary

TikTok ML engineer interview that went deep on Transformer architecture applied to recommendation systems. The whole session was basically one long design question about cross-attention, which I was not fully expecting.

Questions Asked (3)

Q1

In a cross-attention block for a recommendation model, how would you define the Query, Key, and Value tensors using a user behavior sequence and a candidate item embedding? What does each tensor represent semantically?

System DesignTechnical Trade-offs
Author's notes

I fumbled the semantic explanation more than the mechanics.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Start by clarifying the cross-attention setup: the candidate item is the query, and the user behavior sequence provides keys and values. Then explain the semantic meaning of each tensor and how the attention mechanism computes relevance between the candidate and each behavior.

Pro tip: Emphasize that the query represents the target item's information needs, while keys and values represent the historical behaviors' content and context. Mention that this design allows the model to dynamically focus on relevant past behaviors for the candidate item.

1. Define the Query

The query is the candidate item embedding, representing the item we want to score. It asks: 'Which past behaviors are relevant to this item?'

2. Define the Keys

Keys are derived from the user behavior sequence (e.g., each behavior's embedding). They represent the 'addressable' aspects of past behaviors that can be matched against the query.

3. Define the Values

Values are also derived from the user behavior sequence, often the same as keys but possibly with different transformations. They represent the actual content or information of past behaviors that will be aggregated.

4. Explain the Attention Mechanism

Compute attention scores as dot product between query and keys, apply softmax to get weights, and use them to compute a weighted sum of values. This produces a context vector summarizing relevant behaviors.

5. Discuss Semantic Interpretation

The query represents the candidate's 'intent' or 'demand', keys represent the 'attributes' of past behaviors, and values represent the 'content' to be aggregated. The output is a user representation tailored to the candidate.

Key Points to Mention

  • Query = candidate item embedding; Keys and Values = user behavior sequence embeddings.
  • Semantically, query asks 'what is relevant?', keys provide 'matchable features', values provide 'information to aggregate'.
  • Attention weights indicate the importance of each past behavior for the candidate item.
  • The output context vector is a dynamic user representation conditioned on the candidate.
  • This is a form of target attention, common in models like DIN, DIEN, and transformers for recommendation.
  • Mention that keys and values can be the same or different depending on the architecture (e.g., self-attention vs cross-attention).

AI-generated suggestions, not part of the candidate's original notes. May be inaccurate — verify before relying on them.

Q2

Give at least two different design choices for setting up Q, K, and V in a cross-attention block for user-item recommendation. For each, explain what is attending to what, and the tradeoffs involved.

System DesignTechnical Trade-offsData Modeling
Author's notes

This is where it got interesting.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Start by clarifying the cross-attention setup: which modality (user or item) provides the query and which provides the keys/values. Then present two distinct designs: (1) user as query attending to item features, and (2) item as query attending to user features. For each, explain the attention flow and discuss tradeoffs in terms of computational cost, personalization, cold-start, and training dynamics.

Pro tip: Emphasize that the choice of Q, K, V depends on the prediction task and data availability; for example, if item features are rich but user history is sparse, using item as query can mitigate cold-start. Also mention that bidirectional cross-attention can be used but increases complexity.

1. Clarify the cross-attention setup

Define the two modalities: user and item. Explain that in cross-attention, one modality provides the query (Q) and the other provides keys (K) and values (V).

2. Design 1: User as query, item as key/value

Describe that the user representation attends to item features. Explain that this allows the model to weigh item features based on user preferences, enhancing personalization.

3. Design 2: Item as query, user as key/value

Describe that the item representation attends to user features. Explain that this captures how an item appeals to different users, useful for item-centric tasks like ranking.

4. Discuss tradeoffs

Compare the two designs: computational cost (sequence lengths), cold-start handling (which side has richer features), and training stability. Mention that Design 1 is common for user-centric recommendation, while Design 2 can help with item cold-start.

5. Conclude with practical considerations

Summarize that the choice depends on the task, data sparsity, and latency constraints. Suggest that in practice, one might use both directions or a hybrid approach.

Key Points to Mention

  • Cross-attention mechanism: Q from one modality, K and V from another.
  • Design 1: User as query, item as key/value – personalization, user-centric.
  • Design 2: Item as query, user as key/value – item-centric, helps cold-start items.
  • Tradeoffs: computational complexity (sequence length of K/V), cold-start, training data requirements.
  • Bidirectional cross-attention: combining both directions for richer interactions.
  • Practical considerations: latency, model size, and online serving constraints.

AI-generated suggestions, not part of the candidate's original notes. May be inaccurate — verify before relying on them.

Q3

How does cross-attention differ from self-attention over the user behavior sequence, and why would you use cross-attention specifically in a recommendation setting?

System DesignAlgorithms & Data Structures
Author's notes

Easier part of the question.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Start by clearly defining self-attention and cross-attention in the context of user behavior sequences, highlighting the difference in query, key, and value sources. Then explain why cross-attention is beneficial in recommendation systems, focusing on its ability to incorporate external context or target information. Use concrete examples from TikTok's domain to illustrate.

Pro tip: Emphasize that cross-attention allows the model to dynamically weigh the importance of different parts of the user's behavior sequence based on the target item or context, which is crucial for personalized recommendations. Mention that this is particularly effective for handling diverse and evolving user interests.

1. Define self-attention and cross-attention

Explain that self-attention computes attention within the same sequence (e.g., user behavior sequence), while cross-attention computes attention between two different sequences (e.g., user behavior and target item).

2. Contrast their mechanisms

Describe how in self-attention, queries, keys, and values come from the same input, whereas in cross-attention, queries come from one source (e.g., target item) and keys/values from another (e.g., user behavior).

3. Explain the role of cross-attention in recommendation

Discuss how cross-attention enables the model to focus on relevant parts of the user's history conditioned on the target item, improving relevance and personalization.

4. Provide use cases and benefits

Give examples such as incorporating context (time, location) or target item features, and highlight benefits like handling long sequences and capturing dynamic interests.

5. Connect to TikTok's setting

Relate to TikTok's recommendation challenges, such as short videos and diverse user interests, and how cross-attention helps in modeling user-item interactions effectively.

Key Points to Mention

  • Query, key, value sources: self-attention uses same sequence; cross-attention uses different sequences.
  • Cross-attention allows conditioning on target item or context, enabling personalized attention weights.
  • Benefits: handles long user sequences, captures dynamic interests, and improves relevance.
  • Use cases: incorporating item features, context (time, location), or multimodal data.
  • Computational considerations: cross-attention may be more efficient than self-attention over concatenated sequences.
  • TikTok relevance: short videos, diverse interests, and need for real-time recommendations.

AI-generated suggestions, not part of the candidate's original notes. May be inaccurate — verify before relying on them.