Reading 12-lead ECGs with LFM3-1.7B
Nov 24, 2026
OpenTSLM turns a language model into a time-series reader. The signal is encoded into tokens the model can attend to, interleaved with text, and the model answers questions about it with a step-by-step rationale. The published models use Llama-3.2 (1B and 3B) and Gemma-3 backbones, either as a soft prompt or through Flamingo-style cross-attention.
Over a weekend I rebuilt the soft-prompt variant on LFM3-1.7B-Base, with Amazon's Chronos-2 encoder reading every ECG lead at the full 500 Hz. It beats every published OpenTSLM model on macro-F1 across all four benchmarks, matches the most accurate published ECG model (Flamingo on Llama-3.2-3B) with greedy decoding while running twice as fast on a MacBook, and surpasses every published model on accuracy with 8-sample majority voting. Below are real ECG test cases with the model's unedited output.
Results
On ECG-QA-CoT (41,093 test questions over 3,207 recordings), single-pass greedy accuracy is 45.93% against 46.25% for the most accurate published model (Flamingo on Llama-3.2-3B). With a majority vote over 8 sampled rationales (temperature 0.6, chosen on validation), accuracy reaches 48.37% (+2.12 points over every published model) and macro-F1 reaches 46.01 (40.75 support-weighted), at the cost of 8 generations instead of greedy decoding. Accuracy on the other tasks: TSQA 99.88%, HAR-CoT 73.83% (previous best 72.20%) and Sleep-CoT 87.74% (81.08%). The previous best macro-F1 comes from Flamingo with Chronos-2 on TSQA, HAR-CoT (Llama-3.2-3B) and ECG-QA-CoT (Llama-3.2-1B), and the 1B soft-prompt model on Sleep-CoT. Two scoring notes: ECG macro-F1 above is the unweighted per-template average from the paper's scorer (the support-weighted variant is 38.88 greedy / 40.75 majority-of-8, and the paper does not state which one it reports); and on Sleep-CoT the EEG prompt reports amplitude in microvolts instead of volts rounded to 4 decimals (the stock prompt prints std 0.0001, erasing the amplitude cue).
Why LFM3
- 3B-class quality at 1.7B. In a first run with the paper's own recipe, its small CNN encoder at 100 Hz, LFM3-1.7B already matched the paper's Llama-3.2-3B soft-prompt model on ECG (36.8% vs 36.3% accuracy) at about half the size, trained on a quarter of the ECG data.
- Twice as fast as the most accurate baseline. The most accurate published model, Flamingo on Llama-3.2-3B, carries 2.2B parameters of cross-attention that run on every generated token. LFM3 generates a token in 19 ms, against 47 ms for Flamingo and 30 ms for the Llama-3.2-3B soft-prompt model, and needs 5.1 GB of memory against 11.9 GB.
- A short prompt, even at 500 Hz. Twelve leads at 500 Hz take about 2,400 tokens with merged Chronos-2 patches, against 3,500 for the paper's soft-prompt models at 100 Hz.
The 1B Llama models are faster still, but they are 7 to 10 points less accurate on ECG.
What moved the needle
Most of the ECG gain over the paper came from the encoder, the full-resolution signal and more training data. LFM3's part is delivering that at 1.7B parameters and laptop speed. Reinforcement learning (GRPO with a verifiable answer reward) on top of supervised fine-tuning did not improve validation accuracy: at a low learning rate it only sharpened answers the model already gave, and at a higher one it lost diversity.
Does LFM3 need the encoder?
To see what Chronos-2 contributes, I removed it: each 16-sample window of the raw signal passes through a per-patch linear layer and the same MLP projector straight into LFM3, with no mixing across patches or leads before the language model. Reading raw patches requires more capacity in the LLM itself (LoRA rank 256 from stage 1, instead of rank 16 from stage 3). Trained with the same curriculum on TSQA, HAR-CoT and Sleep-CoT, this encoder-free model still beats every published Sleep model and lands within 1 to 2 F1 of the best published results on TSQA and HAR-CoT; a separate shorter ECG run from plain LFM3-1.7B-Base (32-sample patches, 1.5 passes) lands within 3 F1 of the best published ECG score. On an equal short ECG budget from scratch, encoder-free even slightly beat Chronos-2 (34.4 vs 33.4 F1). With longer training the pretrained encoder pulls ahead by 1 to 5.3 F1, which is why the main model keeps it.
How it works
- Each lead (10 s, 5,000 samples) goes through Chronos-2 in 16-sample patches. The 12 leads of a recording attend to each other inside the encoder.
- Pairs of patch embeddings are concatenated and projected by an MLP into the language model's embedding space: 158 soft tokens per lead (157 merged pairs plus Chronos-2's summary token).
- The prompt interleaves text and ECG tokens, then the model writes its reasoning and ends with an answer:
You are an expert cardiologist analyzing an ECG. Clinical Context: ... Question: ...
This is ECG Lead I, it has mean -0.0043 and std 0.0784: <158 ECG tokens>
...
This is ECG Lead V6, it has mean 0.0021 and std 0.0912: <158 ECG tokens>
Select your answer from the following options: ... You MUST end your response with "Answer: "
- LFM3-1.7B-Base is fine-tuned with LoRA (rank 16 on attention, short-conv projections and MLPs, enabled from the CoT stages); the projector is trained throughout and Chronos-2 is unfrozen for the 500 Hz ECG stage. Training follows the OpenTSLM curriculum (TSQA, M4 captioning, HAR, Sleep, then ECG) on AWS L40S GPUs, and full-test ECG evaluation runs with vLLM.
Caveats
- The training rationales were written by GPT-4o, so the model learned to explain a label more than to derive it; read the reasoning as an explanation of the choice.
- The released ECG prompts contain inaccurate clinical context (patient sex, artifact and pacemaker fields; see TimeNet #612). I kept them to compare with the paper on the same inputs, and the model often repeats those claims (including mentioning a pacemaker when none is present).
- The speed numbers use the real pretrained language models and Chronos-2, with random weights for the projectors, adapters and cross-attention layers, which does not change timing.
- This is a research demo, not a medical device.
Try it
The model is on Hugging Face at nathanrchn/OpenTSLM-LFM3-1.7B-ECG and runs on a laptop:
# pip install torch transformers chronos-forecasting huggingface_hub wfdb
import sys, wfdb
from huggingface_hub import snapshot_download
path = snapshot_download("nathanrchn/OpenTSLM-LFM3-1.7B-ECG")
sys.path.append(path)
from inference import EcgReader
reader = EcgReader(path)
# a PTB-XL recording: 10 s, 12 leads, 500 Hz, millivolts
ecg = wfdb.rdrecord("09879_hr", pn_dir="ptb-xl/1.0.3/records500/09000").p_signal
out = reader.ask(
ecg,
"Which rhythm-related symptom does this ECG show, "
"sinus tachycardia or atrial fibrillation?",
options=["sinus tachycardia", "atrial fibrillation"],
)
print(out["answer"]) # atrial fibrillation
print(out["rationale"])
Code and training scripts: github.com/nathanrchn/OpenTSLM.