{"record":{"id":"1d55b62e9d279d13","repo":"stanfordnlp/CoreNLP","slug":"expected-a-lexicalizedparser-with-a-dvmodel-attach","errorCode":null,"errorMessage":"Expected a LexicalizedParser with a DVModel attached","messagePattern":"Expected a LexicalizedParser with a DVModel attached","errorType":"exception","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"src/edu/stanford/nlp/parser/dvparser/FindNearestNeighbors.java","lineNumber":129,"sourceCode":"\n    FileWriter out = new FileWriter(outputPath);\n    BufferedWriter bout = new BufferedWriter(out);\n\n    log.info(\"Parsing \" + testTreebank.size() + \" trees\");\n    int count = 0;\n    List<ParseRecord> records = Generics.newArrayList();\n    for (Tree goldTree : testTreebank) {\n      List<Word> tokens = goldTree.yieldWords();\n      ParserQuery parserQuery = lexparser.parserQuery();\n      if (!parserQuery.parse(tokens)) {\n        throw new AssertionError(\"Could not parse: \" + tokens);\n      }\n      if (!(parserQuery instanceof RerankingParserQuery)) {\n        throw new IllegalArgumentException(\"Expected a LexicalizedParser with a Reranker attached\");\n      }\n      RerankingParserQuery rpq = (RerankingParserQuery) parserQuery;\n      if (!(rpq.rerankerQuery() instanceof DVModelReranker.Query)) {\n        throw new IllegalArgumentException(\"Expected a LexicalizedParser with a DVModel attached\");\n      }\n      DeepTree tree = ((DVModelReranker.Query) rpq.rerankerQuery()).getDeepTrees().get(0);\n\n      SimpleMatrix rootVector = null;\n      for (Map.Entry<Tree, SimpleMatrix> entry : tree.getVectors().entrySet()) {\n        if (entry.getKey().label().value().equals(\"ROOT\")) {\n          rootVector = entry.getValue();\n          break;\n        }\n      }\n      if (rootVector == null) {\n        throw new AssertionError(\"Could not find root nodevector\");\n      }\n      out.write(tokens + \"\\n\");\n      out.write(tree.getTree() + \"\\n\");\n      for (int i = 0; i < rootVector.getNumElements(); ++i) {\n        out.write(\"  \" + rootVector.get(i));\n      }","sourceCodeStart":111,"sourceCodeEnd":147,"githubUrl":"https://github.com/stanfordnlp/CoreNLP/blob/1b7edd19c4d0d7b1f13a2591425b9b60a0b1af7a/src/edu/stanford/nlp/parser/dvparser/FindNearestNeighbors.java#L111-L147","documentation":"Even with a RerankingParserQuery, FindNearestNeighbors specifically requires the reranker to be a DVModelReranker.Query so it can call getDeepTrees(). If the rerankerQuery is some other Reranker implementation, this IllegalArgumentException is thrown. It indicates the attached reranker is not the DV model reranker.","triggerScenarios":"Parsing succeeds and parserQuery is RerankingParserQuery, but rpq.rerankerQuery() is not an instance of DVModelReranker.Query — e.g. a different Reranker was attached via options or the model lacks DV vectors.","commonSituations":"Loading a model trained with a custom/other reranker; options passed to loadModel that override the reranker; mixing model files so the reranker options point at the wrong model.","solutions":["Load the DVParser model saved with a DVModelReranker so the query type matches","Do not pass flags that replace the reranker in newArgs to loadModel","Retrain/save via DVParser if the model was produced by another pipeline"],"exampleFix":"// before\nLexicalizedParser.loadModel(\"someOtherRerankerModel.ser.gz\");\n// after\nLexicalizedParser.loadModel(\"dvparserWithDVModel.ser.gz\", newArgs); // model with DVModelReranker","handlingStrategy":"type-guard","validationCode":"RerankingParserQuery rpq = (RerankingParserQuery) parserQuery;\nif (!(rpq.rerankerQuery() instanceof DVModelReranker.Query)) {\n  throw new IllegalStateException(\"Attached reranker is not DVModelReranker; reload with a DV model\");\n}","typeGuard":"boolean isDvModelRerankerQuery(ParserQuery pq) {\n  return pq instanceof RerankingParserQuery\n      && ((RerankingParserQuery) pq).rerankerQuery() instanceof DVModelReranker.Query;\n}","tryCatchPattern":"try {\n  DeepTree tree = ((DVModelReranker.Query) rpq.rerankerQuery()).getDeepTrees().get(0);\n} catch (IllegalArgumentException e) {\n  System.err.println(\"Non-DV reranker attached: \" + e.getMessage());\n}","preventionTips":["Ensure the model file embeds DVModelReranker options","Do not override reranker flags when loading the model","Verify reranker type once at startup, not per sentence"],"tags":["java","dvparser","type-mismatch","reranker"],"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"}