stanfordnlp/CoreNLP · error · UnsupportedOperationException

CRFLogConditionalObjectiveFloatFunction is not clique…

Error message

CRFLogConditionalObjectiveFloatFunction is not clique potential compatible yet

What it means

getCliquePotentialFunction is part of the clique-potential-based CRF training API, but the float-precision objective function was never implemented for it. Any code path that requests a clique potential function from CRFLogConditionalObjectiveFloatFunction gets this UnsupportedOperationException — it is a deliberate not-implemented marker.

Solutions

  1. Use the double-precision CRFLogConditionalObjectiveFunction, which implements getCliquePotentialFunction.
  2. Avoid trainer/API combinations that call getCliquePotentialFunction with the float objective.
  3. If float precision is required, implement getCliquePotentialFunction by wrapping to2D(weights) in a float CliquePotentialFunction.
  4. Check the Stanford NLP version for updates where float clique-potential support may have been added.

Example fix

// before
CRFLogConditionalObjectiveFloatFunction func = new CRFLogConditionalObjectiveFloatFunction(...);
trainer.setObjective(func); // calls getCliquePotentialFunction -> throws
// after
CRFLogConditionalObjectiveFunction func = new CRFLogConditionalObjectiveFunction(data, labels, classIndex, labelIndices, map, "L2");
Defensive patterns

Strategy: try-catch

Validate before calling

if (objective instanceof CRFLogConditionalObjectiveFloatFunction)
  throw new UnsupportedOperationException("float objective does not support clique potentials; use CRFLogConditionalObjectiveFunction");

Type guard

static boolean supportsCliquePotential(Object f) {
  return !(f instanceof CRFLogConditionalObjectiveFloatFunction);
}

Try / catch

try {
  CliquePotentialFunction cpf = func.getCliquePotentialFunction(x);
} catch (UnsupportedOperationException e) {
  func = new CRFLogConditionalObjectiveFunction(data, labels, window, classIndex, labelIndices, map, priorType, backgroundSymbol, sigma, featureVal, gradThreads);
  CliquePotentialFunction cpf = func.getCliquePotentialFunction(x);
}

Prevention

When it happens

Trigger: Invoking training/decoding code paths that require CliquePotentialFunction (e.g. certain custom potential or factor-based trainers) while using the float variant of the CRF log-conditional objective.

Common situations: Switching CRFClassifier to float weights (FloatCRF variants) and then using a trainer or objective that assumes the double-precision clique potential API.

Understand the failure class

Background: UnsupportedOperationException and "is not supported" errors: when a library deliberately refuses a call — this error's family across 30 libraries.

Related errors


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

Appendix: source

Thrown at src/edu/stanford/nlp/ie/crf/CRFLogConditionalObjectiveFloatFunction.java:84

    this.backgroundSymbol = backgroundSymbol;
    this.sigma = (float) sigma;
    empiricalCounts(data, labels);
  }

  @Override
  public int domainDimension() {
    if (domainDimension < 0) {
      domainDimension = 0;
      for (int aMap : map) {
        domainDimension += labelIndices.get(aMap).size();
      }
    }
    return domainDimension;
  }

  @Override
  public CliquePotentialFunction getCliquePotentialFunction(double[] x) {
    throw new UnsupportedOperationException("CRFLogConditionalObjectiveFloatFunction is not clique potential compatible yet");
  }

  public float[][] to2D(float[] weights) {
    float[][] newWeights = new float[map.length][];
    int index = 0;
    for (int i = 0; i < map.length; i++) {
      newWeights[i] = new float[labelIndices.get(map[i]).size()];
      System.arraycopy(weights, index, newWeights[i], 0, labelIndices.get(map[i]).size());
      index += labelIndices.get(map[i]).size();
    }
    return newWeights;
  }

  public float[] to1D(float[][] weights) {
    float[] newWeights = new float[domainDimension()];
    int index = 0;
    for (float[] weight : weights) {
      System.arraycopy(weight, 0, newWeights, index, weight.length);

View on GitHub (pinned to 1b7edd19c4)