Writing better prompts for GPT

Pranav Tiwari
2 min readFeb 3, 2023

--

Day 34 / 365

I have been using the OpenAI models to build stuff recently, mainly my Whatsapp ChatBot that translates Hindi sentences into English. To use these models, we have to provide them with Prompts.

For instance, a basic prompt I can use to get the model to translate something is -

Translate the following sentence into english — “Kya kr rhe ho?”

When you do that, you get the following response

“What are you doing?”

Which works well. But not always. If we add a few bad spellings, this prompt doesn’t work as well -

Translate the following sentence into english — “Kyu parshan hai bhai?”

The output is

“Why are you so suspicious, brother?”

Which is unacceptable. I am sure if you are a Hindi speaker you would have no trouble understanding what's written there. So how do we get the model to understand this as well?

One way is to make our prompt more descriptive and add some examples to it.

You are a fluent Hindi and English speaker. Given a hindi sentence written using english letters, you will be able to understand it and translate it to English. Even if the words have some letters missing. Some examples —
“tum kya kr rhi ho” -> “What are you doing?”
“mujhe nhi pta kya chl rha hai” → “I don’t know what’s going on.”
“ghr pahuch kr btana meko” -> “Tell me when you reach home”
Translate the following sentence into english — “Kyu parshan hai bhai?”

And the output now is

“Why are you worried, brother?”

The more examples you write, the more details you add to your prompt, and the better result you would get.

This approach still has issues. It would still fail in some cases, and you would have to keep adding examples to make it more accurate. Also, when you call the GPT API, you are charged per token (or for simplicity per word), so each translation would become more and more expensive.

A better approach is to fine-tune the model for your specific use case. This has a one-time cost, but after that, the fine-tuned model would give better results with smaller prompts. I will cover more about how to fine-tune your models in another post.

--

--

Pranav Tiwari
Pranav Tiwari

Written by Pranav Tiwari

I write about life, happiness, work, mental health, and anything else that’s bothering me

No responses yet