{"record":{"id":"b731d7b9b1b7354d","repo":"stanfordnlp/CoreNLP","slug":"node-cliquefeatures-n","errorCode":null,"errorMessage":"node cliqueFeatures[n]=","messagePattern":"node cliqueFeatures\\[n\\]=","errorType":"exception","errorClass":"RuntimeException","httpStatus":null,"severity":"error","filePath":"src/edu/stanford/nlp/ie/crf/CRFClassifierNonlinear.java","lineNumber":89,"sourceCode":"    int[][][] data = result.first();\n    data = transformDocData(data);\n\n    return new Triple<>(data, result.second(), result.third());\n  }\n\n  private int[][][] transformDocData(int[][][] docData) {\n    int[][][] transData = new int[docData.length][][];\n    for (int i = 0; i < docData.length; i++) {\n      transData[i] = new int[docData[i].length][];\n      for (int j = 0; j < docData[i].length; j++) {\n        int[] cliqueFeatures = docData[i][j];\n        transData[i][j] = new int[cliqueFeatures.length];\n        for (int n = 0; n < cliqueFeatures.length; n++) {\n          int transFeatureIndex = -1;\n          if (j == 0) {\n            transFeatureIndex = nodeFeatureIndicesMap.indexOf(cliqueFeatures[n]);\n            if (transFeatureIndex == -1)\n              throw new RuntimeException(\"node cliqueFeatures[n]=\"+cliqueFeatures[n]+\" not found, nodeFeatureIndicesMap.size=\"+nodeFeatureIndicesMap.size());\n          } else {\n            transFeatureIndex = edgeFeatureIndicesMap.indexOf(cliqueFeatures[n]);\n            if (transFeatureIndex == -1)\n              throw new RuntimeException(\"edge cliqueFeatures[n]=\"+cliqueFeatures[n]+\" not found, edgeFeatureIndicesMap.size=\"+edgeFeatureIndicesMap.size());\n          }\n          transData[i][j][n] = transFeatureIndex;\n        }\n      }\n    }\n    return transData;\n  }\n\n  @Override\n  protected CliquePotentialFunction getCliquePotentialFunctionForTest() {\n    if (cliquePotentialFunction == null) {\n      if (flags.secondOrderNonLinear)\n        cliquePotentialFunction = new NonLinearSecondOrderCliquePotentialFunction(inputLayerWeights4Edge, outputLayerWeights4Edge, inputLayerWeights, outputLayerWeights, flags);\n      else","sourceCodeStart":71,"sourceCodeEnd":107,"githubUrl":"https://github.com/stanfordnlp/CoreNLP/blob/1b7edd19c4d0d7b1f13a2591425b9b60a0b1af7a/src/edu/stanford/nlp/ie/crf/CRFClassifierNonlinear.java#L71-L107","documentation":"CRFClassifierNonlinear.transformDocData remaps each clique's feature indices into either the node or edge feature index map depending on the clique type j==0 (node) or j>0 (edge). If cliqueFeatures[n] is not present in nodeFeatureIndicesMap, it throws RuntimeException('node cliqueFeatures[n]=... not found, nodeFeatureIndicesMap.size=...'), an invariant violation meaning the feature index was never registered in the node feature space.","triggerScenarios":"During documentToDataAndLabels -> transformDocData, when a feature index appearing in the document data's node cliques (j==0) is absent from nodeFeatureIndicesMap — e.g. feature maps built from different data, index maps not initialized from training data, or mismatched feature factories between weight-building and data-transformation passes.","commonSituations":"Training nonlinear CRF where the node feature index map was built from a subset of documents; custom feature factory producing features after index maps were frozen; stale/cached index maps reused across datasets; version mismatch in pipeline components.","solutions":["Ensure feature index maps (nodeFeatureIndicesMap) are built by running feature extraction over the full training data before transformDocData.","Verify the same FeatureFactory configuration is used for both index-map construction and document conversion.","Clear stale cached index maps / re-run the index-building pass if data changed.","Check that the document data being transformed came from the same corpus/label scheme used to build the maps.","Log the missing feature to identify which feature factory produces it and why it was unregistered."],"exampleFix":"// before\n// index maps built from only the first document\nint[][][] docData = docDatas.get(0);\nbuildFeatureIndexMap(docData); // incomplete\n// after\n// build maps from ALL documents before transforming any\nfor (int[][][] d : docDatas) addToFeatureIndexMap(d);\nbuildFeatureIndexMap();\nint[][][][] trans = transformDocData(docData);","handlingStrategy":"validation","validationCode":"for (int[][] doc : data) {\n  for (int[] cliqueFeatures : doc) {\n    for (int fi : cliqueFeatures)\n      if (fi >= 0 && nodeFeatureIndicesMap.indexOf(fi) == -1)\n        throw new IllegalStateException(\"Node feature \" + fi + \" missing from nodeFeatureIndicesMap (size=\" + nodeFeatureIndicesMap.size() + \")\");\n  }\n}","typeGuard":null,"tryCatchPattern":"try {\n  int[][][][] trans = transformDocData(docData);\n} catch (RuntimeException e) {\n  if (String.valueOf(e.getMessage()).startsWith(\"node cliqueFeatures\"))\n    throw new IllegalStateException(\"Feature index maps were not built from this training data — rebuild index maps before transforming\", e);\n  throw e;\n}","preventionTips":["Always build node/edge feature index maps over the FULL training data before transformDocData.","Use one consistent FeatureFactory configuration for indexing and data transformation.","Rebuild index maps whenever training data or feature flags change.","Never reuse stale cached index maps across datasets."],"tags":["java","crf","feature-index","invariant"],"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"}