ChatGPT Prompt Engineering: A Complete Guide For Beginners

Hello there, fellow AI enthusiasts and tech-savvy folks!

Today, Iā€™m excited to guide you through the fascinating world of ChatGPT prompt engineering and how it can help you unleash the full potential of these chatbots and other Large Language Models (LLMs).

You might be thinking, ā€œDo I need to be a coding genius for this?ā€ Well, fret not because the answer is a resounding no. Weā€™re going to keep things simple and jargon-free, so no coding background is necessary.

In the article, we will explore the ins and outs of prompt engineering. Why, you ask? Itā€™s a skill thatā€™s in high demand, with some companies reportedly dishing out hefty salaries, reaching up to $335,000 a year (according to Bloomberg), for professionals who master this craft.

Weā€™ll discover its ins and outs. Weā€™ll start with a quick peek into the fascinating realm of AI, followed by a closer examination of the famous and powerful large language model, ChatGPT.

Along the way, weā€™ll discuss the prompt engineering mindset, best practices, IO and CoT prompting, and AI hallucinations, and, to wrap it up, weā€™ll provide a brief introduction to ChatGPT.

What is prompt Engineering?

Letā€™s kick things off by delving into what prompt engineering is all about.

Prompt engineering refines prompts for optimal human-AI interaction for effective AI performance.

Itā€™s a gig that emerged alongside the rise of artificial intelligence. It revolves around crafting, fine-tuning, and systematically optimizing prompts.

The goal? To perfect the interaction between us humans and AI to the max. But it doesnā€™t stop there ā€” prompt engineers also have the task of keeping tabs on these prompts over time, ensuring they stay effective as AI continues to evolve.

Keeping a fresh and updated prompt library is a must for these engineers, along with sharing their insights and being the go-to folks in this field.

Now, you might be wondering, why we even need this prompt engineering thing, and how it sprouted from the realm of AI?

But b.fore we dive into that, letā€™s make sure weā€™re all on the same page about AI itself. Artificial intelligence is like a mimicry of human thought processes carried out by machines.

I say mimicry because AI isnā€™t sentient ā€” at least, not just yet. It canā€™t think for itself, despite how clever it might appear. Often, when we toss around the term ā€œAI,ā€ weā€™re basically talking about something called machine learning.

Machine learning works by munching on huge piles of training data, dissecting it for patterns and connections, and then using that insight to predict stuff based on the data itā€™s seen.

Imagine weā€™re spoon-feeding our AI model some data, telling it that if a paragraph looks a certain way with a specific title, it should belong to a specific category.

With a dash of code magic, we can train our AI to make pretty accurate guesses about what future paragraphs are all about.

As of now, the world of AI is sprinting ahead with impressive strides. Thanks to vast pools of training data and some seriously talented developers, todayā€™s AI tech can whip up lifelike text responses, craft images, compose music, and dabble in various other creative endeavors. Itā€™s a thrilling time to be part of this ever-evolving AI world.

Importance of prompt engineering

Why is machine learning important? And why does prompt engineering matter? With the rapid growth of AI, even its creators find it hard to control and predict its outcomes.

To grasp this, consider asking an AI chatbot a simple math question like ā€œWhat is 1 + 1ā€ Youā€™d expect a clear answer: 2.

However, imagine youā€™re a student learning English.

Iā€™m about to demonstrate how different responses can shape your learning experience based on the prompts given.

For this example, Iā€™m using ChatGPTā€™s GPT-3.5 model. Letā€™s begin with the fundamentals. If you were to type, ā€œcorrect the given textā€ and input a poorly written text like this:

ā€œToday was great in the world for me. I went to Disneyland with my mom. It could have been better though if it wasnā€™t raining.ā€

The English learner gets a better sentence, but thereā€™s room for improvement, and the learner might feel a bit lost.

What if the learners could receive tailored responses from a teacher who understands their interests, keeping them engaged?

Well, with the right prompts, AI can make this happen. Letā€™s go ahead and craft a prompt to achieve this.

Iā€™ll use this: ā€œI want you to act as my spoken English teacher. Iā€™ll speak to you in English, and youā€™ll reply to me in English to help me practice. Keep my reply neat within 100 words. Correct my grammar and typos, and ask a question in your reply. I want you to ask me a question first. Letā€™s begin!ā€

