We all know that the way a request is made can drastically change the result. This is even more true now that large language models based on artificial intelligence, such as ChatGPT and Bard, are widely used worldwide to generate all kinds of content. Just like in real life, the accuracy of the output produced by generative AI creators is closely linked to the clarity of the prompt: vague or poorly phrased requests are very likely to generate irrelevant or hallucinated outputs.
What is prompt engineering?
Prompt engineering is a technique used to enhance the performance of language models. It is based on the idea that the more specific a prompt is, the greater the likelihood of obtaining the desired output, from text generation to language translation and creative writing. A prompt is a short string of text that must be clear and concise, providing the language model with the information it needs to generate an accurate and relevant output.
For example, to get an artificial intelligence to generate a creative text, it is necessary to provide a high-quality, stimulating, and specific prompt, just as you would when asking it to write a story or an article on a particular topic. However, it is not always necessary to supply the language model with lots of details; the key is the quality of the prompt, achieved by selecting the most appropriate words, phrases, sentence structures, and punctuation. In effect, prompt engineering can be described as the art of guiding artificial intelligence to become ever more efficient and capable in processing Natural Language Processing (NLP), enabling an algorithm to interpret human language and produce useful results.
Without delving too deeply into technical details, it is worth noting that the term prompt engineering is also used in a broader sense to describe the field of research focused on creating and using specific functions (called prompts) to be applied to the input during the operation of an LLM (Large Language Model) [2], in order to train it to solve a particular NLP (Natural Language Processing) problem. From this perspective, the specific focus of this article, the textual form of the input provided by the user, therefore represents a particular case within the wider discipline.
Why was prompt engineering created?
The need to communicate with artificial intelligence and to obtain appropriate responses to queries arose with the general public’s access to generative AI language systems. In particular, ChatGPT enabled everyone to experiment with an innovative way of conversing with AI. However, the widespread adoption of these AI systems also highlighted issues related to how questions are posed, the control of responses, the AI’s understanding of human linguistic context, and how to use specific inputs to train the algorithm to deliver the desired outputs. Since generative NLP models produce words based on what is considered most likely in a given context, they ensure plausibility but not necessarily strict adherence to the data used during training; when only the former is present and not the latter, the phenomenon known as “hallucinations” occurs.
Precisely to limit the phenomenon of hallucination and to enable the model to achieve its maximum potential, the role of the user becomes fundamental through the process of interaction with the machine [3]. This interaction should be guided by two key principles:
- the formulation of unambiguous instructions [4], using delimiters where necessary to clarify the input, specifying—when required—the desired structure or format of the output (such as JSON, XML, etc.), and, finally, providing sample responses directly within the prompt (few-shot).
- providing the model with time and support to “think”, by breaking down a complex problem into a sequence of simpler questions [6], that is, defining logical intermediate sub-steps of reasoning which, if solved, lead to the final result (“chain of thought”); and, if necessary, instructing the model to check its own response through additional verification steps.
The need to improve and guide AI learning has thus led to the emergence of prompt engineering and the role of prompt engineer or prompt manager, a communicator capable of crafting prompts or instructions that guide AI towards producing appropriate responses in any sector, from healthcare to retail, from education to security.
Why do companies that want to use AI need prompt engineering?
The aim of prompt engineering is to validate the output of the language model and to establish a context enriched with additional information, such as keywords, guidelines, and rules, designed both to obtain specific results from artificial intelligence and to train language models with sector-specific inputs for different commercial, business, and professional fields.
Every sector uses technical and specialised language to produce content, from communications and social media to marketing, which requires ongoing creativity as well as adherence to the company’s tone of voice. Generative artificial intelligence systems, when properly trained using prompt engineering techniques, are able to generate a vast number of contents and variations at the click of a button.
However, it will be necessary to design a stable prompt in order to obtain text, video, or image content that can consistently follow and replicate the linguistic style and tone of voice as set out in each company’s approved guidelines.
Examples of application
By following basic criteria such as ensuring clarity of the request and breaking a topic down into more manageable sub-problems, the goal of prompt engineering is to define the key characteristics that an input text (the prompt) should possess in order to improve the machine’s performance with respect to important capabilities of its operation.
For example: adopting a particular point of view when analysing a topic; the ability to generate questions for the user to better frame an issue; identifying multiple alternative approaches to achieve a result; explaining the elements that led to a certain conclusion; and the ability to provide responses in a specific format.
As this is a highly topical and interesting field, research into prompt engineering is thriving, and several prompt templates for these purposes have already been outlined in the literature.
For example, regarding the perspective the language model should adopt when evaluating an issue, it is recommended to explicitly tell the machine which human role, professional category, or even inanimate entity to embody, and to request that it provide the response in the same manner as would be expected in reality from that perspective. Prompts of this type include the following [1]:
“From now on, act as a security reviewer. Pay close attention to the security details of any code that we look at. Provide outputs that a security reviewer would regarding the code” and “You are going to pretend to be a Linux terminal for a computer that has been compromised by an attacker. When I type in a command, you are going to output the corresponding text that the Linux terminal would produce”.
On the other hand, for the automatic generation of follow-up questions, users are advised to instruct the LLM to generate alternative queries that are considered better than the original at laying the groundwork for solving a problem—for example, as in the following prompt [1]: “From now on, whenever I ask a question about a software artifact’s security, suggest a better version of the question to use that incorporates information specific to security risks in the language or framework that I am using and ask me if I would like to use your question instead”. To offer this kind of training to language models used in companies with specific requirements, trained prompt engineering experts become essential. This is a profession that is, and will increasingly be, in demand across all types of businesses.
References
[1] J. White, Q. Fu, S. Hays, M. Sandborn, C. Olea, H. Gilbert, A. Elnashar, J. Spencer-Smith, D.C. Schmidt, A prompt pattern catalog to enhance prompt engineering with ChatGPT. arXiv:2302.11382, 2023.
[2] P. Liu, W. Yuan, J. Fu, Z. Jiang, H. Hayashi, G. Neubig, Pre-train, prompt, and predict: A systematic survey of prompting methods in natural language processing. ACM Computing Surveys, 55(9), 1-35, 2023.
[3] L. Henrickson, A. Meroño-Peñuela. Prompting meaning: a hermeneutic approach to optimising prompt engineering with ChatGPT. AI & Soc. 2023.
[4] A. Bozkurt, R.C. Sharma. Generative AI and Prompt Engineering: The Art of Whispering to Let the Genie Out of the Algorithmic World. Asian Journal of Distance Education, 18(2), 2023.
[5] J. Kocoń, I. Cichecki, O. Kaszyca, M. Kochanek, D. Szydło, J. Baran, J. Bielaniewicz, M. Gruza, A. Janz et al. ChatGPT: Jack of all trades, master of none. Information Fusion, 99, 2023.
[6] T.F. Heston, C. Khun. Prompt Engineering in Medical Education. Int. Med. Educ., 2, 198–205, 2023.
[7] J. Hutson, B. Robertson. Exploring the Educational Potential of AI Generative Art in 3D Design Fundamentals: A Case Study on Prompt Engineering and Creative Workflows. Global Journal of Human-Social Science: A Arts & Humanities – Psychology, 23(2), 2023.
[8] R. Peres, M. Schreier, D. Schweidel, A. Sorescu. On ChatGPT and beyond: How generative artificial intelligence may affect research, teaching, and practice. International Journal of Research in Marketing, 40, 269–275, 2023.
[9] M. Wong, Y.-S. Ong, A. Gupta, K.K. Bali,C. Chen. Prompt Evolution for Generative AI: A Classifier-Guided Approach. In 2023 IEEE Conference on Artificial Intelligence (CAI), 226-229, 2023.
[10] S. Arvidsson, J. Axell. Prompt engineering guidelines for LLMs in Requirements Engineering. Thesis, University of Gothenburg Chalmers University of Technology, June 2023.
[11] J. Qadir. Engineering Education in the Era of ChatGPT: Promise and Pitfalls of Generative AI for Education. In 2023 IEEE Global Engineering Education Conference (EDUCON), 1-9, 2023.
[12] F. Fui-Hoon Nah, R. Zheng, J. Cai, K. Siau, L. Chen. Generative AI and ChatGPT: Applications, challenges, and AI-human collaboration. Journal of Information Technology Case and Application Research, 25(3), 277-304, 2023.