# Fine-tuning T5 on Tensorflow

**URL:** <https://discuss.huggingface.co/t/fine-tuning-t5-on-tensorflow/12253>\
**Category:** Beginners\
**Created:** [November 24, 2021, 4:28pm UTC](https://discuss.huggingface.co/t/fine-tuning-t5-on-tensorflow/12253 "2021-11-24T16:28:34Z")\
**Posts on this page:** 1\
**Showing post:** 5

<div class="post-metadata">

**Author:** ![Rocketknight1](https://sea2.discourse-cdn.com/hellohellohello/user_avatar/discuss.huggingface.co/rocketknight1/32/21055_2.png) [@Rocketknight1](https://discuss.huggingface.co/u/Rocketknight1)\
**Post date:** [November 29, 2021, 1:39pm UTC](https://discuss.huggingface.co/t/fine-tuning-t5-on-tensorflow/12253/5 "2021-11-29T13:39:01Z")

</div>

Hi @mazerte, sorry for the delay in replying! This is one of those cases where I’d actually recommend trying our new “internal loss” method. For more complex models like Seq2Seq, getting the right Keras losses can be hard - it’s possible, but it can require a lot of knowledge and some hacky code. Instead, just let our model compute loss for you! To do that you should do two things:

1. Move the labels to the input dictionary so that they’re visible to the model on the forward pass, like so:

```auto
tf_train = inputs.to_tf_dataset(
  columns=["attention_mask", "input_ids", 'decoder_input_ids', 'labels'],
  shuffle=True,
  collate_fn=data_collator,
  batch_size=batch_size,
)

```

1. Remove the `loss` argument to `compile()`. Note that right now, we don’t support Keras metrics when using the internal loss, but this is an area of very active development - that will hopefully change soon!

```auto
model.compile(
  optimizer=optimizer
)

```

If you make these two changes, your model should train successfully. We recommend this method whenever you’re not sure of which loss to use.

---

_[View the full topic](https://discuss.huggingface.co/t/fine-tuning-t5-on-tensorflow/12253)._
