stanfordnlp/CoreNLP · error · RuntimeException

Unknown label:

Error message

Unknown label: 

What it means

IOBToString converts IO/B-tagged tokens back into a segmented string. When a token carries a label outside the recognized IOB scheme (not B*, I*, or the handled control labels), the method throws RuntimeException('Unknown label: ' + label) because no rewrite rule exists for it.

Solutions

  1. Inspect the offending label value in the message and reconcile it with the expected IOB tag set
  2. Retrain/decode with the same label scheme the IOB post-processing expects
  3. Pre-validate/normalize labels before calling IOBToString, mapping or rejecting unknown tags
  4. Update the switch in IOBUtils to handle the new label type if it is legitimate

Example fix

// before
String s = IOBUtils.IOBToString(tokens, "tag"); // unknown custom label
// after
for (CoreLabel t : tokens) {
  String l = t.tag();
  if (!l.equals("B") && !l.equals("I") && !l.startsWith("B-") && !l.startsWith("I-"))
    throw new IllegalArgumentException("Unexpected IOB label: " + l);
}
String s = IOBUtils.IOBToString(tokens, "tag");
Defensive patterns

Strategy: validation

Validate before calling

for (CoreLabel t : tokens) {
  String l = t.tag();
  if (!(l.equals("B") || l.equals("I") || l.startsWith("B-") || l.startsWith("I-")))
    throw new IllegalArgumentException("Unexpected IOB label: " + l);
}

Type guard

boolean isKnownIobLabel(String l){ return l.equals("B")||l.equals("I")||l.startsWith("B-")||l.startsWith("I-"); }

Try / catch

try { String s = IOBUtils.IOBToString(tokens, key); } catch (RuntimeException e) { /* inspect e.getMessage() for the offending label */ }

Prevention

When it happens

Trigger: Running IOBToString over classifier output whose labels were produced with a different tag set or corrupted labeling, so a label reaching the switch's else branch is unrecognized.

Common situations: Mixing label inventories between training and decoding; feeding hand-built or third-party IOB sequences with unexpected tags; classifier emitting labels the post-processor does not know (version or feature-set mismatch).

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


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

Appendix: source

Thrown at src/edu/stanford/nlp/international/arabic/process/IOBUtils.java:542

          case "ل":
            sb.append((addPrefixMarker ? prefixMarker : "") +
                (addSpace ? " " : "") +
                (applyRewrites ? "ال" : "ل"));
            break;
          case "ي":
          case "ا":
            sb.append(applyRewrites ? "ى" : token);
            break;
          case "ى":
            sb.append(applyRewrites ? "ي" : token);
            break;
          default:
            // Nonsense rewrite predicted by the classifier--just assume CONT
            sb.append(token);
            break;
        }
      } else {
        throw new RuntimeException("Unknown label: " + label);
      }
      lastLabel = label;
    }
    return sb.toString().trim();
  }
  
  private static class PrefixMarkerAnnotation implements CoreAnnotation<Boolean> {
    @Override
    public Class<Boolean> getType() {
      return Boolean.class;
    }
  }
  
  private static class SuffixMarkerAnnotation implements CoreAnnotation<Boolean> {
    @Override
    public Class<Boolean> getType() {
      return Boolean.class;
    }

View on GitHub (pinned to 1b7edd19c4)