PyramidDiff
a model for analyzing and generating population pyramids
2 min readupdated
PyramidDiff is a compact conditional diffusion model (a 1D UNet—a one-dimensional network for sequential data—with around 7.3 million parameters) trained on the UN World Population Prospects 2024 dataset. It is built to generate and refine national population structures by age and sex, helping smooth out age distortions in statistics, fill in missing data, and sanity-check demographic pyramids. The tool is aimed at demographers, data researchers, and statistical system developers.
Key features
- Trained on UN data (World Population Prospects 2024) covering countries worldwide from 1950 to 2023.
- Uses a 1D UNet architecture with around 7.3M parameters to model age distributions.
- Supports correcting age distortions and rounding artifacts in statistical data.
- Generates plausible pyramids conditioned on summary metrics like median age and sex ratio.
What you can do
- Generate synthetic population age pyramids for a specific year and target demographic parameters.
- Clean up age rounding errors (age heaping) in statistical datasets.
- Spot anomalies and implausible distributions in demographic reports using denoising error scoring.
Example
from huggingface_hub import snapshot_download
import importlib.util, os
p = snapshot_download("SallySims/pyramiddiff-wpp2024")
spec = importlib.util.spec_from_file_location("pyramiddiff", os.path.join(p, "pyramiddiff.py"))
P = importlib.util.module_from_spec(spec); spec.loader.exec_module(P)
model, diff, norm = P.load_pretrained(p)
samples = P.generate(model, diff, norm, median_age=20, u15=0.42, p65=0.03, sex_ratio=99, year=2005)
Read more
Details• Architecture: 1D UNet, ~7.3M parameters
• MAE score: best result using PCHIP initialization is 0.103
• Limitations: research prototype trained on smoothed UN estimates, not intended for official statistics
• Dataset: UN World Population Prospects 2024 (1950–2023)










Comments