liveBook · Manning

Batch.from_data_list

As explained in Build AI Drug Discovery Pipelines

Batch.from_data_list is a PyTorch Geometric function that combines a list of graph data objects into a batched disconnected graph.

Batch.from_data_list combines variable-sized graph Data objects into one disconnected graph for efficient neural-network processing. Instead of padding molecules or proteins to a common size, it concatenates their nodes and adjusts edge indices. section 11.5.5

The resulting batch preserves graph membership through:

  • Stacked node features: three graphs with 10, 15, and 12 atoms produce 37 nodes. section 11.5.5
  • Adjusted edge indices that reference nodes in the combined graph. section 11.5.5
  • A batch vector labeling every node with its original graph, enabling separate graph-level pooling. section 11.5.5
from torch_geometric.data import Batch
def collate(data_list):
    batchA = Batch.from_data_list([data[-1] for data in data_list])
    batchB = Batch.from_data_list([data[0] for data in data_list])
    return batchA, batchB

Use Batch.from_data_list in a collate function to batch molecular and protein graphs separately before affinity prediction. section 11.5.5

How Build AI Drug Discovery Pipelines covers it

How deep it goes
Explains disjoint-graph construction, feature stacking, edge reindexing, batch labels, and pooling implications.
Examples
Uses three graphs with 10, 15, and 12 atoms, producing 37 nodes and three pooled graph vectors.
What it assumes
Assumes graph Data objects and basic node, edge, and pooling terminology while motivating batching from variable graph sizes.
What you can do after
Apply it via PyTorch Geometric to collate separate lists of molecular or protein Data objects.
How it connects
Connects graph data objects, message passing, global pooling, molecular graphs, and protein graphs.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Build AI Drug Discovery Pipelines. The section links point to the parts of the book it draws on.