stanfordnlp/CoreNLP · error · UnsupportedOperationException
Cannot make normalized counter with Dynamic prior.
Error message
Cannot make normalized counter with Dynamic prior.
What it means
distributionWithDirichletPrior() mixes a counter with a prior Distribution, but a DynamicDistribution prior can change over time and therefore cannot yield a fixed normalized mixture. The method detects this and throws UnsupportedOperationException rather than producing an incorrect static distribution.
Solutions
- Use a static Distribution as the prior (e.g. Distribution.uniform(counter))
- Materialize the dynamic prior into a static snapshot Distribution before mixing
- If dynamic behavior is required, implement the mixture manually and recompute on each prior update
Example fix
// before Distribution<String> d = Distribution.distributionWithDirichletPrior(c, dynamicPrior, 1.0); // after Distribution<String> staticPrior = Distribution.uniform(c); Distribution<String> d = Distribution.distributionWithDirichletPrior(c, staticPrior, 1.0);
Defensive patterns
Strategy: type-guard
Validate before calling
if (prior instanceof DynamicDistribution) {
// choose a static prior instead
} Type guard
boolean isStaticPrior(Distribution<?> prior) { return !(prior instanceof DynamicDistribution); } Try / catch
try {
Distribution<E> d = Distribution.distributionWithDirichletPrior(c, prior, weight);
} catch (UnsupportedOperationException e) {
prior = Distribution.uniform(c);
Distribution<E> d = Distribution.distributionWithDirichletPrior(c, prior, weight);
} Prevention
- Keep dynamic priors out of static-mixing APIs; snapshot them first
- Type-check the prior with instanceof DynamicDistribution at call sites
- Document prior requirements in wrapper methods
When it happens
Trigger: Calling Distribution.distributionWithDirichletPrior(c, prior, weight) where prior is an instance of DynamicDistribution (or a subclass).
Common situations: Developers switching from a static prior (e.g. Distribution.uniform) to an adaptive/online prior without realizing the Dirichlet-mixing path does not support dynamic priors.
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
- Attempt to use ExternalFiniteDifference without passing…
- BackRefPatternExpr.transform not implemented yet!!! Please…
- Bad arguments: " + x + " and " + lambda
- BiLexPCFGParser doesn't support best parses
- BiLexPCFGParser doesn't support k best parses
AI-assisted analysis of stanfordnlp/CoreNLP@1b7edd19c4 (2026-09-10).
Data as JSON: /api/errors/d91adc6480b92790.
Report an issue: GitHub.
Appendix: source
Thrown at src/edu/stanford/nlp/stats/Distribution.java:548
/**
* Returns a Distribution that uses prior as a Dirichlet prior
* weighted by weight. Essentially adds "pseudo-counts" for each Object
* in prior equal to that Object's mass in prior times weight,
* then normalizes.
* <p>
* WARNING: If unseen item is encountered in c, total may not be 1.
* NOTE: This will not work if prior is a DynamicDistribution
* to fix this, you could add a CounterView to Distribution and use that
* in the linearCombination call below
*
* @param weight multiplier of prior to get "pseudo-count"
* @return new Distribution
*/
public static <E> Distribution<E> distributionWithDirichletPrior(Counter<E> c, Distribution<E> prior, double weight) {
Distribution<E> norm = new Distribution<>();
double totalWeight = c.totalCount() + weight;
if (prior instanceof DynamicDistribution) {
throw new UnsupportedOperationException("Cannot make normalized counter with Dynamic prior.");
}
norm.counter = Counters.linearCombination(c, 1 / totalWeight, prior.counter, weight / totalWeight);
norm.numberOfKeys = prior.numberOfKeys;
norm.reservedMass = prior.reservedMass * weight / totalWeight;
//System.out.println("totalCount: " + norm.totalCount());
return norm;
}
/**
* Like normalizedCounterWithDirichletPrior except probabilities are
* computed dynamically from the counter and prior instead of all at once up front.
* The main advantage of this is if you are making many distributions from relatively
* sparse counters using the same relatively dense prior, the prior is only represented
* once, for major memory savings.
*
* @param weight multiplier of prior to get "pseudo-count"
* @return new Distribution
*/View on GitHub (pinned to 1b7edd19c4)