leochen085 commited on
Commit
cacfe76
·
verified ·
1 Parent(s): 7d2676c

Update card, add dataloader

Browse files
Files changed (2) hide show
  1. README.md +75 -157
  2. lapras_dataloader.py +48 -0
README.md CHANGED
@@ -96,9 +96,9 @@ prompt, and a `*_with_ts_tags` prompt with one `<name> (length L): <ts><ts/>` pl
96
 
97
  - **Curated by:** <AUTHORS>
98
  - **Language(s) (NLP):** English
99
- - **License:** mixed, per subset (see [Licensing Information](#licensing-information))
100
 
101
- ### Dataset Sources
102
 
103
  - **Repository:** <CODE_URL>
104
  - **Paper:** <ARXIV_URL>
@@ -114,18 +114,75 @@ prompt, and a `*_with_ts_tags` prompt with one `<name> (length L): <ts><ts/>` pl
114
  huggingface-cli download LeoChen085/Lapras-Reasoning-Datasets --repo-type dataset --include "*.jsonl" --local-dir dataset
115
  ```
116
 
 
 
117
  ```python
118
  from datasets import load_dataset
119
- ds = load_dataset("LeoChen085/Lapras-Reasoning-Datasets", "sleep")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
120
  ```
121
 
122
- Use the plain configs for models that receive the series through a separate encoder input (e.g. SLIP), and
123
- the `*_ts_tags` configs for models that splice the series into the token sequence (e.g. ChatTS, OpenTSLM).
 
 
 
 
 
124
 
125
- ### Out-of-Scope Use
126
 
127
- - Clinical decision making. The ECG and Sleep subsets are research benchmarks, not validated diagnostic data.
128
- - Treating the reference traces as expert-verified explanations (see [Bias, Risks, and Limitations](#bias-risks-and-limitations)).
 
 
 
 
 
 
 
 
 
 
 
 
 
 
129
 
130
  ## Dataset Structure
131
 
@@ -140,14 +197,11 @@ engine/ ...
140
  | Config | Task | Train | Test | Channels | Length | Answer |
141
  |---|---|---:|---:|---:|---:|---|
142
  | `ecg` | cardiological diagnosis | 5,800 | 643 | 12 | 1000 | `Yes` / `No` |
143
- | `sleep` | sleep-stage classification | 7,413 | 923 | 1 | 1500 | 5 stages |
144
- | `har` | human activity recognition | 68,542 | 8,222 | 3 | 128 | 8 activities |
145
  | `tsr` | counterfactual consequence prediction | 22,566 | 4,094 | 1 | 128–1020 | option letter + text (`A`–`D`) |
146
  | `engine` | aero-engine fault diagnosis | 2,305 | 193 | 33 | 600 | option letter (`a`–`d`) |
147
 
148
- Labels: Sleep — `Wake`, `Non-REM stage 1`, `Non-REM stage 2`, `Non-REM stage 3`, `REM sleep`;
149
- HAR — `biking`, `lying`, `running`, `sitting`, `standing`, `walking`, `walking_down`, `walking_up`.
150
-
151
  ### Data Fields
152
 
153
  - `input` (string): the prompt (question, instructions and, for multiple choice, the options).
@@ -163,148 +217,12 @@ HAR — `biking`, `lying`, `running`, `sitting`, `standing`, `walking`, `walking
163
  The `*_with_ts_tags` files contain the same rows in the same order; only `input` differs, by the
164
  placeholder lines prepended to the prompt.
165
 
166
- ## Dataset Creation
167
-
168
- ### Curation Rationale
169
-
170
- Latent-reasoning methods such as Lapras distill a reference reasoning trace into continuous thoughts, so every
171
- task needs a trace. The five tasks were chosen to span medical, activity, synthetic-scenario and industrial
172
- signals with different channel counts and series lengths.
173
-
174
- ### Source Data
175
-
176
- #### Data Collection and Processing
177
-
178
- - **ECG** — from ECG-Reasoning-Benchmark (Oh et al., 2026), whose ECGs come from MIMIC-IV-ECG and PTB-XL
179
- (12 leads, 10 s at 100 Hz). The multi-stage benchmark is reformatted into single binary diagnosis
180
- questions; the trace concatenates the per-stage gold answers (criterion selection → finding
181
- identification → ECG grounding → diagnostic decision).
182
- - **Engine** — from EngineMT-QA (Wang et al., 2025), built on NASA's N-CMAPSS. Only samples with a certified
183
- per-component health label are kept; the trace is generated deterministically from these labels
184
- (component roll-call → severity → maintenance implication). Examples shared between the source splits were removed.
185
- - **HAR** and **Sleep** — prompts, series and labels from the OpenTSLM HAR-CoT and SleepEDF-CoT releases
186
- (Langer et al., 2026). HAR-CoT combines DaLiAc, DOMINO, HHAR, PAMAP2, RealWorld and the Shoaib et al.
187
- datasets (3-axis accelerometer, 50 Hz, 2.56 s windows); Sleep-CoT uses 30 s EEG epochs from Sleep-EDF.
188
- - **TSR** — series pairs (original and counterfactual) from the two-series subset of Merrill et al. (2024),
189
- whose series are synthetic and depict real-world scenarios. For each pair, a consequence question with
190
- four options was written with Qwen3.5-27B from a qualitative feature that differs between the two series;
191
- only pairs whose correct answers differ were kept. Splits are by source series, so no series appears in both.
192
-
193
- #### Who are the source data producers?
194
-
195
- The authors of the source datasets cited below.
196
-
197
- ### Annotations
198
-
199
- #### Annotation process
200
-
201
- ECG and Engine traces are assembled from the sources' annotated labels. HAR, Sleep and TSR traces are
202
- generated with Qwen3.5-27B following ARTIST (Messica et al., 2026): the model is conditioned on plots of the
203
- signal, summary statistics and the gold answer, selects at most three segments, and explains the answer from
204
- them. Traces were checked automatically for answer correctness and template adherence.
205
-
206
- #### Who are the annotators?
207
-
208
- No human annotation was added. Labels come from the source datasets; traces are template-based or model-generated.
209
-
210
- #### Personal and Sensitive Information
211
-
212
- ECG and Sleep recordings come from de-identified, open-access PhysioNet datasets (MIMIC-IV-ECG, PTB-XL,
213
- Sleep-EDF). The ECG `_uid` field carries the de-identified source record identifiers. No names or
214
- demographics are included in the prompts.
215
-
216
- ## Bias, Risks, and Limitations
217
-
218
- - Model-generated traces (HAR, Sleep, TSR) were produced with access to the gold answer and may
219
- rationalize it rather than reflect evidence in the signal.
220
- - TSR series are synthetic, and its questions and options are model-written.
221
- - Class imbalance: e.g. `Wake` is ~45% of Sleep and `sitting` ~28% of HAR; the Engine test set has few healthy engines.
222
- - Sleep splits are at the epoch level, not the subject level; Engine splits are disjoint by sample id, not by engine unit.
223
- - No validation split is provided.
224
-
225
- ### Recommendations
226
-
227
- Report results on the test split without using it for model or hyperparameter selection, and do not use the
228
- data for clinical purposes.
229
-
230
- ## Licensing Information
231
-
232
- The collection is released under per-subset terms that follow its sources. The ECG subset is released under
233
- the **Open Database License v1.0 (ODbL)**, as required by the share-alike terms of MIMIC-IV-ECG (as is its
234
- direct source, ECG-Reasoning-Benchmark). The other subsets remain subject to the terms of their sources:
235
-
236
- | Subset | Source | Source license |
237
- |---|---|---|
238
- | ECG | ECG-Reasoning-Benchmark; MIMIC-IV-ECG v1.0; PTB-XL v1.0.3 | ODbL 1.0; ODbL 1.0; CC BY 4.0 |
239
- | Sleep | OpenTSLM SleepEDF-CoT; Sleep-EDF Database Expanded v1.0.0 | MIT (OpenTSLM project); ODC-By 1.0 |
240
- | HAR | OpenTSLM HAR-CoT (and its source HAR datasets) | MIT (OpenTSLM project); see each source |
241
- | TSR | Merrill et al. (2024), `mikeam/time-series-reasoning` | code MIT; the dataset declares no license |
242
- | Engine | EngineMT-QA (N-CMAPSS) | MIT |
243
-
244
- ## Citation
245
-
246
- If you use this dataset, please cite Lapras and the source datasets.
247
-
248
- **BibTeX:**
249
-
250
- ```bibtex
251
- @inproceedings{lapras2027,
252
- title = {Lapras: Latent Reasoning for Time Series Language Models},
253
- author = {<AUTHORS>},
254
- booktitle = {<VENUE>},
255
- year = {2027}
256
- }
257
-
258
- @misc{oh2026ecgreasoning,
259
- title = {ECG-Reasoning-Benchmark: A Benchmark for Evaluating Clinical Reasoning Capabilities in ECG Interpretation},
260
- author = {Jungwoo Oh and Hyunseung Chung and Junhee Lee and Min-Gyu Kim and Hangyul Yoon and Ki Seong Lee and Youngchae Lee and Muhan Yeo and Edward Choi},
261
- year = {2026},
262
- eprint = {2603.14326},
263
- archivePrefix = {arXiv}
264
- }
265
-
266
- @misc{langer2026opentslm,
267
- title = {OpenTSLM: Time-Series Language Models for Reasoning over Multivariate Medical Text- and Time-Series Data},
268
- author = {Patrick Langer and Thomas Kaar and Max Rosenblattl and Maxwell A. Xu and Winnie Chow and Martin Maritsch and Robert Jakob and Ning Wang and Juncheng Liu and Aradhana Verma and Brian Han and Daniel Seung Kim and Henry Chubb and Scott Ceresnak and Aydin Zahedivash and Alexander Tarlochan Singh Sandhu and Fatima Rodriguez and Daniel McDuff and Elgar Fleisch and Oliver Aalami and Filipe Barata and Paul Schmiedmayer},
269
- year = {2026},
270
- eprint = {2510.02410},
271
- archivePrefix = {arXiv}
272
- }
273
-
274
- @inproceedings{merrill2024language,
275
- title = {Language Models Still Struggle to Zero-shot Reason about Time Series},
276
- author = {Merrill, Mike A and Tan, Mingtian and Gupta, Vinayak and Hartvigsen, Thomas and Althoff, Tim},
277
- booktitle = {Findings of the Association for Computational Linguistics: EMNLP 2024},
278
- pages = {3512--3533},
279
- year = {2024},
280
- doi = {10.18653/v1/2024.findings-emnlp.201}
281
- }
282
-
283
- @misc{wang2025itformer,
284
- title = {ITFormer: Bridging Time Series and Natural Language for Multi-Modal QA with Large-Scale Multitask Dataset},
285
- author = {Yilin Wang and Peixuan Lei and Jie Song and Yuzhe Hao and Tao Chen and Yuxuan Zhang and Lei Jia and Yuanxiang Li and Zhongyu Wei},
286
- year = {2025},
287
- eprint = {2506.20093},
288
- archivePrefix = {arXiv}
289
- }
290
-
291
- @misc{messica2026artist,
292
- title = {Adaptive Time Series Reasoning via Segment Selection},
293
- author = {Shvat Messica and Jiawen Zhang and Kevin Li and Theodoros Tsiligkaridis and Marinka Zitnik},
294
- year = {2026},
295
- eprint = {2602.18645},
296
- archivePrefix = {arXiv}
297
- }
298
- ```
299
-
300
- PhysioNet sources (please also cite):
301
-
302
- - Gow, B., et al. (2023). MIMIC-IV-ECG: Diagnostic Electrocardiogram Matched Subset (version 1.0). PhysioNet. https://doi.org/10.13026/4nqg-sb35
303
- - Wagner, P., Strodthoff, N., Bousseljot, R., Samek, W., & Schaeffter, T. (2022). PTB-XL, a large publicly available electrocardiography dataset (version 1.0.3). PhysioNet. https://doi.org/10.13026/kfzx-aw45
304
- - Wagner, P., et al. (2020). PTB-XL, a large publicly available electrocardiography dataset. Scientific Data. https://doi.org/10.1038/s41597-020-0495-6
305
- - Kemp, B., et al. Sleep-EDF Database Expanded (version 1.0.0). PhysioNet. https://physionet.org/content/sleep-edfx/1.0.0/
306
- - Pollard, T., et al. (2026). PhysioNet as a global platform for biomedical research. Nature Health. https://doi.org/10.1038/s44360-026-00096-z
307
-
308
- ## Dataset Card Contact
309
 
310
- <CONTACT>
 
 
 
 
 
 
 
96
 
97
  - **Curated by:** <AUTHORS>
98
  - **Language(s) (NLP):** English
99
+ - **License:** per subset (see [Data Sources](#data-sources))
100
 
101
+ ### Links
102
 
103
  - **Repository:** <CODE_URL>
104
  - **Paper:** <ARXIV_URL>
 
114
  huggingface-cli download LeoChen085/Lapras-Reasoning-Datasets --repo-type dataset --include "*.jsonl" --local-dir dataset
115
  ```
116
 
117
+ ### Quick start
118
+
119
  ```python
120
  from datasets import load_dataset
121
+
122
+ ds = load_dataset("LeoChen085/Lapras-Reasoning-Datasets", "har")
123
+ print(ds)
124
+ ```
125
+
126
+ ```
127
+ DatasetDict({
128
+ train: Dataset({
129
+ features: ['input', 'timeseries', 'output'],
130
+ num_rows: 68542
131
+ })
132
+ test: Dataset({
133
+ features: ['input', 'timeseries', 'output'],
134
+ num_rows: 8222
135
+ })
136
+ })
137
+ ```
138
+
139
+ Each row is a dict with `input` (str), `timeseries` (list of channels, each a list of floats) and `output` (str).
140
+
141
+ ### Processor, collator and DataLoader
142
+
143
+ [`lapras_dataloader.py`](lapras_dataloader.py) holds a standard multimodal processor and collator, as for
144
+ vision-language models: the processor tokenizes the text and packs the time series into a tensor, and the
145
+ collator builds training batches in which only the response is supervised.
146
+
147
+ ```python
148
+ from huggingface_hub import hf_hub_download
149
+ hf_hub_download("LeoChen085/Lapras-Reasoning-Datasets", "lapras_dataloader.py", repo_type="dataset", local_dir=".")
150
+
151
+ from torch.utils.data import DataLoader
152
+ from transformers import AutoTokenizer
153
+ from lapras_dataloader import TimeSeriesProcessor, TimeSeriesCollator
154
+
155
+ processor = TimeSeriesProcessor(AutoTokenizer.from_pretrained("Qwen/Qwen3-8B"))
156
+ loader = DataLoader(ds["train"], batch_size=4, shuffle=True, collate_fn=TimeSeriesCollator(processor))
157
+ batch = next(iter(loader))
158
  ```
159
 
160
+ ```
161
+ input_ids (4, 514) torch.int64 # length varies by batch
162
+ attention_mask (4, 514) torch.int64
163
+ timeseries (4, 3, 128) torch.float32 # (batch, channels, length), zero-padded
164
+ timeseries_mask (4, 3, 128) torch.bool # True on real samples
165
+ labels (4, 514) torch.int64 # -100 on the prompt and padding
166
+ ```
167
 
168
+ Series of different lengths (TSR) are zero-padded to the longest in the batch and marked in `timeseries_mask`.
169
 
170
+ ### Decoding back
171
+
172
+ ```python
173
+ tok = processor.tokenizer
174
+
175
+ ids = batch["input_ids"][0][batch["attention_mask"][0].bool()]
176
+ tok.decode(ids)
177
+ # '<|im_start|>user\nYou are given accelerometer data in all three dimensions. ... <|eot|>\nAnswer: sitting<|im_end|>'
178
+
179
+ target = tok.decode(batch["labels"][0][batch["labels"][0] != -100], skip_special_tokens=True)
180
+ target # the example's `output`, character for character
181
+ target.rsplit("Answer:", 1)[1].strip() # e.g. 'sitting'
182
+
183
+ n_ch = batch["timeseries_mask"][0].any(-1).sum()
184
+ batch["timeseries"][0][batch["timeseries_mask"][0]].view(n_ch, -1).tolist() # the example's `timeseries`
185
+ ```
186
 
187
  ## Dataset Structure
188
 
 
197
  | Config | Task | Train | Test | Channels | Length | Answer |
198
  |---|---|---:|---:|---:|---:|---|
199
  | `ecg` | cardiological diagnosis | 5,800 | 643 | 12 | 1000 | `Yes` / `No` |
200
+ | `sleep` | sleep-stage classification | 7,413 | 923 | 1 | 1500 | `Wake`, `Non-REM stage 1`, `Non-REM stage 2`, `Non-REM stage 3`, `REM sleep` |
201
+ | `har` | human activity recognition | 68,542 | 8,222 | 3 | 128 | `biking`, `lying`, `running`, `sitting`, `standing`, `walking`, `walking_down`, `walking_up` |
202
  | `tsr` | counterfactual consequence prediction | 22,566 | 4,094 | 1 | 128–1020 | option letter + text (`A`–`D`) |
203
  | `engine` | aero-engine fault diagnosis | 2,305 | 193 | 33 | 600 | option letter (`a`–`d`) |
204
 
 
 
 
205
  ### Data Fields
206
 
207
  - `input` (string): the prompt (question, instructions and, for multiple choice, the options).
 
217
  The `*_with_ts_tags` files contain the same rows in the same order; only `input` differs, by the
218
  placeholder lines prepended to the prompt.
219
 
220
+ ## Data Sources
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
221
 
222
+ | Subset | Source |
223
+ |---|---|
224
+ | ECG | [ECG-Reasoning-Benchmark](https://huggingface.co/datasets/Jwoo5/ECG-Reasoning-Benchmark) |
225
+ | Sleep | [OpenTSLM SleepEDF-CoT](https://github.com/StanfordBDHG/OpenTSLM) |
226
+ | HAR | [OpenTSLM HAR-CoT](https://github.com/StanfordBDHG/OpenTSLM) |
227
+ | TSR | [Merrill et al. (2024)](https://huggingface.co/datasets/mikeam/time-series-reasoning) |
228
+ | Engine | [EngineMT-QA](https://huggingface.co/datasets/pandalin98/EngineMT-QA) |
lapras_dataloader.py ADDED
@@ -0,0 +1,48 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """Processor and collator for the Lapras Reasoning Datasets, in the style of a VLM data pipeline."""
2
+
3
+ import torch
4
+
5
+
6
+ class TimeSeriesProcessor:
7
+ """Tokenizes text and packs time series into tensors, as a VLM processor does for images."""
8
+
9
+ def __init__(self, tokenizer):
10
+ self.tokenizer = tokenizer
11
+ self.tokenizer.padding_side = "right"
12
+
13
+ def apply_chat_template(self, prompt, response=None):
14
+ messages = [{"role": "user", "content": prompt}]
15
+ text = self.tokenizer.apply_chat_template(messages, tokenize=False, add_generation_prompt=True)
16
+ return text if response is None else text + response + self.tokenizer.eos_token
17
+
18
+ def __call__(self, text, timeseries):
19
+ batch = self.tokenizer(text, padding=True, add_special_tokens=False, return_tensors="pt")
20
+ n_ch = max(len(x) for x in timeseries)
21
+ n_t = max(len(ch) for x in timeseries for ch in x)
22
+ values = torch.zeros(len(timeseries), n_ch, n_t)
23
+ mask = torch.zeros(len(timeseries), n_ch, n_t, dtype=torch.bool)
24
+ for i, x in enumerate(timeseries):
25
+ for c, ch in enumerate(x):
26
+ values[i, c, : len(ch)] = torch.tensor(ch)
27
+ mask[i, c, : len(ch)] = True
28
+ batch["timeseries"] = values
29
+ batch["timeseries_mask"] = mask
30
+ return batch
31
+
32
+
33
+ class TimeSeriesCollator:
34
+ """Builds a training batch in which only the response is supervised (labels are -100 elsewhere)."""
35
+
36
+ def __init__(self, processor):
37
+ self.processor = processor
38
+
39
+ def __call__(self, examples):
40
+ prompts = [self.processor.apply_chat_template(ex["input"]) for ex in examples]
41
+ texts = [self.processor.apply_chat_template(ex["input"], ex["output"]) for ex in examples]
42
+ batch = self.processor(texts, [ex["timeseries"] for ex in examples])
43
+ labels = batch["input_ids"].clone()
44
+ labels[batch["attention_mask"] == 0] = -100
45
+ for i, prompt in enumerate(prompts):
46
+ labels[i, : len(self.processor.tokenizer(prompt, add_special_tokens=False)["input_ids"])] = -100
47
+ batch["labels"] = labels
48
+ return batch