liveBook · Manning

Data class

As explained in Graph Neural Networks in Action

The PyTorch Geometric Data class represents a graph and its associated attributes.

A PyTorch Geometric Data object packages one graph and its associated attributes, including node features, labels, connectivity, and train/test masks. Use it for graphs created from preprocessing pipelines or generated directly before batching. section 8.3.4

Build a graph object by assembling:

  • Optional custom attributes when the graph needs additional node-, edge-, subgraph-, or graph-level data. section 8.3.4

Creating a social-network graph

Convert a NetworkX graph or indexed edge list into tensors, then construct Data(x=x, y=y, edge_index=edge_index, train_mask=train_mask, test_mask=test_mask). Store multiple Data objects in a list and pass them to DataLoader for batching.

How Graph Neural Networks in Action covers it

How deep it goes
Defines core attributes and demonstrates construction with tensors and masks, but defers reusable preprocessing to dataset classes.
Examples
Uses a social graph with indexed edges, node features, labels, and train/test masks.
What you can do after
Build it from scratch, populate graph tensors and masks, and pass Data instances to DataLoader.
How it connects
Connects graph attributes with Dataset, InMemoryDataset, DataLoader, NetworkX, and PyTorch tensors.

This explainer was generated by Manning's knowledge graph from the text of Graph Neural Networks in Action. The section links point to the parts of the book it draws on.