When a twelve-lead electrocardiogram is written as text for a large language model, the number of tokens has to be balanced against the information lost through compression. This paper presents a deterministic encoding that writes eight independent leads as amplitude letters and exact time gaps and recovers the remaining four limb leads algebraically. The key points are selected with a cardiac-cycle-dependent tolerance, the amplitudes are parameterized by a 26-letter logarithmic codebook learned from a training set, and a 10-step tolerance schedule keeps all records within a fixed token budget. The encoding was applied to 21,388 records from the public PTB-XL database and evaluated using an exact decode-and-re-encode round trip, waveform reconstruction error, and a paired comparison of convolutional classifiers trained with 5 different seeds on signals from the original and decoded databases. All records were contained in 4,080 tokens (average: 2,866 tokens, 64.3% fewer than a per-sample transcription), and all stored lead strings were exactly reproduced. The average correlation between the decoded and reference signals was 0.982. The macro-averaged area under the receiver operating characteristic curve was 0.9167 for the reference signals and 0.9157 for the decoded signals (paired difference -0.0010; 95% patient-level bootstrap interval, -0.0028 to 0.0007), within the pre-specified non-inferiority margin of -0.010; this is not a confirmatory result, because the test fold had been used during encoder development. The diagnostic content of a compact text can therefore be preserved, while the language model's ability to read the text is yet another matter.
Figures & tables
Approach
Studies
Input to the language model
Meaning of symbols
Waveform recoverable from the input
Encoder alignment
[ 2 , 3 , 12 ]
Continuous embeddings
No symbols
No
Generic symbolic time series
[ 13 , 14 ]
Symbols for aggregates or linear pieces
Value bins or clustered pieces
Approximately
Learned ECG vocabularies
[ 4 , 6 , 15 ]
Learned tokens or codes
Learned from data
Depends on the codebook
Fixed ECG alphabet
[ 5 ]
Amplitude and time letters, 12 leads
Amplitude and duration bins
Approximately; time quantized
ECG-26c (this paper)
–
Amplitude letters and exact gaps, 8 leads, ≤ 4,080 tokens
μ -law bins in mV; exact sample counts
Approximately; key-point times exact
TABLE I: Comparison of related studies and the positioning of this paper.
Fig. 1: Encoder (top) and decoder (bottom) of ECG-26c. The tolerance level k starts at 0 and increases only when the serialized text exceeds the token budget; decoding requires the frozen codebook and the format conventions but no learned model.
Design element
ECG-aBcDe
ECG-26c
Sampling rate
Resampled to 250 Hz
100 Hz (PTB-XL records100)
Leads written
All 12
I, II and V1–V6; the other four rebuilt with Eq. ( 1 )
Key-point selection
ℓ 1 trend filtering
RDP with a cycle-dependent tolerance
Amplitude letters a–z
24 equal-width bins between the 1st and 99th training percentiles, plus 2 open outer bins
μ -law bins ( μ = 20) between the 0.05th and 99.95th training percentiles; a–m ≤ 0 mV < n–z
Decoded amplitude
Upper bound of the bin
Mean of the training key points in the bin
Very large amplitudes
Absorbed by the outer letters
Lead written at half or quarter scale (x2, x4)
TABLE II: Design comparison between ECG-aBcDe [ 5 ] and ECG-26c.
Fig. 2: The 26-letter amplitude partition, with alternating hatching. (a) Full range; the outer bins a and z extend beyond the plotted range. (b) Close-up of the bins near zero, where they are narrowest. The dotted line marks 0 mV.
Point
Sample
Input (mV)
Letter
Decoded (mV)
Gap
Time letter
1
0
0.025
n
0.018
10
J
2
10
0.101
p
0.110
1
–
3
11
0.144
q
0.177
3
C
4
14
− 0.001
m
− 0.024
5
E
5
19
− 0.009
m
− 0.024
1
–
6
20
0.016
n
0.018
2
B
TABLE III: Worked example: the first twelve key points of lead II in PTB-XL record 1. Every key point contributes its amplitude letter and then the time letter of the following gap, which is omitted when the next key point is one sample away.
Fig. 3: Filtered input (solid) and decoded (dashed) amplitudes of the key points in Table 3, covering 0–280 ms. Connecting lines only guide the eye; the example illustrates quantization and is not a diagnostic validation.
Fig. 4: The first four seconds of leads II and V2 in PTB-XL record 1: filtered reference (solid line) and signal decoded from ECG-26c text (dashed line).
Metric
Reference
Decoded
Paired Δ [95% interval]
Macro-AUROC (primary)
0.9167 ± 0.0014
0.9157 ± 0.0010
− 0.0010 [ − 0.0028, 0.0007]
Micro-AUROC
0.9281 ± 0.0027
0.9253 ± 0.0015
− 0.0029 [ − 0.0044, − 0.0013]
Macro-AP
0.8025 ± 0.0044
0.8026 ± 0.0033
0.0001 [ − 0.0036, 0.0039]
Macro-F1
0.7304 ± 0.0027
0.7276 ± 0.0029
− 0.0027 [ − 0.0081, 0.0026]
AUROC, NORM
0.9393 ± 0.0041
0.9408 ± 0.0028
0.0015 [ − 0.0006, 0.0036]
AUROC, MI
0.9115 ± 0.0074
0.9074 ± 0.0024
− 0.0041 [ − 0.0081, − 0.0002]
TABLE IV: Test-fold metrics of the CNN (mean ± SD over five seeds; thresholds selected on the validation fold) and paired differences with 95% patient-cluster bootstrap intervals. The higher mean in each row is shown in bold.
Variant
Mean tokens
Max tokens
Saving
Median PRDN (%) 12 / 8 / 4 leads
Δ macro-AUROC [95% interval]
Quantization only
8,029
8,043
0%
11.7 / 10.6 / 18.7
− 0.0007 [ − 0.0023, 0.0009]
Uniform 0.02 mV
3,611
7,728
55.0%
11.4 / 10.4 / 18.2
− 0.0020 [ − 0.0040, 0.0000]
Level 0 (fixed)
2,912
7,462
63.7%
12.7 / 11.4 / 20.5
0.0000 [ − 0.0016, 0.0016]
ECG-26c (final)
2,866
4,080
64.3%
12.7 / 11.4 / 20.6
− 0.0010 [ − 0.0028, 0.0007]
Level 3 (fixed)
2,177
6,702
72.9%
16.1 / 14.4 / 26.0
− 0.0002 [ − 0.0021, 0.0016]
Level 6 (fixed)
1,637
5,372
79.6%
25.3 / 22.3 / 42.1
− 0.0042 [ − 0.0067, − 0.0017]
TABLE V: Compression, reconstruction, and paired diagnostic change for each encoding variant. Token and PRDN values cover all 21,388 records; Δ macro-AUROC refers to the test fold, with 95% patient-cluster bootstrap intervals. Savings are relative to quantization only.
Fig. 5: Compression trade-off on the test fold. (a) Median PRDN over the twelve leads. (b) Mean paired change in macro-AUROC with 95% patient-cluster bootstrap intervals. The filled marker denotes the final ECG-26c encoding, and the dashed line marks the analytic margin of − 0.010.
ECG-Language Models (ELMs) extend recent advances in Multimodal Large Language Models (MLLMs) to automated ECG interpretation. However, most existing ELMs inherit Vision-Language Model (VLM) design choices and rely on pretrained ECG encoders, introducing substantial architectural and training complexity. Inspired by encoder-free VLMs, we introduce ELF, a family of three encoder-free ELMs that remain competitive with, and often outperform, prior state-of-the-art ELMs across two datasets despite substantially simpler architectures and training pipelines. All code and data are available at github.com/ELM-Research/ECG-Language-Models.
William Han, Tony Chen, Chaojing Duan +6
Carnegie Mellon University, USA · Allegheny Health Network, USA · University of California, Los Angeles, USA +1
The electrocardiogram (ECG) records cardiac electrical activity across multiple leads and is used for detecting cardiac abnormalities. Recent ECG-language models enable large language models (LLMs) to interpret cardiac signals and answer clinically relevant questions. However, existing ECG-language models typically encode the ECG independently of the clinical question, forcing the ECG representation to retain broad and potentially irrelevant signal information. Moreover, these models often aggregate information across leads which can obscure lead-specific details needed for a particular question. To tackle these limitations, we introduce LEAP-LLM, an ECG-LLM architecture for Lead-aware ECG Alignment with Prompt conditioning. LEAP-LLM uses the clinical question to guide ECG feature extraction while preserving explicit lead and temporal structure. Task-trained instruction representations distill information from the question and guide two complementary branches. The Lead branch captures question-relevant temporal patterns within each ECG lead, while the Temporal branch summarizes relevant information across leads at each temporal position. Together, they provide the LLM with compact, question-relevant ECG information while preserving lead and temporal structure. LEAP-LLM reduces modality-token count by 89.0% and prefill FLOPs by 7.2x on average relative to other ECG-LLMs baselines. Across four ECG benchmarks, LEAP-LLM achieves better performance, including a 3.4-percentage-point improvement in G12EC over the strongest prior ECG-specific method. We further show that the model adaptively emphasizes the clinically relevant anatomical lead groups for different cardiac abnormalities, with lead importance patterns consistent with established diagnostic knowledge, providing interpretable evidence that the predictions are supported by clinically meaningful ECG structure.
Transformer-based electrocardiogram (ECG) models commonly tokenize waveforms into fixed temporal patches. Though convenient, fixed patching can split heartbeat structures across token boundaries. We study beat-synchronous tokenization as a physiologically grounded alternative, comparing fixed patches with three beat-aligned strategies: resampled beats, adaptive pooled beats, and resampled beats augmented with R--R interval information. Experiments span two settings: 10-second 12-lead diagnostic classification on PTB-XL after MIMIC-IV-ECG masked pretraining, and 60-second single-lead rhythm classification on Icentia11k after patient-level contrastive pretraining. On PTB-XL, resampled beat tokens achieve the highest mean macro Area Under the ROC Curve (AUROC; 0.8945) and nearly match the best fixed-patch macro Area Under the Precision-Recall Curve (AUPRC; 0.7414), reducing average sequence length from 100 to 11.2 tokens. On Icentia11k, beat-synchronous tokenizers obtain comparable AUPRC to fixed patching with better stability across runs. These results suggest morphology-preserving beat tokenization is a compact, competitive alternative to fixed temporal patching.
Ahmed Sameh, Nolan Wilson, Max Enderlein +1
Computer Science & Engineering, University of Minnesota Twin Cities, Minneapolis, MN 55455, USA.