# sustainlab-group/sustainbench architecture

> Architecture diagram of the GitHub repository sustainlab-group/sustainbench, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-08-24). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/sustainlab-group/sustainbench
- Repository: https://github.com/sustainlab-group/sustainbench

## Overview

#### Purpose and Entry Points
SustainBench is a Python benchmark-data package for SDG-focused ML tasks, exposing PyTorch-ready dataset loaders rather than an application service. Primary access points are dataset retrieval/selection in `sustainbench/get_dataset.py` and `sustainbench/download_datasets.py`; package metadata begins at `sustainbench/__init__.py` and `setup.py`.

#### Dataset Abstraction Layer
The central dataset contract is defined by `sustainbench/datasets/sustainbench_dataset.py`. Task-specific implementations specialize it for DHS/poverty, crop segmentation/yield/type mapping, brick-kiln imagery, and fMoW land-cover tasks:
- `sustainbench/datasets/dhs_dataset.py`
- `sustainbench/datasets/crop_seg_dataset.py`
- `sustainbench/datasets/fmow_dataset.py`

This is the principal boundary between downloaded, task-specific on-disk artifacts and model-facing tensors/labels.

#### Acquisition and Dataset Routing
` s u s t a i n b e n c h / d o w n l o a d _ d a t a s e t s . p y` (path: `sustainbench/download_datasets.py`) obtains processed benchmark data; `sustainbench/datasets/download_utils.py` contains shared download behavior. `sustainbench/get_dataset.py` resolves user-requested datasets to concrete loader implementations. Processed data is externally hosted on Google Drive, while raw data and preprocessing inputs are intentionally outside the normal training path.

#### Training/Evaluation Support
Common ML plumbing is shared across loaders and downstream baselines:
- `sustainbench/common/data_loaders.py`
- `sustainbench/common/grouper.py`
- `sustainbench/common/metrics/all_metrics.py`

The grouper and metrics layers support consistent aggregate and group-aware benchmark evaluation across heterogeneous task types. Loss and metric abstractions live under `sustainbench/common/metrics/`.

#### DHS/LSMS Label Production Pipeline
The most substantial data-creation workflow builds survey-derived labels for poverty, health, education, water, and sanitation. R scripts create DHS and LSMS labels, with notebooks exporting and processing TFRecords:
- `dataset_preprocessing/dhs_lsms/1_create_dhs_labels.R`
- `dataset_preprocessing/dhs_lsms/1_create_lsms_labels.R`
- `dataset_preprocessing/dhs_lsms/2_export_tfrecords.ipynb`

DHS cleanup/recode rules and LSMS country harmonization are separate source boundaries in `dataset_preprocessing/dhs_lsms/dhs_utils/cleaning_utils.R` and `dataset_preprocessing/dhs_lsms/lsms_utils/`. Final DHS outputs are materialized under `dataset_preprocessing/dhs_lsms/output_labels/`.

#### Geospatial and Other Preprocessing
DHS record-to-imagery preparation includes Earth Engine support in `dataset_preprocessing/dhs_lsms/ee_utils.py`; TFRecord export/processing establishes a TensorFlow-era intermediate format. Brick-kiln CSV preparation is isolated in `dataset_preprocessing/brickkiln_csv_processing.ipynb`. These workflows produce release artifacts consumed later by Python loaders, not runtime dependencies for ordinary users.

#### Runtimes and Infrastructure
The repository spans Python 3.7, PyTorch 1.9 for loaders/models, TensorFlow 1.15 for preprocessing/TFRecords, and R 4.1 for survey label engineering. Conda environment definitions are `env_bench.yml` and `dataset_preprocessing/env_create.yml`. GPU execution is optional, with CUDA/cuDNN requirements noted for accelerated TensorFlow/PyTorch workloads; Google Drive is the primary external dataset distribution service.

