Applied ML systems
Collaborative filtering and matrix factorization
Collaborative filtering recommends items from patterns of who interacted with what. Matrix factorization learns a short vector for each user and item, so a dot product predicts affinity.
Collaborative filtering (CF) recommends items because of patterns in who interacted with what. If people with similar histories liked an item, you might like it too. CF needs no description of the items, only the interactions.
The data is a big user-item matrix R, where R[u, i] is a rating or a "watched" flag. Most cells are empty, since no user has touched most items.
The factorization
Matrix factorization approximates the matrix with two smaller ones:
R ≈ U × VᵀU has one row per user, and V has one row per item. Each has k columns, so every user and every item gets a short latent vector of k numbers. Training adjusts those numbers so that the dot product of a user's vector and an item's vector matches the observed interactions. Common solvers are alternating least squares and stochastic gradient descent.
Walking through a small example
Let k = 2. After training, the vectors are:
- Alice:
(0.9, 0.1), which means mostly "sci-fi." - Interstellar:
(0.8, 0.2) - A romantic comedy:
(0.1, 0.9)
The predicted affinity is the dot product:
Alice · Interstellar = 0.9 × 0.8 + 0.1 × 0.2 = 0.72 + 0.02 = 0.74
Alice · romcom = 0.9 × 0.1 + 0.1 × 0.9 = 0.09 + 0.09 = 0.18Interstellar scores higher, so it is the better recommendation. Nobody labeled the two dimensions "sci-fi" and "romance." Training found them because they explain the pattern of interactions.
With 100,000 movies, you would score each one for Alice and keep the top N she has not seen. That is where the cost starts to bite.
Content-based and hybrid
Content-based methods use item features, such as genre, text embeddings and tags. They recommend items similar to ones the user liked. Pure CF fails for brand-new items, and pure content misses taste that is social and hard to describe. Production systems usually mix the two.
Limits at scale
- Scoring every item for every request is
O(number of items), which is too slow for millions of items. - Cold-start users and items have weak or empty vectors.
- Popular items dominate the co-occurrence patterns, which drowns out the long tail.
These limits are why the industry moved to two-tower retrieval with approximate nearest neighbors, covered in two-tower retrieval.
Common mistakes
- Expecting CF to handle new items. An item with no interactions has no vector to learn.
- Treating all unobserved cells as zeros without thought. Missing means unseen, not disliked. See implicit feedback.
- Scoring the whole catalog per request. Precompute item vectors and use an approximate nearest-neighbor index.
Check yourself
- In the example, why is the dot product a good score? Answer: the vectors put Alice and Interstellar on the same "sci-fi" axis, so their product is large.
- Why does CF struggle with a brand-new movie? Answer: nobody has interacted with it, so its vector is never trained.
Key takeaways
- CF predicts from interaction patterns. It needs no item content.
- Matrix factorization gives each user and item a short vector, and a dot product predicts the interaction.
- Pure CF fails on cold start and on huge catalogs.
- Two-tower models and approximate nearest neighbors solve the scale problem.
Further learning
Next, see how the modern retrieval model replaces the full matrix with two towers in two-tower retrieval.
Related
Implicit feedback and objectives
Most recommender training data is implicit, such as clicks, watches and skips. Those signals are plentiful but noisy, and the objective you choose decides what the system learns.
Two-tower retrieval
A two-tower model embeds users and items separately, so item vectors can be indexed in advance and a nearest-neighbor search finds candidates fast.
Unsupervised learning
Clustering, dimensionality reduction and anomaly detection without labels.