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

- **ID:** `tensorflow/ragged-tensor-to-sparse-invalid-splits`
- **领域:** tensorflow
- **类别:** data_error
- **错误码:** `RTS`
- **验证级别:** ai_generated
- **修复率:** 75%

## 根因

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

## 版本兼容性

| 版本 | 状态 | 引入 | 弃用 |
|------|------|------|------|
| tensorflow 2.10 | active | — | — |
| tensorflow 2.11 | active | — | — |
| tensorflow 2.12 | active | — | — |
| tensorflow 2.13 | active | — | — |

## 解决方案

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)
   ```

## 无效尝试

- **Using tf.debugging.assert_all_values_non_negative on the entire tensor** — The error is in the splits structure, not the values; the assert would not catch the issue in row lengths. (85% 失败率)
- **Setting allow_negative=True on RaggedTensor constructor (non-existent flag)** — There is no such flag; negative row lengths are always invalid. (99% 失败率)
