Introduction
Large language models (LLMs), such as ChatGPT, equipped with advanced natural language processing capabilities, offer a unique avenue for enhancing clinical practices. Prompt engineering is crucial for optimizing the performance of LLMs. Prompt engineering refers to the practice of meticulously designing natural language queries that steer the model to produce the desired output.[1]
Prompt engineering i s fundamentally about communication, how to converse with an AI in its language. It may be likened to computer programming wherein the difference is that the "code" is natural language, and the output is not just any text but one that fulfills a specific task or answers a particular question. One key difference to programming, however, is the responsiveness of LLMs to input prompts; slight variations in how a prompt is structured can lead to significantly different outcomes. This sensitivity, often referred to as "prompt brittleness," highlights the importance of syntax and semantics of the prompts given to LLMs.[1] Just as the results from a search engine can vary significantly with minor adjustments in search terms, despite the terms conveying essentially the same meaning, so too can the outputs of LLMs vary based on the subtle intricacies of the input prompt (Fig. 1).
Prompt brittleness turns prompt engineering into both a science, with its principles and patterns, and an art, requiring intuition and creativity to master; akin to the practice of medicine. Exploring prompt engineering shows it is often more about art than science, with success heavily depending on experience and intuition.
The goal of this section is to introduce the concept of prompt engineering and make it accessible and practical for radiologists. Although the following material introduces components of effective prompts and best practices, it is critical to remember that prompt engineering is a skill that improves with trial-and-error. Getting hands-on experience with prompt engineering for a task is crucial to become proficient. As an important sidenote, because the following principles are learned from experience with the GPT family by OpenAI, they may not apply equally to other LLMs.
Best Practices for Prompt Engineering [2-4]
1) Be specific with clear instructions: Ensure your instructions are straightforward and leave little room for interpretation. Be explicit about what you want. If you seek concise answers, specify the desired length (e.g. three sentences, one paragraph, or 200 words, etc.) or ask for brief replies. Similarly, if you're looking for expert-level writing, state that explicitly. This helps minimize the guesswork for the model (Fig. 2).
2) Persona and Perspective: Encourage the model to adopt a specific persona or tone if that suits your task (e.g. “You are an experienced radiologist in abdominal imaging.”). This could range from a scholarly tone for academic inquiries to a more casual one for everyday questions. Likewise, the level and role of the listener can be specified (e.g. “Simplify this for explanation to a patient.”) (Fig. 3).
3) Use of Delimiters and Syntax: Clearly mark different sections or types of information within your prompt using delimiters or clear textual separation. This helps the model distinguish between instructions, reference content, and the questions themselves. Even simple ones, such as two consecutive hyphens (“--"), are effective. This might be because a large portion of LLMs training data are structured text such as HTML and JSON (Fig. 4) [5].
4) Break down complex tasks into subtasks: For complex tasks, break them down into simpler, manageable sub-tasks. Provide instructions step by step or ask the model to follow a sequence of operations. This method reduces errors and enhances the quality of the output (Fig. 5) [5].
5) Repetition and Order: Don’t hesitate to repeat critical instructions or use both instructions and cues to emphasize what you need. The placement of your instructions (before or after your main content) can also significantly affect the model's responses. Therefore, experiment with various orders to achieve the best results (Fig. 4).
6) Provide Options to avoid hallucinations: Giving the model an "out," such as the option to reply "I don't know" or "not found," can prevent it from making up answers (hallucination) or straying too far from factual accuracy (Fig. 4).
7) Reference Material: Supplying reference text or asking the model to use specific sources can steer responses away from fabrications, especially on esoteric topics. This approach grounds the model’s answers in provided or known content and reduces hallucination (Fig. 4).
8) Use of External Tools: Augment the model's capabilities by incorporating outputs from other tools for tasks that require specific knowledge, precise calculations, or data retrieval [6, 7]. This can include using code execution for mathematical operations or application programming interface (API) calls (Fig. 6).
9) Allow for ‘Thinking’ Time: Encourage the model to present a "chain of thought" or reasoning process before delivering its final answer [8]. This can improve the accuracy and depth of responses, especially for complex queries (Fig. 7).
10) Evaluation and Testing: Systematically test changes to your prompts to ensure they consistently improve performance. Evaluate against a set of criteria or a "gold-standard" to verify the effectiveness of your modifications. To accomplish this, it is necessary to separately prepare a validation set for fair comparison of various prompts.
Advanced Prompting Techniques
There are more complex and nuanced prompting techniques, but most of them require multi-turn prompting, usage of programming, or are applicable to very specific scenarios. Most of these are beyond the scope of this review, so in this section, we will introduce two important and easily implementable prompting techniques: incontext learning (ICL) and self consistency.
1) In-Context Learning (also known as few-shot or zero-shot learning)
ICL refers to an LLM’s capability to learn from the prompt without changing the model weights. ICL capitalizes on the ability of LLMs to understand and learn from the concatenation of training data examples provided through the prompt.[1] This enables the user to use the LLM in various natural language processing tasks without the need to train a specialized model. In fact, it is so effective that in some scenarios GPT-4 with 10-shots (examples) shows similar accuracy to a 7900 example-trained BERT model.[9] (Fig. 8)
## Mechanics of ICL
ICL operates through two main mechanisms: task recognition and task learning. Task recognition involves the model's capability to identify and understand the nature of the task from the provided demonstrations, even if these include incorrect labels. Once the task is recognized, the model then applies its pre-existing knowledge to address the task. Task learning, on the other hand, refers to the model's ability to learn new input-label mappings that were not part of its pre-training, effectively adapting to new information and tasks.
## Leveraging ICL
The number of examples given is, in general, positively correlated to the model performance.[10] So, giving the model as many examples as possible is a good way to maximize performance. In practice, since the context is limited and creating the examples are also a burden, we experiment with what we have or create a few, then expand if we need better accuracy. Also, one interesting aspect in task learning is that the order of the examples affect the performance.[11] Consequently, experimenting with different permutations can optimize task learning outcomes.
2) Self-consistency
Self-consistency works by choosing the most consistent answer after multiple generations. Self-consistency is achieved by taking the majority vote as the final answer, after having the model generate multiple chains-of-thought and answers to the same question while introducing a slight randomness in the generation.[12] By default, GPT-3.5 and GPT-4 has a randomness to its response which cannot be completely removed. In other words, even the same prompt may, and probably will, output different generations each time. When the model tries to solve a problem, this randomness might make it take a slightly different path to reach an answer, even though the starting conditions remain the same.
By generating a number of these slightly varied solutions, a spectrum of answers can be obtained. Despite the differences, correct answers tend to cluster around the truth because logical paths, even when varied, often lead to the same conclusion. The self-consistency method leverages this tendency by identifying the most common answer among these attempts, treating it as the most probable or "consistent" solution. This has been experimentally proven to be superior to greedy sampling in LLMs in which the randomness can be turned off.[12] In practice, this means that if resources allow, taking the majority vote after multiple runs will produce better results. (Fig. 9)
Potential applications for abdominal radiology
LLMs can aid or simplify routine tasks like text generation, summarization, and feature extraction, enhancing efficiency and content quality without compromising the written context. In clinical settings, for instance, they can swiftly simplify formal conclusions by evaluating radiological reports [13]. Gu et al. reported that GPT-4 can be used to extract LI-RADS features from existing radiology reports. In particular, the authors iteratively applied various prompt engineering strategies to build the best prompt on a training set, and externally validated it on a separate dataset [5]. In this way, researchers can harness the full potential of LLMs to produce desired outcomes, assisting in the advancement of LLMs for clinical use in radiology.
Conclusion
The strategic application of prompt engineering is crucial for radiologists to effectively leverage LLMs, enhancing clinical application, workflow efficiency, and future research. The authors hope this review of prompt engineering will help improve radiologists' comprehension and application of LLMs in clinical practice.


PDF Links
PubReader
ePub Link
Full text via DOI
Download Citation
Print






