This repository implements a Message Passing Neural Network (MPNN) using PyTorch Geometric to predict the toxicity of chemical compounds across the Tox21 dataset's 12 biological assays. The model handles missing labels (NaN masking), severe class imbalance, and multi-label binary classification.
┌─────────────────────────────────────────────────────┐
│ GNN Toxicity Predictor │
│ │
│ Input: Molecular Graph (atoms + bonds) │
│ │ │
│ ▼ │
│ ┌──────────────────────────────────┐ │
│ │ 3x GCNConv Layers │ │
│ │ (Message Passing + Aggregation) │ │
│ └──────────────┬───────────────────┘ │
│ │ │
│ ▼ │
│ Global Mean Pooling │
│ │ │
│ ▼ │
│ ┌──────────────────────────────────┐ │
│ │ 2-Layer MLP Classifier │ │
│ │ Hidden: 64 → 12 (tasks) │ │
│ │ Activation: ReLU → Sigmoid │ │
│ └──────────────────────────────────┘ │
│ │ │
│ ▼ │
│ 12 Binary Toxicity Predictions │
│ (one per biological assay) │
└─────────────────────────────────────────────────────┘
- Node Features: Atom-level features (atomic number, degree, etc.)
- Edge Features: Bond connectivity
- Convolution: 3 layers of
GCNConvwith ReLU activation - Pooling: Global Mean Pooling over the entire molecular graph
- Classifier: 2-layer MLP with Sigmoid output for multi-label prediction
| Metric | Value |
|---|---|
| Test ROC-AUC | 0.7142 (average across 12 assays) |
| Training Epochs | 20 |
| Optimizer | Adam (lr=0.001, weight_decay=1e-5) |
| Loss Function | BCE with NaN masking |
Training loss across epochs showing stable convergence of the GNN on the Tox21 multi-label classification task.
- NaN Masking: Tox21 has missing labels across its 12 assays. The training loop masks out NaN targets before computing BCE loss (
is_valid = data.y == data.y). - Class Imbalance: Most assays have highly skewed positive/negative ratios. ROC-AUC is used instead of accuracy for robust evaluation.
- Multi-Label Classification: Each molecule is evaluated independently against 12 different biological assays, requiring per-task AUC calculation with validity checks.
pip install -r requirements.txt
python train.py # Train the GNN
python eval.py # Evaluate on test settorch>=2.0.0torch-geometric>=2.3.0scikit-learn>=1.2.0numpy>=1.24.0
This project is licensed under the MIT License.
