{"record":{"id":"3014a682209213e9","repo":"stanfordnlp/CoreNLP","slug":"error-leading-weights-from-modelfile","errorCode":null,"errorMessage":"Error leading weights from {modelFile}","messagePattern":"Error leading weights from (.+?)","errorType":"exception","errorClass":"RuntimeException","httpStatus":null,"severity":"critical","filePath":"src/edu/stanford/nlp/coref/statistical/SimpleLinearClassifier.java","lineNumber":48,"sourceCode":"  public SimpleLinearClassifier(Loss loss, LearningRateSchedule learningRateSchedule,\n      double regularizationStrength) {\n    this(loss, learningRateSchedule, regularizationStrength, null);\n  }\n\n  public SimpleLinearClassifier(Loss loss,LearningRateSchedule learningRateSchedule,\n      double regularizationStrength, String modelFile) {\n    if (modelFile != null) {\n      try {\n        if (modelFile.endsWith(\".tab.gz\")) {\n          Timing.startDoing(\"Reading \" + modelFile);\n          this.weights = Counters.deserializeStringCounter(modelFile);\n          Timing.endDoing(\"Reading \" + modelFile);\n        } else {\n          this.weights = IOUtils.readObjectAnnouncingTimingFromURLOrClasspathOrFileSystem(\n              log, \"Loading coref model\", modelFile);\n        }\n      } catch (Exception e) {\n        throw new RuntimeException(\"Error leading weights from \" + modelFile, e);\n      }\n    } else {\n      this.weights = new ClassicCounter<>();\n    }\n\n    this.defaultLoss = loss;\n    this.regularizationStrength = regularizationStrength;\n    this.learningRateSchedule = learningRateSchedule;\n    accessTimes = new ClassicCounter<>();\n    examplesSeen = 0;\n  }\n\n  public void learn(Counter<String> features, double label, double weight) {\n    learn(features, label, weight, defaultLoss);\n  }\n\n  public void learn(Counter<String> features, double label, double weight, Loss loss) {\n    examplesSeen++;","sourceCodeStart":30,"sourceCodeEnd":66,"githubUrl":"https://github.com/stanfordnlp/CoreNLP/blob/1b7edd19c4d0d7b1f13a2591425b9b60a0b1af7a/src/edu/stanford/nlp/coref/statistical/SimpleLinearClassifier.java#L30-L66","documentation":"SimpleLinearClassifier wraps any exception raised while deserializing the coref model weights into a RuntimeException with this message. It indicates the serialized model file could not be read or unmarshalled (missing file, corrupt data, incompatible serialization version).","triggerScenarios":"Constructing SimpleLinearClassifier with a modelFile path/URL when IOUtils.readObjectAnnouncingTimingFromURLOrClasspathOrFileSystem throws: file absent, unreadable, corrupted, or serialized by an incompatible Java/class version.","commonSituations":"Model file path typo in coref properties, model not on classpath, Stanford CoreNLP model jar version mismatch with code (serialization serialVersionUID changes), truncated download of the classifier model.","solutions":["Verify the modelFile path/URL exists and is readable, and that the model resource is on the classpath","Re-download the Stanford CoreNLP coref model matching your library version","Check for ClassNotFoundException/InvalidClassException in the cause chain and align CoreNLP code and model versions","Pass a valid modelFile, or construct the classifier in learning mode so it starts with empty weights"],"exampleFix":"// before\nnew SimpleLinearClassifier(Loss.logistic, \"coref/model.ser\");\n// after\nFile f = new File(\"coref/model.ser\");\nif (!f.isFile()) throw new IllegalStateException(\"model missing: \" + f);\nnew SimpleLinearClassifier(Loss.logistic, f.getPath());","handlingStrategy":"validation","validationCode":"File f = new File(modelFile);\nif (!f.isFile() || !f.canRead()) throw new IllegalStateException(\"model not readable: \" + modelFile);","typeGuard":null,"tryCatchPattern":"try {\n  new SimpleLinearClassifier(loss, modelFile);\n} catch (RuntimeException e) {\n  logger.severe(\"model load failed: \" + e.getCause());\n  throw e;\n}","preventionTips":["Verify model file presence/readability before constructing the classifier","Keep CoreNLP jar and model jar versions identical","Verify checksums of downloaded models"],"tags":["io","model-loading","deserialization","classpath"],"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"}