Trying to train the TFWav2Vec2ForCTC model
## Environment info
<!-- You can run the command `transformers-cli env` and copy-and-paste its output below.
     Don't forget to fill out the missing fields in that output! -->

- `transformers` version: 4.15.0
- Platform: Colab


### Who can help: @patrickvonplaten @anton-l
<!-- Your issue will be replied to more quickly if you can figure out the right person to tag with @patrickvonplaten @anton-l
 If you know how to use git blame, that is the easiest way, otherwise, here is a rough guide of **who to tag**.
 Please tag fewer than 3 people.

Models:

- ALBERT, BERT, XLM, DeBERTa, DeBERTa-v2, ELECTRA, MobileBert, SqueezeBert: @LysandreJik
- T5, BART, Marian, Pegasus, EncoderDecoder: @patrickvonplaten
- Blenderbot, MBART: @patil-suraj
- Longformer, Reformer, TransfoXL, XLNet, FNet, BigBird: @patrickvonplaten
- FSMT: @stas00
- Funnel: @sgugger
- GPT-2, GPT: @patrickvonplaten, @LysandreJik
- RAG, DPR: @patrickvonplaten, @lhoestq
- TensorFlow: @Rocketknight1
- JAX/Flax: @patil-suraj
- TAPAS, LayoutLM, LayoutLMv2, LUKE, ViT, BEiT, DEiT, DETR, CANINE: @NielsRogge
- GPT-Neo, GPT-J, CLIP: @patil-suraj
- Wav2Vec2, HuBERT, SpeechEncoderDecoder, UniSpeech, UniSpeechSAT, SEW, SEW-D, Speech2Text: @patrickvonplaten, @anton-l

If the model isn't in the list, ping @LysandreJik who will redirect you to the correct contributor.

Library:

- Benchmarks: @patrickvonplaten
- Deepspeed: @stas00
- Ray/raytune: @richardliaw, @amogkam
- Text generation: @patrickvonplaten @narsil
- Tokenizers: @SaulLu
- Trainer: @sgugger
- Pipelines: @Narsil
- Speech: @patrickvonplaten, @anton-l
- Vision: @NielsRogge, @sgugger

Documentation: @sgugger

Model hub:

- for issues with a model, report at https://discuss.huggingface.co/ and tag the model's creator.

HF projects:

