stanfordnlp/CoreNLP · error · IllegalArgumentException
Illegal request for fold
Error message
Illegal request for fold ${fold} of ${numFolds} on data set of size ${size} What it means
Thrown by GeneralDataset.splitOutFold when the requested fold index is out of the valid range [0, numFolds) for a data set of the given size. It is a range-validation guard protecting k-fold partitioning from bad fold arguments.
Solutions
- Use fold indices in 0..numFolds-1
- Verify numFolds matches the value used to create the cross-validation iterator
- Clamp or wrap fold indices before calling splitOutFold
Defensive patterns
Strategy: validation
When it happens
Trigger: Thrown at src/edu/stanford/nlp/classify/GeneralDataset.java:290 when the library encounters an invalid state.
Common situations: See trigger scenarios.
AI-assisted analysis of stanfordnlp/CoreNLP@1b7edd19c4 (2026-09-10).
Data as JSON: /api/errors/b29339262cba50c6.
Report an issue: GitHub.
Appendix: source
Thrown at src/edu/stanford/nlp/classify/GeneralDataset.java:290
* @param fractionSplit The first fractionSplit of datums (rounded down) will be the second split
* @return A Pair of data sets, the first being the remainder of size ceiling(this.size() * (1-p)) drawn
* from the end of the dataset and the second of size floor(this.size() * p) drawn from the
* start of the dataset.
*/
public abstract Pair<GeneralDataset<L, F>, GeneralDataset<L, F>> split (double fractionSplit);
/** Divide out a (devtest) split of the dataset versus the rest of it (as a training set).
*
* @param fold The number of this fold (must be between 0 and (numFolds - 1)
* @param numFolds The number of folds to divide the data into (must be greater than or equal to the
* size of the data set)
* @return A Pair of data sets, the first being roughly (numFolds-1)/numFolds of the data items
* (for use as training data_, and the second being 1/numFolds of the data, taken from the
* fold<sup>th</sup> part of the data (for use as devTest data)
*/
public Pair<GeneralDataset<L, F>, GeneralDataset<L, F>> splitOutFold(int fold, int numFolds) {
if (numFolds < 2 || numFolds > size() || fold < 0 || fold >= numFolds) {
throw new IllegalArgumentException("Illegal request for fold " + fold + " of " + numFolds +
" on data set of size " + size());
}
int normalFoldSize = size()/numFolds;
int start = normalFoldSize * fold;
int end = start + normalFoldSize;
if (fold == (numFolds - 1)) {
end = size();
}
return split(start, end);
}
/**
* Returns the number of examples ({@link Datum}s) in the Dataset.
*/
public int size() {
return size;
}
View on GitHub (pinned to 1b7edd19c4)