Generate Text With Artificial Intelligence GPT-2 From Google Colab Python

GPT-2 text generator, is an artificial intelligence model created by OpenAI which is a non-profit artificial intelligence research company that aims to promote and develop friendly artificial intelligence in a way that benefits humanity as a whole. The gpt-2 model has a trained model to generate text programmed in the pyhton language. Python is a language that is popular for its syntax.

The purpose of the program is to write automatically and generate text based on an example that we write. So it will start writing a series of words based on what it thinks and that prediction will be the text. If we read the text we can see that it is consistent with what it says.

To start generating text we must follow the steps below.

1.- We install the Flow tensor libraries for the neural networks to work correctly.

#ensorflow gpu libraries
!pip install tensorflow-gpu==1.15.0

2.- We set up our Google drive to save the training data there.
When we execute this command it will ask us for permission to access our Google drive and we just accept it

from google.colab import drive
drive.mount('/content/drive')

3.- Download GTP-2 from GitHub to be able to use the model with the libraries.

# run only once
# Create gpt-2 folder
%cd /content/drive/My\ Drive/
!mkdir gpt-2
%cd gpt-2/
!git clone https://github.com/openai/gpt-2.git
%cd cd gpt-2

4.-Navigate to the path where gpt-2 that we have cloned to our drive is located.

# Change tensorflow version
%cd /content/drive/My\ Drive/gpt-2/gpt-2

5.- Select version 1 of tensorflow so that we can run the program.

%tensorflow_version 1.x

6.- We install the pip3 requirements so that we can make use of the text files.

!pip3 install -r requirements.txt

7.- We visualize what is inside the route we are navigating to.

!dir

The following should appear in the terminal.
CONTRIBUTORS.md Dockerfile.gpu LICENSE README.md

DEVELOPERS.md domains.txt model_card.md requirements.txt

Dockerfile.cpu download_model.py models src

We select a model, each one is different so we must consider the storage weight if we want to download any of the 4 we simply remove the symbol # since it is placed so that it does not download all and only downloads the one we want and when executing the console it ignores except the one we want to download.

!python3 download_model.py 124M
#!python3 download_model.py 355M
#!python3 download_model.py 774M
#!python3 download_model.py 1558M

10.- Modify the interactive-conditional-samples.py file by double clicking on it, the code is on the left side.

9.- Before generating text we must execute the command to execute it we must change the model that we downloaded so that it can take it into account.
We go to our colab project and on the left side we go to the navigation folders ?content/drive/MyDrive/gpt-2/gpt-2/gpt-2/src/interactive-conditional-samples.py?

10.- Modify the interactive-conditional-samples.py file by double clicking on it, the code is on the left side.

And now we look in the code for the following command lines from line 11 onward

def interact_model(

model_name='124M', //it belongs to the model we have downloaded as we download the 124M we put that one, but if we download the 355M, 774M or 1558M we simply replace it with '124M' A ?774M?

seed=None,

nsamples=1, //number of examples we want from the text

batch_size=1,

length=None, //we set the length in words None is default but we can set 1000 words or as many as we wish by simply replacing with None

temperature=1,

top_k=0,

top_p=1,

models_dir='models', //folder where the downloaded models are located

):

11.- Now we only execute the last line of code.

!python3 src/interactive_conditional_samples.py --top_k 40

 

Finally to generate text we wait until we get something similar to this:

Where it says "Write a Text" it will be in English, I have modified it so that it is in Spanish, now we write what we want it to generate in English, so I will say

What is a computer? ---- and press enter

We wait a few minutes and a text appears, we just copy and paste it into the Google translator.

Text generated by GTP-2 From Google Colab

To answer this, we need to understand some fundamental facts about software development and development.

Software development

It is common for people to start their own companies when they think they are ready to start their own business. In many different countries there is a small group of people who want to become the founders of the company, but are not necessarily ready to become the person who runs it (this is not a bad thing if you are working on your own business). If you want to become the CEO of a company and you want to work on the ideas or products of your company, you need to have a really solid foundation in your career and you need to be able to keep your ideas and ideas relevant to you .

To give you an idea of the principles of software development, you need to know:

This is very useful because, in one group, the ideas, concepts and basics are usually alone and you have a solid foundation. But when you are dealing with two different groups of people, you may start out as a couple of people and not really be able to connect them.

The other important thing to know is: what really works?

Let's take a look at a simple example like "I'm going to share my experiences" that works for a company. We are not going to take into account how many people came up with this idea. As a group, we are going to create a new website to have more users than our competitors because we have a strong network of users. If we start with a small group, it will take about 20 users, with a core of 200 we will not be able to create another one, with a group of 50 we will not be able to create a good product, and if we start with 20 teams that will all be successful, we can grow by 100 people by our own effort and not have to face the competition at all.

If you are going to be a software company and you have to create a new website, you want to start with a few ideas instead of just the first 500 users that you will have to develop each of our competitors.

What about new product ideas, especially those that will be shared with users? We will not discuss them to show them how much impact the idea has, our competitors will not try to share the product, we will focus on trying to understand the new idea more than people.

How do you find a group of people whose interests are the same and who are willing to

PROJECT LINK:

https://colab.research.google.com/drive/1si8qWwcmUzA1HsPefLswNqgIsrti7BDo#scrollTo=rbpy2zDtIKnf

 

YOU MAY ALSO BE INTERESTED IN READING: WHICH IS THE CENTRAL PROCESSING UNIT (POST CREATED WITH THIS MODEL)

Leave a Reply

Go up

Cookies on this website are used to personalize content and ads, provide social media features and analyze traffic. More information