stanfordnlp/CoreNLP · error · java.lang.IllegalArgumentException

Must supply either a base parser model with -parser or a…

Error message

Must supply either a base parser model with -parser or a serialized DVParser with -model

What it means

DVParser's main() requires a starting point: either a base LexicalizedParser model via -parser or a previously serialized DVParser via -model. When neither path is set after argument parsing, it throws this IllegalArgumentException. This is an upfront configuration sanity check before any training or parsing work begins.

Solutions

  1. Pass -parser <path-to-LexicalizedParser-model.gz> to start from a base parser for training
  2. Or pass -model <path-to-serialized-DVParser> to load an existing DVParser
  3. Run java edu.stanford.nlp.parser.dvparser.DVParser -help or read the source argument loop to confirm flag names

Example fix

// before
java edu.stanford.nlp.parser.dvparser.DVParser -train trainTreebank.gz
// after
java edu.stanford.nlp.parser.dvparser.DVParser -parser englishPCFG.ser.gz -train trainTreebank.gz
Defensive patterns

Strategy: validation

Validate before calling

if (parserPath == null && modelPath == null) {
  throw new IllegalArgumentException("Supply -parser <baseParserModel> or -model <serializedDVParser>");
}

Try / catch

try {
  DVParser.main(args);
} catch (IllegalArgumentException e) {
  System.err.println("Missing model args: " + e.getMessage());
}

Prevention

When it happens

Trigger: Running DVParser.main() with neither the -parser flag nor the -model flag supplied (parserPath == null && modelPath == null after the argument loop).

Common situations: Invoking the class from the command line with only training flags like -trainTreebank but forgetting -parser; copying an example command and dropping the required model argument; scripting the tool without knowing the two entry points.

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


AI-assisted analysis of stanfordnlp/CoreNLP@1b7edd19c4 (2026-09-10). Data as JSON: /api/errors/63dcb340a1ff36d4. Report an issue: GitHub.

Appendix: source

Thrown at src/edu/stanford/nlp/parser/dvparser/DVParser.java:551

        argIndex += 2;
      } else if (args[argIndex].equalsIgnoreCase("-nofilter")) {
        filter = false;
        argIndex++;
      } else if (args[argIndex].equalsIgnoreCase("-continueTraining")) {
        runTraining = true;
        filter = false;
        initialModelPath = args[argIndex + 1];
        argIndex += 2;
      } else if (args[argIndex].equalsIgnoreCase("-resultsRecord")) {
        resultsRecordPath = args[argIndex + 1];
        argIndex += 2;
      } else {
        unusedArgs.add(args[argIndex++]);
      }
    }

    if (parserPath == null && modelPath == null) {
      throw new IllegalArgumentException("Must supply either a base parser model with -parser or a serialized DVParser with -model");
    }

    if (!runTraining && modelPath == null && !runGradientCheck) {
      throw new IllegalArgumentException("Need to either train a new model, run the gradient check or specify a model to load with -model");
    }

    String[] newArgs = unusedArgs.toArray(new String[unusedArgs.size()]);
    DVParser dvparser = null;
    LexicalizedParser lexparser = null;
    if (initialModelPath != null) {
      lexparser = LexicalizedParser.loadModel(initialModelPath, newArgs);
      DVModel model = getModelFromLexicalizedParser(lexparser);
      dvparser = new DVParser(model, lexparser);
    } else if (runTraining || runGradientCheck) {
      lexparser = LexicalizedParser.loadModel(parserPath, newArgs);
      dvparser = new DVParser(lexparser);
    } else if (modelPath != null) {
      lexparser = LexicalizedParser.loadModel(modelPath, newArgs);

View on GitHub (pinned to 1b7edd19c4)