# T5forConditionalGeneration

**URL:** <https://discuss.huggingface.co/t/t5forconditionalgeneration/1134>\
**Category:** Beginners\
**Created:** [September 15, 2020, 6:14am UTC](https://discuss.huggingface.co/t/t5forconditionalgeneration/1134 "2020-09-15T06:14:44Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![ashiishkarhade](https://sea2.discourse-cdn.com/hellohellohello/user_avatar/discuss.huggingface.co/ashiishkarhade/32/346_2.png) [@ashiishkarhade](https://discuss.huggingface.co/u/ashiishkarhade)\
**Post date:** [September 15, 2020, 6:14am UTC](https://discuss.huggingface.co/t/t5forconditionalgeneration/1134/1 "2020-09-15T06:14:44Z")

</div>

Hello,  
I am a newbie in using transformers and never used it before.  
I want to know, what’s the difference between T5Model and T5forConditionalGeneration? Where are they used?

---

<div class="post-metadata">

**Author:** ![valhalla](https://sea2.discourse-cdn.com/hellohellohello/user_avatar/discuss.huggingface.co/valhalla/32/4179_2.png) [@valhalla](https://discuss.huggingface.co/u/valhalla)\
**Post date:** [September 15, 2020, 7:59am UTC](https://discuss.huggingface.co/t/t5forconditionalgeneration/1134/2 "2020-09-15T07:59:31Z")

</div>

Hi @ashiishkarhade  
`T5Model` contains the `encoder` (stack of encoder layers) and `decoder` (stack of decoder layers) without any task specific heads. It returns the raw hidden states of the decoder as output.

`T5ForConditionalGeneration` also contains the `encoder` and `decoder` and adds an additional linear layer (lm\_head) which takes the final hidden states of `decoder` and generates the next token.

For fine-tuning the model for seq2seq generation you should use `T5ForConditionalGeneration`, if you want to add some different task specific head then you can `T5Model`.

And almost all library models have this structure, a base model which returns raw hidden states and additional models with task specific heads(`ForSequenceClassification`, `ForQuestionAnswering` etc) on top of the base model.

---

<div class="post-metadata">

**Author:** ![ashiishkarhade](https://sea2.discourse-cdn.com/hellohellohello/user_avatar/discuss.huggingface.co/ashiishkarhade/32/346_2.png) [@ashiishkarhade](https://discuss.huggingface.co/u/ashiishkarhade)\
**Post date:** [September 15, 2020, 8:31am UTC](https://discuss.huggingface.co/t/t5forconditionalgeneration/1134/3 "2020-09-15T08:31:56Z")

</div>

Thank you for the brief .
