decidekit 0.2.0 → 0.2.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,86 +1,93 @@
1
- # Changelog
2
-
3
- ## 0.2.0 (unreleased)
4
-
5
- ### Training
6
-
7
- - From 8 examples per label (mean across labels), `train()` fits the head with full-batch Adam, starting from the same centroid and label-name point. Test accuracy with all data: BANKING77 90.6% to 93.1%, CLINC150 94.6% to 96.1%, HWU64 90.15% to 91.17% (one seed, on cached embeddings; through train() in eval/results-h14.json, BANKING77 93.1% and CLINC150 96.3%). At 5 per label nothing changes. At 10 per label: BANKING77 84.4% to 87.5%, CLINC150 92.2% to 92.5%, HWU64 85.50% to 85.38%. Adam's settings come from jimothy's `src/linear.ts` (MIT, Andrew Prifer).
8
- - New option `solver`. Setting `learningRate` or `l2` without it keeps SGD, so tuned calls behave as before. The default `epochs` is 100 with Adam.
9
- - Saved heads keep working unchanged. Retrained heads can score differently, so pick `minConfidence` thresholds again: the CLINC150 out-of-scope threshold moved from 0.9 to 0.98.
10
- - Training takes longer: in Node, BANKING77 went from 84 s to 123 s on cached embeddings. In Chrome, BANKING77 took 208 s with a longest page stall of 19 ms.
11
-
12
- ## 0.1.1 (2026-11-02)
13
-
14
- ### Models
15
-
16
- - The default model id is `debuffjp/decide-small` (Decide Small). Before 0.1.1 it was `Xenova/bge-small-en-v1.5`. The
17
- weights are identical, so decisions don't change. For other languages the id is `debuffjp/decide-multilingual`
18
- (Decide Multilingual), identical to `Xenova/multilingual-e5-small`.
19
- - The old ids and heads recording them keep working. They resolve to the new ids, so `d.model` returns the new id. A
20
- head trained on 0.1.1 records the new id, so a 0.1.0 decider needs that id passed as `model` to use it.
21
- - Downloads of both models are pinned to a revision.
22
- - New option `modelHost` serves model files from `<modelHost>/<model>/` instead of Hugging Face. It applies to the
23
- whole page or process.
24
-
25
- ### Docs
26
-
27
- - Label names count as 1 example in every doc, and the advice to turn them off with bge-small is gone: it applied to the
28
- old weight of 3.
29
- - Calibration, out-of-scope and zero-shot numbers are now bge-small's or labelled with the model they were measured on.
30
- - `decide()` documents that a described label scores by the better of its name and description.
31
- - The API reference covers `decidekit/typesafe`.
32
-
33
- ## 0.1.0 (2026-11-02)
34
-
35
- The first release. Numbers are on public test splits unless noted; the scripts that produced them are in `eval/`.
36
-
37
- ### Deciding
38
-
39
- - `createDecider()` picks one of your labels for a text, in Node or the browser, with `confidence` and `probabilities`. Labels
40
- are the type: `choice` has the literal type of the labels you pass.
41
- - Zero-shot from label names, or from described labels (`{ card_arrival: "My card hasn't arrived." }`), which score by
42
- the better of name and description. Zero-shot decisions report `similarity`, the best cosine similarity to any
43
- option, which is low for off-topic text.
44
- - `minConfidence` returns `null` below a threshold. `decideMany()` for batches.
45
- - Default encoder: `Xenova/bge-small-en-v1.5` at 8-bit (34 MB). Any transformers.js feature-extraction model can be
46
- passed as `model`.
47
- - Supported encoders with measured settings: `Xenova/bge-small-en-v1.5` (default) and `Xenova/multilingual-e5-small`.
48
- The temperature fit now searches 0.01 to 10, so encoders with close similarities calibrate.
49
- - `describeLabels()` asks an LLM once to write label descriptions (7 to 10 points better zero-shot on the dev splits).
50
-
51
- ### Training
52
-
53
- - `train()` fits one softmax layer on frozen embeddings: 90.7% on BANKING77 and 94.4% on CLINC150 with all examples,
54
- 82.3% and 89.6% with 5 per label. HWU64, never used for tuning: 90.2%.
55
- - Calibrated: the temperature is fitted on held-out examples (5 folds for small sets), with a per-model floor for
56
- small heads. Calibration error 0.01 to 0.03 for heads with 10 or more examples per label.
57
- - `labels` adds labels without examples yet (they start from their names). `calibrateOn` fits the temperature on
58
- examples known to be right, for training data from a source that is sometimes wrong.
59
- - `saveHead()` and `loadHead()`. Ready-made heads for BANKING77 and CLINC150.
60
-
61
- ### Learning from an LLM
62
-
63
- - `withFallback()` answers locally when confident and calls your `ask` otherwise; each answer becomes a training
64
- example and `retrainEvery` retrains in the background. It can start from labels alone.
65
- - Built for an LLM that is sometimes wrong: starting from labels, it fits confidence on zero-shot's own confident
66
- answers rather than the LLM's, and learns `null` answers as the label `NONE` (`learnNone`) when the text is far
67
- from every label (`noneBelow`), so it can answer `null` itself for off-topic text.
68
- - `route.saved()` returns the learned answers and the calibration set as plain JSON; pass them back as `restore` after
69
- a reload. With real Llama 3.1 8B answers on
70
- 12 labels, the share sent fell from 30% (zero-shot) to 19%, and off-topic text given a wrong label from 6.7% to 2.4%.
71
-
72
- ### Browser and tools
73
-
74
- - `decidekit/typesafe`: `typesafeClient()` gives a decider the shape of TypeSafe's SDK (`systemOne({ state, questions })`,
75
- `choice()`, `probabilities`, their `confidence` formula). Choice questions only.
76
- - `decidekit/browser`: `createWorkerDecider()` runs the encoder in a Web Worker (training BANKING77 froze the page for
77
- 171 s on the main thread; the longest stall in a worker was 18 ms).
78
- - `decidekit/react`: `useDecider()` and `useDecision()`.
79
- - `decidekit/switch`: a decider for the switch agent harness.
80
- - A CLI: `decidekit train` and `decidekit decide`.
81
-
82
- ### Known limits
83
-
84
- - The default encoder reads English. `Xenova/multilingual-e5-small` is supported for other languages (76% on Japanese
85
- and Chinese MASSIVE intents, calibrated), but `withFallback`'s off-topic gate doesn't fire with it.
86
- - Weak at tone: 61% on tweet sentiment and 49% on emotion with 32 examples per label. See the FAQ.
1
+ # Changelog
2
+
3
+ ## 0.2.1 (2026-11-02)
4
+
5
+ ### Browser
6
+
7
+ - `createWorkerDecider()` rejects when the worker fails to load, crashes or sends an unreadable message. Before, the call never settled. Calls after a failure or after `terminate()` reject too.
8
+ - The wasm download is 12.9 MB (3.3 MB gzipped) unless you pass `device: "webgpu"`. Earlier docs said an alias got this size, but in Chrome with an esbuild build, 0.2.0 fetched the 23.6 MB file with or without it. The alias is now optional and only trims about 14.5 KB gzipped of worker JS. Paths you set in `wasmPaths` are left alone.
9
+
10
+ ## 0.2.0 (2026-11-02)
11
+
12
+ ### Training
13
+
14
+ - From 8 examples per label (mean across labels), `train()` fits the head with full-batch Adam, starting from the same centroid and label-name point. Test accuracy with all data: BANKING77 90.6% to 93.1%, CLINC150 94.6% to 96.1%, HWU64 90.15% to 91.17% (one seed, on cached embeddings; through train() in eval/results-h14.json, BANKING77 93.1% and CLINC150 96.3%). At 5 per label nothing changes. At 10 per label: BANKING77 84.4% to 87.5%, CLINC150 92.2% to 92.5%, HWU64 85.50% to 85.38%. Adam's settings come from jimothy's `src/linear.ts` (MIT, Andrew Prifer).
15
+ - New option `solver`. Setting `learningRate` or `l2` without it keeps SGD, so tuned calls behave as before. The default `epochs` is 100 with Adam.
16
+ - Saved heads keep working unchanged. Retrained heads can score differently, so pick `minConfidence` thresholds again: the CLINC150 out-of-scope threshold moved from 0.9 to 0.98.
17
+ - Training takes longer: in Node, BANKING77 went from 84 s to 123 s on cached embeddings. In Chrome, BANKING77 took 208 s with a longest page stall of 19 ms.
18
+
19
+ ## 0.1.1 (2026-11-02)
20
+
21
+ ### Models
22
+
23
+ - The default model id is `debuffjp/decide-small` (Decide Small). Before 0.1.1 it was `Xenova/bge-small-en-v1.5`. The
24
+ weights are identical, so decisions don't change. For other languages the id is `debuffjp/decide-multilingual`
25
+ (Decide Multilingual), identical to `Xenova/multilingual-e5-small`.
26
+ - The old ids and heads recording them keep working. They resolve to the new ids, so `d.model` returns the new id. A
27
+ head trained on 0.1.1 records the new id, so a 0.1.0 decider needs that id passed as `model` to use it.
28
+ - Downloads of both models are pinned to a revision.
29
+ - New option `modelHost` serves model files from `<modelHost>/<model>/` instead of Hugging Face. It applies to the
30
+ whole page or process.
31
+
32
+ ### Docs
33
+
34
+ - Label names count as 1 example in every doc, and the advice to turn them off with bge-small is gone: it applied to the
35
+ old weight of 3.
36
+ - Calibration, out-of-scope and zero-shot numbers are now bge-small's or labelled with the model they were measured on.
37
+ - `decide()` documents that a described label scores by the better of its name and description.
38
+ - The API reference covers `decidekit/typesafe`.
39
+
40
+ ## 0.1.0 (2026-11-02)
41
+
42
+ The first release. Numbers are on public test splits unless noted; the scripts that produced them are in `eval/`.
43
+
44
+ ### Deciding
45
+
46
+ - `createDecider()` picks one of your labels for a text, in Node or the browser, with `confidence` and `probabilities`. Labels
47
+ are the type: `choice` has the literal type of the labels you pass.
48
+ - Zero-shot from label names, or from described labels (`{ card_arrival: "My card hasn't arrived." }`), which score by
49
+ the better of name and description. Zero-shot decisions report `similarity`, the best cosine similarity to any
50
+ option, which is low for off-topic text.
51
+ - `minConfidence` returns `null` below a threshold. `decideMany()` for batches.
52
+ - Default encoder: `Xenova/bge-small-en-v1.5` at 8-bit (34 MB). Any transformers.js feature-extraction model can be
53
+ passed as `model`.
54
+ - Supported encoders with measured settings: `Xenova/bge-small-en-v1.5` (default) and `Xenova/multilingual-e5-small`.
55
+ The temperature fit now searches 0.01 to 10, so encoders with close similarities calibrate.
56
+ - `describeLabels()` asks an LLM once to write label descriptions (7 to 10 points better zero-shot on the dev splits).
57
+
58
+ ### Training
59
+
60
+ - `train()` fits one softmax layer on frozen embeddings: 90.7% on BANKING77 and 94.4% on CLINC150 with all examples,
61
+ 82.3% and 89.6% with 5 per label. HWU64, never used for tuning: 90.2%.
62
+ - Calibrated: the temperature is fitted on held-out examples (5 folds for small sets), with a per-model floor for
63
+ small heads. Calibration error 0.01 to 0.03 for heads with 10 or more examples per label.
64
+ - `labels` adds labels without examples yet (they start from their names). `calibrateOn` fits the temperature on
65
+ examples known to be right, for training data from a source that is sometimes wrong.
66
+ - `saveHead()` and `loadHead()`. Ready-made heads for BANKING77 and CLINC150.
67
+
68
+ ### Learning from an LLM
69
+
70
+ - `withFallback()` answers locally when confident and calls your `ask` otherwise; each answer becomes a training
71
+ example and `retrainEvery` retrains in the background. It can start from labels alone.
72
+ - Built for an LLM that is sometimes wrong: starting from labels, it fits confidence on zero-shot's own confident
73
+ answers rather than the LLM's, and learns `null` answers as the label `NONE` (`learnNone`) when the text is far
74
+ from every label (`noneBelow`), so it can answer `null` itself for off-topic text.
75
+ - `route.saved()` returns the learned answers and the calibration set as plain JSON; pass them back as `restore` after
76
+ a reload. With real Llama 3.1 8B answers on
77
+ 12 labels, the share sent fell from 30% (zero-shot) to 19%, and off-topic text given a wrong label from 6.7% to 2.4%.
78
+
79
+ ### Browser and tools
80
+
81
+ - `decidekit/typesafe`: `typesafeClient()` gives a decider the shape of TypeSafe's SDK (`systemOne({ state, questions })`,
82
+ `choice()`, `probabilities`, their `confidence` formula). Choice questions only.
83
+ - `decidekit/browser`: `createWorkerDecider()` runs the encoder in a Web Worker (training BANKING77 froze the page for
84
+ 171 s on the main thread; the longest stall in a worker was 18 ms).
85
+ - `decidekit/react`: `useDecider()` and `useDecision()`.
86
+ - `decidekit/switch`: a decider for the switch agent harness.
87
+ - A CLI: `decidekit train` and `decidekit decide`.
88
+
89
+ ### Known limits
90
+
91
+ - The default encoder reads English. `Xenova/multilingual-e5-small` is supported for other languages (76% on Japanese
92
+ and Chinese MASSIVE intents, calibrated), but `withFallback`'s off-topic gate doesn't fire with it.
93
+ - Weak at tone: 61% on tweet sentiment and 49% on emotion with 32 examples per label. See the FAQ.
package/README.md CHANGED
@@ -134,8 +134,7 @@ const r = await d.decide(text, head);
134
134
 
