PAT small 29k encoder weights converted from the authors Keras H5 to safetensors, values unchanged
Browse filesFiles changed (3)
- README.mdAdded+126
- config.jsonAdded+17
- model.safetensorsAdded+3
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126---license: cc-by-4.0library_name: riseuppipeline_tag: feature-extractiontags:- 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 itsauthors 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 thatthe model can be run in PyTorch without TensorFlow. RISE UP did not train, fine-tune, prune or quantise them.
## 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 onthese 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 tofloat32 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 perminute, at most a week, each minute standardised with statistics fitted on people, and any patch with a missingminute left out of attention and of the mean (the encoder's pre-training also removed hidden patches before theencoder). The network alone:
```pythonfrom safetensors.torch import load_filefrom riseup.models.foundation import patfrom 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.1234567891011121314151617{ "model_type": "pat", "size": "small", "patch_size": 18, "embed_dim": 96, "num_heads": 6, "ff_dim": 256, "num_layers": 1, "layer_norm_eps": 1e-06, "keras_version": "2.15.0", "trained_length": 10080, "source_file": "PAT-S_29k_weights.h5", "source_sha256": "df8d9f0f66bab088d2d4870cb2df4342745940c732d008cd3d74687be4ee99be", "source": "https://github.com/njacobsonlab/Pretrained-Actigraphy-Transformer", "licence": "CC-BY-4.0", "attribution": "Ruan, Zhang, Oh, Jin and Jacobson, 'A Foundation Model for Wearable Movement Data in Mental Health Research', IEEE J Biomed Health Inform, doi:10.1109/JBHI.2026.3694809. Converted from Keras to PyTorch by RISE UP."}123version https://git-lfs.github.com/spec/v1oid sha256:1ce59f0f0572bc758d1349fbedda6b1ded6a6592c66e5c7eea60c6dc3f01a5bfsize 1100616README.mdAdded+126
config.jsonAdded+17
model.safetensorsAdded+3