---
title: 'SleepLM: Sleep Analysis with Language Modeling'
url: https://www.emergentmind.com/topics/sleeplm
type: topic
---

# SleepLM: Sleep Analysis with Language Modeling

SleepLM denotes a set of research systems that connect sleep analysis with language modeling, but the label is not used for a single standardized architecture. In the recent literature, it has referred to a sequence model that predicts the next sleep stage from prior stage labels, to a two-stage LLM-augmented framework for sleep-efficiency regression and interactive feedback, to GPT-based multimodal prompting over EEG, activity, and behavioral data, and to a family of sleep-language foundation models that align natural language with multimodal polysomnography (PSG) [2302.12709], [2310.16242], [2408.07822], [2602.23605]. Across these usages, the unifying theme is the attempt to couple sleep physiology or sleep-related behavior with language-mediated inference, querying, explanation, or intervention.

## 1. Nomenclature and scope

The literature uses the term in several technically distinct ways. One usage treats SleepLM as a probabilistic prior over discrete sleep-stage sequences. A second usage applies the term to a sleep-oriented language model that combines structured sensing features, synthetic data generation, and interactive GPT-based feedback. A third usage concerns LLM-based prompting pipelines that ingest EEG-derived representations, activity visualizations, and questionnaire text. A fourth usage, introduced by Xu et al., defines SleepLM as a family of sleep-language foundation models with unified pretraining over PSG and text [2602.23605].

| Formulation | Core data | Principal function |
|---|---|---|
| Sequence SleepLM | Sleep-stage label sequences | Predict the next sleep stage and improve decoding |
| Two-stage sleep-oriented language model | Wearable/mobile sensing features plus LLM-derived latent factors | Regress sleep efficiency and generate actionable feedback |
| GPT-based multimodal prompting | EEG waveforms, spectrograms, activity data, PSQI text | Estimate attention, sleep stages, sleep quality, and generate suggestions |
| Sleep-language foundation model | Multimodal PSG paired with multilevel captions | Zero-shot and few-shot sleep understanding, retrieval, captioning, and event localization |

A common misconception is that SleepLM names a single model family. The published record instead shows a progression from discrete sequence modeling, to prompt-based interaction over engineered features, to multimodal foundation modeling over raw physiological data and natural-language supervision.

## 2. Sequence priors for sleep-stage decoding

In "Sleep Model -- A Sequence Model for Predicting the Next Sleep Stage" [2302.12709], SleepLM is a prior over stage sequences \(s_t \in \{W, REM, N1, N2, N3\}\). The paper studies two variants. The first is an \(n\)-gram model,
\[
P(s_t \mid s_{t-n+1},\dots,s_{t-1}) \approx \frac{C(s_{t-n+1},\dots,s_{t-1},s_t)}{C(s_{t-n+1},\dots,s_{t-1})},
\]
with smoothing and back-off as in KenLM, including Kneser–Ney back-off smoothing. The second is an LSTM-RNN sleep model in which the previous stage label is embedded into \(x_t = E\,\mathrm{onehot}(s_{t-1})\), processed by a multi-layer LSTM, and mapped to
\[
P(s_t\mid s_{<t})=\mathrm{softmax}(V\,h_t^{(L)}+b).
\]

The \(n\)-gram models were built with KenLM on concatenated sleep-stage sequences, exploring \(n=2\ldots9\). The LSTM variants used \(L=2\) or \(4\) layers, hidden dimension \(H\in\{256,1024\}\), and embedding dimension \(d=H\). Training minimized cross-entropy and proceeded until validation perplexity plateau. Input data consisted of pure stage-label sequences from HMC, with 98 train, 24 val, and 29 test nights, and NCHSDB, with 3036 train, 379 val, and 380 test nights.

