← Back to posts
ENSV

Three tiny models, one pile of PDFs

How small can a document classifier get?

Nov 21, 2026 · 11 min read

Scroll down

In short

I ran three small local models over 200 business PDFs. Strands Decider (2B) made no mistakes, like Nimble (9B), in about a ninth of the time. Laya (421M) was about 70 times faster than Nimble, but only 85% right. Then I took the hints away: accuracy fell to about 75% for all three, and when the giveaway words were masked too, to 51%, 51.5% and 27% (guessing gives 25%). Laya's confidence also stopped being trustworthy on look-alike documents. So test on your own data, not on clean examples.

Most of us classify documents by asking a chat model “what is this?” and parsing whatever it writes back. It works, until the model adds a friendly preamble, invents a category, or takes ten seconds to say “invoice”. Ollama recently added a different kind of model that doesn't write anything at all. A decision model reads your text, looks at the options you define, and returns a probability for each one. No parsing, no prompt tricks, and every answer comes with a confidence score.

I wanted to know how small one of these can get before it stops being useful. So I took a pile of business PDFs and ran three local models over exactly the same files: Nimble, Strands Decider and Laya. They range from 9 billion parameters down to 421 million. This post covers what you need, the code that matters, the results, and the place where the smallest model broke.

What you need

  • A Mac with Apple silicon. The Strands Decider page lists Apple silicon as a requirement, and I haven't tried other hardware.
  • Ollama 0.40 or later. All three models use its /v1/systemone endpoint. I ran 0.40.17.
  • Python 3 with pypdf to turn PDFs into text. I used Python 3.14, but nothing here depends on the version.
  • About 12 GB of disk for the three models (9.3, 2.0 and 0.85 GB) and about 9 GB of free memory while the biggest one is loaded.
  • The data: the Company Documents dataset by Ayoub Cherguelain, 2,676 PDFs and about 11 MB. I used its Hugging Face copy, which needs no account and is Apache 2.0 licensed.

What is a decision model?

A chat model answers with words. A decision model answers with a decision. You hand it some text and a question, say “what kind of document is this?”, together with the options you accept. It doesn't write a reply. It scores every option and returns the probabilities, so the answer is always one of your options, and it always comes with a number for how sure the model is.

