Skip to content

Getting Started ​

Suzume is a lightweight Japanese tokenizer for JavaScript/WASM, Python, Go, native C/C++, and the command line. It splits Japanese text into tokens and gives each token a part of speech and a base form. Type a sentence below to see the result, then follow the steps for your runtime.

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...

Choose a Binding ​

Each step on this page has one tab per binding:

TabRuntimePackageReference
JavaScriptBrowser, Node.js, Deno, Bun@libraz/suzume on npmAPI Reference
PythonCPython 3.10+ on Linux x86_64 or macOS arm64suzume on PyPIPython guide
GoGo 1.26+ with cgogithub.com/libraz/go-suzumeGo bindings
C++Native C or C++ programBuilt from sourceC / C++ library
CLIShellsuzume command from the PyPI wheelPython CLI

Install ​

bash
npm install @libraz/suzume
bash
pip install suzume
bash
git clone https://github.com/libraz/go-suzume.git
cd go-suzume && make lib

# From your own module:
go mod edit -replace github.com/libraz/go-suzume=/path/to/go-suzume
go get github.com/libraz/go-suzume
bash
git clone https://github.com/libraz/suzume.git
cd suzume
make install   # into /usr/local; override with PREFIX=/opt/suzume
bash
pip install suzume   # the wheel also installs the suzume command

Installation covers other package managers, the CDN build, platform requirements, and the native suzume-cli developer tool.

Analyze Text ​

typescript
import { Suzume } from '@libraz/suzume'

const suzume = await Suzume.create()

for (const m of suzume.analyze('東京で美味しいラーメンを食べた')) {
  console.log(`${m.surface}\t${m.pos}\t${m.baseForm}`)
}

suzume.destroy()
python
from suzume import Suzume

with Suzume() as suzume:
    for m in suzume.analyze("東京で美味しいラーメンを食べた"):
        print(f"{m.surface}\t{m.pos}\t{m.base_form}")
go
package main

import (
	"fmt"
	"log"

	"github.com/libraz/go-suzume"
)

func main() {
	analyzer, err := suzume.New()
	if err != nil {
		log.Fatal(err)
	}
	defer analyzer.Close()

	morphemes, err := analyzer.Analyze("東京で美味しいラーメンを食べた")
	if err != nil {
		log.Fatal(err)
	}
	for _, m := range morphemes {
		fmt.Printf("%s\t%s\t%s\n", m.Surface, m.POS, m.BaseForm)
	}
}
cpp
#include <iostream>

#include "suzume/suzume.hpp"

int main() {
  auto tokenizer = suzume::Tokenizer::create();
  if (!tokenizer) return 1;
  const auto morphemes = tokenizer->analyze("東京で美味しいラーメンを食べた");
  if (!morphemes) return 1;
  for (const auto& m : *morphemes) {
    std::cout << m.surface << '\t' << m.pos << '\t' << m.base_form << '\n';
  }
}
bash
suzume "東京で美味しいラーメンを食べた"

Each printed line is one token, with its surface, part of speech, and base form separated by tabs:

Only 食べ has a base form that differs from its surface
The seven tokens of 東京で美味しいラーメンを食べた in three rows: surface, POS and base form. 食べ has the base form 食べる; every other token has a base form equal to its surface.surfacePOSbase form東京NOUN東京でPARTICLEで美味しいADJ美味しいラーメンNOUNラーメンをPARTICLEを食べVERB食べるたAUXたcontinuative form
Base forms that equal their surface are drawn faint. 食べ is the continuative form, so its base form is 食べる, and the auxiliary た follows as a token of its own.

The CLI prints the same three columns followed by the start and end offsets. 食べ is the continuative form, the form a verb takes before た.

A token carries more than these three fields: conjugation type and form, offsets, and flags such as isUserDict and isUnknown. The full field list is in the Morpheme interface. Offsets count Unicode code points in the normalized text; see Offsets before slicing the input with them.

Construction options select the analysis mode and whether noun compounds merge; see Modes, Offsets, and Normalization. Every option and its default is listed under Suzume.create(options?).

Common Tasks ​

These snippets reuse the instance from Analyze Text, so run them before it is destroyed or closed.

Extract Search Keywords ​

generateTags() drops particles, auxiliaries, formal nouns, and low-information words, and returns the base form of each remaining token. excludeBasic also drops words whose base form is all hiragana.

typescript
const tags = suzume.generateTags('東京スカイツリーで夜景を撮影しました', {
  excludeBasic: true,
  maxTags: 5,
})

for (const t of tags) {
  console.log(`${t.tag}\t${t.pos}`)
}
python
tags = suzume.generate_tags(
    "東京スカイツリーで夜景を撮影しました",
    exclude_basic=True,
    max_tags=5,
)

for t in tags:
    print(f"{t.tag}\t{t.pos}")
go
opts := suzume.DefaultTagOptions()
opts.ExcludeBasic = true
opts.MaxTags = 5

tags, err := analyzer.GenerateTagsWithOptions("東京スカイツリーで夜景を撮影しました", opts)
if err != nil {
	log.Fatal(err)
}
for _, t := range tags {
	fmt.Printf("%s\t%s\n", t.Tag, t.POS)
}
cpp
suzume::TagOptions opts;
opts.exclude_basic = true;
opts.max_tags = 5;

const auto tags = tokenizer->generateTags("東京スカイツリーで夜景を撮影しました", opts);
if (!tags) return 1;
for (const auto& t : *tags) {
  std::cout << t.tag << '\t' << t.pos << '\n';
}
bash
suzume -f tags --tag-exclude-basic --tag-max-tags 5 "東京スカイツリーで夜景を撮影しました"
text
東京	NOUN
スカイツリー	NOUN
夜景	NOUN
撮影	NOUN

All tabs print this output. See generateTags(text, options?) for the remaining filters.

Normalize Conjugated Words ​

Every token in a conjugated chain reports its own base form, so mapping surfaces to base forms undoes the inflection.

typescript
for (const m of suzume.analyze('食べさせられなかった')) {
  if (m.surface !== m.baseForm) {
    console.log(`${m.surface} -> ${m.baseForm}`)
  }
}
python
for m in suzume.analyze("食べさせられなかった"):
    if m.surface != m.base_form:
        print(f"{m.surface} -> {m.base_form}")
go
conjugated, err := analyzer.Analyze("食べさせられなかった")
if err != nil {
	log.Fatal(err)
}
for _, m := range conjugated {
	if m.Surface != m.BaseForm {
		fmt.Printf("%s -> %s\n", m.Surface, m.BaseForm)
	}
}
cpp
const auto conjugated = tokenizer->analyze("食べさせられなかった");
if (!conjugated) return 1;
for (const auto& m : *conjugated) {
  if (m.surface != m.base_form) {
    std::cout << m.surface << " -> " << m.base_form << '\n';
  }
}
bash
# Prints every token; the third column is the base form.
suzume "食べさせられなかった"
text
食べ -> 食べる
させ -> させる
られ -> られる
なかっ -> ない

The final た is already its own base form, so the filter skips it.

Next Steps ​

PageRead it for
InstallationPackage managers, CDN, platform requirements, suzume-cli
User DictionaryAdding domain words
Modes, Offsets, and NormalizationAnalysis modes, compound merging, offsets
GlossaryTerms used in the output and these docs
How It WorksThe analysis pipeline
Native CLIDictionary compilation and test workflows