The sequence prior is combined with a sensor model through beam-search decoding. For each epoch \(e\), the decoder combines the signal-model likelihood \(P_{sig}(s_e\mid d_{e-2:e+2})\) with the SleepLM prior \(P_{SLM}(s_e\mid s_{1:e-1})\), using
\[
\log P(s_{1:E})=\sum_{e=1}^{E}\Bigl[\log P_{sig}(s_e)+\alpha \log P_{SLM}(s_e)\Bigr].
\]
Beam search keeps the top-\(W\) partial hypotheses with \(W=128\), expands them over the five candidate next stages, updates scores, and prunes back to the beam width.

Quantitatively, the paper reports that \(n\)-gram perplexity on HMC decreases up to \(n=5\), then rises because of data sparsity, with best \(PPL \approx 1.60\). The LSTM SleepLM with \(2\times 1024\) hidden units achieves validation/test perplexity \(1.547 / 1.608\) on HMC and \(1.291 / 1.286\) on NCHSDB. For sleep-stage classification, the 4-channel signal model with greedy decoding attains validation \(\kappa=0.741\), accuracy \(=0.804\), and test \(\kappa=0.680\), accuracy \(=0.759\); adding the LSTM SleepLM with \(\alpha=0.12\) and beam \(=128\) yields no appreciable change. By contrast, the 1-channel EOG-only signal model improves from validation \(\kappa=0.505\), accuracy \(=0.629\), and test \(\kappa=0.464\), accuracy \(=0.602\) to validation \(\kappa=0.596\), accuracy \(=0.698\), and test \(\kappa=0.519\), accuracy \(=0.644\) when fused with the LSTM prior at \(\alpha=0.42\), beam \(=128\). The paper’s central conclusion is that SleepLM priors significantly boost accuracy when only limited sensors are available, whereas strong multi-channel PSG models leave little room for additional gain.

## 3. Sleep-efficiency regression and interactive GPT feedback

"ZzzGPT: An Interactive GPT Approach to Enhance Sleep Quality" describes a two-stage framework that its technical narrative explicitly organizes as a Sleep-oriented Language Model, or SleepLM [2310.16242]. Stage 1 is a predictive engine for regression of sleep efficiency \(Q_x \in [0,100]\) from raw wearable and mobile sensing features \(F_r\) plus LLM-derived latent factors \(F_l\), formalized as
\[
f(F_r,F_l)\to Q_x.
\]
Stage 2 is a user-centric feedback layer in which a chat interface powered by an LLM API clarifies ambiguous questions, fetches the predicted \(Q_x\), renders an interactive graph of key features, and produces natural-language recommendations.

The Stage 1 model family includes CatBoost, Random Forest, XGBoost, and a stacked ensemble that feeds each model’s prediction into a ridge regressor. The loss is mean squared error with ridge penalty,
\[
L(\theta)=\frac{1}{N}\sum_{i=1}^{N}(y_i-\hat y_i)^2+\lambda \|w\|_2^2,
\]
and evaluation uses RMSE, MAE, and \(R^2\). Input features include heart rate, step count, screen time, Bluetooth device count, and location. The paper addresses the natural skew in GLOBEM, described as a \(70\%–90\%\) cluster, by generating synthetic low-efficiency samples with an LLM.

The data pipeline begins by excluding entries with missing \(Q_x\) or more than \(50\%\) missing features, imputing outliers via the Tukey method with participant means, discarding features with \(|r|<.001\) to \(Q_x\), removing one of any pair with \(\rho>0.8\), adding `day_of_week` and `is_weekend` flags, dropping the first week per participant to allow historical features, standardizing via \(z\)-score, and applying an \(80/20\) train/test split. Synthetic data generation repeatedly samples 20-day windows, formats them as Markdown-style tables, asks the LLM to generate five additional days with the same columns while preserving temporal correlations, and runs a verification loop that rejects outputs missing required columns. Temperature is set to \(0.7\), \(top_p=0.9\), and \(max\_tokens \approx 500\) to capture all 72 features. The combined training set is the original GLOBEM train set union the LLM-generated samples.

