--- license: mit library_name: pytorch pipeline_tag: token-classification tags: - demography - population-pyramid - transformer - global-health datasets: - SallySims/wpp2024-single-age-pyramids --- # PyramidFormer heaping-detector 0.8M parameters. Outputs, for every single age 0-100, the probability that the reported count is inflated by digit preference (more than 5% above the true count). Trained and evaluated on **synthetic** heaping: 80% of pyramids heaped at multiples of 5 within +-2 years, with a random subset of active heaps and random strengths, 20% clean, plus roster noise. Real survey heaping differs by country, sex and age; this has not been validated on real survey data. ## Evaluation (held-out countries, 3404 pyramids, synthetic) | Method | Precision | Recall | F1 | False-positive rate on clean pyramids | |---|---|---|---|---| | Digit rule (flag every age ending 0/5) | 0.473 | 1.000 | 0.642 | 0.188 | | **PyramidFormer (p >= 0.5)** | 0.975 | 0.995 | 0.985 | 0.000 | PyramidFormer AUROC 1.000, average precision 0.999. The digit rule has perfect recall by construction on this simulator, so compare precision and the false-positive rate on clean pyramids. ## Training run quick run: 2000 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](https://huggingface.co/datasets/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 ```python from huggingface_hub import snapshot_download import importlib.util, os p = snapshot_download("SallySims/pyramidformer-heaping-detector") 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) import numpy as np # obs: (n, 2, 101) reported population, [male, female] x single ages 0..100; years: (n,) survey years obs = obs / obs.sum(axis=(1, 2), keepdims=True) prob = P.predict_heaping(model, norm.encode(obs), years) # (n, 101): P(age is inflated by digit preference) flagged = prob >= 0.5 ```