An fMRI decoder writes English from a brain scan: a language model proposes words, a brain model scores each guess against the scan, and a beam keeps the best. It recovers the gist of heard stories.
Learn how Tang, LeBel, Jain and Huth (2023) turned slow blood-flow images into running text, and exactly where the method works, where it fails, and why.
Pick a method, drag the scan noise, and press New scan. Watch which words each method recovers. Then we build, piece by piece, the encoding model, the likelihood, the language prior, the word rate model and the beam search.
You need what a probability is and a little linear algebra (a list of numbers is a vector). We build the rest from zero.
Paper: Jerry Tang, Amanda LeBel, Shailee Jain and Alexander G. Huth, “Semantic reconstruction of continuous language from non-invasive brain recordings”, Nature Neuroscience 26, 858 to 866 (2023), doi 10.1038/s41593-023-01304-9; open manuscript at PubMed Central; code at HuthLab/semantic-decoding. Every idea is re-taught here in our own words and devices. It is a reading of the lecture LLMs and the Language Brain.
A toy world, not the paper’s data: 19 words, one word per brain image, a made-up encoding model (each image mixes the current word and the one before it) with Gaussian noise, a five slot grammar as the language model, and a beam of 12. The paper’s own scans are 2 s apart with several words in each. The three methods differ exactly as in the paper: no brain data, no language prior, or both.
Chapter 0
See why one brain image holds the echo of twenty words, and why that forces a decoder to guess, predict and compare
Picture a person lying still in a large magnet. Through headphones, a storyteller talks about a hot summer and a ruined plan. Every 2 seconds the scanner takes a picture of the person’s brain. After the story, you get only the pictures. Your job: write down what the person heard.
That is the task of this paper. The scanner is an fMRI machine (functional magnetic resonance imaging). It does not touch the head and needs no surgery. The authors (Tang, LeBel, Jain and Huth, University of Texas at Austin) ask whether such pictures hold enough to write out a story, word after word.
When a patch of brain works harder, the body sends more blood to it. The blood carries oxygen, and oxygen changes the local magnetic signal. The scanner reads that change. It is called the BOLD signal (blood-oxygen-level-dependent). It is a stand-in for neural activity, like judging how busy a kitchen is by watching the delivery trucks.
The scanner cuts the brain into small cubes called voxels (3-D pixels). In this paper a voxel is 2.6 mm on each side. The scanner needs TR = 2.00 s (repetition time) to photograph the whole brain once. So you get one list of voxel values every 2 seconds, and nothing in between.
The picture is sharp in space. Its trouble is time. The paper puts it plainly: after a burst of neural activity, the BOLD signal rises and falls over about 10 seconds.
Now count. People tell stories at a bit over two words per second. Every word sets off its own slow wave of blood flow. A wave lasts about 10 seconds. So one image is touched by the waves of every word spoken in the last 10 seconds.
2 words per second × 10 seconds = 20 words echoing in one image
Think of a bell struck twice a second. Each strike rings for ten seconds. You measure the loudness once every two seconds. From those readings, can you say when each strike happened? Not directly. The rings pile up. Try it below. Drag the speech rate and watch the single image at 14 seconds.
Top: each tick is a spoken word. Middle: each word starts a slow wave of blood flow (thin blue curves). Their sum is the signal the scanner sees (thick curve). Dots mark the scanner’s images, 2 s apart. Drag the speech rate.
Illustrative wave: a smooth bump that peaks 5 s after the word and fades by about 10 to 15 s, so it matches the paper’s statement that BOLD rises and falls over roughly 10 s. The real wave differs by brain region and person. Words are spaced evenly here; real speech is not. The scanner takes one image every 2 s (TR = 2.00 s in the paper).
Notice what the thick curve shows. It is smooth and slow. You cannot see single words in it. You see only a blur of recent speech. This is why the paper calls the task an ill-posed inverse problem. Inverse means we go backward, from effect (brain images) to cause (words). Ill-posed means the answer is not pinned down: there are far more words to find than images to find them in, so many different sentences could have produced the same pictures.
Earlier non-invasive decoders avoided the problem. They took a small menu of words or phrases and picked the one that fit the scan best. That works for a menu of ten. It does not produce a new sentence. Decoders that wrote out speech used electrodes placed in or on the brain, which needs neurosurgery. The paper says the open question was whether fMRI has the spatial and temporal resolution to decode continuous language at all.
Going backward from brain to words is hard. Going forward from words to brain is much easier. If you know the words, you can learn to predict the brain’s response. A detective cannot read a suspect’s face from a smudged fingerprint. But she can take a prints kit, make a print from each suspect, and see which matches the smudge.
The paper does exactly that, in three pieces that this lesson builds one by one:
The result is a sentence that was never on a menu. It usually gets the meaning and sometimes the exact words. The rest of the lesson shows how, how to judge it, what it can and cannot do, and how the authors tested whether someone can resist it.
Chapter 1
Learn a recipe that turns word meanings into the slow signal of one voxel, and fit it with ridge regression
Suppose you recorded one person’s brain for 16 hours while they heard 82 stories. Now someone hands you a new sentence and asks: what will voxel 4,321 do while this person hears it? You have no formula for that. But you have a huge pile of examples: words in, voxel signals out. Fit a recipe to the pile, and the recipe answers.
That recipe is the encoding model. It goes from stimulus to brain. The decoder will later run it forwards on thousands of guessed sentences. This chapter builds it in four moves: describe words as numbers, put them on the scanner’s clock, add delays, and fit weights.
A computer cannot use the letters “river”. It needs numbers that capture meaning. The paper gets them from GPT (the first GPT, a 12-layer language model). The authors feed GPT the current word and the five words before it. GPT turns the text into a list of 768 numbers in each of its layers. They take the list from layer 9 and call it the word’s semantic feature vector.
Why layer 9, and why the five words before? Meaning depends on context: “bank” after “river” differs from “bank” after “money”. And the paper notes that earlier studies found middle layers of language models predict brain responses best. Think of the vector as a meaning card of 768 numbers that GPT writes for each word as it reads.
Words arrive at irregular times. The scanner takes images every 2 seconds. Each story was transcribed by a listener, then a tool called a forced aligner marked the time of every word in the audio, and the authors checked the result by hand. Then a smoothing filter (a 3-lobe Lanczos filter) resamples the cards onto the scanner’s clock. Result: for each image time t, one 768-number vector xt. Stack them: a table X: T × 768 with one row per image.
Chapter 0 showed the problem: a word at time t shows up in the signal later, over several images. So the voxel at time t depends on words from 2, 4, 6 and 8 seconds earlier. The model keeps a separate weight for each delay. This is called a finite impulse response (FIR) model: it learns the voxel’s reaction to a single brief event, at each of a few delays.
In practice you copy the table four times, each copy shifted by one more image, and glue the copies side by side. The table grows from 768 to 4 × 768 = 3,072 columns.
A tiny case with one feature shows the idea. Say a word with feature value 1 arrives at image 3 and nothing else happens. Say the voxel’s four weights are 0.1, 0.5, 0.4 and 0.1 (illustrative). The prediction is 0.1 at image 4, 0.5 at image 5, 0.4 at image 6 and 0.1 at image 7. One brief word becomes a slow bump. Real stories overlap thousands of such bumps, and the model adds them.
Now we need the numbers in W. For each voxel there are 3,072 weights. The recorded stories give about 28,800 images (16 hours at one image per 2 seconds, by simple arithmetic). That sounds like plenty. But each image is noisy, and neighbouring features are tangled. A plain least-squares fit would chase noise.
Ridge regression adds a penalty for large weights. It looks for the weights that minimise squared error plus λ times the sum of squared weights. A bigger λ pulls all weights toward zero. Think of λ as a leash: loose leash fits the training data closely and wobbles on new data; a tight leash gives smooth, cautious weights.
The paper picks one λ per voxel by trial. It repeats 50 times: hold out about a fifth of the images, fit with each of 10 values of λ (log-spaced between 10 and 1,000), and score the prediction on the held-out images with R2 (the share of the held-out signal the prediction explains). It keeps the λ with the best average score. Then it keeps the 10,000 cortical voxels that predicted best. Try the same trade on a toy voxel.
A toy voxel has a true delay filter (outlined bars). We fit it from only 16 noisy training images. Drag λ and watch the fitted filter (purple) and its score on 300 new images.
Toy, not the paper’s numbers: 8 delays instead of 4, one feature instead of 768, and only 16 training images so over-fitting is easy to see. The paper has 3,072 features per voxel and picks λ per voxel from 10 values between 10 and 1,000 by cross-validation. Solved live in your browser from seeded random data.
At a tiny λ, the fit follows the noise in 16 images and the bars jump about. Its score on unseen images is poor. At a huge λ every bar shrinks to nothing and the score falls to zero. Somewhere in between the filter looks like the truth and the held-out score peaks. That is why the paper cross-validates.
Words → GPT layer 9 → T × 768 → resample to image times → add four delays → T × 3,072 → multiply by weights 3,072 × 10,000 → predicted responses T × 10,000. Features and responses are both z-scored (shifted to mean 0 and scaled to unit variance) first, and slow drift in each voxel is removed before fitting. The paper reports that the model predicts responses in most cortical regions outside primary sensory and motor areas.
Chapter 2
Turn the gap between a predicted and a recorded brain response into a probability, with noise measured the right way
You now own a machine that turns words into a predicted brain response. A friend gives you three candidate sentences and a real scan. For each sentence you ask the machine: what would the brain do? You get three predicted responses. The real scan is not equal to any of them. Which sentence fits best?
You need a number for “fits best”. The obvious number is the distance between prediction and recording. The paper does something a little smarter. It turns the gap into a likelihood: the probability that the brain would produce this recording if the candidate sentence were the true one.
Even the right sentence does not give the predicted response exactly. The prediction is a recipe average. The real scan adds noise: head motion, heartbeat, thoughts that wandered. The paper assumes this noise is Gaussian (a bell curve in every direction), added to the prediction. So the recording R, given a sentence S, follows a bell curve centred on the predicted response R̂(S).
Take the logarithm of a Gaussian and the formula becomes simple. Up to a constant, the log-likelihood is minus one half of a squared distance:
log P(R | S) = −½ (R − R̂(S))⊤ Σ−1 (R − R̂(S)) + constant
The middle piece, with Σ−1, is a distance measured with a stretchy ruler. A miss in a noisy voxel counts for little, because noise explains it. A miss in a quiet voxel counts for a lot. Here is a worked case with two voxels. Voxel 1 is noisy (variance 1). Voxel 2 is quiet (variance 0.25).
Try it. Candidates A, B and C below are three predicted responses. The recorded response is the blue dot. Drag the noise and see how the scores change.
Left: two voxels. The blue dot is the recording; purple dots are what the encoding model predicts for sentences A, B and C. The yellow oval is the noise. Right: each sentence’s share of belief. Drag the noise, then switch the language prior on.
Toy numbers, not the paper’s. Two voxels with noise variance 1 and 0.25 times the noise scale squared, and no correlation. The paper uses about 10,000 voxels and a full covariance. The prior percentages are made up to show Bayes’ rule at work.
With low noise, the scan is very sharp about which candidate is closest, and B wins clearly. As noise grows, the oval swallows A and B alike, and the scan can no longer tell them apart. That is exactly where the language prior from the next chapter decides.
What we want is P(S | R): how probable a sentence is given the scan. Bayes’ rule flips the conditional:
Multiply the two and rescale so the shares add up to 100%. In the device, turning the prior on lifts A over B even though B fits the scan slightly better. Real sentences differ in plausibility by factors of millions, so the prior is a strong guide.
The covariance Σ has one row and column per decoding voxel, so about 10,000 by 10,000. The simple way to estimate it is to take the encoding model’s errors on its own training data. The paper explains why that fails: the model has already learned part of the training noise, so the errors look too small. Underestimated noise makes the decoder overconfident.
So the authors use a bootstrap. They hold out one story, fit the encoding model on all the others, and measure the errors on the held-out story. They repeat for each story and average the error matrices. These errors are honest, because the model never saw that story. A shrinkage factor α then regularises the matrix. The paper says a poorly chosen α makes the decoder less semantically correct: too small overestimates the true noise, too large underestimates it.
Chapter 3
Use a language model to offer only sensible next words, so the brain scorer checks a handful instead of thousands
Suppose the decoder has guessed “we walked to the” so far. A new word is due. The brain scorer from Chapter 2 can judge any single guess. But which words should it judge? The decoder’s vocabulary has 6,867 words. Longer stretches are far worse: the number of word strings grows by a factor of 6,867 with every word added. Almost all of those strings are gibberish, such as “the of purple walked”.
The paper needs a guide that knows what English looks like. That guide is a language model: a program that gives every possible next word a probability, given the words before it. It is a bit like your phone’s keyboard suggestions, but far better. (Our sampling and decoding lesson and GPT lesson build one from zero.)
A language model scores a full sentence by the chain rule of probability. It multiplies the probability of each word given all the words before it:
This is the same P(S) that appeared in Bayes’ rule in Chapter 2. The paper’s decoder uses GPT for it: the original 12-layer GPT, which the authors fine-tuned on two text sets. One is Reddit comments (over 200 million words). The other is 240 autobiographical stories from The Moth Radio Hour and Modern Love (over 400,000 words) that were not used for decoder training or testing. Training ran 50 epochs with a maximum context of 100 words.
This choice has an effect worth naming. The decoder can only write what a language model could plausibly write. It makes up new sentences, but ones that read like English. The paper credits two ideas for the whole method: an autoregressive prior that generates new sequences, and a beam search that finds the best ones.
During decoding the language model never sees the brain. It reads the last 8 seconds of words in one candidate and returns a probability for each of the 6,867 vocabulary words. (The vocabulary is every word that occurs at least twice in the encoding model’s training stories.) The probabilities are rescaled to sum to 1. Then three rules trim the list:
Each surviving word is attached to the candidate to make a continuation. Only continuations go to the brain scorer. Here is a toy next-word list for “we walked to the”. Move the two dials and the filter to see which words survive.
Bars are a toy language model’s probabilities for the next word. Warm bars reach the brain scorer; grey bars are dropped. Move the mass and the ratio.
Toy probabilities, made up for this page (they add to 100%). The paper gives the rules (a mass p, a ratio r relative to the most likely word, and a repeat filter) but its settings were tuned by grid search and by hand on a separate calibration story; I do not print them here. In the paper the list has 6,867 words, not 10.
Slide the mass down and fewer words survive: the proposals become safe and similar. Raise it and unlikely words get through, which gives the brain scorer more room to find an odd but correct word. The ratio rule cuts the tail even when the mass is high. The paper reports that these settings matter. It says r set too small makes the decoder less linguistically coherent, and r set too large makes it less semantically correct.
A beam of 200 candidates and 6,867 words would mean 200 × 6,867 = 1,373,400 brain scores per step. Trimming each candidate’s list to its nucleus cuts that by a large factor. The savings are also a safeguard: the decoder cannot output nonsense, because the brain scorer only ever sees plausible English.
Responsibility is split cleanly. The language model supplies grammar, flow and common sense. The scan supplies the meaning that fits this particular person at this particular moment. Neither one alone is enough. The hero at the top of the page shows this: the language model alone writes fluent but random sentences, and the brain alone writes words that do not belong together.
Chapter 4
Predict how many words fell in each 2 second image, then spread them out in time so the decoder knows when to add a word
You are the decoder. You have an encoding model, a likelihood and a language model. A new brain image has just come in. A basic question remains: how many new words should you write for it? One? Five? None, because the storyteller paused?
The encoding model and the language model decide what a word is. Nothing yet decides when to add one. Without that, the decoder would not know how long its sentence should be. A slow reader and a fast talker would get the same number of words. The paper solves it with a small separate model that estimates the speech rate from the brain.
The paper defines the word rate at an image as the number of stimulus words spoken since the previous image. If three words fall in a 2 s gap, the word rate for that image is 3. It is just a count, one number per image. In the training stories the true counts are known, because the transcripts have the time of every word.
The word rate model is another regression. It takes the brain responses and predicts the count. Two design choices matter.
Which voxels. For perceived speech, the model uses only the auditory cortex, the area that hears. Hearing tracks the sound of speech, which has a rhythm. For imagined speech and for silent films there is no sound to hear. There the paper uses Broca’s area and the superior ventral premotor speech area, which are active when a person plans speech. The authors found these areas by having each subject do listening and movement tasks in the scanner.
Which images. The effect of a word reaches the brain image later (Chapter 0). So to know the count at time t, the model looks at images from the future: those taken 2, 4, 6 and 8 seconds after t. This mirrors the encoding model, but backward in time.
The prediction is a smooth number such as 3.4. A real count is a whole number, so the model rounds to the nearest non-negative integer. Then it spreads that many words evenly through the 2 seconds. Three words in a gap land one third of a gap apart. That gives a list of word times: moments when the decoder is allowed to add a word. Try the four-image example below.
Four brain images cover 8 seconds. Set the predicted word rate for each (bars). The model rounds each to a whole number, then places that many words evenly in its 2 s gap (ticks below).
Illustrative rates. The rounding to the nearest non-negative integer and the even spacing inside each 2 s gap follow the paper’s description; the exact tick positions here (the centre of each equal slice) are my drawing choice. The paper’s model is fit with regularised regression on real voxels, not set by sliders.
The gap with rate 0.3 rounds to zero, so it gets no words. That matches a pause in speech. The gap with rate 4.6 rounds to five words packed into 2 seconds, a burst. The sum of the four rounded counts is the number of words the decoder will write for these 8 seconds.
The authors test the word rate model with a correlation between predicted and true counts across a test story. To see whether the correlation could be luck, they shuffled the true counts in blocks of 10 images 2,000 times and checked how often chance matched the real score. For perceived speech, models fit on auditory cortex beat models fit on frontal speech production areas or on random voxels. For imagined speech there was no significant difference between the regions they compared.
Why keep this model separate? Many scores in Chapter 6 (like word error rate) depend on how many words a sequence has. The authors judged the word rate model apart from the decoder for exactly this reason. When they build chance sequences to test significance, they give them the same word times as the real decoder output. The test then measures only whether the words themselves carry meaning from the brain, not whether the decoder got the speech rate right.
Chapter 5
Assemble the four parts into one loop that grows many candidate sentences at once and prunes them against the scan
You are hiking through a forest of forking paths, and fog hides the summit. At each fork you can send scouts. If you send one scout and always follow the path that looks highest right now, a misleading fork can lead you into a dead end. If you send a handful of scouts along the best few paths, one of them may find the real route. That is the idea of beam search.
The sentence space is the forest. Each fork is a new word. Checking every route is impossible. The paper’s decoder keeps a beam: a list of the k most promising partial sentences, called candidates. Everything you built in Chapters 1 to 4 plugs into one loop.
The paper uses a beam width of k = 200. In preliminary tests, performance rose with the beam width and flattened after 200. Nothing about the scoring uses the true words. The decoder never sees the stimulus; it sees only the scan and its own earlier guesses.
A plain top-200 can fill up with near copies of one sentence. So the paper limits how much one candidate can contribute. A candidate may add at most 5 continuations to the new beam. And the allowance depends on how English-like the candidate already is. The candidates are sorted by their language model probability P(S) into five groups (quintiles). The top group may add 5 continuations, the next group 4, and so on down to 1 for the bottom group. Likely sentences get more room to branch, and every sentence still gets at least one chance.
At one word time, with k candidates and about n proposed words each (n is a few dozen at most, far below the 6,867 vocabulary):
Now run a tiny version on the toy world from the hero. The toy has the same loop (propose from a grammar, score against the scan, keep the best k), but only 5 steps and 4 words per step. Change the beam width and step through the decode.
Rows are the best partial sentences after each word, ranked by brain score. A green outline marks the true sentence, if it is still in the beam. Pick a beam width, then step.
Toy, at scan noise 0.90 (a hard scan). Gap = log score behind the best candidate. In this toy the grammar keeps the language prior flat within a slot, so the score is the brain likelihood alone. The survival rate is measured live on 300 seeded scans. The single best sentence improves only a little with width here (the toy’s signal is short), while the chance that the true sentence is still alive at the end climbs steeply; the paper chose 200 because performance flattened beyond it.
At width 1 the decoder is greedy: it commits to its top word at every step and never looks back. A single noisy image that favours a wrong word kills the true sentence for good. Wider beams keep the doubtful word alive long enough for later images to rescue it. The toy’s weak echo (each image mixes the current and previous word) means later images do carry evidence about earlier words, as they do in real fMRI.
Earlier Bayesian decoders of images and video worked with a fixed library of known stimuli. They scored every item in the library and took the best, or a weighted blend. The paper names two differences. First, the prior here is a generative language model, so the decoder can write sentences that were never in any library. Second, a beam search decides what to score next: the words examined at each step depend on the words already decoded. Together these let it reconstruct structured sequences from a slow signal.
Chapter 6
Measure whether decoded text keeps the meaning, test it against chance, and learn what the headline numbers do and do not claim
A person hears “we were busy”. The decoder writes “we had a lot of work”. Is that a hit or a miss? Only one word matches. Yet a reader would say the decoder understood. Any score for this system has to cope with that gap between the exact words and the meaning.
This chapter shows how the paper scores a decoded story, how it checks that the score is not luck, and what the numbers on the front page really say.
The authors use four standard metrics, each against the actual transcript.
Try the first two on your own text pairs. BERTScore needs a neural network, so the device shows a hand judgment of meaning instead (marked as mine).
Pick a pair, or type your own. WER and word overlap are computed live. The meaning verdict is my judgment for the four presets only.
WER is the word-level edit distance divided by the true length. Overlap is BLEU-1 style: each decoded word counts once if it appears in the true text, never more times than it appears there. The first pair is the paper’s own example of different words with the same meaning; the other three pairs are mine. BERTScore, which the paper uses by default, is not computed here.
The dog and car pair is the warning. It scores a perfect word overlap and still has the opposite meaning. The first pair scores badly on overlap and well on meaning. This is why the paper leans on BERTScore, and why it keeps WER, BLEU and METEOR as well: they show how many exact words came through.
The paper compares text inside a 20 second window around each second of the story, called the window similarity. The average over windows is the story similarity. For the main perceived speech test it used one held-out story of 1,839 words (“Where There’s Smoke”, from The Moth Radio Hour).
Any decoder that writes plausible English will share some words and some topic with a story. To prove the brain contributed, the authors build a null model. It runs the same beam search with the same word times, and draws words from the same language model, but ranks continuations with random numbers instead of brain likelihoods. They repeat this 200 times and get 200 null stories. Then p is the fraction of null stories that score at least as high as the real decoder. They also checked that the null scores are not trivially low: null sequences were more similar to the true story than 62 other unrelated story transcripts were.
Two other yardsticks help. A ceiling shows the best a good system could do: a professional translated the story into Mandarin, and a machine translated it back to English. The back-translation holds the same information but different wording, so its score marks the top that word-overlap metrics can reach. And an identification test asks whether a window of decoded words matches its own true window better than all other windows: 0.5 is chance, 1.0 is perfect.
| Measure | Result (3 subjects) | Where |
|---|---|---|
| Above the null model | Significant for all four metrics, especially BERTScore (q(FDR) < 0.05, meaning the false discovery rate is held under 5% across many tests) | Fig. 1d |
| Time-points above chance (BERTScore) | 72 to 82% | Fig. 1e |
| Identification, mean percentile rank | 0.85 to 0.91 (chance 0.5) | Fig. 1f |
| Reading comprehension from decoded words only | 9 of 16 questions answered above chance by readers of one subject’s decoded words | Extended Data Fig. 3 |
| Word error rate, test story | 0.92 to 0.94 | Discussion |
The comprehension test used 100 online participants. Half read the decoder’s words for four 80 second segments and half read the true words, and all answered four multiple-choice questions per segment. The questions were written without looking at the decoder’s output.
Read the WER of 0.92 to 0.94 honestly. Nearly every word differs from the true one. The paper says the decoder paraphrases: different sentences with similar meaning share semantic features. It compares this to invasive decoders, which need training on multiple repeats of the test stimuli before reaching a WER below 0.8. The authors write that loss of specificity is not unique to non-invasive decoding. The decoder recovers gist, not a transcript.
Chapter 7
Follow the same decoder from heard speech to imagined speech and silent film, then test whether a person can resist it
Suppose a decoder works on speech you hear. Does it also work on speech you only imagine? On a film you watch with the sound off? When someone else’s data trains it? When you try to fool it? The paper runs one decoder through each of these tests. The first group shows where the method is strong. The second group asks who is in charge.
The paper first splits the cortex into three regions: the speech network (auditory cortex plus Broca’s area and a premotor speech area, found with listening and movement tasks), a large parietal-temporal-occipital association region (touch, hearing, vision and meaning meet here), and the prefrontal region (planning). Each region in each hemisphere was decoded alone.
Every region gave decodable language: under the WER and BERTScore metrics, all regions beat chance. The regions differed in how consistently they carried the story. Of the time-points that the whole brain decoded, the association region decoded 80 to 86%, the prefrontal region 46 to 77%, and the speech network only 28 to 59%. The authors think the speech network holds lower-level sound and mouth-movement features, while the decoder works with higher-level meaning.
Predictions from different regions were also more alike than chance. The paper reads this as redundancy: several regions each hold a copy of the word-level meaning. A practical hint follows. A future implant could record from whichever region is most accessible or still working.
The decoder was trained only on heard stories. The authors then used it, unchanged, on other tasks. The key point is in the training target. The encoding model predicts the brain response to heard speech. So the decoder looks for words that would produce the recorded response if heard. Imagined speech and film watching can produce similar meaning signals, so the decoder carries over.
The attention result also means people have control: the decoder follows what you attend to, not everything you hear.
A system that writes down thoughts raises the question: can someone use it on you without your agreement? The paper tests two protections.
Test 1: can you train it on other people? The authors collected data from seven subjects and tried to decode each person with a decoder trained on the others, after aligning their brain anatomy. These decoders recovered only 1 to 2% (volumetric alignment) or 1 to 5% (surface alignment) of time-points, against 65 to 82% for within-subject decoders. So the paper concludes that subject cooperation is needed to train a decoder.
Test 2: can a cooperating person later resist it? While hearing a story, subjects silently counted by sevens, named animals, or told a different story in their heads. Naming animals and telling another story significantly reduced decoding in every region, and focusing on one region did not help. Counting by sevens lowered it by less (4 to 50% of time-points against 52 to 57% for passive listening). So subject cooperation is needed to apply the decoder as well.
Compare them side by side. Choose a group of tests below.
Each bar spans the lowest to the highest value across subjects: the share of time-points significantly decoded (BERTScore, q(FDR) < 0.05: a test that keeps the false alarm rate under 5%). Choose a group.
All numbers are from Extended Data Fig. 5 of the paper, as ranges across subjects (ranges across subjects, as the paper reports them). Experiments differ in length, so the paper compares them by this fraction and not by story score.
Notice what these results do and do not show. They show that the decoder as trained needs the person’s own data and can be thwarted by deliberate mental effort. They do not show that future methods will be as limited. The paper says so directly: future developments might bypass these requirements, and even wrong predictions could be misused. The authors argue for raising awareness of the risks and for policies that protect mental privacy. They also withheld the decoder-resistance data from public release because it could be used to find ways around resistance.
Chapter 8
Separate noisy data from a mis-specified model, and use ablations to see which part of the decoder does the work
A student gets a poor grade. Was the exam hard, was the textbook thin, or did the student study the wrong chapters? You cannot fix the grade until you know. The authors ask the same of their decoder: when a stretch of story is decoded badly, what went wrong? They name three suspects.
The authors trained decoders on different amounts of data. With a single session, the decoder was already significantly above chance. But steady decoding of all parts of the test story needed much more. The score rose by about the same amount each time the data doubled. That is a straight line against a logarithmic axis: more data helps, but each doubling costs twice as many hours as the last.
Extended Data Fig. 7 gives a second view. The fraction of significantly decoded time-points grew up to 7 sessions (7.5 hours) and then flattened, with no large gain up to 15 sessions (16 hours). They also ran a simulation to see whether the diminishing returns came from overlapping samples of the training sessions. It did not: overlapping and non-overlapping samples gave very similar curves.
One scan of a story is a single trial and contains noise. The authors made a cleaner test by averaging responses from different repeats of the same story. Averaging raises the signal-to-noise ratio. The decoding score went up slightly. So some error is noise in the test data, but not most of it.
If noise were the only problem, every word would be equally hard. It is not. The authors scored how well each word was decoded and compared the scores with word properties. Words that are more concrete (tied to sensory or motor experience, like “hammer” rather than “justice”) were decoded better, with a rank correlation of 0.14 to 0.27. Word frequency in the training stories showed no significant link. So the decoder is worse for certain kinds of meaning, and that is a model problem. If the cause were thin training data, rare words would suffer more.
The paper then looks inside the decoder. In an isolated test, they gave the encoding model and the language model the true word plus 100 random distractor words and asked each to rank them. A score of 100 means the true word ranks first; 50 is chance. The encoding model’s scores correlated with the full decoder’s scores (r = 0.22 to 0.58), and the language model’s did not. Poorly decoded stretches are mostly stretches where the encoding model struggles. The authors expect better semantic feature extractors to raise decoding performance a lot.
| Suspect | The test | What the paper found |
|---|---|---|
| Training data | Train on 1 to 15 sessions | Equal gain per doubling; flat after 7 sessions on one measure |
| Test noise | Average repeats of the test story | Slight gain |
| Model fit | Score words by concreteness and frequency | Concreteness correlates (0.14 to 0.27); training frequency does not |
| Which component | Rank the true word among 100 distractors | Encoding model tracks decoding (r = 0.22 to 0.58); language model does not |
An ablation removes one part of a system and sees what breaks. The authors decoded normally up to a cutoff point in the test story. After the cutoff they did one of two things. Either they reset the language context: throw away every candidate and restart the beam from the empty sentence. Or they removed the fMRI data: give every continuation a random likelihood instead of the encoding model’s. Then they watched the score.
A schematic of the paper’s ablation. The line is the decoding score over the story. Choose what happens at the cutoff, marked 300 s. The grey band is the range chance gives.
Schematic only. The curve shapes follow the description of Extended Data Fig. 9: after the context reset the score fell and quickly rebounded, and after the fMRI data were removed it quickly fell to chance. The heights, the timing of the rebound and the noise wiggle are drawn by me, not measured. The 300 s cutoff is the paper’s example for one subject.
Resetting the context hurt briefly and then the score came back, because the next brain images pulled the beam toward the right words again. Removing the fMRI data sent the score down to chance and kept it there. The conclusion is plain: the decoder leans on the scan at every step. It does not need a good start, and it cannot coast on the language model.
Chapter 9
Keep the numbers, the checklist, the core loop as code, and the places to go next
The whole paper fits in one sentence. Fit a model that predicts a person’s fMRI response from the meaning of words; then, for a new scan, let a language model propose word sequences, score each by how well its predicted response matches the scan, and keep the best few at every step. The pieces came one chapter each: slow blood flow (0), the encoding model (1), the likelihood (2), the language prior (3), the word rate model (4), the beam (5), the metrics (6), the task and privacy tests (7) and the error analysis (8).
| Item | Value in the paper | Chapter |
|---|---|---|
| Subjects | 3 for the main analyses; 7 for the cross-subject test | 7 |
| Training data per subject | 82 stories of 5 to 15 min; 15 story sessions; about 16 h | 1 |
| Scanner | 3T, TR = 2.00 s, 2.6 mm voxels | 0 |
| Word features | GPT layer 9, 768 numbers, 5 words of context | 1 |
| Delays (FIR) | 4 (2, 4, 6, 8 s), so 4 × 768 = 3,072 features | 1 |
| Ridge penalty | 10 values, log-spaced from 10 to 1,000; chosen per voxel by 50 repeats of cross-validation | 1 |
| Voxels used for decoding | best 10,000 cortical voxels | 1 |
| Noise model | Gaussian; covariance from held-out stories (bootstrap), shrinkage α | 2 |
| Language model | GPT fine-tuned on Reddit (over 200 M words) and 240 stories (over 400 k words); vocabulary 6,867 words; reads the last 8 s | 3 |
| Word rate model | Regression on responses 2 to 8 s later; auditory cortex (heard) or Broca and sPMv (imagined, film) | 4 |
| Beam | k = 200; at most 5 continuations per candidate, set by quintile of P(S) | 5 |
| Null model | 200 sequences from the language model with random likelihoods | 6 |
| Heard speech | 72 to 82% of time-points above chance; identification rank 0.85 to 0.91; WER 0.92 to 0.94 | 6 |
| Imagined speech | 100% identification among 5 stories; 0.23 to 0.83 bits against 2.32 for chance | 7 |
| Other brains | 1 to 2% (volumetric), 1 to 5% (surface) of time-points | 7 |
This is a simplified sketch in Python of the loop from Chapter 5, written for this lesson (not the authors’ code; theirs is linked below). It leaves out the training of the models and the 8 second context window.
pythonimport numpy as np def loglik(r_true, r_pred, Sigma_inv): r = r_true - r_pred # (V,) residual for one image, V = 10,000 return -0.5 * r @ Sigma_inv @ r # Gaussian log-likelihood, up to a constant def decode(R, word_times, enc, lm, Sigma_inv, k=200): beam = [((), 0.0)] # (words so far, score): start empty for t in word_times: # word times come from the word rate model quint = lm.quintiles([w for w, _ in beam]) # 0 = most English-like ... 4 pool = [] for (words, _), q in zip(beam, quint): conts = [] for w in lm.nucleus(words): # tens of words, not all 6,867 cand = words + (w,) pred = enc.predict(cand, t) # (V,) predicted response conts.append((cand, loglik(R[t], pred, Sigma_inv))) conts.sort(key=lambda c: -c[1]) pool += conts[: 5 - q] # 5, 4, 3, 2 or 1 continuations pool.sort(key=lambda c: -c[1]) beam = pool[:k] # keep the k best sentences return beam[0][0] # the most likely sentence
Implanted-electrode decoders read the movements of speech and need surgery. This paper reads meaning from a scanner outside the head, and gives up exact words to do it. The authors suggest the two could meet: motor features for the exact surface form, semantic features for the gist, and fast electrical recordings alongside fMRI. The same recipe, an encoding model, a noise model and a language prior searched by beam, is a template for any recording method. Better feature extractors are the most direct way to raise performance, according to the error analysis.
This lesson re-teaches the paper by Jerry Tang, Amanda LeBel, Shailee Jain and Alexander G. Huth (Departments of Computer Science and Neuroscience, The University of Texas at Austin), Nature Neuroscience 2023, doi 10.1038/s41593-023-01304-9. The open manuscript is on PubMed Central. Code is at HuthLab/semantic-decoding; the data are on OpenNeuro (ds003020 and ds004510), except the decoder-resistance data, which the authors held back. The paper reports support from the National Institute on Deafness and Other Communication Disorders (1R01DC020088-001), the Whitehall Foundation, the Alfred P. Sloan Foundation and the Burroughs Wellcome Fund. Two authors (Huth and Tang) are inventors on a pending patent application, as the paper states. The worked examples and devices on this page are illustrative toys unless a note says they come from the paper.
Now press Present or Teach and explain the pipeline out loud, from memory: why one image holds twenty words, how a guess is scored, what the language model and the word rate model each add, and what one step of the beam does. Then go back to the decoder at the top, set the noise to 1.4, and explain why the brain-only and language-only methods fail in different ways.