Cramming an LLM into an SVG
October 17, 2026Introduction
I’ve been trying to figure out a good problem to tackle for a thesis, and I’ve been rummaging through by box of ideas. I woke up this Saturday with another, somewhat crazy, one: I think I can make a tiny language model inside of an image (an SVG) that runs completely within the browser.
As with most of my ideas, the usefulness of this is not clear. As a subject for a thesis, I don’t think it would hold up because it seems more like a joke than research. However, it does have a few interesting properties:
- There is no server to send your data to
- Since it’s running on the page, it knows about the text on the page (a help system that actually works?)
- The model comes equiped with it’s own drawing surface for graphs, animations, or whatever
- I can leverage the browser for text to speech and speech to text
- It’s such a random cross discipline thing that it would be hilarious to see
So, if you look down at the bottom right of the page, you will find an SVG image. Click it and ask it a question. That image is running my very small language model Alan v4 with tools. It knows about the content of this page, and it can save memories to localStorage. This is how it works.
What is this Madness
If you ask it a few questions, you’ll see it’s pretty dumb. It’s a very, very small model: ~6M parameter with 12 layers, 192 hidden, and a 4096 token vocabulary. It only has a context window of 512 tokens and it can not reason very well (I haven’t trained it to do that yet). None the less, it can sometimes do the right thing (~40% of the time).
It’s a bit of a side step from my little research project Maida Vale which is trying out the idea of making a very small model, surrounding it with robust tools, and letting the deterministic tools do the heavy lifting. I am also leaning on and playing with mixing the language models with traditional machine learning techniques. There is a lot of prior work in this area, most of it has been shelved when people started “just scaling” LLMs, but I think this technique is going to be making a come back here pretty soon.
I don’t want to talk too much about what I am doing there because maybe that’s what I will pick for my thesis, but in spirit that is what the SVG is doing. However, it is using some much simpler techniques than the ones I am playing with “for reals”.
Search
As a simple example, this webpage sends the text to the SVG model harness, and then the harness uses BM25 to “lookup” answers to your questions before sending that text back into the model to formulate it’s response - a really, really simple version of RAG. Alan stuffs this up quite a bit. Mostly because it’s such a small model, but such a rudimentary search technique doesn’t help.
In my testing, retrieval only finds the right sentence about half the time. Making the best use cases: “Does this page mention X?”, “Where is the contact link?”, “Where is the help menu?”, or “Does this paper mention the number of layers used?” not really work at all.
The harness also does a lot of the tricks that Claude code and friends do that you likely just glaze over. Like if you ask it what time it is, it’ll be right, but that’s only because of our good friend regex.
Architecture
The model and harness, obviously, require quite a bit of Javascript (and WASM). The SVG container started out as a bit of a hack as I talked about in my post SVG as a UI. I showed there that you can run Javascript in an SVG, and then include it on a page, or run it by just loading the SVG directly. For example, you can load the SVG language model by directly going here, open the console and type window.answer(“hello!”);. There you can see the animations in all their glory.
The Alan v4 weights weighs in at about 6.3MB. That is both the tokeniser and the weights. That’s already smaller than most images on the internet these days, but in order to give room for the other bits, I quantised the model down to 4-bit weights and it had 90.1% similar output to the original version. I mean, 90.1% of nonsense is still nonsense, but at least it’s the same nonsense. The quantisation took the weights down to 3.8MB.
The second heavy part of the process is the WASM code. I have my own custom weight format, and the majority of the neural network code is not written in javascript so the process also needs to load a WASM file.
I wanted this all in a single SVG file though, so I put all the javascript loading code into the SVG, and base64’ed the WASM and weights. The weights, tokeniser, WASM, BM25, and avatar drawing code comes in as one 8.5 MB SVG (6.3 MB gzipped).
Conclusion
Hum, so yeah, if you were curious. This is possible.
But really, I am building a slightly larger, more robust base model right now. My goal is to see how small I can keep a model and still have it actually be useful in reality. While this doesn’t work that well in this iteration, I think there is still a possibility of something like this being useful - I think the overall concept is interesting - a sandboxed, portable, tiny model with a built in screen that doesn’t need a GPU.
Maybe this is how AI escapes from the lab /jk.
Credits
Trained on:
- Simple English Wikipedia (CC BY-SA 4.0)
- Stanford Alpaca (CC BY-NC 4.0)