Migrating from v7.1 to v7.2

This guide lists what v7.2.0 changes for existing code and files. All of it is in bunsetsu dependency analysis (Lindera Dependency). There are two breaking changes, in the Rust API of lindera-dependency, and they are in a minor version by a decision of the maintainer (#1507, #1499).

Overview

ChangeAffectsWhat you do
Schema has two new fields, head_fallback and sentence_splitRust code that builds a lindera_dependency::Schema with a struct expression that names every fieldAdd the two fields, or end the expression with ..Schema::default()
chunker::TrainOptions has a new field, unfinished_textsRust code that builds a lindera_dependency::chunker::TrainOptions with a struct expression that names every fieldAdd unfinished_texts, or end the expression with ..Default::default()
train-chunker trains on texts it makes from the sentencesA chunker you train: it is another model than v7.1 trained from the same dataNothing, or --sentences-only for the model of v7.1
The model file is version 4A program of v7.1 that is given a model file made by v7.2Give each program the model of its own version. v7.2 reads the model files of v7.1
The published models are built againCode that compares scores, or that adds a 。 to a text without oneNothing: the 。 is not needed any more
A text of several sentences is cut into sentencesCode that counts on the bunsetsu of a text with a 。 in its middleNothing: a bunsetsu starts after the 。
A space is no wordCode that counts on the bunsetsu of a text with full-width spacesNothing: a space is no longer a bunsetsu of its own or a head word

Code that analyzes text with a model of this crate, with lindera dependency parse or with the token filter japanese_dependency, needs no change.

Schema has two new fields

lindera_dependency::Schema has the field head_fallback: HeadFallback (#1507): which morpheme is the head word of a bunsetsu in which the rule finds none, such as する alone in brackets (see A bunsetsu without a head word). It also has the field sentence_split: SentenceSplit (#1512): whether a chunker cuts a text into sentences before it gives it to its model (see A text of several sentences). Schema is not #[non_exhaustive], so a struct expression that names every field no longer compiles:

error[E0063]: missing fields `head_fallback` and `sentence_split` in initializer of `lindera_dependency::Schema`

Add head_fallback: HeadFallback::FirstMorpheme and sentence_split: SentenceSplit::None, which is what every schema did before, or HeadFallback::FirstWord and SentenceSplit::AfterEnds, which is what Schema::ipadic() and Schema::unidic() have from v7.2 on. Or end the expression with ..Schema::default(), which later fields then do not break. Code that takes Schema::ipadic() or Schema::unidic(), that ends its expression with one of them (..Schema::ipadic()), or that takes the schema of a model file is not affected.

TrainOptions of the chunker has a new field

lindera_dependency::chunker::TrainOptions has the field unfinished_texts: bool (#1499). TrainOptions is not #[non_exhaustive], so a struct expression that names every field no longer compiles:

error[E0063]: missing field `unfinished_texts` in initializer of `lindera_dependency::chunker::TrainOptions`

Add unfinished_texts: false, which is what every training did before, or true, which is the default from v7.2 on. Or end the expression with ..Default::default() or ..TrainOptions::for_dictionary(name)?, which later fields then do not break.

train-chunker trains on texts it makes from the sentences

lindera dependency train-chunker and chunker::train make two texts from each sentence of the training data, the sentence without its last period and a phrase cut out of it, and train on them too (see Texts that do not end as a sentence). A chunker trained on sentences alone took a period for the only end of a text, and cut the last bunsetsu of a text without one wrongly.

The model is another one than v7.1 trained from the same data, and it is larger. --sentences-only, or unfinished_texts: false, trains as v7.1 did.

The model file is version 4

The schema of a model file holds the new setting, so the format is version 4 (see The format).

  • v7.2 reads the model files of v7.1 (version 3): the published ones, and the ones you trained. Their schema has no such setting, and a bunsetsu without a head word has its first morpheme as the head word, as in v7.1.
  • v7.1 refuses a model file of v7.2, with the model has the version 4, and this crate reads 3. lindera dependency download gets the model of the version of the command, and a build that embeds a model takes the one of its own version, so this only happens when a file is carried from one version to the other by hand.

The published models are built again

The models for IPADIC and for the three UniDic dictionaries are trained with the changes above, so lindera dependency download and a build that embeds a model get other files than with v7.1, with other scores.

  • A text that does not end with a period is cut as one that does: 人を噛んだ犬 is 人を / 噛んだ / 犬, where v7.1 gave 人を / 噛んだ犬. A 。 that was added to a query or a title for the analysis is not needed any more, and does no harm.
  • A bracket is no longer the head word of a bunsetsu such as 「する」と.
  • On the dev and test files of UD Japanese-GSD and on UD Japanese-PUD the accuracy does not differ from the one of v7.1 (Accuracy).

A text of several sentences is cut into sentences

A chunker with a model of v7.2 cuts its text after each sentence end (。, !, ?) and gives each part to the model on its own, inside brackets as outside (#1512; see A text of several sentences). In v7.1 the word after a 。 in the middle of a text often started no bunsetsu: 雨が降った。試合は中止になった。 was 雨が / 降った / 。試合は / 中止に / なった。, with the 。 in the bunsetsu of the word after it. In v7.2 it is 雨が / 降った。 / 試合は / 中止に / なった。.

  • A text of one sentence is cut as before, but for the sentences that have an end inside them, such as a quotation of two sentences.
  • With a model file of v7.1, and with a model converted from CaboCha's, the text is given to the model whole, as in v7.1.

A space is no word

A token whose surface is of white space alone, which is the full-width space (U+3000) and a half-width space when the tokenizer keeps white space, is no longer read by the chunker and the parser (#1507). This holds with the model files of v7.1 too.

  • A space is in the bunsetsu of the word after it, and the spaces at the end of a sentence are in the last bunsetsu. In v7.1 a space could be a bunsetsu of its own, which changed the numbers of the bunsetsu after it.
  • A space is neither the head word nor the function word of a bunsetsu. In v7.1 it could be the head word of the bunsetsu it started.
  • The token filter japanese_dependency keeps the spaces after the end of a sentence in that sentence. In v7.1 they started the next one.