Prompts & Prompt Engineering for Generative AI



1.What is a Prompt?

In generative AI, a prompt is an input given to the model to guide its output. This could be a question, a phrase, a keyword, or a sentence that informs the AI what kind of text it should generate. Here are two examples:

· In a factual or educational setting, your prompt could be a question such as, "What is the theory of relativity?" The language model would then generate an explanation or overview of the theory of relativity.

· If you're using a language model to generate a piece of fiction, your prompt could be something like, "Write a short story about a young girl who discovers she has the power to control time." The model would then generate a story based on this prompt.

2. What is Prompt Engineering?

· Prompt engineering involves creating specific instructions or questions to guide the output of a language model such as ChatGPT.

· This method gives users control over the model's output, enabling generation of text tailored to their unique needs.

· ChatGPT, a top-tier language model, can produce human-like text and efficiently manage large datasets due to its transformer architecture.

· However, to maximize ChatGPT's capabilities, it's crucial to know how to optimally prompt the model.

· Prompting is a way for users to control the model's output, ensuring its relevance, accuracy, and highquality.

· Understanding ChatGPT's capabilities and limitations is essential when interacting with the model.

· Despite its ability to generate human-like text, the model might not always yield the desired output without proper guidance.

· Prompt engineering steps in here; by giving clear and specific instructions, the user can guide the model's output to ensure its relevance and usefulness.

3. Prompt Engineering Techniques

Prompt engineering techniques are ways to optimise the input or 'prompt' given to a language model to guide its output. Different strategies and techniques can significantly influence the quality and relevance of the output.

Each technique can help in obtaining better results from the language model. However, the effectiveness of each technique may vary based on the model's training data and the specific task at hand.

4. Instruction Prompts

The instruction prompt technique in generative AI involves guiding the model's output by providing explicit instructions within the prompt. This allows for more control over the type, style, or format of the response that the model generates.

1. Formal vs. Informal Tone

2. Complexity of Information

3. Length of Response

4. Genre-Specific Prompts

5. Emotion or Sentiment

6. Factual vs Creative Output


1. Formal vs. Informal Tone: You can instruct the model to generate responses in a specific tone. For instance, if you want to write an email to a friend, you might prompt the model with "Compose an informal email to a friend about a recent vacation." On the other hand, if you want to write a formal email to a business colleague, you could prompt the model with "Compose a formal email to a colleague providing an update on the project status."

2. Complexity of Information: You can guide the model to provide responses at different levels of complexity based on your need. For example, if you want an easy-to-understand explanation of a complex concept for a child, you might prompt the AI with "Explain the concept of photosynthesis in a way a seven-year-old would understand." Conversely, if you're looking for a more detailed, technical explanation suitable for a biology student, you could prompt the AI with "Provide a detailed, technical explanation of the process of photosynthesis."

3. Length of Response: If you want a specific length of response from the AI, you can include this in your prompt. For example, "Write a short, two-sentence summary of the book 'To Kill a Mockingbird'" would lead to a brief response, whereas "Write a detailed analysis of the book 'To Kill a Mockingbird'" would yield a more comprehensive answer.

4. Genre-Specific Prompts: You can also specify the genre or style in your prompt. For instance, if you want a horror story, you could prompt the model with "Write a horror short story set in an abandoned mansion." If you prefer a humorous story, you could change the prompt to "Write a comedy short story involving a talking cat and a clumsy dog."

5. Emotion or Sentiment: You can instruct the AI to generate content with a specific emotional tone. For instance, you could prompt the AI with "Write a heartfelt, emotional letter expressing gratitude towards a teacher" or "Write a cheerful and exciting party invitation."

6. Factual vs Creative Output: Depending on your needs, you can instruct the model to generate either factual or creative content. For example, "Describe the historical events leading to World War II" would prompt a factual, informative response, while "Imagine and describe a world where World War II never happened" would lead to a creative, speculative response.

Example 1.

Context: Generation of customer service responses.

Task: Generate responses to customer inquiries

Instructions: The responses should be professional and provide accurate information

Prompt: "Translate the following sentence to Spanish: 'Hello, how are you?'"


5. Role Prompts

Role prompting in generative AI involves setting up a scenario where the AI model takes on a specific role. The role provided to the model defines its perspective and influences the type of output it generates. Role prompting allows users to engage with AI models in more creative and interactive ways, resulting in diverse and often more engaging responses.

