DEV Community

Cover image for Create an Awesome Cover Letter with GPT-3
Charalambos Ioannou
Charalambos Ioannou

Posted on

Create an Awesome Cover Letter with GPT-3

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?

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.

 

Without further ado let’s dive into the tutorial.

Steps

Step 1: Create a new account with OpenAI

Click here 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

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.

import openai as ai
import json
Enter fullscreen mode Exit fullscreen mode

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

ai.api_key = "YOUR_API_KEY_HERE"
Enter fullscreen mode Exit fullscreen mode

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

with open("prompt.txt") as pro:
    prompt = pro.read()
Enter fullscreen mode Exit fullscreen mode

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:

Enter fullscreen mode Exit fullscreen mode

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.

4) We then create our model using the following:

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.
)
Enter fullscreen mode Exit fullscreen mode

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:

text = returns['choices'][0]['text']
print(text)
Enter fullscreen mode Exit fullscreen mode

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:

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)
Enter fullscreen mode Exit fullscreen mode

This along with the sample text file can be found on my GitHub repo as well.

 

 

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

Hope you enjoyed it 😄.

Happy Exploring!!

Discussion (0)