stanfordnlp/CoreNLP · error · java.lang.IllegalArgumentException

Need to supply a parser model with -model

Error message

Need to supply a parser model with -model

What it means

CacheParseHypotheses.main validates required CLI arguments after parsing and throws IllegalArgumentException if the parser model path was never supplied. The -model flag is mandatory because the tool needs a serialized DVParser to extract hypothesis trees from. It is a fail-fast guard against running with an incomplete command line.

Solutions

  1. Add -model /path/to/parser.ser.gz to the command line
  2. Verify the flag spelling matches -model exactly
  3. Run without arguments or read the usage/help output to confirm required flags

Example fix

// before
java edu.stanford.nlp.parser.dvparser.CacheParseHypotheses -output out.txt -treebank treebank
// after
java edu.stanford.nlp.parser.dvparser.CacheParseHypotheses -model parser.ser.gz -output out.txt -treebank treebank
Defensive patterns

Strategy: validation

Validate before calling

List<String> args = Arrays.asList(cmdArgs);
if (!args.contains("-model")) {
    throw new IllegalArgumentException("CacheParseHypotheses requires -model <parserModel>");
}

Try / catch

try {
    CacheParseHypotheses.main(args);
} catch (IllegalArgumentException e) {
    if (e.getMessage().contains("-model")) {
        System.err.println("Usage: add -model /path/to/parser.ser.gz");
    }
}

Prevention

When it happens

Trigger: Running CacheParseHypotheses from the command line without passing -model <path>, or passing the flag with a typo (e.g. -models) so the parsed parserModel field stays null.

Common situations: Copy-pasting an example command and dropping the -model option; scripting the tool and forgetting to interpolate the model path variable; confusing this tool's flag names with those of other dvparser tools.

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/289df2ca5d5c275e. Report an issue: GitHub.

Appendix: source

Thrown at src/edu/stanford/nlp/parser/dvparser/CacheParseHypotheses.java:233

        argIndex += 2;
        continue;
      }
      if (args[argIndex].equalsIgnoreCase("-treebank")) {
        Pair<String, FileFilter> treebankDescription = ArgUtils.getTreebankDescription(args, argIndex, "-treebank");
        argIndex = argIndex + ArgUtils.numSubArgs(args, argIndex) + 1;
        treebanks.add(treebankDescription);
        continue;
      }
      if (args[argIndex].equalsIgnoreCase("-numThreads")) {
        numThreads = Integer.parseInt(args[argIndex + 1]);
        argIndex += 2;
        continue;
      }
      throw new IllegalArgumentException("Unknown argument " + args[argIndex]);
    }

    if (parserModel == null) {
      throw new IllegalArgumentException("Need to supply a parser model with -model");
    }
    if (output == null) {
      throw new IllegalArgumentException("Need to supply an output filename with -output");
    }
    if (treebanks.isEmpty()) {
      throw new IllegalArgumentException("Need to supply a treebank with -treebank");
    }

    log.info("Writing output to " + output);
    log.info("Loading parser model " + parserModel);
    log.info("Writing " + dvKBest + " hypothesis trees for each tree");

    LexicalizedParser parser = LexicalizedParser.loadModel(parserModel, "-dvKBest", Integer.toString(dvKBest));
    CacheParseHypotheses cacher = new CacheParseHypotheses(parser);
    TreeTransformer transformer = DVParser.buildTrainTransformer(parser.getOp());
    List<Tree> sentences = new ArrayList<>();
    for (Pair<String, FileFilter> description : treebanks) {
      log.info("Reading trees from " + description.first);

View on GitHub (pinned to 1b7edd19c4)