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

Medformer: A Multi-Granularity Patching Transformer for Medical Time-Series Classification

Yihe Wang, Nan Huang, Taida Li, Yujun Yan, Xiang Zhang

TL;DR

Medformer is a specialized Transformer architecture designed to tackle the unique complexities of medical time-series (MedTS) data, such as EEG and ECG. By introducing cross-channel patching and a novel two-stage multi-granularity attention mechanism, it effectively captures both inter-channel correlations and multi-scale temporal patterns, outperforming 10 state-of-the-art baselines in challenging real-world diagnostic scenarios.

The Challenge of Medical Time-Series

Medical time-series data is notoriously difficult to classify. Unlike general time series, signals like Electroencephalography (EEG) and Electrocardiography (ECG) possess two critical characteristics:

  1. Inter-channel Correlations: Brain and heart regions function as cohesive units. An abnormality in one lead often correlates with patterns in others.
  2. Multi-scale Temporal Patterns: Physiological "biomarkers" often hide within specific frequency bands (like alpha or gamma waves in the brain).

Existing Transformer models often fall short because they either treat channels independently, use single-timestamp tokens that miss local dynamics, or rely on fixed-length patches that fail to capture features across different scales.

Conceptual comparison of Medformer against standard Transformer variants in medical time-series processing.

Furthermore, most models struggle with subject-independent classification—the ability to diagnose a new patient whose data was never seen during training—due to the high level of "personal noise" in physiological signals.

Methodology: The Medformer Architecture

Medformer departs from standard Transformer designs through three key innovations designed to address the spatial and temporal nuances of medical data:

  • Cross-Channel Patching: Instead of patching one channel at a time, Medformer creates patches that span across all channels simultaneously. This allows the model to learn spatial-temporal dependencies right at the embedding layer.
  • Multi-Granularity Embedding: Rather than using a single patch length, the model employs a list of different patch lengths (e.g., 2, 4, 8, 16, and 32 timestamps) in parallel. This simulates looking at the data through different "frequency filters" to capture both fine-grained and coarse-grained patterns.
  • Two-Stage Multi-Granularity Self-Attention: To keep computational costs manageable while allowing different scales to "talk" to each other, the authors propose a router-based mechanism. First, Intra-granularity attention is performed within each scale, using a "router" token to summarize information. Second, Inter-granularity attention allows these routers to exchange information across different scales.
The Medformer architecture, featuring cross-channel multi-granularity patch embedding and two-stage self-attention.

Experimental Setup and Datasets

The model was evaluated on five diverse, public medical datasets covering both EEG and ECG modalities:

  • APAVA & ADFTD: EEG datasets for Alzheimer’s disease and Frontotemporal Dementia.
  • TDBrain: EEG data for Parkinson’s disease detection.
  • PTB & PTB-XL: ECG datasets for diagnosing Myocardial Infarction and various other heart conditions.

Key Insights

  • The "Connectome" Matters: The success of cross-channel patching confirms that for medical data, the relationship between sensors (spatial) is just as important as the sequence of data (temporal).
  • Implicit Frequency Analysis: By using multi-granularity patches, Medformer effectively performs a learned version of traditional frequency band analysis without needing handcrafted signal processing filters.
  • Efficiency through Routers: Attending to every patch across every scale would be computationally explosive. The router mechanism acts as an "ambassador" for each scale, reducing complexity to $O(T^2)$, making it as efficient as a standard Transformer while being much more expressive.
  • The Subject-Independent Gap: The paper highlights a massive performance gap between subject-dependent (easy) and subject-independent (hard) setups. For example, on the ADFTD dataset, F1 scores dropped from ~97% to ~50% across models, underscoring the difficulty of generalizing across different human bodies.

Results and Performance

Medformer achieved the top averaged ranking across all five datasets and six evaluation metrics (Accuracy, Precision, Recall, F1, AUROC, and AUPRC). In the most challenging subject-independent setup, Medformer secured 15 top-1 and 30 top-3 rankings out of 30 total evaluations against 10 baselines, including specialized models like PatchTST, iTransformer, and Crossformer.

Limitations and Future Work

While powerful, Medformer's performance is sensitive to the choice of patch lengths, which currently requires manual tuning. Additionally, while it handles subject-independent tasks better than its peers, it lacks an explicit mechanism to disentangle disease features from individual-specific physiological noise. Future research will focus on automating patch length selection and developing modules for subject-invariant feature learning.

Summary updated

BibTeX
@inproceedings{wang2024medformer,
  author = {Yihe Wang and Nan Huang and Taida Li and Yujun Yan and Xiang Zhang},
  title = {{Medformer: A Multi-Granularity Patching Transformer for Medical Time-Series Classification}},
  booktitle = {Advances in Neural Information Processing Systems},
  year = {2024},
  url = {https://openreview.net/forum?id=jfkid2HwNr},
}
Figure