Differentiable Segmentation of Sequences

Erik Scharwächter, Jonathan Lennartz, Emmanuel MüllerICLR 2021

Introduction

Identifying where a data-generating process changes—a task known as sequence segmentation or change point detection—is a fundamental challenge in time-series analysis. This paper introduces a novel method to perform sequence segmentation using standard gradient-based optimization. By relaxing discrete segment boundaries into continuous "warping functions" based on the Two-Sided Power (TSP) distribution, the authors enable the joint training of segmentation boundaries and model parameters directly within modern deep learning frameworks.

The Challenge of Non-Stationary Sequences

Many real-world sequences are non-stationary, meaning their underlying patterns shift over time. Examples include the spread rate of a virus changing after a lockdown or a machine's sensor readings drifting as components wear down. To model these phenomena accurately, researchers use "segmented models" that divide data into distinct regimes separated by change points.

Traditionally, discovering these change points presents a "mixed discrete-continuous" optimization nightmare. The model must simultaneously decide where to cut the sequence (a discrete choice) and what the optimal parameters are for each resulting segment (a continuous choice). Because the discrete "where" component is non-differentiable, standard gradient descent cannot be used. Instead, researchers have historically relied on specialized, rigid algorithms like dynamic programming or greedy searches, which are difficult to integrate with modern neural networks.

A Differentiable Solution: Relaxed Segmented Models

To bridge this gap, the authors propose a relaxed segmented model. Rather than using a "hard" step function that abruptly jumps from one segment to the next, they introduce a "soft" warping function ($\gamma$) that maps time to a continuous segment index.

Illustration of warping functions mapping normalized time to segment indices, demonstrating how continuous curves approximate discrete boundaries.

The core innovation lies in the TSP-based warping function:

  • Two-Sided Power (TSP) Distribution: The authors utilize the cumulative distribution function (CDF) of the TSP distribution to construct these warping paths.
  • Why TSP? Unlike the more commonly used Beta distribution, the TSP distribution features simple closed-form expressions that are computationally efficient. Crucially, it can exactly represent "step-like" functions, allowing the model's soft boundaries to eventually "harden" into distinct, discrete segments during training.
The cumulative distribution function (CDF) of the TSP distribution, providing the differentiable, step-like transitions between segments.
  • Differentiability: Because these warping functions are differentiable almost everywhere, the entire segmentation process can be implemented in standard frameworks like PyTorch, allowing for end-to-end optimization via backpropagation (loss.backward()).
  • Joint Estimation: This relaxation allows the model to learn the segment boundaries (the "when") and the segment-specific parameters (the "what") simultaneously using standard optimizers like Adam.

Key Insights

  • Warping as Segmentation: A major conceptual leap in this work is framing sequence alignment (warping) and sequence segmentation as two sides of the same coin. A warping function that remains flat and then rapidly jumps effectively defines a segment boundary.
  • Regularization via Relaxation: While discrete algorithms (like PELT) are mathematically exact, the authors discovered that continuous relaxation acts as a natural regularizer. It helps prevent the model from converging on "degenerate" segmentations, such as creating segments too small to be statistically meaningful.
  • Versatility: By turning segmentation into a differentiable layer within a computation graph, this approach can be seamlessly combined with any differentiable model, ranging from simple linear regressions to complex deep neural networks.

Experimental Validation

The authors evaluated their TSP-based model (TSPb) across four diverse tasks, demonstrating strong performance and flexibility:

  1. COVID-19 Spread: Modeling daily new cases in Germany using Poisson regression. TSPb matched the performance of specialized statistical baselines but proved significantly more robust, successfully converging even when searching for a high number of segments ($K > 8$) where baseline algorithms failed.
  2. Synthetic Change Point Detection: On a standard benchmark featuring sequences with 10 change points across various distributions, TSPb achieved the lowest Hausdorff distance (measuring the accuracy of detected change points) among methods relying only on mean and variance, even outperforming some specialized dynamic programming techniques.
  3. Concept Drift (Insect Stream Benchmark): In a classification task where the relationship between features and labels changes over time, the model outperformed strong streaming competitors like Adaptive Random Forests (ARF) by precisely identifying when the environmental "concepts" shifted.
  4. Speech Processing (TIMIT Corpus): In a small-scale test on phoneme boundary detection, the model correctly identified 7 out of 9 boundaries in a sample utterance within a 20ms tolerance, showcasing its potential for discrete representation learning.

Limitations and Future Directions

While highly flexible, the approach has a few limitations:

  • The $K$ Problem: The number of segments ($K$) remains a hyperparameter that must be specified in advance. The authors suggest that future work could leverage differentiable architecture search to learn $K$ automatically.
  • Regime Switching: The current formulation treats every segment as entirely unique. If a process reverts to a previous state (e.g., State A $\rightarrow$ State B $\rightarrow$ State A), the model redundantly learns two separate sets of parameters for State A. Integrating a "codebook" or clustering mechanism could enable parameter reuse across non-contiguous segments.
  • Computational Overhead: For very simple models, gradient descent can be slower than highly optimized discrete algorithms. The true advantage of this method lies in its capacity to be embedded within larger, more complex deep learning pipelines where discrete solvers are inapplicable.

Summary updated

BibTeX
@inproceedings{scharwachter2021differentiable,
  author = {Erik Scharwächter and Jonathan Lennartz and Emmanuel Müller},
  title = {{Differentiable Segmentation of Sequences}},
  booktitle = {International Conference on Learning Representations},
  year = {2021},
}
Figure