{"record":{"id":"9a2e27290e95c459","repo":"stanfordnlp/CoreNLP","slug":"this-parser-does-not-contain-a-dvmodel-reranker","errorCode":null,"errorMessage":"This parser does not contain a DVModel reranker","messagePattern":"This parser does not contain a DVModel reranker","errorType":"exception","errorClass":"java.lang.IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"src/edu/stanford/nlp/parser/dvparser/DVParser.java","lineNumber":395,"sourceCode":"\n  public static DVParser loadModel(String filename, String[] args) {\n    log.info(\"Loading serialized model from \" + filename);\n    DVParser dvparser;\n    try {\n      dvparser = IOUtils.readObjectFromURLOrClasspathOrFileSystem(filename);\n      dvparser.op.setOptions(args);\n    } catch (IOException e) {\n      throw new RuntimeIOException(e);\n    } catch (ClassNotFoundException e) {\n      throw new RuntimeIOException(e);\n    }\n    log.info(\"... done\");\n    return dvparser;\n  }\n\n  public static DVModel getModelFromLexicalizedParser(LexicalizedParser parser) {\n    if (!(parser.reranker instanceof DVModelReranker)) {\n      throw new IllegalArgumentException(\"This parser does not contain a DVModel reranker\");\n    }\n    DVModelReranker reranker = (DVModelReranker) parser.reranker;\n    return reranker.getModel();\n  }\n\n  public static void help() {\n    log.info(\"Options supplied by this file:\");\n    log.info(\"  -model <name>: When training, the name of the model to save.  Otherwise, the name of the model to load.\");\n    log.info(\"  -parser <name>: When training, the LexicalizedParser to use as the base model.\");\n    log.info(\"  -cachedTrees <name>: The name of the file containing a treebank with cached parses.  See CacheParseHypotheses.java\");\n    log.info(\"  -treebank <name> [filter]: A treebank to use instead of cachedTrees.  Trees will be reparsed.  Slow.\");\n    log.info(\"  -testTreebank <name> [filter]: A treebank for testing the model.\");\n    log.info(\"  -train: Run training over the treebank, testing on the testTreebank.\");\n    log.info(\"  -continueTraining <name>: The name of a file to continue training.\");\n    log.info(\"  -nofilter: Rules for the parser will not be filtered based on the training treebank.\");\n    log.info(\"  -runGradientCheck: Run a gradient check.\");\n    log.info(\"  -resultsRecord: A file for recording info on intermediate results\");\n    log.info();","sourceCodeStart":377,"sourceCodeEnd":413,"githubUrl":"https://github.com/stanfordnlp/CoreNLP/blob/1b7edd19c4d0d7b1f13a2591425b9b60a0b1af7a/src/edu/stanford/nlp/parser/dvparser/DVParser.java#L377-L413","documentation":"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.","triggerScenarios":"Calling DVParser.getModelFromLexicalizedParser(parser) with a parser loaded from a plain PCFG/factored model file, or a DVParser model whose reranker was replaced/absent.","commonSituations":"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.","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"],"exampleFix":"// before\nLexicalizedParser p = LexicalizedParser.loadModel(\"englishPCFG.ser.gz\");\nDVModel m = DVParser.getModelFromLexicalizedParser(p); // throws\n// after\nLexicalizedParser p = LexicalizedParser.loadModel(\"dvparser.ser.gz\");\nif (p.reranker instanceof DVModelReranker) {\n  DVModel m = DVParser.getModelFromLexicalizedParser(p);\n}","handlingStrategy":"type-guard","validationCode":"if (parser == null || !(parser.reranker instanceof DVModelReranker)) {\n    throw new IllegalArgumentException(\"Parser must be a DVParser model with embedded DVModelReranker\");\n}","typeGuard":"boolean hasDvModelReranker(LexicalizedParser p) {\n    return p != null && p.reranker instanceof DVModelReranker;\n}","tryCatchPattern":"try {\n    DVModel m = DVParser.getModelFromLexicalizedParser(parser);\n} catch (IllegalArgumentException e) {\n    if (e.getMessage().contains(\"DVModel reranker\")) {\n        System.err.println(\"Load a DVParser-trained model, not a plain parser model\");\n    }\n}","preventionTips":["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"],"tags":["type-mismatch","model-loading","stanford-corenlp"],"backgroundTag":"type-mismatch","analyzedSha":"1b7edd19c4d0d7b1f13a2591425b9b60a0b1af7a","analyzedAt":"2026-09-10T02:24:07.274Z","contentChangedAt":"2026-09-10T02:24:07.274Z","schemaVersion":2},"datasetVersion":"2026-09-15T23:17:13.987Z"}