Kenipranit
7 min readJun 12, 2023

Prompt engineering is a technique used in natural language processing (NLP) and machine learning to improve the performance and control the behavior of AI language models like GPT-3.5. It involves carefully designing and crafting the prompts or instructions given to the model in order to elicit desired responses.

The main goal of prompt engineering is to guide the model’s output towards specific objectives, improve the quality of generated responses, and control factors such as style, tone, or content. It can be used to address common challenges in language generation, including issues like response coherence, factuality, avoiding biased or inappropriate content, and generating responses that align with specific criteria.

Prompt engineering techniques vary depending on the specific application or task at hand. Here’s a syllabus-like breakdown of the main components of prompt engineering:

  1. Task Definition:
  • Understand the specific task or objective you want the model to accomplish.
  • Clearly define the input and output requirements of the task.
  • Identify any constraints, guidelines, or evaluation metrics to follow.
  1. Prompt Format and Instruction:
  • Design a clear and concise prompt that instructs the model on what is expected.
  • Specify the format and structure of the desired output.
  • Include explicit cues, keywords, or context to guide the model’s understanding.
  1. Context:
  • Determine the amount and type of context required for the task.
  • Specify whether previous conversation history, user instructions, or additional information should be provided as context.
  • Experiment with different context lengths to find the optimal balance between relevance and information overload.
  1. Control Parameters:
  • Utilize system-level and model-level control settings to modify the behavior of the model.
  • Adjust parameters like temperature or top-k/top-p sampling to control the randomness of generated responses.
  • Explore techniques like nucleus sampling or beam search to enforce constraints on response generation.
  1. Fine-tuning:
  • Consider fine-tuning the base language model on specific data or tasks related to the desired objective.
  • Use task-specific datasets or custom datasets to improve the model’s performance on specific prompts or domains.
  • Fine-tuning can help align the model’s behavior with the desired output and improve its performance on specific tasks.
  1. Iterative Refinement:
  • Continuously iterate and experiment with different prompts, instructions, or techniques.
  • Analyze and evaluate the model’s responses and make adjustments accordingly.
  • Collect feedback from users or human evaluators to identify areas for improvement and fine-tune the prompt engineering process.

Prompt engineering is an ongoing process that requires experimentation, evaluation, and fine-tuning to achieve the desired results. By carefully crafting prompts and providing clear instructions, developers and researchers can shape the behavior of AI language models and improve their performance on specific tasks or applications

DEFINATION

Prompt engineering is a concept in artificial intelligence, particularly natural language processing. In prompt engineering, the description of the task that the AI is supposed to accomplish is embedded in the input, e.g. as a question, instead of it being explicitly given. Prompt engineering typically works by converting one or more tasks to a prompt-based dataset and training a language model with what has been called “prompt-based learning” or just “prompt learning

History

The GPT-2 and GPT-3 language models were important steps in prompt engineering. In 2021, multitask[jargon] prompt engineering using multiple NLP datasets showed good performance on new tasks. In a method called chain-of-thought (CoT) prompting, few-shot examples of a task were given to the language model which improved its ability to reason. The broad accessibility of these tools was driven by the publication of several open-source notebooks and community-led projects for image synthesis.

A description for handling prompts reported that over 2,000 public prompts for around 170 datasets were available in February 2022.

Meta’s Segment Anything computer vision model is a prompting-based model for creating masks for objects in images. It can be prompted in several ways, such as selecting a few “positive” and “negative” points, to create a mask that includes all the positive points and excludes all the negative points.

