MSGL-Transformer: A Multi-Scale Global-Local Transformer for Rodent Social Behavior Recognition
Organizations: Department of Computer Science, Kansas State University, Manhattan, KS, 66506, USA.
Abstract
Recognition of rodent behavior is important for understanding neural and behavioral mechanisms. Traditional manual scoring is time-consuming and prone to human error. We propose MSGL-Transformer, a Multi-Scale Global-Local Transformer for recognizing rodent social behaviors from pose-based temporal sequences. The model employs a lightweight transformer encoder with multi-scale attention to capture motion dynamics across different temporal scales. The architecture integrates parallel short-range, medium-range, and global attention branches to explicitly capture behavior dynamics at multiple temporal scales. We also introduce a Behavior-Aware Modulation (BAM) block, inspired by SE-Networks, which modulates temporal embeddings to emphasize behavior-relevant features prior to attention. We evaluate on two datasets: RatSI (5 behavior classes, 12D pose inputs) and CalMS21 (4 behavior classes, 28D pose inputs). On RatSI, MSGL-Transformer achieves 75.4% mean accuracy and F1-score of 0.745 across nine cross-validation splits, outperforming TCN, LSTM, and Bi-LSTM. On CalMS21, it achieves 87.1% accuracy and F1-score of 0.8745, a +10.7% improvement over HSTWFormer, and outperforms ST-GCN, MS-G3D, CTR-GCN, and STGAT. The same architecture generalizes across both datasets with only input dimensionality and number of classes adjusted.
Figures & tables
| Video | Solitary | Approaching | Following | Moving Away | Social Nose Contact | Allogrooming | Nape Attacking | Pinning | Other | Uncertain | Total Frames |
| Observation01 | 12,281 | 1,405 | 2,150 | 985 | 1,799 | 1,778 | 221 | 16 | 792 | 88 | 21,515 |
| Observation02 | 14,709 | 1,066 | 593 | 592 | 1,754 | 2,240 | 95 | 0 | 231 | 55 | 21,335 |
| Observation03 | 15,428 | 1,083 | 2,522 | 482 | 1,106 | 587 | 104 | 1,036 | 472 | 21 | 22,841 |
| Observation04 | 14,776 | 1,528 | 444 | 931 | 2,621 | 2,003 | 141 | 0 | 300 | 0 | 22,744 |
| Observation05 | 14,297 | 1,310 | 2,955 | 880 | 1,067 | 111 | 434 | 127 | 1,678 | 0 | 22,859 |
| Observation06 | 13,152 | 2,443 | 2,141 | 1,503 | 1,980 | 486 | 192 | 0 | 856 | 0 | 22,753 |
| Behavior | Description / Social Context |
| Solitary | The rat is alone , showing no social engagement (isolation phase). |
| Approaching | The rat initiates interaction by moving toward another (beginning of engagement). |
| Following | Indicates sustained interaction , maintaining social attention. |
| Moving Away | Shows withdrawal or avoidance , marking disengagement. |
| Social Nose Contact | Reflects direct physical interaction , the highest level of social engagement. |
| Behavior | Description / Social Context |
| Attack | Aggressive contact initiated by the resident mouse toward the intruder. |
| Investigation | The resident mouse closely sniffs or investigates the intruder mouse. |
| Mount | The resident mouse mounts the intruder, reflecting dominance behavior. |
| Other | All remaining frames not belonging to the three active social behaviors. |
| Split | Attack | Investigation | Mount | Other | Total Frames |
| Train (70 videos) | 14,039 | 146,615 | 28,615 | 318,469 | 507,738 |
| Test (19 videos) | 12,630 | 61,275 | 31,848 | 156,354 | 262,107 |
| All Videos | 26,669 | 207,890 | 60,463 | 474,823 | 769,845 |
| Train (%) | 2.76 | 28.88 | 5.64 | 62.73 | — |
| Aspect | RatSI | CalMS21 |
| Species | Rats | Mice |
| Number of Videos | 9 | 89 |
| Total Labeled Frames | ~202,550 | ~769,845 |
| Keypoints per Animal | 3 | 7 |
| Input Dimension ( ) | 12 | 28 |
| Behavior Classes ( ) | 5 | 4 |
| Hyperparameter | Symbol / Setting | Value | Description |
| Sequence length | 35 | Number of time steps per sequence | |
| Input dimension | 12 (RatSI) / 28 (CalMS21) | Coordinate features per frame | |
| Output classes | 5 (RatSI) / 4 (CalMS21) | Number of behavior classes | |
| Model dimension | 64 | Embedding size for each token | |
| Feed-forward dimension | 128 | Hidden size of the FFN | |
| Attention heads | 4 | Number of heads |
| Window Size | Parameters | Accuracy | F1-Score | Investigation F1 |
| 223,492 | 0.8706 | 0.8751 | 0.7728 | |
| 285,892 | 0.8709 | 0.8745 | 0.7881 | |
| 348,292 | 0.8711 | 0.8744 | 0.7896 |
| Validation | Test | Precision | Recall | F1 | Accuracy |
| 2 | 8 | 0.716 | 0.724 | 0.714 | 0.724 |
| 3 | 9 | 0.667 | 0.670 | 0.663 | 0.670 |
| 4 | 1 | 0.746 | 0.709 | 0.722 | 0.709 |
| 5 | 6 | 0.747 | 0.773 | 0.745 | 0.773 |
| 6 | 4 | 0.773 | 0.795 | 0.778 | 0.795 |
| 7 | 3 | 0.796 | 0.799 | 0.797 | 0.799 |
| Class | Valid-2-Test-8 | Valid-3-Test-9 | Valid-7-Test-3 |
| Approaching | 0.557 | 0.595 | 0.453 |
| Following | 0.566 | 0.520 | 0.592 |
| Moving away | 0.142 | 0.194 | 0.073 |
| Social Nose Contact | 0.624 | 0.510 | 0.348 |
| Solitary | 0.863 | 0.798 | 0.909 |
| Model | Accuracy | Precision | Recall | F1-score |
| TCN | 0.7519 | 0.7457 | 0.7519 | 0.7393 |
| LSTM | 0.6929 | 0.8361 | 0.6929 | 0.7392 |
| Bi-LSTM | 0.6865 | 0.8414 | 0.6865 | 0.7377 |
| MSGL-Transformer (Ours) | 0.8148 | 0.7976 | 0.8148 | 0.7967 |
| Model Variant | BAM | MSA | Accuracy |
| Base | 0.7567 | ||
| Base + Multi-Scale Attention (MSA) | ✓ | 0.7798 | |
| Base + BAM Module | ✓ | 0.7859 | |
| Full Model (MSGL-Transformer) | ✓ | ✓ | 0.8148 |
| Class | Precision | Recall | F1-Score | Support |
| Attack | 0.5942 | 0.5720 | 0.5829 | 12,586 |
| Investigation | 0.7157 | 0.8768 | 0.7881 | 60,964 |
| Mount | 0.8646 | 0.8798 | 0.8722 | 31,813 |
| Other | 0.9774 | 0.8909 | 0.9321 | 156,079 |
| Model | Accuracy | Precision | Recall | F1-Score |
| TCN | 0.8486 | 0.8825 | 0.8486 | 0.8588 |
| LSTM | 0.8683 | 0.8714 | 0.8683 | 0.8696 |
| Bi-LSTM | 0.8606 | 0.8682 | 0.8606 | 0.8638 |
| MSGL-Transformer (Ours) | 0.8709 | 0.8842 | 0.8709 | 0.8745 |
| Model Variant | BAM | MSA | Accuracy | Attack F1 |
| Base (no MSA, no BAM) | 0.8771 | 0.5635 | ||
| Base + MSA only | ✓ | 0.8677 | 0.5518 | |
| Base + BAM only | ✓ | 0.8786 | 0.5221 | |
| Full (MSA + BAM) | ✓ | ✓ | 0.8709 | 0.5829 |
| Method | Input Type | Avg. Per-Class Acc (%) | Year |
| ST-GCN † | Keypoints | 74.5 | 2018 |
| MS-G3D † | Keypoints | 73.5 | 2020 |
| CTR-GCN † | Keypoints | 71.6 | 2021 |
| STGAT † | Keypoints | 73.9 | 2021 |
| HSTWFormer † [ 38 ] | Keypoints | 76.4 | 2024 |
| MSGL-Transformer (Ours) | Keypoints | 87.1 | N/A |
| Model | Parameters | Time/Epoch (s) |
| TCN | 30,788 | 97 |
| LSTM | 57,604 | 87 |
| Bi-LSTM | 147,972 | 104 |
| MSGL-Transformer (Ours) | 285,892 | 295 |
| Model | RatSI Acc | RatSI F1 | CalMS21 Acc | CalMS21 F1 |
| TCN | 0.7519 | 0.7393 | 0.8486 | 0.8588 |
| LSTM | 0.6929 | 0.7392 | 0.8683 | 0.8696 |
| Bi-LSTM | 0.6865 | 0.7377 | 0.8606 | 0.8638 |
| MSGL-Transformer (Ours) | 0.8148 | 0.7967 | 0.8709 | 0.8745 |