stanfordnlp/CoreNLP · error · RuntimeException

only support settings for CTB and PK now.

Error message

only support settings for CTB and PK now.

What it means

ChineseSegmenterFeatureFactory.featuresCpC builds character-level POS/dictionary features using a tagset that depends on the segmentation corpus flags. If neither useCTBChar2 nor usePKChar2 is enabled (and features were requested that need a tagset), the library cannot know which tag inventory to use and throws a RuntimeException at feature extraction time.

Solutions

  1. Set useCTBChar2=true (or usePKChar2=true) in the segmenter properties file before training/testing
  2. If using Sighan corpora, pass the appropriate properties via -props so flags are loaded correctly
  3. If supporting another corpus, modify featuresCpC to supply a tagset for that setting instead of falling into the else branch

Example fix

// before (Properties)
ser=edu.stanford.nlp.wordseg.ChineseSegmenterFeatureFactory
// after
ser=edu.stanford.nlp.wordseg.ChineseSegmenterFeatureFactory
useCTBChar2=true
Defensive patterns

Strategy: validation

Validate before calling

Properties p = new Properties();
p.load(new FileInputStream(propsFile));
if (!Boolean.parseBoolean(p.getProperty("useCTBChar2","false")) &&
    !Boolean.parseBoolean(p.getProperty("usePKChar2","false"))) {
  throw new IllegalArgumentException("Set useCTBChar2 or usePKChar2 for ChineseSegmenterFeatureFactory");
}

Try / catch

try {
  classifier = CRFClassifier.getClassifier(serializedClassifier, props);
} catch (RuntimeException e) {
  if (e.getMessage().contains("CTB and PK")) {
    props.setProperty("useCTBChar2", "true");
    classifier = CRFClassifier.getClassifier(serializedClassifier, props);
  } else throw e;
}

Prevention

When it happens

Trigger: Running the CRF Chinese segmenter with featuresCpC extraction while flags.useCTBChar2=false and flags.usePKChar2=false (e.g. no -sighanCorporaDict-style property set / properties loaded from a config that only enables base features).

Common situations: Users training or testing on ASBC, HK, or MSR corpora without setting useCTBChar2/usePKChar2; copying an old properties file that predates the CTB/PK flag options; invoking the feature factory programmatically with a partially populated SeqClassifierFlags.

Understand the failure class

Background: "Invalid value" and "allowed values are" config errors: what your library rejected and how to fix it — this error's family across 41 libraries.

Related errors


AI-assisted analysis of stanfordnlp/CoreNLP@1b7edd19c4 (2026-09-10). Data as JSON: /api/errors/ef56aadac4e5ba7d. Report an issue: GitHub.

Appendix: source

Thrown at src/edu/stanford/nlp/wordseg/ChineseSegmenterFeatureFactory.java:302

      (CTB/ASBC/HK/PK/MSR) POS information of each characters.
      If a character falls into some function categories,
      it is very likely there is a boundary.
      A lot of Chinese function words belong to single characters.
      This feature is also good for numbers and punctuations.
      DE* are grouped into DE.
    */
    if (flags.useCTBChar2 || flags.useASBCChar2 || flags.useHKChar2
        || flags.usePKChar2 || flags.useMSRChar2) {
      String[] tagsets;
      // the "useChPos" now only works for CTB and PK
      if (flags.useChPos) {
        if(flags.useCTBChar2) {
          tagsets = new String[]{"AD", "AS", "BA", "CC", "CD", "CS", "DE", "DT", "ETC", "IJ", "JJ", "LB", "LC", "M",  "NN",  "NR", "NT", "OD", "P", "PN", "PU", "SB", "SP", "VA", "VC", "VE", "VV" };
        } else if (flags.usePKChar2) {
          //tagsets = new String[]{"r", "j", "t", "a", "nz", "l", "vn", "i", "m", "ns", "nr", "v", "n", "q", "Ng", "b", "d", "nt"};
          tagsets = new String[]{"2","3","4"};
        } else {
          throw new RuntimeException("only support settings for CTB and PK now.");
        }
      } else {
        //logger.info("Using Derived features");
        tagsets = new String[]{"2","3","4"};
      }

      if (taDetector == null) {
        taDetector = new TagAffixDetector(flags);
      }
      for (String tagset : tagsets) {
        features.add(taDetector.checkDic(tagset + "p", charp) + taDetector.checkDic(tagset + "i", charp) + taDetector.checkDic(tagset + "s", charc) + taDetector.checkInDic(charp) + taDetector.checkInDic(charc) + tagset + "prep-sufc");
        // features.add("|ctbchar2");  // Added a constant feature several times!!
      }
    }

    /*
      In error analysis, we found English words and numbers are often separated.
      Rule 1: isNumber feature: check if the current and previous char is a number.

View on GitHub (pinned to 1b7edd19c4)