Model File
A model file holds what one dictionary needs to be analyzed: the name of the dictionary, its schema, and the trained parts: the chunker and the parser.
A model belongs to one dictionary. It depends on the feature columns of the dictionary and on how the dictionary segments a text, so the file says which dictionary it is for, and one file serves one dictionary.
A release of Lindera publishes the model for IPADIC and the models for UniDic, from 7.1.0 on. train-chunker writes a model file with the chunker, and train-parser one with the parser, or with both.
Reading a model
Model reads a file in place. It is generic over what holds the bytes, and copies none of its tables:
#![allow(unused)] fn main() { use lindera_dependency::model::Model; // Bytes read from a file: the model owns them. let model = Model::new(std::fs::read("ipadic.model")?)?; assert_eq!(model.dictionary(), "ipadic"); let chunker = model.chunker().expect("the file has a chunker"); let parser = model.parser().expect("the file has a parser"); }
| What holds the bytes | How |
|---|---|
| A file read into memory | Model::new(std::fs::read(path)?) gives a Model<Vec<u8>> |
| A file embedded in the program | Model::new(include_bytes!("ipadic.model").as_slice()) gives a Model<&'static [u8]> |
| A memory map | Model::new(map) for any type that implements AsRef<[u8]>, such as the map of the memmap2 crate. This crate has no dependency and maps nothing itself |
The whole file is checked once, in Model::new: bytes that are not a model file of this version give an Error::Model, and nothing fails or panics afterwards. No number is read through a pointer, so the bytes can sit at any address, aligned or not. The same code runs on wasm32-unknown-unknown.
Model::chunker gives a Chunker that reads its weights on the bytes of the model, or None when the file has no chunker part; Model::parser gives a Parser the same way. Model::analyze chunks and parses a sentence in one call. A Model is Send + Sync when its bytes are, and one model serves several threads.
Checking the dictionary
A model used on the morphemes of another dictionary gives wrong answers without an error, unless it is checked. There are two checks.
The name. What knows the dictionary of its morphemes compares its name with the one of the model:
#![allow(unused)] fn main() { model.check_dictionary("ipadic")?; assert!(model.check_dictionary("unidic").is_err()); }
the model is for the dictionary "ipadic", and the morphemes are of "unidic"
The number of feature columns. A morpheme with fewer feature columns than the schema of the model reads is refused when it is chunked or parsed, with an Error::Dictionary. The schema of IPADIC reads seven columns: four levels of part of speech, the conjugation type, the conjugation form and the base form.
#![allow(unused)] fn main() { use lindera_dependency::lattice::LatticeMorpheme; // Three feature columns: not a morpheme of IPADIC. let morphemes = [LatticeMorpheme::new("彼", "名詞,代名詞,一般")]; let error = chunker.chunk(&morphemes).unwrap_err(); println!("{error}"); }
the morpheme 1 ("彼") has fewer than the 7 feature columns the schema reads: it is not of the dictionary of the model
The second check does not find morphemes of another dictionary that are wide enough: the morphemes of UniDic have more columns than IPADIC, and mean something else. Only the name tells those apart, so a caller that knows its dictionary should check the name.
Writing a model
ModelBuilder writes a file from the name of the dictionary, its schema and the parts. The chunker part comes from a ChunkerModel and the parser part from a ParserModel, which are what training gives (of the chunker, of the parser). This chunker is made by hand:
#![allow(unused)] fn main() { use std::collections::HashMap; use lindera_dependency::chunker::{ChunkerModel, Column, Template}; use lindera_dependency::model::{Model, ModelBuilder}; use lindera_dependency::Schema; // A chunker made by hand, with one weight: a morpheme after a particle // starts a bunsetsu. let mut features = HashMap::new(); features.insert("U11:助詞-係助詞".to_string(), [1.0, 0.0]); let transitions = [[0.0, 0.0, 0.0], [0.0, 0.0, 0.5], [0.0, 0.0, 0.5]]; let chunker = ChunkerModel::new( Schema::ipadic(), vec![Column::Surface, Column::PartOfSpeech], Template::cabocha(), transitions, features, )?; let bytes = ModelBuilder::new("ipadic", Schema::ipadic())? .chunker(&chunker)? .to_bytes(); std::fs::write("chunker.model", &bytes)?; let model = Model::new(bytes)?; assert_eq!(model.dictionary(), "ipadic"); }
The same parts give the same bytes. A part trained with another schema than the one of the file is refused.
ModelBuilder::parser takes a ParserModel and how its weights are written (Quantization::F32, I16 or I8). ModelBuilder::from_model starts from the name, the schema and the parts of a file that exists, to add a part to it; train-parser --chunker does this with the chunker.
The model for IPADIC
The project trains a model for IPADIC, with a chunker and a parser. A release of Lindera builds it with build_model.sh and puts it on the page of its version, next to the dictionaries, from 7.1.0 on: lindera-dependency-ipadic-<version>.zip in v<version>. The model has the version of the release, as the dictionaries have, and belongs to it: a program of Lindera 7.1.0 takes the model of 7.1.0.
lindera dependency download ipadic installs the archive of the version of the command, and prints the path of the model file.
The archive holds one directory, lindera-dependency-ipadic, with three files:
| File | What it is |
|---|---|
dependency.model | The model file |
model.json | The name of the model (dependency-ipadic), its dictionary (ipadic) and the version of Lindera (lindera_version) |
NOTICE.txt | The license of the model, what it was made from, and the notice of IPADIC |
| Dictionary | IPADIC (ipadic), as the lindera-ipadic crate builds it from mecab-ipadic 2.7.0 |
| Training data | The train file of UD Japanese-GSD at c662dc9, converted with IPADIC: 7,024 sentences |
| Settings | The defaults of train-chunker and of train-parser |
| Size | 6,304,266 bytes |
| License | MIT, with a notice: see License of the model |
Only the train file is used. The dev and test files of UD Japanese-GSD and UD Japanese-PUD are not seen in training, and no setting was chosen on them, so the accuracy measured on them is the accuracy of the file itself.
Embedding it
The feature embed-model-ipadic of lindera-dependency embeds the model in the program; lindera, lindera-cli and the bindings forward it as embed-dependency-ipadic. The model is then named as the embedded dictionary is:
#![allow(unused)] fn main() { use lindera_dependency::embedded; // The bytes of the program, read in place. let model = embedded::model("ipadic")?; assert_eq!(model.dictionary(), "ipadic"); }
The command takes --model embedded://ipadic, and the token filter model: "embedded://ipadic". A build without the feature answers with an error that names it.
The model is not trained by the build: the training needs the corpus. Where the build takes it from depends on where the crate comes from:
| Build | The model it embeds |
|---|---|
| The crate from crates.io | The archive of its release, which the crate pins by SHA-256 in a prebuilt.json: the build downloads it and checks it, as a dictionary crate does for its dictionary |
The repository (main, a pull request, a git dependency) | The file LINDERA_BUILD_DEPENDENCY_MODEL_IPADIC_FILE names. The repository has no prebuilt.json, and a build without the variable stops with an error that says so |
| docs.rs | An empty file: embedded::model gives an error |
With the variable set, a published crate embeds that file too, instead of the one it pins.
scripts/dependency/build_model.sh
export LINDERA_BUILD_DEPENDENCY_MODEL_IPADIC_FILE=$PWD/scripts/dependency/data/model/lindera-dependency-ipadic/dependency.model
cargo build --release -p lindera-cli --features embed-ipadic,embed-dependency-ipadic
Building it again
One script builds the file from the corpus and the sources of the repository:
scripts/dependency/build_model.sh
It gets UD Japanese-GSD at its fixed commit, builds the lindera command with a named toolchain and the dependencies of Cargo.lock, converts the train file, trains the chunker and the parser, and writes the directory of the archive and the archive to scripts/dependency/data/model. It takes about 15 seconds after the build. At its end it names the commit of Lindera, and then says what else it used and what it made. In the release of v7.3.0:
corpus: UD Japanese-GSD c662dc96ed5ee5ac0fc8b5e44261557e431f50e6
toolchain: rustc 1.100.1 (20ddd0171 2026-11-25)
platform: x86_64-unknown-linux-gnu, glibc 2.43
training data: 5075c95f2518b6af791e6a9ea2bd5f9f63eeaa5b316f3801d8068d71436e5064 train.lattice
chunker: fc9ab7e0ca83c7cf3f34bed44476a672a53e3b37b755d85c25ae047e6fa6235a chunker.model
model: 53ff5be09de7bd3051751fbaaebd4cc9334936ed9ac053979b8f175263019e55 lindera-dependency-ipadic/dependency.model (6304266 bytes)
archive: afc1a5fe6e2d159ac378659d762b36c2a1270bcca5f6b8cf1fcd661f188be341 lindera-dependency-ipadic-7.3.0.zip
--check <sha256> makes the script fail when the file it built has another SHA-256. The script refuses a tree with uncommitted changes, so that the commit it names is what the file was built from.
The same sources, corpus, toolchain and platform give the same bytes: nothing in the training depends on the time, on the number of threads or on the order of a hash table. Whether another platform gives the same bytes is not known. The training of the chunker calls exp and ln_1p of the mathematics library of the platform, and their last bit can differ from one library to another. The notice of a file (NOTICE.txt) names the platform it was built on. The model of a release is built by the runner of the release, so its bytes can differ from those of another machine; the SHA-256 of its archive is in the prebuilt.json of the published crate. The release measures the model it built on dev, test and PUD, and stops when a count is not the one of this documentation (Dictionary Release).
License of the model
The model file is distributed under the MIT license, the license of Lindera's code. NOTICE.txt, which comes with the file, has the text of the license, an acknowledgement of UD Japanese-GSD and the notice of IPADIC. This is how the project handles the question; it is not legal advice.
The question. UD Japanese-GSD is licensed under CC BY-SA 4.0. That license asks that material "derived from or based upon" the licensed material ("Adapted Material") is shared under the same license. Neither the license nor the FAQ of Creative Commons says whether a model trained on a work is such material.
What the model holds. The names of features and their weights. A name is made of a part of speech, a conjugation form or the surface of one morpheme, so single words of the training sentences are in the file. No sentence is, and nothing of the annotation: no bunsetsu and no dependency. The model generates no text.
The position. The project takes such a model not to be an adaptation of the treebank, so that the share-alike condition does not reach it. The position rests on these:
- The Agency for Cultural Affairs of Japan, AI と著作権に関する考え方について (March 2024): a trained model is in many cases not a reproduction of the works it was trained on; it can be one when it is in a state to generate, with high probability, what resembles them. The document says of itself that it is not legally binding.
- Szkalej and Senftleben, Mapping the Impact of Share Alike/Copyleft Licensing on Machine Learning and Generative AI (2024): "the final artefact – the trained model – is unlikely to constitute adapted material", as long as it holds no protected traces of the works.
- Creative Commons, Using CC-licensed Works for AI Training (2025): releasing a model under the license of its training data is "the most conservative approach", and following it "will almost certainly lead to overcompliance".
- Models trained on text under CC BY-SA are released under permissive licenses: the models of BERT, trained on Wikipedia, are under Apache 2.0.
What is uncertain. No court has decided whether a trained model is an adaptation of its training data, and others chose the other way: the Japanese model of spaCy, trained on the same treebank, is under CC BY-SA 4.0. If the position turns out to be wrong, the model is distributed under CC BY-SA 4.0 from then on; the file itself does not change.
What a user does.
| Use | What it asks |
|---|---|
| Analyzing text with the model | Nothing. The project puts no condition on what an analysis gives |
| Distributing the file, or a program that embeds it | NOTICE.txt goes with it: the text of the MIT license and the notice of IPADIC |
| Changing the model and distributing the result | The same |
The models for UniDic
A release of Lindera publishes a model for each of the three UniDic dictionaries too, from 7.1.0 on: unidic (unidic-mecab 2.1.2), unidic-cwj and unidic-csj. What is said above for IPADIC holds with the name of the dictionary in place of ipadic:
| Archive | lindera-dependency-unidic-<version>.zip, lindera-dependency-unidic-cwj-<version>.zip, lindera-dependency-unidic-csj-<version>.zip, each with one directory of the same three files |
| Download | lindera dependency download unidic, unidic-cwj or unidic-csj |
| Embedding | embed-model-unidic, embed-model-unidic-cwj or embed-model-unidic-csj of lindera-dependency, forwarded as embed-dependency-unidic and the like; the model is then embedded://unidic, embedded://unidic-cwj or embedded://unidic-csj |
| File for a build from the repository | LINDERA_BUILD_DEPENDENCY_MODEL_UNIDIC_FILE, LINDERA_BUILD_DEPENDENCY_MODEL_UNIDIC_CWJ_FILE or LINDERA_BUILD_DEPENDENCY_MODEL_UNIDIC_CSJ_FILE |
| Building it again | build_model.sh --dictionary <name>, with --dict for the directory of the dictionary |
| Training data | The train file of UD Japanese-GSD, converted with that dictionary: 7,024 sentences |
| Settings | The ones of train-chunker for UniDic, and the defaults of train-parser |
| Size | 6,291,246 bytes for unidic, 6,286,507 for unidic-cwj, 6,308,536 for unidic-csj |
| License | MIT, with a notice that carries the notice of the dictionary. UniDic is under the GPL v2.0, the LGPL v2.1 or the BSD license, at the choice of the user |
A model is for one dictionary. The three UniDic dictionaries do not segment and tag alike, and the model for unidic-cwj is refused with the morphemes of unidic. UniDic CSJ is a dictionary for spoken language, and the training data is written language.
Nothing embeds UniDic to train a model: build_model.sh takes the directory of the dictionary with --dict, or installs the one of the release of the version of the workspace with lindera dictionary download. A release trains each model with the dictionary it has just built, measures it on the files it was not trained on, and stops when a count is not the one of the documentation, as it does for IPADIC.
The four models of Lindera 7.2, on the test file of UD Japanese-GSD converted with each dictionary, on one core of an AMD Ryzen AI Max+ 395. The speeds are sentences per second. Those of chunking, of parsing and of both are the median of seven runs, which are up to 8.5% apart; the three last columns are from one run each:
| Dictionary | Size of the file (bytes) | Of which the chunker | Chunking | Parsing the bunsetsu of the answer | Chunking and parsing | From text, with the tokenizer | Loading the dictionary and the model | The token filter, microseconds per token |
|---|---|---|---|---|---|---|---|---|
| IPADIC | 6,304,266 | 309,775 | 19,400 | 16,600 | 8,500 | 6,800 | 6 ms | 5.2 |
unidic | 6,291,246 | 396,025 | 12,800 | 16,700 | 6,800 | 5,300 | 6 ms | 6.3 |
unidic-cwj | 6,286,507 | 388,688 | 13,000 | 16,400 | 6,900 | 4,500 | 6 ms | 6.5 |
unidic-csj | 6,308,536 | 405,170 | 13,000 | 16,700 | 6,900 | 4,500 | 6 ms | 6.5 |
The models of 7.1, measured in the same session, differ little from these. The chunkers of 7.2 are larger (IPADIC had 261,857 bytes), and chunk 1% to 2% slower, in 26 of 28 pairs of runs; the files take about 2% longer to read. Parsing does not differ. These differences are smaller than the difference of two runs.
The chunker for UniDic reads four columns through a template of 36 lines, against three columns and 24 lines for IPADIC, and is slower by about a third. From text, most of the difference is the tokenizer.
Loading takes the same time for the four dictionaries, though UniDic CWJ and UniDic CSJ are directories of 1.3 GB: the command maps the matrix and the word lists of a dictionary directory into memory (the mmap feature, which its default build has) and does not read them ahead. The pages are read when the text needs them, so the first sentences are slower: with UniDic CWJ, the 543 sentences of the test file take about 230 ms the first time, and about 120 ms after that.
The format
Version 4. Every number is little endian. A string is its length in bytes as a u32, followed by its UTF-8.
| Field | Type | Content |
|---|---|---|
| Magic number | 8 bytes | LDMODEL and a zero byte |
| Version | u32 | 4 |
| Dictionary | string | The name of the dictionary, not empty |
| Schema | The columns of the part of speech, of the conjugation and of the base form; the patterns of the function words, of what is not a head, of the particles and of the function words taken by their surface; the symbols, with one byte for how a surface is matched against their characters (0: every character of it is one of them; 1: it is one of them, and a mark by its surface is still a word); the normalization of the surface, as the number of its rules and for each two strings, what is replaced and by what, sorted; one byte for the rule of the head word (0: a function word is not the head, and the function word is moved to a head after it; 1: the last morpheme that is not a symbol is the function word, and the two are found apart); one byte for the head word of a bunsetsu in which the rule finds none (0: the first morpheme; 1: the first morpheme that is not a comma, a period, a bracket, a space or a particle); one byte for the sentences of a text (0: the chunker gives the text to its model whole; 1: it cuts the text after each sentence end) | |
| Number of parts | u32 | |
| For each part | u32, u64, u64 | Its kind, its offset from the first byte of the file, its length |
| The parts | One after the other, in the order of the list, up to the end of the file |
The kind of the chunker part is 1 and the kind of the parser part 2, in this order. A file with a part of another kind, with the same kind twice, with parts that are not one after the other, or with bytes after the last part is refused, and so is a file of another version, but for version 3, the one of Lindera 7.1: its schema ends with the rule of the head word, a bunsetsu in which the rule finds no head word has its first morpheme as the head word (0), and a text is not cut into sentences (0). A program of Lindera 7.1 refuses a file of version 4. Version 1 had no rule for the surface of a mark and no normalization, and version 2 no rule of the head word; neither was in a release.
The chunker part
| Field | Type | Content |
|---|---|---|
| Number of columns | u32 | |
| Columns | 1 byte each | What the template reads: 0 the surface, 1 the part of speech, 2 the conjugation type, 3 the conjugation form, 4 the base form |
| Template | string | In the format of CRF++ |
| Transitions | 9 × f64 | As [from][to]: 0 is the start of the sentence as from and its end as to, 1 is B, 2 is I |
| Feature strings | table | Each with two f64: the weight of B, then the weight of I |
The parser part
| Field | Type | Content |
|---|---|---|
| Feature set | string | The groups of features, as distance,source,target,left,right,children,gap,after |
| Quantization | 1 byte | How a weight is written: 0 as an f32, 1 as an i16, 2 as an i8 |
| Pairs | 1 byte | 0 for a weight of its own for each pair, 1 for a table the pairs are hashed into |
| Bias | f64 | |
| Scale | f64 | What a weight as it is written is multiplied by; above 0, and 1 for f32 |
| Feature strings | table | Each with its weight; with hashed pairs, followed by its key as a u32 |
| Weights of the pairs | See below |
The score of a decision is the bias, plus the scale times the sum of the weights, as they are written, of its features and of their pairs. The number of a feature is its index in the table.
With hashed pairs: the number of bits as a u32 (1 to 30), then 2^bits weights. The key of a feature is the hash of its string, the one of a table. The place of a pair is taken from the two keys, the smaller in the upper half of a 64-bit number: that number is mixed (XOR with itself shifted right by 30, times 0xbf58476d1ce4e5b9, XOR shifted by 27, times 0x94d049bb133111eb), and its highest bits are the place. Pairs that fall on the same place share its weight.
With a weight for each pair: the number of pairs as a u64; for each feature and once more, as u32, where its pairs start (those in which it has the smaller number); the larger number of each pair as a u32, sorted for each feature; the weight of each pair.
A table
A table maps strings to values of one width, and is looked up where it is in the file.
| Field | Type | Content |
|---|---|---|
| Number of strings | u32 | |
| Width of a value | u32 | In bytes |
| Number of slots | u32 | A power of two above the number of strings |
| Offsets | (number + 1) × u32 | Where each string starts in the strings below; the last is their length |
| Strings | UTF-8, one after the other, sorted by their bytes, each once | |
| Values | number × width | In the order of the strings |
| Slots | slots × u32 | A hash table over the strings |
A slot is 0 when it is empty, and otherwise one more than the index of a string. A string starts at the slot of its hash and goes to the next free slot after it, the first slot following the last. The hash is the 64-bit FNV-1a of the bytes of the string, folded to 32 bits (the high half XOR the low half), modulo the number of slots. The strings are put in by their order, and a table is written with at least two slots per string.
The strings are sorted so that the same strings always give the same bytes; they are found through the slots.
Size and speed
For the default model of Lindera 7.2, the chunker and the parser trained on the train file of UD Japanese-GSD with IPADIC, measured on the 542 sentences of the test file. The time and the speeds are the median of seven runs:
| Size of the file, with both parts | 6,304,266 bytes |
| Of which the chunker, in a file of its own | 309,775 bytes |
Time to read it (Model::new, with every check) | about 2.9 ms |
| Chunking | about 19,400 sentences per second |
| Parsing the bunsetsu of the answer | about 16,600 sentences per second |
| Chunking and parsing | about 8,500 sentences per second |
The model of 7.1 had 6,258,554 bytes, of which the chunker 261,857. Measured in the same session, it is read in about 2.8 ms, chunks about 19,900 sentences per second, parses about 16,400 and does both at about 8,600: the larger chunker of 7.2 is about 2% slower, and parsing does not differ.
The table of the pairs, with 2^22 weights of one byte, is 4.2 MB of the file; the rest is mostly the 62,251 feature strings of the parser.
How the weights of the pairs are kept decides the size and the speed, not the accuracy (see How the defaults were chosen):
| Pairs | Weights | Size of the file | Parsing, sentences per second |
|---|---|---|---|
| Hashed into 2^22 weights | 1 byte | 6,304,266 bytes | about 16,600 |
| Hashed into 2^22 weights | 4 bytes | 19,073,931 bytes | about 14,400 |
| A weight for each pair | 1 byte | 24,590,526 bytes | about 2,700 |
| A weight for each pair | 4 bytes | 38,254,779 bytes | about 2,700 |
The three other tables are measured in three runs each, and the number is their median.
The chunker alone, trained on the same data (5,408 feature strings), on the 7,024 sentences of the train file, in the median of three runs:
| Size of the file | 309,775 bytes |
Time to read it (Model::new, with every check) | about 0.3 ms |
| Chunking with the chunker of the file | about 16,600 sentences per second |
| Chunking with the same chunker in memory, in a hash table of the standard library | about 18,200 sentences per second |
Measured on one core of an AMD Ryzen AI Max+ 395, with Rust 1.100.1; scripts/dependency/model_speed and scripts/dependency/parser_experiments.sh speed measure it again.