0% found this document useful (0 votes)
81 views

Understanding Prompt Engineering Fundamentals

Uploaded by

Noyula
Copyright
© © All Rights Reserved
Available Formats
Download as PDF or read online on Scribd
0% found this document useful (0 votes)
81 views

Understanding Prompt Engineering Fundamentals

Uploaded by

Noyula
Copyright
© © All Rights Reserved
Available Formats
Download as PDF or read online on Scribd
You are on page 1/ 38
i Tel eg Under- standing ; Prompt Engineering ‘ Fundamentals GENERATIVE Al FOR BEGINNERS HE Microsoft Prompt Engineering Fundamentals ca Z Build your intuition for crafting better prompts by iteration & validation. Think art— not science. =) HE Microsoft What will we be covering in this lesson? J2BB@O Define prompt engineering — what is it and why is it important? Know prompt construction — how are they structured and used? Learn prompting best practices - improve quality with iteration. Apply learned techniques to real examples — in our code challenge Let’s Review — Terminology We've Seen So Far Wists What are Wat re Generative Al Large Language Models Prompts A type of Al that An Al model trained on Text input to LLM that generates new content, massive datasets and “instructs” it what to do using LLMs, in response specialized to work on ~ sets model weights and to a user “prompt” natural language tasks influences response Completion: instruct” tenins ae = Open ae = |=) AREA : e A “predicts” what it to do in natural language (cae thinks | need in response (text chat) (tert, code) ‘Optimized for Chat: 4097 Tokens | Tained to Sep 2021 Let’s Review — Our Target Application & Audience We're an Education Startup building Al apps for Personalized Learning some Administrator € I need an assistant that can help me analyze all the curriculum data ~ and identify ‘gaps in coverage so I can plan better for next year. Educator $ | need an assistant can help me generate a lesson plan for a specific topic and target audience - and | need this to be presentation-friendly by default. ‘Student | need a tutor that can coach me on this subject in a way that matches my skill evel & learning style —| like examples, and | want hints when | get stuck HE Microsoft Lesson Units /2BBO@0 Introduction Prompt Engineering Definition Prompt Engineering Motivation Prompt Engineering Concepts Prompt Engineering Practices Summary HE Microsoft ‘Youcan use the tol belowto understand haw apiece of tert might be toherzed bya language ‘rod naetacooftclanintst cso "snp nots thath natant process varie bats models Newer models Tie GPrasandGPt-t uae saterntcknenancrigsey P73 and medels nd valour torte same nt (errasnerta) crrsuenop How does a Prompt work? TE have « groan hat ny four Lite ehtléren will one day 2ive sn 8 nation te by te cle of he on Ot by he LLM sees prompt as sequence of tokens ... HE Microsoft How does a Prompt work? Base LLMs will simply predict the next token ‘The user did not specify any instructions. AA treats this as request for information and predicts response from trained data. somnee HE Microsoft ‘ryt yours hitos//os aura comyportal/hat How does a Prompt work? Instruction-tuned LLM extends base behavior for task ‘Add context with a “system” message that tunes the default LLM behavior. somnee HE Microsoft ‘Try It yourself: hits //oni azure comoortal/chat How does a Prompt work? Instruction-tuned LLM extends base behavior for task Then try the same content snippet ‘again as your user input. Do you see the difference? HE Microsoft Definition What is Prompt Engineering? J2Beeo A prompt is the text input given to the Generative Al model. Prompt engineering is the process of designing and optimizing the prompt till the response meets the user's expectations for relevance or quality HE Microsoft “hy Ryoursets toe//osi anu com/oontal/hat + LLMs are stochastic in nature Motivation since prompts “program” the model, the responses are even What is Prompt more sensitive to construction of prompt. Engineering | - LLMs can hallucinate responses Necessary? since pre-trained data has a cutoff date, they may predict, completions that are not grounded in fact. + LLMs have diverse capabilities every model has unique features and quirks that can be tuned for better quality responses & Hi Microsoft Model Are Stochastic Same prompt Same model Varying response HE Microsoft Models Can Hallucinate Prompts give responses that appear valid but may not be true ‘Try It yourself model-tent 3 [Ete me metan wrote atesonintson rae Lovet gh Shao 2-2) Sito tory Deaton 2s paride 60 mite ach) once HE Microsoft Model Capabilities Matter Same prompt Newer model Better response ‘Generate fesson plan onthe Martin War of 2076 “The Martan Warf 2076 aso my ast update in January 2022, tional even anda rot actualy occurred in history However, |can help you crate a lesson pan based on this ‘ietlonal concept Hera supgestedautine: Lesson Plan The Maran War of 2078. ‘Objective:By the nd ofthis esson students willbe abe to understandthe causes major ‘events and consequences ofthe fictional Matan War of 2076. Duration 50 minutes HE Microsoft Read the Article: Case Study Real-World Usage in GitHub Copilot “For example, when asking GitHub Copilot to draw an ice cream cone ¥ using p5.js,a JavaScript library for creative coding, we kept receiving irrelevant suggestions—or sometimes no suggestions at all” J2Beeo HE Microsoft ead he Article: ns//athu oa/202 pia beter cre forcast Case Study Real-World Usage in GitHub Copilot “For example, when asking GitHub Copilot to draw an ice cream cone ¥ using p5.js,a JavaScript library for creative coding, we kept receiving irrelevant suggestions—or sometimes no suggestions at all” J2BBeo HE Microsoft caseStnly How is Prompt Engineering Used In Real Apps? “"When we adjusted our prompt, we were able to generate more accurate results” “3 best practices for prompt crafting - set the stage with high-level goal, be simple & specific, give examples” nae HE Microsoft Lesson Units J2BBeo Introduction Prompt Engineering Definition Prompt Engineering Motivation Prompt Engineering Concepts Prompt Engineering Practices Summary HE Microsoft ‘Simple: Content Type in text See completion J2Beeo ‘Try it yourself ps //o1 anu com /oortafchat In the simplest form, you provide a text input (prompt) and the model predicts the next tokens (completion) This is the fundamental behavior any LLM. Remember it. & HE Microsoft ‘Try It yoursatf: https //platform,opensi com/examples/default-mary-sarcastc-chat Complex: Content = == Multi-turn nee | ia conversation a with context Prompt text as ‘messages’ that carry system | ssnpammesee context (priming) and user/assistant exchanges (history) as sliding token window J2Beeo HE Microsoft ‘Tryit yourself: hnips//ol azure com/oorta/chat Write a description of the civil war. Simple: Instruction Text input specifies task, not content HE Microsoft ‘Tey It yourself: https://oai azure.com/portal/chat Write a description of the civil war. Provide key dates and events and describe their significance. ‘Complex: Instruction Text input - a nninntnnietrne | specifies task, adds details HE Microsoft ‘Complex, Formatted: Instruction Text input specifies task, adds details, defines format ‘Tey It yourself: https://oai azure.com/portal/chat Write a description of the Civil War in 1 paragraph. Provide 3 bullet points with key dates and their significance. Provide 3 more bullet points with key historical figures and their contributions. Return the output as a JSON file HE Microsoft Constroct rr + Prrery Coen Specify task and provide content as context for it ‘Tey It yourself: https://oai azure.com/portal/chat Jupiter is the fifth planet from the Sun and the largest in the Solar System. It is a gas giant with a mass one-thousandth that of the Sun, but two-and-a-ha.... ‘Summarize this in 2 short sentences ° HE Microsoft Primary Content: Provide Examples Examples as in- context learning Model learns from tiny training data, infers response patterns ‘Try it yourself: ity Zero-shot prompting User provides 1 instruction (explicit) + 0 examples @ Sol et band rtaichat HE Microsoft Primary Content: Provide Examples Examples as in- context learning Model learns from tiny training data, infers response patterns ‘Try it yourself ity pLazure.com/portal/chat, One-shot prompting User provides 0 instructions + 1 example (implicit) eo “un cia oy ventosor “The Suns Shining” = “Hea Cold and Windy Day sh briland’ HE Microsoft ‘Try it yourself: ttps,//oai azure,com/portal/chat Few-shot prompting User provides 0 instructions + few examples (improve inference) Primary Content: Provide Examples Examples as in- nesmemaersacs twee @ context learning Lhoniat papier The player made aslam-dunk => Model learns from tiny e training data, infers Basketball response patterns HE Microsoft Primary Content: Provide Cues Cues ‘prime’ the response Model ‘takes the cue’ to favor completions that match pattern ‘ivtzatione since before recorded histo Summarie The 9 HE Microsoft Primary Content: Provide Cues Cues ‘prime’ the response Model ‘takes the cue’ to favor completions that match pattern ‘Try it yourself: hips //ol azure com/oorta/chat 1eue the right ty and hasbeen HE Microsoft Primary Content: Provide Cues Cues ‘prime’ the response Model ‘takes the cue’ to favor completions that match pattern rom the Sun a the largestin he System, cote panes the Sola System combines 5 lta is one ofthe bight object blot nag een he ight sy ad as een known 0 nice etre coded ty HE Microsoft Primary Content: Use Templates Pre-Defined “Recipes” for Repeatability Iterate & validate prompt design make it reusable ‘ryt youre: ips //si ane com/oortalchat ‘System message templates can set “personality” consistently HE Microsoft Read About I: Prompt Eginsering and LM wth Langs User message templates with placeholders for dynamic input binding Primary Content: Use Templt erry Comer Use ee Prompt Templates Pre-Defined os ' ——— ce wel yrs “Recipes” for Repeatability Create prompt template ‘libraries’ in code for API-driven usage HE Microsoft Lesson Units J2meeo Introduction Prompt Engineering Definition Prompt Engineering Motivation Prompt Engineering Concepts Prompt Engineering Practices Summary HE Microsoft Prompt Engineering is a trial-and-error process that also relies on your intuition. . Prompt . Build domain understanding — use your domain Engi neering expertise to customize prompt for relevance. Mindset | 2 Build model understanding - adapt prompt to suit Indse’ model strengths & weaknesses to improve quality. 3. Iterate & Validate — define acceptance or termination criteria so you iterate to meet expectations but don’t over-engineer the prompt to reduce reusability J2Beeo HE Microsoft Prompt Engineering Best Practices J2meeo ONDUNAWHD = . Use the latest models . Separate instructions & context . Be specific & clear . Be descriptive & use examples . Use cues - think ‘priming’ responses . Double down - think reinforcement . Order matters — think recency bias . Give the model an out - think fallback Code Challenge — Build Intuition With Trial & Error Pe iviecrad Prompts help you “program” Gen Al What is prompt engineering? Why should we care? aloe Lelia ele Meola iat la cord vier (alana Learned How can we optimize prompts? Today Art, not science ** Code Challenges @QZ/AmRMO®

You might also like