New training runs now use the English default sentence markers <START> and
<END>. Documentation, sample word corpora and example model names also use
English. The public API, CLI help and diagnostic messages are in English.
Loading an existing CTLS2 or CTWM model preserves its exact stored vocabulary, marker labels, token IDs, counts and scores. The loader does not translate or rename tokens. CTLS2 and CTWM keep their existing binary versions, and the lookup/scoring implementations are unchanged.
If you need a new training run to reproduce the marker labels from version 2.1, specify them explicitly:
from languagestatisticslibpy import NGramTrainer
trainer = NGramTrainer(
orders=(2, 3), unit="word", sentence_boundaries=True,
start_token="<ANFANG>", end_token="<SATZENDE>",
)For loaded models, read marker labels and IDs from the model metadata instead
of assuming the current training defaults. Custom names remain supported.
The example corpus files are now examples/words_en.txt and
examples/words_punctuation_en.txt; their models use the en language tag.
Version 2.1 retained the <ANFANG> / <SATZENDE> default labels from 2.0.
Calls that omitted the new options retained their previous punctuation
handling, vocabulary order, counts and scores. New trainer options are
start_token, end_token,
punctuation, sentence_endings and split_word_joiners. Selected punctuation
is added to a fixed vocabulary automatically, before the structural markers.
Enabling punctuation changes the vocabulary and training windows. Train a new
model and re-encode candidate tokens using that model; old IDs or packed keys
must not be reused. In raw-text word tokenization internal apostrophes and
hyphens stay inside words by default. Explicit add_tokens input bypasses
punctuation selection and sentence segmentation.
CTLS2 and CTWM keep their existing binary versions; the additional settings are metadata. Existing model files remain loadable. Scoring methods and the legacy adapter are unchanged. See PUNCTUATION.md.
Existing imports and LanguageStatistics.create_grams_by_size(1..6, ...) keep
the original specialized scoring functions. Existing CTLS filenames such as
en-4gram-nocs.gz and Dictionary_en.dic remain supported.
LanguageStatisticsFile.load_frequencies() now recognizes CTLS1/CTLS2 content
and returns the dense tensor expected by the old classes. It rejects sparse
models with a clear instruction to use NGramModel, avoiding accidental huge
allocations. The original class factory stays limited to its six named classes;
arbitrary n is available through NGramModel and NGramTrainer.
The original alphabet-remapping and normalize algorithms are otherwise unchanged. The new token API does not depend on those legacy remapping methods.
from languagestatisticslibpy import load_model
model = load_model("path/to/model.ctls2")Alternatively, LanguageStatistics.load_model(path) is available. Compression
and format are recognized by magic; a suffix is not required for detection.
Use model.vocabulary for the exact token inventory and model.token_to_id
for its mapping. model.scores is the flat dense array or integer-key dictionary.
IDs and packed keys belong to a specific vocabulary/order. Do not reuse a key from a different model just because its tokens look similar. Token strings may contain arbitrary Unicode; convert them to IDs once outside a search loop.
legacy = model.as_legacy_grams() # dense models, order 1..6
score = legacy.calculate_cost(candidate_ids)This constructs an instance of the old specialized class. No format dispatch
or wrapper runs in its scoring loop. Its score array is a shared view by default;
use copy=True if old normalization or other mutation should be isolated.
The general model.calculate_cost() uses float64 accumulation and may differ
by rounding from the old float32 accumulation. Stored table values are float32
in both cases. The new method is often faster for longer candidates; the exact
old adapter is available when short-candidate latency or identical accumulation
is more important.
- New software loads old CTLS1 files directly.
- Standalone CTLS2 files need the new reader.
- Eligible character models can include a CTLS1 prefix via
legacy_compatible=True, or be exported as pure CTLS1. - An old character-only format cannot represent multi-character syllables, arbitrary word tokens, counts or boundary policy metadata.
python -m languagestatisticslibpy convert old.gz new.ctls2 --format ctls2
python -m languagestatisticslibpy convert old.gz hybrid.ctls2 --format ctls2 --legacy-compatible
python -m languagestatisticslibpy convert new.ctls2 old.gz --format ctlsCTLS1 import cannot recover corpus counts or tokenization rules absent from that
format. Its metadata therefore marks score_kind=legacy; counts remain None.
The API defaults to preserving case and NFC Unicode normalization. An explicit
vocabulary is normalized using the same rules as input. Unknown input to a fixed
inventory is an error by default. unknown="boundary" drops windows containing
unknown positions while preserving a break; unknown="unk" counts a dedicated
<UNK> token. Neither policy silently joins formerly nonadjacent material.
For syllables, whitespace-separated input is the default. Greedy segmentation is optional and needs a fixed inventory. It is a deterministic tokenization rule rather than a language-independent syllabification algorithm.
For words, use pre-segmented sentences for precise results. The built-in .?!
sentence rule is deliberately simple. In the CLI, word training enables
sentence markers by default; the Python constructor's sentence_boundaries
default is false so callers opt in explicitly. add_tokens always represents
one independent sequence, regardless of punctuation inside token labels.
Files stream as paragraphs or individual sentence lines. Wrapped lines within a paragraph remain connected, while blank lines and file boundaries reset the window. Maximum paragraph and sequence sizes are configurable. Training keeps observed n-gram counts in RAM; it is not an external-sort/out-of-core trainer.
WordTree.contains_word() now requires an actual end-of-entry marker; prefixes
are no longer accepted as complete entries. UTF-8 is decoded by complete
characters, and the header word count is validated against the number of entries
instead of counted twice. Code that relied on the previous incorrect prefix or
double-count behavior must adapt.
The word-model format is separate from CT2DIC. The existing single-word
dictionary has no word-order evidence from which real word n-gram counts could
be reconstructed. Train CTWM from a corpus with its sequence structure retained.