retroBERT: susceptibility prediction from pre-stress pose dynamics

retroBERT is a BERT encoder that reads the 3D pose of a mouse in a 10-minute open-field recording, made before any stress exposure. From that recording it predicts whether the animal will later prove susceptible or resilient to chronic social defeat stress.

This repository holds the trained checkpoints behind the reported male-cohort results: 5 independent training runs × 5 leave-one-cohort-out folds = 25 models.

Results

Each fold's model scores the animals of the one cohort it never saw in training or validation. The table reports held-out results for each run and mean ± sample SD across runs.

Run Pair ROC Pooled F1 (%) Pooled Acc (%)
r1 0.744 65.34 68.42
r2 0.698 62.97 66.67
r3 0.698 63.46 68.42
r4 0.705 64.95 70.18
r5 0.682 69.59 75.44
Mean ± SD 0.705 ± 0.023 65.26 ± 2.61 69.82 ± 3.37
  • Pair ROC is the fraction of susceptible/resilient pairs the model ranks correctly. Pairs are formed only within a fold, so scores from different folds are never compared.
  • Pooled F1 / Acc combine the per-animal predictions of all five folds into one list, then compute macro-F1 and accuracy on it.
  • Runs r1–r5 differ only in their training seed, each drawn at random.

Files

r<run>/fold<k>/checkpoint_best_f1.pth.tar      run = 1..5, k = 1..5   (0.44 GB each, 11 GB total)

Fold k holds out cohort k as its test set:

Fold Test cohort (susceptible / resilient) Train (S / R) Validation (S / R)
1 cohort 1 (4 / 7) 11 / 23 4 / 8
2 cohort 2 (6 / 3) 9 / 26 4 / 9
3 cohort 3 (4 / 11) 11 / 20 4 / 7
4 cohort 4 (2 / 12) 12 / 19 5 / 7
5 cohort 5 (3 / 5) 12 / 24 4 / 9

Each file is a PyTorch dictionary:

Key Content
model_state_dict model weights (float32)
args argparse.Namespace with the data and training settings
best_metric validation macro-F1 at which this checkpoint was saved
step optimizer step at which it was saved

Optimizer and scheduler states are not included. These files are for inference, not for resuming training.

Model

  • Input: windows of 511 frames (25.6 s at 20 fps). Each frame has 21 values: the x, y, z coordinates of 7 keypoints (nose, head, body center, both hindpaws, both forepaws).
  • Pose representation: egocentric. Tail base is at the origin and the spine is aligned to +X. Coordinates are scaled by each animal's median spine length.
  • Encoder: a linear embedding (21 → 768) and a learned [CLS] token, followed by sinusoidal positional encoding. This feeds a 12-layer BERT encoder (hidden size 768, 12 heads) with a 2-class head. That makes 512 tokens per window and about 109.5M parameters.
  • Per-animal prediction: a recording of 11,800 frames is cut into 24 non-overlapping windows, with the last window zero-padded and masked. The animal's score is the mean of P(resilient) − P(susceptible) over its windows. A score of 0 or above is called resilient.
  • Feature scaling: a standard scaler is fitted on each fold's training animals. The scaler is not stored in the checkpoint. The code refits it from the training animals of that fold, which reproduces it exactly.

Training

Setting Value
Loss soft (differentiable) F1
Optimizer AdamW, learning rate 1e-6, weight decay 1e-8
Schedule linear warmup for 10% of steps, then linear decay
Epochs 100
Batch size 64
Gradient clipping max norm 1.0
Train / validation split 75 / 25 of the non-test cohorts, stratified by class
Checkpoint selection highest validation macro-F1

Validation animals come from the training cohorts. The held-out cohort is used only for the final test.

Usage

The checkpoints are meant to be used with the retroBERT code. That code builds the folds, refits the scaler, and handles windowing and per-animal scoring. To load a model directly:

import torch
from huggingface_hub import hf_hub_download
from retrobert.model import retroBERT

path = hf_hub_download("ShinSeungJ/retroBERT", "r1/fold1/checkpoint_best_f1.pth.tar")
ckpt = torch.load(path, map_location="cpu", weights_only=False)  # args is a Namespace
model = retroBERT(input_dim=21, max_seq_length=ckpt["args"].max_seq_length)
model.load_state_dict(ckpt["model_state_dict"])
model.eval()

weights_only=False is needed because args is stored as an argparse.Namespace. Load checkpoints only from sources you trust.

Limitations

  • Small dataset. The models were trained on 57 male mice from 5 cohorts. Held-out cohorts have 8–15 animals, so per-fold metrics vary widely.
  • Recording setup. The input is a specific 3D keypoint layout recorded at 20 fps. Other setups need the same egocentric pose representation (see the code repository) and may need retraining.
  • Research use only. These are research models of a preclinical behavioral phenotype, not diagnostic tools.
Downloads last month

-

Downloads are not tracked for this model. How to track
Inference Providers NEW
This model isn't deployed by any Inference Provider. 🙋 Ask for provider support