Recommender Systems: From Collaborative Filtering to Two-Tower Models
Build, evaluate and improve recommenders in Python: neighbourhood methods, matrix factorisation, implicit ALS and two-tower retrieval in PyTorch, with honest offline evaluation and cold-start strategies.
Advanced · Machine Learning · about 15 hours · 5 modules · certificate on completion
Taught by Ngo Thi Huừngé, Jae-Wòn Parkk, AI Learning Companions.
About this course
Recommenders decide much of what people see online: which games, songs, products and posts appear first. This course teaches you to build them and, just as important, to evaluate them honestly. You'll work with six months of plays and ratings from Pixel Bazaar, a fictional store of indie games, generated on your own laptop, with a long tail of niche games and 40 new releases that no model has seen.
You'll start with popularity baselines and the ranking metrics that judge every model (precision, recall, MAP and NDCG), then build content-based, user-kNN and item-kNN recommenders, factorise ratings with SGD and implicit feedback with confidence-weighted ALS, and train a two-tower retrieval model in PyTorch on the CPU, with in-batch negatives, the logQ correction and a feature tower for new games. The last module covers cold start, the evaluation pitfalls that make offline results misleading (random splits, sampled metrics, popularity bias), and coverage, novelty and diversity. For serving at scale, Vector Databases and Semantic Search is a natural next step. Every lab prints real results that your instructor checks, and the capstone is a hybrid recommender for the store's home page.
What you'll learn
- Frame recommendation problems and split interaction data by time for honest offline evaluation
- Compute precision@k, recall@k, MAP@k and NDCG@k, with coverage, novelty and diversity
- Build content-based, user-kNN and item-kNN recommenders and compare them with popularity baselines
- Factorise ratings with SGD and implicit feedback with confidence-weighted ALS, tuned on a validation period
- Train a two-tower retrieval model in PyTorch with in-batch negatives and the logQ correction
- Avoid evaluation pitfalls such as random splits and sampled metrics, and design for cold start
Skills you'll gain
Recommender systems, Collaborative filtering, Content-based filtering, Matrix factorisation, Implicit feedback (ALS), Two-tower retrieval, Ranking metrics, Offline evaluation, Cold-start strategies, PyTorch
Tools
Python 3, NumPy, pandas, scikit-learn, PyTorch
Before you start
Machine Learning Foundations with Python, or the same skills: NumPy, pandas and scikit-learn, and training and evaluating models. Some PyTorch helps for module 4 (Deep Learning with PyTorch covers it), as does linear algebra at the level of dot products and matrix products. Install Python 3.10 or later, then pip install numpy pandas scikit-learn torch (the CPU build is enough).
Modules
Recommendation problems, data and evaluation
What recommenders do and the feedback they learn from, how to split interaction data so offline tests mean something, and the ranking metrics every later module uses.
- What recommenders do, and the data they learn from (12 min)
- Splitting interactions for evaluation (10 min)
- Ranking metrics: precision, recall, MAP and NDCG (12 min)
- Hands-on lab: Split the plays and score popularity baselines
Content-based and neighbourhood methods
Recommend from item attributes, and from the behaviour of similar users and similar items; compare them with popularity, and see which of them can recommend a game nobody has played yet.
- Content-based recommendation (12 min)
- User-based collaborative filtering (12 min)
- Item-based collaborative filtering (12 min)
- Hands-on lab: Compare content-based, item kNN and user kNN
Matrix factorisation
Compress the interaction matrix into user and item factors: fit ratings with biases and SGD, learn when factors help, and fit implicit feedback with confidence-weighted ALS tuned on a validation period.
- Latent factors and rating prediction (12 min)
- Training with SGD and ALS (12 min)
- Implicit feedback and confidence-weighted ALS (12 min)
- Hands-on lab: Factorise ratings with SGD and plays with implicit ALS
Two-tower retrieval with PyTorch
Build the retrieval model behind many large recommenders: user and item towers in one embedding space, trained with in-batch negatives and the logQ correction, with features that give new items a place.
- The two-tower architecture (12 min)
- Training with in-batch negatives, and serving (12 min)
- Hands-on lab: Train a two-tower retrieval model
Cold start, evaluation pitfalls and beyond accuracy
Serve new users and new items, avoid the evaluation mistakes that make offline results look better than they are, and measure coverage, novelty and diversity alongside accuracy.
- Cold start for new users and new items (12 min)
- Evaluation pitfalls (12 min)
- Beyond accuracy: coverage, novelty, diversity and feedback loops (10 min)
- Hands-on lab: Find the pitfalls in an offline evaluation
Project: A hybrid recommender for Pixel Bazaar's home page
Pixel Bazaar wants a 'Recommended for you' row of 10 games on its home page that works for loyal players, for players who have only tried a game or two, and for the games released this month. Using the course data, design an evaluation protocol, compare at least four models on it, and build a hybrid that combines collaborative scores with content features so new games and light players are served well. Tune it on a validation period, test it once on the test period, and report accuracy overall and by segment together with coverage, novelty and diversity. Finish with a proposal for the online A/B test that would decide whether to launch it, and a one-page summary for the product team.
Part of
The products this course names are trademarks of their owners, who haven't made or endorsed it.