JavaScript and the browser¶
The yellowmist npm package has the same tasks and options as the Python package, for browsers and Node.
import * as ym from "yellowmist";
await ym.punct("e kaaro bawo ni", "yor_Latn");
await ym.switch("Niko busy sana leo", { langs: ["swh_Latn", "eng_Latn"] });
await ym.segment("ภาษาไทยไม่มีช่องว่างระหว่างคำ", "tha_Thai");
await ym.suggest("Thank you very much for your", "eng_Latn");
await ym.mend("Mo fe lo si oja", "yor_Latn");
switch is a reserved word in JavaScript: with named imports use switchLangs.
In the browser¶
- Use a Web Worker. Run the models in a worker so typing never waits on a model, and call
ym.preload("punct", { lang: "yor_Latn" })there at start-up. - Files are cached with the Cache API after the first download.
- Set where ONNX Runtime loads its WebAssembly from, for example a CDN:
import * as ort from "onnxruntime-web";
ort.env.wasm.wasmPaths = "https://cdn.jsdelivr.net/npm/onnxruntime-web@1.20.0/dist/";
ym.configure({ ort });
In Node¶
Works with the default onnxruntime-web. For more speed, install onnxruntime-node and pass it:
import * as ort from "onnxruntime-node";
ym.configure({ ort });
Files are cached in ~/.cache/yellowmist (or YELLOWMIST_CACHE). The CLI works too: npx yellowmist punct "..." --lang hau_Latn.
React Native and other runtimes¶
Pass any ONNX Runtime build with configure({ ort }) (for example onnxruntime-react-native), and a file store
with configure({ store: { get, put } }) so models stay on the device between launches.
Options¶
ym.configure({ ... }) once at start-up:
| Option | What it does |
|---|---|
ort |
the ONNX Runtime build to use |
host |
where model files come from (default Hugging Face): a mirror or your own CDN with the same paths |
store |
your own file cache, { get(key), put(key, bytes) } |
fetch |
a custom fetch |