# Use Pretrained T5 for Summarization

**URL:** </static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Fuse-pretrained-t5-for-summarization%2F1992%3E%5C
**Category:** Beginners\
**Created:** [November 11, 2020, 3:36pm UTC](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Fuse-pretrained-t5-for-summarization%2F1992 "2020-11-11T15:36:17Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![npan1990](https://avatars.discourse-cdn.com/v4/letter/n/3d9bf3/32.png) [@npan1990](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Fu%2Fnpan1990)%5C
**Post date:** [November 11, 2020, 3:36pm UTC](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Fuse-pretrained-t5-for-summarization%2F1992%2F1 "2020-11-11T15:36:18Z")

</div>

Hello,

Is there any code snippet of how to use T5 pretrained model in order to do summarization?

---

<div class="post-metadata">

**Author:** ![npan1990](https://avatars.discourse-cdn.com/v4/letter/n/3d9bf3/32.png) [@npan1990](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Fu%2Fnpan1990)%5C
**Post date:** [November 11, 2020, 3:40pm UTC](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Fuse-pretrained-t5-for-summarization%2F1992%2F2 "2020-11-11T15:40:36Z")

</div>

I used the following code to do my task:

```
from transformers import T5ForConditionalGeneration

tokenizer = T5Tokenizer.from_pretrained('t5-small')

model = T5ForConditionalGeneration.from_pretrained('t5-small', return_dict=True)

input = "This is a summarization example. This is a large sentence."
input_ids = tokenizer("summarize: "+input, return_tensors="pt").input_ids # Batch size 1

outputs = model.generate(input_ids)

decoded = tokenizer.decode(outputs[0], skip_special_tokens=True)

print(decoded)
```

---

<div class="post-metadata">

**Author:** ![thomwolf](https://sea2.discourse-cdn.com/hellohellohello/user_avatar/discuss.huggingface.co/thomwolf/32/2198_2.png) [@thomwolf](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Fu%2Fthomwolf)%5C
**Post date:** [November 12, 2020, 12:57pm UTC](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Fuse-pretrained-t5-for-summarization%2F1992%2F3 "2020-11-12T12:57:11Z")

</div>

You can take a look at the contributed notebooks here: [https://github.com/huggingface/transformers/tree/master/notebooks#community-notebooks](https://github.com/huggingface/transformers/tree/master/notebooks#community-notebooks)

For instance this one is about finetuning (and using) T5 for summarization: [https://github.com/abhimishra91/transformers-tutorials/blob/master/transformers\_summarization\_wandb.ipynb](https://github.com/abhimishra91/transformers-tutorials/blob/master/transformers_summarization_wandb.ipynb)

---

<div class="post-metadata">

**Author:** ![cvillela](https://avatars.discourse-cdn.com/v4/letter/c/6f9a4e/32.png) [@cvillela](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Fu%2Fcvillela)%5C
**Post date:** [July 2, 2021, 8:37pm UTC](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Fuse-pretrained-t5-for-summarization%2F1992%2F4 "2021-07-02T20:37:59Z")

</div>

Hey there @thomwolf , I happened to observe that the ROUGE scores achieved on the tutorial notebook that you have posted are kind of far from the results presented on the paper (roughly 43 for rouge-1).

Are there any fine-tune implementations that have results closer to the original paper?

Thanks a lot in advance!
