stanfordnlp/CoreNLP · error · IllegalArgumentException

Input array with uneven columns

Error message

Input array with uneven columns

What it means

ConvertModels.toMatrix validates that every row has the same length as row 0; a ragged List<List<Double>> throws IllegalArgumentException('Input array with uneven columns'). SimpleMatrix requires a dense rectangular shape.

Solutions

  1. Pad or truncate all rows to a uniform length before conversion
  2. Fix the feature-extraction code so every entry yields the same number of features
  3. Validate row lengths in a pre-pass and report the offending row index

Example fix

// before
SimpleMatrix m = ConvertModels.toMatrix(rows); // ragged
// after
int n = rows.get(0).size();
for (int i = 0; i < rows.size(); i++) {
  if (rows.get(i).size() != n) { throw new IllegalStateException("row " + i + " has " + rows.get(i).size() + " cols, expected " + n); }
}
SimpleMatrix m = ConvertModels.toMatrix(rows);
Defensive patterns

Strategy: validation

Validate before calling

int expected = rows.get(0).size();
for (int i = 0; i < rows.size(); i++) {
  if (rows.get(i).size() != expected) {
    throw new IllegalArgumentException("row " + i + " has " + rows.get(i).size() + " columns, expected " + expected);
  }
}

Type guard

static boolean isRectangular(java.util.List<java.util.List<Double>> rows) {
  if (rows == null || rows.isEmpty()) return false;
  int n = rows.get(0).size();
  return rows.stream().allMatch(r -> r != null && r.size() == n);
}

Try / catch

try {
  SimpleMatrix m = ConvertModels.toMatrix(rows);
} catch (IllegalArgumentException e) {
  if (e.getMessage().contains("uneven columns")) {
    throw new IllegalStateException("ragged feature table; regenerate the model", e);
  }
  throw e;
}

Prevention

When it happens

Trigger: Calling toMatrix where some row i>0 has size != in.get(0).size(), e.g. inconsistent feature counts across word vectors or pair features.

Common situations: Hand-edited or partially-written model files, mixing feature sets from different model versions, or a bug in the code assembling rows.

Understand the failure class

Background: Tensor shape mismatch errors ("must have shape", "expected shape ... got ..."): when tensor dimensions disagree with what an op or layer was told to expect — this error's family across 6 libraries.

Related errors


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

Appendix: source

Thrown at src/edu/stanford/nlp/neural/ConvertModels.java:87

    List<List<List<Double>>> out = new ArrayList<>();

    for (int i = 0; i < in.numSlices(); ++i) {
      out.add(fromMatrix(in.getSlice(i)));
    }

    return out;
  }

  public static SimpleMatrix toMatrix(List<List<Double>> in) {
    if (in.size() == 0) {
      throw new IllegalArgumentException("Input array with 0 rows");
    }
    if (in.get(0).size() == 0) {
      throw new IllegalArgumentException("Input array with 0 columns");
    }
    for (int i = 1; i < in.size(); ++i) {
      if (in.get(i).size() != in.get(0).size()) {
        throw new IllegalArgumentException("Input array with uneven columns");
      }
    }

    SimpleMatrix out = new SimpleMatrix(in.size(), in.get(0).size());
    for (int i = 0; i < in.size(); ++i) {
      List<Double> row = in.get(i);
      for (int j = 0; j < row.size(); ++j) {
        out.set(i, j, row.get(j));
      }
    }

    return out;
  }

  public static SimpleTensor toTensor(List<List<List<Double>>> in) {
    int numSlices = in.size();
    SimpleMatrix[] slices = new SimpleMatrix[numSlices];
    for (int i = 0; i < numSlices; ++i) {

View on GitHub (pinned to 1b7edd19c4)