How Did I Sleep?
A private neural network that has only ever learned one person
A small ml5.js neural network, trained only on 33 nights of my own sleep, replays a real night as a Van Gogh painting and then judges how I slept.

1. Concept
Every morning my watch gives me a sleep score. I don’t know why I got that number, and the model behind it was trained on thousands of strangers. How Did I Sleep? asks a smaller, more personal question: what would a model look like if the only person it had ever learned was me?
I trained a neural network on 33 nights of my own sleep data. It learns to predict my sleep score from six things: how long I slept, when I fell asleep, how long I was awake, my overnight HRV, deep sleep %, and REM %. It trains live in the browser, in front of the viewer, and my data never leaves the page.
The experience is a 30-second performance. I pick a night and press play. That night is fast-forwarded from falling asleep to waking, at about ten minutes per second. Every HRV reading my watch took becomes brushwork on a Starry Night–style canvas: a calm heart paints long wind and stars, and a restless heart paints swirls. When I wake, the moon appears. Its size and brightness are the model’s verdict. The model also explains itself in plain English and compares its guess with my watch’s real score.
The project is less about predicting sleep than about owning the model. It is small, it is sometimes wrong, and it knows only one person. Because of that, its reasoning is something I can actually read.
2. Inspiration
- Working on wearables.
- Van Gogh, The Starry Night (1889). It is a night painted from the window of the asylum at Saint-Rémy: a night seen from inside a restless mind. A heart-rate curve feels like that to me.
- Quantified self, flipped. Usually, data about me goes into someone else’s model. Here the model lives on my own page and learns only from me.
How it works
- The page opens → the network trains live. Over about 3 seconds, the screen shows the epoch count and the loss, and a gold line falls across the sky as the model becomes less wrong. The training data is real; it is only slowed down so it can be watched.
- Self-test. In the background, the model checks itself by leave-one-out: for each night, a fresh network learns the other 32 and guesses the one it never saw. The footer then reports its real accuracy (about ±8 points).
- Replay a night (30 s). A new network is trained without that night. The night is then painted reading by reading, with a gold playhead following the time of night.
- Verdict. The moon grows or dims. The page shows the score, the top two reasons (e.g. “how long I slept cost it 11 points”), and the watch’s real score.
- Keep teaching it. I can enter a new night and its score. The network retrains on screen, so the model grows as I keep sleeping.
Visual mapping
| Data | Painting |
|---|---|
| Each 10-minute HRV reading | One patch of brushwork at its time of night |
| HRV above that night’s average (calm) | Long horizontal wind and stars |
| HRV below that night’s average (restless) | Tight, dense swirls |
| Deep sleep % | Darker blues |
| REM % | Violet swirls |
| HRV value | Length and brightness of the river ripples |
| Model’s predicted score | Size and brightness of the moon |
| Training loss | Gold line falling across the sky |
4.
- Library: ml5.js v1,
ml5.neuralNetwork(regression), running on the TensorFlow.js CPU backend. - Data: 33 nights from my COROS watch (Jun 18 – Nov 13, 2026), plus the overnight HRV readings recorded every 10 minutes.
- Inputs (6):
- hours asleep
- the time I fell asleep
- minutes awake
- overnight HRV
- deep %
- REM %
- Output: my COROS sleep score (0–100).
- Network: 1 hidden layer of 16 units, learning rate 0.05, 100 epochs, batch size 8, inputs normalized.
- Evaluation: leave-one-out mean absolute error of about ±8 points, compared with ±13.8 for always guessing my average.
- Explanation: for each feature, I swap in its median value and measure how much the prediction changes.
- Finding: about 80% of what decides my score is simply how long I sleep. HRV, the number I assumed mattered most, barely moves it.
5.
- Front end: one HTML page, vanilla JavaScript, Canvas 2D. There is no server and no build step.
- Data prep:
- Exported through the COROS MCP interface and cleaned once in Python (pandas).
- Timestamps converted across time zones (China → New York).
- Readings outside each night’s sleep window are dropped.
- The data is embedded in the page.
- Painting:
- A 1600×900 canvas scaled to the screen.
- A seeded backdrop: sky strokes, hills, a cypress, a village and a river. Each night always paints the same picture.
- A data layer of brushwork.
- An animated overlay: the moon, the playhead, river ripples and the loss curve.
- Storage: new nights are saved in localStorage.
- Testing: Playwright headless runs of training, self-test, judging and replay.
6.
It is for anyone who wears a sleep tracker and has wondered what the score actually means, and for me. People experience it on a screen as a short performance: watch the model learn, pick a night, watch it paint, see the verdict and the reason. It is interactive but not medical. It is meant to be quietly emotional and slightly provocative: a model that knows only one person, small enough to understand, set against the black-box score on my wrist.
7.
- Tiny dataset (33 nights): predictions vary by a few points between training runs. I show this openly instead of hiding it.
- The model mostly learns sleep duration. That is a finding, not a flaw to cover up.
- No timing for wake-ups: the data has total minutes awake but not when they happened, so the painting doesn’t invent waking moments.
- ml5 loads from a CDN. For the presentation, I’ll bundle it locally as a backup.
- Screen ratio: best on a 16:9 screen at full size. Narrow screens crop the edges.

Leave a Reply