135
135
  Import `loadHead` from `decidekit/browser` too, not from `decidekit`: that keeps the encoder out of your page bundle.
136
136
 
137
- Tested from npm in Vite 7, webpack 5 and Next.js 16 apps; see [docs/bundlers.md](docs/bundlers.md) for the config, including a one-line alias
138
- that halves the wasm download. Serve the page cross-origin isolated if you can:
137
+ Tested from npm in Vite 7, webpack 5 and Next.js 16 apps; see [docs/bundlers.md](docs/bundlers.md) for the config. Serve the page cross-origin isolated if you can:
139
138
 
140
139
  ```
141
140
  Cross-Origin-Opener-Policy: same-origin
@@ -144,7 +143,7 @@ Cross-Origin-Embedder-Policy: credentialless
144
143
 
145
144
  That lets wasm use several threads: in our runs with all-MiniLM-L6-v2 it cut p95 decision time from 14.3 ms to 7.8 ms. With the default bge-small, isolated, p95 is 13.8 ms.
146
145
 
147
- Download on first visit: the model (34 MB) and onnxruntime's wasm (23.6 MB, 5.8 MB gzipped), both cached after.
146
+ Download on first visit: the model (34 MB) and onnxruntime's wasm (12.9 MB, 3.3 MB gzipped; 23.6 MB before 0.2.1), both cached after.
148
147
 
149
148
  ## Models
150
149
 
package/dist/browser.js CHANGED
@@ -18,7 +18,20 @@ export async function createWorkerDecider({ onProgress, ...options } = {}, worke
18
18
  pending.delete(data.id);
19
19
  data.error ? p.reject(new Error(data.error)) : p.resolve(data.value);
20
20
  };
21
+ // After this the worker never answers, so every call, now or later, has to reject.
22
+ let dead;
23
+ const fail = (message) => {
24
+ dead = new Error(message);
25
+ for (const p of pending.values())
26
+ p.reject(dead);
27
+ pending.clear();
28
+ };
29
+ // A failed load gives an empty message, and a wrong worker URL from the bundler is its usual cause.
30
+ worker.onerror = (e) => fail(`decidekit: the worker failed: ${e.message || "it did not load, check the worker URL your bundler produced"}`);
31
+ worker.onmessageerror = () => fail("decidekit: the worker failed: it sent a message the page can't read");
21
32
  const call = (op, payload, progress) => new Promise((resolve, reject) => {
33
+ if (dead)
34
+ return reject(dead);
22
35
  const id = next++;
23
36
  pending.set(id, { resolve, reject, progress });
24
37
  worker.postMessage({ id, op, ...payload });
@@ -35,9 +48,7 @@ export async function createWorkerDecider({ onProgress, ...options } = {}, worke
35
48
  train: (examples, { onEpoch, ...opts } = {}) => call("train", { args: [examples, opts] }, (p) => onEpoch?.(p.epoch, p.accuracy)),
36
49
  terminate: () => {
37
50
  worker.terminate();
38
- for (const p of pending.values())
39
- p.reject(new Error("decidekit: the worker was terminated"));
40
- pending.clear();
51
+ fail("decidekit: the worker was terminated");
41
52
  },
42
53
  };
43
54
  }
package/dist/index.js CHANGED
@@ -40,6 +40,15 @@ function toDecision(labels, p) {
40
40
  const probabilities = Object.fromEntries(labels.map((l, i) => [l, p[i]]));
41
41
  return { choice: labels[best], confidence: p[best], probabilities };
42
42
  }
43
+ function usePlainWasm() {
44
+ // transformers.js points browsers other than Safari at the 23.6 MB WebGPU-capable build whatever JS is bundled.
45
+ // Leaves paths the app set itself alone.
46
+ const paths = env.backends.onnx.wasm?.wasmPaths;
47
+ if (!paths || typeof paths === "string" || !paths.wasm?.startsWith("https://cdn.jsdelivr.net/npm/onnxruntime-web@"))
48
+ return;
49
+ paths.wasm = paths.wasm.replace(".asyncify.", ".");
50
+ paths.mjs = paths.mjs?.replace(".asyncify.", ".");
51
+ }
43
52
  /**
44
53
  * Loads the encoder (downloaded once, then cached by the browser or transformers.js) and returns `decide()` and
45
54
  * `train()`. In a browser, prefer `createWorkerDecider()` from `decidekit/browser`: the encoder blocks the thread
@@ -51,6 +60,8 @@ export async function createDecider({ model: requested = SMALL, device, dtype =
51
60
  env.remoteHost = modelHost.endsWith("/") ? modelHost : modelHost + "/";
52
61
  env.remotePathTemplate = "{model}/";
53
62
  }
63
+ if (device !== "webgpu")
64
+ usePlainWasm();
54
65
  const embed = await pipeline("feature-extraction", model, {
55
66
  device, dtype, revision: REVISIONS[model],
56
67
  progress_callback: onProgress && ((p) => p.status === "progress" && onProgress({ file: p.file, loaded: p.loaded, total: p.total })),
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "decidekit",
3
- "version": "0.2.0",
3
+ "version": "0.2.1",
4
4
  "description": "A System One model in the browser: typed, calibrated text decisions on the user's device. Learns from an LLM when it isn't sure.",
5
5
  "license": "MIT",
6
6
  "repository": "github:debuffjp/decidekit",