- datasets: [different repo](https://github.com/huggingface/datasets)
- rust tokenizers: [different repo](https://github.com/huggingface/tokenizers)

Examples:

- maintained examples (not research project or legacy): @sgugger, @patil-suraj

For research projetcs, please ping the contributor directly. For example, on the following projects:

- research_projects/bert-loses-patience: @JetRunner
- research_projects/distillation: @VictorSanh

 -->

## Information

Model I am using Wav2Vec2 on TensorFlow:

We are trying to use the TFWav2Vec2ForCTC. We can make the prediction but can not train the model. For this we create a random dataset just to text the fitting and give an error.

This is the following code:

```
import tensorflow as tf
from transformers import Wav2Vec2Processor, TFWav2Vec2ForCTC

processor = Wav2Vec2Processor.from_pretrained("facebook/wav2vec2-base-960h")
model = TFWav2Vec2ForCTC.from_pretrained("facebook/wav2vec2-base-960h")

# parameters
AUDIO_MAXLEN = 246000
LABEL_MAXLEN = 256
BATCH_SIZE = 1
VOCAB_SIZE = 32

LEARNING_RATE = 5e-5


def CTCLoss(y_true, y_pred):
    # Compute the training-time loss value
    batch_len = tf.cast(tf.shape(y_true)[0], dtype="int64")
    input_length = tf.cast(tf.shape(y_pred)[1], dtype="int64")
    label_length = tf.cast(tf.shape(y_true)[1], dtype="int64")

    input_length = input_length * tf.ones(shape=(batch_len, 1), dtype="int64")
    label_length = label_length * tf.ones(shape=(batch_len, 1), dtype="int64")

    loss = tf.keras.backend.ctc_batch_cost(y_true, y_pred, input_length, label_length)
    return loss

loss_fn = CTCLoss
optimizer = tf.keras.optimizers.Adam(LEARNING_RATE)
model.compile(optimizer, loss=loss_fn)



def create_random_dataset():
    def gen():
        yield (
            np.random.random((1, AUDIO_MAXLEN)),
            np.random.randint(0, VOCAB_SIZE, LABEL_MAXLEN)                
        )
    
    dataset = tf.data.Dataset.from_generator(
        gen,
        output_types=(tf.float32, tf.int32),
        output_shapes=((1, AUDIO_MAXLEN), (LABEL_MAXLEN, ))
    )
    return dataset


train_dataset = create_random_dataset()
valid_dataset = create_random_dataset()

```

The error arises when we try to ```.fit``` the model in the TF architecture:

command: ``` model.fit(train_dataset, validation_data=valid_dataset, epochs=1, verbose=2, batch_size=BATCH_SIZE)  ```

``` 
OperatorNotAllowedInGraphError            Traceback (most recent call last)
<ipython-input-17-2c9e72985c37> in <module>
----> 1 model.fit(train_dataset, validation_data=valid_dataset, epochs=1, verbose=2, batch_size=BATCH_SIZE)


OperatorNotAllowedInGraphError: in user code:

    File "/home/jovyan/.local/lib/python3.8/site-packages/keras/engine/training.py", line 878, in train_function  *
        return step_function(self, iterator)
    File "/home/jovyan/.local/lib/python3.8/site-packages/keras/engine/training.py", line 867, in step_function  **
        outputs = model.distribute_strategy.run(run_step, args=(data,))
    File "/home/jovyan/.local/lib/python3.8/site-packages/keras/engine/training.py", line 860, in run_step  **
        outputs = model.train_step(data)
    File "/home/jovyan/.local/lib/python3.8/site-packages/transformers/modeling_tf_utils.py", line 889, in train_step
        y_pred = self(x, training=True)
    File "/home/jovyan/.local/lib/python3.8/site-packages/keras/utils/traceback_utils.py", line 67, in error_handler
        raise e.with_traceback(filtered_tb) from None

    OperatorNotAllowedInGraphError: Exception encountered when calling layer "tf_wav2_vec2_for_ctc" (type TFWav2Vec2ForCTC).
    
    in user code:
    
        File "/home/jovyan/.local/lib/python3.8/site-packages/transformers/models/wav2vec2/modeling_tf_wav2vec2.py", line 1557, in call  *
            outputs = self.wav2vec2(
        File "/home/jovyan/.local/lib/python3.8/site-packages/keras/utils/traceback_utils.py", line 67, in error_handler  **
            raise e.with_traceback(filtered_tb) from None
    
        OperatorNotAllowedInGraphError: Exception encountered when calling layer "wav2vec2" (type TFWav2Vec2MainLayer).
        
        in user code:
        
            File "/home/jovyan/.local/lib/python3.8/site-packages/transformers/models/wav2vec2/modeling_tf_wav2vec2.py", line 1228, in call  *
                hidden_states = self._mask_hidden_states(hidden_states, mask_time_indices=mask_time_indices)
            File "/home/jovyan/.local/lib/python3.8/site-packages/transformers/models/wav2vec2/modeling_tf_wav2vec2.py", line 1159, in _mask_hidden_states  *
                mask_time_indices = _compute_mask_indices(
            File "/home/jovyan/.local/lib/python3.8/site-packages/transformers/models/wav2vec2/modeling_tf_wav2vec2.py", line 231, in _compute_mask_indices  *
                num_masked_spans = max(num_masked_spans, min_masks)
        
            OperatorNotAllowedInGraphError: using a `tf.Tensor` as a Python `bool` is not allowed: AutoGraph did convert this function. This might indicate you are trying to use an unsupported feature.
        
        
        Call arguments received:
          • input_values=tf.Tensor(shape=(1, 246000), dtype=float32)
          • attention_mask=None
          • token_type_ids=None
          • position_ids=None
          • head_mask=None
          • inputs_embeds=None
          • output_attentions=False
          • output_hidden_states=False
          • return_dict=True
          • training=True
          • kwargs=<class 'inspect._empty'>
 ```

## To reproduce the error:  
https://colab.research.google.com/drive/10locy1XqKF4hlkJ2uCchAtxQ4oAjz4nH?usp=sharing


<!-- If you have code snippets, error messages, stack traces please provide them here as well.
     Important! Use code tags to correctly format your code. See https://help.github.com/en/github/writing-on-github/creating-and-highlighting-code-blocks#syntax-highlighting
     Do not use screenshots, as they are hard to read and (more importantly) don't allow others to copy-and-paste your code.-->

## Expected behavior
I would like to find a way asap to finetune a TensorFlow model of wav2vec2, any recommendation would be great.

<!-- A clear and concise description of what you would expect to happen. -->

Interesting! cc @anton-l and TF squad {@Rocketknight1, @gante} <|||||>Taking a look<|||||>After some exploration, here are some findings:

@lucasagrizzi, thank you for the provided script, it was very helpful to debug 🙏  There were a few minor issues in the original script -- the generated random labels were not batched and with `CTCLoss` the maximum label has to be `VOCAB_SIZE-2` (see [this](https://github.com/MaybeShewill-CV/CRNN_Tensorflow/issues/69#issuecomment-383992527) answer).

After making the changes above, I run into the (unresolved) issue originally found [here](https://github.com/huggingface/transformers/issues/15059), with a slightly modified error:
```
Traceback (most recent call last):
  File "test.py", line 57, in <module>
    model.fit(train_dataset, validation_data=valid_dataset, epochs=1, verbose=2, batch_size=BATCH_SIZE)
  File "/home/joao_huggingface_co/hf/lib/python3.8/site-packages/keras/utils/traceback_utils.py", line 67, in error_handler
    raise e.with_traceback(filtered_tb) from None
  File "/home/joao_huggingface_co/transformers/src/transformers/modeling_tf_utils.py", line 892, in train_step
    self.optimizer.minimize(loss, self.trainable_variables, tape=tape)
tensorflow.python.framework.errors_impl.InvalidArgumentError: Computed input depth 768 doesn't match filter input depth 48 [Op:Conv2DBackpropInput]
```

I will take a look at this issue, and will let you know of updates.

For reference, here is the modified test script:
<details>
<summary>Modified test script</summary>
<pre>

```python
import numpy as np
import tensorflow as tf
from transformers import Wav2Vec2Processor, TFWav2Vec2ForCTC

processor = Wav2Vec2Processor.from_pretrained("facebook/wav2vec2-base-960h")
model = TFWav2Vec2ForCTC.from_pretrained("facebook/wav2vec2-base-960h")

# parameters
AUDIO_MAXLEN = 246000
LABEL_MAXLEN = 256
BATCH_SIZE = 1
VOCAB_SIZE = 32

LEARNING_RATE = 5e-5


def CTCLoss(y_true, y_pred):
    # Compute the training-time loss value
    batch_len = tf.cast(tf.shape(y_true)[0], dtype="int64")
    input_length = tf.cast(tf.shape(y_pred)[1], dtype="int64")
    label_length = tf.cast(tf.shape(y_true)[1], dtype="int64")

    input_length = input_length * tf.ones(shape=(batch_len, 1), dtype="int64")
    label_length = label_length * tf.ones(shape=(batch_len, 1), dtype="int64")

    loss = tf.keras.backend.ctc_batch_cost(y_true, y_pred, input_length, label_length)
    return loss

loss_fn = CTCLoss
optimizer = tf.keras.optimizers.Adam(LEARNING_RATE)
model.compile(optimizer, loss=loss_fn, run_eagerly=True)



def create_random_dataset():
    def gen():
        yield (
            np.random.random((1, AUDIO_MAXLEN)),
            np.random.randint(0, VOCAB_SIZE-1, (1, LABEL_MAXLEN))
        )

    dataset = tf.data.Dataset.from_generator(
        gen,
        output_types=(tf.float32, tf.int32),
        output_shapes=((1, AUDIO_MAXLEN), (1, LABEL_MAXLEN))
    )
    return dataset


train_dataset = create_random_dataset()
valid_dataset = create_random_dataset()

model.fit(train_dataset, validation_data=valid_dataset, epochs=1, verbose=2, batch_size=BATCH_SIZE)
```

</pre>
</details>
<|||||>Hi everyone
I've been having similar issues trying to fine tune the TFWav2Vec2ForCTC. I'm also working on Colab, on Transformers version 4.15.0
I'm currently able to run the modified test script supplied by @gante without problems. However, I want to use the model's internal loss computation, in order to correctly handle padded inputs and labels in the CTC calculation. Further modifying the previous script as a dummy example, I get the following error when trying that approach. Is there something I'm missing? Sorry for the troubles and thank you in advance.

```
All model checkpoint layers were used when initializing TFWav2Vec2ForCTC.

All the layers of TFWav2Vec2ForCTC were initialized from the model checkpoint at facebook/wav2vec2-base-960h.
If your task is similar to the task the model of the checkpoint was trained on, you can already use TFWav2Vec2ForCTC for predictions without further training.
No loss specified in compile() - the model's internal loss computation will be used as the loss. Don't panic - this is a common way to train TensorFlow models in Transformers! Please ensure your labels are passed as the 'labels' key of the input dict so that they are accessible to the model during the forward pass. To disable this behaviour, please pass a loss argument, or explicitly pass loss=None if you do not want your model to compute a loss.
---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
<ipython-input-1-03dc269f6ab7> in <module>()
     51 valid_dataset = create_random_dataset()
     52 
---> 53 model.fit(train_dataset, validation_data=valid_dataset, epochs=1, verbose=2, batch_size=BATCH_SIZE)

1 frames
/usr/local/lib/python3.7/dist-packages/keras/utils/traceback_utils.py in error_handler(*args, **kwargs)
     65     except Exception as e:  # pylint: disable=broad-except
     66       filtered_tb = _process_traceback_frames(e.__traceback__)
---> 67       raise e.with_traceback(filtered_tb) from None
     68     finally:
     69       del filtered_tb

/usr/local/lib/python3.7/dist-packages/transformers/modeling_tf_utils.py in train_step(self, data)
    890             loss = self.compiled_loss(y, y_pred, sample_weight, regularization_losses=self.losses)
    891         # Run backwards pass.
--> 892         self.optimizer.minimize(loss, self.trainable_variables, tape=tape)
    893         # When y_pred is a ModelOutput and y is a tf.Tensor the metrics update
    894         # should be done only with the relevant ModelOutput param that is

ValueError: No gradients provided for any variable: (['tf_wav2_vec2_for_ctc/wav2vec2/masked_spec_embed:0', 'tf_wav2_vec2_for_ctc/wav2vec2/feature_extractor/conv_layers.0/conv/kernel:0', 'tf_wav2_vec2_for_ctc/wav2vec2/feature_extractor/conv_layers.0/layer_norm/gamma:0', 'tf_wav2_vec2_for_ctc/wav2vec2/feature_extractor/conv_layers.0/layer_norm/beta:0', 'tf_wav2_vec2_for_ctc/wav2vec2/feature_extractor/conv_layers.1/conv/kernel:0', 'tf_wav2_vec2_for_ctc/wav2vec2/feature_extractor/conv_layers.2/conv/kernel:0', 'tf_wav2_vec2_for_ctc/wav2vec2/feature_extractor/conv_layers.3/conv/kernel:0', 'tf_wav2_vec2_for_ctc/wav2vec2/feature_extractor/conv_layers.4/conv/kernel:0', 'tf_wav2_vec2_for_ctc/wav2vec2/feature_extractor/conv_layers.5/conv/kernel:0', 'tf_wav2_vec2_for_ctc/wav2vec2/feature_extractor/conv_layers.6/conv/kernel:0', 'tf_wav2_vec2_for_ctc/wav2vec2/feature_projection/layer_norm/gamma:0', 'tf_wav2_vec2_for_ctc/wav2vec2/feature_projection/layer_norm/beta:0', 'tf_wav2_vec2_for_ctc/wav2vec2/feature_projection/projection/kernel:0', 'tf_wav2_vec2_for_ctc/wav2vec2/feature_projection/projection/bias:0', 'tf_wav2_vec2_for_ctc/wav2vec2/encoder/pos_conv_embed/conv/weight_v:0', 'tf_wav2_vec2_for_ctc/wav2vec2/encoder/pos_conv_embed/conv/weight_g:0', 'tf_wav2_vec2_for_ctc/wav2vec2/encoder/pos_conv_embed/conv/bias:0', 'tf_wav2_vec2_for_ctc/wav2vec2/encoder/layer_norm/gamma:0', 'tf_wav2_vec2_for_ctc/wav2vec2/encoder/layer_norm/beta:0', 'tf_wav2_vec2_for_ctc/wav2vec2/encoder/layers...
```

This is the script I used:

```python
import numpy as np
import tensorflow as tf
from transformers import Wav2Vec2Processor, TFWav2Vec2ForCTC

processor = Wav2Vec2Processor.from_pretrained("facebook/wav2vec2-base-960h")
model = TFWav2Vec2ForCTC.from_pretrained("facebook/wav2vec2-base-960h")

# parameters
AUDIO_MAXLEN = 246000
LABEL_MAXLEN = 256
BATCH_SIZE = 1
VOCAB_SIZE = 32

LEARNING_RATE = 5e-5


def CTCLoss(y_true, y_pred):
    # Compute the training-time loss value
    batch_len = tf.cast(tf.shape(y_true)[0], dtype="int64")
    input_length = tf.cast(tf.shape(y_pred)[1], dtype="int64")
    label_length = tf.cast(tf.shape(y_true)[1], dtype="int64")

    input_length = input_length * tf.ones(shape=(batch_len, 1), dtype="int64")
    label_length = label_length * tf.ones(shape=(batch_len, 1), dtype="int64")

    loss = tf.keras.backend.ctc_batch_cost(y_true, y_pred, input_length, label_length)
    return loss

loss_fn = CTCLoss
optimizer = tf.keras.optimizers.Adam(LEARNING_RATE)
# model.compile(optimizer, loss=loss_fn, run_eagerly=True)
model.compile(optimizer, run_eagerly=True) # No loss is passed according for using internal loss, according to docs


# Modified as to have input dicts with a 'labels' key for intenal loss calculation
def create_random_dataset():
    def gen():
        yield {
            'input_values': np.random.random((1, AUDIO_MAXLEN)),
            'labels': np.random.randint(0, VOCAB_SIZE-1, (1, LABEL_MAXLEN))
        }

    dataset = tf.data.Dataset.from_generator(
        gen,
        output_types={'input_values': tf.int32, 'labels': tf.int32},
        output_shapes={'input_values': (1, AUDIO_MAXLEN), 'labels': (1, LABEL_MAXLEN)}
    )
    return dataset


train_dataset = create_random_dataset()
valid_dataset = create_random_dataset()

model.fit(train_dataset, validation_data=valid_dataset, epochs=1, verbose=2, batch_size=BATCH_SIZE)
```<|||||>Update: the script I shared above works on GPU, but fails on CPU due to upstream problems in Keras -- TF does not support backpropagation of grouped convolutions on CPU. (@lucasagrizzi)

The PR mentioned above adds an informative error message for these situations.<|||||>@dmurillo976s the script I shared (and yours) is missing a `tf.nn.softmax()` in the logits. I.e. the loss function should return ` loss = tf.keras.backend.ctc_batch_cost(y_true, tf.nn.softmax(y_pred), input_length, label_length)`<|||||>@dmurillo976s I am still facing this problem when I try to use fit() with the internal loss. Any leads or do you know how to fix it? Any help would be much appreciated!

@gante any help on how to use the internal CTC loss with the fit() method? Thank You!<|||||>@Sreyan88 sorry, it's been a while since I tested this. Unfortunately I couldn't get it working at the time, and continued using the pytorch implementation. I believe the main problem was that a dummy loss function was being used at the training step, instead of the internal loss of the model. But again, that was just my assessment at the time.

The best thing to do now should be to open a new issue.  <|||||>Hey @Sreyan88 👋 We have very recently pushed a bug change about how we process loss functions, can you try it out with `tranformers==4.20.0.dev0` (i.e. from the `main` branch)?<|||||>Hi @gante ,

Thank You for your reply. On tranformers==4.20.0.dev0 I get:

```
UnknownError: Exception encountered when calling layer "conv" (type Conv1D).

Failed to get convolution algorithm. This is probably because cuDNN failed to initialize, so try looking to see if a warning log message was printed above. [Op:Conv2D]

Call arguments received:
  • inputs=tf.Tensor(shape=(1, 16000, 1), dtype=float32)
```

just by calling `model = TFWav2Vec2ForCTC.from_pretrained(model_checkpoint,apply_spec_augment=False, from_pt = True)`

I use` tensorflow==2.7.0`, the same as I was using for `transformers==4.19.2`.<|||||>@Sreyan88 that's because TFWav2Vec2 does not work without a GPU, due to an upstream TF limitation -- see https://github.com/huggingface/transformers/pull/15612

With a GPU, I was able to run the command you shared without errors :)<|||||>Hi @gante ,
Thank you so much for your reply, it was not a GPU but a cudnn problem, I am now trying to train the model with internal loss but I get a negative ctc loss:

```
Epoch 1/5
 28/3859 [..............................] - ETA: 47:03 - loss: -0.5141
```
​by `next(iter(train))` looks like this:

```
(<tf.Tensor: shape=(2, 88480), dtype=float32, numpy=
 array([[ 0.06280634,  0.07749736,  0.06458706, ..., -0.17759225,
         -0.18961217, -0.19361882],
        [-0.01641779,  0.01576709,  0.03577391, ...,  0.        ,
          0.        ,  0.        ]], dtype=float32)>,
 <tf.Tensor: shape=(2, 78), dtype=int64, numpy=
 array([[  27,   11,   10,   23,    5,   23,   27,   20,   13,    5,    0,
           20,    1,   10,   25,   24,    2,   19,    2,   24,    5,   12,
           15,    5,   10,    2,   19,   14,   11,    1,   23,    5,    4,
           20,    8,    5,   23,   27,   11,   23,    5,   23,   27,    2,
           19,    2,    5,   25,   10,    5,    1,   20,    1,    2,    5,
           17,   25,    9,    2,    5,   27,   25,   12,    5,   13,   22,
           20,    1,    5,   23,   27,    2,    5,    2,   11,   19,   23,
           27],
        [  11,    1,   24,    5,    3,   27,   25,    1,    5,   25,    5,
           11,   10,    9,    2,   24,    5,   27,   25,   12,    5,    3,
           27,   11,   23,    5,   27,    2,    5,    3,   11,   10,    5,
           11,    8,   20,   13,   23, -100, -100, -100, -100, -100, -100,
         -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100,
         -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100,
         -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100,
         -100]])>)
```<|||||>@Sreyan88 could you please share a script (or a colab) with your issue? :)<|||||>@gante , here is a bit dirty version of the notebook:

https://colab.research.google.com/drive/1HXOdDhaIWcLF_4xF-zKZ_gYRf-sMfHkL?usp=sharing

My main issue is I think I am passing valid inputs but the loss output is negative which is not possible in case of CTC.<|||||>I changed my dataset into a dictionary and the negative CTC losses persist:

```
{'input_values': <tf.Tensor: shape=(2, 154480), dtype=float32, numpy=
 array([[ 0.01052614,  0.02730851,  0.02783296, ...,  0.01052614,
          0.0089528 ,  0.00056161],
        [-0.00101706, -0.00101706, -0.00101706, ...,  0.        ,
          0.        ,  0.        ]], dtype=float32)>,
 'labels': <tf.Tensor: shape=(2, 122), dtype=int64, numpy=
 array([[  10,   25,   19,    5,   24,   13,   24,   17,    2,   15,    5,
           24,   25,   26,   26,    2,   10,    5,   10,   25,   19,    5,
            4,   20,   27,    1,    5,    2,   17,   17,   25,   20,   23,
            5,   10,   25,   19,    5,   23,   27,   20,   12,   11,   10,
            5,    3,    2,    1,   23,    3,   20,   19,   23,   27,    5,
           12,   25,   10,   23,    2,   19,    5,   10,    2,   17,   24,
            2,    1,    5,   11,    1,   24,    5,   12,   25,   10,   23,
            2,   19,    5,   22,   15,   12,    5,   11,    1,   25,   12,
           11,   23,    2,   24,    5,    3,   25,   23,   27,    5,   11,
            5,    3,   11,   19,   12,    5,   19,    2,   26,   11,   19,
           24,    5,   23,   20,    5,   17,   25,    8,    2,   19,   23,
           15],
        [  23,   27,    2,    5,   25,   24,    2,   11,    5,   20,    7,
            5,    2,   14,    2,   19,   15,    5,   12,   20,   24,    2,
            5,   25,    1,    5,    3,   27,   25,    0,   27,    5,   23,
           27,    2,    5,   27,   13,   12,   11,    1,    5,    8,   20,
           24,   15,    5,   25,   10,    5,   11,    7,    7,    2,    0,
           23,    2,   24,    5,    8,   15,    5,    2,    6,   23,    2,
           19,    1,   11,   17,    5,    8,   20,   24,   25,    2,   10,
         -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100,
         -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100,
         -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100,
         -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100,
         -100]])>}
```<|||||>@gante ,

When I change the above dictionary key from `labels` to `label` and it throws me this error:

```
Epoch 1/5
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
/tmp/ipykernel_33163/3396866883.py in <module>
      3 tf.compat.v1.logging.set_verbosity(tf.compat.v1.logging.ERROR)
      4 
----> 5 model.fit(train, validation_data = validation, epochs=5)

~/anaconda3/envs/gsoc-2/lib/python3.7/site-packages/keras/utils/traceback_utils.py in error_handler(*args, **kwargs)
     65     except Exception as e:  # pylint: disable=broad-except
     66       filtered_tb = _process_traceback_frames(e.__traceback__)
---> 67       raise e.with_traceback(filtered_tb) from None
     68     finally:
     69       del filtered_tb

~/anaconda3/envs/gsoc-2/lib/python3.7/site-packages/transformers/modeling_tf_utils.py in train_step(self, data)
   1058 
   1059         # Run backwards pass.
-> 1060         self.optimizer.minimize(loss, self.trainable_variables, tape=tape)
   1061 
   1062         self.compiled_metrics.update_state(y, y_pred, sample_weight)

TypeError: Argument `target` should be a list or nested structure of Tensors, Variables or CompositeTensors to be differentiated, but recieved None.
```

Can you please help me with where I am going wrong?<|||||>Hi @gante ,

I think this is a bug. When my input dataset looks like the above, no labels are passing through the model forward pass, it is `None` when I printed it. Can you please look into it?<|||||>Thank you for sharing a script @Sreyan88 :D I'm reopening the issue to track it<|||||>Hi @gante ,

Can adding `@unpack_inputs` solve the problem?

Solved the problem for me, which lead me to another error:

```
InvalidArgumentError                      Traceback (most recent call last)
/tmp/ipykernel_33658/3396866883.py in <module>
      3 tf.compat.v1.logging.set_verbosity(tf.compat.v1.logging.ERROR)
      4 
----> 5 model.fit(train, validation_data = validation, epochs=5)

~/anaconda3/envs/gsoc-2/lib/python3.7/site-packages/keras/utils/traceback_utils.py in error_handler(*args, **kwargs)
     65     except Exception as e:  # pylint: disable=broad-except
     66       filtered_tb = _process_traceback_frames(e.__traceback__)
---> 67       raise e.with_traceback(filtered_tb) from None
     68     finally:
     69       del filtered_tb

~/anaconda3/envs/gsoc-2/lib/python3.7/site-packages/transformers/modeling_tf_utils.py in train_step(self, data)
   1024 
   1025             if self._using_dummy_loss:
-> 1026                 loss = self.compiled_loss(y_pred.loss, y_pred.loss, sample_weight, regularization_losses=self.losses)
   1027             else:
   1028                 loss = None

InvalidArgumentError: slice index 0 of dimension 0 out of bounds. [Op:StridedSlice] name: strided_slice/
```

which I figure can be fixed with `loss = tf.reshape(loss, (1,))` after CTC loss calculation. Please let me know if these sound good.<|||||>Hi @gante ,

Hoping you are doing good! Do we have an update on this fix? Do you want me to create a pull request since I have tested with the above fixes and it works perfectly for me!<|||||>Hi @Sreyan88 👋 I do not have an update for this -- it's on my queue, but the queue is large. 

If you have a fix then yes, please open a PR 🙏 It would be greatly appreciated!<|||||>@gante you can close this as it was fixed in PR 18014.<|||||>Awesome! Thank you very much for your contribution @Sreyan88 <3 