{"record":{"id":"47d39cf5d9310500","repo":"stanfordnlp/CoreNLP","slug":"weights-format-error","errorCode":null,"errorMessage":"weights format error","messagePattern":"weights format error","errorType":"exception","errorClass":"RuntimeException","httpStatus":null,"severity":"error","filePath":"src/edu/stanford/nlp/ie/crf/CRFClassifier.java","lineNumber":2272,"sourceCode":"    // weights.length= 2655170\n    line = br.readLine();\n\n    toks = line.split(\"\\\\t\");\n    if (!toks[0].equals(\"weights.length=\")) {\n      throw new RuntimeException(\"format error\");\n    }\n    int weightsLength = Integer.parseInt(toks[1]);\n    weights = new float[weightsLength][];\n    count = 0;\n    while (count < weightsLength) {\n      line = br.readLine();\n\n      toks = line.split(\"\\\\t\");\n      int weights2Length = Integer.parseInt(toks[0]);\n      weights[count] = new float[weights2Length];\n      String[] weightsValue = toks[1].split(\" \");\n      if (weights2Length != weightsValue.length) {\n        throw new RuntimeException(\"weights format error\");\n      }\n\n      for (int i2 = 0; i2 < weights2Length; i2++) {\n        // TODO: check that this doesn't barf... why would it?\n        weights[count][i2] = Float.parseFloat(weightsValue[i2]);\n      }\n      count++;\n    }\n    System.err.printf(\"DEBUG: float[%d][] weights loaded%n\", weightsLength);\n    line = br.readLine();\n\n    if (line != null) {\n      throw new RuntimeException(\"weights format error\");\n    }\n  }\n\n  public void loadTextClassifier(String text, Properties props) throws ClassCastException, IOException,\n      ClassNotFoundException, InstantiationException, IllegalAccessException {","sourceCodeStart":2254,"sourceCodeEnd":2290,"githubUrl":"https://github.com/stanfordnlp/CoreNLP/blob/1b7edd19c4d0d7b1f13a2591425b9b60a0b1af7a/src/edu/stanford/nlp/ie/crf/CRFClassifier.java#L2254-L2290","documentation":"Inside loadTextClassifier, each weight row line must be '<rowLength>\\t<v1 v2 ...>'. The loader parses the declared row length (weights2Length) and the space-separated values; if the number of parsed float values does not equal the declared length it throws RuntimeException('weights format error'), indicating a malformed or truncated weight row.","triggerScenarios":"Loading a text classifier whose weight-row lines declare a count that does not match the space-separated values present, e.g. values truncated, line-wrapped by an editor, extra spaces, or rows written by a different format version.","commonSituations":"Text weight file truncated by copy/paste or transfer; line wrapping inserted by editors/mail; float values containing non-numeric tokens causing parse mismatch; mixed-format file assembled by hand; version mismatch between writer and reader.","solutions":["Check the offending line: token 0 must equal the number of space-separated floats in token 1; fix or regenerate the file.","Re-export the text classifier from the original serialized model with the same Stanford NLP version.","Open the file in an editor that does not wrap lines and ensure no lines were split or trailing values dropped.","Regenerate the file without any intermediate processing (no sed/Excel/copy-paste) that could drop or alter values.","If the file is unreliable, retrain or use the binary serialized classifier via loadClassifier instead."],"exampleFix":null,"handlingStrategy":"validation","validationCode":"try (BufferedReader br = new BufferedReader(new InputStreamReader(new FileInputStream(path), \"UTF-8\"))) {\n  String header = br.readLine();\n  int n = Integer.parseInt(header.split(\"\\t\")[1]);\n  for (int i = 0; i < n; i++) {\n    String[] toks = br.readLine().split(\"\\t\", -1);\n    if (toks.length < 2 || Integer.parseInt(toks[0]) != toks[1].split(\" \").length)\n      throw new IllegalArgumentException(\"Malformed weight row \" + i + \" in \" + path);\n  }\n  if (br.readLine() != null) throw new IllegalArgumentException(\"Trailing content in \" + path);\n}","typeGuard":"static boolean isWellFormedWeightRow(String line) {\n  String[] toks = line.split(\"\\t\", -1);\n  if (toks.length < 2) return false;\n  try { return Integer.parseInt(toks[0]) == toks[1].trim().split(\"\\\\s+\").length; }\n  catch (NumberFormatException e) { return false; }\n}","tryCatchPattern":"try {\n  crf.loadTextClassifier(path, props);\n} catch (RuntimeException e) {\n  if (\"weights format error\".equals(e.getMessage()))\n    throw new IOException(\"Corrupt text weight rows in \" + path + \" — regenerate the text dump\", e);\n  throw e;\n}","preventionTips":["Transfer generated files in binary mode (no line wrapping/translation).","Validate row structure before loading.","Regenerate rather than hand-repair weight dumps.","Keep writer and reader on the same library version."],"tags":["java","serialization","file-format","crf","parsing"],"backgroundTag":"invalid-argument-format","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"}