4 Methods of Prompt Engineering
Bahram Khanlarov
???? Azure Certified Data Analyst | Python | SQL | Power BI | Tableau | R | Hospitality Trained
Large language models are used for various tasks. Most people are familiar with chatbots, which we encounter frequently. These models are also employed for summarization, and another common use case is information retrieval. These are three distinct applications. But how does this relate to prompt engineering?
Prompt engineering is crucial for effectively communicating with large language models. What does it mean? It involves designing and crafting the right questions to elicit the responses you want from the model. This is important because we want to avoid hallucinations, which occur when a large language model generates false or misleading results. These hallucinations happen because large language models are primarily trained on internet data, which can contain conflicting information and inaccuracies.
RAG
So the large language models, as we know, are trained on the Internet data. They are not aware of our domain specific knowledge base content at all. So when you are querying the LLM models, you want to bring awareness of your knowledge base to the large language models. So when we say knowledge base here, we are referring to something that might be specific to your industry, specific to your company, which you are going to then be applied to the model. So how it works?
Retrieval-Augmented Generation (RAG) is a prompt engineering approach that involves adding domain-specific knowledge to your LLM. To do this, two components are necessary: a retriever component that brings the context of your knowledge base to the generator part of the LLM, and the generator part that responds to your questions based on both the input and the knowledge base. This approach helps ensure accurate responses by grounding the LLM in your specific domain.
Here is practical example of how Retrieval-Augmented Generation (RAG) can be used:
Let's say you work at a biotechnology company that is developing a new drug. You have a large amount of internal research and clinical trial data about the drug's development and performance. You want to use a large language model to assist with answering questions about the drug, but you know the model has not been trained on your company's specific data.
Using the RAG approach, you would first set up a retrieval component that can access your company's internal knowledge base containing all the details about the drug. This might include information like the drug's composition, the results of animal and human trials, potential side effects, and manufacturing details.
When a user asks the large language model a question like "What are the key side effects of Drug X based on the clinical trials?", the retrieval component would first find the relevant information from your company's drug data. It would then pass that context to the generation component of the language model.
The generation component would then use both the user's question and the retrieved data about the drug to produce a response. This allows the language model to provide an informed, accurate answer about the drug's side effects, drawing on the real data from your company's research rather than just general medical knowledge.
The RAG approach ensures the language model's responses are grounded in the specific domain knowledge your company has about this particular drug candidate. This makes the model much more useful and reliable for answering questions compared to relying solely on its broad, generic training data.
Chain-of-Thought
Chain of thought (CoT) prompting is a technique used in prompt engineering to improve the reasoning and accuracy of large language models, especially in tasks that require complex, multi-step reasoning(Wei et al. 2022). The idea behind CoT prompting is to guide the model to break down a problem into a series of logical steps or intermediate stages, which it then solves one by one, leading to a final answer.
The key aspects of the COT approach are:
ReAct: Reasoning and Acting
ReAct?(Reason + Act;?Yao et al. 2023)
领英推荐
It is a prompt engineering approach that combines the reasoning of Chain-of-Thought with the ability to gather additional information from external sources. React goes beyond content grounding in your private knowledge base by also accessing public resources to supplement its responses. This approach allows for more comprehensive and informed answers, especially when the necessary information is not available in your private knowledge base.
React's operates in a three-step process:
1. Thought: Defining the goal of the prompt.
2. Action: Specifying where the necessary information can be found.
3. Observation: Combining the information from both the private and external knowledge bases to arrive at a final response.
Directional Stimulus Prompting (DSP)
Directional Stimulus Prompting (DSP), introduced by Z. Li in 2023, is an innovative approach for steering black-box large language models (LLMs) towards specific desired outcomes. Rather than modifying the LLMs directly, this technique uses a smaller, adjustable policy model to create an auxiliary prompt (or hints) that guides the LLM's response for each input.
References
Weng, Lilian. (Mar 2023). Prompt Engineering. Lil’Log.
IBM (Jan 2024) 4 Methods of Prompt Engineering
Jeff Su (Aug 2023) Master the Perfect ChatGPT Prompt Formula