{"record":{"id":"07e9bc5a8031c518","repo":"stanfordnlp/CoreNLP","slug":"could-not-read-from-double-initial-weight-file-07e9bc","errorCode":null,"errorMessage":"Could not read from double initial weight file ","messagePattern":"Could not read from double initial weight file ","errorType":"exception","errorClass":"RuntimeException","httpStatus":null,"severity":"error","filePath":"src/edu/stanford/nlp/ie/crf/CRFClassifierNonlinear.java","lineNumber":155,"sourceCode":"      this.outputLayerWeights = params.third();\n    }\n\n    return null;\n  }\n\n  private double[] trainWeightsUsingNonLinearCRF(AbstractCachingDiffFunction func, Evaluator[] evaluators) {\n    Minimizer<DiffFunction> minimizer = getMinimizer(0, evaluators);\n\n    double[] initialWeights;\n    if (flags.initialWeights == null) {\n      initialWeights = func.initial();\n    } else {\n      log.info(\"Reading initial weights from file \" + flags.initialWeights);\n      try (DataInputStream dis = new DataInputStream(new BufferedInputStream(new GZIPInputStream(new FileInputStream(\n            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(\"Testing complete... exiting\");\n        System.exit(1);\n      } else {\n        log.info(\"Testing failed....exiting\");\n        System.exit(1);\n      }\n\n    }\n    //check gradient\n    if (flags.checkGradient) {\n      if (func.gradientCheck()) {","sourceCodeStart":137,"sourceCodeEnd":173,"githubUrl":"https://github.com/stanfordnlp/CoreNLP/blob/1b7edd19c4d0d7b1f13a2591425b9b60a0b1af7a/src/edu/stanford/nlp/ie/crf/CRFClassifierNonlinear.java#L137-L173","documentation":"CRFClassifierNonlinear.trainWeightsUsingNonLinearCRF loads initial weights from flags.initialWeights as a gzip-compressed double array. Any IOException while opening or decoding is rethrown as RuntimeException('Could not read from double initial weight file <path>') with the cause discarded, so only the path is reported.","triggerScenarios":"Training a nonlinear CRF with flags.initialWeights set to a missing/unreadable file, a non-gzip file, or a file holding a float array instead of the required double array (ConvertByteArray.readDoubleArr).","commonSituations":"Wrong path/typo in initialWeights; file produced by the float pipeline (float array) and fed to the nonlinear/double trainer; different compression (plain or zip instead of gzip); permissions; file truncated by a failed transfer.","solutions":["Verify flags.initialWeights exists, is readable, and is valid gzip ('file init.gz').","Confirm the file contains a double array written via ConvertByteArray.writeDoubleArr; regenerate it if it was written as float[].","Convert float initial weights to double[] and rewrite with writeDoubleArr before nonlinear training.","Fix file permissions / re-download if truncated.","Catch and log e.getCause() locally (or patch to chain the exception) to see the underlying IOException."],"exampleFix":"// before\nprops.setProperty(\"initialWeights\", \"init.f32.gz\"); // float array -> readDoubleArr fails\n// after\n// rewrite as double array: ConvertByteArray.writeDoubleArr(new GZIPOutputStream(new FileOutputStream(\"init.f64.gz\")), doubleWeights);\nprops.setProperty(\"initialWeights\", \"init.f64.gz\");","handlingStrategy":"validation","validationCode":"File f = new File(flags.initialWeights);\nif (!f.isFile() || !f.canRead()) throw new IllegalArgumentException(\"initialWeights missing/unreadable: \" + flags.initialWeights);\ntry (InputStream in = new GZIPInputStream(new FileInputStream(f))) {\n  in.read(); // fails fast if not gzip\n}","typeGuard":null,"tryCatchPattern":"try {\n  initialWeights = ConvertByteArray.readDoubleArr(\n      new DataInputStream(new BufferedInputStream(new GZIPInputStream(new FileInputStream(flags.initialWeights)))));\n} catch (IOException e) {\n  throw new RuntimeException(\"Could not read double initial weights from \" + flags.initialWeights, e); // chain the cause!\n}","preventionTips":["Confirm the file is a gzip'd DOUBLE array (writeDoubleArr) — the nonlinear trainer cannot read float arrays.","Validate path and gzip integrity before launching training.","Always chain the underlying IOException when wrapping.","Keep float (CRFClassifierFloat) and double (nonlinear) initial-weight files clearly separated by naming."],"tags":["java","io","training","gzip","file-read"],"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"}