SallySims's picture
Upload folder using huggingface_hub
469767e verified
|
Raw History Blame Contribute Delete
2.49 kB
metadata
license: mit
library_name: pytorch
pipeline_tag: time-series-forecasting
tags:
  - demography
  - population-pyramid
  - transformer
  - global-health
datasets:
  - SallySims/wpp2024-single-age-pyramids

PyramidFormer forecaster

0.8M parameters. Given a pyramid and its year, predicts the pyramid h years later (h = 1..25) as a residual on the input. Trained on country-year pairs from WPP estimates 1950-2023.

Evaluation (held-out countries, all origin years; MAE of single-age shares, per mille of total population, lower is better)

Horizon h (years) PyramidFormer Persistence Cohort shift (no mortality)
1 0.118 0.098 0.070
5 0.324 0.379 0.306
10 0.433 0.600 0.571
20 0.544 0.876 1.082
25 0.588 0.968 1.321

Limitations: the targets are UN modelled estimates, so this learns the demographic dynamics embedded in WPP rather than independent real-world forecasts; there is no uncertainty estimate; migration shocks and wars in held-out countries are not anticipated.

Training run

quick run: 3000 optimisation steps.

Training data

UN World Population Prospects 2024, single-age population by sex, countries/areas, 1950-2023 (estimates), as processed in SallySims/wpp2024-single-age-pyramids. Split by country: 80% train / 10% validation / 10% test, so every number above is on countries the model never saw. WPP pyramids are modelled estimates, not raw census counts. Source: United Nations, DESA, Population Division (2024). World Population Prospects 2024. https://population.un.org/wpp/ Check the UN terms of use before reuse. Research prototype; not for official statistics. This repo is self-contained: pyramidformer.py (model code), model.safetensors, config.json. There is no hosted inference widget because the architecture is custom; use the snippet below.

Usage

from huggingface_hub import snapshot_download
import importlib.util, os
p = snapshot_download("SallySims/pyramidformer-forecaster")
spec = importlib.util.spec_from_file_location("pyramidformer", os.path.join(p, "pyramidformer.py"))
P = importlib.util.module_from_spec(spec); spec.loader.exec_module(P)
model, norm = P.load_pretrained(p)
# shares_now: (n, 2, 101) = [male, female] x single ages 0..100 for the year in `year_now`
future = P.predict_forecast(model, norm, shares_now, year_now, h=10)    # (n, 2, 101) shares, h in 1..25