stanfordnlp/CoreNLP · error · RuntimeException
Unparsable sentence:
Error message
Unparsable sentence:
What it means
When the reranking parser fails to find a parse for a sentence, ParseAndPrintMatrices.main() throws RuntimeException("Unparsable sentence: ...") including the token list. With no parse produced there are no deep trees or matrices to print, so the tool aborts that run.
Solutions
- Wrap rpq.parse in a try/catch or check the boolean and skip/log unparsable sentences instead of letting main throw
- Pre-filter sentences: length limits, strip noise, ensure non-empty token lists
- Increase parser limits (e.g. maximum sentence length / beam size options) for long sentences
Example fix
// before
if (!rpq.parse(sentence)) {
throw new RuntimeException("Unparsable sentence: " + sentence);
}
// after
if (!rpq.parse(sentence)) {
System.err.println("Skipping unparsable sentence: " + sentence);
continue;
} Defensive patterns
Strategy: try-catch
Validate before calling
List<HasWord> tokens = sentence;
if (tokens.isEmpty() || tokens.size() > maxSentenceLength) {
continue; // skip sentences the parser cannot handle
} Try / catch
if (!rpq.parse(sentence)) {
System.err.println("Skipping unparsable sentence: " + sentence);
continue;
}
// or wrap the whole loop:
try {
processAllSentences();
} catch (RuntimeException e) {
if (e.getMessage().startsWith("Unparsable sentence")) { logAndSkip(e); } else { throw e; }
} Prevention
- Pre-filter input: remove empty/overly long lines and non-text noise
- Log skipped sentences instead of aborting the batch
- Tune parser limits (length, beam) for your data domain
- Run a small sample of the input through the parser first
When it happens
Trigger: rpq.parse(sentence) returns false inside the DocumentPreprocessor loop — typically sentences that exceed parser length/beam limits, contain only punctuation or unknown tokens, or are malformed input text in the input file.
Common situations: Feeding long sentences or noisy text (web data, OCR output) to the parser; empty lines producing degenerate token lists; unusually low nThreads/beam settings causing parse failures.
Understand the failure class
Background: 'Something went wrong' / 'Request failed (500)' / 'HTTP error! status: 404' — what failed HTTP requests actually mean and how to find the real cause — this error's family across 28 libraries.
Related errors
- Bad data format:
- Bad number put into wordToNumber. Word is: \"" + input +…
- Error in wordToNumber function.
- Bad number put into wordToNumber. Word is: \"" + curPart +…
- format error
AI-assisted analysis of stanfordnlp/CoreNLP@1b7edd19c4 (2026-09-10).
Data as JSON: /api/errors/9a1b558760af0539.
Report an issue: GitHub.
Appendix: source
Thrown at src/edu/stanford/nlp/parser/dvparser/ParseAndPrintMatrices.java:116
DVModel model = DVParser.getModelFromLexicalizedParser(parser);
File outputFile = new File(outputPath);
FileSystem.checkNotExistsOrFail(outputFile);
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());View on GitHub (pinned to 1b7edd19c4)