The interactive layer is organized by prompt templates. A system prompt instructs the model to act as a sleep coach. Few-shot prompt templates cover clarification, prediction, and recommendation turns, including the instruction, “Given \(Q_x=72\%\), suggest three actionable tips, ranked by expected sleep-efficiency gain.” GPT also returns JSON containing feature names, current values, and sensitivity slopes \((\partial Q/\partial F_r)\) for JavaScript-driven sliders. Example interactive elements include sliders for `screen_time_last_2h`, `steps_daytime`, `bedtime_variability`, and `surrounding_BT_devices`, each paired with a predicted \(\partial Q/\partial \text{Feature}\) value.

The reported performance on the INS-W\(_1\) cohort shows that with hand-picked 72 features, the stacked model attains RMSE \(2.661\), MAE \(2.105\), and \(R^2=0.256\). With top-\(k\) 20 features plus LLM-generated data, CatBoost reaches RMSE \(2.675\), MAE \(2.114\), and \(R^2=0.248\), identified in the paper as the best overall result for that configuration. Incorporating LLM-generated data improves \(R^2\) from \(0.239\) to \(0.248\) for CatBoost and yields small gains in RMSE and MAE across all models. Figure 4 further reports that “CatBoost 20+G” outperforms three baseline depression-prediction pipelines by a margin of \(5\%–10\%\) in RMSE reduction and \(3\%–6\%\) in \(R^2\) gain. The feedback layer then translates prediction into intervention through recommendations such as reducing screen time before bed, increasing daytime steps, adjusting bedtime routine, and optional push notifications.

## 4. Prompt-based LLMs over EEG, activity, and behavioral data

"Exploration of LLMs, EEG, and behavioral data to measure and support attention and sleep" studies a broader prompt-based SleepLM formulation in which each modality is treated as prompt material for GPT-4 or GPT-3.5 Turbo [2408.07822]. EEG waveforms are sampled at \(128–256\) Hz, band-pass filtered with a Butterworth filter \((0–40\ \text{Hz}, \text{order }128)\), and segmented into fixed windows: 10 s for attention and 30 s for sleep. Time-frequency spectrograms are computed via Daubechies wavelet transforms. The numerical EEG representation \(X_{num}\in\mathbb{R}^{11}\) contains band power PSD in \(\{\delta,\theta,\alpha,\beta\}\), amplitude, standard deviation, kurtosis, band ratios \(\alpha/\delta\), \(\theta/\alpha\), \(\delta/\theta\), and 90th percentile amplitude. Additional modalities are actogram images, hourly-averaged activity graphs, and free-text PSQI responses.

The paper expresses the approach conceptually as
\[
h_{LLM}=LLM\_encoder([\text{prompt\_images}],[\text{prompt\_text}]),
\]
followed by task-specific outputs for attention, sleep stage, and sleep quality. In practice, these heads are not separate Transformer layers but prompt instructions asking the LLM to return JSON with label, confidence, and explanation. Numerical features are converted into short JSON-like text or fed via fine-tuning as tabular tokens; images are passed to GPT-4 Vision; PSQI text is used directly as natural-language input.

The empirical results are explicitly mixed. On the Mental Attention State dataset, fine-tuned GPT-3.5 on features yields accuracy \(53.7\%\), \(F1=0.51\); in-context GPT-4 Vision on spectrograms yields accuracy \(55.7\%\), \(F1=0.56\), with \(25\%\) “cannot assist”; zero-shot GPT-4 Vision yields accuracy \(66.2\%\), \(F1=0.55\), with \(30\%\) failures; XGBoost on numerical features attains accuracy \(91.3\%\), \(F1=0.93\); and the majority-vote baseline gives accuracy \(66.6\%\), \(F1=0.53\). On Sleep EDF Expanded for five-class sleep staging, fine-tuned GPT-3.5 on features reaches accuracy \(50.6\%\), \(F1=0.46\); in-context GPT-4 Vision on waveform images reaches accuracy \(25.4\%\), \(F1=0.21\), with \(51\%\) failures; zero-shot GPT-4 on features yields accuracy \(29.0\%\), \(F1=0.25\); XGBoost reaches accuracy \(75.6\%\), \(F1=0.74\); and the baseline gives accuracy \(37.2\%\), \(F1=0.20\). On sleep quality detection from PSQI for \(N=77\), ground truth is 39 good and 38 poor sleepers, and GPT-4 correctly identifies 39 good and 27 poor, with 11 poor-to-good errors, for overall \(85.7\%\) accuracy.

