Commands
The Lindera CLI provides six main commands:
- list - List the morphological analysis dictionaries and their status
- tokenize - Perform morphological analysis on text
- build - Build a dictionary from source CSV files
- download - Download a pre-built dictionary from the GitHub releases page
- train - Train a CRF model from annotated corpus data
- export - Export a trained model to dictionary format
Warnings and log messages
Every command writes its results to standard output and the warnings of the Lindera libraries to standard error. For example, when tokenize reads more than 32 KiB of text without a sentence delimiter, it cuts the sentence there (see Sentence Splitting) and warns:
% head -c 40000 /dev/zero | tr '\0' a | lindera tokenize --dict embedded://ipadic -o wakati > /dev/null
[WARN lindera_segmenter::segmenter] no sentence delimiter (\n, \t, 。, 、) found within 32768 bytes from offset 0; forcing a sentence boundary to bound lattice size (see https://github.com/lindera/lindera/issues/871)
The RUST_LOG environment variable selects the messages, in the syntax of env_logger:
- Not set: warnings and errors.
RUST_LOG=error: errors only, which hides the warnings.RUST_LOG=offwrites no log messages at all.RUST_LOG=debug: also debugging messages, such as the fileslindera buildreads and writes.
The setting does not change standard output, and the error of a command that fails is written whatever the setting. The messages are colored when standard error is a terminal; RUST_LOG_STYLE=never turns the colors off.
list
List all known morphological analysis dictionaries and show, for each one, whether it is embedded in the binary (via the embed-* feature flags) and whether a pre-built copy has been downloaded locally with lindera download.
List parameters
This command takes no arguments. The LINDERA_DATA_DIR environment variable overrides the application data directory searched for downloaded dictionaries, exactly as it does for lindera download.
List usage
% lindera list
NAME EMBEDDED DOWNLOADED PATH
ipadic yes yes /home/user/.local/share/lindera/dictionaries/5.1.0/lindera-ipadic
ipadic-neologd no no -
unidic no incomplete /home/user/.local/share/lindera/dictionaries/5.1.0/lindera-unidic
sudachidict no no -
ko-dic no no -
cc-cedict no no -
jieba no no -
The output contains one dictionary per line:
EMBEDDEDisyeswhen the dictionary was embedded at build time (e.g.--features=embed-ipadic).DOWNLOADEDisyeswhen a complete dictionary installed bylindera downloadexists for the running CLI version, andincompletewhen the installation directory exists but required files are missing (re-download it withlindera download <name> --force).PATHshows the installation directory when it exists, and-otherwise.
tokenize
Perform morphological analysis (tokenization) on Japanese, Chinese, or Korean text using various dictionaries.
Parameters
--dict/-d: Dictionary path, URI, or downloaded dictionary name (required)- File path:
/path/to/dictionary - Embedded:
embedded://ipadic,embedded://unidic, etc. - Downloaded dictionary name:
ipadic,unidic, etc. — resolved to the dictionary installed bylindera download. An existing filesystem path with the same name takes precedence.
- File path:
--output/-o: Output format (default: mecab)mecab: MeCab-compatible format with part-of-speech infowakati: Space-separated tokens only, one line per input line (an empty line for a line without tokens)json: Detailed JSON format with all token information
--user-dict/-u: User dictionary path (optional). An entry whose context ID lies outside the system dictionary's connection matrix is an error (see Context IDs).--mode/-m: Tokenization mode (default: normal)normal: Standard tokenizationdecompose: Decompose compound words
--char-filter/-c: Character filter configuration (JSON)--token-filter/-t: Token filter configuration (JSON)--keep-whitespace: Keep whitespace tokens in the output. Whitespace then also stays in the lattice, so the other tokens can differ from those of the default output, in which whitespace is dropped and, unless the dictionary'smetadata.jsonturns it off (SudachiDict does), skipped in the lattice as MeCab does--disable-skip-whitespace: Keep whitespace in the lattice as a node of its own (a whitespace dictionary entry or theSPACEunknown word) instead of skipping it, while still dropping it from the output (the behavior before v7). With ko-dic, whose connection costs for that node are all zero, every space then resets the connection context. Skipping is on by default for every dictionary whosemetadata.jsondoes not turn it off (SudachiDict does). No effect with--keep-whitespace. See the Segmenter documentation--max-grouping-len: Cap on unknown-word grouping, in characters beyond the first (MeCab'smax-grouping-size; MeCab defaults to 24). The cap is applied at each position: a run (characters that each share achar.defcategory with the one before, as in MeCab) longer than the cap is not grouped there, the single-character candidate (plus the length ladder and dictionary words) remains, and the remaining tail is grouped again once it fits, so no unknown token exceeds cap+1 characters.0or omitted: unbounded. See the Segmenter documentation for an example--disable-unknown-word-ladder: Disable the MeCab/Vibrato-inspired unknown-word length ladder (char.def'sLENGTHfield). Enabled by default. Disabling it leaves out these candidates, as before v6; other changes since then, such as unknown words that start inside a grouped run, still apply. See the Segmenter documentation--disable-space-penalty: Disable the left-space penalty (mecab-ko'sleft-space-penalty-factor) that a dictionary shipping rules in itsmetadata.jsonapplies by default (ko-dic ships mecab-ko-dic's). A candidate that starts right after whitespace and whose first part-of-speech tag is listed gets the cost added; disabling it together with--disable-skip-whitespaceturns off both changes since v6.0 in how Korean is read around spaces (this penalty and whitespace skipping), but not the other output changes since then, such as the split of punctuation runs like.". See the Segmenter documentation--space-penalty-rules: Use explicit left-space penalty rules as JSON instead of the dictionary's, e.g.'{"rules":[{"pos":["JKS","JX"],"cost":6000}]}'. Mutually exclusive with--disable-space-penalty--mmap: Use memory-mapped file loading for the dictionary directory's word list. Ignored forembedded://dictionaries and when themmapfeature is disabled. Rebuilding or truncating the dictionary directory while a process holds it mapped can cause a SIGBUS on the next lookup.--nbest/-N: Number of N-best results to return (default: 1). When set to 2 or more, N-best output is enabled.--nbest-unique: Deduplicate N-best results by removing paths that produce the same segmentation: each result is the cheapest path of its word boundaries.--nbest-cost-threshold: Maximum cost difference from the best result. Only results with cost withinbest_cost + thresholdare returned; both costs are totals over the whole input line.- Input file: Optional file path (default: stdin). The input is read line by line, and each line is tokenized on its own. Only the line terminator (
\n, or\r\n) is removed: whitespace at the start or end of a line is handled as elsewhere in the line (spaces and tabs, which areSPACEcharacters, are skipped and dropped from the output; U+3000 is a token with IPADIC, IPADIC-NEologd and UniDic), and the byte offsets in the JSON output index the line. Unlike MeCab, which outputs the\rof a CRLF line as an unknown word, Lindera removes it
Basic usage
# Tokenize text using a dictionary directory
echo "日本語の形態素解析を行うことができます。" | lindera tokenize \
--dict /path/to/dictionary
# Tokenize text using embedded dictionary
echo "日本語の形態素解析を行うことができます。" | lindera tokenize \
--dict embedded://ipadic
# Tokenize with different output format
echo "日本語の形態素解析を行うことができます。" | lindera tokenize \
--dict embedded://ipadic \
--output json
# Tokenize text from file
lindera tokenize \
--dict /path/to/dictionary \
--output wakati \
input.txt
Examples with external dictionaries
Tokenize with external IPADIC (Japanese dictionary)
% echo "日本語の形態素解析を行うことができます。" | lindera tokenize \
--dict /tmp/lindera-ipadic-2.7.0-20250920
日本語 名詞,一般,*,*,*,*,日本語,ニホンゴ,ニホンゴ
の 助詞,連体化,*,*,*,*,の,ノ,ノ
形態素 名詞,一般,*,*,*,*,形態素,ケイタイソ,ケイタイソ
解析 名詞,サ変接続,*,*,*,*,解析,カイセキ,カイセキ
を 助詞,格助詞,一般,*,*,*,を,ヲ,ヲ
行う 動詞,自立,*,*,五段・ワ行促音便,基本形,行う,オコナウ,オコナウ
こと 名詞,非自立,一般,*,*,*,こと,コト,コト
が 助詞,格助詞,一般,*,*,*,が,ガ,ガ
でき 動詞,自立,*,*,一段,連用形,できる,デキ,デキ
ます 助動詞,*,*,*,特殊・マス,基本形,ます,マス,マス
。 記号,句点,*,*,*,*,。,。,。
EOS
Tokenize with external IPADIC Neologd (Japanese dictionary)
% echo "日本語の形態素解析を行うことができます。" | lindera tokenize \
--dict /tmp/lindera-ipadic-neologd-0.0.7-20200820
日本語 名詞,一般,*,*,*,*,日本語,ニホンゴ,ニホンゴ
の 助詞,連体化,*,*,*,*,の,ノ,ノ
形態素解析 名詞,固有名詞,一般,*,*,*,形態素解析,ケイタイソカイセキ,ケイタイソカイセキ
を 助詞,格助詞,一般,*,*,*,を,ヲ,ヲ
行う 動詞,自立,*,*,五段・ワ行促音便,基本形,行う,オコナウ,オコナウ
こと 名詞,非自立,一般,*,*,*,こと,コト,コト
が 助詞,格助詞,一般,*,*,*,が,ガ,ガ
でき 動詞,自立,*,*,一段,連用形,できる,デキ,デキ
ます 助動詞,*,*,*,特殊・マス,基本形,ます,マス,マス
。 記号,句点,*,*,*,*,。,。,。
EOS
Tokenize with external UniDic (Japanese dictionary)
% echo "日本語の形態素解析を行うことができます。" | lindera tokenize \
--dict /tmp/lindera-unidic-2.1.2
日本 名詞,固有名詞,地名,国,*,*,ニッポン,日本,日本,ニッポン,日本,ニッポン,固,*,*,*,*
語 名詞,普通名詞,一般,*,*,*,ゴ,語,語,ゴ,語,ゴ,漢,*,*,*,*
の 助詞,格助詞,*,*,*,*,ノ,の,の,ノ,の,ノ,和,*,*,*,*
形態 名詞,普通名詞,一般,*,*,*,ケイタイ,形態,形態,ケータイ,形態,ケータイ,漢,*,*,*,*
素 接尾辞,名詞的,一般,*,*,*,ソ,素,素,ソ,素,ソ,漢,*,*,*,*
解析 名詞,普通名詞,サ変可能,*,*,*,カイセキ,解析,解析,カイセキ,解析,カイセキ,漢,*,*,*,*
を 助詞,格助詞,*,*,*,*,ヲ,を,を,オ,を,オ,和,*,*,*,*
行う 動詞,一般,*,*,五段-ワア行,連体形-一般,オコナウ,行う,行う,オコナウ,行う,オコナウ,和,*,*,*,*
こと 名詞,普通名詞,一般,*,*,*,コト,事,こと,コト,こと,コト,和,コ濁,基本形,*,*
が 助詞,格助詞,*,*,*,*,ガ,が,が,ガ,が,ガ,和,*,*,*,*
でき 動詞,非自立可能,*,*,上一段-カ行,連用形-一般,デキル,出来る,でき,デキ,できる,デキル,和,*,*,*,*
ます 助動詞,*,*,*,助動詞-マス,終止形-一般,マス,ます,ます,マス,ます,マス,和,*,*,*,*
。 補助記号,句点,*,*,*,*,,。,。,,。,,記号,*,*,*,*
EOS
Tokenize with external ko-dic (Korean dictionary)
% echo "한국어의형태해석을실시할수있습니다." | lindera tokenize \
--dict /tmp/lindera-ko-dic-2.1.1-20180720
한국어 NNG,*,F,한국어,Compound,*,*,한국/NNG/*+어/NNG/*
의 JKG,*,F,의,*,*,*,*
형태 NNG,*,F,형태,*,*,*,*
해석 NNG,행위,T,해석,*,*,*,*
을 JKO,*,T,을,*,*,*,*
실시 NNG,행위,F,실시,*,*,*,*
할 XSV+ETM,*,T,할,Inflect,XSV,ETM,하/XSV/*+ᆯ/ETM/*
수 NNB,*,F,수,*,*,*,*
있 VV,*,T,있,*,*,*,*
습니다 EF,*,F,습니다,*,*,*,*
. SF,*,*,*,*,*,*,*
EOS
Tokenize with external CC-CEDICT (Chinese dictionary)
% echo "可以进行中文形态学分析。" | lindera tokenize \
--dict /tmp/lindera-cc-cedict-0.1.0-20261021
可以 *,*,*,*,ke3 yi3,可以,可以,can/may/possible/able to/not bad/pretty good/
进行 *,*,*,*,jin4 xing2,進行,进行,to advance/to conduct/underway/in progress/to do/to carry out/to carry on/to execute/
中文 *,*,*,*,Zhong1 wen2,中文,中文,Chinese language/
形态学 *,*,*,*,xing2 tai4 xue2,形態學,形态学,morphology (in biology or linguistics)/
分析 *,*,*,*,fen1 xi1,分析,分析,to analyze/analysis/CL:個|个[ge4]/
。 *,*,*,*,*,*,*,*
EOS
Tokenize with external Jieba (Chinese dictionary)
% echo "可以进行中文形态学分析。" | lindera tokenize \
--dict /tmp/lindera-jieba-0.1.3
Examples with embedded dictionaries
Lindera can include dictionaries directly in the binary when built with specific feature flags. This allows tokenization without external dictionary files.
Tokenize with embedded IPADIC (Japanese dictionary)
% echo "日本語の形態素解析を行うことができます。" | lindera tokenize \
--dict embedded://ipadic
日本語 名詞,一般,*,*,*,*,日本語,ニホンゴ,ニホンゴ
の 助詞,連体化,*,*,*,*,の,ノ,ノ
形態素 名詞,一般,*,*,*,*,形態素,ケイタイソ,ケイタイソ
解析 名詞,サ変接続,*,*,*,*,解析,カイセキ,カイセキ
を 助詞,格助詞,一般,*,*,*,を,ヲ,ヲ
行う 動詞,自立,*,*,五段・ワ行促音便,基本形,行う,オコナウ,オコナウ
こと 名詞,非自立,一般,*,*,*,こと,コト,コト
が 助詞,格助詞,一般,*,*,*,が,ガ,ガ
でき 動詞,自立,*,*,一段,連用形,できる,デキ,デキ
ます 助動詞,*,*,*,特殊・マス,基本形,ます,マス,マス
。 記号,句点,*,*,*,*,。,。,。
EOS
NOTE: To include IPADIC dictionary in the binary, you must build with the --features=embed-ipadic option.
Tokenize with embedded UniDic (Japanese dictionary)
% echo "日本語の形態素解析を行うことができます。" | lindera tokenize \
--dict embedded://unidic
日本 名詞,固有名詞,地名,国,*,*,ニッポン,日本,日本,ニッポン,日本,ニッポン,固,*,*,*,*
語 名詞,普通名詞,一般,*,*,*,ゴ,語,語,ゴ,語,ゴ,漢,*,*,*,*
の 助詞,格助詞,*,*,*,*,ノ,の,の,ノ,の,ノ,和,*,*,*,*
形態 名詞,普通名詞,一般,*,*,*,ケイタイ,形態,形態,ケータイ,形態,ケータイ,漢,*,*,*,*
素 接尾辞,名詞的,一般,*,*,*,ソ,素,素,ソ,素,ソ,漢,*,*,*,*
解析 名詞,普通名詞,サ変可能,*,*,*,カイセキ,解析,解析,カイセキ,解析,カイセキ,漢,*,*,*,*
を 助詞,格助詞,*,*,*,*,ヲ,を,を,オ,を,オ,和,*,*,*,*
行う 動詞,一般,*,*,五段-ワア行,連体形-一般,オコナウ,行う,行う,オコナウ,行う,オコナウ,和,*,*,*,*
こと 名詞,普通名詞,一般,*,*,*,コト,事,こと,コト,こと,コト,和,コ濁,基本形,*,*
が 助詞,格助詞,*,*,*,*,ガ,が,が,ガ,が,ガ,和,*,*,*,*
でき 動詞,非自立可能,*,*,上一段-カ行,連用形-一般,デキル,出来る,でき,デキ,できる,デキル,和,*,*,*,*
ます 助動詞,*,*,*,助動詞-マス,終止形-一般,マス,ます,ます,マス,ます,マス,和,*,*,*,*
。 補助記号,句点,*,*,*,*,,。,。,,。,,記号,*,*,*,*
EOS
NOTE: To include UniDic dictionary in the binary, you must build with the --features=embed-unidic option.
Tokenize with embedded IPADIC NEologd (Japanese dictionary)
% echo "日本語の形態素解析を行うことができます。" | lindera tokenize \
--dict embedded://ipadic-neologd
日本語 名詞,一般,*,*,*,*,日本語,ニホンゴ,ニホンゴ
の 助詞,連体化,*,*,*,*,の,ノ,ノ
形態素解析 名詞,固有名詞,一般,*,*,*,形態素解析,ケイタイソカイセキ,ケイタイソカイセキ
を 助詞,格助詞,一般,*,*,*,を,ヲ,ヲ
行う 動詞,自立,*,*,五段・ワ行促音便,基本形,行う,オコナウ,オコナウ
こと 名詞,非自立,一般,*,*,*,こと,コト,コト
が 助詞,格助詞,一般,*,*,*,が,ガ,ガ
でき 動詞,自立,*,*,一段,連用形,できる,デキ,デキ
ます 助動詞,*,*,*,特殊・マス,基本形,ます,マス,マス
。 記号,句点,*,*,*,*,。,。,。
EOS
NOTE: To include UniDic dictionary in the binary, you must build with the --features=embed-ipadic-neologd option.
Tokenize with embedded ko-dic (Korean dictionary)
% echo "한국어의형태해석을실시할수있습니다." | lindera tokenize \
--dict embedded://ko-dic
한국어 NNG,*,F,한국어,Compound,*,*,한국/NNG/*+어/NNG/*
의 JKG,*,F,의,*,*,*,*
형태 NNG,*,F,형태,*,*,*,*
해석 NNG,행위,T,해석,*,*,*,*
을 JKO,*,T,을,*,*,*,*
실시 NNG,행위,F,실시,*,*,*,*
할 XSV+ETM,*,T,할,Inflect,XSV,ETM,하/XSV/*+ᆯ/ETM/*
수 NNB,*,F,수,*,*,*,*
있 VV,*,T,있,*,*,*,*
습니다 EF,*,F,습니다,*,*,*,*
. SF,*,*,*,*,*,*,*
EOS
NOTE: To include ko-dic dictionary in the binary, you must build with the --features=embed-ko-dic option.
Tokenize with embedded CC-CEDICT (Chinese dictionary)
% echo "可以进行中文形态学分析。" | lindera tokenize \
--dict embedded://cc-cedict
可以 *,*,*,*,ke3 yi3,可以,可以,can/may/possible/able to/not bad/pretty good/
进行 *,*,*,*,jin4 xing2,進行,进行,to advance/to conduct/underway/in progress/to do/to carry out/to carry on/to execute/
中文 *,*,*,*,Zhong1 wen2,中文,中文,Chinese language/
形态学 *,*,*,*,xing2 tai4 xue2,形態學,形态学,morphology (in biology or linguistics)/
分析 *,*,*,*,fen1 xi1,分析,分析,to analyze/analysis/CL:個|个[ge4]/
。 *,*,*,*,*,*,*,*
EOS
NOTE: To include CC-CEDICT dictionary in the binary, you must build with the --features=embed-cc-cedict option.
Tokenize with embedded Jieba (Chinese dictionary)
% echo "可以进行中文形态学分析。" | lindera tokenize \
--dict embedded://jieba
NOTE: To include Jieba dictionary in the binary, you must build with the --features=embed-jieba option.
User dictionary examples
Lindera supports user dictionaries to add custom words alongside system dictionaries. User dictionaries can be in CSV or binary format.
Use user dictionary (CSV format)
% echo "東京スカイツリーの最寄り駅はとうきょうスカイツリー駅です" | lindera tokenize \
--dict embedded://ipadic \
--user-dict ./resources/user_dict/ipadic_simple_userdic.csv
東京スカイツリー カスタム名詞,*,*,*,*,*,東京スカイツリー,トウキョウスカイツリー,*
の 助詞,連体化,*,*,*,*,の,ノ,ノ
最寄り駅 名詞,一般,*,*,*,*,最寄り駅,モヨリエキ,モヨリエキ
は 助詞,係助詞,*,*,*,*,は,ハ,ワ
とうきょうスカイツリー駅 カスタム名詞,*,*,*,*,*,とうきょうスカイツリー駅,トウキョウスカイツリーエキ,*
です 助動詞,*,*,*,特殊・デス,基本形,です,デス,デス
EOS
Use user dictionary (Binary format)
% echo "東京スカイツリーの最寄り駅はとうきょうスカイツリー駅です" | lindera tokenize \
--dict /tmp/lindera-ipadic-2.7.0-20250920 \
--user-dict ./resources/user_dict/ipadic_simple_userdic.bin
東京スカイツリー カスタム名詞,*,*,*,*,*,東京スカイツリー,トウキョウスカイツリー,*
の 助詞,連体化,*,*,*,*,の,ノ,ノ
最寄り駅 名詞,一般,*,*,*,*,最寄り駅,モヨリエキ,モヨリエキ
は 助詞,係助詞,*,*,*,*,は,ハ,ワ
とうきょうスカイツリー駅 カスタム名詞,*,*,*,*,*,とうきょうスカイツリー駅,トウキョウスカイツリーエキ,*
です 助動詞,*,*,*,特殊・デス,基本形,です,デス,デス
EOS
Tokenization modes
Lindera provides two tokenization modes: normal and decompose.
Normal mode (default)
Tokenizes faithfully based on words registered in the dictionary:
% echo "関西国際空港限定トートバッグ" | lindera tokenize \
--dict embedded://ipadic \
--mode normal
関西国際空港 名詞,固有名詞,組織,*,*,*,関西国際空港,カンサイコクサイクウコウ,カンサイコクサイクーコー
限定 名詞,サ変接続,*,*,*,*,限定,ゲンテイ,ゲンテイ
トートバッグ 名詞,一般,*,*,*,*,*,*,*
EOS
Decompose mode
Tokenizes compound noun words additionally:
% echo "関西国際空港限定トートバッグ" | lindera tokenize \
--dict embedded://ipadic \
--mode decompose
関西 名詞,固有名詞,地域,一般,*,*,関西,カンサイ,カンサイ
国際 名詞,一般,*,*,*,*,国際,コクサイ,コクサイ
空港 名詞,一般,*,*,*,*,空港,クウコウ,クーコー
限定 名詞,サ変接続,*,*,*,*,限定,ゲンテイ,ゲンテイ
トートバッグ 名詞,一般,*,*,*,*,*,*,*
EOS
Output formats
Lindera provides three output formats: mecab, wakati and json.
MeCab format (default)
Outputs results in MeCab-compatible format with part-of-speech information:
% echo "お待ちしております。" | lindera tokenize \
--dict embedded://ipadic \
--output mecab
お待ち 名詞,サ変接続,*,*,*,*,お待ち,オマチ,オマチ
し 動詞,自立,*,*,サ変・スル,連用形,する,シ,シ
て 助詞,接続助詞,*,*,*,*,て,テ,テ
おり 動詞,非自立,*,*,五段・ラ行,連用形,おる,オリ,オリ
ます 助動詞,*,*,*,特殊・マス,基本形,ます,マス,マス
。 記号,句点,*,*,*,*,。,。,。
EOS
Wakati format
Outputs only the token text separated by spaces, one line per input line (or per result with -N). A line without tokens, such as an empty line or a line of spaces, gives an empty line, as in MeCab:
% echo "お待ちしております。" | lindera tokenize \
--dict embedded://ipadic \
--output wakati
お待ち し て おり ます 。
JSON format
Outputs detailed token information in JSON format:
% echo "お待ちしております。" | lindera tokenize \
--dict embedded://ipadic \
--output json
[
{
"base_form": "お待ち",
"byte_end": 9,
"byte_start": 0,
"conjugation_form": "*",
"conjugation_type": "*",
"part_of_speech": "名詞",
"part_of_speech_subcategory_1": "サ変接続",
"part_of_speech_subcategory_2": "*",
"part_of_speech_subcategory_3": "*",
"pronunciation": "オマチ",
"reading": "オマチ",
"surface": "お待ち",
"word_id": 14698
},
...
]
N-Best tokenization
Lindera supports N-Best tokenization, which returns the top N tokenization candidates ordered by cost (lower cost = better). This is based on the Forward-DP Backward-A* algorithm, compatible with MeCab's N-Best implementation.
A line is cut into sentences at \t, 。 and 、, but the context is carried across 、 and 。, so the candidates for a line without a tab are the N best segmentations of the whole line (for the few exceptions, see Sentence Splitting). A tab ends a segment: a line with tabs is searched segment by segment, and its candidates are the N cheapest combinations of one path per segment. Every candidate segments the whole line.
Basic N-Best example
% echo "すもももももももものうち" | lindera tokenize \
--dict embedded://ipadic \
-N 3
NBEST 1 (cost=21245)
すもも 名詞,一般,*,*,*,*,すもも,スモモ,スモモ
も 助詞,係助詞,*,*,*,*,も,モ,モ
もも 名詞,一般,*,*,*,*,もも,モモ,モモ
も 助詞,係助詞,*,*,*,*,も,モ,モ
もも 名詞,一般,*,*,*,*,もも,モモ,モモ
の 助詞,連体化,*,*,*,*,の,ノ,ノ
うち 名詞,非自立,副詞可能,*,*,*,うち,ウチ,ウチ
EOS
NBEST 2 (cost=24541)
すもも 名詞,一般,*,*,*,*,すもも,スモモ,スモモ
もも 名詞,一般,*,*,*,*,もも,モモ,モモ
も 助詞,係助詞,*,*,*,*,も,モ,モ
もも 名詞,一般,*,*,*,*,もも,モモ,モモ
も 助詞,係助詞,*,*,*,*,も,モ,モ
の 助詞,連体化,*,*,*,*,の,ノ,ノ
うち 名詞,非自立,副詞可能,*,*,*,うち,ウチ,ウチ
EOS
NBEST 3 (cost=24541)
すもも 名詞,一般,*,*,*,*,すもも,スモモ,スモモ
も 助詞,係助詞,*,*,*,*,も,モ,モ
もも 名詞,一般,*,*,*,*,もも,モモ,モモ
もも 名詞,一般,*,*,*,*,もも,モモ,モモ
も 助詞,係助詞,*,*,*,*,も,モ,モ
の 助詞,連体化,*,*,*,*,の,ノ,ノ
うち 名詞,非自立,副詞可能,*,*,*,うち,ウチ,ウチ
EOS
Results 2 and 3 are different segmentations with the same cost (24541).
N-Best with unique results
When the same segmentation appears in multiple paths (differing only in the dictionary entries of their words, such as their parts of speech), use --nbest-unique to deduplicate. Each result is then the cheapest path of its word boundaries, and the search does not go through the other paths, which can be millions for a short line:
% echo "営業部長谷川です" | lindera tokenize \
--dict embedded://ipadic \
-N 5 --nbest-unique -o wakati
NBEST 1 (cost=15760)
営業 部長 谷川 です
NBEST 2 (cost=17747)
営業 部 長谷川 です
NBEST 3 (cost=18365)
営業 部 長谷 川 です
NBEST 4 (cost=21125)
営業 部 長 谷川 です
NBEST 5 (cost=22259)
営業 部長 谷 川 です
N-Best with cost threshold
Use --nbest-cost-threshold to limit results to paths within a certain cost range of the best path:
% echo "営業部長谷川です" | lindera tokenize \
--dict embedded://ipadic \
-N 10 --nbest-unique --nbest-cost-threshold 5000 -o wakati
NBEST 1 (cost=15760)
営業 部長 谷川 です
NBEST 2 (cost=17747)
営業 部 長谷川 です
NBEST 3 (cost=18365)
営業 部 長谷 川 です
Only 3 results are returned: the 4th result of the example above costs 21125, which exceeds 15760 + 5000 = 20760.
Advanced tokenization with filters
Lindera provides an analytical framework that combines character filters, tokenizers, and token filters for advanced text processing. Filters are configured using JSON.
% echo "すもももももももものうち" | lindera tokenize \
--dict embedded://ipadic \
--char-filter 'unicode_normalize:{"kind":"nfkc"}' \
--token-filter 'japanese_keep_tags:{"tags":["名詞,一般"]}'
すもも 名詞,一般,*,*,*,*,すもも,スモモ,スモモ
もも 名詞,一般,*,*,*,*,もも,モモ,モモ
もも 名詞,一般,*,*,*,*,もも,モモ,モモ
EOS
build
Build (compile) a morphological analysis dictionary from source CSV files for use with Lindera.
Build parameters
--src/-s: Source directory containing dictionary CSV files (or single CSV file for user dictionary)--dest/-d: Destination directory for compiled dictionary output--metadata/-m: Metadata configuration file (metadata.json) that defines dictionary structure--user/-u: Build user dictionary instead of system dictionary (optional flag)--system-dict: The system dictionary the user dictionary is for, as a directory path, URI, or downloaded dictionary name, the formstokenize --dictaccepts (optional; only with--user). The build then checks every row's context IDs against its connection matrix (see Context ID check)--context-id-freq/-f: Context-ID access-frequency file used to reorder connection-cost IDs (optional; only meaningful when the dictionary'smetadata.jsonsetsconnection_id_mapping: true)
Dictionary types
System dictionary
A full morphological analysis dictionary containing:
- Lexicon entries (word definitions)
- Connection cost matrix
- Unknown word handling rules
- Character type definitions
User dictionary
A supplementary dictionary for custom words that works alongside a system dictionary.
Context ID check
When it builds a system dictionary, lindera build checks that every context ID lies inside the connection matrix, as MeCab's mecab-dict-index does. In every lex.csv row and unk.def line, the right context ID must be below the first value of the matrix.def header, and the left context ID below the second. A dictionary that breaks this fails to build, with an error that names the file, the line, the ID and the matrix size. For example, with a 2 x 2 matrix.def and a lex.csv whose second row has the right context ID 2:
Error: LinderaError { kind: Content, source: ./dict-source/lex.csv: line 2: right context id 2 is out of range for the connection matrix (matrix.def size 2 2; right context ids must be below 2) }
- If the dictionary's
metadata.jsonsetsskip_invalid_cost_or_idtotrue, such alex.csvrow is dropped instead, with a warning on standard error (see Warnings and log messages). Anunk.defline is always checked. - A
matrix.defrow whose IDs fall outside its axes is an error too, and so is anunk.defline with fewer than four fields. - A user dictionary (
--user) is checked only when--system-dictnames the system dictionary it is for, as described below.
With --system-dict, lindera build --user checks every row of the user dictionary against the connection matrix of that system dictionary, with the same bounds. A simple row is checked with the default context IDs of metadata.json (default_left_context_id and default_right_context_id). The first row outside the matrix fails the build, with an error that names its CSV line and surface, and no .bin file is written. For example, against IPADIC's 1316 x 1316 matrix, with a userdic.csv whose second row has the left context ID 60000:
% lindera build --src ./userdic.csv --dest ./user_dict --metadata ./lindera-ipadic/metadata.json --user --system-dict embedded://ipadic
Error: LinderaError { kind: Content, source: user dictionary line 2 (surface: '東京スカイツリー'): left context id 60000 is out of range for the connection matrix (matrix.def size 1316 1316; left context ids must be below 1316) }
Without --system-dict, the build does not know the system dictionary, and the user dictionary builds. lindera tokenize --user-dict then checks it against the system dictionary and fails with an error that names the first entry outside the matrix by its word id (see Context IDs). A .csv given to lindera tokenize --user-dict is built for the system dictionary of --dict as it is loaded, so its error names the CSV line and surface, as with --system-dict.
Cells missing from matrix.def
A matrix.def does not have to list every cell. lindera build gives a cell that it leaves out the cost 0, as MeCab's mecab-dict-index does. Up to v6.2.0, such a cell cost 32767 (i16::MAX), which made the connection very expensive. For example, with the following matrix.def, the connections from the right context ID 1 to the left context IDs 0 and 1 cost 10 and 20, and the other seven cells cost 0:
3 3
1 0 10
1 1 20
The bundled dictionaries and the matrix.def that lindera export writes list every cell, so this rule does not change them.
char.def and unk.def check
When it builds a system dictionary, lindera build also checks char.def and unk.def against each other, as mecab-dict-index does:
- A range line of
char.defnames only categories defined on an earlier line. - Each category is defined once.
- Every
unk.defline names a category thatchar.defdefines. - Every
char.defcategory has at least oneunk.defline.
A dictionary that breaks one of these fails to build, with an error that names the file, the category and, except for a category without an unk.def line, the line. Such a dictionary used to build, and then lindera tokenize panicked on a character of an undefined category, gave some categories the settings of others, stopped its output before a character that no word or unknown word covers, or ignored the unk.def line. For example, with a char.def that defines the SPACE category and an unk.def that has no SPACE line:
Error: LinderaError { kind: Content, source: ./dict-source/unk.def: no line for category SPACE, which char.def defines; every char.def category needs at least one unk.def line }
lindera train checks its --char-def and --unk-def in the same way before it trains (see Training Pipeline).
Examples
Build IPADIC (Japanese dictionary)
# Download and extract IPADIC source files
% curl -L -o /tmp/mecab-ipadic-2.7.0-20250920.tar.gz "https://Lindera.dev/mecab-ipadic-2.7.0-20250920.tar.gz"
% tar zxvf /tmp/mecab-ipadic-2.7.0-20250920.tar.gz -C /tmp
# Build the dictionary
% lindera build \
--src /tmp/mecab-ipadic-2.7.0-20250920 \
--dest /tmp/lindera-ipadic-2.7.0-20250920 \
--metadata ./lindera-ipadic/metadata.json
Build IPADIC NEologd (Japanese dictionary)
% curl -L -o /tmp/mecab-ipadic-neologd-0.0.7-20200820.tar.gz "https://lindera.dev/mecab-ipadic-neologd-0.0.7-20200820.tar.gz"
% tar zxvf /tmp/mecab-ipadic-neologd-0.0.7-20200820.tar.gz -C /tmp
% lindera build \
--src /tmp/mecab-ipadic-neologd-0.0.7-20200820 \
--dest /tmp/lindera-ipadic-neologd-0.0.7-20200820 \
--metadata ./lindera-ipadic-neologd/metadata.json
Build UniDic (Japanese dictionary)
% curl -L -o /tmp/unidic-mecab-2.1.2.tar.gz "https://Lindera.dev/unidic-mecab-2.1.2.tar.gz"
% tar zxvf /tmp/unidic-mecab-2.1.2.tar.gz -C /tmp
% lindera build \
--src /tmp/unidic-mecab-2.1.2 \
--dest /tmp/lindera-unidic-2.1.2 \
--metadata ./lindera-unidic/metadata.json \
--context-id-freq ./lindera-unidic/context_id_freq.txt
Build CC-CEDICT (Chinese dictionary)
% curl -L -o /tmp/CC-CEDICT-MeCab-0.1.0-20261021.tar.gz "https://lindera.dev/CC-CEDICT-MeCab-0.1.0-20261021.tar.gz"
% tar zxvf /tmp/CC-CEDICT-MeCab-0.1.0-20261021.tar.gz -C /tmp
% lindera build \
--src /tmp/CC-CEDICT-MeCab-0.1.0-20261021 \
--dest /tmp/lindera-cc-cedict-0.1.0-20261021 \
--metadata ./lindera-cc-cedict/metadata.json
Build Jieba (Chinese dictionary)
% curl -L -o /tmp/mecab-jieba-0.1.3.tar.gz "https://lindera.dev/mecab-jieba-0.1.3.tar.gz"
% tar zxvf /tmp/mecab-jieba-0.1.3.tar.gz -C /tmp
% lindera build \
--src /tmp/mecab-jieba-0.1.3/dict-src \
--dest /tmp/lindera-jieba-0.1.3 \
--metadata ./lindera-jieba/metadata.json
Build ko-dic (Korean dictionary)
% curl -L -o /tmp/mecab-ko-dic-2.1.1-20180720.tar.gz "https://Lindera.dev/mecab-ko-dic-2.1.1-20180720.tar.gz"
% tar zxvf /tmp/mecab-ko-dic-2.1.1-20180720.tar.gz -C /tmp
% lindera build \
--src /tmp/mecab-ko-dic-2.1.1-20180720 \
--dest /tmp/lindera-ko-dic-2.1.1-20180720 \
--metadata ./lindera-ko-dic/metadata.json \
--context-id-freq ./lindera-ko-dic/context_id_freq.txt
Build user dictionaries
Build IPADIC user dictionary (Japanese)
For more details about user dictionary format please refer to the following URL:
% lindera build \
--src ./resources/user_dict/ipadic_simple_userdic.csv \
--dest ./resources/user_dict \
--metadata ./lindera-ipadic/metadata.json \
--user
Add --system-dict embedded://ipadic, or the path of a built IPADIC, to check the rows' context IDs against IPADIC's connection matrix (see Context ID check).
Build UniDic user dictionary (Japanese)
For more details about user dictionary format please refer to the following URL:
% lindera build \
--src ./resources/user_dict/unidic_simple_userdic.csv \
--dest ./resources/user_dict \
--metadata ./lindera-unidic/metadata.json \
--user
Build SudachiDict user dictionary (Japanese)
For more details about user dictionary format please refer to the following URL:
% lindera build \
--src ./resources/user_dict/sudachidict_simple_userdic.csv \
--dest ./resources/user_dict \
--metadata ./lindera-sudachidict/metadata.json \
--user
Build CC-CEDICT user dictionary (Chinese)
For more details about user dictionary format please refer to the following URL:
% lindera build \
--src ./resources/user_dict/cc-cedict_simple_userdic.csv \
--dest ./resources/user_dict \
--metadata ./lindera-cc-cedict/metadata.json \
--user
Build Jieba user dictionary (Chinese)
For more details about user dictionary format please refer to the following URL:
% lindera build \
--src ./resources/user_dict/jieba_simple_userdic.csv \
--dest ./resources/user_dict \
--metadata ./lindera-jieba/metadata.json \
--user
Build ko-dic user dictionary (Korean)
For more details about user dictionary format please refer to the following URL:
% lindera build \
--src ./resources/user_dict/ko-dic_simple_userdic.csv \
--dest ./resources/user_dict \
--metadata ./lindera-ko-dic/metadata.json \
--user
download
Download the pre-built dictionary archive matching the CLI version from the GitHub releases page and install it under the OS-standard application data directory.
Download parameters
- Dictionary name (required): one of
ipadic,ipadic-neologd,unidic,sudachidict,ko-dic,cc-cedict,jieba --force: Re-download and replace an existing dictionary
Storage location
Dictionaries are installed under a versioned layout <data dir>/dictionaries/<version>/lindera-<name>/. The default base directory per OS:
| OS | Default location |
|---|---|
| Linux | ~/.local/share/lindera |
| macOS | ~/Library/Application Support/lindera |
| Windows | %LOCALAPPDATA%\lindera |
Set the LINDERA_DATA_DIR environment variable to override the base directory. This variable is unrelated to the build-time source cache variable LINDERA_BUILD_DICTIONARY_CACHE_DIR.
Download usage
% lindera download ipadic
Downloading https://github.com/lindera/lindera/releases/download/v5.1.0/lindera-ipadic-5.1.0.zip
100% (15.1/15.1 MiB)
Downloaded dictionary 'ipadic'
/home/user/.local/share/lindera/dictionaries/5.1.0/lindera-ipadic
The installed path is printed to stdout (progress and notices go to stderr), so it can be captured in scripts:
% DICT_DIR=$(lindera download ipadic)
After downloading, the dictionary can be referenced by name in tokenize:
% echo "日本語の形態素解析を行うことができます。" | lindera tokenize --dict ipadic
Notes:
- The archive version always matches the CLI version; running a development build whose version has no published release yet fails with HTTP 404.
- Integrity is verified via the HTTPS transport and the ZIP archive's built-in per-file CRC32 checksums.
- The largest dictionary (
ipadic-neologd) is a ~305 MB download and requires roughly twice that amount of free disk space during extraction.
train
Train a new morphological analysis model from annotated corpus data. To use this feature, you must build with the train feature flag enabled. (The train feature flag is enabled by default.)
Train parameters
--seed/-s: Seed lexicon file (CSV format) to be weighted--corpus/-c: Training corpus (annotated text)--char-def/-C: Character definition file (char.def)--unk-def/-u: Unknown word definition file (unk.def) to be weighted--feature-def/-f: Feature definition file (feature.def)--rewrite-def/-r: Rewrite rule definition file (rewrite.def)--output/-o: Output model file--lambda/-l: Regularization coefficient, finite and >= 0 (0 disables regularization); withl2, MeCab's learner's-c Cis1 / C(default: 1.0, MeCab's-c 1.0)--regularization/-R: Regularization type:l1,l2, orelasticnet, in any case;elastic_netandelastic-netalso select Elastic Net (default:l2)--elastic-net-l1-ratio: L1 ratio for Elastic Net regularization (0.0-1.0), only used with--regularization elasticnet; 0 uses only L2, 1 uses only L1 (default: 0.5)--max-iterations/-i: Maximum number of iterations for training, 1 or more (default: 100)--eta/-e: Tolerance of the convergence test: training stops before--max-iterationsonce the relative change of the objective stays below this value for 3 iterations in a row;0disables the test (default: 0.00005, the default of MeCab's learner)--max-threads/-t: Maximum number of threads, 1 or more (defaults to CPU core count; affects only speed, never the trained model)
Basic workflow
1. Prepare training files
Seed lexicon file (seed.csv):
The seed lexicon file contains initial dictionary entries used for training the CRF model. Each line represents a word entry with comma-separated fields:
- Surface
- Left context ID
- Right context ID
- Word cost
- Part-of-speech tags (multiple fields)
- Base form
- Reading (katakana)
- Pronunciation
Note: The exact field definitions differ between dictionary formats (IPADIC, UniDic, ko-dic, CC-CEDICT). Please refer to each dictionary's format specification for details.
外国,0,0,0,名詞,一般,*,*,*,*,外国,ガイコク,ガイコク
人,0,0,0,名詞,接尾,一般,*,*,*,人,ジン,ジン
The file is read as CSV, as lindera build reads lex.csv: a field may be quoted (",",0,0,0,...), and a line that starts with # is an entry, not a comment. See Seed Lexicon for the details.
Training corpus (corpus.txt):
The training corpus file contains annotated text data used to train the CRF model. Each line consists of:
- A surface form (word) followed by a tab character
- Comma-separated morphological features (part-of-speech tags, base form, reading, pronunciation)
- Sentences are separated by "EOS" (End Of Sentence) markers
外国 名詞,一般,*,*,*,*,外国,ガイコク,ガイコク
人 名詞,接尾,一般,*,*,*,人,ジン,ジン
参政 名詞,サ変接続,*,*,*,*,参政,サンセイ,サンセイ
権 名詞,接尾,一般,*,*,*,権,ケン,ケン
EOS
For detailed information about file formats and advanced features, see Training Pipeline.
2. Train model
lindera train \
--seed ./resources/training/seed.csv \
--corpus ./resources/training/corpus.txt \
--unk-def ./resources/training/unk.def \
--char-def ./resources/training/char.def \
--feature-def ./resources/training/feature.def \
--rewrite-def ./resources/training/rewrite.def \
--output /tmp/lindera/training/model.dat \
--max-iterations 100
3. Training results
lindera train writes the model to the --output file. Once it has built the training lattices, it prints how the gold tokens of the corpus were labelled (see How training works). With the files in ./resources/training/:
Lattice statistics: gold_lexicon=14 gold_unknown=0 gold_virtual=0 virtual_labels=0 negative_lexicon=0 negative_unknown=17
When no gold token is a seed word, or fewer than half of the gold tokens whose surface has seed rows are, it then writes a warning on stderr, with the first gold token whose surface has seed rows but none with its feature string, next to those rows (see How training works).
Once training stops, it prints why, with the number of iterations and of evaluations of the loss and its gradient (see --eta above):
L-BFGS stopped after 8 iterations and 9 evaluations of the loss and its gradient: converged
When an iteration left the objective unchanged or the line search failed far from the optimum, it then writes a warning on stderr (see How training works).
The trained model contains:
- Seed words: every seed lexicon row, with a learned weight and context IDs
- Unknown words: every
unk.defentry, in file order, with a learned weight and context IDs
Corpus words that are not in the seed lexicon are not added as words. They are learned through the unk.def entries, or through virtual labels, which are trained but not exported.
export
Export a trained model file to Lindera dictionary format files. This feature requires building with the train feature flag enabled.
Export parameters
--model/-m: Path to the trained model file (.dat format)--output/-o: Directory to output the dictionary files--metadata: Optional metadata.json file to update with trained model information--cost-factor: Override cost factor for weight-to-cost conversion (default: value from trained model, typically 700)
Output files
The export command creates the following dictionary files in the output directory:
lex.csv: Lexicon file with learned weights (MeCab-compatible cost viatocost())matrix.def: Dense connection cost matrix covering all (right_id, left_id) pairs of the model's context IDs, plus 0 for BOS/EOS. A pair without a trained weight costs 0, as in training and in MeCabunk.def: Unknown word definitions, one line for eachunk.defentry of the training input, in the same orderchar.def: Character type definitionsfeature.def: Feature template definitions (copied from trained model)rewrite.def: Feature rewrite rules (copied from trained model)left-id.def: Left context ID to feature string mappingright-id.def: Right context ID to feature string mappingmetadata.json: Updated metadata file (if--metadataoption is provided)
Model format version
lindera export reads a model of the current format version (3.0.0) only. A model.dat written by an earlier version, which includes every model.dat written before 7.0.0, is rejected, and has to be trained again with lindera train. For a model trained with the 6.1.0 CLI:
Error: LinderaError { kind: Deserialize, source: failed to deserialize model: failed without error information; enable debug assertions and the `alloc` feature in rancor for error information. The file is not a legacy JSON model either, so it was most likely written by a different version of lindera-trainer; re-run `lindera train` to regenerate it. }
Complete workflow example
1. Train model
lindera train \
--seed ./resources/training/seed.csv \
--corpus ./resources/training/corpus.txt \
--unk-def ./resources/training/unk.def \
--char-def ./resources/training/char.def \
--feature-def ./resources/training/feature.def \
--rewrite-def ./resources/training/rewrite.def \
--output /tmp/lindera/training/model.dat \
--max-iterations 100
2. Export to dictionary format
lindera export \
--model /tmp/lindera/training/model.dat \
--metadata ./resources/training/metadata.json \
--output /tmp/lindera/training/dictionary
3. Build dictionary
lindera build \
--src /tmp/lindera/training/dictionary \
--dest /tmp/lindera/training/compiled_dictionary \
--metadata /tmp/lindera/training/dictionary/metadata.json
4. Use trained dictionary
echo "これは外国人参政権です。" | lindera tokenize -d /tmp/lindera/training/compiled_dictionary
これ 名詞,代名詞,一般,*,*,*,これ,コレ,コレ
は 助詞,係助詞,*,*,*,*,は,ハ,ワ
外国 名詞,一般,*,*,*,*,外国,ガイコク,ガイコク
人 名詞,接尾,一般,*,*,*,人,ジン,ジン
参政 名詞,サ変接続,*,*,*,*,参政,サンセイ,サンセイ
権 名詞,接尾,一般,*,*,*,権,ケン,ケン
です 助動詞,*,*,*,特殊・デス,基本形,です,デス,デス
。 記号,句点,*,*,*,*,。,。,。
EOS
Metadata update feature
When the --metadata option is provided, the export command will:
- Read the base metadata.json file to preserve existing configuration
- Update specific fields with values from the trained model:
default_word_cost: Calculated from feature weight medianmodel_info: Training statistics including feature count, label count, matrix size (connection_matrix_size, the size ofmatrix.defas rows x columns), the number of training iterations that ran (training_iterations, at most--max-iterations), the regularization coefficient (regularization), its type (regularization_type:l1,l2orelasticnet) and, for Elastic Net only, its L1 ratio (elastic_net_l1_ratio), and the model format version. No timestamp is written, so exporting the same model twice produces identical output
- Preserve existing settings such as dictionary name, character encoding, schema definitions, and other user-defined configuration