{"record":{"id":"81b3a001dda02b20","repo":"stanfordnlp/CoreNLP","slug":"could-not-read-from-float-initial-weight-file","errorCode":null,"errorMessage":"Could not read from float initial weight file ","messagePattern":"Could not read from float initial weight file ","errorType":"exception","errorClass":"RuntimeException","httpStatus":null,"severity":"error","filePath":"src/edu/stanford/nlp/ie/crf/CRFClassifierFloat.java","lineNumber":92,"sourceCode":"\n    if (pruneFeatureItr == 0) {\n      minimizer.setM(flags.QNsize);\n    } else {\n      minimizer.setM(flags.QNsize2);\n    }\n\n    float[] 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        try (DataInputStream dis = new DataInputStream(new BufferedInputStream(new GZIPInputStream(new FileInputStream(\n            flags.initialWeights))))) {\n          initialWeights = ConvertByteArray.readFloatArr(dis);\n        }\n      } catch (IOException e) {\n        throw new RuntimeException(\"Could not read from float initial weight file \" + flags.initialWeights);\n      }\n    }\n    log.info(\"numWeights: \" + initialWeights.length);\n    float[] weightsArray = minimizer.minimize(func, (float) flags.tolerance, initialWeights);\n    return ArrayMath.floatArrayToDoubleArray(weightsArray);\n  }\n\n} // end class CRFClassifierFloat\n","sourceCodeStart":74,"sourceCodeEnd":101,"githubUrl":"https://github.com/stanfordnlp/CoreNLP/blob/1b7edd19c4d0d7b1f13a2591425b9b60a0b1af7a/src/edu/stanford/nlp/ie/crf/CRFClassifierFloat.java#L74-L101","documentation":"CRFClassifierFloat.trainWeights loads initial weights from flags.initialWeights as a gzip-compressed float array. If opening/reading the stream or decoding the array throws IOException, it throws RuntimeException('Could not read from float initial weight file <path>') — notably WITHOUT the cause chained, so the original IOException detail is lost.","triggerScenarios":"Setting flags.initialWeights to a nonexistent file, unreadable file, or a file that is not a gzip stream of a float array (wrong format, plain text, double array) during training with float weights.","commonSituations":"Typo in initialWeights path; file compressed differently (plain vs gzip); passing a double-array dump instead of a float dump; permissions; file created by another tool with a different binary layout.","solutions":["Check that flags.initialWeights points to an existing, readable gzip-compressed float-array file.","Verify the file is valid gzip ('file initialweights.gz') and was written with ConvertByteArray.writeFloatArr.","Regenerate the initial weights file as a float array with the matching utility/serialization.","If you only have a double array, convert it to float[] before writing/using it for the float trainer.","Wrap the call yourself or patch to chain the cause (new RuntimeException(msg, e)) to see the true IOException."],"exampleFix":"// before\nprops.setProperty(\"initialWeights\", \"init.txt\"); // plain text, not gzip float array\n// after\n// write with ConvertByteArray.writeFloatArr(new GZIPOutputStream(new FileOutputStream(\"init.f32.gz\")), floatWeights);\nprops.setProperty(\"initialWeights\", \"init.f32.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(); // throws IOException('Not in GZIP format') if not gzip\n}","typeGuard":null,"tryCatchPattern":"try {\n  initialWeights = ConvertByteArray.readFloatArr(\n      new DataInputStream(new BufferedInputStream(new GZIPInputStream(new FileInputStream(flags.initialWeights)))));\n} catch (IOException e) {\n  throw new RuntimeException(\"Could not read float initial weights from \" + flags.initialWeights, e); // chain the cause!\n}","preventionTips":["Verify the initialWeights file exists and is gzip before training.","Ensure it was written with ConvertByteArray.writeFloatArr (float, not double).","When reproducing this code, always chain the IOException as the cause.","Validate gzip integrity ('gzip -t file.gz') beforehand."],"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"}