Whybook / How it works
How Whybook works
Point at the data, pick a question or type your own, and read the answer as cells that run in the notebook, with every choice behind it on chips. The parts below are interactive replays of the prototype on its demo data.
- 1Drag a variable or a column onto a cell, or click it and then the cell, to get questions about it.
- 2Code, Bench and Map: three views of one notebook, from each line to the whole analysis.
- 3Question this text: each number that the text states, with the output that shows it.
- 4Chips: the values that the result depends on, coloured by where each one comes from.
- 5Drag across a plot to ask about the rows in a region.
- 6The Exploration panel counts the questions by type, and suggests what to ask next.
§1 The idea
A notebook view built around questions
Whybook opens any .ipynb file as a second view, in JupyterLab or in Jupyter Notebook 7. Both views share one notebook model and one kernel, so an edit in one shows in the other. Agents do most of the work, under one rule: the result is an ordinary notebook, and the questions, choices and assumptions go into its metadata. The analyst chooses how deep to go on each cell: its question, the choices on its chips, or its code.
Drag or click
Ask by pointing at the data
Anything in the Variables and Contents panels can be dragged onto a cell, a variable or a column, and so can files and database tables. Whybook lists up to 12 ranked questions of , each with in the notebook.
Questions from templates show at once, and most of them run code with no model call: a template is code written in advance, with the selected names filled in. For those marked , an AI writes the code. A connected model adds up to 5 questions of its own a few seconds later. Above the questions, a box takes .
Dragging is optional: in Click mode the analyst clicks the source, then the target, or uses the keyboard. The modes change which questions rank first: Wonder is for finding what else is in the data, Do for carrying the analysis on, and Report for building what goes into a report.
What the prototype offers when the analyst drags, selects or clicks
IL6column onto cell[5]Add IL6 as a covariateMIN_DAYSconstant onto cell[4]What changes ifMIN_DAYSchanges?sleep_hourscolumn ontopain_scoreAre sleep_hours and pain_score associated, within or between patients?diarydata frame onto itselfProfile diary: types, missingness, duplicates- Weeks 14 to 24 selected on a plotWho is still in the data here, by treatment_arm?
- The text of the SummaryCan each number in this text be recomputed from the data?
patientsdata frame onto cell[5]Screen every column of patients against this cell's outcomevisitsSQLite table onto cell[5]Join the per-patient_id means of visits to model_data- Cells
[4]and[5]selected on the mapIs the trajectory in [4] what [5] estimates? - Bar
Aclicked on a bar plotIs treatment_arm A different from treatment_arm B by more than chance?
Decision chips
Every choice in plain sight
After a cell runs, Whybook reads its code against the live kernel and lists the values that the result depends on. Each value becomes a short chip, its name and its value, such as MIN_DAYS 14, or inner join ×2 for two merges that keep pandas' default. The colour shows where the value comes from, and the tooltip describes what the value does. Constants defined in imported files are shown on the cell that uses them.
MIN_DAYS = 14 is set in prep.py. It leaves out 27 of 318 patients, and no cell sets it. Drop MIN_DAYS onto cell [4] and Whybook re-runs [4] with 7, 14 and 21 in a branch.
- x
- Written in the notebook's code: by the analyst, a colleague, or an agent outside Whybook.
- xAI
- Chosen by the AI model that wrote the cell in Whybook.
- x
- Not set in the notebook: a parameter left at the library's default, or a constant from an imported file that no cell sets. The tooltip shows which.
31MIN_DAYS = 14
32
33
34def drop_sparse(df, min_days=MIN_DAYS):
35 """Keep patients with at least ``min_days`` diary days."""
36 keep = df.groupby("patient_id").size() >= min_days
37 return df[df["patient_id"].isin(keep[keep].index)]
What changes if MIN_DAYS changes?
Model check
branch| MIN_DAYS | weekly rows | patient_ids | mean pain_score |
|---|---|---|---|
| 7 | 5,868 | 307 | 2.324 |
| 14 | 5,837 | 291 | 2.309 |
| 21 | 5,837 | 291 | 2.309 |
The prototype's output. With 14 or 21 days, 27 of the 318 patients are left out. With 7 days, 11 are.
Plot selection
Question the result
Every mark of a plot drawn by Whybook's helpers maps to rows of its data frame. A selection on the plot shows how many rows it holds, what differs there, and questions about it. The analyst can keep the selection as a variable and drag it like any other.
Try it: drag across the plot. This is the plot of the demo's cell [4], weekly pain per patient by treatment arm, with bootstrap intervals. The numbers next to the plot are computed from the plot's data the way the prototype computes them.
Drag across the plot to select weeks. Every mark maps to rows of weekly.
Markdown cells
Question the writeup
The text of a markdown cell shows in each of Whybook's views of the notebook, and it can be questioned like a result. Whybook first lists each number the text states, with the outputs that show it, rounded as the text rounds it. A number that no output shows stands out. Then come the questions, which an agent answers with the cells they need after the text. Words selected in the text are the subject of the questions instead.
Try it: the panel shows the questions about the words "by 0.32 points more per month", marked in the summary. Select other words to question them instead, or press Question this text. This is the summary of the demo after six more hours of analysis, and the matches are the ones the prototype finds in its outputs.
Pain falls over the six months in both arms, faster in arm B, by 0.32 points more per month, and the difference holds without site east and for each value of MIN_DAYS. More patients stop keeping the diary in the first 12 weeks in arm A (26%) than in arm B (9%), so the patients who stay are not a random half of either arm. Of the 4,812 proteins, only NGF tracks how fast pain changes once the false discovery rate is controlled.
Shift+drop, Alt+drop
Branch in parallel, keep one line of cells
Shift+drop turns any question into a branch. Alt+drop starts several branches at once. Whybook calls each one a parallel run: underneath, each branch runs in its own kernel subshell (Jupyter Enhancement Proposal 91, in ipykernel 7), so branches run in parallel on the same data without copying it.
The notebook stays a single list of cells. The Code view shows the cells as the notebook does, branches included. There is no reactive execution: an edit to a cell does not re-run the cells after it.
Weekly pain per patient, by arm
AssociationMIN_DAYS = 14 change the result of [4]?Does MIN_DAYS = 14 change the result of [4]?
Model checkbranchWhat changes if MIN_DAYS changes?
Model checkbranchMake MIN_DAYS an explicit choice in this cell
Model checkbranchMixed model: does arm change the trajectory?
Model checkOrdinal model
Model checkbranch- [1] Tools and the shared prep module
- [2] Load the diary, the patients and the protein panel
- [3] One row per patient-day
- [4] Weekly pain per patient, by arm
- [4b] Does
MIN_DAYS=14change the result of [4]? branch of [4] - [4c] What changes if
MIN_DAYSchanges? branch of [4] - [4d] Make
MIN_DAYSan explicit choice in this cell branch of [4] - [5] Mixed model: does arm change the trajectory?
- [5b] Ordinal model branch of [5]
Answers by an agent
One question, as many cells as it needs
When a question needs AI and its answer goes into a new cell, an agent answers it in the notebook. It adds and runs the cells that the question needs, reads what each one shows, and compares choices side by side as branches that run in parallel, such as another model or another subset. It ends with an answer of a few sentences that links the cells that show it, and with follow-up questions. When one cell is enough, it writes one, and code too long for a cell goes into a module next to the notebook.
Each cell goes into the notebook as it runs, marked as written by AI, with the choices in its code on chips. Stop ends the run, and one click removes its cells, with an Undo. With the data kept on this machine, the agent reads what local models wrote about each table, and only the kind and size of other outputs, never their values.
Code, Bench and Map
See the whole analysis, then the lines that matter
Whybook shows one notebook in three views. The map draws the cells and the data frames they use as a graph. The bench shows each cell as a card with its title, its chips and its outputs, and Show code opens its code. The Code view shows every cell as the notebook does. Within each view, the Detail slider sets how much of each output shows, down to a tile with its size and a label.
An agent, Whybook's or any other, does not tire after a hundred cells. The analyst still has to understand those cells, and chooses what to understand, and how deeply. The map shows the whole analysis, the bench each step, and the Code view each line. This is the order of Ben Shneiderman's Visual Information-Seeking Mantra: "Overview first, zoom and filter, then details-on-demand".
In a long notebook, the analyst finds a cell on the map: a double-click on its card shows the cell on the bench. With the setting Minimap on, a minimap in the corner of the bench opens the map again.
Try it: switch between the views, each in a box of the same size, move the Detail slider, and double-click a card on the map.
Pain diary cohort
Does treatment arm B change how pain evolves over the first six months? The data is synthetic, made for the Whybook demo.
Load and reshape
import whybook
import pandas as pd
import statsmodels.formula.api as smf
from prep import MIN_DAYS, drop_sparse, load_diary_raw, load_olink, load_patients, to_longdiary_raw = load_diary_raw()
patients = load_patients()
olink = load_olink()diary = to_long(diary_raw)
diary.head()Shape
weekly = (
diary.pipe(drop_sparse)
.merge(patients[["patient_id", "treatment_arm"]], on="patient_id")
.groupby(["patient_id", "treatment_arm", "week"], as_index=False, observed=True)["pain_score"]
.mean()
)
whybook.ribbon(weekly, x="week", y="pain_score", by="treatment_arm", ci="bootstrap", n_boot=1000)Model
model_data = weekly.merge(patients[["patient_id", "age", "site"]], on="patient_id", how="left").assign(
month=lambda d: (d["week"] - 1) / 4.345
)
lmm_fit = smf.mixedlm(
"pain_score ~ treatment_arm * month + age",
data=model_data,
groups="patient_id",
re_formula="~month",
missing="drop",
).fit()
lmm_fit.summary().tables[1]from statsmodels.miscmodels.ordinal_model import OrderedModel
ordinal_data = model_data.assign(
pain_level=pd.cut(model_data["pain_score"], [-1, 3, 6, 10], labels=["mild", "moderate", "severe"]),
arm_b=(model_data["treatment_arm"] == "B").astype(int),
)
estimates = []
for i in range(40):
whybook.progress(i / 40, f"bootstrap {i + 1} of 40")
sample = ordinal_data.sample(frac=1, replace=True, random_state=i)
fit = OrderedModel.from_formula("pain_level ~ 0 + arm_b * month + age", sample, distr="logit").fit(method="bfgs", disp=False)
estimates.append(fit.params["arm_b:month"])
whybook.progress(1.0, "done")
ordinal_arm_month = pd.Series(estimates, name="arm B × month (log odds)").describe()
ordinal_arm_monthDoes treatment arm B change how pain evolves over the first six months? The data is synthetic, made for the Whybook demo.
| Row | patient_id | diary_day | week | pain_score | sleep_hours | analgesic_use | cycle_day | bleeding | mood | notes |
|---|---|---|---|---|---|---|---|---|---|---|
| 0 | P001 | 1 | 1 | 2.0 | 7.4 | none | 17 | False | 4.0 | |
| 1 | P001 | 2 | 1 | 2.0 | 7.5 | none | 18 | False | 5.0 | |
| 2 | P001 | 3 | 1 | 2.0 | 8.4 | none | 19 | False | 4.0 | |
| 3 | P001 | 4 | 1 | 3.0 | 7.6 | none | 20 | False | 4.0 | |
| 4 | P001 | 5 | 1 | 2.0 | 7.3 | none | 21 | False | 5.0 |
| Term | Coef. | Std.Err. | z | P>|z| | [0.025 | 0.975] |
|---|---|---|---|---|---|---|
| Intercept | 5.009 | 0.355 | 14.113 | 0.000 | 4.313 | 5.705 |
| treatment_arm[T.B] | -0.857 | 0.160 | -5.359 | 0.000 | -1.170 | -0.544 |
| month | -0.750 | 0.036 | -20.595 | 0.000 | -0.821 | -0.679 |
| treatment_arm[T.B]:month | -0.318 | 0.050 | -6.383 | 0.000 | -0.416 | -0.221 |
| age | -0.003 | 0.009 | -0.281 | 0.779 | -0.021 | 0.016 |
| patient_id Var | 1.751 | 0.211 | ||||
| patient_id x month Cov | -0.250 | 0.051 | ||||
| month Var | 0.152 | 0.020 |
Exploration panel
Make it feel like a game
Analysis tools have to be fun to use, or analysts take the lowest-effort route and ask a chat. In web design, language models gave people new room to explore, and many of them are happier for it.
Work in progress always has a progress bar. The Exploration panel counts each question by type once its answer has run, apart from those that failed. It also counts guesses: while a cell about a relation or an effect runs, the analyst can say with one click what they expect, such as higher or lower. The panel fills a square for each column, Series or array that the analysis has used, and suggests what to ask next, with the reason. Once a causal question is asked, and while fewer than 15% of the questions are causal, the panel shows the note "Few causal questions so far: the effect estimate rests on untested paths."
The panel rewards questions of one's own. A question the analyst types counts in a darker shade than one picked from the offers, and a column reached only through offered questions gets a lighter square. The box for a question of one's own sits above the suggestions, and the setting "Offered questions per request" at None hides the offers, so that every question is typed.
Writing one's own questions helps understanding
Across 26 studies, students taught to write questions about what they read understood new texts better.1 In a tool for data, a display of the columns already covered doubled the questions that analysts asked, and raised their main findings from 5.2 to 7.6 each.2 The kind of question counts more than their number: in tutoring, students who asked a larger share of "why" and "how" questions had higher exam scores, and students who asked more questions did not.3
A count on screen makes people do more of what it counts, and the extra work is not always better,4 so we weigh four designs before any reward grows.
Try it: type a question of your own, or press Ask on a suggestion, and watch the counts change. The panel starts from the demo notebook's state after Run all.
Darker: questions you typed. Lighter: questions you picked.
Sources for this block
- The median gain was 0.36 standard deviations on standardized reading tests and 0.86 on tests the researchers wrote, from grade 3 to college (Rosenshine and others, 1996). Writing questions helped no more than answering someone else's (Weinstein and others, 2010). ↩
- 20 business students, 60 minutes each: 18.7 questions against 9.7, and 7.6 correct top-level findings against 5.2 (Sarvghad and others, 2017). When findings could be checked against the model that made the data, over 60% of those from open exploration were false (Zgraggen and others, 2018). ↩
- 27 college students in tutoring: exam scores went with the share of deep questions (r = 0.47), not with their number (r = -0.56 and -0.12) (Graesser and Person, 1994). ↩
- A count on screen: more pictures coloured, rated less creative (Etkin, 2016). Where the counted activity helps learning, counting it can help too: badges raised self-testing and exam scores for 701 students (Denny and others, 2018). ↩
§2 Prototype
It runs today
The prototype is an extension for JupyterLab 4.4 and later, on a laptop or on JupyterHub, with a Jupyter server extension. Its demo is a synthetic clinical cohort: a daily pain diary, patient characteristics, a protein panel and a SQLite database of clinic visits. A second copy of the demo shows the notebook after about six more hours of analysis, with 28 cells, larger tables and a written summary.
Watch it work
Each video is one recorded session in JupyterLab, on public data, with a live AI model. Start with the 4-minute demo: a validator checks a notebook that someone else wrote. Or watch a whole analysis, from the raw file to the answer.
A model developer hands over a credit scorecard notebook (today, often written with an AI agent), and a validator checks it in Whybook. The chips on the model's cell show the settings that the code never wrote. A click on a chip reruns the cell with another value, in a branch. An agent writes the same model in R, and Whybook compares every estimate with R's. The data are 30,000 card holders of a bank in Taiwan; the scorecard notebook was written for this video.
Chapters
A whole causal analysis of 1,629 US smokers weighed in 1971, and 1,566 of them again in 1982: the codebook, a question about a plot, an agent's comparison of who quits and who does not, the adjusted effect checked by three methods, the 63 people with no weight in 1982, and the same models in R.
Chapters
- 0:00 The question
- 0:33 The data (a CSV and its codebook)
- 1:45 The outcome (a column dropped on itself)
- 2:26 Who gained the most? (a selection on a plot)
- 2:58 The simple comparison (one column dropped on another)
- 3:39 Who quits? (an agent)
- 4:49 The adjusted effect (a user question)
- 6:04 Squared terms (a user question)
- 6:25 Two more methods (parallel branches)
- 7:21 Did the weighting work? (a user question)
- 7:51 The quitters' own gain
- 8:15 The missing outcomes
- 9:13 Men and women (a user question)
- 9:40 The same answer in R? (another kernel)
- 11:03 The whole analysis (the map and the notebook)
- 11:31 The answer
A whole analysis of the CDC's 2025 survey of 10,710 high school students, with the survey's weights: shares checked against the CDC's own tables, the assumptions drawn as a causal diagram, an adjusted ratio, and a negative control: a check that should not find a link.
Chapters
- 0:00 The question
- 0:43 The data (a CSV and its codebook)
- 1:37 Sad or hopeless (a column dropped on itself)
- 2:34 Social media (a selection on a plot)
- 3:29 The simple comparison (one column, then another)
- 4:33 What else could explain it? (an agent)
- 5:25 The assumptions, drawn (a causal diagram)
- 6:36 The adjusted ratio (a user question)
- 7:29 A third of the students left out
- 8:02 Girls and boys
- 8:33 More use, more sadness?
- 9:05 A check that should not find a link (a negative control)
- 9:45 The whole analysis (the notebook)
- 9:59 The answer
Another application: home energy use
A second example, from another field: 360 homes, their electricity meters, and a time-of-use tariff that a quarter of them chose. Nothing in Whybook is specific to either example.
How Whybook fits into Jupyter
Whybook is one Python package with two parts: an extension for JupyterLab in the browser, and an extension for the Jupyter server. It needs no kernel and no file format of its own: the notebook's kernel runs the cells, and the sandboxed kernel that it adds is ipykernel in a sandbox.
When the analyst drags a column onto a cell, the browser part asks the server part for questions. Once the analyst picks one, the server part writes or edits its code, the browser part runs that code in the notebook's kernel, and the result is saved in the .ipynb file.
-
In the browser
JupyterLab extension
Three ways to show a notebook: Code, Bench and Map. The panels Variables, Contents, Questions, Exploration and Cell details. Cell details shows all that Whybook knows of one cell, in one place: the cell that the analyst worked on last, or the one picked on the map. A Databases panel sits under the file browser.
-
In the Jupyter server
Server extension
Questions from templates, ordered by the rules and a small learned ranker, or by a model of the analyst's choice. Code edits on the syntax tree. Local models through llama.cpp, and the review guard. Calls to the models of the AI provider that the analyst connects, with a default cost cap of $0.50 on each call and $2 on each run of an agent, where the price is known. SQLite files, read-only.
-
The notebook's own
Kernel
The main shell runs the cells. Subshells run branches at the same time, and list variables while a cell runs.
-
On disk
The .ipynb file
Cells and outputs, as in any notebook. The whybook metadata keeps each cell's question, assumptions, decisions and branch, so the notebook opens as it was left, and the version of its layout, so later releases can migrate it.
Whybook builds on these parts of Jupyter and adds its own, such as the questions, the AI models and the kernel sandbox. Why Jupyter shows what each part of Jupyter gives it.
§3 Install
Try the prototype
Whybook is on PyPI, and its code is at openteams-ai/whybook. Install it into the environment of your JupyterLab:
pip install "whybook[kernel,demo,models]"
python -m whybook.demo pain_diary
jupyter lab pain_diary/pain_diary_cohort.ipynb
Add local for the models that run in the Jupyter server: pip builds llama-cpp-python with the system's C++ compiler, in about 4 minutes, and each model is a download of 1.6 to 7 GB.
The second command writes three files of the installed release into the folder pain_diary: the notebook, prep.py and clinic.sqlite. The notebook imports its helpers and data from prep.py. In JupyterLab, choose "Open Notebook in Whybook" in the command palette. The first time, Whybook asks which of three ways to use models: pick one, or press Decide later. Then press Run all. The run takes under a minute. The demo after six more hours of analysis is on GitHub, and it opens with its map and panels before anything runs. Questions marked "needs AI", and questions that the analyst types, need a model connected in the AI models panel: OpenRouter after a sign-in, a Hugging Face access token, an API key of Anthropic, OpenAI, Google or Mistral AI, or a model server on this machine. Until one is connected, Whybook greys those questions and shows what to set up. With the setting "Keep data on this machine", no tables, printed outputs or pictures leave the machine.
Known gaps
- R and other languages. In an R kernel, branches run one after another, questions about plots need a Python kernel, and a model writes the code of every answer. In a kernel of another language, such as SAS, cells run and their outputs show, with no variables and no questions. Planned after v1
- Databases. The Databases panel opens SQLite files only: tables from PostgreSQL, MySQL and other servers cannot be dragged onto a cell. Planned for the alpha
- JupyterLite. JupyterLite has no server, so there Whybook opens notebooks and runs their cells with the questions turned off. Planned after v1
- The sandbox. The sandboxed kernel runs on Linux and macOS, not on Windows, where JupyterLab inside WSL2 gets the Linux sandbox (planned after v1). It has no network, so packages cannot be installed into it (planned for the beta).
![A cell with a table of pain by arm, and under it the agent's run for the question 'Does the fall in pain over the weeks differ by arm?': three steps with the cells they added, [3], [4], and the branches [4b] and [4c], an answer that links them, and two follow-up questions. The agent's first cell, a table of mean pain by week and arm, follows.](img/roadmap/agent-strip.png)