The same study also uses the LLM as an intervention generator. The prompt context can include habitual EEG feature summaries, PSQI responses, actogram visuals, demographics, health issues such as anxiety, PTSD, insomnia, pain, or shift work, and personal preferences such as beach, forest, favorite animals, or hobbies. Prompts instruct the model to produce sleep hygiene suggestions aligned with CBT-i best practices and a guided imagery script tailored to user preferences. The paper notes that initial scripts included raw EEG ratios, which later prompts explicitly disallowed. It also records several failure modes: GPT-4 Vision often refuses to process raw spectrogram or actogram images; high-dimensional numeric features prompt “I can’t assist” responses or superficial heuristic reasoning; and infrequent night-time movements in actograms may be misread as poor sleep. The stated implication is that improved performance would require more labeled data, domain-specific pretraining or fine-tuning, or retrieval of external sleep-science knowledge.

## 5. Sleep-language foundation models

The 2026 paper "SleepLM: Natural-Language Intelligence for Human Sleep" formalizes SleepLM as a family of sleep-language foundation models built on the ReCoCa architecture [2602.23605]. Its stated goal is to bridge natural language and multimodal polysomnography so that sleep analysis is no longer confined to closed label spaces such as predefined stages or events. To support this alignment, the authors curate what they describe as the first large-scale sleep-text dataset, comprising five NSRR cohorts—SHHS, MrOS, CCSHS, CFS, and WSC—with more than 10,000 participants, 12,000 nights, and more than 100,000 hours of PSG. The data contain 12 channels at 64 Hz: EEG, EOG, EMG, ECG, heart rate, \(\text{SpO}_2\), respiration, and body position, segmented into non-overlapping 30 s windows.

Text supervision is generated through a multilevel caption pipeline. Channel captions convert numeric statistics such as EEG band power, HRV, and respiration rate into language templates. Local captions describe event onsets and offsets, including hypopnea, desaturation, and arousal, via peak or trend detection. Global captions summarize sleep stage and autonomic state. The result is dense, hierarchically structured text supervision for every 30 s epoch.

ReCoCa consists of four components. The channel-specific sleep encoder performs patch embedding per channel, followed by interleaved temporal attention with RoPE along time and channel attention with RoPE along the sensor dimension, producing a CLS token embedding \(s\in\mathbb{R}^d\). A lightweight transformer reconstruction decoder predicts signal patches \(\hat x\) from encoder latents. A modality-conditioned text decoder prepends a learnable modality token \([m]\in\{\text{Brain}, \text{Respiratory}, \text{Cardiac}, \text{Somatic}\}\) and generates the multilevel caption \(y\) conditioned on \(s\) and \([m]\). By toggling loss weights \((\lambda_{con}, \lambda_{rec}, \lambda_{cap})\), the framework yields CLIP-style, Cap-style, CoCa-style, or full ReCoCa training variants.

The unified pretraining objective combines contrastive alignment, reconstruction, and caption generation:
\[
L_{total}=\lambda_{con}L_{contrast}+\lambda_{rec}L_{recon}+\lambda_{cap}L_{cap},
\]
with \(\lambda_{con}=1.0\), \(\lambda_{rec}=0.1\), and \(\lambda_{cap}=2.0\). Here \(L_{contrast}\) is an InfoNCE objective over sleep embeddings \(s_i\) and text embeddings \(v_i\), \(L_{recon}\) is an MSE loss over \(x_i\) and \(\hat x_i\), and \(L_{cap}\) is an autoregressive cross-entropy loss over caption tokens.

