{"record":{"id":"14dec1e57d438213","repo":"stanfordnlp/CoreNLP","slug":"could-not-read-from-double-initial-weight-file","errorCode":null,"errorMessage":"Could not read from double initial weight file \" + flags.initialWeights","messagePattern":"Could not read from double initial weight file \" \\+ flags\\.initialWeights","errorType":"exception","errorClass":"RuntimeException","httpStatus":null,"severity":"error","filePath":"src/edu/stanford/nlp/ie/crf/CRFClassifier.java","lineNumber":1857,"sourceCode":"        for (Integer val : aSet)\n          fg[count][i++] = val;\n        count++;\n      }\n      func.setFeatureGrouping(fg);\n    }\n\n    Minimizer<DiffFunction> minimizer = getMinimizer(pruneFeatureItr, evaluators);\n\n    double[] initialWeights;\n    if (flags.initialWeights == null) {\n      initialWeights = func.initial();\n    } else {\n      try {\n        log.info(\"Reading initial weights from file \" + flags.initialWeights);\n        DataInputStream dis = IOUtils.getDataInputStream(flags.initialWeights);\n        initialWeights = ConvertByteArray.readDoubleArr(dis);\n      } catch (IOException e) {\n        throw new RuntimeException(\"Could not read from double initial weight file \" + flags.initialWeights);\n      }\n    }\n    log.info(\"numWeights: \" + initialWeights.length);\n\n    if (flags.testObjFunction) {\n      StochasticDiffFunctionTester tester = new StochasticDiffFunctionTester(func);\n      if (tester.testSumOfBatches(initialWeights, 1e-4)) {\n        log.info(\"Successfully tested stochastic objective function.\");\n      } else {\n        throw new IllegalStateException(\"Testing of stochastic objective function failed.\");\n      }\n\n    }\n    //check gradient\n    if (flags.checkGradient) {\n      if (func.gradientCheck()) {\n        log.info(\"gradient check passed\");\n      } else {","sourceCodeStart":1839,"sourceCodeEnd":1875,"githubUrl":"https://github.com/stanfordnlp/CoreNLP/blob/1b7edd19c4d0d7b1f13a2591425b9b60a0b1af7a/src/edu/stanford/nlp/ie/crf/CRFClassifier.java#L1839-L1875","documentation":"When flags.initialWeights points to a file, the stochastic training path reads a double array of initial weights via IOUtils.getDataInputStream and ConvertByteArray.readDoubleArr. An IOException (missing file, unreadable, truncated, wrong binary format) is wrapped in this RuntimeException naming the offending path.","triggerScenarios":"Setting initialWeights=<path> where the file doesn't exist, lacks read permission, or doesn't contain a valid binary double array of the expected length for the model.","commonSituations":"Reusing weights saved from a different model size (feature/label mismatch causing truncated or misaligned reads); stale or renamed path; files produced by a different library version.","solutions":["Verify initialWeights points to an existing readable file produced by the same model configuration and version.","Regenerate the weights file with the current CRF setup.","Remove the initialWeights property to use default initialization.","Inspect the wrapped IOException to distinguish not-found vs. EOF/truncation."],"exampleFix":"// before\nprops.setProperty(\"initialWeights\", \"/models/old-weights.ser\"); // file deleted\n// after\nprops.setProperty(\"initialWeights\", \"/models/crf-weights-v2.ser\");\n// or remove the property to start from default initialization","handlingStrategy":"validation","validationCode":"String path = props.getProperty(\"initialWeights\");\nif (path != null) {\n  File f = new File(path);\n  if (!f.isFile() || !f.canRead() || f.length() == 0 || f.length() % 8 != 0) {\n    throw new IllegalArgumentException(\"initialWeights missing/unreadable or not a double array: \" + path);\n  }\n}","typeGuard":null,"tryCatchPattern":"try {\n  classifier.train(files);\n} catch (RuntimeException e) {\n  if (String.valueOf(e.getMessage()).startsWith(\"Could not read from double initial weight file\")) {\n    props.remove(\"initialWeights\"); // fall back to default initialization\n    // rebuild and retry\n  } else throw e;\n}","preventionTips":["Only pass weights files produced by the same model configuration and library version.","Check existence, permissions, and that byte length is a multiple of 8.","Don't rename or move weights files referenced in stored configs."],"tags":["java","io","weights","crf"],"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"}