Now, this interaction becomes dynamic. The AI asks you questions, corrects your mistakes, and guides your learning journey.

Itā€™s an interactive experience, that transforms your learning process. All thanks to the carefully crafted prompt we provided.

You could even ask the AI to correct factual errors for a more enriching learning experience.

Pretty amazing, isnā€™t it? Weā€™ll explore more of these concepts soon, but letā€™s start with the basics for now.

Linguistics

Linguistics, in a nutshell, explores the intricate world of language.

It delves into a wide range of aspects, from the way we produce and perceive speech sounds (phonetics) to the study of sound patterns and changes (phonology).

Morphology is all about understanding how words are structured, while syntax focuses on the arrangement of words in sentences.

Semantics examines the meaning of words and phrases, and pragmatics looks at how language functions within different contexts.

Historical linguistics explores how languages change over time, while sociolinguistics investigates the connection between language and society.

Computational linguistics is the study of how computers can handle human language, and psycholinguistics delves into how humans learn and use language.

And much moreā€¦

Itā€™s quite a diverse field, isnā€™t it?

Now, you might wonder why linguistics is so important for engineering, specifically when it comes to crafting prompts.

Well, the key lies in understanding the nuances of language and how itā€™s employed in various situations.

By grasping these intricacies, we can create more effective prompts. Moreover, using a standardized grammar and language structure thatā€™s commonly accepted ensures that AI systems generate the most accurate results.

Since these systems are typically trained on vast amounts of data that adhere to universal language standards, maintaining this standardization is absolutely crucial.

Language models

Think of language models as the key to a world where computers can understand and produce human language effortlessly.

In this fantastic realm, machines chat, craft stories, and even compose poetry with ease, thanks to the magic of language models.

These models are like digital wizards, capable of comprehending and generating text that resembles human language.

So, whatā€™s the secret behind this wizardry? It all starts with a language model ingesting a vast amount of written content, from books and articles to websites.

It learns how humans use language, becoming a master linguist in the process, adept at conversing, maintaining grammar, and adhering to various writing styles.

To break it down further, when you input a sentence into a language model, it dissects the sentence, analyzing word order, meanings, and the way everything connects.

After this analysis, it generates a coherent prediction or continuation of the sentence, making it seem like it was crafted by a human.

Picture it as a conversation with a digital buddy ā€” you ask a question, and it provides a well-thought-out response. You share a joke, and it responds with a clever remark. Itā€™s like having a language expert at your disposal, always ready for a chat.

Now, you might be curious about where you can find these language models in action. Theyā€™re all around, from your smartphoneā€™s virtual assistants to customer service chatbots and even in the creative world of writing.

They help us find information, offer suggestions, and create content. But hereā€™s the thing to remember: these language models are a blend of human creativity and the power of algorithms, harnessing the strengths of both worlds.

History of language models

Letā€™s dive into the intriguing history of language models, starting with 1964 and the birth of the first AI, Eliza.

It was a pioneering natural language processing computer program developed at MIT by Joseph Weizenbaum between 1964 and 1966.

It was designed to simulate conversations with humans, particularly resembling the role of a Rogerian psychotherapist who listens attentively and asks insightful questions to help individuals explore their thoughts and emotions.

Elizaā€™s magic lay in its pattern-matching capability. It had an extensive collection of predefined patterns, each linked to specific responses, like enchanted spells enabling Eliza to comprehend and reply to human language.

In an interaction with Eliza, it would meticulously analyze your input, searching for patterns and keywords.

Your words were transformed into a sequence of symbols, which Eliza would then match against its stored patterns.

When a pattern was identified, Eliza would work its charm by converting your words into a question or statement designed to encourage deeper introspection.

For instance, if you write ā€œI am sadā€, Eliza would detect the pattern and respond with a question like, ā€œWhy do you think you feel sad?ā€ It encouraged reflection and introspection, akin to the support of a caring therapist.

However, thereā€™s an intriguing twist here: Eliza didnā€™t genuinely comprehend your words. It was a clever facade.

