Gemini Nano 本機表單填寫準確率為 80.7%,Pastewise 程式閘門的實測教訓
I aimed for 90% form-fill accuracy on-device and got 80.7%: what a code gate around Gemini Nano taught me
作者以 Gemini Nano 在 Chrome 建構 Pastewise 本機表單填寫工具,測得嚴格欄位準確率為 80.7%,未達 90% 目標。工具只接受同時出現在貼上訊息並通過格式檢查的欄位值,但這仍無法阻止把正確資訊填入錯誤欄位。
Dewi (an invented shop owner) takes orders in chat. Every evening she retypes each message into a courier booking form: name, phone, address, a postal code. One wrong digit and a parcel comes back. Pasting the message into a cloud chatbot would fix the typing and send a stranger's name, phone and address to a third party.
So I built Pastewise: paste the message, press one button, and the form fills on the laptop with Gemini Nano in Chrome, called through Firebase AI Logic. This post is about the three numbers I aimed for, missed, and published anyway. Source: github.com/edycutjong/pastewise (Apache-2.0) · 2:59 demo video · Devpost entry.
The model is not allowed to decide what's right
A small on-device model will sometimes write a value that looks right and isn't. A wrong value in a blue "done" box costs more than an empty box, so acceptance is code, not model confidence. A value is accepted only if it appears in the pasted text and passes the field's format check. Otherwise the box stays amber with a reason ("two numbers in your text — pick one").
The on-device call has no cloud fallback by construction:
export function deviceModel(schema: JsonSchema): GenerativeModel {
return getGenerativeModel(firebase().ai, {
mode: InferenceMode.ONLY_ON_DEVICE,
onDeviceParams: {
createOptions: DEVICE_CREATE_OPTIONS,
promptOptions: { responseConstraint: schema },
},
});
}
The schema is built from the live form (a <select> becomes an enum), so the model can only emit that form's fields. With Nano on the laptop, the cloud (ONLY_IN_CLOUD) has one job: read the empty form and write hints for boxes labelled CNEE or RMKS. It never sees the message. A laptop without Nano gets a notice and a sheet showing the exact message that would leave; nothing is sent until the person presses Send this one, and then that one paste goes through PREFER_ON_DEVICE.
Three bars, three misses
The targets were strict field accuracy at least 90%, wrong value shown at most 3%, warm median fill at most 2 s. The held-out set is 45 message/form pairs, written and hashed before any run on it, run once on the release build (the hints-on column ran with one uncommitted edit to the /bench page only, marked "dirty" there), three repeats, one M1 Max with Chrome 157:
| Hints off | Hints on (dirty, see below) | |
|---|---|---|
| Strict field accuracy | 80.7% (80.3–81.5) | 81.5% (80.0–82.6) |
| Wrong value shown, all boxes | 5.9% | 5.3% |
| Wrong shown in name/phone/address/postal boxes | 2.0% | 1.3% |
| Warm p50 / p95 | 2.34 s / 2.94 s | 2.40 s / 2.93 s |
All three bars missed. Most of the 5.9% is free text (notes, remarks): any phrase that really is in the message passes the "in your text" check, and a strict comparison with one clerk's wording marks 27–38% of those wrong. In the boxes where a wrong value does damage it is 2.0%. The set is small, so the ranges are wide.
The wall: "found in your text" is not "in the right box"
The gate catches invention, not misplacement. On the 180-pair bench the model picked the sender, a kinship word or an organisation as the recipient name: 10.6% wrong on one form, 8.3% on another. Both names were in the text, so the gate accepted them. My rule: a name, phone, address or postal box above 5% wrong-shown becomes always-amber. The release gate now never shows a recipient name as "found in your text":
export const ALWAYS_CHECK_KEYS: ReadonlySet<string> = new Set(["name", "cnee_nm"]);
// in gateField: if (r.state === "found" && ALWAYS_CHECK_KEYS.has(field.key)) return amber("check_by_hand", ...)
The cost is measured and on the /bench page: re-gating the same bench outputs offline takes wrong-shown in the four box types where a wrong value does damage (name, phone, address, postal code) from 2.9% to 1.0% and raises the share left amber from 7.9% to 15.6%.
The cloud teacher barely helped
I expected the cloud-written hints for cryptic labels to add about 10 points on the hardest form. On the bench they moved strict accuracy from 78.28% to 78.39%. I report it as an experiment, not a feature.
How I check "customer data never left"
A receipt on the page counts words and numbers (four characters or more) from the paste found in any request the page's own code makes. A recorded browser network log is in the repo, and a planted canary request (a same-origin fetch carrying a demo paste) is caught by both the log and the in-page ledger. Separately, with Nano unavailable and consent given, the screen showed 682 bytes (a retry sent the 341-byte message twice) and Chrome's wire log agreed. Re-run five times with a fresh profile, 0 AI requests went out before the Yes in 5 of 5; the 4 runs that reached the cloud showed 341 bytes and 341 were on the wire, and the fifth hit an App Check throttle and sent nothing. On the hosted page, 4 on-device fills made 0 requests and 0 paste-word hits. Blind spots are stated: words shorter than four letters and encoded text such as base64 are not matched, and it measures this page's requests, not the browser.
Small things that mattered
- Nano can stall under load, so each batch has a 10 s default timeout (20 s on the first attempt of the first fill of a session) and one retry. A stalled fill leaves its boxes amber and says "timed out" instead of hanging.
- Every fill carries a badge from
response.inferenceSource, so a visitor can see where it ran. - Two phone numbers in one message (an old dead one and a new one) always leave the box amber, whichever number the model picked. A model cannot guess between two numbers, so it is not asked to.
Limits
- Chrome desktop with Gemini Nano only for the on-device path; a hosted web app, not an extension, so it fills its own forms and not other sites.
- Synthetic data, one machine, three repeats, mostly English messages.
- The Content-Security-Policy still allows
unsafe-inline.
Try it (free, no login): pastewise.edycu.dev. Tests: 128 unit and 18 browser, plus 5 against the live URL, all run from the repo. (The hints-on column ran with one uncommitted edit, to the /bench page only; the prompt and the gate were unchanged, and the run file records srcDirty: true.) The Devpost entry for #BuildHybridAI is at https://devpost.com/software/pastewise.
來源:DEV Community · dev.to