{
  "id": "tensorflow/ragged-tensor-batch",
  "signature": "ValueError: RaggedTensor from tf.ragged.constant has inconsistent row lengths: row 2 has length 5 but expected length 3 based on first row",
  "signature_zh": "ValueError：来自tf.ragged.constant的RaggedTensor行长度不一致：第2行的长度为5，但根据第一行期望长度为3",
  "regex": "ValueError: RaggedTensor from tf\\.ragged\\.constant has inconsistent row lengths: row \\d+ has length \\d+ but expected length \\d+ based on first row",
  "domain": "tensorflow",
  "category": "type_error",
  "subcategory": null,
  "root_cause": "When creating a RaggedTensor from nested lists, the specified row lengths do not match; for a uniform-ragged conversion, all rows must have the same number of values per partition.",
  "root_cause_type": "generic",
  "root_cause_zh": "从嵌套列表创建RaggedTensor时，指定的行长度不匹配；对于统一到不规则的转换，所有分区每行的值的数量必须相同。",
  "versions": [
    {
      "version": "tensorflow>=2.8.0",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    },
    {
      "version": "python>=3.7",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    }
  ],
  "os_specific": {},
  "dead_ends": [
    {
      "action": "Using tf.ragged.constant with ragged_rank=1 to force raggedness but ignoring the structure.",
      "why_fails": "If the data is not truly ragged (i.e., variable-length), setting ragged_rank incorrectly can cause silent data corruption or downstream shape errors.",
      "fail_rate": 0.7,
      "condition": "",
      "sources": []
    },
    {
      "action": "Padding all rows to the same length with -1 values and then using tf.ragged.boolean_mask.",
      "why_fails": "Padding changes the data semantics and the mask may not correctly reconstruct the original ragged structure; also inefficient.",
      "fail_rate": 0.6,
      "condition": "",
      "sources": []
    }
  ],
  "workarounds": [
    {
      "action": "Ensure that the input nested list has consistent row lengths for the first dimension. For example, if you have variable-length sequences, use `tf.ragged.constant` with `ragged_rank=1` and provide a list of lists where each inner list can have different lengths: `tf.ragged.constant([[1,2], [3,4,5]])`. The error occurs only if you try to create a uniform tensor from ragged data.",
      "success_rate": 0.9,
      "how": "Ensure that the input nested list has consistent row lengths for the first dimension. For example, if you have variable-length sequences, use `tf.ragged.constant` with `ragged_rank=1` and provide a list of lists where each inner list can have different lengths: `tf.ragged.constant([[1,2], [3,4,5]])`. The error occurs only if you try to create a uniform tensor from ragged data.",
      "condition": "",
      "sources": []
    },
    {
      "action": "Use `tf.RaggedTensor.from_row_lengths` to explicitly specify row lengths: `tf.RaggedTensor.from_row_lengths(values=[1,2,3,4,5], row_lengths=[2,3])`. This gives full control over the ragged structure.",
      "success_rate": 0.85,
      "how": "Use `tf.RaggedTensor.from_row_lengths` to explicitly specify row lengths: `tf.RaggedTensor.from_row_lengths(values=[1,2,3,4,5], row_lengths=[2,3])`. This gives full control over the ragged structure.",
      "condition": "",
      "sources": []
    }
  ],
  "workarounds_zh": [
    "Ensure that the input nested list has consistent row lengths for the first dimension. For example, if you have variable-length sequences, use `tf.ragged.constant` with `ragged_rank=1` and provide a list of lists where each inner list can have different lengths: `tf.ragged.constant([[1,2], [3,4,5]])`. The error occurs only if you try to create a uniform tensor from ragged data.",
    "Use `tf.RaggedTensor.from_row_lengths` to explicitly specify row lengths: `tf.RaggedTensor.from_row_lengths(values=[1,2,3,4,5], row_lengths=[2,3])`. This gives full control over the ragged structure."
  ],
  "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": "RTI",
  "verification_tier": "ai_generated",
  "confidence": 0.81,
  "fix_success_rate": 0.9,
  "resolvable": "true",
  "first_seen": "2023-11-05",
  "last_confirmed": "2024-06-01",
  "last_updated": "2024-06-01",
  "evidence_count": 1,
  "tags": [],
  "locale": "en",
  "aliases": []
}