LongCut logo

第3集-迭代-ChatGPT提示工程师|AI大神吴恩达教你写提示词

By 退休生活真精彩

Summary

## Key takeaways - **Prompts Rarely Work First Try**: When building applications with large language models, I've never used the first prompt in the final application. What matters is having a good process to iteratively make your prompt better. [00:04], [00:24] - **ML Iteration Mirrors Prompt Dev**: Prompt development follows a similar process to machine learning: have an idea, implement a prompt, get results, do error analysis, refine, and iterate until effective. [01:07], [02:09] - **Ignore 'Perfect Prompts' Lists**: I personally have not paid much attention to internet articles with 30 perfect prompts because there isn't a perfect prompt for everything; it's more important to have a process for your specific application. [02:21], [02:54] - **Iterate Chair Fact Sheet Summary**: First prompt produced a long description; refined to 'use at most 50 words' for shorter output, then specified for furniture retailers focusing on technical details and materials, finally adding product IDs like SWC-110. [04:20], [08:56] - **Control Output with Constraints**: Large language models are okay but not great at precise word counts; try 'at most 50 words', 'three sentences', or '280 characters' to control length. [05:45], [06:53] - **Scale to Multiple Examples Later**: For early development, iterate with one example like the chair fact sheet; for mature applications, evaluate prompts against dozens of fact sheets for average or worst-case performance. [12:03], [12:48]

Topics Covered

  • Full Video

Full Transcript

when I've been building applications with large language models I don't think I've ever come to the prompt that I ended up using in the final application on my first attempt and this isn't what

matters as long as you have a good process to iteratively make your prompt better then you'll be able to come to something that works well for the task you want to achieve

you may have heard me say that when I create a machine learning model it almost never works the first time in fact I'm very surprised of the first model I train works I think we're prompting the odds of it working the

first time is maybe a little bit higher but as is saying doesn't matter if the first prompt Works what matters most the process for getting to the prompts that works for your application so with that

let's jump into the codes and let me show you some Frameworks to think about how to iteratively develop a prompt right so if you've taken a machine learning course with me before you may

have seen me use a diagram saying that with machine learning development you often have an idea and then implement it so write the code

get the data train your model and that gives you an experimental result and you can then look at that output maybe do error analysis figure out where it's working or not working and then maybe

even change your idea of exactly what problem you want to solve or how to approach it and then change the implementation and run another experiment and so on and iterate over and over to get to an effective machine

learning model if you're not familiar with machine learning and hasn't seen this diagram before don't worry about it not that important for the rest of this presentation but when you are writing

prompts to develop an application using an oom the process can be quite similar where you have an idea for what you want to do

the tasks you want to complete and you can then take a first attempt at writing a prompt that hopefully is clearance specific

and maybe if appropriate gives the system time to think and then you can run it and see what result you get and if it doesn't work well not the first

time then the iterative process of figuring out why the instructions for example we're not clear enough or why it didn't give the algorithm enough time to think allows you to refine the idea refine the prompts and so on and to go

around this Loop multiple times until you end up with a prompt that works with your application this too is why I personally have not paid as much attention to the internet

articles that say 30 perfect prompts because I think there probably isn't a perfect prom for everything under the sun it's more important that you have a process for developing a good prompt for

your specific application so let's look at an example together in code I have here the starter code that you saw in the previous videos I've been

pulled open AI import OS here um we get the open AI API key and this is the same helper function that you saw as last time and

I'm going to use as the running example in this video the task of summarizing a fact sheet for a chair

so let me just paste that in here and um feel free to pause the video and read this more carefully in The Notebook on the left if you want but here's a fact sheet for a chair with a

description saying it's part of a beautiful family of mid century inspired and so on um talks about the construction as the dimensions options for the chair

materials and so on comes from Italy so let's say you want to take this fact sheet and help a marketing team write a

description for a online retail website let me just quickly run these three and then um we'll come up with our prompt as follows and I'll just

and I'll just paste this in so my prompt here says your task is to help a marketing team create a description for retail websites or product based on techno fact sheet write

a product description and so on right so this is my first attempt to explain the task to the large language model so let me hit shift enter and this takes a few

seconds to run and we get this result it looks like it's done a nice job writing a description introducing a stunning mid-century inspired office chair

perfect Edition and so on but when they look at this I go boy this is really long it's done a nice job doing exactly what I asked it to which is start from the technical fact sheet and write a

product description but when I look at this I go this is kind of long maybe we want it to be a little bit shorter so so I have had an idea I wrote a prompt got a result I'm

