Hi guys. In this blog, we are going to learn about GPT3 and how it can help us to generate text
It stands for Generative Pre-trained Transformer 3
GPT3 is a deep learning language model trained on 175+ million parameters that makes it best for most NLP tasks.
GPT-3 can create anything that has a language structure — which means it can answer questions, write essays, summarize long texts, translate languages, take memos, and even create computer code.
So we are going how we can use GPT 3 models for generating text using Python.
So for that, we need PyTorch and Transformers.
So let’s install it in our Google Colab/Jupyter Notebook.
!pip install torch==1.8.1+cu111 torchvision==0.9.1+cu111 torchaudio===0.8.1 -f https://download.pytorch.org/whl/torch_stable.html!pip install transformers
Now we need to import pipeline
from transformers import pipeline
Now we are going to load GPT 3 Model. Here I have used EleutherAI/gpt-neo-1.3B model. You can also use EleutherAI/gpt-neo-2.7B which is more accurate but requires around 60 GB of download file. You can use anyone.
generator = pipeline(‘text-generation’, model=’EleutherAI/gpt-neo-1.3B’)
Now we need to pass the text to the downloaded model
1. Why Corporate AI projects fail?
2. How AI Will Power the Next Wave of Healthcare Innovation?
3. Machine Learning by Using Regression Model
4. Top Data Science Platforms in 2021 Other than Kaggle
text = ‘Who is Elon Musk'
Now we’ll use the generator function and we’ll pass max_length, do_sample and temperature.
result = generator(text, max_length=100, do_sample=True, temperature=0.9)
And last we’ll print our result
>>Who is Elon Musk? Elon Musk made a name for himself at Tesla, where he transformed the auto industry. In 2009, the entrepreneur and founder of Tesla Motors was named the “World’s Most Hated Person.” Today, Musk is the richest man on Earth;
You can access my GitHub repository here
I hope you like this blog. Feel free to share your thoughts in the comment section and you can also connect with me in:-
Linkedin — https://www.linkedin.com/in/shreyak007/
Github — https://github.com/Shreyakkk
Twitter — https://twitter.com/Shreyakkkk
Instagram — https://www.instagram.com/shreyakkk/
Snapchat — shreyak001
Facebook — https://www.facebook.com/007shreyak