Troubleshooting
Common errors and surprises, with the cause and the fix. These are drawn from the documented contracts of each method (see API Reference).
Training
ValueError: No words found meeting minimum frequency thresholdtrain()builds its vocabulary from words above a 0.01% heavy-hitter threshold. This error means no word cleared it — usually the corpus is empty, far too small, or was already consumed.Pass a fresh iterable. A generator or file handle is consumed once; if you iterate it before calling
train(or calltraintwice on the same generator), the second pass sees nothing.Give it more data. The internal PPMI step also requires word and skip-gram counts above 5, so very small corpora can train but yield a near-empty vocabulary.
most_similarreturns[]/distanceandget_vectorreturnNoneThe model has not been trained, the word is not in the vocabulary, or the word’s vector has effectively zero norm. These cases are deliberately non-raising and are indistinguishable from each other. Check
len(model.vocabulary)andword in model.vocabularyfirst.- Results change between identical runs
If sparse SVD fails on a small or degenerate matrix,
train()silently falls back to a dense SVD with a tiny amount of random noise added, so embeddings can vary slightly run-to-run. A larger corpus avoids the fallback path.
Memory and accuracy (Count-Min Sketch)
The counter is a CountMinSketch
sized by cms_width and cms_depth.
Memory is
cms_width * cms_depth * 4bytes per sketch. The defaultcms_width=1_000_000is ~20 MB per sketch (two are used during training).Accuracy: counts are never underestimated but can be over-estimated on hash collisions. If rare words leak into the vocabulary, increase
cms_width. If memory is tight on a small corpus, lower it.
Saving and loading
FileNotFoundErrorwhen callingload_modelThe directory is missing
embeddings.npyorvocabulary.pkl. The most common cause is callingsave_model()beforetrain: only attributes that are set are written, so an untrained model saves an emptyvocabulary.pkland no embeddings. Train before saving.ValueError: Directory not foundload_model()was given a path that is not an existing directory.save_modelwrites a directory of files, not a single file — pass that directory toload_model.- Loading executes code
Both
SVDAlgebra.load_modelandload()unpickle their input, which can run arbitrary code. Only load files you produced or trust.
Alignment
ValueError: No common words found for alignment/No valid anchor words foundfit()could not assemble anchors. Either the two vocabularies share too few words in the frequency-rank window, or every candidate anchor was dropped for being missing from one space or having a near-zero vector. Widenmax_freq_rank, or pass an explicitanchor_wordslist of words you know are in both vocabularies.ValueError: Aligner must be fit before transformCall
fit()beforetransform().get_word_similarityraises or returnsnanIt returns
Noneif the word is missing from either vocabulary, but it does not guard against zero-norm vectors (a zero vector yieldsnanand aRuntimeWarning) and it assumes the aligner has been fit. Make sure the word is shared and the aligner is fitted.
Topic modeling
ValueErrorfromTopicModel.fitRaised by scikit-learn’s NMF when
n_topicsexceeds the matrix dimensions, or if the matrix has negative entries. PPMI matrices are non-negative, so the usual cause is too many topics for a small vocabulary — reducen_topics.ValueError: Model must be fit before getting document topicsCall
fit()beforeget_document_topics().- Empty or all-zero topics
On a tiny PPMI matrix, NMF can produce degenerate components whose weights sum to zero; chronowords leaves those distributions unnormalised rather than raising. Use a larger corpus for meaningful topics.
Build / install
- The Cython extension fails to import
chronowords.utils.count_skipgramsis a compiled Cython module. After editing the.pyxsource, rebuild it with:uv sync --reinstall-package chronowords
A C/C++ compiler must be available on the build machine.