Starling 4B, swappable decision adapters for business

Starling 4B (szpak)

Starling 4B is a set of four decision adapters for business paperwork in Polish: legal, accounting, procurement and finance. They share one frozen base, Qwen3.5-4B in 4-bit. For each question your code switches on the adapter of the department that owns it. General questions go to Bullfinch 4B, the general Polish decision model that every Starling adapter was trained from.

Each adapter reads a state, such as a contract clause, an invoice line or an e-mail, together with one typed question: a choice or a yes/no. It returns a probability for every option. The answer comes from the option-letter logits of one forward pass, so no text is generated. It runs on a laptop GPU with 8 GB.

Made by TAKZEN_DEV.

Why adapters

Starling is half of an experiment. One question is whether a single 4B decision model can carry a whole company process, or whether one base with swappable adapters does better. The other half of the experiment is Wren 4B, a single adapter trained on the same rows with the same recipe. Both are reported below, whichever wins.

The case for adapters is not that 4B is too small. It rests on three points:

  1. Fixing one department does not move the others. If you retrain the legal adapter, the accounting, procurement and finance answers stay bit-identical.
  2. Each department owns its adapter, along with its data and its audit trail.
  3. A new task is a new adapter. Nothing else is retrained.

Each adapter specialises, and that costs it some general skill (see "General questions" below). This is why general questions are routed to Bullfinch 4B rather than to a department adapter.

Adapters also have a cost. Each adapter reads the document on its own, so departments cannot share a prompt cache, and long documents become more expensive.

Decisions

A B2B contract and an invoice arrive with an e-mail. Starling answers six kinds of question across four departments.

Adapter Decision Type Options
legal does the NDA excerpt support a statement (17 ContractNLI hypotheses) choice supports / contradicts / does not say
legal does the clause provide for X (13 CUAD categories, e.g. uncapped liability, auto-renewal, non-compete) yes/no
accounting which expense account fits the invoice line choice 6 accounts from the chart given in the question
accounting which VAT rate fits the invoice line under the company's rate matrix choice 23% / 8% / 5% / exempt, with the matrix rules in the options
procurement is the invoice line the same item as the purchase-order line (ignoring quantity and price) yes/no
finance should the payment be held and verified through another channel five yes/no questions about the e-mail and the company's rule in code

Two rules hold throughout:

  • Knowledge that changes goes in the question, not in the weights. The chart of accounts, the VAT matrix and the PO are part of the state or the options. A new account or a new rate therefore needs no retraining.
  • Code compares numbers and applies policy. Ordinary code checks amounts, prices, quantities and the company's rules. The model only judges what is fuzzy, such as whether "Papier ksero A4 80 g/m², ryza" and "Papier do drukarek A4 80 g, karton 5 ryz" are the same item.

Why finance asks five questions

"Is this e-mail fraud?" is not something you can read off the text. A fake invoice looks exactly like a real one, and only the company's records tell them apart. A model trained on that question learns what the training e-mails looked like. In our first version it approved 74 of 125 fake invoices, a kind of fraud it had never seen.

The finance adapter therefore answers five literal questions about the e-mail text, each with an answer that is the same for a real and a fake invoice:

  1. Does it ask for a payment?
  2. Does it change the bank account?
  3. Does it ask for discretion or for skipping the usual procedure?
  4. Does it ask for a login or for card details?
  5. Does it refer to an earlier order, delivery or contract?

The company system adds two facts the text cannot provide: whether the sender is in the supplier master, and whether a purchase order exists. A rule in code then combines the answers. The questions, the rule and the automation threshold are in finance/SIGNALS.json. The rule was tuned on the development data and fixed before the final test was scored.

Results

All models were scored the same way:

  • Starling, Wren, Bullfinch and Qwen ran through the Bullfinch engine, with the tuned models using their own calibration.
  • basal 2.0 4.5B ran through basal-serve (/v1/systemone, official GGUF Q8_0 build, its own calibration).

