Node & browser
The parser core (src/parser.ts) is runtime-agnostic: it takes an ONNX InferenceSession, the
runtime’s Tensor constructor, and a sub-word tokenizer, then builds the model’s word-grid input and
decodes the raw tensors by argmax. Platform specifics live only in the two entry points.
import { NlpGraph } from 'nlpgraph';
const nlp = await NlpGraph.load(); // onnxruntime-node (native), model auto-resolvedconst doc = await nlp.parse('The controller shall notify the supervisory authority.');load({ modelDir }) points at a directory containing config.json, the tokenizer files, and
model.fp16.onnx. Omit it to use the resolve-or-download behavior described in
Getting started.
Browser
Section titled “Browser”import { NlpGraph } from 'nlpgraph/browser'; // onnxruntime-web (WASM / WebGPU)
const nlp = await NlpGraph.load({ model: '/model/model.fp16.onnx', // URL or bytes config: '/model/config.json', // URL or object tokenizer, // a transformers.js PreTrainedTokenizer, or tokenizerId});const doc = await nlp.parse('Access rights must be reviewed annually.');onnxruntime-web also runs under Node (WASM), which is how the browser path is tested without a
browser. This very page’s live demo is the browser backend: the model and the ONNX WASM
runtime stream from Cloudflare R2, parsing happens client-side, and nothing is sent to a server.
Determinism
Section titled “Determinism”Decoding is greedy argmax with no randomness, so the same input yields byte-identical output on every run and on both runtimes — important for reproducible compliance/reg-tech pipelines.