The quantitative results define the foundation-model usage of SleepLM. Averaged over SHHS, MrOS, and CFS, zero-shot SleepLM (ReCoCa) reaches stage AUC \(85.4\), stage balanced accuracy \(76.9\), event IoU \(30.4\), event balanced accuracy \(74.3\), HR MAE \(1.97\), HR trend recall \(35.8\), \(\text{SpO}_2\) MAE \(2.24\), \(\text{SpO}_2\) trend recall \(39.1\), and channel sMAPE \(3.15\). The paper reports gains over the best baseline of \(+15.2\) in stage AUC, \(+25.6\) in stage balanced accuracy, \(+15.9\) in event IoU, \(+14.5\) in event balanced accuracy, approximately zero in HR MAE, \(+8.5\) in HR recall, \(+20.3\) in \(\text{SpO}_2\) recall, and \(-31.47\) in channel-statistics sMAPE. In zero-shot retrieval on CFS, SleepLM (ReCoCa) obtains text-to-signal \(R@1=78.7\), \(R@5=91.5\), and signal-to-text \(R@1=70.0\), \(R@5=86.5\); on SHHS it reaches \(96.1\), \(99.8\), \(96.7\), and \(99.8\), respectively. For unseen apnea classification, with mixed apnea and obstructive apnea absent from training, SleepLM reports mixed apnea \(F1=78.2\), balanced accuracy \(81.8\), and obstructive apnea \(F1=79.7\), balanced accuracy \(77.1\). The paper also describes qualitative and perturbation evidence for language-guided event localization, noting that cosine similarity correlates linearly with temporal IoU even without explicit localization supervision.

## 6. Methodological themes, limitations, and interpretive issues

Taken together, these papers suggest three methodological axes for SleepLM research. The first is sequential prior modeling over discrete stage labels, where language-model techniques function as transition regularizers for sensor-based classifiers [2302.12709]. The second is prompt-mediated interaction over engineered or tabular sleep features, where the LLM acts as a conversational interface, explanation layer, or synthetic-data generator rather than as the primary physiological encoder [2310.16242], [2408.07822]. The third is joint representation learning over raw PSG and text, where SleepLM becomes a multimodal foundation model with open-vocabulary capabilities [2602.23605].

A second recurring issue is that the benefit of language-model components is task- and modality-dependent. In the sequence-model formulation, the prior provides substantial gains for EOG-only sleep staging but no appreciable change for a 4-channel signal model. In the GPT-based prompting study, LLM-based detection performs substantially worse than classical ML on low-dimensional EEG features and activity-derived inputs, even though the same systems can produce plausible sleep hygiene suggestions and guided imagery. In the two-stage sleep-efficiency framework, LLM involvement yields measurable but modest predictive gains through synthetic augmentation and supports actionable feedback. In the foundation-model setting, by contrast, natural-language supervision is integral to zero-shot classification, retrieval, captioning, and unseen-task transfer. This suggests that SleepLM is most effective when language is structurally aligned with the task, rather than merely appended to a weak physiological representation.

The limitations reported in the literature are likewise heterogeneous but consistent in emphasis. The foundation-model work notes that cohort diversity is limited to five NSRR datasets, that clinical validation and regulatory approval remain outstanding, and that the 30 s context window leaves longer-range dependencies to sliding and aggregation. The GPT-based prompting study highlights multimodal fusion limits, privacy concerns for EEG, latency, and reliability under drift. The interactive GPT framework depends on prompt engineering, verification loops for synthetic data, and interface design choices such as clarification turns and optional push notifications. None of the papers presents SleepLM as a completed clinical diagnostic system.

The resulting state of the field is technically plural rather than terminologically unified. "SleepLM" can denote a next-stage sequence prior, an interactive sleep-efficiency assistant, a prompt-based multimodal GPT pipeline, or a sleep-language foundation model. The strongest common denominator is the use of language modeling to extend sleep analysis beyond isolated per-epoch classification, whether by enforcing sequence consistency, generating actionable advice, enabling natural-language querying, or learning language-grounded representations of sleep physiology.

Source: https://www.emergentmind.com/topics/sleeplm