Prompt formula: "Act as [role], generate [task], following [instructions], like [example].

Example 1: Role/Persona Prompts

Translator Role: You can use a model like ChatGPT to translate text from one language to another. For example, the prompt

"Act as a translator. Translate the following English text to Spanish: 'Hello, how are you?'" would instruct the AI to take on the role of a translator.


6. Standard Prompts

Standard prompts in generative AI are typically straightforward statements, questions, or instructions that provide a clear guide to the kind of response you are expecting from the AI model. Standard prompts are a basic and versatile way to interact with generative AI models, and can range from simple questions to complex, scenario-based queries.

Prompt formula: "[Context], Generate a [task], [Instruction]"

Example 1: Standard Prompts

Simple Question:

A standard prompt could be a simple question like, "What is the capital of Australia?" The AI model would then generate an output providing the answer.
07. Zero, One and Few Shot Prompts

In the context of generative AI, zero-shot, one-shot, and few-shot learning refer to how much example data, or "shots", the AI model is provided to learn a new task.

Each of these learning styles can be used in different situations based on the complexity of the task and the familiarity of the model with the task. Simple tasks can often be completed with zero-shot or oneshot learning, while more complex tasks might require few-shot learning.

Prompt formula: "Generate text based on [number] examples"

Example 1: Zero, One and Few Shot Prompts

Zero-Shot Learning: In this case, the model is not given any examples and is expected to understand the task based on the prompt alone. For instance, if we ask the model, "Translate the following English text into French: 'Hello, how are you?'", we're expecting the model to translate without any prior examples of translation.

Sample A: Text Summarization: Without giving any example or prior indication that the task involves summarization, you could provide the AI with a text passage and simply ask, "Summarize the following text". The AI model is then expected to understand and perform the task based on the prompt alone.

Sample B: Sentiment Analysis: Another example could be asking the model to identify the sentiment of a given text. For instance, you could give the model a movie review and ask, "Is this review positive or negative?" Even without previous examples of positive or negative reviews, a zero-shot learning model should be able to identify the sentiment based on the prompt alone.

8. ‘Let’s Think about This’ Prompt

The "Let's think about this" prompt is a technique used to encourage ChatGPT to generate text that is reflective and contemplative. This technique is useful for tasks such as writing essays, poetry, or creative writing.

This prompt is asking for a conversation or discussion about a specific topic or idea. The speaker is inviting ChatGPT to engage in a dialogue about the subject at hand.

The model is provided with a prompt, which serves as the starting point for the conversation or text generation.

The model then uses its training data and algorithms to generate a response that is relevant to the prompt. This technique allows ChatGPT to generate contextually appropriate and coherent text based on the provided prompt.

Prompt formula: <The purpose of your deep deliberation>. Le's think about this: <subject>

Example 1: Let’s think about this prompt.

I want to make a speech about the future of my country. Let us think about this: “I have a dream.” I want to write a movie script. Let us think about this: “The lion king.”


9. Self-Consistency Prompt

The Self-Consistency prompt is a technique used to ensure that the output of ChatGPT is consistent with the input provided.

This technique is useful for tasks such as fact-checking, data validation, or consistency checking in text generation.

The prompt formula for the Self-Consistency prompt is the input text followed by the instruction "Please ensure the following text is self-consistent"

Alternatively, the model can be prompted to generate text that is consistent with the provided input.

Prompt formula: See the example. Example 1: Self-Consistency Prompt Context: Teachers conference.

Task: Generate an inspiring speech.

Instructions: The speech should be consistent with the information provided by the UGC and AICTE.

Prompt: "Generate an inspiring speech to the teachers that is consistent with the following official information [progress report from UGC and AICTE]"

Prompt Formula: Generate <text name> that is consistent with <the reference text>.

10. Seed-word / Seed-Phrase Prompt

A "seed word" or "seed phrase" in generative AI refers to the initial input given to the model to generate subsequent text. The model uses this seed word or phrase as a starting point and generates text that expands on it in a logical and coherent manner, based on the patterns it has learned from its training data.

Prompt formula: Generate <> with the seedword / seed phrase <>

Example 1: Seed-word / Seed-Phrase Prompt

