{"record":{"id":"8eb1e198eb7f933f","repo":"stanfordnlp/CoreNLP","slug":"weights-format-error-8eb1e1","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/CRFClassifierNonlinear.java","lineNumber":301,"sourceCode":"    int  weightsLength = -1;\n    if (flags.secondOrderNonLinear) {\n      line = br.readLine();\n      toks = line.split(\"\\\\t\");\n      if (!toks[0].equals(\"inputLayerWeights4Edge.length=\")) {\n        throw new RuntimeException(\"format error\");\n      }\n      weightsLength = Integer.parseInt(toks[1]);\n      inputLayerWeights4Edge = new double[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        inputLayerWeights4Edge[count] = new double[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          inputLayerWeights4Edge[count][i2] = Double.parseDouble(weightsValue[i2]);\n        }\n        count++;\n      }\n      line = br.readLine();\n\n      toks = line.split(\"\\\\t\");\n      if (!toks[0].equals(\"outputLayerWeights4Edge.length=\")) {\n        throw new RuntimeException(\"format error\");\n      }\n      weightsLength = Integer.parseInt(toks[1]);\n      outputLayerWeights4Edge = new double[weightsLength][];\n      count = 0;\n      while (count < weightsLength) {\n        line = br.readLine();","sourceCodeStart":283,"sourceCodeEnd":319,"githubUrl":"https://github.com/stanfordnlp/CoreNLP/blob/1b7edd19c4d0d7b1f13a2591425b9b60a0b1af7a/src/edu/stanford/nlp/ie/crf/CRFClassifierNonlinear.java#L283-L319","documentation":"Each inputLayerWeights4Edge row in a text-serialized CRFClassifierNonlinear model is written as \"<rowLength>\\t<w1 w2 w3 ...>\". After parsing the row length, the loader splits the second token on spaces and requires the number of values to equal the declared row length; otherwise this RuntimeException is thrown. It means a weight row's declared length does not match the values actually present on that line.","triggerScenarios":"loadTextClassifier parses a row line where toks[1] contains fewer/more space-separated numbers than toks[0] declares: manual edits, truncation cutting off trailing values, tabs/spaces corruption, or files written by a different version with a different row encoding.","commonSituations":"Hand-edited weight files; truncated downloads; editors normalizing whitespace; mixing models between Stanford NLP versions; double-precision values pasted incompletely.","solutions":["Regenerate the model with serializeTextClassifier instead of editing weights manually.","Verify each row line's leading count equals the number of space-separated weight values after the tab.","Check the file was not truncated (last rows often lose values).","Re-transfer or re-serialize if the file was corrupted.","Use the same library version for saving and loading."],"exampleFix":"// before\n3\t0.5 0.25   // declares 3 weights but only 2 present\n// after\n3\t0.5 0.25 0.75","handlingStrategy":"validation","validationCode":"// Verify each inputLayerWeights4Edge row: leading count must equal the number of space-separated values.\n// e.g. for line \"3\\t0.5 0.25 0.75\": toks[0]=3, toks[1].split(\" \").length must be 3.","typeGuard":null,"tryCatchPattern":"try {\n  crf = CRFClassifier.getClassifier(modelPath);\n} catch (Exception e) {\n  if (String.valueOf(e.getMessage()).equals(\"weights format error\")) {\n    throw new IOException(\"Weight row length mismatch in inputLayerWeights4Edge; regenerate the model file: \" + modelPath, e);\n  }\n  throw e;\n}","preventionTips":["Do not edit weight values in text model files manually.","Verify checksums after transferring models to catch truncation.","Avoid text editors that reflow or normalize whitespace on model files.","Serialize and load with the same Stanford NLP release."],"tags":["serialization","model-loading","format-validation","weights","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"}