A language model
you can edit.
A transformer is one frozen function. LenticulumLM is a plan for a language model built as a factor graph: thousands to tens of thousands of small models, each a relation between a few variables, wired together by the belief algebra of Lenticulum.jl. Factors are added, deleted and loaded from a store. Writing text becomes a problem roboticists already solve well, incremental smoothing, and the effort spent on a query grows with how deep the query reaches.
- Julia
- On Lenticulum.jl · Sophia · Moonkale
- Concept: not implemented yet
Not one network, a graph of small ones.
In statistical terms: a transformer is a single conditional distribution, fitted once. LenticulumLM is a probabilistic graphical model whose factors are learned relations, whose structure changes while it runs, and on which generation is inference. What that changes, row by row:
| a transformer LLM | LenticulumLM, the goal | |
|---|---|---|
| What the model is | One fixed function: billions of parameters in one checkpoint | A graph of thousands to tens of thousands of small relations (factors), kept in a store |
| Adding knowledge | Fine-tune or retrain the network, or paste it into the prompt | Append factors, and train only those, against the graph around them |
| Removing knowledge | No reliable way: unlearning is an open problem | Delete the factors: their contribution is gone |
| Generating text | Left to right, one committed token per forward pass | Denoising beliefs at any positions; a token stays revisable until it settles |
| Cost of a query | The same for every query of a given length | Set by the part of the graph the query reaches |
| Uncertainty | A softmax over the next token | A belief on every position; the free energy says how much the factors disagree |
| Hard constraints | Mask logits, or check the output afterwards | Constraint factors in the graph: a grammar, a type checker, a Lean 4 kernel |
| Tools, retrieval, agent loop | Code outside the model (the harness) | Variables and factors inside the graph, edited like the rest |
| Why this answer? | Post-hoc attribution | Per-factor energies: which factors pulled where |
| Direction | Prompt → continuation | Any: continue, fill a gap, infer a premise from a conclusion |
Writing is mapping while you move.
A robot doing SLAM keeps a factor graph of where it has been and what it has seen, and adds to it at every step. iSAM2 (Kaess et al., 2012) made that fast: it keeps the graph factorised and, when new factors arrive, re-solves only the variables they reach. Generating text has the same shape: each new token is a new pose, and a reference back to something said earlier is a loop closure.
The prompt is clamped: four known positions, like the first poses of a map.
SLAM: the starting poses, known
A toy, solved exactly in your browser. The halos are the marginal standard deviations of a small linear-Gaussian graph, recomputed at every step; the count of re-solved variables is iSAM2's for a graph eliminated in time order. In LenticulumLM the positions would carry beliefs over tokens, and the factors would be learned.
The dictionary
Every piece of SLAM has a counterpart in text. Lenticulum.jl was built with GTSAM as its inspiration, and its notes on dynamic graphs already plan appends that touch only the newest factors, for SLAM and for next-token prediction alike (backlog I10, O4).
| in SLAM | in LenticulumLM |
|---|---|
| the pose xₜ of a robot | the state of position t: a belief over its token |
| an odometry factor between poses | a local language relation between neighbouring positions |
| a landmark | a fact, a definition, a document from the store |
| a loop closure | a reference back: a name, a variable, a claim made earlier |
| a GPS fix, a global constraint | a verifier over a span: Lean 4, a type checker, a test |
| the marginal covariance | how settled a position is: its noise level |
| iSAM2's incremental update | the next token: re-solve only what the new factors reach |
| relinearisation | revising an earlier token when new evidence says it was wrong |
Text that settles, not text that is committed.
The factors can be diffusion models or energy networks, both of which Lenticulum.jl already queries as relations. Two ways to read generation with them. As a stream: older tokens carry little noise, newer ones a lot, and a front moves forward. Or as a graph: many positions are denoised at once, wherever the graph knows enough.
The proof “Lemma: every prime p > 2 is odd. Proof: if p were even, then 2 ∣ p, so p = 2, contradicting p > 2. ∎”, its tokens denoised one schedule or the other.
A schedule drawn in your browser, not a model. The stream reading is close to rolling diffusion (Ruhe et al., 2024) and diffusion forcing (Chen et al., 2024); masked diffusion language models (LLaDA, MDLM, SEDD) denoise all positions together. The graph reading lets the structure decide which positions go first.
Pay for what you ask.
A transformer runs all of its weights for every token, whether the question is arithmetic or a proof. Here a query clamps the variables it mentions and loads only the factors connected to them through what is still unknown. A shallow question touches a few dozen factors; a deep one reaches far into the store. The model's size, for that query, is how far the query reaches.
A random graph of a few hundred factors, drawn at build time. The presets are illustrative depths, not measurements. In the library this is the subgraph a query reaches by d-separation from its clamps, with a schedule restricted to it (Lenticulum.jl backlog O4).
A checker is just a factor.
Any language with a checker can run inside the model as a factor: Lean 4, a type checker, a SQL engine, a JSON schema, a unit system. To the graph a checker is a hard constraint on the positions it covers, and it combines with the learned factors through the same belief algebra. The model can still propose something wrong, but in the parts a checker covers, nothing wrong comes out.
- Constrained decoding already masks logits with a grammar. That is a categorical belief combined with a hard factor, done ad hoc. Here it is the general rule.
- A tool result (a compiler verdict, a query result, a retrieved document) is a clamped variable, and the rest is inferred around it.
- Lenticulum.jl marks every belief as exact or approximate. A checked span says exact; everything else says it is not.
# a model is a graph, backed by a store
g = LMGraph(store = Sophia("factors"))
# the prompt is clamped
prompt!(g, "Lemma: every prime p > 2 is odd.")
# retrieved facts become factors
attach!(g, Retrieve(kind = :theorem, k = 8))
# a hard factor: the kernel must accept
attach!(g, LeanFactor(span = :proof))
# denoise until the free energy is low,
# or the budget runs out
ans = denoise!(g; budget = :adaptive)
isexact(ans.proof) # true: checked
energies(ans) # who pulled where New knowledge, new factors.
Training runs along knowledge graphs and code graphs. Teaching the model a new library version, a new paper or a company's internal API means adding the factors that encode it and training those, against the graph around them. Nothing else is retrained.
- Append. A fact, a definition, a function from the code graph: a new factor, keyed in Sophia by the hash of its structure, so the same definition is never stored twice.
- Train locally. Gradients are local to each factor's parameters, so a loaded subgraph trains as one block of coordinates and writes its parameters back (backlog O5).
- Delete. A factor removed is knowledge removed: for retracted facts, outdated APIs, and data that must be forgotten.
- Trace. Every answer comes with the factors that shaped it and their energies: provenance by construction.
The agent loop is part of the model.
Around today's models sits a growing harness: prompts, retrieval, tool calls, agent chains, checks, all written outside the weights and invisible to them. In LenticulumLM they are subgraphs of the model itself: variables and factors that inference sees, training can tune, and a person can open and edit in Moonkale.
Eight pieces, one graph.
What LenticulumLM is made of. Most of the pieces exist in some form in the sister projects; what is new is putting them together into a language model.
- Factors
Small relation learners
Diffusion models and EnergyNetworks from Lenticulum.jl, n-gram windows, small networks. Each is a relation, queried in any direction.
- Beliefs
A belief on every position
Categorical over tokens, Gaussian over embeddings, a point for what is clamped, a mixture for several readings at once.
- Belief algebra
The wiring
Pooling two beliefs is the product of their densities; for tokens, an elementwise product. Messages are exact where they can be and labelled approximate where not.
- Store
Factors in Sophia
Content-addressed: a factor is keyed by the hash of its structure, versioned, and loaded only when a query reaches it.
- Verifiers
DSLs as factors
A Lean 4 kernel, a type checker, a SQL engine, a JSON schema: hard factors, exact where they apply.
- Learning
Training along graphs
Knowledge graphs and code graphs give the structure. A new fact or a new library version is a new factor, trained locally.
- Harness
The agent loop inside
Retrieval, tool calls, plans and checks are subgraphs, edited in Moonkale like any other part of the model.
- Budget
Anytime inference
The free energy measures disagreement: stop when it is low, reach further when it is high, abstain when it stays high.
A plan, on working parts.
LenticulumLM has no code yet. What it would be built from does: a factor-graph library with learned relations, a content-addressed store and a graph editor. Here is what exists, what does not, and what could make it fail.
Exists today
- Lenticulum.jl: factor graphs, message passing and free energies, checked against closed forms
- Diffusion models and EnergyNetworks used as relations, queried in any direction by root finding
- The belief algebra, with categorical beliefs and their exact product
- Sophia: a content-addressed store for code with a Datalog query language
- Moonkale: a graph-native editor, with LLM agents behind an approval gate
Not built yet
- LenticulumLM itself: no tokeniser, no language factors, no trained model
- Factors kept in a store and loaded where a query reaches (Lenticulum.jl backlog O1–O5)
- Incremental inference that reuses factorisations after an append (backlog I10)
- A GPU path for categorical beliefs; verifier factors; the harness as a graph
Open questions
- Adding the scores of diffusion models samples their product only at t = 0; along the trajectory it needs a correction, such as MCMC at each noise level (Du et al. 2023)
- Products of experts are hard to sample, and agreement tends to select bland text
- Message passing on loopy graphs need not converge; schedules matter
- The central bet, unmeasured: whether many small factors match one large network on fluency at equal compute
The open questions come from Lenticulum.jl's own review of the idea, Language Models: a product of experts over diffusion models, where it pays (heterogeneous spans, hard constraints, tool outputs) and where it does not.
The road, in six steps
- 01
An n-gram chain
Window relations joined by separators, exact in every query direction. The smallest language model that is honestly a factor graph.
- 02
Next token as an append
Generation as incremental smoothing: each token appends factors, and only what they reach is re-solved.
- 03
A store behind the graph
Factors in Sophia, loaded lazily where a query reaches; training on a loaded subgraph, with parameters written back.
- 04
Denoising over spans
Diffusion and energy factors over spans of positions; several positions denoised at once; a sequence-level energy per step.
- 05
Verifiers in the loop
Lean 4 and type checkers as hard factors, so the parts they cover come out checked.
- 06
The harness in the graph
Retrieval, tools and agent loops as editable subgraphs in Moonkale; benchmarks against transformers at equal compute.
Help build the first one.
LenticulumLM is a research bet: that a language model can be a graph you can grow, prune, inspect and verify, rather than a checkpoint you can only run. If you fund research, work on probabilistic inference, SLAM or diffusion models, or want a model whose knowledge you can edit, we would like to hear from you.