Error while finetuning XLM-RoBERTa on Tensorflow-Keras
## env:
tensorflow                   2.8.0
keras                        2.8.0
transformers                 4.18.0
python                    3.8


## code
### data loader
```python
def gen_dataset_iter(model_config):
    data_files = {"train": model_config.train_path, "validation": model_config.dev_path, "test": model_config.test_path}
    src_data = load_dataset("csv", data_files=data_files)
    def preprocess_function(examples):
        return model_config.tokenizer(examples["content"], truncation=True)
    tokenized_data = src_data.map(preprocess_function, batched=True)
    data_collator = DataCollatorWithPadding(tokenizer=model_config.tokenizer, return_tensors="tf")
    train_iter = tokenized_data["train"].to_tf_dataset(
        columns=["attention_mask", "input_ids"],
        label_cols=["label"],
        shuffle=True,
        batch_size=model_config.batch_size,
        collate_fn=data_collator,
    )

    val_iter = tokenized_data["validation"].to_tf_dataset(
        columns=["attention_mask", "input_ids"],
        label_cols=["label"],
        shuffle=False,
        batch_size=model_config.batch_size,
        collate_fn=data_collator,
    )

    test_iter = tokenized_data["test"].to_tf_dataset(
        columns=["attention_mask", "input_ids"],
        label_cols=["label"],
        shuffle=False,
        batch_size=model_config.batch_size,
        collate_fn=data_collator,
    )
    return train_iter, val_iter, test_iter
```
### model
```python
model = TFAutoModelForSequenceClassification.from_pretrained(self.model_config.model_path, num_labels=self.model_config.num_classes)
loss = tf.keras.losses.SparseCategoricalCrossentropy(from_logits=True)
metrics = [tf.keras.metrics.SparseCategoricalAccuracy(), tf.keras.metrics.Precision(), tf.keras.metrics.Recall()]
self.model.compile(optimizer="adam", loss=loss, metrics=metrics)
stop_callback = tf.keras.callbacks.EarlyStopping(monitor="val_loss", patience=3)
best_model_callback = tf.keras.callbacks.ModelCheckpoint(self.model_config.save_path, monitor="val_loss", verbose=1, save_best_only=True, save_weights_only=True)
call_funs = [stop_callback, best_model_callback] 
self.model.fit(self.train_iter, epochs=self.model_config.num_epochs, verbose=2, validation_data=self.val_iter, callbacks=call_funs)
```
## error
```shell
File "/home/hellotalk/work/content_detect/models/model.py", line 70, in train
    self.model.fit(self.train_iter, epochs=self.model_config.num_epochs, verbose=2, validation_data=self.val_iter, callbacks=call_funs)
  File "/home/hellotalk/software/miniconda3/envs/py3.8/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/hellotalk/software/miniconda3/envs/py3.8/lib/python3.8/site-packages/tensorflow/python/framework/func_graph.py", line 1147, in autograph_handler
    raise e.ag_error_metadata.to_exception(e)
ValueError: in user code:

    File "/home/hellotalk/software/miniconda3/envs/py3.8/lib/python3.8/site-packages/keras/engine/training.py", line 1021, in train_function  *
        return step_function(self, iterator)
    File "/home/hellotalk/software/miniconda3/envs/py3.8/lib/python3.8/site-packages/keras/engine/training.py", line 1010, in step_function  **
        outputs = model.distribute_strategy.run(run_step, args=(data,))
    File "/home/hellotalk/software/miniconda3/envs/py3.8/lib/python3.8/site-packages/keras/engine/training.py", line 1000, in run_step  **
        outputs = model.train_step(data)
    File "/home/hellotalk/software/miniconda3/envs/py3.8/lib/python3.8/site-packages/transformers/modeling_tf_utils.py", line 1008, in train_step
        self.compiled_metrics.update_state(y, y_pred, sample_weight)
    File "/home/hellotalk/software/miniconda3/envs/py3.8/lib/python3.8/site-packages/keras/engine/compile_utils.py", line 459, in update_state
        metric_obj.update_state(y_t, y_p, sample_weight=mask)
    File "/home/hellotalk/software/miniconda3/envs/py3.8/lib/python3.8/site-packages/keras/utils/metrics_utils.py", line 70, in decorated
        update_op = update_state_fn(*args, **kwargs)
    File "/home/hellotalk/software/miniconda3/envs/py3.8/lib/python3.8/site-packages/keras/metrics.py", line 178, in update_state_fn
        return ag_update_state(*args, **kwargs)
    File "/home/hellotalk/software/miniconda3/envs/py3.8/lib/python3.8/site-packages/keras/metrics.py", line 1403, in update_state  **
        return metrics_utils.update_confusion_matrix_variables(
    File "/home/hellotalk/software/miniconda3/envs/py3.8/lib/python3.8/site-packages/keras/utils/metrics_utils.py", line 619, in update_confusion_matrix_variables
        y_pred.shape.assert_is_compatible_with(y_true.shape)

    ValueError: Shapes (256, 20) and (256, 1) are incompatible
```
Hey @tdr1991 👋  The error seems to come from `Precision` and `Recall`, which are designed for binary classification -- see this StackOverflow thread: https://stackoverflow.com/questions/59305514/tensorflow-how-to-use-tf-keras-metrics-in-multiclass-classification

(Closing the issue, since it is not related to `transformers`. Feel free to reopen if you find a `transformers`-related issue :) )