--- 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-L (29k): the Pretrained Actigraphy Transformer, large, as PyTorch safetensors These are the **encoder weights of the Pretrained Actigraphy Transformer (PAT), large size**, that its authors published as a Keras weights file (`PAT-L_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 . 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**: , 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-L_29k_weights.h5` (SHA-256 `e8ebef52e34a6f1ea92bbe3f752afcd1ae427b9efbe0323856e873f12c989521`), 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.2e-4 (3.5e-5 of the largest value) | | The mean of the patch vectors (the published embedding) | 3.5e-6 | | The same, given TensorFlow's own float32 position table: each patch / the mean | 1.2e-5 / 8.3e-7 | | A subset of patches (70 % kept), against the pre-training notebook's own route for visible patches | 5.2e-4 | The patch vectors reach about 15 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 (1120 patches). The length must be a whole number of 9-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 9-minute patch to 96 numbers, sine-cosine positions (the first 48 numbers sines, the last 48 cosines), then 4 post-norm transformer blocks with 12 attention heads of 96 numbers each, a ReLU feed-forward layer of 256 and layer norms with epsilon 1e-6. - **Parameters**: 1,984,192 (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.PatLargeEmbedder`: 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["large"].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.