NeurIPS 2026Coming to NeurIPS?Explore papers, orals & directions

A kernel Stein test of goodness of fit for sequential models

Jerome Baum, Heishiro Kanagawa, Arthur Gretton

Abstract

We propose a goodness-of-fit measure for probability densities modeling observations with varying dimensionality, such as text documents of differing lengths or variable-length sequences. The proposed measure is an instance of the kernel Stein discrepancy (KSD), which has been used to construct goodness-of-fit tests for unnormalized densities. The KSD is defined by its Stein operator: current operators used in testing apply to fixed-dimensional spaces. As our main contribution, we extend the KSD to the variable-dimension setting by identifying appropriate Stein operators, and propose a novel KSD goodness-of-fit test. As with the previous variants, the proposed KSD does not require the density to be normalized, allowing the evaluation of a large class of models. Our test is shown to perform well in practice on discrete sequential data benchmarks.

Introduction

In machine learning, "goodness-of-fit" tests are essential for determining if a set of data actually originates from a specific probabilistic model. While standard tests work well for fixed-dimensional data (e.g., vectors of a constant size), real-world sequential data—such as text documents, user clickstreams, or genomic sequences—frequently vary in length.

Traditional methods like the Maximum Mean Discrepancy (MMD) are "model-blind," comparing samples without considering the internal structure of the model being tested, which often leads to sample inefficiency. Conversely, likelihood-based tests require "normalized" models where all probabilities sum to one. This requirement is computationally prohibitive for many sophisticated generative models, such as Markov Random Fields (MRFs) or large-scale language models. This paper bridges this gap by introducing a test that is both model-aware and normalization-independent for variable-length sequences.

Methodology: Extending KSD to Variable Dimensions

The researchers built their test on the Zanella-Stein (ZS) operator. The core idea of a Stein operator is to create a function that has an expected value of zero if the data perfectly matches the model.

The key technical innovation is the design of a neighborhood structure for variable-length sequences. To apply the Stein operator to a discrete set of sequences, one needs a way to "jump" from one sequence to a similar one. The authors propose the J-location modification neighborhood, which allows for:

  1. Insertions: Adding a symbol.
  2. Deletions: Removing a symbol.
  3. Substitutions: Swapping a symbol.

By examining modifications across $J$ positions from the end of a sequence, the test captures dependencies within the data. These operators are combined with Reproducing Kernel Hilbert Spaces (RKHS) to derive a computable test statistic. To determine statistical significance, the authors employ parametric and wild bootstrapping to simulate the null distribution.

Key Results and Insights

Superior Power and Model Awareness

Unlike MMD, which only compares samples, the KSD "interrogates" the model's probability ratios. This allows the test to detect subtle discrepancies that sample-only tests would miss. In perturbed random walk experiments, the KSD test significantly outperformed MMD and non-oracle likelihood ratio tests, particularly when perturbations were subtle.

Comparison of test power (estimated rejection rate) against holding probability $p_{\text{hold}}$ in a perturbed random walk. KSD significantly outperforms the model-blind MMD.

Evidence Accumulation

A critical advantage of the proposed KSD is its ability to "harvest" information from every transition in a sequence. Consequently, the test becomes more powerful as the sequences get longer, effectively treating each transition as a data point rather than viewing the entire sequence as a single observation.

The effect of sequence length on test power. As the expected sequence length $\lambda$ increases, KSD (green) accumulates more evidence and achieves higher rejection rates compared to MMD (orange).

Efficiency on Intractable Models

On intractable Markov Random Fields, where the normalization constant is unknown, the KSD test proved much more sample-efficient than MMD. For instance, with a sample size of 700, KSD achieved nearly a 100% detection rate of model mismatch, while MMD lagged significantly. The test also successfully validated conditional distributions of the GPT-2 language model, demonstrating its utility for modern NLP tasks.

Limitations and Future Work

While powerful, the current neighborhood structure is less sensitive to changes in the length distribution itself. If a model predicts content correctly but fails on sequence length, the KSD test might not reject it; the authors suggest pairing it with classical length-distribution tests. Additionally, the computational cost scales with the neighborhood size and alphabet, presenting an opportunity for future research into sparsification. Finally, automating the selection of optimal "sequence kernels" remains an open challenge.

Summary updated

BibTeX
@inproceedings{baum2023kernel,
  author = {Jerome Baum and Heishiro Kanagawa and Arthur Gretton},
  title = {{A kernel Stein test of goodness of fit for sequential models}},
  booktitle = {International Conference on Machine Learning},
  year = {2023},
  url = {https://openreview.net/forum?id=XxMRhjbDGq},
}
Figure