stanfordnlp/CoreNLP · error · java.lang.IllegalArgumentException

Need to specify -model to load an already prepared…

Error message

Need to specify -model to load an already prepared CombinedParser

What it means

CombineDVModels supports two modes: combine base models and save a combined parser (-model output path), or load an already prepared combined parser (-loadModel). If neither combine mode ran (no -baseModels given) and no -loadModel path was supplied, it throws IllegalArgumentException because there is no -model to load the CombinedParser from.

Solutions

  1. When combining: pass both -baseModels <paths> and -model <output path>
  2. When loading a prepared combined parser: pass -loadModel /path/to/combined.ser.gz (with -model naming it, per this branch's contract) instead of running in combine mode
  3. Review the tool's usage to pick the correct mode before invoking

Example fix

// before
java ... CombineDVModels -testTreebank wsj-test.txt
// after
java ... CombineDVModels -loadModel combined.ser.gz -testTreebank wsj-test.txt
Defensive patterns

Strategy: validation

Validate before calling

boolean hasBaseModels = Arrays.asList(cmdArgs).contains("-baseModels");
boolean hasLoadModel = Arrays.asList(cmdArgs).contains("-loadModel");
if (!hasBaseModels && !hasLoadModel) {
    throw new IllegalArgumentException("CombineDVModels needs -baseModels (combine mode) or -loadModel (load mode)");
}

Try / catch

try {
    CombineDVModels.main(args);
} catch (IllegalArgumentException e) {
    if (e.getMessage().contains("-model to load")) {
        System.err.println("Use -loadModel combined.ser.gz to evaluate an existing CombinedParser");
    }
}

Prevention

When it happens

Trigger: Running CombineDVModels without -baseModels and without -loadModel, so the code reaches the else branch expecting modelPath to name an existing CombinedParser to load; or supplying only -model for output in a context where no combination was performed.

Common situations: Misunderstanding the tool's dual mode: -model is an output when combining but a required input when loading; forgetting -loadModel when the intent was to evaluate an existing combined parser.

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/6f65ec63cea60ea6. Report an issue: GitHub.

Appendix: source

Thrown at src/edu/stanford/nlp/parser/dvparser/CombineDVModels.java:91

        Reranker reranker = dvparser.reranker;
        if (!(reranker instanceof DVModelReranker)) {
          throw new IllegalArgumentException("Expected parsers with DVModel embedded");
        }
        dvparsers.add(((DVModelReranker) reranker).getModel());
        if (underlyingParser == null) {
          underlyingParser = dvparser;
          options = underlyingParser.getOp();
          // TODO: other parser's options?
          options.setOptions(newArgs);
        }
        log.info("... done");
      }
      combinedParser = LexicalizedParser.copyLexicalizedParser(underlyingParser);
      CombinedDVModelReranker reranker = new CombinedDVModelReranker(options, dvparsers);
      combinedParser.reranker = reranker;
      combinedParser.saveParserToSerialized(modelPath);
    } else {
      throw new IllegalArgumentException("Need to specify -model to load an already prepared CombinedParser");
    }

    Treebank testTreebank = null;
    if (testTreebankPath != null) {
      log.info("Reading in trees from " + testTreebankPath);
      if (testTreebankFilter != null) {
        log.info("Filtering on " + testTreebankFilter);
      }
      testTreebank = combinedParser.getOp().tlpParams.memoryTreebank();;
      testTreebank.loadPath(testTreebankPath, testTreebankFilter);
      log.info("Read in " + testTreebank.size() + " trees for testing");

      EvaluateTreebank evaluator = new EvaluateTreebank(combinedParser.getOp(), null, combinedParser);
      evaluator.testOnTreebank(testTreebank);
    }
  }
}

View on GitHub (pinned to 1b7edd19c4)