# Lilavati

Canonical: https://udgamlabs.com/models/lilavati · Updated: 2026-10-16

/ LilavatiMaths model · Public release · 16 October 2026

Solves maths word problems by writing a short Python program and running it.

- **Parameters**: 95M
- **Runs on**: A laptop CPU
- **Licence**: Apache-2.0

Try it in your browser: [https://udgamlabs.com/models/lilavati#try](https://udgamlabs.com/models/lilavati#try)

## 01 / What it is

Pocket Mathematician

A 95M-parameter model, trained from scratch, that solves maths word problems by writing a short Python program and running it.

[Read the release post](https://udgamlabs.com/blog/lilavati)

## 02 / The result

Good at everyday word problems. Weak at traps, units and working backwards.

On GSM8K, the standard test of grade-school maths word problems, Lilavati solves 54.7% on its first try, with its program executed. When Lilavati-Checker, a second 95M model, weighs 48 tries, it solves 72.3%. It is weak at numbers that should be ignored, working backwards and unit conversions, and it always returns a number, even when a question has no answer.

[Try it in your browser](https://udgamlabs.com/models/lilavati#try)[Weights on Hugging Face](https://huggingface.co/udgamlabs/Lilavati) [The checker on Hugging Face](https://huggingface.co/udgamlabs/Lilavati-Checker) [Code & evaluation on GitHub](https://github.com/udgamlabs/lilavati) [Technical report](https://udgamlabs.com/research/lilavati)

- 54.7%

    of GSM8K solved on its first try, with its program executed

- 72.3%

    when Lilavati-Checker, a second 95M model, weighs 48 tries

## 03 / How it answers

Small models are unreliable at arithmetic, but they can learn to plan it. Lilavati writes the plan as a short Python program. Python does the arithmetic, so the model only has to get the reasoning right.

1.  01

    Read the question

    Lilavati reads an English maths word problem.

2.  02

    Write a program

    It writes a short Python function whose return value is the answer.

3.  03

    Run it in a sandbox

    The program passes a structure check (maths-only building blocks, no file or network access) and runs in a restricted sandbox with time and memory limits.

4.  04

    Read the answer

    The return value is the answer. The program comes with it, so you can check the working.

[![The chai stall question, the Python program Lilavati wrote for it, which ran in a sandbox, and the answer: 1,620 rupees](https://udgamlabs.com/models/lilavati/how-it-answers.png)](https://udgamlabs.com/models/lilavati/how-it-answers.png)

*A real answer: the question, the program Lilavati wrote, and the result of running it.*

## 04 / Many programs

## Not sure? It writes many programs.

Lilavati can write several programs for the same question and run each one. Lilavati-Checker, a second 95M model, reads the question and each program with its result, and rates how likely it is to be right. Each answer gets the sum of the ratings of the programs that produced it, and the answer with the most support wins.

Over 48 tries, that lifts GSM8K from 54.7% to 72.3%. The try box above uses 8 tries in Best mode and one in Fast mode.

[![The answers vote on the cricket question: 75 from 5 tries, and 5, 20 and 50 from one try each. A second tiny model checks the work. Answer: 75 runs](https://udgamlabs.com/models/lilavati/many-tries.png)](https://udgamlabs.com/models/lilavati/many-tries.png)

*A real vote on the cricket question: eight programs, four different answers. 75 runs wins.*

## 05 / How good is it

- **Parameters**: 95M Trained from scratch. Small enough to run on a laptop CPU
- **GSM8K, first try (code executed)**: 54.7% One greedy try. The program is run and its return value is compared with the reference answer
- **GSM8K, with the checker over 48 tries**: 72.3% Lilavati-Checker weighs 48 programs per problem. With 16 tries: 68.8%

One try, code executed · every test set

| Test set | Items | Lilavati |
| --- | --- | --- |
| GSM8K test | 1,319 | 54.7 |
| SVAMP | 1,000 | 69.9 |
| ASDiv, numeric answers | 2,159 | 74.0 |
| GSM-Hard | 1,319 | 43.7 |
| GSM-Plus testmini, the 7 answerable perturbation types | 2,100 | 39.2 |

GSM8K test · 48 tries per problem

| How the answer is chosen | Score |
| --- | --- |
| Checker-weighted vote (the default) | 72.3 |
| The checker’s single top-rated program | 66.7 |
| Plain majority vote | 65.7 |
| At least one of the 48 programs is right (an upper bound) | 89.5 |

With 16 tries, the checker-weighted vote scores 68.8.

All numbers were measured by us. “Code executed” means the model’s program is run and its return value is compared with the reference answer. No test-set problems were used for training; the model card has a contamination audit for every test set.

### Compared with other open models up to 150M parameters

On GSM8K it solves 54.7% on its first try: about 2.7× the best open model of its size we tested.\*

[![GSM8K test, open models up to 150M parameters, measured by Udgam Labs: Lilavati (95M) 54.7%, cagliostro-v3.5-chat (146M) 21.3%, Falcon-H1-Tiny-R (90M) 18.7%; about 2.7 times](https://udgamlabs.com/models/lilavati/compare-up-to-150m.png)](https://udgamlabs.com/models/lilavati/compare-up-to-150m.png)

*\*Open models up to 150M parameters. Greedy GSM8K-test with code execution, measured by Udgam Labs on 14–15 Oct 2026 with one harness. Other models answer in text, their native format. cagliostro-v3.5 was scored on the first 300 items; on those, Lilavati scores 57.3% (≈2.7×). TinyGSM (2023, weights not released) reported higher numbers under its own protocol.*

GSM8K test, greedy, measured by us on 15 October 2026 with one harness

| Model | Params | GSM8K test | Notes |
| --- | --- | --- | --- |
| Lilavati | 95M | 54.7 | Code executed. 57.3 on the first 300 items |
| cagliostro-v3.5-chat | 146M | 21.3 | First 300 items; 1K-token cap |
| Falcon-H1-Tiny-R-90M | 90M | 18.7 | All items, 16K-token cap. SVAMP: 40.1 with an 8K-token cap (Lilavati 69.9) |
| MobileLLM-R1.5-140M | 140M | 6.7 | First 300 items; 99% of its answers ran past our 8K-token cap. Its developers report 8.3 |
| GPT-X3-150M | 150M | 2.3 | First 300 items; 1K-token cap |
| GPT-X2.5-135M | 135M | 1.7 | First 300 items; 1K-token cap |
| Supra2-100M-Instruct | 100M | 1.6 | All items |
| JugnuLM-110M-R2plus | 110M | 1.3 | First 300 items; 1K-token cap |

Other models answer in text, their native format, and are scored on their final number.

Published results for models whose weights are not released: TinyGSM (Liu et al., 2023, [arXiv:2312.09241](https://arxiv.org/abs/2312.09241)) reports a 125M model, first pretrained on Phi-1.5 data, at 63.1% with one try and 68.9% when a 125M verifier picks one of 48 programs. Under that exact protocol (the checker’s single top pick), Lilavati scores 66.7%. TinyGSM’s 125M model trained from random initialisation reports 53.1%.

## 06 / What it is good at, and what it is not

Where it does well

Grade-school word problems: shopping and change, rates and speeds, percentages, discounts and tax, averages, simple interest, areas and perimeters, and multi-step arithmetic.

[![Eight real Lilavati answers, each from a program that ran: shopping 42 rupees, trains meeting 2 hours, discount and tax 12,600 rupees, irrelevant number 53, averages 26, cricket 75 runs, simple interest 6,000 rupees, fencing 9,360 rupees](https://udgamlabs.com/models/lilavati/examples.png)](https://udgamlabs.com/models/lilavati/examples.png)

*Selected examples. Every answer is a real Lilavati output from a program that ran.*

Where it is weak

- Irrelevant information: a number that should be ignored often gets used anyway.
- Working backwards, and problems that add an extra step to a familiar pattern.
- Unit conversions, and some ratio questions.
- Unanswerable questions: it always returns a number, even when the question has no answer.
- Anything that is not a maths word problem: it is not a chatbot and has little general knowledge.

Every answer comes with its agreement (the share of tries that gave it) and the checker’s confidence. When either is below half, treat the answer as a guess; the try box then says it is not sure.

## 07 / Limitations, and three things it gets wrong

## Limitations

- Not for grading, financial or medical calculations, or anything where a wrong number could cause harm, without a person checking the program. A program that runs is not proof that it is correct.
- It works best on English grade-school maths word problems. Expect lower accuracy on other styles, longer problems and other languages.
- Never run its programs without a sandbox. The `lilavati` package checks and sandboxes every program for you.
- Intended for research and education on small reasoning models, program-aided maths, offline maths help on small devices, and as a starting point for fine-tuning.

## Three things it gets wrong

- Unit conversion

    “How many seconds are there in 3.5 hours?”

    It said 756,000; the answer is 12,600. Only 1 of 8 tries agreed, so it said it was not sure.

- Ratio

    “A recipe for 4 people needs 3 cups of rice. How many cups of rice are needed for 10 people?”

    It said 30; the answer is 7.5. Only 1 of 8 tries agreed, so it said it was not sure.

- Working backwards

    “After spending half of his money on a book and then 30 rupees on lunch, Arjun has 70 rupees left. How much money did he have at first?”

    It said 340; the answer is 200. Only 1 of 8 tries agreed, so it said it was not sure.

## 08 / The name

The name

## Līlāvatī (लीलावती)

Bhāskara II · 1150 CE

In 1150 CE, the mathematician Bhāskara II wrote Līlāvatī, a book of arithmetic word problems for a young student: merchants and markets, travellers and tanks of water.

Today, that book has a new reader.

## 09 / The model, and how to run it

## The model

- **Parameters**: 94.7M · 12 layers, width 640
- **Initialisation**: Random weights; trained from scratch
- **Training data**: Public synthetic maths datasets with Python solutions, general English text, the GSM8K training split, and problems generated with large language models and verified by executing their solutions.
- **Input → output**: An English word problem → a Python function whose return value is the answer
- **Context**: 4,096 tokens
- **Checker**: Lilavati-Checker (95M) rates each program so that many tries can be combined
- **Licence**: Apache-2.0 (weights and code)

## How to run it

It is small enough to run on a laptop CPU. The `lilavati` package writes the programs, runs them in a restricted sandbox and combines the answers.

```
pip install torch transformers
git clone https://github.com/udgamlabs/lilavati && cd lilavati && pip install -e .

# from Python
from lilavati import Lilavati
lv = Lilavati()      # downloads udgamlabs/Lilavati and udgamlabs/Lilavati-Checker

r = lv.solve("A shop sells pencils at 8 rupees each. Riya buys 6 pencils and 2 erasers at 5 rupees each. "
             "She pays with a 100 rupee note. How much change does she get?")
print(r["answer"])        # 42
print(r["agreement"])     # share of tries that gave this answer
print(r["program"])       # the program behind the answer
```

- `lv.solve(q, tries=1)` is one greedy try: fastest, no checker.
- `lv.solve(q, tries=8)` (the default) writes 8 programs, runs them all, and picks the answer with the most checker-weighted support. More tries are slower but more accurate.

### From an AI agent

Lilavati also runs as a tool on our MCP server, so Claude Code, Codex, Cursor and other MCP clients can call it. Each call returns the answer, how sure Lilavati is and the program behind it; the default writes 8 programs and adds the checker’s score, or ask for one quick try.

```
# Claude Code
claude mcp add --transport http udgamlabs https://mcp.udgamlabs.com/mcp

# Codex
codex mcp add udgamlabs --url https://mcp.udgamlabs.com/mcp

# Cursor: .cursor/mcp.json
{ "mcpServers": { "udgamlabs": { "url": "https://mcp.udgamlabs.com/mcp" } } }
```

The tool is `lilavati_solve`; the same server has every model that runs as a tool ([all tools, and setup for Claude, VS Code and other apps](https://udgamlabs.com/mcp)). The model runs on Hugging Face’s shared GPUs (ZeroGPU), which give each caller a few free GPU minutes a day; if they run out, add your own Hugging Face token as the header `X-HF-Token` to use your account’s minutes.

## 10 / Weights, code and the evaluation

- [Lilavati on Hugging Face](https://huggingface.co/udgamlabs/Lilavati)

    Weights and model card

- [Lilavati-Checker on Hugging Face](https://huggingface.co/udgamlabs/Lilavati-Checker)

    The 95M model that rates programs

- [Lilavati-GGUF](https://huggingface.co/udgamlabs/Lilavati-GGUF)

    Both models for llama.cpp and for running in the browser

- [GitHub repository](https://github.com/udgamlabs/lilavati)

    Code, sandbox and evaluation

Weights and code are released under Apache-2.0.

---

## About Udgam Labs

Udgam Labs is an independent AI research lab. We work from first principles: before we build, we understand why things work, whether we are training a model, fine-tuning one or applying AI to a new problem. Today that means open models such as Gargi, a 384M-parameter language model that comes within 2 points of Qwen2.5-0.5B on three reasoning benchmarks with about 1,000× less training data. Next come products, custom models for businesses, and AI in the physical world. Udgam (उद्गम) is Sanskrit for origin.

Udgam Labs · AI research from first principles · https://udgamlabs.com
