Agora: a language learner whose memory is a market

This research prototype runs entirely in your browser.

Abstract. Agora learns to predict text without neurons, gradients or backpropagation. Its memory is a population of small traders, each watching one context and betting on the next word. Prices are wealth-weighted averages of their bets, and each settlement is a Kelly bet, which is mathematically the same operation as a Bayesian update and as arithmetic compression. Traders are born only where the market is surprised and are liquidated during periodic sleep. An analyst with position-bound hypervectors adds generalisation by analogy, and a curiosity rule decides what to read next. Trained on 54,000 words of Shakespeare, the market compresses unseen pages to about 10 bits per word, against 14.7 for deflate. The page includes eight public-domain corpora, from the King James Bible and Adam Smith to State of the Union addresses and a French novel, so the same mechanisms can be compared across very different kinds of text.

Explained simply

Imagine a room full of people playing a guessing game. Someone reads a book aloud, one word at a time, and stops before each new word. Everyone in the room bets play money on what the next word will be.

Each person only listens for one thing. One person perks up whenever they hear “good”. Another only cares about “my good”. When the reader says “my good…”, both of them bet. The “my good” person has heard this many times before and bets most of their money on “lord”.

Then the real word is read out. If it was “lord”, the people who bet on “lord” win money, and people who guessed badly lose some. Over time, the people who guess well get rich, and rich people's bets count for more. The room as a whole gets better and better at guessing.

A few simple rules keep the room tidy. When the whole room is caught by surprise, a new person is invited in to listen for exactly that situation next time. Every so often everyone takes a nap, and people who never win anything are sent home, so the room doesn't overflow. There is also a helper who notices that words behave alike, for instance that “lord” and “king” turn up in the same kinds of places, and uses that to guess in situations nobody has seen before.

The room also chooses its own books: it picks pages that are a little harder than what it already knows, and skips pages that look like gibberish. To check that it has really learned something, it is tested on pages it has never read. The less surprised it is by those pages, the more it knows. That's the whole idea: no brain cells, just a very well-run guessing market.

1Project overview

A human brain runs on about 20 watts, barely enough to illuminate a dim lightbulb, while training and hosting frontier large language models demands the output of entire industrial data centers. The gap has identifiable causes: computers shuttle memory to the processor for every operation, activate every parameter for every token, compute with costly precision and learn with an algorithm that needs trillions of examples.

Agora is an experiment in the opposite direction. It asks how far a learner can go when memory and computation are the same structure, updates are purely local and sparse, and nothing is stored unless it was surprising. Instead of borrowing the brain's vocabulary of neurons and synapses, it borrows the vocabulary of markets, for a concrete reason: a market is a well-understood machine for aggregating many partial, competing opinions into a single price, and its accounting is exactly the accounting of prediction.

The system has five working parts.

Performance is measured honestly as compression: the number of bits the market needs to encode sealed pages it has never read. The whole system, including eight public-domain corpora of about 60,000 words each, runs locally in this page. Section 3 walks through using it.

2Mechanisms

2.1Traders and prices

Text is split into lower-case words and punctuation. A trader is attached to one context: the last one to five words, such as “my good”. It holds counts of the words that have followed that context, a count of its trades n, and a trust value τ. A trader's belief about the next word follows the PPM-D estimator: words it has seen get probability proportional to their counts, and the remaining mass, which grows with the number u of distinct words it has seen, is spread according to public base rates.

β(w) = 2c(w) − 12n if w was seen,    otherwise  u2n · b0(w)(1)

The base rate b0 is a smoothed word frequency, quoted by a market maker who trades at every table. A word never seen before must be spelled out letter by letter, costing about 4.75 bits per letter, so unknown vocabulary is paid for rather than ignored. When a context arrives, every trader whose context matches a suffix of it is active. The price of a candidate word is the stake-weighted average of the maker's quote and the active traders' beliefs:

p(w) = b0(w) + Σk sk βk(w)1 + Σk sk,    sk = τ1 τ2τk(2)

Here k is the context length, from general (one word) to specific (up to five). A trader's stake is the product of its own trust and that of every more general trader beneath it. That design choice matters. In an early version, each trader held absolute wealth, and general traders, which take part in far more markets, accumulated wealth regardless of skill. Step 7 draws these parent and child relationships as a family tree. Holding trust relative to the parent context means a specialist inherits its parent's reputation and only has to beat the parent where the two overlap, much as context tree weighting weighs contexts in classical compression.

2.2Settlement: betting, updating and compressing are one operation

When the actual word w arrives, the market pays its cost, the number of bits an ideal coder would spend given the price:

cost(w) = −log2 p(w)(3)

