GPT-3: The All-in-One Solution for Automated Emails, Sentiment Analysis and Topic Detection

Omkar Gawade
4 min readJan 21, 2023
Image by Diego PH on Unsplash.com

Generating automated emails with GPT-3 can be a powerful tool for businesses and organizations looking to improve their communication with customers and clients. One of the key advantages of using GPT-3 is its ability to understand the context and intent of a given message, which allows it to generate highly personalized and accurate responses.

GPT-3 is trained on a massive dataset of text, which includes a diverse range of sources such as books, articles, websites, and more. The training dataset for GPT-3 is estimated to be on the order of billions of words, which allows the model to learn a wide variety of language patterns and styles.

The training dataset for GPT-3 is preprocessed to clean and preprocess the text, such as lowercasing, tokenization, and stemming. The cleaned text used to train the model, which is based on a transformer architecture. The transformer architecture allows the model to learn the underlying patterns and relationships between words in the text, which enables it to generate highly coherent and natural-sounding text.

Since GPT-3 has been already trained on about 45 TB text data and has 175 trainable parameters, even without fine tuning it can be used to effectively generate automated responses to incoming emails based on the context and intent of the message. For example, if a customer sends an email asking for help with a product, the model can generate a personalized response that provides the necessary information and assistance. Similarly, if a sales prospect sends an email expressing interest in a product or service, the model can generate a tailored sales pitch that addresses their specific needs and concerns.

Lets look at the code in python to connect to GPT-3 api and generate email responses:

Step 1: Import required libraries and import generic csv email file:

Image by Author

Step 2: Define a function in python which calls GPT-3 public api — In order to do this you will need to create a personal account on open AI with your personal email; Open AI provides an $18 credit for you to explore and experiment with various models. After the account is created click on your account on the top right corner and go to view API keys ; once you are in the API keys page you can create a new API secret key — be sure to copy this key in secret variable in python.

Define a function with api key, mention a prompt to GPT-3 text model “text-davinci-003”— in our case we will use text string joining with prompt “Reply to this below email”.

Image by Author

Once the function is defined — we can use pandas with apply functionality to apply the function defined above to generate responses.

Image by Author

You can see in the above example how effective GPT-3 is to generate human like responses to the email.

Similarly you can change the prompt in define function provided to GPT-3 to provide sentiment & detect email type of the email received:

Image by Author
Image by Author

Create two columns Sentiment_email & Email_type by using apply functionality in pandas to apply above two defined functions.

Let’s checkout the results:

Image by Author

The possibilities are endless with GPT-3- you can generate essay’s , have it write resume or songs or whatever floats your boat!

Let’s get coding ya’ll!

Follow my medium blog and add me on linked in — would love to connect with ya’ll.

Linked in: Omkar-gawade

--

--

Omkar Gawade

Sr. Data Scientist @ Sourceday | Data professional with 5 plus years experience in analytics, visualizations and modeling.