jetc@portfolio ~/projects/athena-a-continuous-thought-language-model
jetc@debian: ~/project/athena-a-continuous-thought-language-model

$ cat athena-a-continuous-thought-language-model.md

Athena - A Continuous Thought Language Model

Hey o/

Introduction

When we talk about AI, with the objective of creating AGI, and maybe emulating consciousness, there are mostly two types of people. People who think that LLMs, and their evolution through MoE, will go through some major breakthrough and will ultimately create what we crave. And people who, like Yann LeCun, think that this kind of architecture is not enough to emulate the complexity this task needs.

I'm more like the second type of person, and even though I don't have the resources to challenge million-dollar firms, I like to imagine how to create something that could show some results. One of the many ideas I have is to give a model the ability to use more compute time when it seems needed, maybe by having something that emulates neurons in a better way than our current models. Codename: Athena.

Continuous Thought Machine - Sakana AI

While working on this idea, I stumbled upon a paper from Sakana AI: Continuous Thought Machine.

This paper describes a model that tries to implement two main points:

  • Each neuron keeps a history of its own activations, which allows it to detect patterns in its own activity.
  • As the model works in ticks, the output is not a specific set of neurons, but the synchronization between pairs of neurons over time.

The model has been trained on image classification, maze solving and small arithmetic tasks, and performs nicely on them.

As I'm more interested in language models, which emulate human language, I decided to try plugging the model into it, to see if it could detect patterns, work as a decent next-token prediction machine, and maybe see which tokens need more compute time.

Unfortunately, you cannot just throw words into the current project and see what happens.

Word representation

The first step was to allow the model to play with words, which means cutting the text into tokens and turning each token into a vector. This could be an entire project by itself, finding the best way to represent them, and I invite you to watch videos about the subject on YouTube if you want to dig in (I particularly advise you to watch 3B1B's and Andrej Karpathy's channels).

For my use case, as I didn't have a lot of compute resources (only two RTX 3070 in a computer way too consumer-grade for its own good), I avoided the question by using the embeddings of a pretrained RWKV-7 checkpoint, and froze them: the model doesn't learn what a word is, only what to do with it. RWKV is indeed an RNN language model, which means it shares the same idea of feeding tokens one after the other into the model, instead of looking at a whole context window at once like LLMs do (RWKV competes with Google's Transformers, but I won't go into details here).
I'll also take a short break to talk about the data and the size of the model I used. As I didn't have much horsepower, as said above, I had to avoid using tons of data, and could not train a billion-parameter model. So I decided to train an 82.8-million-parameter model (with 67M parameters dedicated to the frozen RWKV-7 embeddings, so a trained part of around 15M parameters), on one shard of public StackOverflow data: about 230k questions and their answers.

Starting training

The original CTM uses attention to decide where to look in an image. A token doesn't have a "where", so I removed it and fed one token per tick, like an RNN: 1 tick per question token, 4 per answer token, and a reset after each answer.

Before spending weeks of GPU time, I needed to know if the idea was dead on arrival: synchronisation was designed for 10 classes, not for a vocabulary of 65,536 tokens. So I first made the model overfit on purpose, on 20 question/answer pairs replayed in a loop. It ended up reciting them almost word for word (97% token accuracy). Useless on any other question, of course, but at least synchronisation can represent words.

The first real training showed that thinking actually helps: the accuracy goes from 9.6% at the first tick of an answer token to 26% at the third one. But the model learned a rhythm rather than "think more = better" (giving it more ticks made things worse), and the question slowly dilutes in its memory along the answer, as this memory is a simple running sum.

The next version let the model choose how long to think, between 2 and 8 ticks per token. It used them like a switch, mostly 2 or 8, thinking longer at the start of a sentence or of a code block, but it didn't do better overall. Then I added a gate on the memory, so the model can decide what it writes and forgets. The question survived long silences much better, partly because, as I found out later, the padding of the batches was secretly feeding it silence during training. The last version simply doubled the output vocabulary (32k tokens), for a small but real gain.

But, that's a lot of "I did that" and "This is new, I assure you". But we are number nerds here. We want the data.

How does it compare to a real language model?

To get a fair comparison, I trained a small GPT (based on Karpathy's nanoGPT) in exactly the same conditions as my last CTM (Athena): same frozen embeddings, same data, same number of steps, and the same number of trained parameters (about 30M), with a core of the same size.

Athena GPT
Loss per token 4.016 ± 0.028 3.169 ± 0.030
Perplexity 55.5 ± 1.6 23.8 ± 0.7
Answer finds its question (MRR) 0.301 0.540

The MRR (Mean Reciprocal Rank) checks if an answer can find its own question among the others of the batch: if the right question is ranked first, it scores 1, second 1/2, third 1/3, and so on. We then take the average.

It's not close: the GPT wins on every batch, and its answers stick much more to the question. My first guess was that it simply copies words from the question through attention, while the CTM has to keep them in its state. It does, but that only explains about a quarter of the gap.

On public benchmarks (ARC, HellaSwag, PIQA, MMLU...), both models are at chance, which is no surprise as they only ever saw StackOverflow. SmolLM2-135M, trained on 2 trillion tokens, is clearly above them. So for now, a plain GPT does better than my CTM with the same budget. That doesn't kill the idea, as the CTM was never supposed to win on next-token prediction alone, but it gives me a clear bar to beat.

Benchmark Chance Athena GPT, same core SmolLM2-135M
ARC-Easy 25% 26.0 ± 1.0 26.3 ± 1.0 59.7 ± 1.0
HellaSwag 25% 25.5 ± 1.0 24.6 ± 1.0 43.2 ± 0.5
PIQA 50% 50.2 ± 1.2 49.8 ± 1.2 68.7 ± 1.1
MMLU 25% 24.5 ± 1.0 24.7 ± 1.0 29.7 ± 0.4
TriviaQA 0% 0.0 0.0 5.4 ± 0.2

What's next ?

I still have some ideas to improve this model, and I will run some tests on them. When I have something to show, I will write a new post about it ;)

jetc@debian: ~
jetc@debian: ~/