Ollama's version of the idea is based on the Jev API from TypeSafe. You can ask three kinds of question about a text:

  • choice: pick one option from a list. You get the winner and a probability for every option. This is the one I use for sorting PDFs.
  • noul: a yes/no question, such as “does the customer ask for a refund?”. You get the probability that the answer is yes. (That is the API's name for the type.)
  • score: rate something on a scale you describe, from “not urgent” to “critical”. You get a score between the levels.

Several questions about the same text fit in one request. Typical jobs are triaging support tickets, routing a request to the right model, and moderating content.

Why not just ask a chat model? Three reasons. There is nothing to parse, because the answer can only be one of your options. It can be fast and cheap, because the model reads the text once and has nothing to write. And the confidence is built in, so unsure cases can go to a person or a bigger model. The price: it can only choose among options you wrote, it only reads text, and its confidence is not a guarantee. It can be wrong and still fairly sure. The model pages advise you to test thresholds on your own data, which is exactly what the rest of this post does.

The contestants

ModelMade byParametersOn disk
NimbleBespoke Labs9B9.3 GB
Strands DeciderStrands Agents2B2.0 GB
LayaConvai Innovations421M0.85 GB
Ollama announced the feature in this post.

All three speak the same protocol, so swapping one for another is a one-word change. Laya is the odd one out: it is a small encoder model, fine-tuned from ModernBERT, with no text-generating part at all. It scores every option in a single pass. That is why it is so small, and, as you will see, why it is so fast.

How a decision model is called

You send a piece of text, called the state, and a set of named questions. For classification the question type is choice: you list the labels and describe each one in a sentence. The reply holds the winning label, a probability for every label, and an overall confidence.

POST http://localhost:11434/v1/systemone

{
  "model": "laya",
  "state": { "document": "INVOICE #4821 ... Total due: 12,500" },
  "questions": {
    "doc_type": {
      "type": "choice",
      "instructions": "What kind of business document is this?",
      "criteria": {
        "invoice": "A bill sent to a customer asking for payment",
        "purchase_order": "An order from a buyer to a supplier",
        "shipping_order": "Delivery details for sending goods",
        "inventory": "A stock report listing quantities"
      }
    }
  }
}

-> { "answers": { "doc_type": {
       "choice": "invoice",
       "probabilities": { "invoice": 0.999, ... },
       "confidence": 0.996 } } }
The whole protocol. Swap the model name to swap the model.

One limit shapes everything else: these models only take text. There is no image or PDF input, so the PDF has to become text first. That turns out to be the easy part.

The data

The dataset holds four kinds of PDF: invoices, purchase orders, shipping orders and inventory (stock) reports. The label is hidden in the file name, which is handy for scoring and dangerous for testing. So the script never sends the file name, and it refuses to classify a file whose name shows up in its own text. The models see only what is printed inside the PDF.

One gotcha for anyone repeating this: the folders in the dataset mix two kinds of document, so label by the file-name prefix instead. I sampled 50 files per class, 200 in total, with a fixed random seed so every model gets exactly the same files. The first page of each PDF is enough, roughly 200 to 900 characters.

The code

Three small pieces do the work. Everything else is bookkeeping that an agent can fill in. First, PDF to text:

from pypdf import PdfReader

def pdf_text(path, max_chars=2000):
    page = PdfReader(path).pages[0]
    text = page.extract_text() or ""
    lines = [l.strip() for l in text.splitlines()]
    return "\n".join(l for l in lines if l)[:max_chars]

Then the call to the model, which is the request from above in Python:

import json, urllib.request

LABELS = {...}  # label -> one sentence describing it
URL = "http://localhost:11434/v1/systemone"

def classify(text, model):
    question = {
        "type": "choice",
        "instructions": "What kind of business document is this?",
        "criteria": LABELS,
    }
    body = {"model": model, "state": {"document": text},
            "questions": {"doc_type": question}}
    req = urllib.request.Request(
        URL, data=json.dumps(body).encode(),
        headers={"Content-Type": "application/json"})
    with urllib.request.urlopen(req, timeout=120) as r:
        return json.load(r)["answers"]["doc_type"]

And a loop that times the two steps separately and saves everything:

import time

for path in files:   # same seeded sample for every model
    t0 = time.perf_counter()
    text = pdf_text(path)
    t1 = time.perf_counter()
    answer = classify(text, model)
    t2 = time.perf_counter()
    save(path.name, true_label(path.name), answer, text,
         extract_ms=(t1 - t0) * 1000,
         classify_ms=(t2 - t1) * 1000)

Save more than you think you need: the prediction, the confidence and probabilities for every label, the runner-up, both timings, the exact text that was sent and the raw reply. When a model is wrong, that data lets you ask why instead of guessing. Run the models one at a time, unload the others, and make one untimed warm-up request first. Loading Nimble took 55 seconds, which would have ruined the timing of its first file.

Results

ModelAccuracyMedian time per fileWhole run
Nimble100%7.9 s26.6 min
Strands Decider100%0.88 s3.1 min
Laya85%0.11 s0.4 min
200 PDFs, 50 per class. The time is for classification only; reading the PDF added about 9 ms.

Two of the three made no mistakes at all. On this data the 2B model matched the 9B one and was about nine times faster. Laya was the fastest by far, roughly 70 times faster than Nimble, and the least accurate.

The interesting part is where Laya failed. Every invoice, purchase order and inventory report was right. But it got only 20 of 50 shipping orders, and called 29 of the rest purchase orders. My guess, after reading the saved text: a shipping order opens with “Order ID” and lists products and quantities, which looks a lot like a purchase order. Laya couldn't separate them, and it knew it. Its confidence on every shipping order was below 0.43, while on every other document it was 0.64 or higher, with a median of 0.94.

Confidence is the trade-off

That makes confidence a usable alarm bell. Try keeping only the answers above a threshold, and see how much of the work is automated (coverage) and how right those answers are:

Confidence at leastNimbleStrands DeciderLaya
0.5100% / 100%97.5% / 100%75% / 100%
0.8100% / 100%75% / 100%73.5% / 100%
0.995.5% / 100%25% / 100%63.5% / 100%
Coverage / accuracy among the answers kept. Every answer above 0.5 was correct, for every model.

The scales differ, though. Nimble is bold (average 0.96 when right) and Strands Decider is cautious (0.82), so pick thresholds per model, from your own data. It also suggests a cheap trick: let Laya answer first, and ask Strands Decider only when Laya's confidence is under 0.5. I replayed that from the saved logs, without any new model calls. All 200 were correct, and the average time fell to about 0.38 s per file, against roughly 0.9 s for Strands Decider alone.

The catch is that the 50 uncertain files were exactly the shipping orders, so Laya's fast path simply covered the other three types. This is a replay on one dataset, not a live measurement. Treat it as an idea to test, not a result.

Taking the hints away

Everything so far had a hint in plain sight. Invoices open with the word “Invoice”, purchase orders with “Purchase Orders” and inventory reports with “Stock Report”, and shipping orders are full of “Ship Name” and “Shipping Details”. So I ran the same 200 files again with the hints taken away, in two rounds. First with the title line dropped. Then with that and every giveaway word masked out (invoice, purchase, ship, stock, report, units, sold), shown to the model as xxxx.

Dropping the title was enough to knock every model down to about 75%, and the reason is simple. Inventory reports and shipping orders still gave themselves away in the body (“Units Sold”, “Ship Name”), so all three models kept those at 92% to 100%. But invoices and purchase orders, which share most of their fields, became impossible to tell apart. Strands Decider called 46 of 50 invoices purchase orders. Nimble did the opposite and called 46 of 50 purchase orders invoices. Laya called every invoice a purchase order. Each model picked a side and stuck to it, which is how you get from 100% to roughly 75%: 100 files right, and half of the other 100.

With the giveaway words masked, the shipping orders fell apart too. Strands Decider labelled all 50 of them invoices, and Nimble got only 6 right. Inventory reports survived for Strands Decider (50 of 50) and Nimble (48 of 50), apparently from the shape of the tables, which suggests they do read structure and not only words. Laya didn't: it called nearly everything a purchase order and scored 27%, barely above the 25% you would get by guessing.

The confidence scores tell the other half of the story. Strands Decider and Nimble stayed honest at the top: what they answered with confidence 0.9 or more was correct (that was 25% and 42% of the files with the title gone, and nothing at all once the words were masked). Laya's confidence turned against it. With the title gone, its answers at 0.9 or higher covered 16% of the files and none of them was right, and on average it was more sure when wrong (0.83) than when right (0.50).

That breaks the “Laya first” idea from earlier. A confidence gate only works while the confidence can be trusted, and here Laya's could not. On the easy data it worked because the uncertain cases were exactly the shipping orders. Take the hints away and it is sure and wrong.

Gotchas

  • The first request is slow, because the model has to load. Do an untimed warm-up, or your first file pays for it.
  • Advertised speeds are best cases. The model pages quote times from a few tens of milliseconds. On my Mac the models were between 3 and 90 times slower than the numbers on their pages. That may just be different hardware, and I didn't dig into it.
  • Laya's window is small. Ollama reports 512 tokens, and at least one of my 200 documents hit the cap and was cut. Most were around 240 tokens, so it rarely mattered, but long documents would.

What this doesn't show

This is still a small, friendly test. The documents are clean, machine-generated templates from one source, and 200 files is a sample, each model run once on one machine. “100%” means I saw no mistakes, not that there are none. The harder rounds have their own catches: the xxxx mask leaves a trace a model could pick up on, and without its title an invoice is very close to a purchase order, so part of the drop is the test and not the models. Real invoices and orders come in many layouts, and I haven't tried those.

Verdict

For a simple, cheap classifier I would still start with Strands Decider: perfect while the documents announce themselves, as good as Nimble when they don't, under a second per file and 2 GB on disk. Nimble gave no extra accuracy anywhere and costs about nine times as long. Laya is tempting for its speed, but the harder test showed its confidence can't be trusted on look-alike documents, so I wouldn't put it in front of anything without checking it on your own data first. The most useful thing I learned isn't a ranking. How well a model does depends on how much the documents give away, and all three lean heavily on headings and vocabulary. A 100% on clean data tells you little, so test on the data you will actually have.

Reproduce it with your agent

Hand the recipe to your coding agent. The button copies a prompt to your clipboard with the setup, the data, the method and every link from this article. The scripts I used live in labs/pdf-classifier/ in this site's repository, if you would rather read than rebuild.

Copies a prompt for your coding agent.

Written together with AI

This article was written together with AI (Claude). The experiments ran on my own machine and the numbers come from the saved results, but treat it as a starting point and check things before you rely on them.