All models

AnomalyTransformer official

A Transformer that flags time-series anomalies by how little a point associates with the rest of the series.

Time series · 159 operations Checked

100%

Showing the top corner; full diagram not loaded yetShowing a small copy; full diagram not loaded yetLarge diagram, not loaded yet

Open SVG

Loading diagram (29 KB)

Open in a new tab

Click or tap a spot to read it up close. Scroll or drag inside the diagram to move through it. Zoom with + and − or Ctrl and scroll. Press 0 for the whole graph. Swipe inside the diagram to move through it. Use + and − to zoom.

At a glance

Parameters
4.8M
Operations
159
Framework
PyTorch
Recurrent
No
Published
ICLR 2022
Cited by
1,319 (as of 17 October 2026)
Authors
Jiehui Xu, Haixu Wu, Jianmin Wang, Mingsheng Long
License
MIT
Checked
Passed: the trace was replayed operation by operation and matched the model's own output for this input.

Files

The diagram is a drawing of a TorchLens trace of the source code. It contains no code or weights.

Details
Stable ID
m105
Graph hash
88b77c29862b64097a90a3a2666162299c3a575deacf5e2ad7517cdadcbb137e
Skeleton hash
898369f825645a2699a98173065746aefa10dbcfa66c0d339538c5e6f8ea0832
Architecture hash
aff84ff410f383682c89af07764390a83d62b51fe70dc3db385125e4b402acb7
Diagram SHA-256
0c9da8ba225a6b0e850205ebcf5c72c80f0d621becff22b132df00202b9c3b78
TorchLens version
2.36.0
Renderer
graphviz 2.43.0+pyvips 3.2.0+libvips 8.18.7+render-opts@06c1f0d3
Check
Forward pass replayed in PyTorch

What it is

Anomaly Transformer is a Transformer for finding abnormal time points in multivariate time series without labels, the unsupervised setting the authors focus on. The motivating data are the successive sensor measurements that real-world systems such as industrial equipment and space probes generate. The key observation is that anomalies are rare, so an abnormal point struggles to build meaningful associations with the whole series and its attention concentrates on its neighbours. The paper turns that gap into a score called the Association Discrepancy, the distance between each point's prior-association and its series-association.

To compute it, the model replaces ordinary self-attention with Anomaly-Attention, a two-branch block that models the prior-association and the series-association of each time point at once. The prior branch is a learnable Gaussian kernel over relative temporal distance, so it naturally favours the adjacent horizon, while the series branch is the usual attention learned from the raw series. The discrepancy itself is the symmetrized KL divergence between the two association distributions, averaged over layers. Training uses a reconstruction loss plus a minimax game, in which the prior is pulled toward the series-association in one phase and the series-association is pushed to enlarge the discrepancy in the other. At test time the anomaly score combines the discrepancy with the pointwise reconstruction error, so the two signals collaborate.

The paper's model, and the official implementation traced here, has 3 layers, 512 hidden channels and 8 attention heads. Inputs are non-overlapping sliding windows with a fixed size of 100 for all datasets. It was evaluated on six unsupervised benchmarks spanning service monitoring, space and earth exploration, and water treatment. The paper compares against 18 baselines, naming InterFusion and THOC as the state-of-the-art deep models. Evaluation uses the point-adjustment convention, under which detecting any point in an abnormal segment counts the whole segment as found. The paper appeared at ICLR 2022, where the repository notes it was a Spotlight.

Key idea. Anomaly-Attention, a two-branch attention that models a Gaussian prior-association alongside the learned series-association so that their discrepancy becomes an inherently distinguishable anomaly criterion, sharpened by minimax training.

  • anomaly transformer
  • anomaly-attention
  • association discrepancy
  • time series anomaly detection
  • unsupervised anomaly detection
  • multivariate time series
  • thuml
  • smd
  • msl
  • smap
  • psm
  • swat
  • minimax

AI-written summary, based on the paper and checked automatically against it; not reviewed by a person. Corrections welcome.

Cite the paper

@misc{xu2022anomalytransformertimeseries,
      title={Anomaly Transformer: Time Series Anomaly Detection with Association Discrepancy}, 
      author={Jiehui Xu and Haixu Wu and Jianmin Wang and Mingsheng Long},
      year={2022},
      eprint={2110.02642},
      archivePrefix={arXiv},
      primaryClass={cs.LG},
      url={https://arxiv.org/abs/2110.02642}, 
}