Whybook

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.

§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

  • IL6 column onto cell [5]Add IL6 as a covariateModel checkedit [5] in place
  • MIN_DAYS constant onto cell [4]What changes if MIN_DAYS changes?Model checkbranch of [4] · runs in parallel
  • sleep_hours column onto pain_scoreAre sleep_hours and pain_score associated, within or between patients?Associationnew cell
  • diary data frame onto itselfProfile diary: types, missingness, duplicatesData qualitypreview only
  • Weeks 14 to 24 selected on a plotWho is still in the data here, by treatment_arm?Data qualitynew cell after [5]
  • The text of the SummaryCan each number in this text be recomputed from the data?Data qualityafter §8 Summary · needs AI
  • patients data frame onto cell [5]Screen every column of patients against this cell's outcomeAssociationnew cell after [5]
  • visits SQLite table onto cell [5]Join the per-patient_id means of visits to model_dataDescriptivenew cell after [5]
  • Cells [4] and [5] selected on the mapIs the trajectory in [4] what [5] estimates?Model checkedit [4] · needs AI
  • Bar A clicked on a bar plotIs treatment_arm A different from treatment_arm B by more than chance?Associationnew cell after [17]

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.
[4]

Weekly pain per patient, by arm

Association
prep.py § drop_sparse()line 31
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)]
[4c]

What changes if MIN_DAYS changes?

Model check branch
MIN_DAYSweekly rowspatient_idsmean pain_score
75,8683072.324
145,8372912.309
215,8372912.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.

pain_score by week

Drag across the plot to select weeks. Every mark maps to rows of weekly.

The data of the plot pain_score by week, for arms A and B

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.

[4]

Weekly pain per patient, by arm

Association
Branch of [4] · runs in parallelDoes MIN_DAYS = 14 change the result of [4]?
[4b]

Does MIN_DAYS = 14 change the result of [4]?

Model checkbranch
done
[4c]

What changes if MIN_DAYS changes?

Model checkbranch
done
[4d]

Make MIN_DAYS an explicit choice in this cell

Model checkbranch
done
[5]

Mixed model: does arm change the trajectory?

Model check
[5b]

Ordinal model

Model checkbranch
Parallel 0/8Python 3 (ipykernel)

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.

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.

A run answered by the screenshot script: the cells ran in the kernel, and the script wrote the steps and the answer.

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.

[4]
Weekly pain per patient, by armAssociation
MIN_DAYS 14 inner join ci bootstrapAI n_boot 1000AI
[5]
Mixed model: does arm change the trajectory?Model check
reml True left joinAI re_formula ~monthAI missing dropAI
[5b]
Ordinal modelModel checkbranch
bins [-1, 3, 6, 10]AI distr logitAI

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.

Questions asked5

Variables explored
1subanalysis
1open assumption
0guesses
Worth asking nextsuggested

Sources for this block
  1. 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). ↩
  2. 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). ↩
  3. 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). ↩
  4. 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

  1. 0:00 The task
  2. 0:40 The developer's notebook
  3. 0:57 Run it as written
  4. 1:31 Is it the penalty? (a chip's what-if)
  5. 1:55 The same model in R (another kernel)
  6. 3:19 Let it converge (the limit's what-if)
  7. 3:57 The answer
Weeks 14 to 24 selected on the plot of cell [4]: the rows behind the selection, one line on what differs there, and questions about it. The field at the top takes a question of one's own.
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.

The cell that joins each day to its home and its weather shows two constants that energy.py sets and no cell names: BASE_TEMP_C 15.5 and MIN_COVERAGE 0.9. It also shows inner join ×2: both of its merges keep pandas' default.

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:

Shell
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).

What comes next: the roadmap to v1