stanfordnlp/CoreNLP · error · IllegalArgumentException
Expected a DVModelReranker
Error message
Expected a DVModelReranker
What it means
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.
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
Example fix
// before java edu.stanford.nlp.parser.dvparser.ParseAndPrintMatrices -model parser.ser.gz // after java edu.stanford.nlp.parser.dvparser.ParseAndPrintMatrices -model parser.ser.gz -dvModel dvmodel.ser.gz
Defensive patterns
Strategy: type-guard
Validate before calling
RerankerQuery rq = rpq.rerankerQuery();
if (!(rq instanceof DVModelReranker.Query)) {
throw new IllegalStateException("Model was not built with DVModelReranker; re-load with -dvModel");
} Type guard
function isDVModelRerankerQuery(rq) { return rq instanceof DVModelReranker.Query; } Try / catch
try {
RerankerQuery reranker = rpq.rerankerQuery();
if (!(reranker instanceof DVModelReranker.Query)) {
log.warning("skipping matrix dump: reranker is " + reranker.getClass().getName());
return;
}
} catch (IllegalArgumentException e) {
log.severe("DV reranker required: " + e.getMessage());
} Prevention
- 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
When it happens
Trigger: 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.
Common situations: 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.
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 a LexicalizedParser with a Reranker attached
- Expected a LexicalizedParser with a DVModel attached
- Expected a RerankingParserQuery
- addFeature was called with a features object that is…
- Unexpected node class
AI-assisted analysis of stanfordnlp/CoreNLP@1b7edd19c4 (2026-09-10).
Data as JSON: /api/errors/4088656805c4cd13.
Report an issue: GitHub.
Appendix: source
Thrown at src/edu/stanford/nlp/parser/dvparser/ParseAndPrintMatrices.java:120
FileSystem.mkdirOrFail(outputFile);
int count = 0;
if (inputPath != null) {
Reader input = new BufferedReader(new FileReader(inputPath));
DocumentPreprocessor processor = new DocumentPreprocessor(input);
for (List<HasWord> sentence : processor) {
count++; // index from 1
ParserQuery pq = parser.parserQuery();
if (!(pq instanceof RerankingParserQuery)) {
throw new IllegalArgumentException("Expected a RerankingParserQuery");
}
RerankingParserQuery rpq = (RerankingParserQuery) pq;
if (!rpq.parse(sentence)) {
throw new RuntimeException("Unparsable sentence: " + sentence);
}
RerankerQuery reranker = rpq.rerankerQuery();
if (!(reranker instanceof DVModelReranker.Query)) {
throw new IllegalArgumentException("Expected a DVModelReranker");
}
DeepTree deepTree = ((DVModelReranker.Query) reranker).getDeepTrees().get(0);
IdentityHashMap<Tree, SimpleMatrix> vectors = deepTree.getVectors();
for (Map.Entry<Tree, SimpleMatrix> entry : vectors.entrySet()) {
log.info(entry.getKey() + " " + entry.getValue());
}
FileWriter fout = new FileWriter(outputPath + File.separator + "sentence" + count + ".txt");
BufferedWriter bout = new BufferedWriter(fout);
bout.write(SentenceUtils.listToString(sentence));
bout.newLine();
bout.write(deepTree.getTree().toString());
bout.newLine();
for (HasWord word : sentence) {
outputMatrix(bout, model.getWordVector(word.word()));View on GitHub (pinned to 1b7edd19c4)