An Explainable, Demographic-Aware ECG Transformer for Atrial Fibrillation Detection
Matteo Zannini, Hagen Malberg, Martin SchmidtAbstract
Deep learning models have demonstrated strong performance in electrocardiogram (ECG)-based cardiovascular disease detection, but face the challenge of systematic variation across individual patients. Patient-specific information, a cornerstone of precision medicine, may help models account for this variability, yet its integration into ECG analysis remains underexplored. We present a transformer architecture with cross-attention-based metadata conditioning for atrial fibrillation (AF) detection from single-lead ECGs, trained on a large classbalanced dataset including 77,261 patients. A systematic ablation study evaluated four metadata configurations including age, sex, ethnicity and AF-associated risk factors. All configurations achieved F1 scores between 96.7% and 96.8% on the held-out test set and between 92.7% and 93.4% on an independent multi-source dataset, confirming competitive performance and strong cross-dataset generalisation. Post-hoc explainability analysis revealed that age is the dominant demographic feature, while sex and ethnicity showed negligible contribution. QRS complexes and fibrillatory T-Q intervals were found to be the most highlighted segments, aligning with established clinical markers of AF. These findings provide a quantitative basis for evaluating when demographic conditioning is clinically justified, and establish an interpretable baseline for future patient-specific adaptive models.