Graph-Based Recommenders
Every recommender so far worked on matrices. A graph-based recommender redraws the problem: users and items become nodes, ratings become edges, and a recommendation is a random walk — start at a user, follow edges to items, to users, back to items, and rank where you land. The famous P³ method does this in three hops and reveals that item-based CF is a degree-normalised walk.
The big idea
Represent the collaborative data as a bipartite graph — users on one side, items on the other, an edge wherever a rating exists. A recommendation is the probability of landing on each item after a random walk that starts at the target user. Walk three hops (P³) and the item scores become , which simplifies to with — the familiar item-based CF form.
01 · Users + items = nodes
Graph representation of the URM
The rating matrix isn’t a table — it’s a bipartite graph. Drawing it that way unlocks random walks.
A graph is a set of nodes and edges . For collaborative filtering, nodes are users and items ; an edge exists wherever the URM has a non-zero rating. This is a bipartite graph — two disjoint sets, edges only across — with nodes and as many edges as observed ratings.
Add item attributes (the ICM, Ch. 4) and you get a tripartite graph: , with edges from ratings and from content. This fuses collaborative and content signals into one graph — hybridisation by design (Ch. 9). The graph is written as an adjacency matrix with if edge exists. Ordering the nodes as [Users, Items] gives a clean block structure:
The graph is undirected — an edge means a rating, not a direction — but the transition matrix we build next is directional, because we normalise each row independently.
Same data, new lens
is just the URM stacked into a bigger matrix. The off-diagonal block structure forces every two-hop walk to land on a user, and every three-hop walk to land on an item — which is exactly why P³ works: the meta-path connects a user to items they haven’t rated, through users who share their taste.
02 · Walk the graph
Random walks and state probability
Start at a user, follow edges at random, and count how often you land on each item.
The core mechanism is a transition probability — the chance of stepping from node to node in one hop. For an unweighted graph it is simply , where is the degree of node : every neighbour is equally likely. Collecting these into the block transition matrix:
A state probability vector tracks where the walker is. Start at user with one-hot at ; each hop updates , a distribution that always sums to 1. After hops, is the probability of being at node . To recommend, read off the item nodes and rank them highest-first.
Random walk on the bipartite URM graph
Start at a user and take h degree-normalised hops. Hop 0 sits on the start user; hop 1 spreads evenly over their rated items; hop 2 re-focuses on users who share those items; hop 3 lands on candidate items. The ranking is the P³ recommendation — odd hops reach items, even hops do not.
Formal Definition 10.1 — transition & state
For an undirected, unweighted graph the transition probability is with degree . The state after hops is . For recommendation, the predicted score of item for user is the item-node probability , ranked descending.
03 · Three hops: U→I→U→I
P³ and the hidden CF connection
The magic of exactly three hops: it decomposes into an item–item similarity that looks strikingly familiar.
Why three? One hop () just lists the user’s own rated items — no discovery. Two hops () lands on users, not items. Three hops () reaches items the user hasn’t seen, through a user who shares their taste. The slides put the optimal hop count at 3 (sometimes 5, rarely 7); beyond that, oversmoothing washes out personalisation and the walk drifts to popularity. Because is block-structured, its powers alternate between blocks:
Starting from a user, we only need the upper-right block, . The inner product is an item–item similarity:
This is cosine similarity with degree normalisation instead of the L2 norm. For implicit interactions (binary ), is the item’s popularity, and equals cosine similarity on the binary URM — without shrinkage. The full chain gives , i.e. — the same form as item-CF (Ch. 5) and SLIM (Ch. 6).
All roads still lead to R·S
Item-CF (Ch. 5), SLIM (Ch. 6), PureSVD (Ch. 8), and now P³ (Ch. 10) all compute . The difference is only in how is obtained: a cosine over columns, a learned regression, a low-rank projection, or three hops of degree-normalised propagation.
04 · Two knobs on P³
P³α and RP³β
Two refinements that alter the transition probabilities to control popularity bias.
P³α raises the transition probabilities to a power before normalising: , and likewise from . When , small probabilities are attenuated — weak connections are damped more than strong ones. This sharpens the walk toward high-weight paths, but also amplifies popularity bias: popular items have larger rating columns, and the power exaggerates the gap.
RP³β attacks popularity directly, dividing the similarity by the destination item’s degree raised to :
The extra penalises recommending a hugely popular item. With the walker is pushed away from over-popular destinations, increasing diversity. Together, (edge-strength attenuation) and (popularity penalty) are two independent knobs on the precision–diversity trade-off.
P³ (baseline)
P³α + RP³β
Formal Definition 10.2 — P³α & RP³β
P³α. Power the rating matrix, , before degree-normalising the transition matrix.
RP³β. The item similarity is .
Both are tuned on validation (Ch. 3). Typical ranges: , .
05 · Attributes & infinite walks
Side information and the steady state
Adding attributes opens new meta-paths — and infinite walks converge to a page-rank-like steady state.
Adding attribute nodes (the tripartite graph ) lets the walker follow a new 3-hop meta-path, : from a user to an item they rated, to that item’s attributes, and finally to other items sharing those attributes. That is a pure content-based recommendation, discovered through the same machinery. The catch: not every meta-path ends on an item. Paths that end on attribute or user nodes are dead ends for recommendation, so we modify at the relevant hop to drop edges that lead off-target — a form of meta-path control.
The slides also discuss the steady state (stationary distribution): the vector satisfying . For a bipartite graph the walk does not converge to a single point — it cycles between the two sides (a periodic Markov chain, period 2). To force convergence, random walk with restart adds a teleport probability back to the start user:
At it is 100% restart (just the user’s own profile); as it is a pure unrestricted walk. The restart parameter is a personalisation knob: lower anchors the walker near the user. Solving for exactly needs a linear system, which is expensive — so in practice truncated walks (P³, P⁵) are used instead.
Too many hops = oversmoothing
As grows, the walker diffuses across the whole graph and the state probability approaches the node-degree distribution — the recommendation becomes Top-Popular in graph clothing. For a bipartite graph the walk never settles on its own: it alternates between the user and item sides forever, so a recommendation needs either a fixed odd hop count or the restart trick.
06 · Exam intel
What the exam tests
Draw the bipartite graph from a URM; write the adjacency matrix ; define the transition matrix ; propagate the state one hop; explain P³ and why it equals item-CF; and distinguish P³α (amplifies popularity) from RP³β (reduces it). Graders look for , the alternating blocks of , and the identity as cosine on a degree-normalised URM.
Worked question — walk two hops by hand
Bipartite graph: connects to ; connects to . Node order . (a) Write and . (b) From compute and . (c) At which hop do items reappear?
- (a) Degrees . row-normalises the adjacency, so from you reach each with probability .
- (b) (on items). Hop again: returns to (degree 1); splits to (degree 2). So — entirely on users, with the item slots zero.
- (c) Items reappear at every odd hop ; even hops land on users. P³ uses , the first hop that discovers new items rather than the user’s own.
Trap: an even-hop state has zero mass on every item — if your has a non-zero item entry, you double-counted a degree.
07 · Exam · past papers
Past-paper questions
Past paper Exam 2020 · Graph-based recommender for implicit data (6 pts)
Q. Implement a collaborative recommender for an implicit dataset with a graph-based approach: the bipartite graph structure (1); the incidence/adjacency matrix (1); the jump probability between nodes (1); the steady-state probability with and without restart (2); and how to extend the graph for side information (1).
Model answer. Bipartite graph. Two disjoint node sets, users and items; an undirected edge exists iff interacted with — no user–user or item–item edges. Adjacency. The URM is the incidence structure; the full adjacency is . Jump probability. Row-normalise by degree, , so you move to each neighbour with probability . Steady state. Without restart, converges to a degree/popularity distribution that has forgotten the seed; with restart (personalised PageRank), teleports back to the seed with probability , keeping the visit probabilities personalised. Side information. Add item- and/or user-attribute nodes and edges, turning the bipartite graph into a tri-/multipartite graph so walks pass through shared attributes — helping cold items.
Past paper FT-Sample · Hops and personalization (6 pts)
Q. Implicit ratings: the graph structure (1); the adjacency matrix (1); the transition matrix (1); how the number of hops relates to personalization (2); extending the graph to item and user attributes (1).
Model answer. Graph & adjacency. Bipartite user–item graph; symmetric adjacency . Transition. , each row a distribution over neighbours. Hops & personalization. A short walk stays in the seed user’s neighbourhood — highly personalised but narrow coverage; as hops grow the walk mixes toward the graph’s degree-based stationary distribution, becoming more popular/diverse but less personalised. The 3-hop walk is the sweet spot used by P³. Side information. Add user- and item-attribute nodes/edges (multipartite graph) so walks traverse shared attributes as well as co-interactions.
Past paper FT-Jan26 · Relation to item-CF; P³ vs P³α vs RP³β (7 pts)
Q. Implicit ratings: the graph structure (1); the transition matrix (1); how the model relates to item-based CF (2); the differences between P³, P³α and RP³β (3).
Model answer. Graph & transitions. Bipartite user–item graph; . Relation to item-CF. The 3-hop walk produces a matrix of landing probabilities between items — this is an item–item similarity, so scoring with it () makes P³ a random-walk-derived item-based CF. P³ / P³α / RP³β. P³ is the plain 3-step walk, items scored by landing probability. P³α raises each transition probability to a power before walking, sharpening (or damping) the influence of strong paths — a tunable hyper-parameter. RP³β takes P³α and re-ranks by dividing each item’s score by its popularity raised to , explicitly penalising popular items to counter popularity bias and improve the long tail.
Past paper Practice Exam 1 · Graph construction, state probability, PageRank (5 pts)
Q. How a user–item interaction graph is constructed (2); the concept of a state probability in a random walk (1); the PageRank algorithm and how it is used for recommendations (2).
Model answer. Graph construction. Nodes are users + items; add an edge for every observed interaction (the URM). The result is a bipartite graph with adjacency . State probability. The probability of being at a node after a number of random-walk steps; the vector evolves as . PageRank. The stationary distribution of a random walk with teleport, . For recommendation, use personalised PageRank — set the teleport vector to the target user’s items — then rank items by their stationary visit probability.
Past paper Practice Exam 4 · Random walks and side-information pitfalls (5 pts)
Q. How random walks find recommendations in a user–item graph (2); how to compute the state probability (1); how to incorporate side information, including potential problems (2).
Model answer. Random walks. Start at the target user and follow degree-normalised transitions ; the items reached most often (highest landing probability, typically via a 3-hop walk or RWR) are recommended. State probability. Iterate from the seed; is the probability of being at node after steps. Side information & problems. Add attribute nodes and edges so walks traverse shared content. Problem: a popular attribute node has very high degree, so the walk funnels through it — diluting personalisation (over-smoothing) and amplifying popular items. The attribute edges must be weighted or normalised carefully.
08 · Self-check
Three questions before you move on
In a bipartite user–item graph, why does a 2-hop random walk not produce recommendations?
The P³ item–item similarity S_ij = Σ_u r_ui r_uj / (d_i d_j) is:
How does RP³β differ from P³α?
09 · Recap
One-screen summary
Chapter 10 — load-bearing ideas
- Graph = URM: the bipartite graph ; recommendation is a random walk from a user, with .
- P³ = item-CF: the 3-hop walk gives with — the same as Ch. 5/6/8.
- Two knobs: P³α ( attenuates small similarities, amplifies popularity); RP³β ( penalises high-degree items, improves diversity). Side information adds the meta-path.
- Even hops land on users; too many hops over-smooth to popularity; the bipartite walk is periodic, so it needs an odd hop count or restart .