Main entry points: [`sustainbench/datasets/sustainbench_dataset.py`](https://github.com/sustainlab-group/sustainbench/blob/main/sustainbench/datasets/sustainbench_dataset.py) (Dataset contract), [`sustainbench/get_dataset.py`](https://github.com/sustainlab-group/sustainbench/blob/main/sustainbench/get_dataset.py) (Dataset selector), [`sustainbench/datasets/dhs_dataset.py`](https://github.com/sustainlab-group/sustainbench/blob/main/sustainbench/datasets/dhs_dataset.py) (Task dataset loaders), [`dataset_preprocessing/dhs_lsms/2_export_tfrecords.ipynb`](https://github.com/sustainlab-group/sustainbench/blob/main/dataset_preprocessing/dhs_lsms/2_export_tfrecords.ipynb) (TFRecord export)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_package["Python benchmark package"]
  node_metadata["Package metadata<br/>Python packaging<br/>[__init__.py]"]
  node_setup["Installation metadata<br/>setuptools<br/>[setup.py]"]
  node_get_dataset["Dataset selector<br/>Python API<br/>[get_dataset.py]"]
  node_download_datasets["Dataset retrieval<br/>Python CLI/API"]
  node_download_utils["Download utilities<br/>Python module<br/>[download_utils.py]"]
end

subgraph group_runtime["Dataset runtime"]
  node_dataset_contract["Dataset contract<br/>base dataset"]
  node_task_loaders["Task dataset loaders<br/>dataset implementations<br/>[dhs_dataset.py]"]
  node_crop_loader["Crop segmentation loader<br/>dataset implementation"]
  node_fmow_loader["fMoW loader<br/>dataset implementation<br/>[fmow_dataset.py]"]
  node_data_loaders["ML data loaders<br/>PyTorch utilities<br/>[data_loaders.py]"]
  node_grouper["Group evaluation<br/>grouping utility<br/>[grouper.py]"]
  node_metrics["Metrics<br/>evaluation module<br/>[all_metrics.py]"]
end

subgraph group_preprocessing["Release-data preprocessing"]
  node_survey_labels["DHS and LSMS labels<br/>R label engineering"]
  node_survey_rules["Survey cleanup and harmonization<br/>R utilities<br/>[cleaning_utils.R]"]
  node_tfrecord_export["TFRecord export<br/>TensorFlow notebook"]
  node_earth_engine["DHS imagery preparation<br/>Earth Engine utility<br/>[ee_utils.py]"]
  node_label_outputs[("Survey release artifacts<br/>processed labels")]
  node_brickkiln_prep["Brick-kiln CSV preparation<br/>preprocessing notebook"]
end

node_google_drive[("Processed dataset releases<br/>Google Drive")]

node_metadata -->|"packaged by"| node_setup
node_get_dataset -->|"selects"| node_task_loaders
node_get_dataset -->|"selects"| node_crop_loader
node_get_dataset -->|"selects"| node_fmow_loader
node_task_loaders -->|"specializes"| node_dataset_contract
node_crop_loader -->|"specializes"| node_dataset_contract
node_fmow_loader -->|"specializes"| node_dataset_contract
node_data_loaders -->|"batches"| node_dataset_contract
node_grouper -->|"supports group-aware evaluation"| node_metrics
node_download_datasets -->|"uses"| node_download_utils
node_download_utils -->|"downloads from"| node_google_drive
node_download_datasets -.->|"provisions artifacts for"| node_task_loaders
node_survey_rules -->|"supplies recoding rules"| node_survey_labels
node_survey_labels -->|"provides survey labels"| node_tfrecord_export
node_earth_engine -->|"prepares imagery records"| node_tfrecord_export
node_tfrecord_export -->|"materializes"| node_label_outputs
node_label_outputs -.->|"published as release data"| node_google_drive
node_brickkiln_prep -.->|"publishes release artifacts"| node_google_drive

click node_metadata "https://github.com/sustainlab-group/sustainbench/blob/main/sustainbench/__init__.py"
click node_setup "https://github.com/sustainlab-group/sustainbench/blob/main/setup.py"
click node_get_dataset "https://github.com/sustainlab-group/sustainbench/blob/main/sustainbench/get_dataset.py"
click node_download_datasets "https://github.com/sustainlab-group/sustainbench/blob/main/sustainbench/download_datasets.py"
click node_download_utils "https://github.com/sustainlab-group/sustainbench/blob/main/sustainbench/datasets/download_utils.py"
click node_dataset_contract "https://github.com/sustainlab-group/sustainbench/blob/main/sustainbench/datasets/sustainbench_dataset.py"
click node_task_loaders "https://github.com/sustainlab-group/sustainbench/blob/main/sustainbench/datasets/dhs_dataset.py"
click node_crop_loader "https://github.com/sustainlab-group/sustainbench/blob/main/sustainbench/datasets/crop_seg_dataset.py"
click node_fmow_loader "https://github.com/sustainlab-group/sustainbench/blob/main/sustainbench/datasets/fmow_dataset.py"
click node_data_loaders "https://github.com/sustainlab-group/sustainbench/blob/main/sustainbench/common/data_loaders.py"
click node_grouper "https://github.com/sustainlab-group/sustainbench/blob/main/sustainbench/common/grouper.py"
click node_metrics "https://github.com/sustainlab-group/sustainbench/blob/main/sustainbench/common/metrics/all_metrics.py"
click node_survey_labels "https://github.com/sustainlab-group/sustainbench/blob/main/dataset_preprocessing/dhs_lsms/1_create_dhs_labels.R"
click node_survey_rules "https://github.com/sustainlab-group/sustainbench/blob/main/dataset_preprocessing/dhs_lsms/dhs_utils/cleaning_utils.R"
click node_tfrecord_export "https://github.com/sustainlab-group/sustainbench/blob/main/dataset_preprocessing/dhs_lsms/2_export_tfrecords.ipynb"
click node_earth_engine "https://github.com/sustainlab-group/sustainbench/blob/main/dataset_preprocessing/dhs_lsms/ee_utils.py"
click node_brickkiln_prep "https://github.com/sustainlab-group/sustainbench/blob/main/dataset_preprocessing/brickkiln_csv_processing.ipynb"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_metadata,node_setup,node_get_dataset,node_download_datasets,node_download_utils toneBlue
class node_dataset_contract,node_task_loaders,node_crop_loader,node_fmow_loader,node_data_loaders,node_grouper,node_metrics toneAmber
class node_survey_labels,node_survey_rules,node_tfrecord_export,node_earth_engine,node_label_outputs,node_brickkiln_prep toneMint
class node_google_drive toneNeutral
```

## Components

### Python benchmark package

- [Package metadata](https://github.com/sustainlab-group/sustainbench/blob/main/sustainbench/__init__.py): Python packaging · `sustainbench/__init__.py`
- [Installation metadata](https://github.com/sustainlab-group/sustainbench/blob/main/setup.py): setuptools · `setup.py`
- [Dataset selector](https://github.com/sustainlab-group/sustainbench/blob/main/sustainbench/get_dataset.py): Python API · Resolves requested benchmark datasets to concrete loaders. · `sustainbench/get_dataset.py`
- [Dataset retrieval](https://github.com/sustainlab-group/sustainbench/blob/main/sustainbench/download_datasets.py): Python CLI/API · Obtains processed benchmark releases. · `sustainbench/download_datasets.py`
- [Download utilities](https://github.com/sustainlab-group/sustainbench/blob/main/sustainbench/datasets/download_utils.py): Python module · `sustainbench/datasets/download_utils.py`

### Dataset runtime

- [Dataset contract](https://github.com/sustainlab-group/sustainbench/blob/main/sustainbench/datasets/sustainbench_dataset.py): base dataset · Boundary from on-disk artifacts to model-facing tensors and labels. · `sustainbench/datasets/sustainbench_dataset.py`
- [Task dataset loaders](https://github.com/sustainlab-group/sustainbench/blob/main/sustainbench/datasets/dhs_dataset.py): dataset implementations · DHS, crop, brick-kiln, and fMoW task specializations. · `sustainbench/datasets/dhs_dataset.py`
- [Crop segmentation loader](https://github.com/sustainlab-group/sustainbench/blob/main/sustainbench/datasets/crop_seg_dataset.py): dataset implementation · `sustainbench/datasets/crop_seg_dataset.py`
- [fMoW loader](https://github.com/sustainlab-group/sustainbench/blob/main/sustainbench/datasets/fmow_dataset.py): dataset implementation · `sustainbench/datasets/fmow_dataset.py`
- [ML data loaders](https://github.com/sustainlab-group/sustainbench/blob/main/sustainbench/common/data_loaders.py): PyTorch utilities · `sustainbench/common/data_loaders.py`
- [Group evaluation](https://github.com/sustainlab-group/sustainbench/blob/main/sustainbench/common/grouper.py): grouping utility · `sustainbench/common/grouper.py`
- [Metrics](https://github.com/sustainlab-group/sustainbench/blob/main/sustainbench/common/metrics/all_metrics.py): evaluation module · Provides aggregate and group-aware benchmark metrics. · `sustainbench/common/metrics/all_metrics.py`

### Release-data preprocessing

Offline workflows produce artifacts for package loaders.

- [DHS and LSMS labels](https://github.com/sustainlab-group/sustainbench/blob/main/dataset_preprocessing/dhs_lsms/1_create_dhs_labels.R): R label engineering · Creates poverty, health, education, water, and sanitation labels. · `dataset_preprocessing/dhs_lsms/1_create_dhs_labels.R`
- [Survey cleanup and harmonization](https://github.com/sustainlab-group/sustainbench/blob/main/dataset_preprocessing/dhs_lsms/dhs_utils/cleaning_utils.R): R utilities · DHS recoding and LSMS country harmonization inputs. · `dataset_preprocessing/dhs_lsms/dhs_utils/cleaning_utils.R`
- [TFRecord export](https://github.com/sustainlab-group/sustainbench/blob/main/dataset_preprocessing/dhs_lsms/2_export_tfrecords.ipynb): TensorFlow notebook · Exports and processes survey data into a TensorFlow-era intermediate. · `dataset_preprocessing/dhs_lsms/2_export_tfrecords.ipynb`
- [DHS imagery preparation](https://github.com/sustainlab-group/sustainbench/blob/main/dataset_preprocessing/dhs_lsms/ee_utils.py): Earth Engine utility · `dataset_preprocessing/dhs_lsms/ee_utils.py`
- **Survey release artifacts**: processed labels
- [Brick-kiln CSV preparation](https://github.com/sustainlab-group/sustainbench/blob/main/dataset_preprocessing/brickkiln_csv_processing.ipynb): preprocessing notebook · Offline preparation for brick-kiln release artifacts. · `dataset_preprocessing/brickkiln_csv_processing.ipynb`

### Other components

- **Processed dataset releases**: Google Drive · External distribution for processed benchmark data.

## Connections

- Package metadata → Installation metadata: packaged by
- Dataset selector → Task dataset loaders: selects
- Dataset selector → Crop segmentation loader: selects
- Dataset selector → fMoW loader: selects
- Task dataset loaders → Dataset contract: specializes
- Crop segmentation loader → Dataset contract: specializes
- fMoW loader → Dataset contract: specializes
- ML data loaders → Dataset contract: batches
- Group evaluation → Metrics: supports group-aware evaluation
- Dataset retrieval → Download utilities: uses
- Download utilities → Processed dataset releases: downloads from
- Dataset retrieval → Task dataset loaders: provisions artifacts for
- Survey cleanup and harmonization → DHS and LSMS labels: supplies recoding rules
- DHS and LSMS labels → TFRecord export: provides survey labels
- DHS imagery preparation → TFRecord export: prepares imagery records
- TFRecord export → Survey release artifacts: materializes
- Survey release artifacts → Processed dataset releases: published as release data
- Brick-kiln CSV preparation → Processed dataset releases: publishes release artifacts
