First Steps Into GPT-3
By Umut Can Alaçam
GPT-3 is a very powerful language model developed by OpenAI in 2021. GPT-3 created a great impact since its impressive capabilities on a variety of tasks. Such as: article writing, poetry, rhyme generation, semantic analysis, code generation and so on. In fact, GPT-3 achieves impressive success on all these different tasks by doing two important things well: natural language understanding and natural language generation.
In simplest form, GPT-3 takes a text as an input and generates some text as output. GPT-3 perceives the context of the provided text input then produces a completion that is compliant with the context. Basically, GPT-3 might be considered as a very talented auto-complete engine. Interestingly, this approach yields a task agnostic model, since it is possible to encourage GPT-3 to perform for different task domains by providing the task context within the text input or more technically the prompt.
Accessing to GPT-3
OpenAI provides access to the GPT-3 through a rest api. Using this api, you can send a prompt and receive completions. For using this API you need to create an OpenAI account. You can access to the OpenAI API official web page by this link: https://beta.openai.com/
OpenAI Api is a paid API. Therefore, be careful while experimenting to avoid expensive bills. Fortunately OpenAI provides 18$ credit for the first 3 months. You can use this credit for experiencing and learning GPT-3.
After you created an account and logged in, you can access the playground and create compilations with GPT-3. You can see an example completion below. The compilation generated by GPT-3 is highlighted with green.
You can observe that GPT-3 follows the context of the given prompt and creates a reasonable compilation.
Using GPT-3 for different tasks
As mentioned before, GPT-3 performs well on different task domains. However, prompt design is crucial for success in the desired task domain. Note that GPT-3 is trained with a huge corpus which contains information from the internet and books. Therefore, it is very likely the model has already seen similar cases to your prompt. Recalling this knowledge depends on the prompt design and it is tricky.
Prompt Design
OpenAI recommends that a prompt should consist of a short description and a few examples for the task. Using such a prompt design helps GPT-3 to perceive the context and recall the knowledge that is gained while training.
Using the playground feature of the OpenAI console, you can easily test different prompts or perform experiments. You can find an example prompt design below. Assuming that we want to create a semantic analysis application for detecting the opinions on comments about a movie.
Prompt:
Semantic analysis for movie comments.
I think it is not a good idea. - Negative
It is not bad. - Positive
This film is not getting the credit it deserves. It is in my opinion one of
the most underrated films of all time.- Positive
The movie is not achieving what it needs to do. However, the scenario is
very open minded. - Mixed
Following the recommended prompt design approach, we provided a simple description about what we expect from GPT-3. Then, a few examples are included. Incredibly, for most cases such a prompt design achieves very reasonable results.
Now we can perform semantic analysis on any user comment by concatenating it to the end of the prompt. Please find the example below.
Semantic analysis for movie comments.
I think it is not a good idea. - Negative
It is not bad. - Positive
This film is not getting the credit it deserves. It is in my opinion one of
the most underrated films of all time.- Positive
The movie is not achieving what it needs to do. However, the scenario is
very open minded. - Mixed
They really upped the ante with all the stunning visuals and effects on
this one. It actually had a good story (still not as amazing or in-depth as
the first film), told properly, albeit some convalusion. The fight scenes
were of decent length and better choreographed. Cinematography was excellent
and the score on point. -
Note that the trailing hyphen at the end. It is included for keeping the prompt in a consistent structure. You can hit the submit button for testing. The model generates the following completion as a result:
Positive
As you can see, the model responds with ‘Positive’, what we were hoping for. You can find more prompt examples for many kinds of use cases from official OpenAI web site: https://beta.openai.com/examples
Parameters
The parameters of GPT-3 affect the behavior of the model. Using the parameters you can improve the results slightly. You can try different parameters through the playground.
Temperature: Effects the randomness of the results, the creativity of the completions increases when increased. Maximum length: Number of the tokens to generate. Tokens consist of two to four characters. Top P: Controls the probability threshold for the possible completion tokens. GPT-3 generates a number of possible completions, then selects one completion randomly. Increasing this threshold affects the uniqueness and randomness of the output. Frequency penalty: Defines the penalty value for already generated words. Depending on how many times a word has already been in the prediction, there will be a penalty. Presence penalty: Similar to the frequency penalty, defines a penalty value for already generated words. However the penalty value does not rely on the frequency of the word.
Implementing application using OpenAI
Although experiencing GPT-3 using OpenAI playground is very inspiring, using capabilities of GPT-3 within an actual application is much more important. As mentioned before, OpenAI provides an API for using GPT-3 on application development. There are some libraries for different languages to encapsulate the API communication with GPT-3 but you don’t have to use these libraries for accessing the API. You can access the Rest API using HTTP requests.
You can access to the API reference through this link: https://beta.openai.com/docs/api-reference/introduction