stanfordnlp/CoreNLP · error · java.lang.IllegalArgumentException

Need to either train a new model, run the gradient check or…

Error message

Need to either train a new model, run the gradient check or specify a model to load with -model

What it means

After validating a model source exists, DVParser.main() checks what work it should do: train a new model, run a gradient check, or load a serialized model. If runTraining is false, no -model is given, and runGradientCheck is false, there is nothing to do, so it throws. It prevents a silent no-op run.

Solutions

  1. Add -model <path> to load and use an existing serialized DVParser
  2. Add the training flag (e.g. -trainTreebank with training data) to enable runTraining
  3. Add -gradientCheck (with the required -parser model) if you intend to run the gradient check

Example fix

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

Strategy: validation

Validate before calling

boolean hasMode = runTraining || runGradientCheck || modelPath != null;
if (!hasMode) {
  throw new IllegalArgumentException("Set a mode: train (-trainTreebank), -gradientCheck, or -model");
}

Try / catch

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

Prevention

When it happens

Trigger: Running DVParser.main() without -trainingThreads... specifically without flags that set runTraining or runGradientCheck to true, and without -model, e.g. only passing -parser plus unused args.

Common situations: Supplying -parser alone expecting the parser to just parse text (DVParser's main is for training/checking, not parsing); typo-ing -trainingInput... misspelling a mode flag so it lands in unusedArgs and no mode is activated.

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/68a14e3219ded253. Report an issue: GitHub.

Appendix: source

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

      } 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);
      DVModel model = getModelFromLexicalizedParser(lexparser);
      dvparser = new DVParser(model, lexparser);
    }

View on GitHub (pinned to 1b7edd19c4)