Each decision has 400 test rows and 250 held-out rows. Legal rows are real contracts (English text, Polish questions). The other decisions were written by Bielik 11B v3.1, a different model from the one that wrote the training rows. Accuracy is in %. ECE is the calibration error in %. "Automated" is the share of rows answered automatically when the threshold allows at most 5% error. That threshold is fitted on the calibration split.

Test (decision types seen in training)

Decision Qwen3.5-4B untuned basal 2.0 4.5B Bullfinch 4B Wren 4B (one adapter) Starling 4B
NDA statement (ContractNLI, 3) 72.8 81.5 78.5 91.2 91.5
Risky clause (CUAD, yes/no) 80.5 80.0 80.0 89.0 89.8
Expense account (6) 98.8 98.2 99.0 99.0 99.0
VAT rate (4) 95.5 95.2 98.2 99.8 99.2
Invoice line matches PO (yes/no) 95.0 96.5 85.8 97.0 98.8
Mean of 5 88.5 90.3 88.3 95.2 95.7
Mean ECE 3.7 3.4 3.3 2.1 1.9
Automated at ≤ 5% error 67 80 68 95 96

Held-out tasks (never trained, 1,250 rows)

The held-out tasks are:

  • three ContractNLI hypotheses and three CUAD categories;
  • a different company's cost centres instead of the chart of accounts;
  • four VAT groups absent from training, with the matrix extended in the options;
  • two new kinds of goods.
Decision Qwen3.5-4B untuned basal 2.0 4.5B Bullfinch 4B Wren 4B Starling 4B
NDA statement 86.4 84.0 88.4 84.8 90.0
Risky clause 90.4 88.8 92.0 93.6 95.6
Cost centre 98.0 98.0 95.6 96.8 97.6
VAT rate, new groups 94.8 98.4 96.4 98.4 97.6
PO match, new goods 92.8 97.2 85.6 94.0 97.2
Mean of 5 92.5 93.3 91.6 93.5 95.6
Mean ECE 6.5 3.7 4.6 4.4 2.1
Automated at ≤ 5% error 65 79 69 94 95

Payments: a fresh test

This test has 495 e-mails, written by Bielik 11B with a new seed. The finance rule was fixed before scoring, and no model and no person looked at the e-mails before then. It contains 221 e-mails of the kinds seen in training. It also contains 268 e-mails of two kinds never seen in training: fake invoices from an "existing supplier", and genuine order confirmations.

The other models get one question with the company's policy appended. That policy is the same rule Starling applies in code.

Qwen3.5-4B + policy basal 2.0 4.5B + policy Bullfinch 4B + policy Wren 4B Starling 4B
Known kinds of e-mail, accuracy 95.9 95.0 91.9 100.0 100.0
Fake invoices held (new kind) 132/134 130/134 104/134 122/134 133/134
Genuine confirmations let through 126/134 134/134 134/134 134/134 132/134
Fake invoices passed by the automation 0/134 1/134 18/134 12/134 1/134

Wren asks the same five questions and uses the same rule. Its single adapter reads the signals worse on fake invoices.

General questions

This is the mean accuracy on Bullfinch's Polish choice and yes/no sets: KLEJ, PolQA, MASSIVE, Belebele, INCLUDE and OpenDecisions.

Bullfinch 4B basal 2.0 4.5B Qwen3.5-4B Wren 4B legal accounting procurement finance
83.6 82.9 75.8 81.8 82.2 78.3 81.8 81.1

Every adapter was trained with 40% general rows, yet each one still loses 1.4 to 5.3 points of general skill. Wren loses 1.8. Route general questions to Bullfinch 4B.

Updating one department

The legal department wants the held-out clause types handled. The update adds 500 training rows of those types per legal decision, taken from training contracts only, plus 1,000 old rows as rehearsal. The held-out test rows stay unseen. Starling retrains only its legal adapter. Wren has to retrain its one adapter, which also holds the other departments. Both start from the released state and train for 60 steps. Two learning rates were tried: gentle (2e-5) and harsh (1e-4).

