Generative AIPrompt engineeringPrompting techniques

Combining prompting techniques

9 minutes read

The way you craft your prompts can greatly affect how well LLMs respond. Your prompt can include examples, scenarios, instructions, context, or steps for LLMs. In this topic, you'll learn to combine the prompt, which can enhance the performance of LLMs, where you can tackle complex problems with your guidance and training. Using combined prompting techniques results in more effective interactions with LLMs, as it allows for better overall results. This technique helps LLMs gain better insights into the problem's context and utilize the information provided by the user through prompts.

Exploring prompting techniques

Various prompting strategies, such as Zero-shot, Few-shot, and Chain-of-Thought (to name a few), can be used to prompt LLMs for tailored result generation. Here's a quick explanation of each technique:

Zero-shot prompting: In this technique, the prompt contains no examples or training that the LLMs could learn from and use to generate the answer. In the following example, it could not generate the right answer.

AI Advisor's avatar
Go ahead and try sending a question. You can try different models.
Question: Write a code in Python to calculate the sum of all even numbers in [2, 4, 6, 16, 1].

Few-shot prompting: Here, you need to provide examples relevant to your question. LLMs learn from these examples provided to them via prompts to generate their answers effectively.

AI Advisor's avatar
Go ahead and try sending a question. You can try different models.
Question: Calculate the sum of all even numbers in [2, 4, 6, 16, 1]. Use the pattern from following examples to generate the answer. Example 1. Question: [2, 4, 6] Answer: 12 Example 2. Question: [1, 2, 4, 7] Answer: 6

Chain-of-Thought prompting: In this technique, you provide detailed reasoning to the LLMs via prompts so that they can understand the context more clearly. From the following example, you can see how this approach leads to the correct result.

AI Advisor's avatar
Go ahead and try sending a question. You can try different models.
Question: Calculate the sum of all even numbers in [2, 4, 6, 16, 1]. Use the logic from following examples to generate the answer. Example 1. Question: [2, 4, 6] Answer: 12 Explanation: The even numbers in the list are 2, 4, 6, and 16. The sum of these even numbers is 2+4+6+16 Example 2. Question: [1, 2, 4, 7] Answer: 6 Explanation: The even numbers in the list are 2 and 4. The sum of these even numbers is 2 + 6

Context prompting: This technique involves giving enough background information in your question so that LLMs can generate a response tailored to your needs. It ensures that the model can produce a relevant and accurate result based on the provided context. Here is an example of it:

AI Advisor's avatar
Go ahead and try sending a question. You can try different models.
I need a workout routine that I can do at home. I have basic fitness equipment like dumbbells and a yoga mat. I want a routine that focuses on full-body exercises and takes around 30 minutes. Can you suggest something suitable? (in short)

By utilizing the distinctive strengths of each technique, you can create a powerful approach to AI prompting.

Prompting Strategies: Combinations of techniques

Combining various prompting techniques can be effective in obtaining the accuracy of responses from LLMs. Various methods of guiding LLMs include presenting scenarios, defining roles, providing detailed context, offering examples, and giving instructions. It can be useful in situations where your prompt might be complex or prone to misinterpretation. You might consider combining Few-shot prompting and Chain-of-Thought prompting so that LLMs can learn from the examples provided and generate results with reasoning, thereby achieving higher accuracy. Below is an example of how this can be applied.

AI Advisor's avatar
Go ahead and try sending a question. You can try different models.
Question: For a game selection process, there were initially 40 participants. After every 7 minutes, a round of selection occurred, removing 4 participants. The total of 16 participants was removed. How much time, in total, did the game selection process take? Use the following examples to solve the above question: Example 1. Question: For a game selection process, there were initially 30 participants. After every 22 minutes, a round of selection occurred, removing 3 participants. The total of 9 participants was removed. How much time, in total, did the game selection process take? Answer: Initially, there were 30 participants. In every round, 3 participants were removed, and each round lasted for 22 minutes. A total of 9 participants were removed in total, which corresponds to 3 rounds since (9 participants removed/ 3 participant each round = 3 rounds). To calculate the total time taken, multiply the number of rounds by the duration per round: 3 rounds * 22 minutes = 66 minutes. Example 2. Question: For a game selection process, there were initially 50 participants. After every 20 minutes, a round of selection occurred, removing 5 participants. The total of 10 participants was removed. How much time, in total, did the game selection process take? Answer: Initially, there were 50 participants. In every round, 5 participants were removed, and each round lasted for 20 minutes. A total of 10 participants were removed in total, which corresponds to 2 rounds since (10 participants removed/ 5 participant each round = 2 rounds). To calculate the total time taken, multiply the number of rounds by the duration per round: 2 rounds * 20 minutes = 40 minutes.

As seen in the prompt, two detailed examples are provided, each demonstrating the correct approach to solving specific questions. These examples serve as instructive few-shot prompts, guiding LLMs to accurate solutions. These examples not only give us the final answer but also guide LLMs through the process of reaching the right solution. This is where the Chain-of-Thought technique is utilized, which can make the reasoning process easy to follow and understand. What's particularly helpful is the 'Answer' section, which breaks down the process of how these answers have been found. It dives into why we calculate the number of rounds and how this step contributes to figuring out the total time required for the selection process. As a result, the response we get won't just be correct but will also come with logical reasoning.

Successful integration of combined prompting methods

Combined prompting methods can be successfully applied in LLMs like ChatGPT, Claude, Gemini, and others. Using these methods enhances contextual understanding and results in more accurate and personalized responses. The application of combined prompting becomes crucial when addressing complex problems that require precise guidance. Here are some use cases of the combined prompting method:

