Advancing Prompt Engineering Techniques in LLMs: Chapter 10
Skills:
Prompt Craft90%LLM Foundations80%Advanced Prompting80%Prompting Basics70%Fine-tuning LLMs60%
Key Takeaways
The video demonstrates advanced prompt engineering techniques in LLMs using tools like Jupiter notebook, Open AI API, Weights and Biases, GPT 3.5 turbo model, and GPT 4, focusing on synthetic datasets and zero-shot techniques.
Full Transcript
[Music] in this video we will explore different prompt engineering techniques and experiment with them in code and in order to do this we need a motivating use case remember what we're trying to build in this course is an LL owered application and we specifically work towards some an application like weight and bies onebot the application that allows um weights and biases users to ask different questions and get responses on how to get stuff done with weights and biases and in order to to build this application um one thing that we will need in the future is a set of questions and answers that's something that might be helpful for example when we are evaluating uh different prompt engineering techniques uh of um and and different design choices in our application so in this video we're going to generate a synthetic data set of weights and biases user questions let's dive in again we will use a Jupiter notebook because we want to interactively experiment with the apis uh we need uh to install the libraries if we haven't done this before import them and have our open AI API key configured uh we'll also keep logging uh the results of our experimentation into weights and biases with the outo log function one new thing that we will introduce in this notebook is completion with back off as you've seen uh open AI uh API is very popular uh we can sometimes get this rate limiting error uh which uh we' like to handle more gracefully and for that reason we will add this retri decorator and whenever we uh we hit one of this uh limits the uh function will wait and then we'll try to uh make that uh request Quest again so that should make uh the experience of working U with this notebook a bit easier so let's um run the cell Let's uh start with GPT 3.5 turbo model here but we'll switch ultimately into GPT 4 um and because we're using a chat model we need our prompt to be to be done in two parts the first part is the system prompt and this is the part that should determine the behavior the qualities uh of the LLS uh it it it becomes the Persona that it tries to follow as it tries to answer our question and then the user prompt actually like defines like what we ask of the language model to do in this case we'll keep the system prompt very uh limited and will um will generate a very like we put a very simple prompt which is to generate a support question from a weight Andes user so if you go back to prompt engineering techniques this is a zero shot prompting we're not giving the model any examples we're not giving it any context we're just asking it to do some work generate a support question and we'll fit that uh into the the chat API uh with back off uh because we want to be prepared for the uh the rate limiting errors and uh will generate a bunch of responses we can actually ask the model to generate several responses and doing this through the API is um better than simply repeating this call several times because it reduces the cost of generating this responses and then we'll display them and print them this time using markdown so it's a bit easier to read in a notebook so let's run this and see uh what comes out okay we can see add this one pretty quickly uh we get a bunch of questions how do I track the performance of different models over time on weights and biases how do I connect and monitor my machine learning experiments in weight and bies how do I save my project to a specific directory in weights and biases and so on and we can see um these are pretty good but these are also very generic questions and I'm not sure if they are actually similar to what real users are asking that's something that we can evaluate later on um but uh The Next Step that we can do from uh Beyond Z shot is to give the model several examples and this is the few shot example in this case so how do we do it first uh we collected several uh user questions from our Discord server and we put this into examples uh text file which is uh to The Limited so we can now read these examples and we can display a sample question so this is a real uh question one of two like a little bit above 200 queries what are the risk um of supplying proprietary data into a third party cloud provider such as weight and biases uh interesting question not something that I would expect but it reflects the the distribution uh of of user questions in the real world so I think maybe this will help uh the model to to generate like to create more diverse examples so for the F future prompt uh we will uh add a random choice of real questions into the prompt and we will share that as examples of real user queries and again we'll ask the model to use this and to generate um several examples this is again the printed version of The Prompt that we're fitting into the model now we're giving it real examples from our list and let's run the model and see what uh it comes up with okay we can now see uh the questions that the model generates uh the first one is quite similar to the previous ones uh then it asks how do I visualize the distribution of a specific column in my weights and bues table using histograms and density plots I think this one is a bit more specific might have been inspired by one of the fure examples and there's this artifact here which I actually would like to avoid uh the model responds with sure here's a support question based on these examples that's something I would should probably put into the prompt that I'd like to avoid just give me the question don't give me extra text uh and again I think this these questions are a bit more diverse I think this few short um examples are helping but we can we can go even further and um to go further and to increase the range of questions that we can ask the model uh we may uh want to give it some more context and um the type of questions that we actually want to be like should be able to respond are the type of questions where we also have some documentation available as long as that is the documentation for a specific user question we should be able to answer that question so in order to to evaluate our model we especially want to make sure that whenever documentation is available the answer is correct for that question so why don't we use documentation to also generate synthetic questions and to do this uh we provided in our um in our course repo we provided just several examples of weight and by docs we don't um we don't um provide the entire docs they are available at docs. 1db doai uh however um going through all of these documents would uh take a lot of time and a lot of uh API calls so we just I will just use a small sample of that um what you need to uh understand as you using just a small sample of of docs then this data set of questions um will also be limited to what is available in this docs so first let's process our directory and uh collect all of the markdown markdown files and we can see there are 11 documents uh in this in this folder uh then um we want to fit this documents into the prompt into the context window of our model uh so let's check how long these documents are and we're interested in the number of tokens we will use the tick token library to calculate the number of tokens per document and we can see that some of them are actually quite long we don't need that much text in our prompt and and for those uh documents we will um just extract a random chunk of a document to um uh to to to inspire the model to create some questions so let's also Define this uh random junking function and now uh we will generate a context prompt where um we ask the model to generate a support question from a weight invis user and we give a a context of fragment of weight inisis documentation and we tell the model that this question should be answerable by the provided fragment of weight inisis documentation so let's um do this let's see this uh prompt so in our case um the model picked randomly um let's see I think a fragment of code from one of our Integrations let's see if we can see which integration this is no I think it might be just a simple standard example um of um weights and biases and then it talks also about defining metric it's probably from the intro uh collab okay let's see uh let's see what uh what this uh prompt results uh in and what type of generations it can it can trigger let's give the model a couple of seconds and then see the outputs okay so uh the model asks the following questions what is the purpose of the defined metric function in weights Andes how can it be used to control the display of summary metrix um what is the purpose of get bread loss accuracy function in this weight and bis documentation fragment that's not something we're looking for this uh definitely looks like a synthetic question where um let's call it the the model or the user has seen documentation and then ask questions about it we are actually interested in natural questions in questions that a user might have without seeing the documentation however we do want to make sure that documentation can answer it so probably we have not done a good job with a prompt so how do we how do we do a better job on the prompt side
Original Description
🤖 Unlock Advanced Prompt Engineering in Chapter 10: Dive into synthetic datasets and zero-shot techniques in LLMs.
🧑🏾🎓 Full course with certification and class materials available free at http://wandb.me/building-llm-powered-apps
🏆 Daily swag draw and grand prize Airpods draw from Dec 1 and 31, 2023. Details at http://wandb.me/llm-apps-contest
🗣️ Join the course conversation on our Discord channel at http://wandb.me/course-discord
*Episode Description*
Unlock the potential of prompt engineering in Large Language Models (LLMs) with this vital chapter of our "Building LLM-Powered Apps" course, brought to you by Weights & Biases. Darek Kleczek, our expert machine learning engineer, guides you through various prompt engineering techniques with practical code experiments.
🌟 Chapter Highlights
-Understanding Prompt Engineering: Delve into the world of prompt engineering and its significance in LLMs.
-Synthetic Dataset Generation: Learn how to generate a synthetic dataset of user questions for a hypothetical LLM-powered application like Weights & Biases' Wandbot.
-Interactive Experiments with Jupyter Notebooks: Follow along with interactive coding sessions in Jupyter Notebooks to experiment with LLM APIs.
-Exploring Zero Shot and Few Shot Techniques: See how zero shot and few shot prompting techniques can be applied and evaluated for effectiveness.
-Advanced Contextual Prompts: Discover how to create more complex prompts using documentation excerpts to generate more natural user questions.
🎓 Enroll for Free: Join us on this educational journey to master the art of building LLM-powered applications. Enroll at http://wandb.me/building-llm-powered-apps.
👉 Next Chapter Sneak Peek: Stay tuned for our next chapter, where we focus on building the baseline architecture for an LLM application.
Watch on YouTube ↗
(saves to browser)
Sign in to unlock AI tutor explanation · ⚡30
Playlist
Uploads from Weights & Biases · Weights & Biases · 0 of 60
← Previous
Next →
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
0. What is machine learning?
Weights & Biases
1. Build Your First Machine Learning Model
Weights & Biases
Intro to ML: Course Overview
Weights & Biases
2. Multi-Layer Perceptrons
Weights & Biases
3. Convolutional Neural Networks
Weights & Biases
Weights & Biases at OpenAI
Weights & Biases
Why Experiment Tracking is Crucial to OpenAI
Weights & Biases
4. Autoencoders
Weights & Biases
5. Sentiment Analysis
Weights & Biases
6. Recurrent Neural Networks [RNNs]
Weights & Biases
7. Text Generation using LSTMs and GRUs
Weights & Biases
8. Text Classification Using Convolutional Neural Networks
Weights & Biases
9. Hybrid LSTMs [Long Short-Term Memory]
Weights & Biases
Toyota Research Institute on Experiment Tracking with Weights & Biases
Weights & Biases
Weights and Biases - Developer Tools for Deep Learning
Weights & Biases
Introducing Weights & Biases
Weights & Biases
10. Seq2Seq Models
Weights & Biases
11. Transfer Learning for Domain-Specific Image Classification with Small Datasets
Weights & Biases
12. One-shot learning for teaching neural networks to classify objects never seen before
Weights & Biases
13. Speech Recognition with Convolutional Neural Networks in Keras/TensorFlow
Weights & Biases
14. Data Augmentation | Keras
Weights & Biases
15. Batch Size and Learning Rate in CNNs
Weights & Biases
Applied Deep Learning Fellowship Overview and Project Selection with Josh Tobin (2019)
Weights & Biases
Grading Rubric for AI Applications with Sergey Karayev (2019)
Weights & Biases
16. Video Frame Prediction using CNNs and LSTMs (2019)
Weights & Biases
Image to LaTeX - Applied Deep Learning Fellowship (2019)
Weights & Biases
17. Build and Deploy an Emotion Classifier (2019)
Weights & Biases
Applied Deep Learning - Data Management with Josh Tobin (2019)
Weights & Biases
Snorkel: Programming Training Data with Paroma Varma of Stanford University (2019)
Weights & Biases
Applied Deep Learning - Troubleshooting and Debugging with Josh Tobin (2019)
Weights & Biases
Troubleshooting and Iterating ML Models with Lee Redden (2019)
Weights & Biases
Designing a Machine Learning Project with Neal Khosla (2019)
Weights & Biases
Lukas Beiwald on ML Tools and Experiment Management (2019)
Weights & Biases
Building Machine Learning Teams with Josh Tobin (2019)
Weights & Biases
Pieter Abeel on Potential Deep Learning Research Directions (2019)
Weights & Biases
Testing and Deployment of Deep Learning Models with Josh Tobin (2019)
Weights & Biases
Five Lessons for Team-Oriented Research with Peter Welder (2019)
Weights & Biases
Applied Deep Learning - Rosanne Liu on AI Research (2019)
Weights & Biases
Making the Mid-career Leap from Urban Design to Deep Learning/Data Science
Weights & Biases
Organizing ML projects — W&B walkthrough (2020)
Weights & Biases
Brandon Rohrer — Machine Learning in Production for Robots
Weights & Biases
Nicolas Koumchatzky — Machine Learning in Production for Self-Driving Cars
Weights & Biases
My experiments with Reinforcement Learning with Jariullah Safi
Weights & Biases
Applications of Machine Learning to COVID-19 Research with Isaac Godfried
Weights & Biases
Testing Machine Learning Models with Eric Schles
Weights & Biases
How Linear Algebra is not like Algebra with Charles Frye
Weights & Biases
Predicting Protein Structures using Deep Learning with Jonathan King
Weights & Biases
Rachael Tatman — Conversational AI and Linguistics
Weights & Biases
Reformer by Han Lee
Weights & Biases
Sequence Models with Pujaa Rajan
Weights & Biases
GitHub Actions & Machine Learning Workflows with Hamel Husain
Weights & Biases
Look Mom, No Indices! Vector Calculus with the Fréchet Derivative by Charles Frye
Weights & Biases
Jack Clark — Building Trustworthy AI Systems
Weights & Biases
Surprising Utility of Surprise: Why ML Uses Negative Log Probabilities - Charles Frye
Weights & Biases
Track your machine learning experiments locally, with W&B Local - Chris Van Pelt
Weights & Biases
Antipatterns in open source research code with Jariullah Safi
Weights & Biases
Attention for time series forecasting & COVID predictions - Isaac Godfried
Weights & Biases
Made with ML - Goku Mohandas
Weights & Biases
Angela & Danielle — Designing ML Models for Millions of Consumer Robots
Weights & Biases
Deep Learning Salon by Weights & Biases
Weights & Biases
More on: Prompt Craft
View skill →Related Reads
📰
📰
📰
📰
ChatGPT Plus vs. a Local AI Assistant: What You Actually Get (and Give Up)
Dev.to AI
OpenAI Quietly Cut Codex's Context Window 27%, and Most Harnesses Still Don't Know
Dev.to AI
Building Production-Grade LLM Evaluation Pipelines: From Vibes to Metrics
Dev.to AI
Getting Started with Open-Weight LLM API Integration: A Developer's Guide
Dev.to AI
🎓
Tutor Explanation
DeepCamp AI