stanfordnlp/CoreNLP · error · IllegalArgumentException
Name and weight arrays must be of the same length
Error message
Name and weight arrays must be of the same length
What it means
SplitTrainingSet splits a treebank into named subsets by weights; it validates that the SPLIT_NAMES and SPLIT_WEIGHTS option arrays have equal length. When the number of split names differs from the number of weights, main throws this IllegalArgumentException at startup.
Solutions
- Make splitNames and splitWeights contain the same number of comma-separated elements in the properties passed via -splitNames/-splitWeights.
- Check for stray or missing commas that shift element counts.
- Add an explicit weight for each named split (weights need not sum to 1 but must be positive in total).
Example fix
// before -splitNames train,dev,test -splitWeights 0.8,0.2 // after -splitNames train,dev,test -splitWeights 0.8,0.1,0.1
Defensive patterns
Strategy: validation
Validate before calling
String[] names = props.getProperty("splitNames", "").split(",");
double[] ws = Arrays.stream(props.getProperty("splitWeights", "").split(","))
.mapToDouble(Double::parseDouble).toArray();
if (names.length != ws.length)
throw new IllegalArgumentException("splitNames and splitWeights must have equal counts"); Try / catch
try {
SplitTrainingSet.main(args);
} catch (IllegalArgumentException e) {
if (e.getMessage() != null && e.getMessage().contains("same length")) {
log.error("Config error: provide one weight per split name");
} else throw e;
} Prevention
- Keep split names and weights defined together in one config block so they stay in sync.
- Count entries after comma-splitting when editing properties files.
- Add a smoke test that builds the options and calls the validation path.
When it happens
Trigger: Invoking SplitTrainingSet.main (or filling its options) with properties where splitNames and splitWeights have different cardinalities — e.g. three names but two weights, or a weight string with a malformed/dropped element after comma splitting.
Common situations: Editing a properties/config file and adding a split name without adding its weight (or vice versa); trailing/extra commas producing an empty name entry; programmatically building the arrays with unequal lengths.
Understand the failure class
Background: "Must be a positive integer", "Invalid value", "Unsupported": the invalid-argument-value error family, when a library rejects the value you pass — this error's family across 35 libraries.
Related errors
- Split weights cannot be negative
- 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/763367c71e2221f3.
Report an issue: GitHub.
Appendix: source
Thrown at src/edu/stanford/nlp/trees/SplitTrainingSet.java:68
int index = 0;
for (Double weight : weights) {
offset = offset - weight;
if (offset < 0.0) {
return index;
}
index = index + 1;
}
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);
}View on GitHub (pinned to 1b7edd19c4)