{"record":{"id":"a7c6e99c227e11d0","repo":"stanfordnlp/CoreNLP","slug":"two-models-must-have-the-same-sequence-length","errorCode":null,"errorMessage":"Two models must have the same sequence length","messagePattern":"Two models must have the same sequence length","errorType":"exception","errorClass":"RuntimeException","httpStatus":null,"severity":"error","filePath":"src/edu/stanford/nlp/sequences/FactoredSequenceModel.java","lineNumber":112,"sourceCode":"  }\n\n  /**\n   * using this constructor results in a weighted addition of the two models' scores.\n   * @param model1\n   * @param model2\n   * @param wt1 weight of model1\n   * @param wt2 weight of model2\n   */\n  public FactoredSequenceModel(SequenceModel model1, SequenceModel model2, double wt1, double wt2){\n    this(model1,model2);\n    this.model1Wt = wt1;\n    this.model2Wt = wt2;\n  }\n\n  public FactoredSequenceModel(SequenceModel model1, SequenceModel model2) {\n    //if (model1.leftWindow() != model2.leftWindow()) throw new RuntimeException(\"Two models must have same window size\");\n    if (model1.getPossibleValues(0).length != model2.getPossibleValues(0).length) throw new RuntimeException(\"Two models must have the same number of classes\");\n    if (model1.length() != model2.length()) throw new RuntimeException(\"Two models must have the same sequence length\");\n    this.model1 = model1;\n    this.model2 = model2;\n  }\n\n  public FactoredSequenceModel(SequenceModel[] models, double[] weights){\n    this.models = models;\n    this.wts = weights;\n    /*\n  for(int i = 1; i < models.length; i++){\n    if (models[0].getPossibleValues(0).length != models[i].getPossibleValues(0).length) throw new RuntimeException(\"All models must have the same number of classes\");\n    if(models[0].length() != models[i].length())\n      throw new RuntimeException(\"All models must have the same sequence length\");\n\n    }\n    */\n  }\n\n}","sourceCodeStart":94,"sourceCodeEnd":130,"githubUrl":"https://github.com/stanfordnlp/CoreNLP/blob/1b7edd19c4d0d7b1f13a2591425b9b60a0b1af7a/src/edu/stanford/nlp/sequences/FactoredSequenceModel.java#L94-L130","documentation":"The two-model FactoredSequenceModel constructor also requires both models to describe the same sequence length; if model1.length() != model2.length() it throws RuntimeException('Two models must have the same sequence length').","triggerScenarios":"new FactoredSequenceModel(model1, model2) where the two SequenceModels report different length() values — e.g. one model built over a longer windowed/padded sequence than the other, at FactoredSequenceModel.java:112.","commonSituations":"Combining a model constructed on the full padded sequence with one built on a raw-length sequence; models whose length() derives from different underlying documents or sentence splits.","solutions":["Ensure both models are constructed over the same underlying sequence (same document, same padding/windowing) before combining.","Align lengths by rebuilding one model with the other's length/window conventions.","Check that both models consume identical input documents (same tokenization and sentence boundaries)."],"exampleFix":"// before\nFactoredSequenceModel f = new FactoredSequenceModel(modelOverPaddedSeq, modelOverRawSeq);\n// after\nSequenceModel m2 = new MyModel(paddedDocument); // same length as model1\nFactoredSequenceModel f = new FactoredSequenceModel(modelOverPaddedSeq, m2);","handlingStrategy":"validation","validationCode":"// verify equal sequence lengths before composing\nif (m1.length() != m2.length())\n  throw new IllegalArgumentException(\"length mismatch: \" + m1.length() + \" vs \" + m2.length());","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Build both models over the identical tokenized/padded document.","Avoid mixing raw-length and padded-length models.","Check window/padding conventions match before composing."],"tags":["java","stanford-corenlp","sequence-model","model-composition"],"backgroundTag":"internal-invariant-violation","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"}