Inspect the decisions behind a parse
You'll save a parser trace for the same address used in the first-parse tutorial, then run a short script that checks every returned 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. and prints the decisions leading to the tree. The exercise takes about ten minutes after that tutorial's packages are installed.
Prerequisites
- Node.js
^24.22.3 || >=26.13.1. - The project directory from Install Mailwoman and inspect a first parse, with
mailwoman@11.0.0,@mailwoman/neural@11.0.0, and@mailwoman/neural-weights-en-us@11.0.0installed. - The exact input
apt 4b 350 5th ave new york ny 10118. The printed spansspanA 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. and scores belong to that input and the stated package versions.
1. Save the parser trace
Run the installed command from the project directory:
npx mailwoman parse --debug "apt 4b 350 5th ave new york ny 10118" > trace.json
The command writes the full JSON trace to trace.json. It also prints a warning to standard error when it finds no 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.-prefix index, saying that the anchor-regionregionThe first-level administrative subdivision of a country — a US state, a French region, a province. The component between country and locality. prior is off. The parseaddress parsingThe process of decomposing a free-text postal address string into structured components — house number, street name, locality, region, postcode, and country — so a geocoder can resolve them to coordinates. below was captured with that warning showing. Keep diagnostic messages visible when you run the command.
2. Write a trace reader
Save this file as inspect-trace.ts beside trace.json:
import { readFile } from "node:fs/promises"
interface TraceNode {
tag: string
value: string
start: number
end: number
confidence: number
children: TraceNode[]
}
interface Trace {
input: string
path: string
locale: { locale: string; source: string }
kind: { kind: string }
queryShape: { knownFormats: Array<{ format: string; span: { start: number; end: number; body: string } }> }
tree: { raw: string; roots: TraceNode[] }
}
const trace: Trace = JSON.parse(await readFile("trace.json", "utf8"))
const raw = trace.tree.raw
console.log("input:", trace.input)
console.log("tree.raw:", raw)
console.log("path:", trace.path)
console.log("locale:", trace.locale.locale, `(${trace.locale.source})`)
console.log("kind:", trace.kind.kind)
for (const match of trace.queryShape.knownFormats) {
const { start, end, body } = match.span
console.log(`shape: ${match.format} [${start}, ${end}): ${JSON.stringify(body)}`)
}
function printNode(node: TraceNode, depth = 0): void {
const source = raw.slice(node.start, node.end)
if (source !== node.value) throw new Error(`Unexpected span for ${node.tag}`)
const indent = " ".repeat(depth)
console.log(
`${indent}${node.tag} [${node.start}, ${node.end}): ${JSON.stringify(node.value)} score ${node.confidence.toFixed(3)}`
)
for (const child of node.children) {
printNode(child, depth + 1)
}
}
for (const root of trace.tree.roots) {
printNode(root)
}
The Trace interface declares the fields this reader uses, out of the larger trace document. The raw.slice check compares each node's value with the text at its offsets in tree.raw, the text returned with the tree. For this input, each selected substring equals the node's displayed value.
3. Read the result
node inspect-trace.ts
input: apt 4b 350 5th ave new york ny 10118
tree.raw: Apt 4B 350 5TH Ave New York NY 10118
path: full
locale: en-US (caller)
kind: structured_address
shape: us_zip [31, 36): "10118"
shape: fr_postcode [31, 36): "10118"
shape: de_postcode [31, 36): "10118"
region [28, 30): "NY" score 0.915
locality [19, 27): "New York" score 0.935
street [11, 14): "5TH" score 0.941
unit [0, 6): "Apt 4B" score 0.920
house_number [7, 10): "350" score 0.919
street_suffix [15, 18): "Ave" score 0.910
postcode [31, 36): "10118" score 0.917
Find "New York" in tree.raw. Its [19, 27) 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. starts at 19 and ends before 27. The script checks that slicing those positions returns the displayed value. Every other node passes the same check in this run.
The three shape lines are proposed format matches for the same five-digit text. They show that 10118 fits several 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. shapes. These matches describe the tokentokenOne word or subword in the tokenized input. For the neural classifier, tokens come from SentencePiece (subword units); for the rule classifiers, tokens are whitespace- and punctuation-separated words.'s form. The locale field records the parser's choice for the full input, and the final postcode node is its selected tag for that 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..
path: full records that the input used the full parser path. kind: structured_address is the query-kind decision. The CLI supplies en-US as its default --locale, so this trace records locale.source as caller. The library call in the first tutorial passed no localelocaleThe combination of language and country an address comes from. en-US and fr-FR are the locales Mailwoman ships weights for.. With MW_LOCALE unset, the pipelinestaged pipelineMailwoman's runtime architecture: a sequence of pure-function stages (normalize → query-shape → locale-hint → kind-classifier → phrase-grouper → classifier → decoder) connected by typed handoffs. Each stage is published as its own npm package. detects the same localelocaleThe combination of language and country an address comes from. en-US and fr-FR are the locales Mailwoman ships weights for. from the five-digit 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. shape and records locale.source as detected.
Each node's score is its returned confidence rounded to three decimal places for display. These values describe this 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.''s output for this address, as opposed to the fraction of correct labelscomponent tagOne of the 25 labels in Mailwoman's address schema — street, locality, region, postcode, house_number, unit, po_box, country, venue, intersection, and others. Each parsed span carries exactly one component tag. across other addresses. The trace also contains per-stagestageOne of the dataflow stages in the runtime pipeline (normalize, locale check, kind classify, phrase group, token classify, sequence correct, reconcile, resolve). Distinct from tier (model vocabulary) and phase (plan milestone). timing values. Those depend on the host and run conditions, so this exercise leaves them out of its fixed output.
What you have now
trace.json records the input, stagestageOne of the dataflow stages in the runtime pipeline (normalize, locale check, kind classify, phrase group, token classify, sequence correct, reconcile, resolve). Distinct from tier (model vocabulary) and phase (plan milestone). decisions, and full component tree for one parseaddress parsingThe process of decomposing a free-text postal address string into structured components — house number, street name, locality, region, postcode, and country — so a geocoder can resolve them to coordinates.. inspect-trace.ts checks the spansspanA 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. and prints the fields needed to explain this result.
Next
- Parse and geocode result schema lists the available labelscomponent tagOne of the 25 labels in Mailwoman's address schema — street, locality, region, postcode, house_number, unit, po_box, country, venue, intersection, and others. Each parsed span carries exactly one component tag. and defines the result fields.
- Library API lists the import paths and parseaddress parsingThe process of decomposing a free-text postal address string into structured components — house number, street name, locality, region, postcode, and country — so a geocoder can resolve them to coordinates. options.
- How Mailwoman turns text into a parse explains how the stagesstageOne of the dataflow stages in the runtime pipeline (normalize, locale check, kind classify, phrase group, token classify, sequence correct, reconcile, resolve). Distinct from tier (model vocabulary) and phase (plan milestone). and decoderdecoderIn a transformer encoder-decoder model, the part that produces output sequences. Mailwoman's classifier is encoder-only (no decoder); the 'CRF decoder' is a different thing — a structured-prediction layer that picks the best label sequence from the encoder's outputs. produce this tree.