for optimal perplexity or speech recognition accuracy or to obtain a specific size lexicon. A greedy search algorithm is used to find the optimal segmentation of morphs, given the training data. When the best model is found, it is used to segment the language model training corpus using the Viterbi algorithm.

We apply the Morfessor 2.0 implementation[^8] of the Morfessor Baseline algorithm with the hyperparameter extension [@Virpioja:2013]. In the output segmentation, we prepend and append the in-word boundaries of the morph surface forms by a “+” character. For example the compound word “luentokalvoja” is segmented into “luento kalvo ja” and then transformed to “luento+ +kalvo+ +ja” \[*lecture+ +slide+ +s*\] before language model training. All four different variants of a subword (e.g. “kalvo”, “kalvo+”, “+kalvo”, and “+kalvo+”) are treated as separate tokens in language model training. As high-order n-grams are required to provide enough context information for subword-based modeling, we use variable-length n-gram models trained using the VariKN toolkit[^9] that implements the Kneser-Ney growing and revised Kneser pruning algorithms [@Siivola:2007].

In the speech recognition framework based on weighted finite-state transducers (FSTs), we restrict the lexicon FST in such a way that only legal sequences (meaning that a morph can start with 