Then every active trader is settled. A Kelly bettor that spreads its wealth in proportion to its beliefs multiplies that wealth by β(w) / p(w). That multiplication is exactly Bayes' rule for a mixture of models, and the log of total wealth growth equals the bits saved relative to the market price. Agora applies the rule to trust relative to the parent, tempered by a learning rate η and bounded so that no trader is ever infinitely right or wrong:

τk ← clip( τk · ( βk(w) / βk−1(w) )η, 0.01, 100 ),    β0 = b0(4)

After settlement each active trader adds w to its counts. Step 6 in Section 3 replays this process word by word, and step 2 shows it live while the market reads. No error signal travels anywhere else: the only structures touched are those that were active for this word.

2.3Birth from surprise, liquidation in sleep

New traders are created only when the market is caught out. If the cost of a word exceeds a threshold θ (4 bits by default), the market opens one new trader, one word more specific than the deepest active one, seeded with the word that surprised it. Predictable text therefore costs no new memory, which is the minimum-description-length principle in operational form: store only what the current model fails to explain. Deep contexts are grown one level per surprise, so the market deepens exactly where it keeps being wrong.

Every S words (60,000 by default) the market sleeps. Every count is halved, and traders left with no counts, or with trust at the floor, are liquidated. Sleep keeps memory bounded, lets old statistics fade in favour of recent evidence, and removes traders that were born from one-off accidents.

2.4Role vectors and the analyst

Traders cannot generalise: a context they have never seen gets no help from similar contexts. The analyst supplies that help using hyperdimensional computing. Each word receives a fixed random identity vector of ±1 values in 256 dimensions. Each word also accumulates a role vector: every time word a appears k positions before word w, the identity of a is rotated by −k positions and added to the role of w, and the identity of w, rotated by +k, is added to the role of a.

r(w) ← r(w) + ρk( id(a) ),    r(a) ← r(a) + ρk( id(w) )(5)

The rotation ρ binds position into the vector, so “the king” and “king the” leave different traces, and words used in the same positions around the same neighbours end up pointing the same way. Similarity is the cosine between role vectors after the mean vector is removed. Nobody tells the system that “lord” and “liege” are related; the relation appears because they sit in the same slots.

When no trader of length two or more matches the current context, the analyst joins the market. It finds the eight words whose roles most resemble the last word, borrows the beliefs of their one-word traders weighted by similarity, and bets half on that borrowed view and half on base rates. It must earn its influence like everyone else: its stake is a share of each pot it joins, updated by the same Kelly rule and kept between 0.1% and 1,000 times the traders' pot. The floor is the fixed-share method from online learning, and it ensures the analyst can win influence back if the text changes.

2.5Curiosity-driven reading

Before choosing a page, the market tastes the opening 80 words of every unread page and measures its cost in bits per word, without learning anything. Let m be the average taste of the last eight pages it read. It then reads the page whose taste is closest to m + 1: slightly beyond current knowledge, where learning progress is likely. Pure novelty-seeking has a known failure, sometimes called the noisy-TV problem, in which an agent fixates on randomness because randomness is always surprising. Agora guards against it: once three pages have been read, any page tasting more than 4 bits above m is marked as noise and never read. Pages you add yourself skip the queue and are read first.

2.6Evaluation

Before any reading, about one page in five of the chosen corpus is sealed as an exam, chosen by a fixed hash so the split never changes; small corpora get extra sealed pages so the exam is not too short. The first 450 words of each sealed page form the test set. After every page read, the market prices the test set without learning, and the chart reports the average cost from equation (3). As a reference, the same text is compressed with deflate, the algorithm inside zip and gzip, using the browser's built-in compressor. A market that beats deflate has captured regularities in language that a generic byte-pattern compressor misses.

3Usage, step by step

Everything below is live. The controls in the bar stay at the top of the screen while you scroll through the steps.

Preparing the library…

Choose a corpus and start reading

At first the market knows nothing and pays over 20 bits per word, mostly spelling out unknown words. Reading drives that cost down. Eight public-domain corpora are built in, each cut into pages of about 900 words, plus a mixed library that draws eight pages from each.

  1. Pick a corpus from the cards below or from the Corpus menu in the bar. Switching resets the market and fills the other steps with examples suited to that text.
  2. Press Start reading to read continuously, or Read one page to advance one page at a time.
  3. Use Pace to slow down or speed up. Slow is best for watching the trading floor in step 2; on Fast, the whole library takes under a minute.
  4. Watch Figure 1. The black line should fall steeply and cross below the dashed deflate line after a few pages.
Exam score
Bits per word on sealed pages; lower is better
bits per word
Figure 1. The built-in corpora, and compression of the chosen corpus's sealed test set as the market reads. The dashed line is deflate on the same text.

Watch the trading floor

