stanfordnlp/CoreNLP · error · IllegalArgumentException
Split weights cannot be negative
Error message
Split weights cannot be negative
What it means
SplitTrainingSet validates that each split weight is non-negative; after summing SPLIT_WEIGHTS in main, a weight below 0.0 triggers this IllegalArgumentException. Weights define the proportional size of each named split, so negatives are meaningless.
Solutions
- Replace any negative value in -splitWeights with a zero or positive weight (use 0 to exclude a split's content rather than a negative number).
- Ensure all weights together total a positive value, since the following check also requires totalWeight > 0.
- Validate the properties file values before running the tool.
Example fix
// before -splitNames train,holdout -splitWeights 0.9,-0.1 // after -splitNames train,holdout -splitWeights 0.9,0.1
Defensive patterns
Strategy: validation
Validate before calling
double[] ws = Arrays.stream(props.getProperty("splitWeights").split(","))
.mapToDouble(Double::parseDouble).toArray();
for (double w : ws)
if (w < 0.0) throw new IllegalArgumentException("Negative split weight: " + w);
if (Arrays.stream(ws).sum() <= 0.0)
throw new IllegalArgumentException("Split weights must total positive"); Try / catch
try {
SplitTrainingSet.main(args);
} catch (IllegalArgumentException e) {
if (e.getMessage() != null && e.getMessage().contains("cannot be negative")) {
log.error("Config error: splitWeights must all be >= 0 and sum > 0");
} else throw e;
} Prevention
- Validate weight strings with a regex like ^\d+(\.\d+)?$ before passing them.
- Use 0.0 (not negative values) to effectively exclude a split.
- Keep weights in a reviewed config file rather than typing them inline on the command line.
When it happens
Trigger: Passing -splitWeights with a negative number (e.g. -0.1) or a value parsed as negative due to a stray minus sign/typo in the properties file.
Common situations: Hand-edited config files where a dash from surrounding text got into the numbers; experimenting with 'negative weights' to shrink a split instead of removing it; copy-paste mistakes.
Understand the failure class
Background: "value must be between 0 and 1" / "out of range" / "must not be negative" errors: fixing range-validation failures across open-source libraries — this error's family across 42 libraries.
Related errors
- Name and weight arrays must be of the same length
- Conflicting properties. Multi-word rules file will be…
- Found an argument -baseModels with no actual models named
- Must specify a treebank to train from with -trainTreebank…
- Need to specify -model to load an already prepared…
AI-assisted analysis of stanfordnlp/CoreNLP@1b7edd19c4 (2026-09-10).
Data as JSON: /api/errors/493a36c4a19f51b6.
Report an issue: GitHub.
Appendix: source
Thrown at src/edu/stanford/nlp/trees/SplitTrainingSet.java:75
}
return weights.size() - 1;
}
@SuppressWarnings("unused")
public static void main(String[] args) throws IOException {
// Parse the arguments
Properties props = StringUtils.argsToProperties(args);
ArgumentParser.fillOptions(new Class[]{ArgumentParser.class, SplitTrainingSet.class}, props);
if (SPLIT_NAMES.length != SPLIT_WEIGHTS.length) {
throw new IllegalArgumentException("Name and weight arrays must be of the same length");
}
double totalWeight = 0.0;
for (Double weight : SPLIT_WEIGHTS) {
totalWeight += weight;
if (weight < 0.0) {
throw new IllegalArgumentException("Split weights cannot be negative");
}
}
if (totalWeight <= 0.0) {
throw new IllegalArgumentException("Split weights must total to a positive weight");
}
List<Double> splitWeights = new ArrayList<>();
for (Double weight : SPLIT_WEIGHTS) {
splitWeights.add(weight / totalWeight);
}
logger.info("Splitting into " + splitWeights.size() + " lists with weights " + splitWeights);
if (SEED == 0L) {
SEED = System.nanoTime();
logger.info("Random seed not set by options, using " + SEED);
}View on GitHub (pinned to 1b7edd19c4)