Parse an address in a browser
Use the browser loader when an application needs address components in the tab. This procedure runs the published en-US modelneural classifierThe machine learning model at the core of Mailwoman's parser — a transformer encoder (~30M parameters) trained from scratch to do BIO token classification over addresses. It learns the 'grammar' of address formats; the gazetteer supplies the 'atlas.' on one address. It returns a parse treeparse treeThe hierarchical address structure produced by decoding BIO labels into spans and nesting them per the schema's containment rules (house_number → street → locality → region → country).. A geographic lookup and a delivery check are separate operations.
Prerequisites
- Node.js
^24.22.3 || >=26.13.1, for the build commands. - An ECMAScript module project with
"type": "module"in itspackage.json.
Node runs only the build. The browser runs the JavaScript and WebAssembly that Vite generates. Install these exact published versions in a fresh project:
- npm
- Yarn
- pnpm
- Bun
npm install @mailwoman/core @mailwoman/neural @mailwoman/neural-weights-en-us onnxruntime-web@1.31.1 vite@8.3.5
yarn add @mailwoman/core @mailwoman/neural @mailwoman/neural-weights-en-us onnxruntime-web@1.31.1 vite@8.3.5
pnpm add @mailwoman/core @mailwoman/neural @mailwoman/neural-weights-en-us onnxruntime-web@1.31.1 vite@8.3.5
bun add @mailwoman/core @mailwoman/neural @mailwoman/neural-weights-en-us onnxruntime-web@1.31.1 vite@8.3.5
The modelneural classifierThe machine learning model at the core of Mailwoman's parser — a transformer encoder (~30M parameters) trained from scratch to do BIO token classification over addresses. It learns the 'grammar' of address formats; the gazetteer supplies the 'atlas.' files must be served over HTTP. Copy the ten files used by this example into Vite's public/mailwoman directory. Keep the four lexicons beside model.onnx: the loader derives their URLs from the modelneural classifierThe machine learning model at the core of Mailwoman's parser — a transformer encoder (~30M parameters) trained from scratch to do BIO token classification over addresses. It learns the 'grammar' of address formats; the gazetteer supplies the 'atlas.' URL and the published model cardmodel cardA JSON metadata file (model-card.json) shipped with each weights bundle. It declares the model version, lineage, label set, required inference channels (anchor, gazetteer), calibration data, and training provenance..
mkdir -p public/mailwoman public/ort
for file in model.onnx tokenizer.model model-card.json \
anchor-lexicon-v1.json country-surface-lexicon-v1.json \
street-type-lexicon-v3.json locality-surface-lexicon-v7.json \
postcode-us.bin postcode-prefix-us.bin pair-index-us.bin; do
cp "node_modules/@mailwoman/neural-weights-en-us/$file" public/mailwoman/
done
cp node_modules/onnxruntime-web/dist/ort-wasm-simd-threaded.mjs public/ort/
cp node_modules/onnxruntime-web/dist/ort-wasm-simd-threaded.wasm public/ort/
The two ONNX RuntimeONNX (Open Neural Network Exchange). An open format for machine learning models that enables interoperability between training frameworks and inference runtimes. Mailwoman ships its trained model as an ONNX file so it can run in Node.js and the browser via onnxruntime. files are the pair fetched in the Chromium run below. A browser or runtime using another execution variant may require that variant's matching .mjs and .wasm files. Without the .mjs file beside the .wasm file, loading failed before inferenceinferenceRunning the trained model on new input to get predictions, as opposed to training, which produces the model. In Mailwoman that means a small transformer encoder reads an address string and classifies every token — house number, street, locality, region, postcode, and the rest. A Who's On First gazetteer can feed soft location hints into the pass, but the model makes the final call on every label. Where a generative model writes text token by token, Mailwoman's output is a retrieval-augmented token classification: one label per input piece. with Error: no available backend found. ERR: [wasm] TypeError: Failed to fetch dynamically imported module: http://127.0.0.1:4173/ort/ort-wasm-simd-threaded.mjs, and it succeeded once the .mjs file was in place.
Add the page and parser
Save this page as index.html at the project root:
<!doctype html>
<html lang="en">
<meta charset="utf-8" />
<title>Mailwoman browser parse</title>
<pre id="result">Loading</pre>
<script type="module" src="/main.ts"></script>
</html>
Save this module as main.ts beside index.html. Vite compiles the TypeScript entry module itself:
import { decodeAsJSON } from "@mailwoman/core/decoder"
import { loadNeuralClassifierFromURLs } from "@mailwoman/neural/web/loader"
const result = document.querySelector<HTMLPreElement>("#result")
if (!result) throw new Error("The page has no #result element")
try {
const { classifier, diagnostics, labels, pairIndexes, release } = await loadNeuralClassifierFromURLs({
modelURL: "/mailwoman/model.onnx",
tokenizerURL: "/mailwoman/tokenizer.model",
modelCardURL: "/mailwoman/model-card.json",
postcodeBinaryURLs: ["/mailwoman/postcode-us.bin"],
postcodePrefixURLs: ["/mailwoman/postcode-prefix-us.bin"],
pairIndexURLs: ["/mailwoman/pair-index-us.bin"],
country: "US",
runner: { wasmPathsRoot: "/ort/" },
})
const tree = await classifier.parse("350 5th Ave, New York, NY 10118")
result.textContent = JSON.stringify(
{
backend: diagnostics?.backend,
labels: labels?.length,
pairIndexes: pairIndexes.length,
raw: tree.raw,
components: decodeAsJSON(tree),
},
null,
2
)
await release()
} catch (error) {
result.textContent = String(error)
}
Build the page with npx vite build, then serve the built files with npx vite preview --host 127.0.0.1. Open the preview address in a browser. Chromium 156.0.8078.4 returned this complete content inside the pre element for the published 11.0.0 assets:
{
"backend": "wasm",
"labels": 33,
"pairIndexes": 1,
"raw": "350 5th Ave, New York, NY 10118",
"components": {
"region": "NY",
"locality": "New York",
"postcode": "10118",
"street": "5th",
"house_number": "350",
"street_suffix": "Ave"
}
}
decodeAsJSON provides a flat view of the tree. Use the result schema when repeated tags or spanspanA contiguous range of characters or tokens in the input string, tagged with an address component type (street, locality, postcode, etc.). Parsed addresses are represented as collections of spans, possibly nested in a tree. provenance matter.
Check the asset cost
The ten copied modelneural classifierThe machine learning model at the core of Mailwoman's parser — a transformer encoder (~30M parameters) trained from scratch to do BIO token classification over addresses. It learns the 'grammar' of address formats; the gazetteer supplies the 'atlas.', tokenizertokenizerThe component that converts a raw address string into a sequence of numeric token IDs the model can process. Mailwoman's tokenizer is a SentencePiece unigram model trained specifically on postal addresses., lexicon, postcodepostcodeThe country-specific postcode (US ZIP, French code postal, etc.). Mailwoman handles postcode parsing entirely by rule classifier — a regex problem, not an ML one., and pair-index files occupied 42,850,059 bytes on disk in the published 11.0.0 package. The copied ONNX RuntimeONNX (Open Neural Network Exchange). An open format for machine learning models that enables interoperability between training frameworks and inference runtimes. Mailwoman ships its trained model as an ONNX file so it can run in Node.js and the browser via onnxruntime. .mjs and .wasm pair occupied another 14,873,590 bytes, for 57,723,649 copied asset bytes in this example. The production build was served from local Vite preview to headless Chromium 156.0.8078.4 with the cache disabled. Chrome DevTools Protocol reported 44,150,884 encoded transfer bytes across 16 completed requests, including the page, generated scripts, modelneural classifierThe machine learning model at the core of Mailwoman's parser — a transformer encoder (~30M parameters) trained from scratch to do BIO token classification over addresses. It learns the 'grammar' of address formats; the gazetteer supplies the 'atlas.' files, and runtime files. A warm cache, a different server compression policy, or another runtime variant can change that transfer count. Browser memory use is unknown, because this run produced no reliable measurement of it.
This example loads one parser modelneural classifierThe machine learning model at the core of Mailwoman's parser — a transformer encoder (~30M parameters) trained from scratch to do BIO token classification over addresses. It learns the 'grammar' of address formats; the gazetteer supplies the 'atlas.' and one US pair index. Geographic candidates and coordinates require separate data and resolverresolverThe component that converts parsed address components (locality, region, postcode) into coordinates by looking them up in the gazetteer. The resolver ranks candidates by name match, population, and proximity, and returns the best-matching place with its centroid or polygon. behavior. See data and locale prerequisites before adding a geographic lookup.