# Fine-tuning T5 for sentiment classification

**URL:** </static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Ffine-tuning-t5-for-sentiment-classification%2F44929%3E%5C
**Category:** Beginners\
**Created:** [June 29, 2023, 9:23am UTC](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Ffine-tuning-t5-for-sentiment-classification%2F44929 "2023-06-29T09:23:28Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![dammy](https://avatars.discourse-cdn.com/v4/letter/d/c5a1d2/32.png) [@dammy](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Fu%2Fdammy)%5C
**Post date:** [June 29, 2023, 9:23am UTC](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Ffine-tuning-t5-for-sentiment-classification%2F44929%2F1 "2023-06-29T09:23:29Z")

</div>

Hi all,

I would like to fine-tune a T5 model for sequence classification (specifically sentiment classification). However, all the tutorials are doing seq-2-seq analysis, such as text summarization as below. I understand why it uses ROUGE score for the cost calculation and it uses AutoModelForSeq2SeqLM package since it is seq-2-seq task. I think I need to change my cost function and also need to replace AutoModelForSeq2SeqLM by something? Any suggestions/ideas how to proceed?

> **[Google Colaboratory](https://colab.research.google.com/github/huggingface/notebooks/blob/main/examples/summarization.ipynb#scrollTo=FBiW8UpKIrJW)**

Thank you

Best

---

<div class="post-metadata">

**Author:** ![merve](https://sea2.discourse-cdn.com/hellohellohello/user_avatar/discuss.huggingface.co/merve/32/49809_2.png) [@merve](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Fu%2Fmerve)%5C
**Post date:** [June 29, 2023, 2:29pm UTC](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Ffine-tuning-t5-for-sentiment-classification%2F44929%2F2 "2023-06-29T14:29:06Z")

</div>

Hello @dammy,  
You can check out [this notebook](https://github.com/patil-suraj/exploring-T5/blob/master/t5_fine_tuning.ipynb) to fine tune T5 on sequence classification (not in the classification way like encoder only models do but rather with conditional generation. In case you haven’t checked, I’d suggest you to use encoder only models with classification heads and see how they perform. It’s a simpler approach that would work better for classification IMHO.

---

<div class="post-metadata">

**Author:** ![dammy](https://avatars.discourse-cdn.com/v4/letter/d/c5a1d2/32.png) [@dammy](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Fu%2Fdammy)%5C
**Post date:** [June 30, 2023, 2:25pm UTC](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Ffine-tuning-t5-for-sentiment-classification%2F44929%2F3 "2023-06-30T14:25:54Z")

</div>

Thanks @merve, I have tried BERT as an encoder only method, the accuracy is fine. However, I want to see if I can have something better with T5 fine-tuned.

---

<div class="post-metadata">

**Author:** ![CUIGuy](https://avatars.discourse-cdn.com/v4/letter/c/cab0a1/32.png) [@CUIGuy](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Fu%2FCUIGuy)%5C
**Post date:** [December 22, 2023, 11:23pm UTC](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Ffine-tuning-t5-for-sentiment-classification%2F44929%2F4 "2023-12-22T23:23:12Z")

</div>

@dammy how did your experiment with T5 fine-tuning on sentiment classification?