Classifying the texts.

You might have traveled to various places and likely used hotel apps where you can see ratings and reviews of different hotels. Some reviews are positive, some negative, and others a mix of both. Similarly, let's have a look at a prompt that determines whether a review is positive or negative. This prompt utilizes three different techniques: Context prompting, Chain-of-Thought prompting, and Few-shot prompting.

In this example, context is provided to make the LLMs more aware of the task. For instance, it informs them that the texts to be classified will consist of the experiences shared by customers. This prepares the LLMs to expect reviews specifically about hotels and their services. Next, Few-shot prompting is utilized to provide examples that illustrate correct answers for different types of customer reviews. This approach enables LLMs to learn from these examples, enhancing their ability to generate relevant and accurate answers to your question.

AI Advisor's avatar
Go ahead and try sending a question. You can try different models.
ABC is a hotel booking app where customers can review their experiences. What would be the classification for the review based on learning how to classify the review as negative or positive: Review: The staff were incredibly friendly and helpful. Classification: Positive Review: I had a bad experience at this hotel. The air conditioning was broken. Classification: Negative Review: We had a wonderful experience at this beautiful hotel. Classification: Positive Review: The service was terrible, and the location was noisy. Classification: Negative Review: This hotel exceeded my expectations. The rooms were spacious. Classification:

Solving complex mathematical problems.

In this example, you can observe the combination of Chain-of-Thought prompting and Few-shot prompting. The Chain-of-Thought prompt helps to provide the reasoning behind the steps taken by LLMs to arrive at the final answer. For instance, it explains why numbers were multiplied or added in a particular calculation. This approach allows the model to learn from existing data effectively. It enhances the accuracy of generating answers by utilizing patterns and information extracted from these examples. As a result, the model's ability to handle a wide range of queries and scenarios is further strengthened.

AI Advisor's avatar
Go ahead and try sending a question. You can try different models.
Question: A shipping company is loading containers onto ships, which is capable of holding up to 50 containers. The loading rates vary throughout the day: from 9:00 AM to 12:00 PM, containers are loaded at 6 per hour; from 12:00 PM to 3:00 PM, the rate is 4 per hour; and from 3:00 PM to 6:00 PM, it increases to 8 per hour. There is a scheduled break from 12:00 PM to 1:00 PM, during which no containers are loaded. What is the total number of containers loaded by the end of the day? Use the logic from following examples and format to generate the answer: Question: As an experienced mathematician, consider a scenario where a shipping company is loading containers onto ships, which is capable of holding up to 80 containers. The loading rates vary throughout the day: from 8:00 AM to 12:00 PM, containers are loaded at 3 per hour; from 12:00 PM to 2:00 PM, the rate is 6 per hour; and from 3:00 PM to 7:00 PM, it increases to 5 per hour. There is a scheduled break from 12:00 PM to 1:00 PM, during which no containers are loaded. What is the total number of containers loaded by the end of the day? Answer: The ship has the capacity to hold 80 containers. There is a scheduled break from 12:00 PM to 1:00 PM. It loads 3 container per hour between the time 8:00 AM to 12:00 PM, which means the total container loaded in the ship in this time period is 4 * 3 = 12. It loads 6 container per hour between the time 12:00 PM to 2:00 PM, but there is a scheduled break from 12:00 PM to 1:00 PM. This means the total container loaded in the ship in this time period is 1 * 6 = 6. It loads 5 container per hour between the time 3:00 PM to 7:00 PM, which means the total container loaded in the ship in this time period is 4 * 5 = 20. So, the total number of container in ship is 38. Question: As an experienced mathematician, consider a scenario where a shipping company is loading containers onto ships, which is capable of holding up to 40 containers. The loading rates vary throughout the day: from 7:00 AM to 12:00 PM, containers are loaded at 3 per hour; from 12:00 PM to 2:00 PM, the rate is 3 per hour; and from 4:00 PM to 8:00 PM, it increases to 2 per hour. There is a scheduled break from 12:00 PM to 1:00 PM, during which no containers are loaded. What is the total number of containers loaded by the end of the day? Answer: The ship has the capacity to hold 40 containers. There is a scheduled break from 12:00 PM to 1:00 PM. It loads 3 container per hour between the time 7:00 AM to 12:00 PM, which means the total container loaded in the ship in this time period is 5 * 3 = 15. It loads 3 container per hour between the time 12:00 PM to 2:00 PM, but there is a scheduled break from 12:00 PM to 1:00 PM. This means the total container loaded in the ship in this time period is 1 * 3 = 3. It loads 3 container per hour between the time 4:00 PM to 8:00 PM, which means the total container loaded in the ship in this time period is 4 * 2 = 8. So, the total number of container in ship is 26.

Conclusion

In this exploration of combining various prompting techniques to enhance LLM performance, the significance of using various prompts like Chain-of-Thought, Context, and Few-shot has been highlighted. They can be applied to solve complex mathematical problems, classify texts, and in situations where LLMs could misinterpret the prompt. Through these methods, LLMs are equipped to deliver more accurate and insightful responses, which enhances their utility across various use cases.

Chain-of-Thought prompts encourage the LLM to explain the reasoning process step-by-step. Few-shot prompting provides examples to LLMs so that they can learn from them and generate accurate answers. Context prompting is particularly useful for providing background information necessary for the task.

2 learners liked this piece of theory. 0 didn't like it. What about you?
Report a typo