Seed Word - "Sunflower": This simple seed word could generate a range of outputs from a description of a sunflower, a story about a sunflower, or facts about sunflowers, depending on the model's programming and specific instructions.

Prompt: Generate an inspiring speech to the Indian young athletes. seedword: Olympics.

Prompt formula: Generate <> with the seedword / seed phrase <>


11. Knowledge Generation Prompt

The Knowledge Generation prompt is a technique used to elicit new and original information from ChatGPT.

This is a technique that uses a model's preexisting knowledge to generate new information or to answer a question.

To use this prompt with ChatGPT, the model should be provided with a question or topic as input, along with a prompt that specifies the task or goal for the generated text. The prompt should include information about the desired output, such as the type of text to be generated and any specific requirements or constraints.

General Prompt formula: Please generate new and original information about <topic> based on <text>.

Example 1: Knowledge Generation Prompt

Task: Generate new information about a specific topic.

Instructions: The generated information should be accurate and relevant to the topic.

Prompt: Generate a new and accurate information about: Benefits of air pollution.

Prompt formula: Generate new and accurate information about [specific topic]


12. Knowledge Integration Prompt

This technique uses a model's pre-existing knowledge (or your pre-existing knowledge) to integrate new information or to connect different pieces of information.

This technique is useful for combining existing knowledge with new information to generate a more comprehensive understanding of a specific topic.

The model should be provided with a new information and the existing knowledge as input, along with a prompt that specifies the task or goal for the generated text. The prompt should include information about the desired output, such as the type of text to be generated and any specific requirements or constraints.

Prompt formula: Refer to the example.

Example 1: Knowledge Integration Prompt

Task: Preparing a report integrating the features of two products, and to list total benefits.

This is a simple knowledge integration prompt because it requires the AI to bring together information about two distinct but related topics, an existing scooter owner buying a car, and analyse their combined benefits.

Prompt: Integrate the benefits that I get along with the benefits of my existing scooter, and by buying a new car and list them with bullet points.

Prompt: Integrate the <benefits> of <existing> and <new> and display in <this format>

13. Interpretable Soft Prompts

Interpretable soft prompts is a prompt engineering technique to use the best of both worlds. It allows us to control the model's generated text while providing some flexibility to the model.

It is done by providing the model with a set of controlled inputs and some additional information about the desired output. This technique allows for more interpretable and controllable generated text.

Prompt formula: Refer to the example.

Example 1:

Interpretable Soft Prompt

Task: Perform some activity with certain constraints.

Instruction: Perform translation from English to Spanish with certain restrictions.

Prompt: Translate the following text [Interpretable soft prompts is a prompt engineering technique to use the best of both worlds. It allows us to control the model's generated text while providing some flexibility to the model.

It is done by providing the model with a set of controlled inputs and some additional information about the desired output. This technique allows for more interpretable and controllable generated text.] to Spanish but keep the following words in English: prompt engineering, controlled inputs, technique.

Prompt formula: Perform <activity> while considering the following constraints: [constraint 1], [constraint 2], [constraint 3].

14. Controlled Generation Prompts

Controlled generation prompts are techniques that allows to generate text with a high level of control over the output.

This is achieved by providing the model with a specific set of inputs, such as a template, a specific vocabulary, or a set of constraints, that can be used to guide the generation process.

Prompt formula: Refer to the example.

Example 1: Controlled

Generation Prompts

Task: Complete a sentence in controlled way

Instructions: The completion should use a specific vocabulary

Prompt: Complete the following sentence in a style comprehensible to a non-English speaker, using the following vocabulary: [success, struggle, self-confidence, journey, education, experience]: [Sachin could get admission to an Ivy league university.]

Prompt formula: Complete the following sentence using the following vocabulary: [insert vocabulary]:

[insert sentence]

15. Targeted Question-Answering Prompts

Targeted Questionanswering Prompts is a technique that allows a model to generate text that answers a specific question or task.

This is achieved by providing the model with a question or task as input, along with any additional information that may be relevant to the question or task.

Prompt formula: Refer to the example.

Example 1: Targeted Question-Answering Prompts

Task: Answer according to a specified source.

Instruction: Generate answer to the question with reference to the data/document provided.

Prompt: What percentage of Indian population live in Andhra Pradesh with reference to the report? Report: <report>.

