liveBook · Manning

Heterogeneous graph

As explained in Knowledge Graphs and LLMs in Action

A heterogeneous graph is a graph containing multiple types of nodes, relationships, or both.

A heterogeneous graph contains multiple node or relationship types. In recommendation, users and movies form distinct node types connected by user–movie rating edges. section 12.2.3 section 12.2.4

A practical PyG pipeline handles the graph in explicit stages:

  • Create a HeteroData object with user and movie nodes, movie features, rating edges, and reverse edges for bidirectional message passing. section 12.2.3 section 12.2.4
  • Split rating edges into disjoint message-passing and supervision sets, reserving validation and testing edges and generating negative examples. section 12.2.3
  • Sample neighborhood subgraphs with LinkNeighborLoader when the full graph exceeds CPU or GPU memory. section 12.2.3
  • Generate user and movie embeddings, update them with a heterogeneous GNN, and use a dot product to score candidate links. section 12.2.4

Movie recommendation

User embeddings are learned from node identities, while movie representations combine genre features with learned embeddings. Heterogeneous message passing exchanges information across user–movie ratings before dot-product decoding estimates interaction likelihood. section 12.2.4

Figure 12.8 The data processing pipeline for the MovieLens dataset, including incremental ID mapping, genre encoding, and edge creation. The heterogeneous graph data comprises two node types (users and movies) and one edge type (user-rates-movie). Edges are split into training (80%), validation (10%), and testing (10%) sets, with negative examples generated for validation and testing. A mini-batch loader then prepares subgraphs for GNN input, ensuring scalability for large graphs that exceed memory capacity.
figure

Trace the MovieLens preparation pipeline from identifier mapping and genre encoding through edge splitting and mini-batch subgraph construction. section 12.2.3

How Knowledge Graphs and LLMs in Action covers it

How deep it goes
Implements construction, disjoint edge splitting, neighbor sampling, embeddings, heterogeneous message passing, and dot-product decoding.
Examples
Uses MovieLens users, movies, genres, ratings, reverse edges, sampled neighborhoods, and train–validation–test edge splits.
What you can do after
Builds a PyTorch Geometric link-prediction pipeline for heterogeneous recommendation graphs.
How it connects
Connects node features, embeddings, GNNs, link prediction, recommendation, message passing, and encoder–decoder architectures.

Also explained in

Compare how 3 books explain heterogeneous graph →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Knowledge Graphs and LLMs in Action. The section links point to the parts of the book it draws on.