How sreshwarprasad/hierarchical-gz2 works
Purpose and entry points
This is an offline ML research pipeline for probabilistic Galaxy Zoo 2 morphology prediction from galaxy images. It trains image models to emit per-question vote distributions rather than hard labels, then evaluates distribution validity, accuracy, calibration, uncertainty, and attention-based interpretability.
Primary execution surfaces are training in src/train.py and src/train_single.py, experiment orchestration in src/ablation.py, and shell launch integration in scripts/training/run_model.sh.
Data preparation and dataset boundary
Raw Galaxy Zoo/image assets are converted, labeled, and validated before model training. The data boundary is handled by scripts/data/convert_zenodo_images.py, scripts/data/prepare_labels.py, and src/dataset.py; dataset verification is available in scripts/data/verify_dataset.py.
The dataset loader supplies transformed image tensors and hierarchical vote-distribution targets to the training/evaluation stack. External dataset/model hosting is Hugging Face; source imagery is associated with Galaxy Zoo 2.
Hierarchical probabilistic model
The core predictor is a Vision Transformer-oriented regression model in src/model.py. Its architectural contract is to produce probability distributions over answer branches for Galaxy Zoo questions, respecting each question’s simplex constraint rather than independent unconstrained scalar regression.
Alternative modeling and baseline paths are centralized in src/baselines.py, enabling comparison with ResNet, ViT MSE-only, and Dirichlet-style approaches. Experiment variants are selected through YAML configurations such as configs/base.yaml, configs/full_train.yaml, and configs/ablation.yaml.
Optimization and experiment execution
Training consumes batches from src/dataset.py, forwards them through src/model.py, and applies the composite probabilistic objective in src/loss.py: KL divergence plus MSE. src/train.py is the main multi-stage training workflow, while src/train_single.py supports a single configured run.
Ablation control in src/ablation.py varies important training choices, notably loss weighting/configuration. Run configuration is externalized in configs/, keeping experiment parameters separate from model and loss implementation.
Evaluation, validity, and calibration
Full evaluation is orchestrated by src/evaluate_full.py, using shared calculations from src/metrics.py. This boundary measures MAE/RMSE and probability-quality properties, including calibration and simplex violations—critical because valid per-question distributions are a core model guarantee.
The evaluation path compares proposed and baseline models, with generated manuscript artifacts retained under outputs/manuscript/03_baseline_comparison/ and outputs/manuscript/05_calibration/.
Interpretability and uncertainty stages
Attention inspection is a distinct post-training analysis stage in src/attention_viz.py, producing ViT attention rollout/entropy artifacts represented in outputs/manuscript/06_interpretability/.
Uncertainty analysis is implemented in src/uncertainty_analysis.py; its outputs relate predicted uncertainty to prediction error and are published under outputs/manuscript/07_uncertainty/. These stages consume trained-model predictions rather than altering the training path.
Output collection and publication artifacts
scripts/training/collect_outputs.py consolidates experiment results. Analysis scripts such as scripts/analysis/generate_comparison_tables.py and scripts/analysis/plot_training_curves.py transform collected metrics/checkpoints into tables and figures.
outputs/manuscript/ is the committed research-result boundary, with outputs/manuscript/MANIFEST.csv indexing final artifacts. The repository itself does not contain the described web demo; the deployed demo is an external Vercel service.
Main entry points: evaluate_full.py Full evaluation · train.py Multi-stage training · train_single.py Single-run training · dataset.py Dataset loader
Components 20
Data preparation
- Galaxy Zoo 2 imagery
- Hugging Face hosting · Hosts dataset and model assets.
- Image conversion
scripts/data/convert_zenodo_images.py - Label preparation · Builds hierarchical vote-distribution targets.
scripts/data/prepare_labels.py - Dataset verification
scripts/data/verify_dataset.py - Dataset loader · Supplies transformed images and hierarchical targets.
src/dataset.py
Model experiments
- Experiment configs · Selects training and ablation variants.
configs/base.yaml - Hierarchical ViT predictor · Emits simplex-constrained answer distributions per question.
src/model.py - Baseline models · ResNet, MSE-only ViT, and Dirichlet-style comparisons.
src/baselines.py - Composite objective · Combines KL divergence and MSE.
src/loss.py - Multi-stage training
src/train.py - Single-run training
src/train_single.py - Ablation orchestrator · Varies loss weighting and training choices.
src/ablation.py - Shell launcher
scripts/training/run_model.sh
Evaluation and publication
- Full evaluation · Evaluates validity, accuracy, calibration, and model comparisons.
src/evaluate_full.py - Probability metrics · Calculates errors, calibration, and simplex violations.
src/metrics.py - Attention analysis · Produces ViT attention rollout and entropy artifacts.
src/attention_viz.py - Uncertainty analysis · Relates predicted uncertainty to prediction error.
src/uncertainty_analysis.py - Result collection
scripts/training/collect_outputs.py - Manuscript artifacts · Manifest-indexed committed research tables and figures.
outputs/manuscript/MANIFEST.csv
Connections 26
- Galaxy Zoo 2 imagery → Image conversion: source images
- Image conversion → Label preparation: prepared assets
- Label preparation → Dataset verification: labeled dataset
- Dataset verification → Dataset loader: validated data
- Hugging Face hosting → Dataset loader: hosted assets
- Experiment configs → Multi-stage training: parameters
- Experiment configs → Single-run training: run configuration
- Experiment configs → Ablation orchestrator: variant definitions
- Shell launcher → Multi-stage training: launches
- Ablation orchestrator → Single-run training: configured runs
- Dataset loader → Multi-stage training: image batches and targets
- Hierarchical ViT predictor → Multi-stage training: forward model
- Composite objective → Multi-stage training: optimization objective
- Dataset loader → Single-run training: image batches and targets
- Hierarchical ViT predictor → Single-run training: forward model
- Composite objective → Single-run training: optimization objective
- Multi-stage training → Full evaluation: trained predictions
- Single-run training → Full evaluation: trained predictions
- Baseline models → Full evaluation: comparison predictions
- Probability metrics → Full evaluation: shared calculations
- Full evaluation → Attention analysis: trained model outputs
- Full evaluation → Uncertainty analysis: predictions and errors
- Full evaluation → Result collection: metrics and checkpoints
- Attention analysis → Result collection: interpretability artifacts
- Uncertainty analysis → Result collection: uncertainty artifacts
- Result collection → Manuscript artifacts: tables and figures