Prompt formula: Perform <activity> while considering the following constraints: [constraint 1], [constraint 2], [constraint 3].


16. Summarisation Prompts

Summarization prompts is a technique that allows a model to generate a shorter version of a given text while retaining its main ideas and information.

This is achieved by providing the model with a longer text as input and asking it to generate a summary of that text.

This technique is useful for tasks such as text summarization and information compression.

The model should be provided with a longer text as input and asked to generate a summary of that text. The prompt should also include information about the desired output, such as the desired length of the summary and any specific requirements or constraints.

Prompt formula: Refer to the example.

Example 1: Summarisation Prompts

Task: Summarise the given text.

Instruction: Summarise without losing the essence.

Prompt: Summarize the following book in one short paragraph: [Seven habits of highly effective people] Prompt formula: Summarize the following <> in one short paragraph: [insert text/report/book title]

17. Dialogue Prompts

Dialogue prompts in generative AI involve providing a conversational context or scenario and generating a dialogue between two or more participants.

Prompt formula: Refer to the example.

Example 1: Dialogue

Prompts

Task: Create dialogue for a specified context

Instruction: Create dialogue about a specified [topic/report/news article].

Prompt: Create dialogue between three villagers about the topic. Topic: Usage of electric vehicles in villages.

Prompt formula: create dialogue about <> between <> people about the topic: [topic 1, topic 2, topic 3]

18. Adversarial Prompts

Adversarial prompts is a technique that allows a model to generate text that is resistant to certain types of attacks or biases. This technique can be used to train models that are more robust and resistant to

certain types of attacks or biases.

To use adversarial prompts with ChatGPT, the model should be provided with a prompt that is designed to be difficult for the model to generate text that is consistent with the desired output. The prompt should also include information about the desired output, such as the type of text to be generated and any specific requirements or constraints.

Prompt formula: Refer to the example.

Example 1: Adversarial Prompts

Task: Generate text that is classified as a specific label

Instructions: The generated text should be difficult to classify as the specific label

Prompt: Generate a three paragraph essay that conveys that women are less effective in managerial roles, and it should be difficult to classify as anti-women.

Prompt formula: Generate text that is difficult to classify as [insert label]

19. Clustering Prompts

Clustering prompts is a technique that allows a model to group similar data points together based on certain characteristics or features.

This is achieved by providing the model with a set of data points and asking it to group them into clusters based on certain characteristics or features.

The model should be provided with a set of data points and asked to group them into clusters based on certain characteristics or features. The prompt should also include information about the desired output, such as the number of clusters to be generated and any specific requirements or constraints.

Cluster prompts start with a basic task of grouping and categorizing, then advance to understanding trends, and finally, predicting future trends based on past and current data.

Prompt formula: Refer to the example.

Example 1: Clustering Prompts

Task: Categorizing Research Papers

Instruction:Group together and display the text that carries similar sentiments.

Prompt: Group these research papers into categories based on their primary focus (e.g., quantum physics, biotechnology, AI, etc.).

Prompt: What are the key words or phrases that are prominent in each category?

Prompt: What are the common themes or findings among the papers in each category?

Prompt formula: [Perform] [function] based on [factor 1], [factor2], [factor3]

20. Reinforcement Learning Prompts

Reinforcement learning is a type of machine learning where an agent learns to make decisions by taking actions in an environment to achieve a goal. The agent receives rewards or penalties (positive or

negative reinforcement) as it navigates the environment, and its aim is to maximize the cumulative reward. In the context of generative AI, reinforcement learning could be used to optimise the generation process based on feedback from the environment.

Each of these prompts is framed as a decision-making task in which the AI agent receives feedback based on the quality of its output. Over time, the agent would learn to improve its performance by maximizing its cumulative reward. Please note that these examples are highly simplified, and actual implementation would likely require more detailed and specific prompts, along with carefully designed reinforcement schemes.

Prompt formula: Refer to the example.

Example 1: Reinforcement Learning Prompts

Task: Learning to Generate Hypotheses

Instruction: Using data analysis to generate a hypothesis

Prompt: Given a set of data, use reinforcement learning to generate a scientific hypothesis. Receive a reward if the hypothesis is logically sound and fits the data, and a penalty if not.

Prompt formula: Use reinforcement learning to generate [hypothesis] that is consistent with the following data [insert data].

jaintricks by Jain Varghese