{
  "id": "tensorflow/ragged-tensor-to-sparse-invalid-splits",
  "signature": "InvalidArgumentError: Row lengths must be non-negative. Got values: [-1, 3, 2]",
  "signature_zh": "无效参数错误：行长度必须为非负。得到值：[-1, 3, 2]",
  "regex": "Row lengths must be non-negative\\. Got values: \\[.*\\]",
  "domain": "tensorflow",
  "category": "data_error",
  "subcategory": null,
  "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.",
  "root_cause_type": "generic",
  "root_cause_zh": "不规则张量构造或转换为稀疏张量时遇到负行长度，通常是由于数据损坏或嵌套 tf.RaggedTensor.from_row_splits 中的索引错误。",
  "versions": [
    {
      "version": "tensorflow 2.10",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    },
    {
      "version": "tensorflow 2.11",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    },
    {
      "version": "tensorflow 2.12",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    },
    {
      "version": "tensorflow 2.13",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    }
  ],
  "os_specific": {},
  "dead_ends": [
    {
      "action": "Using tf.debugging.assert_all_values_non_negative on the entire tensor",
      "why_fails": "The error is in the splits structure, not the values; the assert would not catch the issue in row lengths.",
      "fail_rate": 0.85,
      "condition": "",
      "sources": []
    },
    {
      "action": "Setting allow_negative=True on RaggedTensor constructor (non-existent flag)",
      "why_fails": "There is no such flag; negative row lengths are always invalid.",
      "fail_rate": 0.99,
      "condition": "",
      "sources": []
    }
  ],
  "workarounds": [
    {
      "action": "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)",
      "success_rate": 0.8,
      "how": "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)",
      "condition": "",
      "sources": []
    },
    {
      "action": "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)",
      "success_rate": 0.75,
      "how": "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)",
      "condition": "",
      "sources": []
    }
  ],
  "workarounds_zh": [
    "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)",
    "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)"
  ],
  "transition_graph": {
    "leads_to": [],
    "preceded_by": [],
    "frequently_confused_with": []
  },
  "official_doc_url": "https://www.tensorflow.org/api_docs/python/tf/RaggedTensor",
  "official_doc_section": null,
  "error_code": "RTS",
  "verification_tier": "ai_generated",
  "confidence": 0.84,
  "fix_success_rate": 0.75,
  "resolvable": "partial",
  "first_seen": "2023-09-30",
  "last_confirmed": "2024-06-01",
  "last_updated": "2024-06-01",
  "evidence_count": 1,
  "tags": [],
  "locale": "en",
  "aliases": []
}