Eliza relied on pattern matching and ingenious programming to create the illusion of understanding while essentially following a set of predefined rules.

Nevertheless, people found themselves captivated by its conversational abilities. They felt heard and understood, even though they were aware they were conversing with a machine.

It was like having a digital confidant always ready to listen and provide gentle guidance. Interestingly, Weizenbaum, Elizaā€™s creator, initially designed the program to explore human-machine communication.

But was taken aback when individuals, including his secretary, ascribed human-like emotions to the computer program.

But thatā€™s a discussion in itself.

Eliza had a profound impact, sparking interest and research in the realm of natural language processing, paving the way for more advanced systems capable of genuine human language understanding and generation.

This marked the humble beginning of the remarkable journey into the world of conversational AI.

Fast forward to the 1970s, when we encountered ā€˜SHRDLUā€™, a program that could comprehend simple commands and interact with a virtual world of blocks.

While not precisely a language model, it laid the groundwork for machines understanding human language.

The real era of language models took off around 2010 when the potential of deep learning and neural networks came to the forefront. Enter GPT, or generative pre-trained transformer, a powerful entity poised to revolutionize the world of language.

In 2018, OpenAI introduced a rapidly evolving version of GPT, trained on huge amount of text data, encompassing knowledge from books, articles, and a substantial chunk of the internet.

GPT-1 was a glimpse of what was to come, an impressive language model dwarfed by its successors we use today.

Over time, the saga continued with the introduction of GPT-2 in 2019, followed by GPT-3 in 2020.

GPT-3 emerged as a titan among language models, equipped with an enormous number of parameters, exceeding 175 billion to be precise.

It captivated the world with its unparalleled capacity to understand, respond, and even generate creative pieces of writing.

The advent of GPT-3 marked a significant turning point in the landscape of language models and AI. As of the present, we now have GPT-3.5 and GPT-4, which are trained on virtually the entire internet, rather than outdated large datasets.

Additionally, thereā€™s Googleā€™s PaLM and many other innovations. It seems like weā€™re only scratching the surface in the realm of language models and AI.

Hence, mastering the art of harnessing this data through prompt engineering is a wise move for anyone in the present day.

Prompt Engineering Mindset

When youā€™re thinking about coming up with effective prompts, itā€™s crucial to approach it with the right mindset.

Essentially, your goal is to craft a single prompt that yields the desired result without wasting time and tokens on numerous attempts.

This approach is somewhat akin to how weā€™ve improved our Googling skills over the past five years.

Back then, we might have taken multiple tries to find the information we wanted, but now, weā€™ve become more adept at entering the right search terms from the get-go, saving time.

A similar mindset can be applied to prompt engineering.

Letā€™s take a quick look at how to use ChatGPT powered by OpenAI, specifically the GPT-3.5 model.

Iā€™ll be demonstrating examples using ChatGPT.

To follow along or understand how to use the platform, you can head over to openai.com and sign up for an account.

If youā€™ve already signed up, just log in, and that will take you to the platform where you can choose your preferred model.

By default, it is set on the GPT-3.5 model.

Excellent! You can see your previous chat interactions. If you want to start a new conversation, simply click the ā€œNew Chatā€ button.

For instance, you can ask a question like ā€œWhat is 1+1?ā€ and hit ā€œSendā€ to get a response. Youā€™re now interacting with ChatGPT.

You can also continue the conversation by building on what was previously discussed. For example, you can ask, ā€œGreat. Now, can you add another 8 to that? What is the answer?ā€ And it will consider the context.

This is just a brief introduction, and weā€™ll delve deeper in a minute.

To create a new chat, click the ā€œNew Chatā€ button, and if you want to delete the old one, use the ā€œDeleteā€ button. It will automatically bring up a new chat.

Wonderful! You can also use OpenAIā€™s API, which allows you to build your own applications. To use the API, go to the API references, get an API key, and create one. This key enables you to interact with the OpenAI API and build custom applications similar to what weā€™ve just seen.

Anyways, letā€™s continue using ChatGPT.

Tokens

Tokens, in this context, refer to chunks of text, which can be as short as a single character or as long as a word.

This means that GPT-3.5 can analyze and understand up to 4,000 tokens (around 3000 words) of text at once, making it highly proficient at comprehending lengthy passages, long conversations, and complex documents.