While a page is being read, the floor shows the words streaming past and, every few hundred words, the full auction for one of them: who took part, what each bet on the word that actually arrived, and how settlement moved the money.

  1. Set Pace to Slow and start reading.
  2. Read the tape from left to right. Red words were expensive surprises; pale words were expected. A gold underline marks a word whose surprise gave birth to a new trader.
  3. In the auction, the grey bar is a participant's share of the money before settlement and the black bar its share after. Participants that gave the actual word a high probability gain share.
Reading nothing yet 0 words per second 0 traders born on this page
The auction appears once reading starts. price cost
ParticipantBet on the actual wordShare of moneyTrust
Figure 2. Live trading floor. Bet bars use a square-root scale so that small probabilities remain visible; the percentages are exact.

Follow the curiosity log

Each entry records a decision from Section 2.5: which page was read and what it cost, or which page was rejected as noise.

  1. Look for “Static interference”, a page of random letters hidden in the library. It should be marked Ignored as noise within the first few pages.
  2. Hover over a read page in the library to see what it cost. Later pages should cost less as the market learns.
  1. Nothing read yet. Start reading to open the market.
Figure 3. Reading log, newest first, and the state of every page in the library.

Add your own texts (optional)

The market can learn from anything you give it. Long texts are split into pages of about 900 words. Your pages are read before the built-in library and are never sealed for the exam, so the exam curve stays comparable.

  1. Paste text into the box and give it a title, then press Add to library.
  2. Or choose one or more .txt, .md or .html files. Scripts, styles and navigation are stripped from HTML.
  3. Press Start reading again if the market has finished the library.
Figure 4. Adding material. Nothing leaves your browser.

Open the order book

The order book shows equation (2) at work for one context: who is active, what share of the stake each holds and what each is betting on, followed by the resulting prices.

  1. Type a phrase, or keep the one suggested for the chosen corpus, and press Open book.
  2. Compare stakes. A specific trader that has earned trust will hold most of the money; where specialists have little experience, the general trader or the market maker dominates.
  3. Reopen the same phrase after more reading to see stakes shift.
Figure 5. Order book: stake shares and top bets of each participant, and the price ladder for the next word.

Replay an auction in slow motion

The replay walks through a sentence one word at a time and separates each auction into the four phases of Sections 2.1 and 2.2. It does not change the market: it shows what settlement would do.

  1. Keep the sentence or type your own, then press Play. Use Next word to go at your own pace, and Restart after editing the sentence.
  2. Match: the thickening underline beneath the preceding words shows how many traders recognise each part of the context.
  3. Bet: each participant's favourite words appear. Reveal: the word arrives, and each bar shows the probability that participant gave it. Settle: trust moves and the money is redistributed.
  1. 1. Match traders
  2. 2. Place bets
  3. 3. Reveal the word
  4. 4. Settle
ParticipantBet on the actual wordShare of moneyTrust

Press Play once the market has read at least one page.

price cost sentence so far
Figure 6. One auction per word, in four phases. Past words are shaded by what they cost.

Explore a family of traders

Traders form families. The trader watching “lord” is the parent of “my lord” and “good lord”, which are in turn parents of longer contexts. Because trust is held relative to the parent (Section 2.1), a family tree is the natural way to see where the market has specialised.

  1. Keep the suggested word or enter another common word from the corpus, and press Show family.
  2. Read the tree from left to right: each step adds one earlier word to the context. Circle size shows how many trades a trader has made, and darkness shows its trust relative to its parent.
  3. Leave the tree open while reading. New children grow in and the tree reshapes itself after every page.

Figure 7. Trader family for one word. Only the busiest branches are shown: up to six children at the first level, then two, then one.

Let the market write

Generation samples each next word from the market's own prices. Temperature below 1 sharpens the prices toward the favourite; above 1 flattens them.

  1. Enter opening words and press Write.
  2. Read the underlines: a solid green line marks a word the market priced highly, a faint one a long shot.
  3. Try low and high temperature on the same prompt.
Figure 8. Generated text, with each word underlined by the price the market gave it.

Measure surprise in any passage

The surprise lens prices a passage word by word using equation (3), without learning from it. It shows which parts of a text the market already understands.

  1. Keep the sample passage for the chosen corpus, or paste your own, and press Measure.
  2. Darker red means more bits. Hover over a word to see its exact cost.
  3. Compare a passage in the corpus's style with modern prose: the modern text should cost far more.
predictable surprising
Figure 9. Word-by-word cost of a passage. Nothing measured here is learned.

Compare word roles

This view queries the role vectors of Section 2.4 directly and lists the words whose positioned neighbourhoods look most alike.

  1. Enter a word the market has read, or keep the suggestion, and press Compare.
  2. Scores are cosine similarities. Values above about 0.6 usually indicate words that can stand in for one another grammatically.
Figure 10. Most similar roles, learned without any information about meaning.

Check the health of the market

