stanfordnlp/CoreNLP · error · RuntimeException

Error -- can't conditionalize a distribution of depth 1

Error message

Error -- can't conditionalize a distribution of depth 1

What it means

GeneralizedCounter.conditionalizeHelper() descends one level of the nested counter structure; a depth-1 GeneralizedCounter holds only leaf counts and has no sub-counters to condition on, so conditioning deeper is impossible and a RuntimeException is thrown. Note this exception has no depth value interpolated into the message (unlike its siblings).

Solutions

  1. Only condition while depth() > 1; check depth() before each conditionalizeOnce call
  2. Keep a reference to the original GeneralizedCounter rather than overwriting it with the conditioned (depth-reduced) result
  3. For depth-1 counters, read counts directly via getCount() instead of conditioning

Example fix

// before
GeneralizedCounter<String> gc = ...; // depth 2
gc = gc.conditionalizeOnce("a");
gc = gc.conditionalizeOnce("b"); // depth now 1 -> throws
// after
GeneralizedCounter<String> cond = gc.conditionalizeOnce("a"); // keep original gc
// use cond.getCount(Collections.singletonList("b")) for leaf lookups
Defensive patterns

Strategy: validation

Validate before calling

if (gc.depth() <= 1) {
  throw new IllegalStateException("cannot conditionalize a depth-1 GeneralizedCounter");
}

Type guard

boolean conditionable(GeneralizedCounter<?> gc) { return gc.depth() > 1; }

Try / catch

try {
  GeneralizedCounter<K> sub = gc.conditionalizeOnce(o);
} catch (RuntimeException e) {
  if (e.getMessage().contains("depth 1")) { /* use getCount on the leaf instead */ }
}

Prevention

When it happens

Trigger: Calling conditionalize(List) or conditionalizeOnce(o) on a depth-1 GeneralizedCounter, or chaining conditionalizeOnce enough times to exhaust the depth (each call reduces depth by 1, so the second call on a depth-2 counter fails).

Common situations: Building bigram-style tables (depth 2) and accidentally conditioning twice; reusing a counter variable after a prior conditionalizeOnce reduced its depth.

Understand the failure class

Background: "Invalid state transition" errors: "status must be X, actually Y", "already rejected/charging/uninstalled", "cannot ... while running" — what they mean when a library rejects your call — this error's family across 31 libraries.

Related errors


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

Appendix: source

Thrown at src/edu/stanford/nlp/stats/GeneralizedCounter.java:397

      o = i.next();
      j++;
    }
    counts[depth] = next.getCount(o);

    return counts;
  }

  /* haven't decided about access for this one yet */
  private GeneralizedCounter<K> conditionalizeHelper(K o) {
    if (depth > 1) {
      GeneralizedCounter<K> next = ErasureUtils.uncheckedCast(map.get(o));
      if (next == null) // adds a new GeneralizedCounter if needed
      {
        map.put(o, (next = new GeneralizedCounter<>(depth - 1)));
      }
      return next;
    } else {
      throw new RuntimeException("Error -- can't conditionalize a distribution of depth 1");
    }
  }

  /**
   * returns a GeneralizedCounter conditioned on the objects in the
   * {@link List} argument. The length of the argument {@link List}
   * must be less than the depth of the GeneralizedCounter.
   */
  public GeneralizedCounter<K> conditionalize(List<K> l) {
    int n = l.size();
    if (n >= depth()) {
      throw new RuntimeException("Error -- attempted to conditionalize a GeneralizedCounter of depth " + depth() + " on a vector of length " + n);
    } else {
      GeneralizedCounter<K> next = this;
      for (K o: l) {
        next = next.conditionalizeHelper(o);
      }
      return next;

View on GitHub (pinned to 1b7edd19c4)