stanfordnlp/CoreNLP · error · IllegalArgumentException
Must specify a treebank to train from with -trainTreebank…
Error message
Must specify a treebank to train from with -trainTreebank or a parser to load with -serializedPath
What it means
ShiftReduceParser.main is the command-line entry point for training or loading a shift-reduce parser. It requires either a training treebank path (-trainTreebank) to train a new model, or a serialized parser path (-serializedPath) to load an existing one. If neither is given it cannot do anything meaningful and throws IllegalArgumentException.
Solutions
- Pass -trainTreebank <path> to train a new parser from treebank data
- Or pass -serializedPath <model.ser.gz> to load an existing parser
- Verify flag spelling and that your launcher script actually forwards the arguments
Example fix
// before java edu.stanford.nlp.parser.shiftreduce.ShiftReduceParser -trainingMethod BEAM // after java edu.stanford.nlp.parser.shiftreduce.ShiftReduceParser -serializedPath model.ser.gz -testTreebank tests/treebank
Defensive patterns
Strategy: validation
Validate before calling
if (args == null || (Arrays.stream(args).noneMatch(a -> a.startsWith("-trainTreebank"))
&& Arrays.stream(args).noneMatch(a -> a.startsWith("-serializedPath")))) {
throw new IllegalArgumentException("Usage: ShiftReduceParser -trainTreebank <path> | -serializedPath <model>");
} Try / catch
try {
ShiftReduceParser.main(args);
} catch (IllegalArgumentException e) {
log.severe("Usage: must pass -trainTreebank or -serializedPath");
System.exit(2);
} Prevention
- Wrap the CLI in a script that validates required flags
- Watch for flag case-sensitivity typos
- Document both invocation modes (train vs load)
When it happens
Trigger: Running java edu.stanford.nlp.parser.shiftreduce.ShiftReduceParser (or Main) with neither -trainTreebank nor -serializedPath on the command line.
Common situations: Mis-typed CLI flags (e.g. -trainTreeBank with wrong case), an options file whose values weren't passed through, or a script that dropped the model path argument.
Understand the failure class
Background: "missing required argument" and "the following required arguments were not provided": what required-argument errors mean and how to fix them — this error's family across 20 libraries.
Related errors
- Error: -train option must have treebankPath as first…
- No test treebank path specified...
- Both parse.model and parse.executable properties must be…
- Cannot enable POSSequence features without POS sequence…
- Conflicting properties. Multi-word rules file will be…
AI-assisted analysis of stanfordnlp/CoreNLP@1b7edd19c4 (2026-09-10).
Data as JSON: /api/errors/db0962c7033532bb.
Report an issue: GitHub.
Appendix: source
Thrown at src/edu/stanford/nlp/parser/shiftreduce/ShiftReduceParser.java:642
serializedPath = args[argIndex + 1];
argIndex += 2;
} else if (args[argIndex].equalsIgnoreCase("-tlpp")) {
tlppClass = args[argIndex + 1];
argIndex += 2;
} else if (args[argIndex].equalsIgnoreCase("-continueTraining")) {
continueTraining = args[argIndex + 1];
argIndex += 2;
} else {
remainingArgs.add(args[argIndex]);
++argIndex;
}
}
String[] newArgs = new String[remainingArgs.size()];
newArgs = remainingArgs.toArray(newArgs);
if (trainTreebankPath == null && serializedPath == null) {
throw new IllegalArgumentException("Must specify a treebank to train from with -trainTreebank or a parser to load with -serializedPath");
}
ShiftReduceParser parser = null;
if (trainTreebankPath != null) {
log.info("Training ShiftReduceParser");
log.info("Initial arguments:");
log.info(" " + StringUtils.join(args));
if (continueTraining != null) {
parser = ShiftReduceParser.loadModel(continueTraining, ArrayUtils.concatenate(BASIC_TRAINING_OPTIONS, newArgs));
} else {
ShiftReduceOptions op = buildTrainingOptions(tlppClass, newArgs);
parser = new ShiftReduceParser(op);
}
Timing trainingTimer = new Timing();
parser.train(trainTreebankPath, devTreebankPath, serializedPath);
trainingTimer.done("Overall training process");
parser.saveModel(serializedPath);View on GitHub (pinned to 1b7edd19c4)