{"record":{"id":"5dc6d1091adbc044","repo":"stanfordnlp/CoreNLP","slug":"error-loading-word-counts","errorCode":null,"errorMessage":"Error loading word counts","messagePattern":"Error loading word counts","errorType":"exception","errorClass":"RuntimeException","httpStatus":null,"severity":"error","filePath":"src/edu/stanford/nlp/coref/statistical/FeatureExtractor.java","lineNumber":97,"sourceCode":"      Compressor<String> compressor, Set<String> vocabulary) {\n    this.dictionaries = dictionaries;\n    this.compressor = compressor;\n    this.vocabulary = vocabulary;\n    this.useDocSource = CorefProperties.conll(props);\n    this.useConstituencyParse = CorefProperties.useConstituencyParse(props);\n  }\n\n  private static Set<String> loadVocabulary(String wordCountsPath) {\n    Set<String> vocabulary = new HashSet<>();\n    try {\n      Counter<String> counts = IOUtils.readObjectFromURLOrClasspathOrFileSystem(wordCountsPath);\n      for (Map.Entry<String, Double> e : counts.entrySet()) {\n        if (e.getValue() > MIN_WORD_COUNT) {\n          vocabulary.add(e.getKey());\n        }\n      }\n    } catch (Exception e) {\n      throw new RuntimeException(\"Error loading word counts\", e);\n    }\n    return vocabulary;\n  }\n\n  public DocumentExamples extract(int id, Document document,\n      Map<Pair<Integer, Integer>, Boolean> labeledPairs) {\n    return extract(id, document, labeledPairs, compressor);\n  }\n\n  public DocumentExamples extract(int id, Document document,\n      Map<Pair<Integer, Integer>, Boolean> labeledPairs, Compressor<String> compressor) {\n    List<Mention> mentionsList = CorefUtils.getSortedMentions(document);\n    Map<Integer, List<Mention>> mentionsByHeadIndex = new HashMap<>();\n    for (Mention m : mentionsList) {\n      List<Mention> withIndex = mentionsByHeadIndex.get(m.headIndex);\n      if (withIndex == null) {\n        withIndex = new ArrayList<>();\n        mentionsByHeadIndex.put(m.headIndex, withIndex);","sourceCodeStart":79,"sourceCodeEnd":115,"githubUrl":"https://github.com/stanfordnlp/CoreNLP/blob/1b7edd19c4d0d7b1f13a2591425b9b60a0b1af7a/src/edu/stanford/nlp/coref/statistical/FeatureExtractor.java#L79-L115","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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"],"exampleFix":"// before\n// models jar missing; default edu/stanford/nlp/models/dcoref/... uncountable\n// after\nclasspath += \":/path/to/stanford-corenlp-<ver>-models.jar\"   // supplies word counts\n// or set explicitly:\nprops.setProperty(\"coref.word.counts\", \"/abs/path/word_counts.txt\");","handlingStrategy":"try-catch","validationCode":"String countsPath = props.getProperty(\"coref.word.counts\",\n    \"edu/stanford/nlp/models/dcoref/... (default in models jar)\");\nboolean resolvable = Thread.currentThread().getContextClassLoader()\n    .getResource(countsPath) != null || new java.io.File(countsPath).canRead();\nif (!resolvable) throw new IllegalStateException(\"Word counts resource not on classpath: \" + countsPath);","typeGuard":null,"tryCatchPattern":"try {\n  FeatureExtractor fx = new FeatureExtractor(props, dictionaries, compressor);\n} catch (RuntimeException e) {\n  if (\"Error loading word counts\".equals(e.getMessage()))\n    throw new IllegalStateException(\"Word-counts resource missing — install CoreNLP models jar\", e);\n  throw e;\n}","preventionTips":["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"],"tags":["java","corenlp","vocabulary","resource-loading"],"backgroundTag":"file-read-failed","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"}