Gentle update (lr 2e-5) Wren 4B Starling 4B
Legal, held-out clause types: accuracy 89.2 → 92.6 92.8 → 93.8
Legal, automated at 5% error: test / held-out 88 → 88 / 87 → 90 89 → 94 / 88 → 94
Accounts, VAT, PO: automated at 5% error 98.9 → 98.5 unchanged (same files)
Payments, fresh test: fakes held 122 → 122 of 134 unchanged (same files)
General questions 81.8 → 82.0 82.2 → 82.2
Retrain + re-check, minutes 24.8 + 40.4 15.6 + 5.7
Harsh update (lr 1e-4) Wren 4B Starling 4B
Legal, automated at 5% error: test 88 → 61 89 → 77
Accounts, VAT, PO: automated at 5% error 98.9 → 88.6 (procurement 97 → 67) unchanged (same files)
Payments, fresh test: fakes held 122 → 132 of 134 unchanged (same files)
General questions 81.8 → 78.8 82.2 → 81.5
  • Gentle update. Both models learn the new clause types and neither breaks. Starling gains more automation on legal: +4.1 points on the test (95% CI +2.4 … +5.9) and +6.0 on held-out types (+3.4 … +8.8), with no loss in accuracy.
  • Harsh update. The single adapter loses automation on every department it holds. In Starling the damage stays in the legal adapter, which fails its check and is simply not shipped.
  • The other Starling adapters are byte-identical before and after (sha256 checked), so only legal needs re-checking.
  • In both recipes no step beat the starting point on raw dev loss, and training kept step 60. The gentle versions are better only after calibration. Judge an update on calibrated results.

Verdict

The rule was fixed before training, on 22 November 2026. Adapters win only if both of the following hold:

  • they automate at least 3 points more at 5% error, or cut ECE by at least 1 point;
  • the paired bootstrap 95% interval excludes zero.

Result on the five shared decisions: not met.

  • Starling automates 1.2 points more on the test (95% CI +0.2 … +2.2) and 1.7 points more on held-out tasks (+0.4 … +3.0). Both gains are real but smaller than 3 points.
  • ECE does not move: −0.0 and −0.4 points, and both intervals include zero.

Starling still beats Wren where the rule does not look:

  • It is more accurate on held-out tasks: +2.1 points (+1.0 … +3.1).
  • It is safer on payments. On the fresh test it lets 1 fake invoice through, against Wren's 12. Decision accuracy there is +1.8 points (+0.4 … +3.3).
  • Wren is never clearly better.

The update test is where adapters pay off. They do not make every update safe, because a harsh update hurt the legal adapter too. They keep a bad update contained and cheap to catch: one department to re-check, 21 minutes against 65, and the other departments cannot change.

How to use

The four adapters sit in subfolders of this repo. Bullfinch 4B comes from its own repo. Load the base once, load every adapter, and switch with set_adapter before each question.

