stanfordnlp/CoreNLP · error · IllegalArgumentException
KBestSequenceFinder only works with rightWindow == 0 not
Error message
KBestSequenceFinder only works with rightWindow == 0 not
What it means
KBestSequenceFinder.kBestSequences enumerates k-best label sequences with a left-to-right algorithm that requires the model to have no right context window (rightWindow == 0). Models with a non-zero right window throw IllegalArgumentException('KBestSequenceFinder only works with rightWindow == 0 not ' + rightWindow).
Solutions
- Rebuild/wrap the SequenceModel so it has rightWindow == 0 (move right-context features into left context or drop them).
- Use ExactBestSequenceFinder (or another finder supporting right windows) if you only need the single best sequence.
- If you need k-best with right windows, implement a search that handles them, since this finder explicitly does not.
Example fix
// before new KBestSequenceFinder().kBestSequences(modelWithRightWindow, k); // model.rightWindow() == 1 // after new ExactBestSequenceFinder().bestSequence(modelWithRightWindow); // or construct the model with rightWindow = 0 and then: new KBestSequenceFinder().kBestSequences(modelRightWindowZero, k);
Defensive patterns
Strategy: validation
Validate before calling
// check the finder's precondition before calling
if (ts.rightWindow() != 0)
throw new IllegalArgumentException("use ExactBestSequenceFinder for rightWindow=" + ts.rightWindow()); Type guard
boolean supportsKBest(SequenceModel ts) { return ts.rightWindow() == 0; } Prevention
- Check rightWindow() before choosing a sequence finder.
- Prefer ExactBestSequenceFinder when right context is needed.
- Document right-window requirements in custom SequenceModel implementations.
When it happens
Trigger: Calling kBestSequences (or bestSequences/bestSequence/bestLabelsCounter, which delegate to it) on a SequenceModel whose rightWindow() is non-zero, at KBestSequenceFinder.java:46.
Common situations: Requesting n-best output from taggers/CRFs whose SequenceModel carries right-side context (e.g. models built with a right window for lookahead features); switching a pipeline from ExactBestSequenceFinder to KBestSequenceFinder without adjusting the model.
Understand the failure class
Background: UnsupportedOperationException and "is not supported" errors: when a library deliberately refuses a call — this error's family across 30 libraries.
Related errors
- BiLexPCFGParser doesn't support k best parses
- linearConstraints.length (
- Two models must have the same number of classes
- Two models must have the same sequence length
- LogPrior.getSigmaSquaredM is undefined for any prior but…
AI-assisted analysis of stanfordnlp/CoreNLP@1b7edd19c4 (2026-09-10).
Data as JSON: /api/errors/93adb8d392042d48.
Report an issue: GitHub.
Appendix: source
Thrown at src/edu/stanford/nlp/sequences/KBestSequenceFinder.java:46
/**
* Runs the Viterbi algorithm on the sequence model, and then proceeds to efficiently
* backwards decode the best k label sequence assignments.
* This sequence finder only works on SequenceModel's with rightWindow == 0.
*
* @param ts The SequenceModel to find the best k label sequence assignments of
* @param k The number of top-scoring assignments to find.
* @return A Counter with k entries that map from a sequence assignment (int array) to a double score
*/
@SuppressWarnings("MethodMayBeStatic")
public Counter<int[]> kBestSequences(SequenceModel ts, int k) {
// Set up tag options
int length = ts.length();
int leftWindow = ts.leftWindow();
int rightWindow = ts.rightWindow();
if (rightWindow != 0) {
throw new IllegalArgumentException("KBestSequenceFinder only works with rightWindow == 0 not " + rightWindow);
}
int padLength = length + leftWindow + rightWindow;
int[][] tags = new int[padLength][];
int[] tagNum = new int[padLength];
for (int pos = 0; pos < padLength; pos++) {
tags[pos] = ts.getPossibleValues(pos);
tagNum[pos] = tags[pos].length;
}
int[] tempTags = new int[padLength];
// Set up product space sizes
int[] productSizes = new int[padLength];
int curProduct = 1;
for (int i = 0; i < leftWindow; i++) {View on GitHub (pinned to 1b7edd19c4)