Dataset Splitters
Relevant source files
The following files were used as context for generating this wiki page:
Dataset Splitters in DGL-LifeSci provide standardized methods for dividing chemical datasets into training, validation, and test subsets. These utilities are critical for evaluating the generalization performance of Graph Neural Networks (GNNs) on molecular tasks such as property prediction and generative modeling. The project implements various splitting strategies, ranging from simple random assignments to complex, chemistry-aware structural splits.
The primary goal of these splitters is to ensure that models are tested on data distributions that represent real-world scenarios, such as predicting properties for novel molecular scaffolds or maintaining class balances in multi-label classification tasks.
Sources: python/dgllife/utils/splitters.py:1-25, examples/property_prediction/csv_data_configuration/README.md
Core Splitter Architecture
The library utilizes a functional and object-oriented approach to splitting. Most splitters provide static methods for standard train_val_test_split and k_fold_split operations. They interact with DGL Subset objects to manage data indices without duplicating underlying dataset memory.
General Workflow for Molecular Splitting
The following diagram illustrates the high-level logic used when a splitter processes a dataset, particularly those requiring RDKit molecule objects.
Citations: python/dgllife/utils/splitters.py:112-149, python/dgllife/utils/splitters.py:252-290
Splitter Types and Strategies
DGL-LifeSci implements several specialized splitters categorized by their underlying logic:
1. Simple Splitters
These splitters do not account for molecular structure but focus on index-based or random distribution.
- ConsecutiveSplitter: Splits the dataset into consecutive chunks based on the original input order. This is deterministic and useful when the input data already has a meaningful sequence.
- RandomSplitter: Randomly permutes the dataset indices before splitting. This is the most common baseline for data division.
Sources: python/dgllife/utils/splitters.py:155-219
2. Physics and Chemistry Aware Splitters
These splitters use molecular descriptors to ensure structural diversity or specific distributions across splits.
- MolecularWeightSplitter: Sorts molecules by their exact molecular weight. Splitting on sorted weights ensures that the model is tested on a different mass range than it was trained on, or that mass is distributed evenly.
- ScaffoldSplitter: Groups molecules based on their Bemis-Murcko scaffolds. It ensures that all molecules with the same structural framework stay together in a single split (e.g., all in training or all in test). This is a rigorous test of a model's ability to generalize to novel chemical structures.
Sources: python/dgllife/utils/splitters.py:222-269, python/dgllife/utils/splitters.py:328-360
3. Task-Specific Splitters
- SingleTaskStratifiedSplitter: Designed for imbalanced datasets, it ensures that each split maintains a similar distribution of label values for a specific target task.
Sources: python/dgllife/utils/splitters.py:465-490
Comparison of Splitting Methods
| Splitter Class | Basis for Splitting | Use Case |
|---|---|---|
ConsecutiveSplitter | Original Index Order | Deterministic testing on ordered data |
RandomSplitter | Random Permutation | General baseline evaluation |
MolecularWeightSplitter | Exact Molecular Weight | Testing generalization across sizes |
ScaffoldSplitter | Bemis-Murcko Scaffold | Evaluating generalization to new chemotypes |
SingleTaskStratifiedSplitter | Label Distribution | Handling imbalanced classification/regression |
Sources: python/dgllife/utils/splitters.py:25-33
Technical Implementation Details
Bemis-Murcko Scaffold Grouping
The ScaffoldSplitter identifies the molecular framework of each compound. The algorithm proceeds as follows:
- Compute the scaffold for every molecule using RDKit's
MurckoDecompose. - Group indices of molecules sharing the same scaffold.
- Sort scaffold groups by size (largest groups first).
- Distribute groups into subsets until the desired ratios (e.g., 0.8, 0.1, 0.1) are met.
K-Fold Cross Validation
The library provides a base utility base_k_fold_split that allows any splitting method to be converted into a cross-validation generator. For ScaffoldSplitter, k-fold is implemented to ensure that even during cross-validation, scaffold groups are never split between training and validation in any fold.
Sources: python/dgllife/utils/splitters.py:35-61, python/dgllife/utils/splitters.py:431-463
Usage in Training Pipelines
In the property prediction examples (e.g., classification_train.py), the split type is specified via command-line arguments. The default is often set to scaffold to provide a more realistic assessment of model performance.
# Example of scaffold split usage in a configuration context
# Default split ratio is 0.8, 0.1, 0.1
splitter = ScaffoldSplitter()
train_set, val_set, test_set = splitter.train_val_test_split(
dataset, frac_train=0.8, frac_val=0.1, frac_test=0.1
)
Sources: examples/property_prediction/csv_data_configuration/README.md, python/dgllife/utils/splitters.py:382-415
Dataset Integration
Many built-in datasets like ESOL, MUV, and Tox21 are designed to work seamlessly with these splitters by providing a smiles attribute, which the splitters use to generate the required RDKit molecule instances for structural analysis.
Sources: python/dgllife/data/esol.py:110-120, python/dgllife/data/muv.py:100-110
Dataset Splitters are a fundamental component of the DGL-LifeSci ecosystem, providing the necessary tools for rigorous model validation. By offering both standard and chemically-aware splitting strategies, the project enables developers to assess model robustness against both random variance and significant structural shifts in chemical space.