{"record":{"id":"393fcfd702837023","repo":"keras-team/keras","slug":"targets-y-true-are-expected-to-be-a-tensor-of-sh","errorCode":null,"errorMessage":"Targets `y_true` are expected to be a tensor of shape `(batch_size, max_length)` in integer format. Received: y_true.shape={ops.shape(y_true)}","messagePattern":"Targets `y_true` are expected to be a tensor of shape `\\(batch_size, max_length\\)` in integer format\\. Received: y_true\\.shape=(.+?)","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"keras/src/losses/losses.py","lineNumber":2541,"sourceCode":"        focal_bce = weight * focal_bce\n\n    return ops.mean(focal_bce, axis=axis)\n\n\n@keras_export(\"keras.losses.ctc\")\ndef ctc(y_true, y_pred):\n    \"\"\"CTC (Connectionist Temporal Classification) loss.\n\n    Args:\n        y_true: A tensor of shape `(batch_size, max_length)` containing\n            the true labels in integer format. `0` always represents\n            the blank/mask index and should not be used for classes.\n        y_pred: A tensor of shape `(batch_size, max_length, num_classes)`\n            containing logits (the output of your model).\n            They should *not* be normalized via softmax.\n    \"\"\"\n    if len(ops.shape(y_true)) != 2:\n        raise ValueError(\n            \"Targets `y_true` are expected to be a tensor of shape \"\n            \"`(batch_size, max_length)` in integer format. \"\n            f\"Received: y_true.shape={ops.shape(y_true)}\"\n        )\n    if len(ops.shape(y_pred)) != 3:\n        raise ValueError(\n            \"Logits `y_pred` are expected to be a tensor of shape \"\n            \"`(batch_size, max_length, num_classes)`. \"\n            f\"Received: y_pred.shape={ops.shape(y_pred)}\"\n        )\n\n    mask_index = 0\n    batch_length = ops.shape(y_pred)[0]\n    input_length = ops.shape(y_pred)[1]\n    input_length = input_length * ops.ones((batch_length,), dtype=\"int32\")\n    label_length = ops.cast(\n        ops.sum(y_true != mask_index, axis=-1), dtype=\"int32\"\n    )","sourceCodeStart":2523,"sourceCodeEnd":2559,"githubUrl":"https://github.com/keras-team/keras/blob/7a34a03db60bf60042242d6a556fc3be119046a5/keras/src/losses/losses.py#L2523-L2559","documentation":"Error \"Targets `y_true` are expected to be a tensor of shape `(batch_size, max_length)` in integer format. Received: y_true.shape={ops.shape(y_true)}\" thrown in keras-team/keras.","triggerScenarios":"Thrown at keras/src/losses/losses.py:2541 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":[],"exampleFix":null,"handlingStrategy":null,"validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"7a34a03db60bf60042242d6a556fc3be119046a5","analyzedAt":"2026-08-25T21:25:25.994Z","schemaVersion":2},"datasetVersion":"2026-08-26T02:17:13.382Z"}