The generous context window is an essential feature for tasks like text generation, translation, summarization, and more.

It allows GPT-3.5 to maintain context and coherence in longer documents, improving its overall performance and making it more versatile for various applications.

In conclusion, GPT-3.5ā€™s substantial context window and tokens are pivotal elements that set it apart in the field of natural language processing.

These features enable it to tackle complex language-related tasks with unparalleled finesse, making it a powerful tool for developers and researchers exploring the frontiers of AI and NLP.

Basic prompt engineering practices

The concept of prompt engineering may seem straightforward, but thereā€™s more to it than meets the eye.

Itā€™s not just about crafting a single sentence, like the ā€œcorrect the given textā€ example weā€™ve seen earlier.

Creating powerful prompts involves considering several key factors. Here are some tips for composing effective prompts:

1. Clarity is Key

Ensure your instructions are clear and detailed in your query. Avoid assuming that the AI understands the specifics of what youā€™re asking.

For instance, instead of a vague question like ā€œWhen is the election?ā€ which leaves room for misinterpretation.

Specify the context, such as ā€œWhen is the next presidential election for France?ā€

Here, Iā€™m being more specific about the context.

This precision saves time and avoids potential frustration.

Letā€™s take another example.

It gave me a summary of the article as it thinks best. But this summary is still very long (I couldnā€™t take the entire summary in one screenshot though) and I donā€™t wanna read the entire text.

I want a more specific and more detailed summary of the essay. So letā€™s try another prompt.

Now, it describes the essay in bullet points as instructed in the prompt. I canā€™t capture the entire text in one screenshot but I hope you got an idea of how the prompt affects the results.

2. Personification

Now, letā€™s talk about adopting a ā€˜Personificationā€™. When working with writing prompts, it can be quite useful to create a persona.

This essentially means that youā€™re requesting the AI to respond as if it were a specific character.

Just like the example we saw earlier with the English language teacher, using a persona in prompt engineering can ensure that the language modelā€™s output aligns well with the needs and preferences of the intended audience.

This makes it a valuable tool for developing effective language models.

Letā€™s explore some examples of adopting a persona.

Consider this prompt: ā€œCompose a poem for a younger sisterā€™s high school graduation to be read aloud to family and close friends.ā€œ

Now, letā€™s run this prompt and see what the AI generates.

The poem is decent, maybe even better than what I could write. Itā€™s somewhat generic, though, but that might be what youā€™re looking for.

However, I believe we can aim for something even better.

Letā€™s try something else,

Now, Iā€™m going to use a persona in the prompt. Iā€™ll specify who Iā€™m writing as.

Hereā€™s the new prompt:

ā€œWrite a poem as Gracie. Gracie is a 25-year-old and a talented writer. Her writing style is akin to the famous 21st-century poet Rupi Kaur. Writing as Gracie, create a poem for her 18-year-old sisterā€™s high school graduation, which will be read to friends and family at the gathering.ā€

Now, letā€™s see what Chat GPT comes up with writing as Gracie, who has the style of Rupi Kaur, should give us a unique touch.

The result is much more affectionate.

We refer to the sister as the ā€œlittle sister,ā€ and in general, this poem is of higher quality. This poem is more refined and personal, thanks to the prompts we used.

3. Adjusting the format

Weā€™ve previously explored how to control the format of our text when we restrict the length of our bullet points. Itā€™s a handy technique I frequently use.

But there are plenty of other formatting options at our disposal. You can indicate if something is a summary, a list, or a detailed explanation. You can even craft checklists.

Letā€™s dive into how you can achieve this.

Iā€™ll provide an example prompt, and see what happensā€¦

Great! weā€™ve successfully created a checklist. The list is much longer but you know, I canā€™t capture the entire text in a single screenshot šŸ™

ChatGPT offers a wide range of formatting possibilities; just be clear about the format you want, and it should be able to deliver.

Letā€™s level up

Awesome, now that weā€™ve covered some basics, letā€™s dive into a little more advanced topics related to prompt engineering for natural language processing.

In this section, Iā€™ll talk about two different types of prompts:

  • Input and Output (IO) prompting
  • Chain of Thought (CoT) prompting

