Skip to content

How It Works ​

Why So Small? ​

Suzume's WebAssembly binary, including its built-in dictionaries, is about 269KiB gzipped. Dictionary-based analyzers often need tens of megabytes of dictionaries. How does Suzume keep its binary small?

The Short Answer ​

MeCab with an IPADIC-style dictionarySuzume
VocabularyLoads a broad word list with morphological metadataStores selected words and exceptions
ConnectionsLoads a pre-computed connection-cost matrixComputes connections from compact rules
Words not in the dictionaryUnknown-word definitions by character typePattern-generated candidates

The exact MeCab setup used elsewhere in these docs is recorded in the comparison baseline. Which tool fits which job is covered in When to Use Which.

The Three Pillars ​

Three design choices keep the binary small
A minimal dictionary, grammar patterns and rule-based scoring combine into one small WASM binary with its dictionaries included.Minimal dictionaryFunction words, particlesand selected exceptionsGrammar patternsUnknown words proposed fromcharacter type and endingsRule-based scoringConnection costs computedat runtime; no matrix shippedOne small WASM binaryAbout 269KiB gzipped, dictionaries included
Each choice replaces a large data file with compact code or a short curated list, which is what lets the dictionaries live inside the binary.

What is Tokenization?

Breaking text into meaningful units (tokens) and identifying their parts of speech. For Japanese, this means segmenting continuous text like "東京に行く" into "東京 / に / 行く".

1. Minimal Dictionary ​

Dictionary-based analyzers store exhaustive word lists:

# MeCab dictionary entry (simplified)
東京,noun,proper,place,*,*,*,東京,トウキョウ,トーキョー,0/3,C1

Suzume stores high-frequency function words, particles, auxiliaries, and selected exceptions. For many content words, it relies on character patterns and grammar rules instead of shipping every possible surface form.

CategoryDictionary-based analyzerSuzume
Function wordsStored in the dictionaryCompact entries and grammar rules
Verbs and adjectivesMany surface/conjugated entriesConjugation rules plus selected exceptions
General and proper nounsBroad lexical coverageCharacter-pattern candidates plus a compact dictionary
Domain-specific termsDictionary package or customizationRuntime user dictionary

2. Pattern Recognition ​

Instead of storing every word, Suzume recognizes patterns:

Patterns propose candidates; scoring decides
Candidates from character patterns and from the dictionary both enter the lattice, and Viterbi keeps the lowest-cost path.Pattern candidatescharacter runexamplecandidateKatakanaスカイツリーNOUNKanji量子計算NOUNKanji + する配信するNOUN + VERBHiragana + いえぐいADJDictionary lookupentries from every dictionary layerLatticeall candidates competeViterbilowest-cost path wins
Pattern candidates are generated next to dictionary candidates, not only when the lookup fails. Every example in the table is tokenized as an unknown word.

Why This Works

Japanese character types and inflectional endings provide useful candidate signals. Suzume combines those signals with dictionary entries and surrounding connection scores; a pattern match alone does not guarantee the final POS or boundary.

Try it with your own text. The playground marks each token's origin, so you can see which tokens came from a dictionary and which were generated from patterns (unknown words):

Try it in the browser

Nothing is sent to a server. The Suzume WASM bundled with this page tokenizes, lemmatizes, and extracts tags locally.

Loading WASM...

3. Dynamic Connection Scoring ​

A MeCab dictionary such as IPADIC includes a pre-computed connection-cost matrix:

# Which word can follow which? (simplified)
noun → particle: cost 100
noun → verb: cost 500
particle → noun: cost 50
...millions of combinations

Suzume computes connection scores dynamically using compact rules:

Connection costs come from rules, not a shipped matrix
The cost of joining two adjacent tokens is the sum of a POS-pair term, an extended-POS-pair term and lexical rules; Viterbi minimizes it together with word costs across the sentence.Connection cost = sum ofPOS pair13 × 13 table of coarse classesExtended-POS pairfine classes, such as topic は and case がLexical rulesadjustments keyed on specific surfaces or base forms++POS table excerptNOUN → PARTICLE0.0NOUN → VERB0.5NOUN → SUFFIX−0.8bonusViterbiAdds word and connection costsand keeps the cheapest full path
All three terms are computed by compact code inside the WASM module. Negative values are bonuses, and the total over the whole sentence, not any single pair, picks the path.

Consistency of Analysis ​

Suzume decides boundaries and POS from shared rules for character types, conjugation and connections, so the same construction gets the same analysis wherever it appears: じゃ is an AUX with the base form だ in 本じゃない, 本じゃなかった and 本じゃな alike. This is a property of the rules, not a claim that Suzume's segmentation is the only correct one; see Copula Negation, Causative-Passive, and the known limits under Constraints.

