{"record":{"id":"fcfc5d5a521da49b","repo":"stanfordnlp/CoreNLP","slug":"format-error-in-nodefeatureindicesmap","errorCode":null,"errorMessage":"format error in nodeFeatureIndicesMap","messagePattern":"format error in nodeFeatureIndicesMap","errorType":"exception","errorClass":"RuntimeException","httpStatus":null,"severity":"error","filePath":"src/edu/stanford/nlp/ie/crf/CRFClassifierNonlinear.java","lineNumber":248,"sourceCode":"    }\n    pw.printf(\"outputLayerWeights.length=\\t%d%n\", outputLayerWeights.length);\n    for (double[] ws : outputLayerWeights) {\n      ArrayList<Double> list = new ArrayList<>();\n      for (double w : ws) {\n        list.add(w);\n      }\n      pw.printf(\"%d\\t%s%n\", ws.length, StringUtils.join(list, \" \"));\n    }\n  }\n\n  @Override\n  protected void loadTextClassifier(BufferedReader br) throws Exception {\n    super.loadTextClassifier(br);\n\n    String line = br.readLine();\n    String[] toks = line.split(\"\\\\t\");\n    if (!toks[0].equals(\"nodeFeatureIndicesMap.size()=\")) {\n      throw new RuntimeException(\"format error in nodeFeatureIndicesMap\");\n    }\n    int nodeFeatureIndicesMapSize = Integer.parseInt(toks[1]);\n    nodeFeatureIndicesMap = new HashIndex<>();\n    int count = 0;\n    while (count < nodeFeatureIndicesMapSize) {\n      line = br.readLine();\n      toks = line.split(\"\\\\t\");\n      int idx = Integer.parseInt(toks[0]);\n      if (count != idx) {\n        throw new RuntimeException(\"format error\");\n      }\n      nodeFeatureIndicesMap.add(Integer.parseInt(toks[1]));\n      count++;\n    }\n\n    line = br.readLine();\n    toks = line.split(\"\\\\t\");\n    if (!toks[0].equals(\"edgeFeatureIndicesMap.size()=\")) {","sourceCodeStart":230,"sourceCodeEnd":266,"githubUrl":"https://github.com/stanfordnlp/CoreNLP/blob/1b7edd19c4d0d7b1f13a2591425b9b60a0b1af7a/src/edu/stanford/nlp/ie/crf/CRFClassifierNonlinear.java#L230-L266","documentation":"loadTextClassifier reads a text-serialized CRFClassifierNonlinear model line by line and expects the first line after the superclass section to be the header \"nodeFeatureIndicesMap.size()=\\t<size>\". When the tab-split first token does not equal that exact header string, this RuntimeException is thrown. It signals the model file is not in the expected text serialization format produced by serializeTextClassifier.","triggerScenarios":"Calling loadTextClassifier (e.g. via loadTextClassifier for a non-linear CRF) on a file whose next line is not the nodeFeatureIndicesMap header: the file was not saved with serializeTextClassifier, was saved by a different classifier type/version, is truncated, or line endings/encoding differ so split(\"\\\\t\") yields a wrong token.","commonSituations":"Pointing the loader at a serializedClassifier (gzip/binary) file instead of a text one; hand-editing the model file; loading a model written by a different Stanford NLP version where the text format changed; files corrupted by editors converting tabs to spaces.","solutions":["Regenerate the model file with serializeTextClassifier from the same CRFClassifierNonlinear version.","Verify you are loading the correct file (text serialization, not .ser binary or gzipped model).","Check that the expected header line \"nodeFeatureIndicesMap.size()=\" exists with a literal tab before the size.","Match the Stanford NLP library version used to write the model with the one doing the loading.","Write a loader for the actual format of the file if it was produced elsewhere."],"exampleFix":"// before\nCRFClassifier<CoreLabel> crf = CRFClassifier.getClassifier(\"model.ser\"); // binary file, header line missing\n// after\nCRFClassifier<CoreLabel> crf = CRFClassifier.getClassifier(\"model.txt\"); // text-serialized with serializeTextClassifier","handlingStrategy":"validation","validationCode":"// Verify the model file is text-serialized and starts with the expected section before loading:\ntry (BufferedReader br = new BufferedReader(new FileReader(modelFile))) {\n  String firstLine = br.readLine();\n  boolean hasHeader = false, line;\n  while ((line = br.readLine()) != null) {\n    if (line.startsWith(\"nodeFeatureIndicesMap.size()=\")) { hasHeader = true; break; }\n  }\n  if (!hasHeader) throw new IOException(modelFile + \" is not a text-serialized non-linear CRF model\");\n}","typeGuard":null,"tryCatchPattern":"try {\n  classifier = CRFClassifier.getClassifier(modelPath);\n} catch (Exception e) {\n  if (String.valueOf(e.getMessage()).contains(\"format error in nodeFeatureIndicesMap\")) {\n    throw new IOException(\"Model file is not a text-serialized CRFClassifierNonlinear model: \" + modelPath, e);\n  }\n  throw e;\n}","preventionTips":["Load only models written by serializeTextClassifier of the same classifier type.","Never hand-edit text model files; regenerate them from training.","Pin the Stanford NLP version so serializer and deserializer match.","Check the file is not gzipped/binary before text loading."],"tags":["serialization","model-loading","format-validation","crf"],"backgroundTag":"unexpected-response-shape","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"}