Input and Output (IO) prompting

IO prompting makes use of a pre-trained modelā€™s knowledge about words and how they relate to each other, without needing additional training.

This is the simplest type of prompting, in this you just need to give a single and detailed prompt.

All the prompts we used above in this article were examples of IO prompts.

Letā€™s look at one more super simple example:

Chain of thought (CoT) prompting

Now, letā€™s talk about CoT prompting, a technique that takes our interaction with ChatGPT a step further.

While IO prompting involves giving a prompt and receiving a response, CoT prompting requires additional training.

In this method, we enhance our language model by providing specific examples of tasks we want it to perform, giving it a small amount of relevant data to learn from.

Imagine if it doesnā€™t know your favorite types of food.

To address this, we can provide a few examples.

Initially, I asked, ā€œWhat is Haruā€™s favorite type of food?ā€

ChatGPT admits it doesnā€™t know, which is perfectly fine.

Next, we introduce some sample data: ā€œHaruā€™s favorite type of food includes Sushi, Takoyaki, and Pizza.ā€

With this knowledge, ChatGPT can suggest restaurants in Osaka that align with my preferences.

Although the information might be based on data up until January 2022, it still offers valuable recommendations.

This example demonstrates the concept of CoT prompting, showcasing how providing specific examples enables the model to answer complex questions it couldnā€™t address without adequate training.

CoT prompting is also highly helpful when you have a huge and pretty detailed prompt.

In that case, you need to break the task into multiple sections and try creating shorter prompts for each section.

That way, ChatGPT will process less information at a time and provide better results.

CoT prompting is one of the most commonly used prompt engineering techniques among professional prompt engineers.

Also, please check out the article ā€œThis prompt will change the way you use ChatGPTā€œ. it is perfect for beginners

AI hallucinations

Now, letā€™s talk about something unexpected in the area of artificial intelligence ā€” Hallucinations.

So, what exactly are AI hallucinations?

No, they donā€™t involve your AI assistants seeing unicorns and rainbows. Instead, this term refers to the peculiar, often erroneous, outputs generated by AI models when they misinterpret data.

A classic illustration of this is Googleā€™s Deep Dream, a project that transforms your photos into bizarre images.

Deep Dream is an experiment that visualizes the patterns learned by a neural network. It has a tendency to over-interpret and exaggerate patterns within images, essentially filling in gaps with its own interpretations.

But sometimes, these interpretations go astray, resulting in peculiar outcomes, which are a prime example of AI models misinterpreting data.

Now, the concept of hallucinations isnā€™t confined to image models; it can also manifest in text models like ChatGPT.

If it lacks the answer, it might generate a fabricated response, resulting in an inaccurate reply.

You might be wondering why these hallucinations occur. AI models are trained on extensive datasets and rely on their prior knowledge to make sense of new data.

However, occasionally, they make imaginative connections that lead to, letā€™s say, creative interpretations, and thatā€™s when an AI hallucination takes place.

Beyond their amusing results, these hallucinations offer valuable insights into how AI models comprehend and process data ā€” itā€™s like peering into their cognitive processes.

Conclusion

Ok! So, we discussed a whole lot of prompt engineering and its vital role in harnessing the power of language models like ChatGPT.

Weā€™ve explored the importance of clarity and personification in crafting effective prompts, as well as the significance of adjusting the format to optimize results.

As weā€™ve seen, prompt engineering is a key to unlocking the potential of AI, allowing us to interact with language models more effectively and produce meaningful outcomes.

Whether through Input and Output (IO) prompting, Chain of Thought (CoT) prompting, or addressing AI hallucinations, it is clear that understanding and mastering the art of prompt engineering is crucial in our journey to leverage the capabilities of language models to their fullest extent.

As we continue to advance in this field, prompt engineering will remain an indispensable tool, driving innovation and shaping the future of AI-powered communication and problem-solving.

Got any questions? Drop in the comments below!

--

--

Akhil Kumar
š€šˆ š¦šØš§š¤š¬.š¢šØ

AI enthusiast, prompt engineer, and blogger. Passionate about AI's real-life applications. Dedicated to providing valuable content, and knowledge.