Semi-supervised sequence modeling for improved behavioral segmentation

Matthew R Whiteway, Evan Schaffer, Anqi Wu, E. Kelly Buchanan, Omer Fahri Onder, Neeli Mishra, Liam PaninskibioRxiv 2021

Abstract: A popular approach to quantifying animal behavior from video data is through discrete behavioral segmentation, wherein video frames are labeled as containing one or more behavior classes such as walking or grooming. Sequence models learn to map behavioral features extracted from video frames to discrete behaviors, and both supervised and unsupervised methods are common. However, each approach has its drawbacks: supervised models require a time-consuming annotation step where humans must hand label the desired behaviors; unsupervised models may fail to accurately segment particular behaviors of interest. We introduce a semi-supervised approach that addresses these challenges by constructing a sequence model loss function with (1) a standard supervised loss that classifies a sparse set of hand labels; (2) a weakly supervised loss that classifies a set of easy-to-compute heuristic labels; and (3) a self-supervised loss that predicts the evolution of the behavioral features. With this approach, we show that a large number of unlabeled frames can improve supervised segmentation in the regime of sparse hand labels and also show that a small number of hand labeled frames can increase the precision of unsupervised segmentation.

Introduction

Quantifying animal behavior from video data is a cornerstone of modern neuroscience and ethology. A common approach is discrete behavioral segmentation, where each video frame is assigned a label corresponding to a specific action, such as walking, grooming, or resting. Currently, researchers typically choose between two paradigms: supervised learning, which is highly accurate but requires labor-intensive manual labeling, and unsupervised learning, which scales easily but often fails to isolate specific behaviors of interest with high precision.

This paper introduces a semi-supervised framework designed to bridge this gap, particularly in scenarios where researchers only have the resources to hand-label a tiny fraction (e.g., ~1%) of their data.

Methods

The proposed framework utilizes a sequence modeling approach that integrates three distinct types of supervision into a single loss function. The model architecture consists of an Encoder that maps high-dimensional pose features into a low-dimensional behavioral embedding ($z_t$), a Classifier for behavior prediction, and a Predictor for forecasting future states.

The semi-supervised framework combines a standard supervised loss for sparse hand labels, a weakly supervised loss for dense heuristic labels, and a self-supervised loss for predicting future behavioral features.

The total loss function is a weighted sum of three components:

  1. Standard Supervised Loss ($L_{super}$): Applied only to the sparse set of expert-provided hand labels.
  2. Weakly Supervised Loss ($L_{heur}$): Applied to "heuristic labels" generated by simple, rule-based algorithms (e.g., thresholding limb velocity to identify walking). These are noisy but available for every frame.
  3. Self-Supervised Loss ($L_{pred}$): A predictive loss where the model attempts to forecast the behavioral features at time $t+1$ from the embedding at time $t$. This forces the model to learn the underlying temporal dynamics of behavior from unlabeled data.

Experimental Setup

The researchers validated their approach using a dataset of head-fixed fruit flies (Drosophila melanogaster) recorded while walking on an air-supported ball. Pose features were extracted for eight body parts (limbs and head) using Deep Graph Pose. The dataset comprised 10 videos ranging from 10 to 34 minutes, with only approximately 1.1% of total frames manually labeled for four initial behaviors: Still, Walk, Front Groom, and Back Groom.

Key Results and Discussion

The integration of weak and self-supervision led to substantial improvements in classification performance. As shown in the results, increasing the weights of the heuristic ($\lambda_h$) and predictive ($\lambda_p$) penalties significantly boosted F1 scores compared to a purely supervised baseline (where $\lambda_h=0, \lambda_p=0$).

Heatmap showing the impact of heuristic label penalty (lambda_h) and prediction penalty (lambda_p) on F1 scores. Performance improves significantly as these semi-supervised components are introduced.

Key insights from the study include:

  • Heuristics as "Good Enough" Teachers: Even imperfect heuristic rules provide a massive training signal that helps the model generalize far better than sparse hand labels alone. For example, in the "Still" category, F1 scores jumped from ~0.6 to over 0.9.
  • Dynamics as a Regularizer: By forcing the model to predict the next frame, the internal representation is forced to capture the temporal structure of movement. This prevents the model from over-fitting to the static poses found in the few hand-labeled frames.
  • The Discovery Loop: The semi-supervised embedding space naturally clusters unlabeled behaviors. The authors found that their model identified a cluster for "Abdomen movement" that was not in the original label set. By identifying this cluster and hand-labeling a few examples, they could iteratively refine the model to recognize new behaviors.

While the method relies on the ability to define simple rules for behaviors of interest, it offers a robust path forward for behavioral analysis in the "small data" regime, significantly reducing the human effort required for high-precision segmentation.

Summary updated

BibTeX
@misc{whiteway2021semi,
  author = {Matthew R Whiteway and Evan Schaffer and Anqi Wu and E. Kelly Buchanan and Omer Fahri Onder and Neeli Mishra and Liam Paninski},
  title = {{Semi-supervised sequence modeling for improved behavioral segmentation}},
  year = {2021},
  doi = {10.1101/2021.06.16.448685},
  howpublished = {bioRxiv},
}
Figure