Create an Awesome Cover Letter with GPT-3
Tags: python, tutorial, beginners, career
Published: 2022-04-27 16:02:44

In this tutorial I am going to show you how to use a deep learning model called GPT-3 to create a cover letter for you in seconds with tons of variation. This cover letter can be used when applying for new jobs.

## Sections:

* [What is GPT-3?](#what-is-gpt3)
* [Is it cheating?](#is-it-cheating)
* [What will we be coding?](#what-will-we-be-coding)
* [Tutorial Steps](#steps)
     1. [Step 1: Create a new account with OpenAI](#step-1-create-a-new-account-with-openai)
     2. [Step 2: Create new API key](#step-2-create-new-api-key)
     3. [Step 3: Time To Code](#step-3-time-to-code)
* [Full Code](#full-code)


## What is GPT-3?

GPT-3 stands for Generative Pre-trained Transformer 3 and is a transformer model created by OpenAI. In short this model was created and trained using text on the internet, and can be used to generate realistic human text.

## Is it cheating?

Since all of us here are developers, having an algorithm generate realistic text for a cover letter shows innovation and staying up to date with all the latest trends in technology. So I do not believe this is cheating in any way but shows dedication and curiosity to learn new technologies.

I have personally used this for a job application and the feedback that I got was that "Your application stood out to us..." and finally after passing the next interview steps got offered a job. 

## What will we be coding?

What we will be coding is very simple, we are just utilizing the power of the GPT-3 algorithm. We will not be training or testing anything. We will simply supply the GPT-3 algorithm with some sample cover letters so that it will understand what we are trying to generate and then call a function which runs the GPT-3 algorithm and generates our cover letter.

&nbsp;


Without further ado let’s dive into the tutorial.


## Steps

### Step 1: Create a new account with OpenAI

Click [here](https://beta.openai.com/signup) to go to OpenAI's sign up page and create a new account.

After the account is created some free credits are given to you which expire **within one month**. So be sure to create your cover letter within that month.


### Step 2: Create new API key

By going to your account on the top right corner and clicking on "View API keys" you are redirected to the page where you can create a new key. This can be seen on the screenshot below. Go ahead and create a new API key.

![Create new API key](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/mypc0ecjbzth88shnwxi.png)
 

### Step 3: Time To Code

Open up your favourite code editor and follow along with me. We only need to do 5 steps. 

**1)** First we import the necessary libraries. Most probably you will need to install the openai library by typing `pip install openai`.

```{python}
import openai as ai
import json
```

**2)** Then we add our API key as a variable:

```{python}
ai.api_key = "YOUR_API_KEY_HERE"
```

**3)** Then we import our text file which contains some sample inputs along with responses so that GPT-3 will know what to generate. 

```{python}
with open("prompt.txt") as pro:
	prompt = pro.read()
```
This file has the form of:

```
Input: Generate a cover letter for a Management Consulting job at Goldman Sachs. 

Output: Dear Hiring Manager,

I would like .....

Input: "Generate a cover letter for a Management Consulting job at ABC company."

Output:

```
By leaving the output as blank in the last line, the algorithm will know and fill out the text by itself. By adding more input/output combinations the algorithm learns better what to generate.
The full text file that I used can be found [here](https://github.com/CharalambosIoannou/GPT-3-Cover-Letter/blob/main/prompt.txt).

**4)** We then create our model using the following:

```{python}
returns = ai.Completion.create(
    engine="davinci", # OpenAI has made four text completion engines available, named davinci, ada, babbage and curie. We are using davinci, which is the most capable of the four.
	prompt=prompt, # The text file we use as input (step 3)
    max_tokens=100, # how many maximum characters the text will consists of.
	temperature=0.9, # a number between 0 and 1 that determines how many creative risks the engine takes when generating text.,
	top_p=1, # an alternative way to control the originality and creativity of the generated text.
	n=1, # number of predictions to generate
	frequency_penalty=0.5, # a number between 0 and 1. The higher this value the model will make a bigger effort in not repeating itself.
	presence_penalty=0.9 # a number between 0 and 1. The higher this value the model will make a bigger effort in talking about new topics.
)
```
All parameters this function takes are explained as comments.

**5)** Lastly we need to obtain the actual text return from the function. This is done using the following line:

```{python}
text = returns['choices'][0]['text']
print(text)
```

If you choose to return more than 1 sample (set n>1 in the function above) you need to change the `[0]` to the corresponding
index.

### Full Code:

For those who just need the code here is the complete file:
```{python}
import openai as ai
import json

ai.api_key = "YOUR_API_KEY_HERE"

# Import text prompt
with open("prompt.txt") as pro:
	prompt = pro.read()
	
# The Model
returns = ai.Completion.create(
    engine="davinci", # OpenAI has made four text completion engines available, named davinci, ada, babbage and curie. We are using davinci, which is the most capable of the four.
    prompt=prompt, # The text file we use as input (step 3)
    max_tokens=100, # how many maximum characters the text will consists of.
    temperature=0.9, # a number between 0 and 1 that determines how many creative risks the engine takes when generating text.,
    top_p=1, # an alternative way to control the originality and creativity of the generated text.
    n=1, # number of predictions to generate
    frequency_penalty=0.5, # a number between 0 and 1. The higher this value the model will make a bigger effort in not repeating itself.
    presence_penalty=0.9 # a number between 0 and 1. The higher this value the model will make a bigger effort in talking about new topics.
)


text = returns['choices'][0]['text']

print(text)
```

This along with the sample text file can be found on my [GitHub repo](https://github.com/CharalambosIoannou/GPT-3-Cover-Letter) as well.



&nbsp;

&nbsp;

THAT’S IT!!!
I hope you find this easy and useful.

Hope you enjoyed it 😄.

Happy Exploring!!