The prompt is the Bullfinch format: lettered options, and an assistant turn prefilled with {"answer": ". The decision is a softmax over the logits of the option letters, divided by the temperature from <adapter>/CALIBRATION.json.

import json
import math

import torch
from huggingface_hub import hf_hub_download
from peft import PeftModel
from transformers import AutoModelForCausalLM, AutoTokenizer, BitsAndBytesConfig

BASE, REVISION = "Qwen/Qwen3.5-4B", "851bf6e806efd8d0a36b00ddf55e13ccb7b8cd0a"
REPO = "Takzen/starling-4b"
ADAPTERS = ("legal", "accounting", "procurement", "finance")
PREFILL = '{"answer": "'
FRAME = ("Stan", "Pytanie", "Opcje", 'Odpowiedz wyłącznie w formacie JSON: {"answer": "<litera opcji>"}.')

tok = AutoTokenizer.from_pretrained(BASE, revision=REVISION)
base = AutoModelForCausalLM.from_pretrained(
    BASE, revision=REVISION, device_map={"": 0}, dtype=torch.bfloat16,
    quantization_config=BitsAndBytesConfig(load_in_4bit=True, bnb_4bit_quant_type="nf4",
                                           bnb_4bit_compute_dtype=torch.bfloat16,
                                           bnb_4bit_use_double_quant=True))
model = PeftModel.from_pretrained(base, "Takzen/bullfinch-4b", adapter_name="general")
for name in ADAPTERS:
    model.load_adapter(REPO, adapter_name=name, subfolder=name)
model.eval()
prefix = tok.encode(PREFILL, add_special_tokens=False)
CAL = {a: json.load(open(hf_hub_download(REPO, f"{a}/CALIBRATION.json")))["families"] for a in ADAPTERS}


def decide(adapter: str, state: str, question: str, options: dict[str, str],
           kind: str = "choice", temperature: float = 1.0) -> dict[str, float]:
    """Probability of each option key. `kind` is "choice" or "noul" (yes/no)."""
    model.set_adapter(adapter)
    s, q, o, reply = FRAME
    codes = dict(zip("ABCDEFGHIJKLMNOPQRSTUVWXYZ", options))
    lines = "\n".join(f"{c}) {k}: {options[k]}" if kind == "choice" else f"{c}) {options[k]}"
                      for c, k in codes.items())
    content = f"{s}:\n{state}\n\n{q}: {question}\n\n{o}:\n{lines}\n\n{reply}"
    text = tok.apply_chat_template([{"role": "user", "content": content}], tokenize=False,
                                   add_generation_prompt=True, enable_thinking=False)
    ids = tok(text + PREFILL, return_tensors="pt", add_special_tokens=False).input_ids.to(0)
    with torch.inference_mode():
        logits = model(input_ids=ids, logits_to_keep=1).logits[0, -1].float()
    letters = [tok.encode(PREFILL + c, add_special_tokens=False)[len(prefix)] for c in codes]
    probs = torch.softmax(logits[letters] / temperature, dim=0)
    return dict(zip(codes.values(), probs.tolist()))


# procurement: is the invoice line the PO item?
print(decide("procurement",
             "Pozycja w zamówieniu (PO): Długopisy żelowe Pentel EnerGel 0,7 mm, niebieskie\n"
             "Pozycja na fakturze: Długopis żelowy Pentel EnerGel BL77, niebieski, 0,7 mm",
             "Czy pozycja z faktury to ten sam towar lub usługa co pozycja z zamówienia (PO)? Ilości i ceny pomiń.",
             {"true": "tak, ta sama pozycja", "false": "nie, inny towar lub inny wariant"},
             kind="noul", temperature=CAL["procurement"]["po_match"]["temperature"]))
# {'true': 0.962, 'false': 0.038}: the same pen, 96% sure


# finance: five questions about the e-mail text, the company's rule in code
SIGNALS = json.load(open(hf_hub_download(REPO, "finance/SIGNALS.json"), encoding="utf-8"))


def hold_payment(mail: str, sender_in_supplier_master: bool, has_purchase_order: bool) -> float:
    """P(hold the payment and verify through a known channel)."""
    p = {name: decide("finance", mail, s["question"], s["criteria"], kind="noul")["true"]
         for name, s in SIGNALS["signals"].items()}
    facts = not sender_in_supplier_master and not has_purchase_order
    conds = [p["pay"] if facts else 0.0, p["account"], p["skip"], p["login"], p["pay"] * (1 - p["order"]) ** 2]
    return 1 - math.prod(1 - c for c in conds)


mail = ("Od: Katarzyna Wróbel <k.wrobel@hurtpol-sp.pl>\nTemat: Aktualizacja danych do przelewu\n\n"
        "Dzień dobry, w związku ze zmianą banku prosimy, aby płatność za fakturę FV/11/2211 "
        "przelać na nowy rachunek podany w załączniku. Prosimy o realizację jeszcze dziś.")
print(hold_payment(mail, sender_in_supplier_master=True, has_purchase_order=True))
# 0.9999: hold the payment (new account, pay today)

Use the model with thresholds, not with the top answer alone:

p = hold_payment(mail, True, True)
auto = CAL["finance"]["payment_fraud"]["thresholds"]["0.05"]   # fitted at 5% error
if p >= 0.5:
    action = "hold the payment, call the supplier on a known number"
elif 1 - p >= auto:
    action = "pay"
else:
    action = "send to a person"
  • Yes/no questions use the option keys true and false, listed by description only.
  • Choice questions list key: description. For accounts and VAT the description carries the company's own rules, so put your chart of accounts and your matrix there.
  • Each decision has its own calibration. CALIBRATION.json holds a temperature and the automation thresholds at 1% and 5% error. Fit your own on a few hundred of your rows before automating anything.
  • Questions can also be asked with an English frame (State, Question, Options). Every decision was trained with several Polish phrasings and one English one.

Run the whole flow

starling.py in this repo puts the pieces together in one file:

  • Step 0, files of unknown type: classify() asks Bullfinch 4B whether a file is a contract or an invoice. Below its threshold, the file goes to a person. E-mails are known by their channel. Bullfinch tends to call an e-mail that sends an invoice an invoice.
  • Routing: code sends each question to the adapter of the department that owns it.
  • Decisions: each one is calibrated and checked against its threshold from CALIBRATION.json.
  • Payment rule: it runs in code.
  • Gate: it decides the whole package as BLOCK, TO PERSON or AUTO.

The document's content comes from your systems: invoice lines, the purchase order, facts about the sender. A KSeF invoice and your ERP are typical sources. The model does not extract data. It only decides.

pip install torch transformers peft bitsandbytes huggingface_hub
python starling.py

It runs one package twice. The package has a contract clause, an invoice with three lines and an e-mail. The first run uses a genuine e-mail, the second a fake one asking for a new bank account.

== package with the genuine e-mail ==
document       contract  99.2%  threshold  90.0%  sure
document       invoice   98.2%  threshold  90.0%  sure
contract_risk  true      97.5%  threshold  87.5%  sure
gl_account     401-01    99.0%  threshold  52.7%  sure
vat_rate       23       100.0%  threshold  55.1%  sure
po_match       true      94.1%  threshold  59.5%  sure
gl_account     401-01    98.7%  threshold  52.7%  sure
vat_rate       23       100.0%  threshold  55.1%  sure
po_match       true      96.2%  threshold  59.5%  sure
gl_account     402-01    99.8%  threshold  52.7%  sure
vat_rate       23       100.0%  threshold  55.1%  sure
po_match       true      92.1%  threshold  59.5%  sure
payment_fraud  pay       99.9%  threshold  52.8%  sure
gate: AUTO

== package with the fraud e-mail ==
... (the same 12 decisions) ...
payment_fraud  hold     100.0%  threshold  52.8%  sure
gate: BLOCK

AUTO means every decision is sure. It does not mean "approve". Here the contract does renew automatically (contract_risk true). Your code decides what follows, such as flagging the clause for the legal team.

Training

  • Recipe: QLoRA, as in Bullfinch.
    • The base stays frozen in 4-bit NF4.
    • LoRA r 32, alpha 64, dropout 0.05, on the attention, Gated DeltaNet and MLP projections.
    • Learning rate 1e-4, batch 16, cosine decay, one pass, 2,048 tokens.
  • Each adapter starts from Bullfinch 4B, not from a fresh LoRA, so it is a continuation of the general decision model.
  • 40% of every adapter's rows are general questions from Bullfinch's training sets (KLEJ, PolQA, PLLuM-Align, MASSIVE, EXAMS). The number of examples stays the same.
  • Rows per adapter: legal 2,000, accounting 2,000, procurement 1,000 and finance 1,500. Each adapter is trained only on its own department's rows plus the general mix. Wren 4B sees all rows in one adapter, with the same recipe.
  • Rendering: every example gets a random option order and a random frame language, so neither a letter's position nor the frame carries the answer.
  • Checkpoint: the one with the lowest dev NLL out of 8 evaluations, with a stop after 4 evaluations without improvement. The chosen steps are legal 120, accounting 15, procurement 49 and finance 33.
  • Calibration: one temperature per decision, plus automation thresholds, fitted on 250 held-back rows per decision.

Data

Source Licence Used for
ContractNLI CC BY 4.0 NDA excerpt and a statement: supports, contradicts or does not say. Real contracts, human labels
CUAD CC BY 4.0 contract clause, does it provide for a given risk. Real contracts, lawyers' labels; negatives are clauses of related categories
Synthetic, training side: Qwen3.5-9B Apache 2.0 e-mails, invoice and PO lines, expense lines
Synthetic, test side: Bielik 11B v3.1 Apache 2.0 the same decisions written by a different model; the fresh payment test
General mix: KLEJ PolEmo, DYK, PSC, PolQA, PLLuM-Align, EXAMS CC BY-SA 3.0 / 4.0 general Polish decisions, as in Bullfinch
General mix: MASSIVE pl-PL CC BY 4.0 general Polish decisions, as in Bullfinch
  • Labels come first. For synthetic rows the label is drawn before generation, and the generator is told what to write, for example: a supplier asks to change the bank account without saying so outright. Outputs with template brackets, or with words that give the label away, are dropped.
  • A different writer for the test. Training rows come from Qwen and test rows from Bielik, so a model cannot score well by learning one generator's style.
  • No leaks. Splits are made by contract, by document or by generator call, never by row. Any training row whose text also appears in a test row is dropped; this removed 64 rows.
  • Balanced. Each decision has 1,000 train, 250 calibration, 100 dev, 400 test and 250 held-out test rows, balanced by label and then by subtype.
  • No outputs of commercial models or decision APIs were used.

Limitations

  • Contracts are in English (ContractNLI, CUAD), with Polish questions. There is no open Polish contract corpus with clause labels, so check the model on your own Polish contracts.
  • Accounting, procurement and finance rows are synthetic. Real invoices and e-mails are messier. Measure on your own documents and fit your own thresholds before automating anything.
  • The VAT matrix is a simplified company policy, not tax advice. The rates in force come from the law and your adviser; the model only applies the matrix you give it.
  • Finance flags e-mails for verification; it does not prove fraud. A held payment should be checked by a person through a known channel. It asks five questions per e-mail, which makes it five times slower than a single question.
  • Procurement does not know part-number aliases. It treats a different product code as a different variant. For example, it says that "HP 59A" and "CF259A" are different toners, though they are the same. Keep an alias table in code, or put both codes in the description.
  • Department adapters are weaker at general questions than Bullfinch 4B. Route those to Bullfinch.
  • Decisions with legal or financial consequences should be reviewed by a person.

Licence and attribution

The adapters are released under CC BY-SA 4.0. They are trained from Bullfinch 4B (CC BY-SA 4.0) with its CC BY-SA training sets in the mix.

  • Base model: Qwen3.5-4B (Apache 2.0).
  • Business data: ContractNLI (Koreeda and Manning, 2021) and CUAD (The Atticus Project, Hendrycks et al., 2021), both CC BY 4.0.
  • Synthetic rows: training rows written by Qwen3.5-9B; test rows written by Bielik 11B v3.1 (SpeakLeash).
  • General mix: KLEJ (Allegro), PolQA (IPI PAN), PLLuM-Align (NASK PIB), MASSIVE (Amazon) and EXAMS.
Downloads last month
-
Inference Providers NEW
This model isn't deployed by any Inference Provider. 🙋 Ask for provider support

Model tree for Takzen/starling-4b

Finetuned
Qwen/Qwen3.5-4B
Adapter
(1,265)
this model

Datasets used to train Takzen/starling-4b