Skip to content

[BTY-64] SleepKD on ISRUC-III with a sequence sleep staging task - #1503

Merged
github-actions[bot] merged 2 commits into
sunlabuiuc:masterfrom
samehaisaa:feat/sleepkd
Nov 19, 2026
Merged

github-actions[bot] merged 2 commits into
sunlabuiuc:masterfrom
samehaisaa:feat/sleepkd

Conversation

@samehaisaa

@samehaisaa samehaisaa commented Nov 16, 2026 •

Copy link
Copy Markdown
Contributor

Contributor: Sameh Aissa

Contribution Type: Task and example, bounty BTY-64

Description:

The ISRUC-III half of BTY-64 on top of #1518 which added SleepKD and the Sleep-EDF part, so together they cover both datasets the bounty names. SleepStagingSequenceISRUC builds on the ISRUC port from #1486 and gives 20 epoch windows of one EEG channel with a stage per epoch like SleepStagingSequenceSleepEDF. It uses F3-A2 resampled from 200 to 100 Hz as in the paper and a window never spans a dropped epoch.

The example now takes --dataset isruc and --fold k for a subject-wise cross validation since ISRUC-III has only 10 subjects. I ran all nine runs on the 10 folds with the paper's settings of 300 epochs, lr 1e-5 and batch 20. Mean (std) of accuracy and macro-F1 next to the paper's Table 3.

Run Accuracy Macro-F1 Paper
teacher 67.7 (5.3) 62.9 (4.5) 83.97
student 66.5 (5.2) 61.5 (3.8)
kd 64.9 (7.3) 60.0 (5.3) 80.22 / 74.54
fitnets 65.1 (6.3) 60.0 (5.8) 81.11 / 75.05
sleepkd_noTA 65.2 (6.3) 60.1 (5.3)
takd_ta 68.4 (5.0) 62.0 (4.2)
takd 66.1 (5.8) 60.6 (4.9) 81.59 / 76.46
sleepkd_ta 67.0 (6.2) 61.4 (5.5)
sleepkd 65.0 (5.6) 59.0 (5.6) 83.29 / 77.29

Every method is about 15 points of accuracy below the paper and no distilled student beats the student trained alone on average. Each fold tests on one subject so the spread between folds is larger than the gaps between methods, like #1518 found on Sleep-EDF. The table is also in the example's docstring.

Files to Review:

  • pyhealth/tasks/sleep_staging_isruc.py the sequence task
  • examples/eeg/sleep_staging/sleepkd_deepsleepnet.py renamed from sleepkd_sleepedf_deepsleepnet.py with --dataset, --fold and the ISRUC results
  • tests/core/test_isruc.py tests for the sequence task on synthetic recordings
  • docs/api/tasks/pyhealth.tasks.SleepStagingSequenceISRUC.rst and docs/api/tasks.rst the docs page

Testing: pytest tests/core/test_isruc.py 33 passed with 100% coverage on sleep_staging_isruc.py and tools/check_pr_rules.py passes. The results come from the example on a local RTX 5050.

@github-actions

github-actions Bot commented Nov 16, 2026 •

Copy link
Copy Markdown

Test Coverage

Total: 84.96% (39757 / 46796 lines)

Modified file Coverage Lines
pyhealth/tasks/__init__.py 97.30% 72 / 74
pyhealth/tasks/sleep_staging_isruc.py 100.00% 121 / 121

Workflow run · bf15c4e

@github-actions github-actions Bot mentioned this pull request Nov 17, 2026
@samehaisaa

Copy link
Copy Markdown
Contributor Author

#1518 landed first and covers Sleep-EDF so I'll turn this one into the ISRUC-III half on top of it. I ported ISRUC in #1486 and already ran SleepKD on ISRUC-III as 10 subject-wise folds, @irvifa if you haven't started on ISRUC yet I'll take it here so we don't do it twice

@samehaisaa samehaisaa changed the title [BTY-64] Add SleepKD distillation with DeepSleepNet for sleep staging [BTY-64] SleepKD on ISRUC-III with a sequence sleep staging task Nov 18, 2026
@samehaisaa
samehaisaa marked this pull request as ready for review November 18, 2026 22:26
@solarsys solarsys added the status: automatic The PR will go through automatic review process. label Nov 19, 2026
@solarsys

Copy link
Copy Markdown
Collaborator

/review

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed commit bf15c4e

sleepkd_ta 67.0 (6.2) 61.4 (5.5)
sleepkd 65.0 (5.6) 59.0 (5.6) paper 83.29 77.29

Every method is about 15 points of accuracy below the paper and no distilled

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[low] ISRUC results gap to the paper is stated but unexplained

The docstring reports every method about 15 points of accuracy below the paper (the table gives 15 to 18 points, with sleepkd the largest at 18.3). The gap is far larger than the Sleep-EDF gap, which the author says is in range, so it may point to an ISRUC-specific pipeline difference rather than split noise alone. Non-blocking, but either note the likely causes or say what was checked (for example, the expert annotator, channel, resampling or label mapping) so readers know the ISRUC numbers are not a reproduction.

Attributes:
task_name (str): The name of the task, "SleepStagingSequenceISRUC".
input_schema (dict[str, str]): ``{"signal": "tensor"}``, a float array
of shape ``(seq_len, 1, 30 * sfreq)``.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[low] Attributes shape ignores sfreq=None

The Attributes section says the signal shape is (seq_len, 1, 30 * sfreq), but sfreq can be None, which keeps the recording's rate (200 Hz), so the shape is then (seq_len, 1, 6000). Write the shape as 30 * sfreq samples, where sfreq is the rate in Hz (200 when sfreq=None).

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

AI Review

suggestion: approve
decision: approve

Thank you for this contribution. It adds SleepStagingSequenceISRUC, a 20-epoch single-channel sequence task for ISRUC-III. It also adds a --dataset isruc / --fold k option to the SleepKD example, plus a docs page and tests. It looks ready to merge.

  • The task subclasses SleepStagingISRUC and reuses its read_recording and _samples_from_event. The description says it builds on the ISRUC port from #1486, so that link is explained.
  • Coverage meets the bar. sleep_staging_isruc.py is at 100% and tasks/__init__.py at 97.3%. The whole repository is at 84.96%.
  • The tests cover windowing, dropped-epoch gaps, stride, resampling, a missing channel, invalid arguments and set_task.
  • The docs match the code.

Optional suggestions:

  • The ISRUC results are about 15 points of accuracy below the paper for every method. You state this clearly and it doesn't make the code wrong. If you find a cause later, a short note in the docstring would help readers.
  • The sfreq=None case isn't shown in the docstring's output shape. In that case the signal length is 30 × the recording's rate, which is 6000 at 200 Hz. One extra line would make that clear.
  • The default --out is shared across folds, so runs from different folds can overwrite each other. Consider making the default include the fold, or warning when --fold is given without a custom --out.

Reviewed commit bf15c4e

@samehaisaa

Copy link
Copy Markdown
Contributor Author

/merge

@github-actions
github-actions Bot merged commit d58cc15 into sunlabuiuc:master Nov 19, 2026
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

status: automatic The PR will go through automatic review process.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants