{"record":{"id":"4088656805c4cd13","repo":"stanfordnlp/CoreNLP","slug":"expected-a-dvmodelreranker","errorCode":null,"errorMessage":"Expected a DVModelReranker","messagePattern":"Expected a DVModelReranker","errorType":"exception","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"src/edu/stanford/nlp/parser/dvparser/ParseAndPrintMatrices.java","lineNumber":120,"sourceCode":"    FileSystem.mkdirOrFail(outputFile);\n\n    int count = 0;\n    if (inputPath != null) {\n      Reader input = new BufferedReader(new FileReader(inputPath));\n      DocumentPreprocessor processor = new DocumentPreprocessor(input);\n      for (List<HasWord> sentence : processor) {\n        count++; // index from 1\n        ParserQuery pq = parser.parserQuery();\n        if (!(pq instanceof RerankingParserQuery)) {\n          throw new IllegalArgumentException(\"Expected a RerankingParserQuery\");\n        }\n        RerankingParserQuery rpq = (RerankingParserQuery) pq;\n        if (!rpq.parse(sentence)) {\n          throw new RuntimeException(\"Unparsable sentence: \" + sentence);\n        }\n        RerankerQuery reranker = rpq.rerankerQuery();\n        if (!(reranker instanceof DVModelReranker.Query)) {\n          throw new IllegalArgumentException(\"Expected a DVModelReranker\");\n        }\n        DeepTree deepTree = ((DVModelReranker.Query) reranker).getDeepTrees().get(0);\n        IdentityHashMap<Tree, SimpleMatrix> vectors = deepTree.getVectors();\n\n        for (Map.Entry<Tree, SimpleMatrix> entry : vectors.entrySet()) {\n          log.info(entry.getKey() + \"   \" +  entry.getValue());\n        }\n\n        FileWriter fout = new FileWriter(outputPath + File.separator + \"sentence\" + count + \".txt\");\n        BufferedWriter bout = new BufferedWriter(fout);\n\n        bout.write(SentenceUtils.listToString(sentence));\n        bout.newLine();\n        bout.write(deepTree.getTree().toString());\n        bout.newLine();\n\n        for (HasWord word : sentence) {\n          outputMatrix(bout, model.getWordVector(word.word()));","sourceCodeStart":102,"sourceCodeEnd":138,"githubUrl":"https://github.com/stanfordnlp/CoreNLP/blob/1b7edd19c4d0d7b1f13a2591425b9b60a0b1af7a/src/edu/stanford/nlp/parser/dvparser/ParseAndPrintMatrices.java#L102-L138","documentation":"ParseAndPrintMatrices re-ranks a parsed sentence and expects the parser query's reranker to be a DVModelReranker.Query so it can extract deep per-tree vectors. The generic RerankerQuery returned by RerankingParserQuery is type-checked with instanceof; any other reranker implementation means the tool cannot access DeepTree vectors, so it throws IllegalArgumentException.","triggerScenarios":"Running ParseAndPrintMatrices with a parser model whose reranker is not a DVModelReranker — e.g. a model saved with TaggerReranker (AddTaggerToParser) or no neural reranker at all, so rpq.rerankerQuery() returns a different RerankerQuery implementation.","commonSituations":"Users point the tool at a serialized parser trained or post-processed with a non-DV reranker, or at a parser loaded without -dvModel specified, so the cast precondition fails.","solutions":["Load a parser model that was built with a DVModelReranker (pass -dvModel / train with the DV model options)","Check the model's options: reranker must be DVModelReranker, not TaggerReranker or another Reranker","If you only need parse output, use a different tool that does not require deep trees"],"exampleFix":"// before\njava edu.stanford.nlp.parser.dvparser.ParseAndPrintMatrices -model parser.ser.gz\n// after\njava edu.stanford.nlp.parser.dvparser.ParseAndPrintMatrices -model parser.ser.gz -dvModel dvmodel.ser.gz","handlingStrategy":"type-guard","validationCode":"RerankerQuery rq = rpq.rerankerQuery();\nif (!(rq instanceof DVModelReranker.Query)) {\n  throw new IllegalStateException(\"Model was not built with DVModelReranker; re-load with -dvModel\");\n}","typeGuard":"function isDVModelRerankerQuery(rq) { return rq instanceof DVModelReranker.Query; }","tryCatchPattern":"try {\n  RerankerQuery reranker = rpq.rerankerQuery();\n  if (!(reranker instanceof DVModelReranker.Query)) {\n    log.warning(\"skipping matrix dump: reranker is \" + reranker.getClass().getName());\n    return;\n  }\n} catch (IllegalArgumentException e) {\n  log.severe(\"DV reranker required: \" + e.getMessage());\n}","preventionTips":["Verify the serialized model's options show a DVModelReranker before running DV-specific tools","Always pass -dvModel when loading models for dvparser tooling","Keep parser-training flags and analysis tools paired with the same model type"],"tags":["java","stanford-parser","dvparser","type-mismatch"],"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"}