# Beginners Guide to Flan-T5

Flan-T5 is an enhanced version of Google’s T5 AI model which is quite good at certain language tasks.

For example, it’s supposed to be better at a lot of zero-shot examples even than [**GPT-3**](https://harishgarg.com/writing/how-to-fine-tune-gpt-3-api/).

Table of Contents

*   [Install and Setup Flan-T5](https://harishgarg.com/#Install_and_Setup_Flan-T5)
*   [Using Flan-T5 for language AI tasks](https://harishgarg.com/#Using_Flan-T5_for_language_AI_tasks)
*   [Flan-T5 versions](https://harishgarg.com/#Flan-T5_versions)

Install and Setup Flan-T5
-------------------------

First, we install the transformers module by running the below command

pip install transformers

If you run into an issue, check out the [Transformers Installation Guide](https://huggingface.co/docs/transformers/installation).

Then, we load the Flan-T5 model

from transformers import AutoModelForSeq2SeqLM, AutoTokenizer

model = AutoModelForSeq2SeqLM.from\_pretrained("google/flan-t5-small")

Load the tokenizer

tokenizer = AutoTokenizer.from\_pretrained("google/flan-t5-small")

Note we loaded the small model.  You can load any of the versions listed in a later section below.

The bigger the model, the better it is but also more resource consuming

Using Flan-T5 for language AI tasks
-----------------------------------

Next, we pass the prompt we want the AI model to generate text for.

inputs = tokenizer("A intro paragraph on a article on space travel:", return\_tensors="pt")

We call the model’s generate function and get the response.

outputs = model.generate(\*\*inputs)

You can then print the output from the AI model

print(tokenizer.batch\_decode(outputs, skip\_special\_tokens=True))

Flan-T5 versions
----------------

Model

Gin File Location

Checkpoint Location

Flan-T5 Small

[t5\_1\_1/small.gin](https://github.com/google-research/t5x/blob/main/t5x/examples/t5/t5_1_1/small.gin)

[gs://t5-data/pretrained\_models/t5x/flan\_t5\_small/checkpoint\_1198000](https://console.cloud.google.com/storage/browser/t5-data/pretrained_models/t5x/flan_t5_small/checkpoint_1198000)

Flan-T5 Base

[t5\_1\_1/base.gin](https://github.com/google-research/t5x/blob/main/t5x/examples/t5/t5_1_1/base.gin)

[gs://t5-data/pretrained\_models/t5x/flan\_t5\_base/checkpoint\_1184000](https://console.cloud.google.com/storage/browser/t5-data/pretrained_models/t5x/flan_t5_base/checkpoint_1184000)

Flan-T5 Large

[t5\_1\_1\_large.gin](https://github.com/google-research/t5x/blob/main/t5x/examples/t5/t5_1_1/large.gin)

[gs://t5-data/pretrained\_models/t5x/flan\_t5\_large/checkpoint\_1164000](https://console.cloud.google.com/storage/browser/t5-data/pretrained_models/t5x/flan_t5_large/checkpoint_1164000)

Flan-T5 XL

[t5\_1\_1\_xl.gin](https://github.com/google-research/t5x/blob/main/t5x/examples/t5/t5_1_1/xl.gin)

[gs://t5-data/pretrained\_models/t5x/flan\_t5\_xl/checkpoint\_1138000](https://console.cloud.google.com/storage/browser/t5-data/pretrained_models/t5x/flan_t5_xl/checkpoint_1138000)

Flan-T5 XXL

[t5\_1\_1\_xxl.gin](https://github.com/google-research/t5x/blob/main/t5x/examples/t5/t5_1_1/xxl.gin)

[gs://t5-data/pretrained\_models/t5x/flan\_t5\_xxl/checkpoint\_1114000](https://console.cloud.google.com/storage/browser/t5-data/pretrained_models/t5x/flan_t5_xxl/checkpoint_1114000)
