# Running Next-Concept Modeling in the browser

Source: https://yasirurangana.com/articles/ncm-in-the-browser

A Sudoku solver and a story writer that draft the whole answer, then refine it, running on your own device.

[Try the demos](https://ncmlab.vercel.app) · [Source](https://github.com/yrangana/ncm-lab) · [Paper](https://arxiv.org/abs/2610.14162) · [4-bit model](https://huggingface.co/yrangana/ncm-lab-models)

Open the [Sudoku demo](https://ncmlab.vercel.app/sudoku/) and press Solve. The model fills all 81 cells in its first pass, most of them wrong, then fixes them over 11 more passes.

![Four Sudoku grids from one ncm-lab run. Pass 1 has 66 wrong cells, pass 4 has 60, pass 8 has 36, and pass 12 is solved.](https://yasirurangana.com/images/articles/ncm-sudoku-passes.svg)

*One run of the easy model. Red cells are wrong. Bold digits are givens it got right; the first pass gets 33 of the 40 givens wrong.*

Most language models write one token at a time and never change what they wrote. Next-Concept Modeling (NCM), from Hazy Research at Stanford ([Kumbong et al., 2026](https://arxiv.org/abs/2610.14162)), drafts the whole answer first and then refines it.

## How it works

Each pass covers the whole answer in more detail than the last. The story model goes from 1 token to 8, 16 and up to 128 over 12 passes.

![Two charts. A standard model writes a 128-token story one token at a time, in 128 steps. NCM writes the whole story on every pass, in 1, 8, 16 and up to 128 pieces, over 12 passes.](https://yasirurangana.com/images/articles/ncm-concept.svg)

*The story model's real pass sizes. Equal-width pieces are a simplification.*

The method and checkpoints are theirs. I built the demos so anyone can run them in a browser instead of on a GPU server.

## Running it in the browser

The public ONNX exports by [mrfakename](https://huggingface.co/mrfakename/ncm-webgpu-weights) put all 12 passes in one graph. One call returns every pass, and the page plays them back.

The demos use onnxruntime-web, on WebGPU or the CPU. There is no server. On my GPU a Sudoku takes 0.1 to 0.2 seconds and a story about 0.2. On a CPU it takes a few seconds.

## Sudoku

The checkpoints expect puzzles with one solution, so the demo generates its own. On 50 puzzles per level they solved 49 easy, 49 medium and 42 hard in my runs.

## Stories

The story model was trained on TinyStories, short stories for young children. One story at four of its passes:

**Pass 1** (1 token): a single full stop.

**Pass 4** (24 tokens)

> Once was big A Amy special Mom?" and! it". " then saidJo two,ushed He..

**Pass 8** (64 tokens)

> upon a, was big It was empty! little Amy wanted create special Amy her,Mom can create today mom and,Sure!'s it special special asked " can make thought a moment then,Let something special took two some colorful and some flles. the pieces the pieces paper They some

**Pass 12** (128 tokens)

> Once upon a time, there was a big board. It was so empty it! A little girl named Amy wanted to create something special. Amy asked her mom, "Mom, can we create today?" Her mom smiled and said, "Sure! Let's make something special for it special." Amy asked, "How can can we make?" Amy thought for a moment and then said, "Let's create something special". She took two pieces, some colorful paper, and some shiny flushles. They placed the colorful pieces of the down paper onto the paper. They put some

It has no prompt input, so you can't ask it for a story about a dragon. The demo writes up to 10 drafts and keeps the first that uses your word. Some words almost never come up.

![Bar chart of 16 words and how many of 40 random stories used each. Friend 19, mom 13, park 9, toy 8, tree 6, car 6, dog 5, ball 4, cat 3, bird 3, sun 3, cake 1, fish 1, princess 0, dragon 0, rain 0.](https://yasirurangana.com/images/articles/ncm-topics.svg)

*How often each word came up in 40 random stories.*

## Making it fit

The story model is 573 MB. Storing its weights in 4 bits cut it to 258 MB.

| Model | Original | 4-bit | Outcome |
|---|---|---|---|
| Stories | 573 MB | 258 MB | Half the memory, stories read the same. Kept. |
| Stories, 4-bit embeddings | 573 MB | not kept | The text broke. Embeddings stay full precision. |
| Sudoku | 138 MB | 9% less memory | Ran slower. Kept the original. |

Loading the 4-bit story model takes about 1 GB of memory, four times the file size. Older phones close the tab, so the page warns phone users first.

## Next

A Sinhala to English translator: a small NCM, about 100 million parameters, compared with a standard model of the same size. Then more puzzles: nonograms, KenKen and timetables.
