liveBook · Manning

PyTorch Geometric

As explained in Knowledge Graphs and LLMs in Action

PyTorch Geometric is an open-source library that provides data structures and neural-network layers for geometric and graph machine learning with PyTorch.

PyTorch Geometric (PyG) supplies graph data structures and neural-network components for building GNN systems in PyTorch. A typical workflow preprocesses graph data, packages node features, edges, and labels into a Data object, applies masks, and trains a task-specific model. section 12.1.3 section 12.0

A practical PyG pipeline includes:

  • Create a Data object with x for node features, edge_index for graph connectivity, and y for node labels. section 12.1.3
  • Expose only known labels through a mask, randomly partition eligible nodes, and attach train_mask, val_mask, and test_mask to the graph. section 12.1.3
  • Build node-classification or link-prediction models with GNN encoders, including GCN, GraphSAGE, and GAT variants. section 12.0 section 12.2.4
  • Handle heterogeneous graphs by converting a homogeneous base model with to_hetero() and supplying metadata describing node and edge types. section 12.2.4

Fraud detection and recommendations

For financial transactions, PyG supports node classification into licit and illicit classes. For movie recommendations, user and movie embeddings pass through a heterogeneous GNN, and a dot product scores likely user–movie links. section 12.1.3 section 12.2.4

Figure 12.3 Overview of data processing applied to the Elliptic dataset. Source data is preprocessed to create node features, edge indices, and encoded labels. These tensors are incorporated into a PyG Data object, where a node masking approach partitions the nodes into training (80%), validation (10%), and testing (10%) sets.
figure

Trace preprocessing into a PyG Data object and see how node masks create training, validation, and testing partitions. section 12.1.3

How Knowledge Graphs and LLMs in Action covers it

How deep it goes
Explains Data construction, masking, dataset partitioning, embeddings, heterogeneous conversion, and encoder–decoder implementation.
Examples
Uses an Elliptic financial transaction graph and a MovieLens user–movie rating graph as implementation examples.
What it assumes
Assumes PyTorch and GNN familiarity while demonstrating graph preparation and PyG model construction concretely.
What you can do after
Build it from scratch by preparing PyG graph objects, defining masks, and assembling homogeneous or heterogeneous GNN models.
How it connects
Connects graph data objects and masks with GNNs, embeddings, encoder–decoder architectures, node classification, and link prediction.

Also explained in

Compare how 2 books explain PyTorch Geometric →

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.