@nodd/browser
v0.2.0
Published
Run nodd task-specific classifiers in the browser (transformers.js on onnxruntime-web, WASM or WebGPU).
Readme
@nodd/browser
Run a nodd model in the browser with transformers.js (onnxruntime-web: WASM by default, WebGPU opt-in). Inference runs in a Web Worker; model files are cached with the Cache API, so a model loads offline after the first visit.
npm install @nodd/browserimport { nodd } from "@nodd/browser";
const m = await nodd.load("/models/comment_moderation/v3"); // a `nodd export` folder
const d = await m.decide("Buy cheap followers at ...");
// { label: "spam", probabilities: {...}, confidence: 0.99, source: "micro", ... }
if (!m.isConfident(d)) { /* below the calibrated threshold: escalate */ }
m.dispose(); // stops the workerOptions: device: "auto" | "webgpu" | "wasm" (auto = wasm, measured faster than WebGPU at this
size), dtype: "q8" | "fp32", onProgress({ loaded, total }), worker, cache,
ortWasmPaths (default /ort/).
Serving:
- The export folder must be served from the page's own origin (never the Hub or a CDN).
- Serve
onnxruntime-web/dist/ort-wasm*atortWasmPaths. - Optional:
Cross-Origin-Opener-Policy: same-originandCross-Origin-Embedder-Policy: require-corpenable multi-threaded WASM.
The package ships as plain ESM that uses new Worker(new URL("./worker.js", import.meta.url)),
so your bundler (Vite, webpack 5, …) compiles the worker and its dependencies.
On a server, use @nodd/node: same API, native CPU.
