stanfordnlp/CoreNLP · error · java.lang.IllegalArgumentException
This parser does not contain a DVModel reranker
Error message
This parser does not contain a DVModel reranker
What it means
DVParser.getModelFromLexicalizedParser extracts the DVModel from a loaded parser by casting parser.reranker to DVModelReranker; if the reranker is not an instance of DVModelReranker it throws IllegalArgumentException. Only parsers trained with an embedded DV model expose their neural parameters through this method.
Solutions
- Ensure the parser was loaded from a model trained by DVParser with an embedded DVModelReranker
- Check parser.reranker instanceof DVModelReranker before calling the extraction method
- Re-train or re-save the parser with DVParser so the reranker is embedded
Example fix
// before
LexicalizedParser p = LexicalizedParser.loadModel("englishPCFG.ser.gz");
DVModel m = DVParser.getModelFromLexicalizedParser(p); // throws
// after
LexicalizedParser p = LexicalizedParser.loadModel("dvparser.ser.gz");
if (p.reranker instanceof DVModelReranker) {
DVModel m = DVParser.getModelFromLexicalizedParser(p);
} Defensive patterns
Strategy: type-guard
Validate before calling
if (parser == null || !(parser.reranker instanceof DVModelReranker)) {
throw new IllegalArgumentException("Parser must be a DVParser model with embedded DVModelReranker");
} Type guard
boolean hasDvModelReranker(LexicalizedParser p) {
return p != null && p.reranker instanceof DVModelReranker;
} Try / catch
try {
DVModel m = DVParser.getModelFromLexicalizedParser(parser);
} catch (IllegalArgumentException e) {
if (e.getMessage().contains("DVModel reranker")) {
System.err.println("Load a DVParser-trained model, not a plain parser model");
}
} Prevention
- Check reranker type before extracting the DVModel
- Only call this helper on models produced by DVParser training
- Tag model files so plain and DV models are distinguishable in pipelines
When it happens
Trigger: Calling DVParser.getModelFromLexicalizedParser(parser) with a parser loaded from a plain PCFG/factored model file, or a DVParser model whose reranker was replaced/absent.
Common situations: Passing a standard Stanford parser model (englishPCFG.ser.gz) instead of a DVParser-trained model; programmatic pipelines that reassemble LexicalizedParser objects and drop the reranker; old model files predating the reranker field.
Understand the failure class
Background: Type mismatch errors: IllegalArgumentException, TypeError and type guards across 150 open-source libraries — this error's family across 150 libraries.
Related errors
- Expected parsers with DVModel embedded
- format error in embeddings
- format error unexpected featureFactory line:
- Unknown word vector not specified in the word vector file
- Unable to annotate attribute " + key
AI-assisted analysis of stanfordnlp/CoreNLP@1b7edd19c4 (2026-09-10).
Data as JSON: /api/errors/9a2e27290e95c459.
Report an issue: GitHub.
Appendix: source
Thrown at src/edu/stanford/nlp/parser/dvparser/DVParser.java:395
public static DVParser loadModel(String filename, String[] args) {
log.info("Loading serialized model from " + filename);
DVParser dvparser;
try {
dvparser = IOUtils.readObjectFromURLOrClasspathOrFileSystem(filename);
dvparser.op.setOptions(args);
} catch (IOException e) {
throw new RuntimeIOException(e);
} catch (ClassNotFoundException e) {
throw new RuntimeIOException(e);
}
log.info("... done");
return dvparser;
}
public static DVModel getModelFromLexicalizedParser(LexicalizedParser parser) {
if (!(parser.reranker instanceof DVModelReranker)) {
throw new IllegalArgumentException("This parser does not contain a DVModel reranker");
}
DVModelReranker reranker = (DVModelReranker) parser.reranker;
return reranker.getModel();
}
public static void help() {
log.info("Options supplied by this file:");
log.info(" -model <name>: When training, the name of the model to save. Otherwise, the name of the model to load.");
log.info(" -parser <name>: When training, the LexicalizedParser to use as the base model.");
log.info(" -cachedTrees <name>: The name of the file containing a treebank with cached parses. See CacheParseHypotheses.java");
log.info(" -treebank <name> [filter]: A treebank to use instead of cachedTrees. Trees will be reparsed. Slow.");
log.info(" -testTreebank <name> [filter]: A treebank for testing the model.");
log.info(" -train: Run training over the treebank, testing on the testTreebank.");
log.info(" -continueTraining <name>: The name of a file to continue training.");
log.info(" -nofilter: Rules for the parser will not be filtered based on the training treebank.");
log.info(" -runGradientCheck: Run a gradient check.");
log.info(" -resultsRecord: A file for recording info on intermediate results");
log.info();View on GitHub (pinned to 1b7edd19c4)