The recommendation engine behind this website is based on 113.6M Letterboxd film ratings, and uses a graph-based model to find films that you will probably like. But how does it work?
Step 1: the data
The original dataset contains 141,455,748 individual ratings from 263,100 users on 157,381 films, but training the model on the totality of that data would be suboptimal: the size of the recommendation engine files would be huge, and the majority of those films would never be recommended because they don't have enough ratings. To solve this problem, the choice has been made to only keep the top 20,000 films by number of ratings, excluding short films (under 30 min), TV movies, stand-up specials and concert films. With those changes applied we get 123.1M ratings. 20,000 users are then set aside to test the model, which leaves 113.6M ratings to train it.
Step 2: the training
The graph
Everything starts with a graph that links every user to every film they rated. The more people loved both films, the closer they are. To explain this we are going to work on a fictional subset of users; here are their ratings:
| User | Heat | The Departed | The Godfather | Interstellar | Barbie | Shrek |
|---|---|---|---|---|---|---|
| Titouan | 5★ | 4.5★ | 4★ | 3★ | — | — |
| Eliot | 4.5★ | — | 5★ | 3.5★ | 2★ | — |
| Bertrand | — | — | — | 4★ | 4★ | 5★ |
| Noah | — | 2★ | — | 3★ | 4.5★ | 4★ |
| Sylvie | 3★ | 3.5★ | 3★ | 4★ | 3.5★ | 3★ |
We now have our graph , with the nodes that represent either the users or the films , and the edges that represent a rating. An edge exists when has rated ; we write for that rating.
The Ratings
Four stars does not mean the same thing for all the users: for some it's a really good film, and for others it is just a decent movie. To fix that we are going to replace the rating by its rank within the user's ratings. If is the number of ratings of the user :
( is the number of ratings of less than or equal to divided by the total number of ratings of .)
With that the best rating of a user is now worth 1 (ties are counted together), and the weight of the edge between and is computed the following way:
is worth 4: this way the weight of a rating clearly reflects whether it's one of the user's favorites, or just above average.
Example
A user rated five films 5★, 4.5★, 4★, 4★ and 3★ ():
| Rating | Ratings ≤ it | ||
|---|---|---|---|
| 5★ | 5 of 5 | 1.0 | 1 |
| 4.5★ | 4 of 5 | 0.8 | 0.41 |
| 4★ | 3 of 5 | 0.6 | 0.13 |
| 3★ | 1 of 5 | 0.2 | 0.0016 |
The Heart of the model
Before going further, here are two sums that are going to be very helpful:
is the "mass" of a user: a lot of favorite films give a high value to this sum; is the popularity of a film: a lot of high ratings give a high value to this sum.
To calculate the similarity between films we need to go back to our graph: on it, two films are never linked to each other, the connections always go through the users. We can picture the following steps as a random walk: we start from a film, go through a user node, and come back to a film. The higher the probability of landing on a film , the closer it is to the starting film.
Step 1, from the film to a user. We start from film and pick a user in proportion to their weight on that film.
Step 2, from the user to a film. We pick one of that user's films in proportion to its weight:
Probability of arriving at . We add up every possible path, that is, every user in between (law of total probability):
With that we have the first functional version of our movie graph:
The corrective parameters
As you may have seen on the interactive graph, there are two new parameters: and . They both help to adjust and improve the accuracy of the results.
Alpha
is useful to smooth the probabilities: each transition probability is raised to the power
The intuition is that with a small probability is boosted more than a bigger one:
This parameter helps prevent a few users from dominating the computation.
Beta
A classic issue when building a recommendation engine is that the films everyone has seen (Parasite, Interstellar) are often the ones you end up with, even if they don't specifically match your profile. To fix that, the parameter divides by the popularity of the film in the following way:
The Inference
When you write your username in the search bar, the site collects your favorite films (the top 20 % of your ratings), and with them computes a score. Given the vector with for the films in your top 20 % and for all the others:
If we go back to our previous analogy, this is a 3-step walk: your favorite films → the users who loved them → their favorite films. Once we have our vector , we remove the films you have already logged, sort the rest, and get your film recommendations.