Nonstationarity is ubiquitous in practical classification settings, leading deployed models to perform poorly even when they generalize well to holdout sets available at training time. We address this by reframing nonstationary classification as time series prediction: rather than predicting from the current input alone, we condition the classifier on a sequence of historical labeled examples that extends beyond the training cutoff. To scale to large sequences, we introduce a learned discrete retrieval mechanism that samples relevant historical examples via input-dependent queries, trained end-to-end with the classifier using a score-based gradient estimator. This enables the full corpus of historical data to remain on an arbitrary filesystem during training and deployment. Experiments on synthetic benchmarks and Amazon Reviews '23 (electronics category) show improved robustness to distribution shift compared to standard classifiers, with VRAM scaling predictably as the length of the historical data sequence increases.
Figures & tables
Figure 1: A diagram illustrating the architecture of our system. We learn input-dependent queries, which are used to sample from a massive corpus of historical data in a manner similar to stochastic hard attention. The input and selected corpus items are then fed to a downstream classifier which predicts the label. Through hard sampling at training time and attention masking, our implementation allows full corpus to stay on an arbitrary filesystem at both training and inference time, facilitating scaling to huge corpora.
Figure 2: Synthetic settings. ( left ) Accuracy vs. time in a nonstationary binary classification setting with rotating decision boundary. Models train on t∈[0,0.5] and test on t∈[0,1]. Our method leverages historical context to mitigate performance degradation beyond the training distribution. ( right ) Training dynamics on a ‘needle in haystack’ task where the label is encoded in one historical item. The system learns to retrieve the correct item after a random exploration phase with duration scaling linearly with the number of items.
Figure 3: Amazon Electronics Reviews. ( left ) Peak VRAM consumption during training vs. hyperparameters. Scaling is consistent with Eqn. 2 . ( right ) Accuracy over time for models trained on pre-2014 data. Our method leverages historical context to mitigate performance degradation on out-of-distribution data beyond 2014.
Appendix figures & tables3 assets
Supplementary material from the paper’s appendix.
Appendix
Figure 4: Additional results in the ‘needle in haystack’ setting. ( left ) Binary cross-entropy classification loss vs. training steps. Loss remains random for some exploration period which scales linearly with the number of historical examples, after which it sharply decreases as the query mechanism learns to retrieve the correct item. ( center ) Cross-entropy loss of the retrieval mechanism over time, when viewing the index of the key-containing historical item as the ‘true label’. This loss decreases at around the same point at which the classification loss decreases. Note that we do not directly train on this objective – the retrieval mechanism learns to select the correct item because this leads to lower classification loss. ( right ) Entropy of the distribution over historical examples from which the retrieval mechanism samples. This sharply increases and then decreases at around the time the classification loss decreases.
Figure 5: Diagram of a Perceiver block ( Jaegle et al., 2021 ) . Rather than attending directly to the full input sequence like a standard transformer, Perceivers use cross-attention to combine the input with a learned data-independent ‘latent’ vector. They then apply a sequence of standard transformer blocks to this sequence. This approach reduces the computational cost from L2 to LM where L is the input sequence length and M is the latent sequence length (a hyperparameter). The Perceiver architecture is appealing for our use case because it was proposed with multimodal feature fusion in mind, and because it is more-scalable to long sequences than standard transformers.
Figure 6: Accuracy over time for models trained on pre-2014 data from the electronics category of Amazon Reviews ’23. ( left ) Our retrieval mechanism returns full historical examples (Xt−m,Yt−m). ( right ) Our retrieval mechanism returns only the labels Yt−m of historical examples. In the former case our system has similar robustness to a standard classifier, while in the latter case it is able to leverage historical context to mitigate performance degradation on the out-of-distribution data beyond 2014.