stanfordnlp/CoreNLP · error · IllegalArgumentException
Need to specify -model
Error message
Need to specify -model
What it means
FindNearestNeighbors locates similar phrase vectors using a trained DVModel, which is only available inside a serialized DVParser model file. main() throws this IllegalArgumentException when -model is absent. It is the first of three mandatory-option checks.
Solutions
- Pass -model <path-to-serialized-DVParser> on the command line
- Verify the file is a DVParser model (saved by DVParser), not a plain LexicalizedParser
- Check flag spelling: it must be exactly -model
Example fix
// before java edu.stanford.nlp.parser.dvparser.FindNearestNeighbors -testTreebank tb -output out.txt // after java edu.stanford.nlp.parser.dvparser.FindNearestNeighbors -model dvparser.ser.gz -testTreebank tb -output out.txt
Defensive patterns
Strategy: validation
Validate before calling
if (!Arrays.asList(args).contains("-model")) {
throw new IllegalArgumentException("FindNearestNeighbors requires -model <serializedDVParser>");
} Try / catch
try {
FindNearestNeighbors.main(args);
} catch (IllegalArgumentException e) {
System.err.println("Missing required option: " + e.getMessage());
} Prevention
- Always pass -model pointing at a DVParser-serialized model
- Use a wrapper script listing all three required flags
- Validate required flags in CI for tool invocations
When it happens
Trigger: Running FindNearestNeighbors.main() without the -model flag, so modelPath stays null after argument parsing.
Common situations: Forgetting that the tool operates on a trained DV model, not a plain parser model; running with only -testTreebank and -output; scripting examples that assumed a default model path.
Understand the failure class
Background: "Must pass :limit option" / "Missing required option" — required option errors explained — this error's family across 41 libraries.
Related errors
- Must specify input with -input
- Must specify output with -output
- -o argument (output path for built tagger) is required
- Must supply either a base parser model with -parser or a…
- Need to either train a new model, run the gradient check or…
AI-assisted analysis of stanfordnlp/CoreNLP@1b7edd19c4 (2026-09-10).
Data as JSON: /api/errors/444001d8e42b1c82.
Report an issue: GitHub.
Appendix: source
Thrown at src/edu/stanford/nlp/parser/dvparser/FindNearestNeighbors.java:88
for (int argIndex = 0; argIndex < args.length; ) {
if (args[argIndex].equalsIgnoreCase("-model")) {
modelPath = args[argIndex + 1];
argIndex += 2;
} else if (args[argIndex].equalsIgnoreCase("-testTreebank")) {
Pair<String, FileFilter> treebankDescription = ArgUtils.getTreebankDescription(args, argIndex, "-testTreebank");
argIndex = argIndex + ArgUtils.numSubArgs(args, argIndex) + 1;
testTreebankPath = treebankDescription.first();
testTreebankFilter = treebankDescription.second();
} else if (args[argIndex].equalsIgnoreCase("-output")) {
outputPath = args[argIndex + 1];
argIndex += 2;
} else {
unusedArgs.add(args[argIndex++]);
}
}
if (modelPath == null) {
throw new IllegalArgumentException("Need to specify -model");
}
if (testTreebankPath == null) {
throw new IllegalArgumentException("Need to specify -testTreebank");
}
if (outputPath == null) {
throw new IllegalArgumentException("Need to specify -output");
}
String[] newArgs = unusedArgs.toArray(new String[unusedArgs.size()]);
LexicalizedParser lexparser = LexicalizedParser.loadModel(modelPath, newArgs);
Treebank testTreebank = null;
if (testTreebankPath != null) {
log.info("Reading in trees from " + testTreebankPath);
if (testTreebankFilter != null) {
log.info("Filtering on " + testTreebankFilter);
}View on GitHub (pinned to 1b7edd19c4)