I. INTRODUCTION Conversational large language models (LLMs) [1], such as ChatGPT [2], have generated immense interest in a range of domains for tasks ranging from answering questions on medical licensing exams [3] to generating code snippets. This paper focuses on enhancing the application of LLMs in several domains, such as helping developers code effectively and efficiently with unfamiliar APIs or allowing students to acquire new coding skills and techniques. LLMs are particularly promising in domains where humans and AI tools work together as trustworthy collaborators to more rapidly and reliably evolve software-reliant systems [4]. For example, LLMs are being integrated directly into software tools, such as Github’s Co-Pilot and included in integrated development environments (IDEs), such as IntelliJ and Visual Studio Code, thereby allowing software teams to access these tools directly from their preferred IDE. A prompt is a set of instructions provided to an LLM that programs the LLM by customizing it and/or enhancing or refining its capabilities. A prompt can influence subsequent interactions with — and output generated from — an LLM by providing specific rules and guidelines for an LLM conversation with a set of initial rules. In particular, a prompt sets the context for the conversation and tells the LLM what information is important and what the desired output form and content should be. For example, a prompt could specify that an LLM should only generate code that follows a certain coding style or programming paradigm. Likewise, it could specify that an LLM should flag certain keywords or phrases in a generated document and provide additional information related to those keywords. By introducing these guidelines, prompts facilitate more structured and nuanced outputs to aid a large variety of software engineering tasks in the context of LLMs. Prompt engineering is the means by which LLMs are programmed via prompts. To demonstrate the power of prompt engineering, we provide the following prompt: Prompt: “From now on, I would like you to ask me questions to deploy a Python application to AWS. When you have enough information to deploy the application, create a Python script to automate the deployment.” This example prompt causes ChatGPT to begin asking the user questions about their software application. ChatGPT will drive the question-asking process until it reaches a point where it has sufficient information to generate a Python script that automates deployment. This example demonstrates the programming potential of prompts beyond conventional “generate a method that does X” style prompts or “answer this quiz question”. Moreover, prompts can be engineered to program an LLM to accomplish much more than simply dictating the output type or filtering the information provided to the model. With the right prompt, it is possible to create entirely new interaction paradigms, such as having an LLM generate and give a quiz associated with a software engineering concept or tool, or even simulate a Linux terminal window. Moreover, prompts have the potential for self-adaptation, suggesting other prompts to gather additional information or generate related artifacts. These advanced capabilities of prompts highlight the importance of engineering them to provide value beyond simple text or code generation

Several possible approaches could be used, ranging from diagrams to defining grammars for a prompt language. Although grammars may seem attractive due to their formal nature, they also incur the following challenges: • The goal of prompts is to communicate knowledge in a clear and concise way to conversation LLM users, who may or may not be computer scientists or programmers. As a community, we should strive to create an approachable format that communicates knowledge clearly to a diverse target audience. • It is possible to phrase a prompt in many different ways. It is hard, however, to define a grammar that accurately and completely expresses all the nuanced ways that components of a prompt could be expressed in text or symbols. • Prompts fundamentally convey ideas to a conversational LLM and are not simply the production of tokens for input. In particular, an idea built into a prompt pattern can be communicated in many ways and its expression should be at a higher-level than the underlying tokens representing the idea. • It is possible to program an LLM to introduce novel semantics for statements and words that create new ways for communicating an idea. In contrast, grammars may not easily represent ideas that can be expressed through completely new symbology or languages that the grammar designer was not aware of. D. A Way Forward: Fundamental Contextual Statements An open research question, therefore, is what approach is more effective than formal grammars for describing prompt pattern structure and ideas. We propose the concept of fundamental contextual statements, which are written descriptions of the important ideas to communicate in a prompt to an LLM. An idea can be rewritten and expressed in arbitrary ways based on user needs and experience. The key ideas to communicate, however, are presented to the user as a series of simple, but fundamental, statements. One benefit of adopting and applying the fundamental contextual statements approach is that it is intentionally intuitive to users. In particular, we expect users will understand how to express and adapt the statements in a contextually appropriate way for their domain. Moreover, since the underlying ideas of the prompt are captured, these same ideas can be expressed by the user in alternate symbology or wording that has been introduced to the LLM using patterns, such as the Meta Language Creation pattern presented in Section III-B. Our ultimate goal is to enhance prompt engineering by providing a framework for designing prompts that can be reused and/or adapted to other LLMs in the same way that software patterns can be implemented in different programming languages and platforms. For the purposes of this paper, however, all prompts were tested with ChatGPT [12] using the ChatGPT+ service. We use ChatGPT as the LLM for all examples presented in this paper due to its widespread availability and popularity. These examples were documented through a combination of exploring the corpus of community-posted prompts on the Internet and independent prompt creation from our use of ChatGPT to automating software development tasks.

Kenipranit

Electronics Engineer and Machine Learning Professional