[ad_1]
Getting the most out of LLM models as a Data Analyst with Prompt Engineering
Large Language Model (LLM) is on the rise, driven by the popularity of ChatGPT by OpenAI which took the internet by storm. As a practitioner in the data field, I look for ways to best utilize this technology in my work, especially for insightful-yet-practical work as a Data Analyst.
LLMs can solve tasks without additional model training via “prompting” techniques, in which the problem is presented to the model as a text prompt. Getting to “the right prompts” are important to ensure the model is providing high-quality and accurate results for the tasks assigned.
In this article, I will be sharing the principles of prompting, techniques to build prompts, and the roles Data Analysts can play in this “prompting era”.
Quoting Ben Lorica from Gradient Flow, “prompt engineering is the art of crafting effective input prompts to elicit the desired output from foundation models.” It’s the iterative process of developing prompts that can effectively leverage the capabilities of existing generative AI models to accomplish specific objectives.
Prompt engineering skills can help us understand the capabilities and limitations of a large language model. The prompt itself acts as an input to the model, which signifies the impact on the model output. A good prompt will get the model to produce desirable output, whereas working iteratively from a bad prompt will help us understand the limitations of the model and how to work with it.
Isa Fulford and Andrew Ng in the ChatGPT Prompt Engineering for Developers course mentioned two main principles of prompting:
- Principle 1: Write clear and specific instructions
- Principle 2: Give the model time to “think”
I think prompting is like giving instructions to a naive “machine kid”.
The child is very intelligent, but you need to be clear about what you need from it (by providing explanations, examples, specified output format, etc) and give it some space to digest and process it (specify the problem-solving steps, ask it to slowly process it). The child, given its exposure, can also be very creative and imaginary in providing answers — which we call a hallucination of the LLM. Understanding the context and providing the right prompt might help in avoiding this problem.
Prompt engineering is a growing field, with research on this topic rapidly increasing from 2022 onwards. Some of the state-of-the-art prompting techniques commonly used include n-shot prompting, chain-of-thought (CoT) prompting, and generated knowledge prompting.
A sample Python notebook demonstrating these techniques is shared under this GitHub project.
1. N-shot prompting (Zero-shot prompting, Few-shot prompting)
Known for its variation like Zero-shot prompting and Few-shot prompting, the N in N-shot prompting represents the number of “training” or clues given to the model to make predictions.
Zero-shot prompting is where a model makes predictions without any additional training. This works for common straightforward problems like classification (i.e. sentiment analysis, spam classification), text transformation (i.e. translation, summarizing, expanding), and simple text generation on which the LLM has been largely trained.
Few-shot prompting uses a small amount of data (typically between two and five) to adapt its output based on these small examples. These examples are meant to steer the model to better performance for a more context-specific problem.
2. Chain-of-Thought (CoT) prompting
Chain-of-Thought prompting was introduced by Google researchers in 2022. In the Chain-of-Thought prompting, the model is prompted to produce intermediate reasoning steps before giving the final answer to a multi-step problem. The idea is that a model-generated chain of thought would mimic an intuitive thought process when working through a multi-step reasoning problem.
This method enables models to decompose multi-step problems into intermediate steps, enabling them to solve complex reasoning problems that are not solvable with standard prompting methods.
Some further variations of Chain-of Thought prompting include:
- Self-consistency prompting: Sample multiple diverse reasoning paths and select the most consistent answers. By utilizing a majority voting system, the model can arrive at more accurate and reliable answers.
- Least-to-Most prompting (LtM): Specify the chain of thought to first break a problem into a series of simpler subproblems and then solve them in sequence. Solving each subproblem is facilitated by the answers to previously solved subproblems. This technique is inspired by real-world educational strategies for children.
- Active Prompting: Scaling the CoT approach by determining which questions are the most important and helpful ones for human annotation. It first calculates the uncertainty among the LLM’s predictions, then select the most uncertain questions, and these questions are selected for human annotation before being put into a CoT prompt.
3. Generated knowledge prompting
The idea behind the generated knowledge prompting is to ask the LLM to generate potentially useful information about a given question/prompt, and then leverage that provided knowledge as additional input for generating a final response.
For example, say you want to write an article about cybersecurity, particularly cookie theft. Before asking the LLM to write the article, you can ask it to generate some danger and protection against cookie theft. This will help the LLM write a more informative blog post.
Additional tactics
On top of the above-specified techniques, you can also use these tactics below to make the prompting more effective
- Use delimiters like triple backticks (“`), angle brackets (<>), or tags (<tag> </tag>) to indicate distinct parts of the input, making it cleaner for debugging and avoiding prompt injection.
- Ask for structured output (i.e. HTML/JSON format), this is useful for using the model output for another machine processing.
- Specify the intended tone of the text to get the tonality, format, and length of model output that you need. For example, you can instruct the model to formalize the language, generate not more than 50 words, etc.
- Modify the model’s temperature parameter to play around the model’s degree of randomness. The higher the temperature, the model’s output would be random than accurate, and even hallucinate.
A sample Python notebook demonstrating these techniques is shared under this GitHub project.
As you can possibly infer from the examples above, prompt engineering requires a very specific technical communication craft. While you still require business context and problem-solving skills, it is still a new kind of craft that is not entirely covered as part of a conventional data analytics skillset.
Data Analysts can leverage their context knowledge, problem-solving skills, and statistical/technical capabilities, with the addition of effective communication for prompt engineering. These are the key tasks related to prompt engineering (and LLMs) which potentially be done by Analysts:
- Specifying LLM problems to be solved. With an understanding of the LLM concepts, we can define the actions to be executed by the model (i.e. whether it is text classification, generation, or transformation problem) and the right question with reference points to be put as the prompts.
- Iterative prompting. In developing a data model, oftentimes we go through an iterative process. After building the initial model, we evaluate the result, refine it, and retry it along the way. Similarly for a prompt, we analyze where the result does not give what you want, and refine it with clearer instructions, additional examples, or specified steps. This requires critical reasoning which most Data Analysts are already good at.
- Prompt versioning and management. With iterative prompting, you will end up with numerous prompt attempts, and the identified model capabilities and/or limitations. It is important to keep track of and document these findings for team learning and continuous improvement, as with any other existing data analysis.
- Designing for safe-prompting. Although it has shown impressive capabilities, LLM is still in a very early stage and is prone to loopholes and limitations. There is this hallucination problem where models provide highly misleading information, and also prompt injection risk of getting untrusted text is used as part of the prompt. Depending on the use case of the model and prompting, Analysts can advise programmatic safeguards to limit the prompt usage and analysis of problematic prompting detection.
On top of leveraging the existing skills, Analysts need to hone their communication skills and the ability to break down problems to provide better prompts.
Large Language Models have shown promising results in performing numerous types of language tasks, and prompt engineering is the key to unlocking these capabilities. Prompt engineering is about communicating effectively with an AI to achieve desired results.
Several techniques can be used to do prompt engineering, but the foundational principle is consistent. It is about providing clear instructions to the model and helping it in digesting and processing these instructions. Data Analysts can leverage their context knowledge and problem-solving skills to frame the right prompts and leverage their technical capabilities for designing prompt safeguards.
For further resources on prompt engineering, check out:
I believe this area will grow even further in the next few years, and I’m excited to see and take part in the evolution.
[ad_2]
Source link