These figures show the life cycle from Section 2.3 and how trust is spread across the population.

  1. Compare births with liquidations to see how much of what the market stores survives. The population line drops sharply each time the market sleeps.
  2. In the trust map, each row is a context length and each column a level of trust relative to the parent. Watch mass move away from the middle column as traders prove themselves or fail.
  3. Watch the analyst's stake. If analogy is not paying on this text, the market pushes it toward its 0.1% floor.
0words read
0traders
0words known
0born from surprise
0liquidated in sleep
10%analyst's stake
Figure 11. Market statistics, trader population after each page, and the trust map: circle area is proportional to the number of traders in each cell.

Run experiments and save your market

Changing a setting resets the market so that runs remain comparable. The exam pages stay the same.

  1. Change one setting, press Apply and reset market, then read the library again and note the final exam score and trader count.
  2. A useful first experiment: set Sleep every to 10,000,000 to turn sleep off, and compare with the default.
  3. Press Save market to download the trained market as a JSON file, and Load market to restore it later.
Figure 12. Settings, with the symbols used in Section 2, and saving.

4Results and limitations

The figures below come from test runs of this implementation. Exact numbers vary slightly between runs, because curiosity can read pages in a different order.

ConfigurationExam (bits/word)Traders at end
Before any reading22.10
Deflate reference on the same text14.7
Full library, sleep off10.254,056
Full library, sleep every 60,000 words (default)10.1–10.38,312–8,564
Python version, 180,000 words of Shakespeare9.3180,662

Table 1. Compression of held-out Shakespeare. The browser runs use the built-in library; the Python row uses a larger split of the same source.

CorpusAgora (bits/word)Deflate (bits/word)Roles found for the sample word
Genesis and Exodus, King James Bible7.711.5god: jacob, joseph
Emma, Jane Austen9.114.6father: friend, husband
Alice in Wonderland, Lewis Carroll9.115.3king: hatter, cat, mouse
State of the Union, 1945–20069.316.0economy: country, nation, people
The Wealth of Nations, Adam Smith9.514.6labour: industry, stock, silver
Shakespeare10.114.5lord: son, brother, gracious
Moby-Dick, Herman Melville11.816.2ship: pequod, sea, deck
Le Tour du monde en 80 jours, Jules Verne12.317.5fogg: fix, passepartout

Table 2. One pass over each corpus in page order with default settings, scored on sealed pages chosen by the same hash the page uses. Alice's test set is small because the book is short.

Across corpora, the ranking follows intuition. The formulaic Bible compresses best, and Moby-Dick, with its enormous vocabulary, worst among the English texts. The French novel costs most, partly because the market must first spell out many inflected word forms. Three further findings stand out. First, sleep is cheap: it removes about 84% of traders for roughly a tenth of a bit per word, which shows that most surprise-born traders record accidents rather than regularities. Second, the market consistently defunds the analyst. On this amount of text, borrowing opinions from similar words loses money against specialists and base rates, even though the role vectors themselves are clearly meaningful. Analogy should begin to pay only with far more data. Third, refinements to the betting rules improved scores by only about 0.1 bits. The binding constraint is data, not cleverness.

The limitations are real. Agora captures local word statistics, not composition: it produces fluent phrases but no reasoning or coherence beyond a sentence or two. The noise filter can reject a legitimate page early on, when it has too little history to judge what counts as normal. Memory, although bounded by sleep, still grows with vocabulary. And unlike the Python version, this page cannot crawl the web, because hosted pages are not permitted to fetch other sites; it reads the built-in corpora and whatever you add.

5References

  1. Cleary, J. and Witten, I. (1984). Data compression using adaptive coding and partial string matching. IEEE Transactions on Communications, 32(4).
  2. Willems, F., Shtarkov, Y. and Tjalkens, T. (1995). The context-tree weighting method: basic properties. IEEE Transactions on Information Theory, 41(3).
  3. Kelly, J. L. (1956). A new interpretation of information rate. Bell System Technical Journal, 35(4).
  4. Cover, T. and Thomas, J. (2006). Elements of Information Theory, 2nd ed., chapter 6 on gambling and data compression. Wiley.
  5. Freund, Y., Schapire, R., Singer, Y. and Warmuth, M. (1997). Using and combining predictors that specialize. Proceedings of STOC.
  6. Herbster, M. and Warmuth, M. (1998). Tracking the best expert. Machine Learning, 32(2).
  7. Kanerva, P. (2009). Hyperdimensional computing. Cognitive Computation, 1(2).
  8. Sahlgren, M., Holst, A. and Kanerva, P. (2008). Permutations as a means to encode order in word space. Proceedings of the Cognitive Science Society.
  9. Rissanen, J. (1978). Modeling by shortest data description. Automatica, 14(4).
  10. Schmidhuber, J. (1991). Curious model-building control systems. Proceedings of the International Joint Conference on Neural Networks.