stanfordnlp/CoreNLP · error · RuntimeException
Error loading word counts
Error message
Error loading word counts
What it means
FeatureExtractor.loadVocabulary loads a word-count file to build a frequency-thresholded vocabulary and wraps any failure in RuntimeException("Error loading word counts"). The word counts resource is required input for statistical/neural coref feature extraction.
Solutions
- Ensure the CoreNLP models jar/file distribution is on the classpath so the default word-counts resource is found
- If you set a custom word-counts path, verify the file exists and is a tab/space-separated word-count file
- Check file permissions
- Inspect e.getCause() to distinguish missing-file from parse errors
Example fix
// before
// models jar missing; default edu/stanford/nlp/models/dcoref/... uncountable
// after
classpath += ":/path/to/stanford-corenlp-<ver>-models.jar" // supplies word counts
// or set explicitly:
props.setProperty("coref.word.counts", "/abs/path/word_counts.txt"); Defensive patterns
Strategy: try-catch
Validate before calling
String countsPath = props.getProperty("coref.word.counts",
"edu/stanford/nlp/models/dcoref/... (default in models jar)");
boolean resolvable = Thread.currentThread().getContextClassLoader()
.getResource(countsPath) != null || new java.io.File(countsPath).canRead();
if (!resolvable) throw new IllegalStateException("Word counts resource not on classpath: " + countsPath); Try / catch
try {
FeatureExtractor fx = new FeatureExtractor(props, dictionaries, compressor);
} catch (RuntimeException e) {
if ("Error loading word counts".equals(e.getMessage()))
throw new IllegalStateException("Word-counts resource missing — install CoreNLP models jar", e);
throw e;
} Prevention
- Always include the stanford-corenlp models jar in the classpath
- Validate custom coref.word.counts paths at startup
- Keep counts file format consistent (word + whitespace + count per line)
- Check e.getCause() to distinguish missing file vs parse error
When it happens
Trigger: Constructing a FeatureExtractor when the word-counts resource (dictionaries.getCounts (coref.word.counts file)) is missing, unreadable, or has an unexpected format so reading/parsing throws.
Common situations: CoreNLP models jar not on the classpath (the default word counts live inside the model distribution); custom word-counts file path wrong; corrupted or wrong-format counts file.
Understand the failure class
Background: "failed to read file", EACCES, ENOENT and "could not read <path>" errors: when a program can't read a file from disk — this error's family across 49 libraries.
Related errors
- RuntimeIOException wrapping IOException
- Couldn't load
- RuntimeException wrapping IOException
- Shouldn't happen:
- Error reading saved links
AI-assisted analysis of stanfordnlp/CoreNLP@1b7edd19c4 (2026-09-10).
Data as JSON: /api/errors/5dc6d1091adbc044.
Report an issue: GitHub.
Appendix: source
Thrown at src/edu/stanford/nlp/coref/statistical/FeatureExtractor.java:97
Compressor<String> compressor, Set<String> vocabulary) {
this.dictionaries = dictionaries;
this.compressor = compressor;
this.vocabulary = vocabulary;
this.useDocSource = CorefProperties.conll(props);
this.useConstituencyParse = CorefProperties.useConstituencyParse(props);
}
private static Set<String> loadVocabulary(String wordCountsPath) {
Set<String> vocabulary = new HashSet<>();
try {
Counter<String> counts = IOUtils.readObjectFromURLOrClasspathOrFileSystem(wordCountsPath);
for (Map.Entry<String, Double> e : counts.entrySet()) {
if (e.getValue() > MIN_WORD_COUNT) {
vocabulary.add(e.getKey());
}
}
} catch (Exception e) {
throw new RuntimeException("Error loading word counts", e);
}
return vocabulary;
}
public DocumentExamples extract(int id, Document document,
Map<Pair<Integer, Integer>, Boolean> labeledPairs) {
return extract(id, document, labeledPairs, compressor);
}
public DocumentExamples extract(int id, Document document,
Map<Pair<Integer, Integer>, Boolean> labeledPairs, Compressor<String> compressor) {
List<Mention> mentionsList = CorefUtils.getSortedMentions(document);
Map<Integer, List<Mention>> mentionsByHeadIndex = new HashMap<>();
for (Mention m : mentionsList) {
List<Mention> withIndex = mentionsByHeadIndex.get(m.headIndex);
if (withIndex == null) {
withIndex = new ArrayList<>();
mentionsByHeadIndex.put(m.headIndex, withIndex);View on GitHub (pinned to 1b7edd19c4)