Install Mailwoman and inspect a first parse
You'll make a small TypeScript script that parsesaddress 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. one address and prints each labeled part with its position in the text. The exercise installs the current published Mailwoman packages and takes about ten minutes, plus package download time.
Prerequisites
- Node.js
^24.22.3 || >=26.13.1. - An empty project directory with room for the packages and the English 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.'. This exercise reads no geocodinggeocodingThe process of converting an address into geographic coordinates (latitude and longitude). Mailwoman geocodes in a multi-tier cascade: exact address-point match → street interpolation → locality centroid. Each tier is progressively coarser but more widely available. database.
1. Set up the project
Run this command in the empty project directory. It creates a package.json that marks the project as an ECMAScript module project. Node needs that setting to run the script's import statements and top-level await:
npm init -y --init-type=module
2. Install the package
- npm
- Yarn
- pnpm
- Bun
npm install mailwoman
yarn add mailwoman
pnpm add mailwoman
bun add mailwoman
mailwoman installs the parser together with the classifier and the English 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. npm reports its download progress and dependency count for your environment. Check the installed Mailwoman version:
node -p "require('mailwoman/package.json').version"
11.2.0
3. Write the parser script
Save the following complete file as parse.ts in the same directory:
import { createParser, decodeAsOutline } from "mailwoman"
await using parser = await createParser()
const result = await parser.parse("apt 4b 350 5th ave new york ny 10118")
console.log("input:", result.input)
console.log("tree.raw:", result.tree.raw)
console.log("locale:", result.locale.locale)
console.log("kind:", result.kind.kind)
console.log(decodeAsOutline(result.tree))
The address is lowercase, has no commas, and places the apartment before the street numberhouse numberThe numeric or alphanumeric identifier of a building on a street. Mailwoman's house_number component; its position relative to the street name flips between locales.. createParser loads the English 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 the parser keeps it loaded for every parser.parse call. await using releases 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.' when the script ends. decodeAsOutline prints the returned tree one node per line and indents each child under its parent.
4. Run the script
Node runs the TypeScript file directly:
node parse.ts
input: apt 4b 350 5th ave new york ny 10118
tree.raw: Apt 4B 350 5TH Ave New York NY 10118
locale: en-US
kind: structured_address
region [28, 30): "NY"
locality [19, 27): "New York"
street [11, 14): "5TH"
unit [0, 6): "Apt 4B"
house_number [7, 10): "350"
street_suffix [15, 18): "Ave"
postcode [31, 36): "10118"
The printed indentation shows the returned tree. Each node has a component tagcomponent 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., such as street or postcode, and a value. The [start, end) 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. selects text from result.tree.raw. For example, result.tree.raw.slice(19, 27) returns "New York". Read 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. against tree.raw, the case-adjusted text that the classifier returns with the tree. The script prints it on the tree.raw: line.
The locale and kind lines report 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.'s decisions for this input. This script returns labeled address components. Forward geocodinggeocodingThe process of converting an address into geographic coordinates (latitude and longitude). Mailwoman geocodes in a multi-tier cascade: exact address-point match → street interpolation → locality centroid. Each tier is progressively coarser but more widely available. reads a separate geographic data layerlayerOne transformer block — attention plus a feed-forward network, with normalization and residual connections — applied to every position. Stacking layers lets the model build up richer representations; Mailwoman's encoder has 6.. Geocode a file of addresses installs one.
What you have now
The parse.ts file runs a local 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. and prints the case-adjusted text, classification, and component tree. You can replace the input string with another address and inspect its returned tags and 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. with the same script.
Next
Inspect the decisions behind a parse uses the same address to show the query-shape matches, localelocaleThe combination of language and country an address comes from. en-US and fr-FR are the locales Mailwoman ships weights for. and kind decisions, and node scores behind this tree.
Parse and geocode result schema defines the tags and 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. fields used in the output.
Library API lists the import paths and call options for this script.