not that happy with it because it's too long so I will then clarify my prompt um and say use

at most 50 words to try to give better guidance on the desired length of this and let's run it again okay this actually looks like a much

nicer short description of the product introducing on mid-century inside office chair and so on five for you just yeah both stylish and practical not bad um

and let me double check the length that this is so I'm going to take the response split it according to where there's space is and then you'll print out the length so it's 52 words it's actually not bad

um large language models are okay but not that great at following instructions about a very precise workout but this is actually not bad sometimes it will print out something

with 60 or 65 and so on words but it's kind of within reason some of the things you could try to do would be um to say use that knows the

three sentences let me run that again but these are different ways to tell the large language model what's the length of the output that you want so this is one two

three I call it three sentences also I did a pretty good job um and then I've also seen people sometimes do things like uh I don't know use that most 280

characters large language models because of the way they interpret text using something called a tokenizer which which I won't

talk about but um they tend to be so so accounting characters but let's see 281 characters is actually surprisingly close usually a large

language models doesn't get quite as close but these are different ways they can play with to try to control the length of the output that you get but let me just switch it back to use at

those 50 words and that's that result that we had just now as we continue to refine this text for our website we might decide that boy

this website isn't selling direct consumers is actually intended to sell Furniture to Furniture retailers that would be more interested in the

technical details of the chair and the materials of the chair in that case you can take this prompt and say I want to modify this prompt to get it to be more

precise about the technical details so let me keep on modifying this prompt and I'm going to say this description is intended for furniture retailers so should be

Technical and focus on materials products and construct it from well let's run that and let's see

not bad says you know coated aluminum based and pneumatic chair high quality materials so by changing the prompt you can get it to focus more

on specific characters on specific characteristics you wanted to and when I look at this I might decide at the end

of the description I also wanted to include the product IDs so the two offerings of

this chair swc110 SOC 100.

so maybe I can further improve this prompt and to get it to give me the product IDs I can add this instruction at the end of the description include every seven

character product ID in the technical specification and let's run it and see what happens and so it says introducing the sections

file office chair colors talks about plastic coating aluminum base um practical some options

talks about the two product IDs so this looks pretty good and what you've just seen is a short example of the iterative prompt development that many developers

will go through and I think our guidelines is in the last video you saw either share a number of best practices and so what I usually

do is keep best practices like that in mind be clear and specific and if necessary give the model time to think with those in mind it's worthwhile so often take a first attemptive writing a

problem see what happens and then go from there to iteratively refine the prompt to get closer and closer to the result that you need and so a lot of the successful prompts

that you may see used in various programs was arrive at an iterative process like this just for fun let me show you an example

of a even more complex prompt that might give you a sense of what GPT can do which is um I've just added a few extra instructions here after the description

include the table that gives the product dimensions and then you know form everything as HTML so let's run that and in practice you would end up with a prompt like this really only after

multiple iterations I don't think I know anyone that would write this exact prompt the first time they were trying to get the system to process a fact sheet

and so this actually outputs a bunch of HTML let's display the HTML to see if this is even valid HTML and see if this works

and I don't actually know what's going to work but let's see oh cool all right let's look at rendered so it has this really nice looking description of a chair um Construction

materials product dimensions um oh it looks like I left out the uh use at most 50 words instructions so this is a little bit long but if you want that

you know you can even feel free to pause the video tell it to be more succinct and regenerate this and see what results you get so I hope you take away from this video

that prompt development is an iterative process try something see how it does not yet fulfill exactly what you want and then think about how to clarify your instructions or in some cases think

about how to give it more space to think to get it closer to delivering the results that you want I think the key to being an effective

prompt engineer isn't so much about knowing the perfect prompt is about having a good process to develop problems that are effective for your application

and in this video I Illustrated developing a prompt using just one example for more sophisticated applications sometimes you will have

multiple examples say a list of 10 or even 50 or 100 fact sheets and iteratively develop a prompt and

evaluate it against a large set of cases but for the early development of most applications I see many people developing it sort of the way I am with

just one example but then for more mature applications sometimes it could be useful to evaluate prompts against a larger set of examples such as

to test different problems on dozens of fact sheets to see how is average or worst case performances on multiple fact sheets but usually you end up doing that only when an application is more mature

and you have to have those metrics to drive that incremental last few steps of prompt Improvement so with that please do play with the Jupiter code notebook examples and try

out different variations and see what results you get and when you're done let's go on to the next video where we'll talk about one very common use of

large language models in software applications which is to summarize sex so when you're ready let's go on to the next video

Loading...

Loading video analysis...