{"id":35889,"date":"2023-08-28T15:14:53","date_gmt":"2023-08-28T22:14:53","guid":{"rendered":"https:\/\/coderpad.io\/?p=35889"},"modified":"2023-08-28T15:20:33","modified_gmt":"2023-08-28T22:20:33","slug":"what-is-prompt-engineering","status":"publish","type":"post","link":"https:\/\/coderpad.io\/blog\/development\/what-is-prompt-engineering\/","title":{"rendered":"What is Prompt Engineering?"},"content":{"rendered":"\n<p>The introduction of AI tools such as ChatGPT and Bard helps increase the efficiency of tasks such as data generation, code generation and completion, text summarization, etc. How were these AI tools trained to answer better almost every question you ask them? The answer is prompt engineering.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">What is prompt engineering?<\/h2>\n\n\n\n<p>Prompt engineering is a technique used to train large language models (LLMs) by supplying these models with specific prompts to improve the accuracy of responses returned. This engineering technique relies heavily on deliberate actions such as providing detailed instructions, context, and input data to the language model.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Prompting techniques<\/h2>\n\n\n\n<p>Several prompting techniques exist, such as the zero-shot, few-shot, chain-of-thought, etc. Each of these techniques has unique features that set them apart.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Zero-shot technique<\/h3>\n\n\n\n<p>The zero-shot technique responds to prompts containing no context by relying on knowledge acquired during the training of related tasks. For example, the prompt below is supplied to ChatGPT:<\/p>\n\n\n\n<p>\u2014<\/p>\n\n\n\n<p>Classify the language into compiled or interpreted<\/p>\n\n\n\n<p>Language: Python<\/p>\n\n\n\n<p><strong>Interpreted<\/strong><\/p>\n\n\n\n<p>\u2014<\/p>\n\n\n\n<p>In the prompt above, no further context on what languages are or what compiled or interpreted means in this scenario, yet the model was able to return the correct answer. LLMs are trained on large datasets, allowing them to analyze and match prompts.<\/p>\n\n\n\n<p>However, this is only sometimes the case for every prompt, as responses from prompts powered by the zero-shot technique may need more detail. In such cases, the few-shot technique should be applied.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Few-shot technique<\/h3>\n\n\n\n<p>In this technique, the prompt engineer supplies a prompt with more context to aid the model in returning a proper response. An example of the few-shot technique is providing the model with a sample summarized paragraph before providing an essay to summarize. For example, we provided the summary for this blog post <a href=\"https:\/\/coderpad.io\/blog\/interviewing\/front-end-design-skills\/\">3 Design Skills You Should Look For In Front-End Candidates<\/a> to ChatGPT and asked it to summarize the article. The summarized article returned is:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-1\" data-shcb-language-name=\"JavaScript\" data-shcb-language-slug=\"javascript\"><span><code class=\"hljs language-javascript shcb-wrap-lines\">The article emphasizes the importance <span class=\"hljs-keyword\">of<\/span> design skills <span class=\"hljs-keyword\">for<\/span> front-end engineers and provides recommendations on how to find engineers who can create visually appealing and user-friendly applications. It highlights three crucial skill sets to prioritize during interviews:\n\n<span class=\"hljs-number\">1.<\/span> Knowledge <span class=\"hljs-keyword\">of<\/span> semantic layout: Understanding and using semantic HTML elements to enhance accessibility and facilitate code maintenance.\n\n<span class=\"hljs-number\">2.<\/span> Attention to detail: Focusing on small design elements that contribute to a friendly and accessible user interface.\n\n<span class=\"hljs-number\">3.<\/span> Proficiency <span class=\"hljs-keyword\">in<\/span> using design libraries: Being adept at utilizing popular design libraries like Bootstrap, Material UI, and Tailwind CSS to avoid reinventing existing features.\n\nThe essay also acknowledges that <span class=\"hljs-keyword\">while<\/span> these skills are essential, candidates without all three can still be considered based on their other strengths, adjacent skills, ability to learn quickly, and interest <span class=\"hljs-keyword\">in<\/span> improving their design skills. Overall, the essay emphasizes the significance <span class=\"hljs-keyword\">of<\/span> design <span class=\"hljs-keyword\">in<\/span> front-end development and encourages a thorough assessment <span class=\"hljs-keyword\">of<\/span> candidates<span class=\"hljs-string\">' design abilities during the hiring process.<\/span><\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-1\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">JavaScript<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">javascript<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<h3 class=\"wp-block-heading\">Chain-of-thought technique<\/h3>\n\n\n\n<p>As the name implies, in this technique, the prompt engineer supplies instructions and provides more context around a prompt, creating a pattern for the model to analyze before responding. The chain-of-thought technique requires the prompt engineer to walk through the query. An example is providing examples of arithmetic operations before asking the model for an answer to an arithmetic operation. An example of this prompting technique is:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-2\" data-shcb-language-name=\"JavaScript\" data-shcb-language-slug=\"javascript\"><span><code class=\"hljs language-javascript shcb-wrap-lines\">Provide me some detailed questions containing equal parts <span class=\"hljs-keyword\">of<\/span> fix the code and theoretical questions and answers <span class=\"hljs-keyword\">for<\/span> a junior Golang developer. These questions should cover the basics <span class=\"hljs-keyword\">of<\/span> Golang.\u00a0\n\nUse the format below:\u00a0\n\nQuestion:\u00a0\n\nAnswer:\n\nHere\u2019s an example:\nQuestion: What is the difference between a slice and an array?\n\nAnswer: Arrays have a fixed size and are less flexible, <span class=\"hljs-keyword\">while<\/span> slices provide dynamic sizing and are more versatile <span class=\"hljs-keyword\">for<\/span> working <span class=\"hljs-keyword\">with<\/span> collections <span class=\"hljs-keyword\">of<\/span> elements.<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-2\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">JavaScript<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">javascript<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p>There are <a href=\"https:\/\/www.promptingguide.ai\/techniques\" target=\"_blank\" rel=\"noopener\">other techniques<\/a> a prompt engineer employs for accurate or near-accurate answers from AI models.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Applications of prompt engineering<\/h2>\n\n\n\n<p>Prompt engineering finds its application in areas such as generating data and generating code and <a href=\"https:\/\/coderpad.io\/blog\/interviewing\/prompt-engineering-for-technical-interview-questions\/\">technical interviews<\/a>.<\/p>\n\n\n\n<p>The most popular use case for prompt engineering is generating data such as essays, answers to questions, etc. This application of prompt engineering plays a crucial role in the AI industry as language models can be trained to generate texts based on the inputs given. For example, GPT can write the Zen of Python:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-3\" data-shcb-language-name=\"PHP\" data-shcb-language-slug=\"php\"><span><code class=\"hljs language-php shcb-wrap-lines\">The Zen of Python is a collection of guiding principles <span class=\"hljs-keyword\">and<\/span> aphorisms that serve <span class=\"hljs-keyword\">as<\/span> a philosophy <span class=\"hljs-keyword\">for<\/span> writing computer programs in the Python language. It encapsulates the core values <span class=\"hljs-keyword\">and<\/span> best practices that Python developers strive to adhere to. Here is the Zen of Python:\n\nBeautiful is better than ugly.\n\nExplicit is better than implicit.\n\nSimple is better than complex.\n\nComplex is better than complicated.\n\nFlat is better than nested.\n\nSparse is better than dense.\n\nReadability counts.\n\nSpecial cases aren<span class=\"hljs-string\">'t special enough to break the rules.\n\nAlthough practicality beats purity.\n\nErrors should never pass silently.\n\nUnless explicitly silenced.\n\nIn the face of ambiguity, refuse the temptation to guess.\n\nThere should be one\u2014and preferably only one\u2014obvious way to do it.\n\nAlthough that way may not be obvious at first unless you'<\/span>re Dutch.\n\nNow is better than never.\n\nAlthough never is often better than *right* now.\n\n<span class=\"hljs-keyword\">If<\/span> the implementation is hard to explain, it<span class=\"hljs-string\">'s a bad idea.\n\nIf the implementation is easy to explain, it may be a good idea.\n\nNamespaces are one honking great idea\u2014let'<\/span>s <span class=\"hljs-keyword\">do<\/span> more of those!\n\nThese guiding principles encourage Python developers to prioritize code readability, simplicity, <span class=\"hljs-keyword\">and<\/span> maintainability. The Zen of Python emphasizes the importance of clear <span class=\"hljs-keyword\">and<\/span> explicit code over clever <span class=\"hljs-keyword\">or<\/span> convoluted solutions. It promotes the idea that code should be easy to understand <span class=\"hljs-keyword\">and<\/span> follow, even at the expense of brevity. By adhering to these principles, Python developers can write code that is more efficient, easier to debug, <span class=\"hljs-keyword\">and<\/span> more enjoyable to work with.<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-3\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">PHP<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">php<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p>ChatGPT&#8217;s response to my input adds an extra paragraph to tell us what the Zen of Python is about.&nbsp;<\/p>\n\n\n\n<p>Code generation is a close second as developers utilize the availability of LLMs to provide working code samples based on the context provided. Prompt engineering is crucial to achieving this task, as the language models require adequate context and instructions to return proper responses. For example, we can ask ChatGPT to generate a function that says my name:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-4\" data-shcb-language-name=\"Go\" data-shcb-language-slug=\"go\"><span><code class=\"hljs language-go shcb-wrap-lines\"><span class=\"hljs-keyword\">package<\/span> main\n\n<span class=\"hljs-keyword\">import<\/span> <span class=\"hljs-string\">\"fmt\"<\/span>\n\n<span class=\"hljs-function\"><span class=\"hljs-keyword\">func<\/span> <span class=\"hljs-title\">sayMyName<\/span><span class=\"hljs-params\">(name <span class=\"hljs-keyword\">string<\/span>)<\/span><\/span> {\n\n\u00a0\u00a0\u00a0\u00a0fmt.Println(<span class=\"hljs-string\">\"Hello, my name is\"<\/span>, name)\n\n}\n\n<span class=\"hljs-function\"><span class=\"hljs-keyword\">func<\/span> <span class=\"hljs-title\">main<\/span><span class=\"hljs-params\">()<\/span><\/span> {\n\n\u00a0\u00a0\u00a0\u00a0myName := <span class=\"hljs-string\">\"Coderpad\"<\/span>\n\n\u00a0\u00a0\u00a0\u00a0sayMyName(myName) <span class=\"hljs-comment\">\/\/ Prints out Hello, my name is Coderpad<\/span>\n\n}<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-4\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">Go<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">go<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<h2 class=\"wp-block-heading\">Shortfalls<\/h2>\n\n\n\n<p>The significant shortfall of prompt engineering is the inaccuracy of some responses from language models. We must remember that these models are trained based on datasets and inputs supplied to them. As a result, we must review the responses from AI tools like ChatGPT and Bard.<\/p>\n\n\n\n<p>Other shortfalls of prompt engineering are the time taken to refine a prompt to return accurate results and the limited knowledge base of the language model. For example, ChatGPT models are trained up to 2021, thereby being unable to provide accurate results on questions involving events from the year 2021 upwards. Luckily, the language models quickly learn how to return results from previous training via prompt engineering techniques. For example, the clause \u201cUsing previous criteria\u201d on new prompts instructs the language model to return results based on the criteria defined in earlier prompts.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Conclusion<\/h2>\n\n\n\n<p>Prompt engineering plays a crucial role in improving the quality of responses from AI models such as ChatGPT and Bard. Prompt engineers can train language models to generate precise and relevant responses by providing more context to prompts. This can be achieved via the various techniques mentioned in this article.<\/p>\n\n\n\n<p>The applications of prompt engineering are diverse, with data generation and code generation being prominent examples. Prompt engineering enables the generation of essays, answers to questions, and other text-based content, providing valuable assistance in various domains. Moreover, developers can utilize prompt engineering to generate functional code snippets based on specific requirements and context.<\/p>\n\n\n\n<p>However, it is important to acknowledge the limitations of prompt engineering. Language models are not infallible and may occasionally provide inaccurate responses. Therefore, it is crucial to review and validate the outputs generated by AI tools to ensure their reliability.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Introducing AI tools such as ChatGPT and Bard helps increase the efficiency of tasks such as data generation, code generation and completion, text summarization, etc. How were these AI tools trained to answer almost every question you ask them? The answer, prompt engineering, is discussed in this blog post.<\/p>\n","protected":false},"author":1,"featured_media":36172,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[9],"tags":[],"persona":[29],"blog-programming-language":[],"keyword-cluster":[],"class_list":["post-35889","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-development"],"acf":[],"_links":{"self":[{"href":"https:\/\/coderpad.io\/wp-json\/wp\/v2\/posts\/35889","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/coderpad.io\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/coderpad.io\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/coderpad.io\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/coderpad.io\/wp-json\/wp\/v2\/comments?post=35889"}],"version-history":[{"count":9,"href":"https:\/\/coderpad.io\/wp-json\/wp\/v2\/posts\/35889\/revisions"}],"predecessor-version":[{"id":42760,"href":"https:\/\/coderpad.io\/wp-json\/wp\/v2\/posts\/35889\/revisions\/42760"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/coderpad.io\/wp-json\/wp\/v2\/media\/36172"}],"wp:attachment":[{"href":"https:\/\/coderpad.io\/wp-json\/wp\/v2\/media?parent=35889"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/coderpad.io\/wp-json\/wp\/v2\/categories?post=35889"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/coderpad.io\/wp-json\/wp\/v2\/tags?post=35889"},{"taxonomy":"persona","embeddable":true,"href":"https:\/\/coderpad.io\/wp-json\/wp\/v2\/persona?post=35889"},{"taxonomy":"blog-programming-language","embeddable":true,"href":"https:\/\/coderpad.io\/wp-json\/wp\/v2\/blog-programming-language?post=35889"},{"taxonomy":"keyword-cluster","embeddable":true,"href":"https:\/\/coderpad.io\/wp-json\/wp\/v2\/keyword-cluster?post=35889"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}