<br />

|---|
| [![](https://www.tensorflow.org/images/GitHub-Mark-32px.png) View source on GitHub](https://github.com/keras-team/keras/tree/v3.15.1/keras/src/ops/nn.py#L2588-L2652) |

Decodes the output of a CTC model.

#### View aliases


**Main aliases**

[`tf.keras.ops.nn.ctc_decode`](https://www.tensorflow.org/api_docs/python/tf/keras/ops/ctc_decode)

<br />

    tf.keras.ops.ctc_decode(
        inputs,
        sequence_lengths,
        strategy='greedy',
        beam_width=100,
        top_paths=1,
        merge_repeated=True,
        mask_index=0
    )

<br />

<br />

<br />

| ## Args ||
|---|---|
| `inputs` | A tensor of shape `(batch_size, max_length, num_classes)` containing the logits (the output of the model). They should *not* be normalized via softmax. |
| `sequence_lengths` | A tensor of shape `(batch_size,)` containing the sequence lengths for the batch. |
| `strategy` | A string for the decoding strategy. Supported values are `"greedy"` and `"beam_search"`. |
| `beam_width` | An integer scalar beam width used in beam search. Defaults to 100. |
| `top_paths` | An integer scalar, the number of top paths to return. Defaults to 1. |
| `merge_repeated` | A boolean scalar, whether to merge repeated labels in the output. Defaults to `True`. |
| `mask_index` | An integer scalar, the index of the mask character in the vocabulary. Defaults to `0`. |

<br />

<br />

<br />

| ## Returns ||
|---|---|
| A tuple containing: <br /> - The tensor representing the list of decoded sequences. If `strategy="greedy"`, the shape is `(1, batch_size, max_length)`. If `strategy="beam_search"`, the shape is `(top_paths, batch_size, max_length)`. Note that: `-1` indicates the blank label. - If `strategy="greedy"`, a tensor of shape `(batch_size, 1)` representing the negative of the sum of the probability logits for each sequence. If `strategy="beam_seatch"`, a tensor of shape `(batch_size, top_paths)` representing the log probability for each sequence. ||

<br />