How satvik8954/generics works
Purpose and Entry Points
ExciPick is a PyTorch pipeline for multilabel prediction of inactive pharmaceutical ingredients from an API’s molecular properties, dose/per-unit context, administration route, and dosage form. Operational entry points are compute_features.py, preprocess.py, training.py, test.py, and likely inference via predict.py.
Source Data and Molecular Feature Stage
FDA SPL/NDC formulation records enter from Data/f3.csv. compute_features.py uses RDKit to transform API SMILES into 20 fixed molecular descriptors and persists them in Data/api_features.csv. This isolates chemistry-specific dependency and feature extraction from model training.
Preprocessing and Dataset Contract
preprocess.py parses formulation excipient labels, joins descriptor rows, normalizes dose (including log-normalized mg), and creates categorical vocabularies for excipients, route, dosage form, and per-unit information. Its processed artifact is consumed by splitting/training rather than raw CSVs. dataset.py defines the PyTorch dataset/batch-facing representation, establishing the boundary between tabular preprocessing and tensor training.
Leakage-Resistant Split Stage
split.py partitions formulations by API chemical-similarity clusters (Morgan fingerprint/Tanimoto-based per README), rather than random records. This keeps chemically related APIs from spanning train, validation, and test partitions. Training produces test_data.pkl, preserving the held-out evaluation input.
Neural Model Assembly
model/FULL_MODEL.py composes four learned stages:
• model/api_encoder.py: 20-descriptor API vector through a 20→256→128 MLP.
• model/strength_encoder.py: dose and per-unit encoding into a 64-dimensional representation.
• model/context_fusion.py: combines API and strength encodings with learned route and dosage-form embeddings into a 192-dimensional context.
• model/excipient_scorer.py: scores the context against the complete excipient vocabulary, producing one score per excipient.
This is a shared-context, multi-label ranking/classification design: a single formulation context is evaluated across all candidate excipients.
Training, Checkpointing, and Evaluation
training.py orchestrates cluster-aware splits, PyTorch optimization (Adam per README), validation, and best-checkpoint selection, saving best_model.pt by validation loss. test.py reloads the trained system and evaluates held-out data; it also has a smoke-test path. metrics.py evaluates ranked multilabel outputs using Precision, Recall, F1, and Jaccard at K.
Runtime and External Dependencies
The runtime is Python 3.10+ with PyTorch, optionally CUDA with CPU fallback. RDKit is required for descriptor generation and similarity-aware splitting; pandas/numpy support tabular transformations, and scikit-learn supports ML preprocessing/splitting-related work. Central model dimensions, optimization settings, device choice, and top-K defaults reside in config.py. Primary persisted boundaries are CSV source/features, preprocessing artifacts, test_data.pkl, and best_model.pt.
Main entry points: training.py Training orchestration · config.py Central configuration · dataset.py Tensor dataset contract · split.py Chemical-cluster split
Components 18
Data pipeline
- FDA SPL/NDC records · Formulation records with API, excipient, dose, route, and dosage-form data.
Data/f3.csv - Molecular descriptors · Computes 20 fixed descriptors from API SMILES.
compute_features.py - API feature table
Data/api_features.csv - Formulation preprocessing · Parses labels, joins descriptors, normalizes dose, and builds vocabularies.
preprocess.py - Tensor dataset contract · Converts processed formulation data into batch-facing tensors.
dataset.py - Chemical-cluster split · Partitions API formulations by Morgan fingerprint and Tanimoto similarity clusters.
split.py - Held-out test data · Persisted test partition produced during training.
Neural model
- API encoder
model/api_encoder.py - Strength encoder · Produces a 64-dimensional strength representation.
model/strength_encoder.py - Context fusion · Combines API and strength features with route and dosage-form embeddings.
model/context_fusion.py - Excipient scorer · Scores the fused context against the complete excipient vocabulary.
model/excipient_scorer.py - Full model assembly · Assembles the shared-context multilabel predictor.
model/FULL_MODEL.py
Training and evaluation
- Training orchestration · Optimizes, validates, and selects the best checkpoint.
training.py - Best model checkpoint · Selected by validation loss.
- Held-out evaluation · Reloads the model and evaluates held-out data; includes a smoke-test path.
test.py - Top-K metrics · Computes Precision, Recall, F1, and Jaccard at K.
metrics.py - Prediction runtime
predict.py - Central configuration · Defines dimensions, optimization, device, and top-K defaults.
config.py
Connections 22
- FDA SPL/NDC records → Molecular descriptors: API SMILES
- Molecular descriptors → API feature table: writes descriptors
- FDA SPL/NDC records → Formulation preprocessing: formulation fields
- API feature table → Formulation preprocessing: descriptor join
- Formulation preprocessing → Tensor dataset contract: processed records and vocabularies
- Tensor dataset contract → Chemical-cluster split: formulations
- Chemical-cluster split → Training orchestration: train/validation partitions
- Chemical-cluster split → Held-out test data: persists test partition
- API encoder → Context fusion: 128-d API representation
- Strength encoder → Context fusion: 64-d strength representation
- Context fusion → Excipient scorer: 192-d context
- Excipient scorer → Full model assembly: candidate excipient scores
- Tensor dataset contract → Training orchestration: tensor batches
- Full model assembly → Training orchestration: model architecture
- Training orchestration → Best model checkpoint: best validation loss
- Held-out test data → Held-out evaluation: held-out inputs
- Best model checkpoint → Held-out evaluation: reloads model
- Held-out evaluation → Top-K metrics: ranked multilabel outputs
- Best model checkpoint → Prediction runtime: loads trained model
- Central configuration → Training orchestration: optimization and device settings
- Central configuration → Full model assembly: model dimensions
- Central configuration → Top-K metrics: top-K defaults