Technical Deep Dive ​

What is a Lattice?

A graph structure representing all possible ways to segment text. Each path through the lattice is a potential tokenization. For "すもも", possible paths include "すもも" (plum) or "す/もも" (vinegar + peach).

What is Viterbi Algorithm?

A dynamic programming algorithm that finds the optimal path through the lattice. Instead of evaluating every possible combination, it efficiently finds the best segmentation by reusing previous calculations.

The lattice holds every candidate; Viterbi keeps the cheapest path
Lattice for 東京に行く. Dictionary and pattern candidates sit at each position, and the path through 東京, に and 行く has the lowest cost.東京に行くBOSEOS東京unk 1東unk 1.4京unk 1.4にdict 0.2行くdict 0.5行くunk 0.178行unk 1.4くunk 2lowest-cost pathother candidatepath cost 1.103dict = dictionary entry, unk = pattern-generated; numbers are word costs
Candidates that touch are joined by an edge, and Viterbi keeps the path with the smallest sum of word and connection costs. The pattern candidate for 行く has the lower word cost (0.178), yet the path through the dictionary 行く (0.5) wins.

Analysis Pipeline ​

Normalization comes first; base forms are fixed after selection
Input is normalized and pre-tokenized, a lattice is built from dictionary and pattern candidates, Viterbi selects a path, and post-processing fixes base forms and merges.Before the latticeLattice and selectionAfter selectionNormalize charactersテスト → テスト · ABC → ABCPre-tokenizeURLs, emails, dates, numberskept as tokensremaining textDictionary candidatesfrom all four layersPattern candidatesfor unknown wordsLatticeevery candidate edgenothing is final yetViterbilowest-cost pathPost-processbase forms and conjugation formsmerges numbers; compounds by modeTokenssurface, pos, baseForm, …
A word no dictionary lists enters through the pattern branch and competes in the same lattice as every other candidate. URLs and numbers become tokens at pre-tokenization and rejoin the stream before post-processing.

The pipeline always runs in this order. An unknown word such as スカイツリー takes the pattern branch: the katakana run yields a noun candidate, which competes with every other candidate in the lattice and survives only if Viterbi scores it best.

Options change what goes into and comes out of the pipeline, not the pipeline itself: normalization, the segmentation mode and compound merging, dictionary loading, scorer configuration, and (in JavaScript) whether an instance uses an isolated WASM runtime. The full option set is in the API reference.

Verb Conjugation ​

Suzume derives regular inflected forms from shared conjugation rules instead of requiring each form as a hand-authored lexical entry. Selected dictionary entries can still be expanded into materialized forms when dictionaries are compiled or loaded; see the user dictionary guide for the runtime case.

One verb, two stems; the next token fixes the form
The verb 食べる splits into the stems 食べ and 食べれ. 食べ precedes ない, ます, た and て, and 食べれ precedes ば; the stem conjForm values are irrealis, continuative and conditional.Base formStem tokenNext tokenStem form食べるichidan verb食べVERB食べれVERBないAUX未然形negativeますAUX連用形politeたAUX連用形pastてPARTICLE連用形te-formばPARTICLE仮定形conditional
The stem’s conjForm depends on the token that follows. Before ない it is 未然形; before ます, た and て it is 連用形; before ば the stem is the separate form 食べれ, in 仮定形.

When to Use Which ​

Suzume is built for compact tokenization for search and display, with one core running in browsers, edge and server runtimes, Python, Go and C/C++. A dictionary-based analyzer such as MeCab is a different tool, chosen when its dictionary's coverage and detailed taxonomy are requirements. The two outputs are not meant to be interchangeable, so agreement with MeCab is not Suzume's success metric.

RequirementChooseWhy
Tokenize in the browser or on the client, with no serverSuzumeCompact dictionaries are embedded in the WASM binary (about 269KiB gzipped)
Tokenize as the user typesSuzumeNo network round trip
Search indexing or tag extractionSuzumeCompounds stay whole, or merge in search mode
Words that no dictionary listsSuzumePattern-based candidates cover character sequences without an entry
The same tokenizer across browser, server, Python, Go and C/C++SuzumeOne core behind every binding
Compatibility with a particular MeCab dictionary or corpusMeCabKeeps that dictionary's boundaries and taxonomy
Dictionary-defined boundaries inside compounds (東京都庁前)MeCabBoundaries come from the selected dictionary; with Suzume, register them in a user dictionary
Readings and a detailed POS hierarchyMeCabThe dictionary supplies them; Suzume's POS set is coarser

For concrete differences on the same input, see Differences from MeCab.

See also ​