RTS tensorflow data_error ai_generated partial

无效参数错误:行长度必须为非负。得到值:[-1, 3, 2]

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

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

其他格式: JSON · Markdown 中文 · English
75%修复率
84%置信度
1证据数
2023-09-30首次发现

版本兼容性

版本状态引入弃用备注
tensorflow 2.10 active
tensorflow 2.11 active
tensorflow 2.12 active
tensorflow 2.13 active

根因分析

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

English

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

官方文档

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

解决方案

  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)

无效尝试

常见但无效的做法:

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

    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% 失败

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