Better Programming

Advice for programmers.

Follow publication

Is Google’s Flan-T5 Better Than OpenAI GPT-3?

Daniel Avila
Better Programming
Published in
4 min readFeb 4, 2023

What is Google Flan-T5?

Google AI has released an open-source language model — Flan-T5

T5 = Text-to-Text Transfer Transformer

Flan T5 is an open-source transformer-based architecture that uses a text-to-text approach for NLP.

To know more about Flan-T5, read the whole paper here.

Let’s Try Google Flan-T5

Here is the code so you can try it yourself:

This code installs the Python packages “transformers”, “accelerate”, and “sentencepiece” using the pip package manager. The -q flag is used to suppress output from the installation process.

Gradio is a web application for building interactive machine-learning tools, so this code may be used to install Gradio’s dependencies.

! pip install -q transformers accelerate sentencepiece gradio

This code imports the T5Tokenizer and T5ForConditionalGeneration classes from the transformers library. It then creates a tokenizer object from the google/flan-t5-xl pre-trained model and a model object from the same pre-trained model, which is set to run on a CUDA device.

The T5Tokenizer is used for tokenizing text into tokens that can be used by the T5ForConditionalGeneration model for generating text.

from transformers import T5Tokenizer, T5ForConditionalGeneration

tokenizer = T5Tokenizer.from_pretrained("google/flan-t5-xl")
model = T5ForConditionalGeneration.from_pretrained("google/flan-t5-xl").to("cuda")

This code is used to generate text using a pre-trained language model. It takes an input text, tokenizes it using the tokenizer, and then passes the tokenized input to the model.

The model then generates a sequence of tokens up to a maximum length of 100. Finally, the generated tokens are decoded back into text using the tokenizer and any special tokens are skipped.

def generate(input_text):
input_ids = tokenizer(input_text, return_tensors="pt").input_ids.to("cuda")
output = model.generate(input_ids, max_length=100)
return tokenizer.decode(output[0], skip_special_tokens=True)

All the above code descriptions were created with Code GPT

Let’s Review Each Model

For this example, we are going to test flan-t5-xl with Google Colab and OpenAI text-davinci-003 with Code GPT within Visual Studio Code.

If you want to know how to download and install Code GPT in Visual Studio Code, please read this article 👉 Code GPT for Visual Studio Code

With Code GPT you will be able to test different artificial intelligence providers very easily and with only a few configurations.

Let’s Start With The Tests

Translation tasks

prompt: Translate English to Spanish: What is Google Flan-T5?

Google Colab: flan-t5-xl:

Code GPT: text-davinci-003:

Simple Question

prompt: Please answer the following question. What is Google?

Google Colab: flan-t5-xl

Code GPT: text-davinci-003

Sense of Humor

prompt: Tell me a programming joke

Google Colab: flan-t5-xl

Code GPT: text-davinci-003

Reasoning

Google Colab: flan-t5-xl

Code GPT: text-davinci-003

Closing Thoughts

FLAN-T5 requires fewer parameters and can be trained faster. This makes it easier to use and more accessible to the general public. Finally, FLAN-T5 is open source, so anyone can access it and use it for their own projects.

Flan T5 looks really interesting to be an open-source model that allows one to be trained very easily.

I will continue testing with this model, stay tuned so you don’t miss the next experiments.

Resources

Sign up to discover human stories that deepen your understanding of the world.

Free

Distraction-free reading. No ads.

Organize your knowledge with lists and highlights.

Tell your story. Find your audience.

Membership

Read member-only stories

Support writers you read most

Earn money for your writing

Listen to audio narrations

Read offline with the Medium app

Daniel Avila
Daniel Avila

Written by Daniel Avila

CTO | AWS | Serverless | CodeGPT

Responses (3)

Write a response

Thanks for the comparison! Not sure how the programming joke is a programming joke (AI humor?!) but based on this limited slice, it looks like GPT3 still wins for now although it looks like we are just at the beginning of this strange AI powered arms race and there’s much more to come :P

Simple Question

I am not sure why chatGPT gives a more lengthy and colorful answer compared to T5. I would love to understand as I prefer the long version but would prefer not to use open source.

Hmm it looks like T5 will give GPT a run for its money.

Also, what a name Google chose for it lol.