stanfordnlp/CoreNLP · error · RuntimeException
Unknown feature type " + feature
Error message
Unknown feature type " + feature
What it means
getFeatureTypeIndex maps a feature name to an index (0-5) based on its suffix (e.g. |C, |Cp2C, ... |Cp5C), which encodes the label-window size for that feature. If the feature name ends with none of the recognized suffixes, the classifier cannot determine how many labels the feature's weight matrix applies to, so it throws a RuntimeException.
Solutions
- Check the feature name reported in the exception; ensure both models were trained with the same featureFactory (flags.featureFactory) and its suffix conventions.
- Retrain or re-serialize both classifiers with matching feature definitions before calling combine().
- Extend getFeatureTypeIndex (or the feature factory) to emit a recognized suffix for your custom features, or exclude non-standard features before combining.
Example fix
// before: custom feature factory emits features like "MYFEAT-3" // after: emit with the expected suffix so the type index resolves new CoreLabel(); featName = base + "|C"; // e.g. "MYFEAT-3|C"
Defensive patterns
Strategy: validation
Validate before calling
List<String> SUFFIXES = List.of("|C", "|Cp2C", "|Cp3C", "|Cp4C", "|Cp5C");
for (String f : (Iterable<String>) crf.featureIndex) {
if (SUFFIXES.stream().noneMatch(f::endsWith))
throw new IllegalStateException("Unrecognized feature suffix: " + f);
} Prevention
- Use the same featureFactory configuration for all models you plan to combine.
- Inspect a serialized model's featureIndex before combining it.
- Keep standard |CpNC suffixes in any custom feature factory.
When it happens
Trigger: Calling combine() (or any code path that builds the feature-type map via getFeatureTypeIndex) when one classifier's featureIndex contains a feature whose name lacks a recognized '|CpNC' suffix; typically features created by a CRF with different featureFactory suffix configuration.
Common situations: Merging two CRF models trained with different feature factories or suffix conventions; custom SeqClassifierFlags.props / featureFactory strings that drop the standard suffix; loading a model whose feature naming doesn't match the current code's expectations.
Understand the failure class
Background: Invalid enum value errors: "Unknown type", "Invalid scope", "must be one of" — when a string is not on the library's allowed list — this error's family across 23 libraries.
Related errors
- Incompatible CRFClassifier: weight length mismatch for…
- Incompatible CRFClassifier: pad does not match
- Incompatible CRFClassifier: windowSize does not match
- Incompatible CRFClassifier: labelIndices length does not…
- node cliqueFeatures[n]=
AI-assisted analysis of stanfordnlp/CoreNLP@1b7edd19c4 (2026-09-10).
Data as JSON: /api/errors/4d874f598f585420.
Report an issue: GitHub.
Appendix: source
Thrown at src/edu/stanford/nlp/ie/crf/CRFClassifier.java:257
*
* @param feature Feature string
* @return index of featureType
*/
private static int getFeatureTypeIndex(String feature) {
if (feature.endsWith("|C")) {
return 0;
} else if (feature.endsWith("|CpC")) {
return 1;
} else if (feature.endsWith("|Cp2C")) {
return 2;
} else if (feature.endsWith("|Cp3C")) {
return 3;
} else if (feature.endsWith("|Cp4C")) {
return 4;
} else if (feature.endsWith("|Cp5C")) {
return 5;
} else {
throw new RuntimeException("Unknown feature type " + feature);
}
}
/**
* Scales the weights of this CRFClassifier by the specified weight.
*
* @param scale The scale to multiply by
*/
public void scaleWeights(double scale) {
for (int i = 0; i < weights.length; i++) {
for (int j = 0; j < weights[i].length; j++) {
weights[i][j] *= scale;
}
}
}
/**
* Combines weights from another crf (scaled by weight) into this CRF'sView on GitHub (pinned to 1b7edd19c4)