|
Download README.md from RISEUP-Lab/pat-small-29k: direct link, hf CLI and curl.
- Browser
- Download file 7.45 kB
-
https://huggingface.co/RISEUP-Lab/pat-small-29k/resolve/main/README.md
- Command line
-
hf download hf://RISEUP-Lab/pat-small-29k/README.md
-
curl -L -o README.md https://huggingface.co/RISEUP-Lab/pat-small-29k/resolve/main/README.md
7.45 kB
| license: cc-by-4.0 | |
| library_name: riseup | |
| pipeline_tag: feature-extraction | |
| tags: | |
| - actigraphy | |
| - accelerometry | |
| - wearables | |
| - physical-activity | |
| - mental-health | |
| - time-series | |
| - foundation-model | |
| - masked-autoencoder | |
| - pytorch | |
| - safetensors | |
| # PAT-S (29k): the Pretrained Actigraphy Transformer, small, as PyTorch safetensors | |
| These are the **encoder weights of the Pretrained Actigraphy Transformer (PAT), small size**, that its | |
| authors published as a Keras weights file (`PAT-S_29k_weights.h5`), converted by the | |
| [RISE UP](https://huggingface.co/RISEUP-Lab) project to `safetensors` **with every value unchanged**, so that | |
| the model can be run in PyTorch without TensorFlow. RISE UP did not train, fine-tune, prune or quantise them. | |
| RISE UP's code is at <https://github.com/RISEUP-Lab/riseup>. This card and RISE UP's conversion code were written with the help of generative AI (Claude Code); see RISE UP's README, ["Use of AI"](https://github.com/RISEUP-Lab/riseup#use-of-ai). | |
| ## The original work | |
| - **Authors**: Franklin Y. Ruan, Aiwei Zhang, Jenny Y. Oh, SouYoung Jin and Nicholas C. Jacobson. | |
| - **Paper**: "A Foundation Model for Wearable Movement Data in Mental Health Research", *IEEE Journal of | |
| Biomedical and Health Informatics* (early access), doi:[10.1109/JBHI.2026.3694809](https://doi.org/10.1109/JBHI.2026.3694809); | |
| preprint [arXiv:2411.15240](https://arxiv.org/abs/2411.15240). | |
| - **Code and original weights**: <https://github.com/njacobsonlab/Pretrained-Actigraphy-Transformer>, released | |
| under the [Creative Commons Attribution 4.0 International licence (CC BY 4.0)](https://creativecommons.org/licenses/by/4.0/). | |
| This conversion is distributed under the same licence. | |
| Please cite the authors' paper if you use these weights: | |
| ```bibtex | |
| @article{ruan2026pat, | |
| author = {Ruan, Franklin Y. and Zhang, Aiwei and Oh, Jenny Y. and Jin, SouYoung and Jacobson, Nicholas C.}, | |
| title = {A Foundation Model for Wearable Movement Data in Mental Health Research}, | |
| journal = {IEEE Journal of Biomedical and Health Informatics}, | |
| year = {2026}, | |
| doi = {10.1109/JBHI.2026.3694809} | |
| } | |
| ``` | |
| ## What was changed (CC BY 4.0: "indicate if changes were made") | |
| - **Source**: `PAT-S_29k_weights.h5` (SHA-256 `df8d9f0f66bab088d2d4870cb2df4342745940c732d008cd3d74687be4ee99be`), the file the original repository's README links | |
| under "Pretrained on 2003-2004, 2005-2006, 2011-2012, 2013-2014 NHANES Actigraphy (N=29,307)". | |
| - **Conversion**: the file was read as data with `h5py` (never loaded as a Keras model) and written to | |
| `model.safetensors`. The values are the original float32 values, bit for bit: only the tensor names changed, | |
| and the dense layers' kernels (the patch projection and the feed-forward layers) were transposed to PyTorch's | |
| `(out, in)` layout. `config.json` records the architecture and the source file's SHA-256. | |
| - **Code**: the network is RISE UP's PyTorch rewrite of the authors' Keras encoder | |
| (`riseup/models/foundation/pat_network.py`, CC BY 4.0 with this attribution). Its fixed sine-cosine position | |
| table is computed in float64 and rounded once to float32; the original computes it in float32. | |
| ## Agreement with the original | |
| On seeded inputs of 1,440, 4,320, 4,338 and 10,080 minutes (four series each), RISE UP's PyTorch port on | |
| these weights was compared with TensorFlow 2.15.1 (Keras 2.15.0) running the authors' own encoder code | |
| (`load_encoder_model` from their fine-tuning demo) on the original H5 file: | |
| | Output | Largest absolute difference | | |
| |---|---| | |
| | Each patch's 96 numbers | 5.5e-4 (3.0e-5 of the largest value) | | |
| | The mean of the patch vectors (the published embedding) | 2.4e-6 | | |
| | The same, given TensorFlow's own float32 position table: each patch / the mean | 1.0e-5 / 7.2e-7 | | |
| | A subset of patches (70 % kept), against the pre-training notebook's own route for visible patches | 5.5e-4 | | |
| The patch vectors reach about 18 in magnitude. With TensorFlow's own position table the two agree to | |
| float32 rounding; the rest of the difference is that table. TensorFlow's and PyTorch's float32 `sin` and `exp` | |
| differ by up to about 1e-4 at the farthest patches of a week. | |
| ## What the model expects | |
| - **One value per minute of movement**, one series at a time. In pre-training these were ActiGraph activity | |
| counts (hip) and MIMS units (wrist). | |
| - **Each minute standardised across people**, as the authors did: a z-score per minute, fitted with | |
| scikit-learn's `StandardScaler` on a people x minutes matrix (paper §III.B.1). The model does not rescale its | |
| input itself; raw values are not what it was trained on. | |
| - **Up to a week**: it was pre-trained on 10,080 minutes (560 patches). The length must be a whole | |
| number of 18-minute patches; the authors zero-pad at the end otherwise. | |
| - **Output**: one 96-number vector per patch. The paper's embedding is their mean (global average pooling); | |
| there is no class token. | |
| - **Architecture**: a linear projection of each 18-minute patch to 96 numbers, sine-cosine positions (the | |
| first 48 numbers sines, the last 48 cosines), then 1 post-norm transformer block with 6 | |
| attention heads of 96 numbers each, a ReLU feed-forward layer of 256 and layer norms with epsilon 1e-6. | |
| - **Parameters**: 274,720 (the encoder alone; the paper's figures include its classification head). | |
| - **Pre-training**: a masked autoencoder, 90 % of each week's patches hidden and reconstructed, mean squared | |
| error over all minutes (paper §III.D and Supplementary Table 1). | |
| ## Use with RISE UP | |
| RISE UP reads these weights as a frozen embedder, `riseup.models.foundation.pat.PatSmallEmbedder`: one value per | |
| minute, at most a week, each minute standardised with statistics fitted on people, and any patch with a missing | |
| minute left out of attention and of the mean (the encoder's pre-training also removed hidden patches before the | |
| encoder). The network alone: | |
| ```python | |
| from safetensors.torch import load_file | |
| from riseup.models.foundation import pat | |
| from riseup.models.foundation.pat_network import PatEncoder | |
| encoder = PatEncoder(**pat.SIZES["small"].config()) | |
| encoder.load_state_dict(load_file("model.safetensors")) | |
| encoder.eval() | |
| tokens = encoder(z_scored_minutes) # (batch, minutes) float32 -> (batch, patches, 96) | |
| embedding = tokens.mean(dim=1) # the published embedding | |
| ``` | |
| ## Training data and limitations | |
| - **Who**: 29,307 participants of the US National Health and Nutrition Examination Survey (NHANES), cycles | |
| 2003-04, 2005-06, 2011-12 and 2013-14; each kept record held at least 10,080 consecutive minutes (paper | |
| §III.A). A study of NHANES actigraphy from these cycles uses people whose recordings this model has | |
| already seen, though not their labels. The authors also publish a set pre-trained without 2013-14 | |
| (N=21,538), which is not converted here. | |
| - **Devices and units**: 2003-06, a hip-worn uniaxial ActiGraph AM-7164 (activity counts per minute); 2011-14, | |
| a wrist-worn ActiGraph GT3X+ with its three axes summed into one value per minute (MIMS units). Each cycle was | |
| standardised on its own to reduce device differences, which the authors note it does not remove. **It never | |
| saw ENMO** or any other device's units: its numbers on such data are an extrapolation. | |
| - **Evaluated on**: benzodiazepine and SSRI use, depression (PHQ-9 of 10 or more), sleep disorder and sleep | |
| abnormalities, from NHANES 2013-14 (paper Table II). | |
| - A research tool, not a clinical decision support system. | |