RTS tensorflow data_error ai_generated partial

InvalidArgumentError: Row lengths must be non-negative. Got values: [-1, 3, 2]

ID: tensorflow/ragged-tensor-to-sparse-invalid-splits

Also available as: JSON · Markdown · 中文
75%Fix Rate
84%Confidence
1Evidence
2023-09-30First Seen

Version Compatibility

VersionStatusIntroducedDeprecatedNotes
tensorflow 2.10 active
tensorflow 2.11 active
tensorflow 2.12 active
tensorflow 2.13 active

Root Cause

Ragged tensor construction or conversion to sparse tensor encountered negative row lengths, typically due to corrupted data or incorrect indexing in nested tf.RaggedTensor.from_row_splits.

generic

中文

不规则张量构造或转换为稀疏张量时遇到负行长度,通常是由于数据损坏或嵌套 tf.RaggedTensor.from_row_splits 中的索引错误。

Official Documentation

https://www.tensorflow.org/api_docs/python/tf/RaggedTensor

Workarounds

  1. 80% success Validate and sanitize row splits before constructing RaggedTensor: row_splits = [0, 2, 5, 8]; row_splits = tf.maximum(row_splits, 0); row_splits = tf.cast(row_splits, tf.int64); rt = tf.RaggedTensor.from_row_splits(values, row_splits)
    Validate and sanitize row splits before constructing RaggedTensor: row_splits = [0, 2, 5, 8]; row_splits = tf.maximum(row_splits, 0); row_splits = tf.cast(row_splits, tf.int64); rt = tf.RaggedTensor.from_row_splits(values, row_splits)
  2. 75% success Use tf.RaggedTensor.from_value_rowids instead of from_row_splits if row lengths are derived from data: value_rowids = [0, 0, 1, 1, 1, 2, 2, 2]; rt = tf.RaggedTensor.from_value_rowids(values, value_rowids)
    Use tf.RaggedTensor.from_value_rowids instead of from_row_splits if row lengths are derived from data: value_rowids = [0, 0, 1, 1, 1, 2, 2, 2]; rt = tf.RaggedTensor.from_value_rowids(values, value_rowids)

中文步骤

  1. Validate and sanitize row splits before constructing RaggedTensor: row_splits = [0, 2, 5, 8]; row_splits = tf.maximum(row_splits, 0); row_splits = tf.cast(row_splits, tf.int64); rt = tf.RaggedTensor.from_row_splits(values, row_splits)
  2. Use tf.RaggedTensor.from_value_rowids instead of from_row_splits if row lengths are derived from data: value_rowids = [0, 0, 1, 1, 1, 2, 2, 2]; rt = tf.RaggedTensor.from_value_rowids(values, value_rowids)

Dead Ends

Common approaches that don't work:

  1. Using tf.debugging.assert_all_values_non_negative on the entire tensor 85% fail

    The error is in the splits structure, not the values; the assert would not catch the issue in row lengths.

  2. Setting allow_negative=True on RaggedTensor constructor (non-existent flag) 99% fail

    There is no such flag; negative row lengths are always invalid.