Prompt Engineering
์ค๋๋ฅ ๊ต์๋์ ํ๋กฌํํธ ๊ฐ์ ์ ๋ฆฌ
๊ฐ์ Url
๊ฐ์ ๋ด์ฉ
introduce
๊ฐ๋ฐ์๋ก์ ๋ํ ์ธ์ด ๋ชจ๋ธ(LLM)์ ์ฌ์ฉํ์ฌ API ํธ์ถ์ ํตํด ์ํํธ์จ์ด ์ ํ๋ฆฌ์ผ์ด์ ์ ๋น ๋ฅด๊ฒ ๊ตฌ์ถํ๋ ๊ฒ์ ํ์ ์ฌ์ ํ ๋ง์ด ๊ณผ์ ํ๊ฐ๋๊ณ ์๋ค
Base LLM(๊ธฐ๋ณธ LLM) and Instruction-tuned LLM(์ง์์ฌํญ ์กฐ์ LLM)
๊ธฐ๋ณธ LLM์ ์ธํฐ๋ท ๋ฐ ๊ธฐํ ์ถ์ฒ์ ๋๋์ ํ ์คํธ ๋ฐ์ดํฐ๋ฅผ ๊ธฐ๋ฐ์ผ๋ก ๋ค์ ๋จ์ด๋ฅผ ์์ธกํ๋ ๋ฐฉ์์ผ๋ก ํ์ต๋ฉ๋๋ค.
๊ทธ๋ฌ๋ ํ๋์ค์ ์๋๊ฐ ๋ฌด์์ธ์ง ๋ฌผ์ผ๋ฉด, ์ธํฐ๋ท ์์ ๊ธฐ์ฌ๋ฅผ ๊ธฐ๋ฐ์ผ๋ก ๊ธฐ๋ณธ LLM์ ํ๋์ค์ ๊ฐ์ฅ ํฐ ๋์, ํ๋์ค์ ์ธ๊ตฌ ๋ฑ์ ์ถ๋ ฅํ ์ ์์ต๋๋ค. ์๋ํ๋ฉด ์ธํฐ๋ท์์ ํ๋์ค์ ๋ํ ํด์ฆ ์ง๋ฌธ ๋ชฉ๋ก์ด ์์ ์ ์๊ธฐ ๋๋ฌธ์ ๋๋ค.
๋ฐ๋ฉด ์ง์์ฌํญ ์กฐ์ LLM์ ์ง์์ฌํญ์ ๋ฐ๋ฅด๋๋ก ํ๋ จ๋ ๋ชจ๋ธ์ ๋๋ค. ํ๋์ค์ ์๋๊ฐ ๋ฌด์์ธ์ง ๋ฌผ์ผ๋ฉด, ์ง์์ฌํญ ์กฐ์ LLM์ ํ๋์ค์ ์๋๋ ํ๋ฆฌ๋ผ๊ณ ์ถ๋ ฅํ ๊ฐ๋ฅ์ฑ์ด ๋์ต๋๋ค.
์ง์์ฌํญ ์กฐ์ LLM์ ์ผ๋ฐ์ ์ผ๋ก ๋๋์ ํ ์คํธ ๋ฐ์ดํฐ๋ก ํ๋ จ๋ ๊ธฐ๋ณธ LLM์ ์์์ ์ผ๋ก ์ผ์, ์ ๋ ฅ๊ณผ ์ถ๋ ฅ์ด ์ง์์ฌํญ๊ณผ ๊ทธ์ ๋ฐ๋ฅธ ์ข์ ์๋ต์ผ๋ก ์ด๋ฃจ์ด์ง ๋ฐ์ดํฐ๋ก ์ถ๊ฐ ํ๋ จ(๋ฏธ์ธ ์กฐ์ fine tunning)์ ํฉ๋๋ค.
๊ทธ๋ฐ ๋ค์, RLHF(์ธ๊ฐ ํผ๋๋ฐฑ์์์ ๊ฐํ ํ์ต reinforcement learning from human feedback)๋ผ๋ ๊ธฐ์ ์ ์ฌ์ฉํ์ฌ ์์คํ ์ ๋ ๋์์ด ๋๊ณ ์ง์์ฌํญ์ ๋ฐ๋ฅด๋๋ก ๋ง๋ญ๋๋ค. ์ง์์ฌํญ ์กฐ์ LLM์ ๋์์ด ๋๊ณ , ์ ์งํ๋ฉฐ, ํด๋ฅผ ๋ผ์น์ง ์๋๋ก ํ๋ จ๋์์ต๋๋ค. ์๋ฅผ ๋ค์ด, ๊ธฐ๋ณธ LLM์ ๋นํด ์ ํดํ ํ ์คํธ ์ถ๋ ฅ์ ์ค์ ๋๋ค. ์ค์ ์ฌ์ฉ ์ฌ๋ก์์๋ ์ง์์ฌํญ ์กฐ์ LLM์ด ๋ง์ด ์ฌ์ฉ๋๊ณ ์์ต๋๋ค. ์ด ๊ณผ์ ์์๋ ๋๋ถ๋ถ์ ์ ํ๋ฆฌ์ผ์ด์ ์ ์ฌ์ฉํ ๊ฒ์ ๊ถ์ฅํ๋ ์ง์์ฌํญ ์กฐ์ LLM์ ์ด์ ์ ๋ง์ถฅ๋๋ค.
์ง์์ฌํญ ์กฐ์ LLM์ ์ฌ์ฉํ ๋, ๋ค๋ฅธ ์ฌ๋์๊ฒ ์ง์์ฌํญ์ ์ฃผ๋ ๊ฒ์ฒ๋ผ ์๊ฐํ์ธ์. ์๋ฅผ ๋ค์ด ๋๋ํ์ง๋ง ํน์ ์์ ์ ๋ํ ์ง์์ด ์๋ ์ฌ๋์๊ฒ ์ง์๋ฅผ ๋ด๋ฆฝ๋๋ค. ๋๋ก๋ LLM์ด ์๋ํ์ง ์๋ ์ด์ ๋ ์ง์์ฌํญ์ด ์ถฉ๋ถํ ๋ช ํํ์ง ์๊ธฐ ๋๋ฌธ์ผ ์ ์์ต๋๋ค. ์๋ฅผ ๋ค์ด, "์จ๋ฐ ํ๋ง์ ๋ํด ๋ฌด์ธ๊ฐ๋ฅผ ์จ ์ฃผ์ธ์"๋ผ๊ณ ๋งํ๋ฉด, ๊ทธ์ ๊ณผํ์ ์ ์ ์ด๋ ๊ฐ์ธ์ ์ธ ์ถ, ์ญ์ฌ์์์ ์ญํ ๋ฑ์ ์ด์ ์ ๋ง์ถ๋์ง ๋ช ํํ ํด์ฃผ๋ ๊ฒ์ด ๋์์ด ๋ ๊ฒ์ ๋๋ค.
๋ํ ํ ์คํธ์ ์ด์กฐ๋ฅผ ์ง์ ํด ์ฃผ๋ฉด ๋์์ด ๋ฉ๋๋ค. ์ ๋ฌธ ๊ธฐ์๊ฐ ์์ฑํ ๊ฒ์ฒ๋ผ ํน์ ์น๊ตฌ์๊ฒ ๋ณด๋ด๋ ์บ์ฃผ์ผํ ๋ ธํธ์ฒ๋ผ ์์ฑ๋์ด์ผ ํ๋์ง๋ฅผ ๋งํด์ฃผ๋ฉด LLM์ด ์ํ๋ ๊ฒฐ๊ณผ๋ฌผ์ ์์ฑํ๋ ๋ฐ ๋์์ด ๋ฉ๋๋ค. ๋ฌผ๋ก , ์จ๋ฐ ํ๋ง์ ๋ํ ํ ์คํธ๋ฅผ ์์ฑํ๊ธฐ ์ ์ ์ฝ์ด์ผ ํ ํ ์คํธ ์กฐ๊ฐ์ ์ง์ ํ ์ ์๋ค๋ฉด, ๊ทธ ์์ ์ ์ํํ๋ ๋ฐ ๋ ์ฑ๊ณต์ ์ผ ๊ฒ์ ๋๋ค.
๋๊ฐ์ง ์์น
Principle 1: Write clear and specific instructions Principle 2: Give the model time to "think"
๋ช ํํ๊ณ ๊ตฌ์ฒด์ ์ธ ๋ฐฉ๋ฒ์ ์ฌ์ฉํ๋ ๊ฒ์ด ํ๋กฌํํธ ์์ฑ์ ์ค์ํ ์์น
LLM์๊ฒ ์๊ฐํ ์๊ฐ์ ์ฃผ๋ ๊ฒ์ด ํ๋กฌํํธ์ ๋ ๋ค๋ฅธ ์์น
Guideline
Prompting Principles
Principle 1: Write clear and specific instructions
Principle 2: Give the model time to "think"
Principle 1: Write clear and specific instructions

์ ๋ต 1: Use delimiters to clearly indicate distinct parts of the input
๊ตฌ๋ถ ๊ธฐํธ๋ฅผ ์ฌ์ฉํ์ฌ ์ ๋ ฅ์ ๊ตฌ๋ถ๋๋ ๋ถ๋ถ์ ๋ช ํํ๊ฒ ํ์ํฉ๋๋ค.
Delimiters can be anything like: ``` """ ''' tag : ๋๋ :::
Avoiding prompt injection ํ๋กฌํํธ์ ์ธ์ ์ ์ ๋ง์๋ผ. ์ง๋ฌธ๋ด์ฉ๊ณผ ์๋ฃ ๋ด์ฉ์ด ์์ด๊ฒ ๋๋ ๋ฌธ์ ๋ฅผ ๋ง์๋ผ ๋ผ๋ ๋ป

์ ๋ต 2: Ask for a structured output
๊ตฌ์กฐํ๋ ์์ํ์ ์๊ตฌํด๋ผ.
json/html
์ ๋ต 3: Ask the model to check whether conditions are satisfied
๋ชจ๋ธ์๊ฒ ์กฐ๊ฑด์ด ์ถฉ์กฑ๋์๋์ง ํ์ธํ๋๋ก ์์ฒญํฉ๋๋ค.
์ ๋ต 4: "Few-shot" prompting
give successful examples of completing tasks then ask model to perform the task
์์ ์๋ฃ์ ์ฑ๊ณต์ ์ธ ์๋ฅผ ์ ์ํ ๋ค์ ๋ชจ๋ธ์๊ฒ ์์ ์ ์ํํ๋๋ก ์์ฒญํฉ๋๋ค.

๋น์ทํ๊ฒ ๋ต๋ณ์ด ๋์จ๋ค.
Principle 2: Give the model time to โthinkโ

์ ๋ต 1: Specify the steps required to complete a task
์์ ์ ์๋ฃํ๋ ๋ฐ ํ์ํ ๋จ๊ณ๋ฅผ ์ง์ ํ์ธ์.

Ask for output in a specified format
์์ ๊ทธ๋ฆผ์ ๋์จ ๋ด์ฉ์ ํฌ๋งท์ ๋ฐ๊ฟ์ ์ถ๋ ฅํ๋ผ๊ณ ๋ช ๋ น
์๋๋ค.
์ ๋ต 2: Instruct the model to work out its own solution before rushing to a conclusion
๊ฒฐ๋ก ์ ๋ด๋ฆฌ๊ธฐ ์ ์ ๋ชจ๋ธ ์ค์ค๋ก ํด๊ฒฐ์ฑ ์ ์ฐพ๋๋ก ์ง์ํ์ธ์.
์ฌ์ค์ ํ๋ฆฌ๋ค๊ฐ ๋์์ผ ํจ ๊ทธ๋ฌ๋ chatgpt๊ฐ ๋ง๋ค๊ณ ํจ.
๋๋์ ๋ค์์ฒ๋ผ ์์ ํด์ ์๊ฐํ ์๊ฐ์ ์ฃผ๋ฉด chatgpt๊ฐ ๋ง๋ ๋ต์ ์ค๋ค๋ ์ด์ผ๊ธฐ

์์ ๋ง๋๋ต์ ์ฃผ๊ฑฐ๋ ์๊ฐํ ๊ฑฐ๋ฆฌ๋ฅผ ์ค ์ดํ์ ๋ง์ง๋ง์ ์ง๋ฌธ์ ํ์ ๋ต์ ๋ฃ์ด์ฃผ๊ณ ์ด๊ฒ ๋ง๋์ง ๋ฌผ์ด๋ณด๋ฉด๋จ.
Model Limitations

Hallucinations (ํ๊ฐ)
makes statements that sound plausible but are not true (๊ทธ๋ด๋ฏํ๊ฒ ๋ค๋ฆฌ์ง๋ง ์ฌ์ค์ด ์๋ ์ง์ ์ ํ๋ ๊ฒฝ์ฐ)
reducing hallucinations
ํ๊ฐ์ ์ค์ฌ์ผํ๋ค.
First find relevant information, then answer the question based on the relevant information.
๋จผ์ ๊ด๋ จ ์ ๋ณด๋ฅผ ์ฐพ์ ๋ค์ ๊ด๋ จ ์ ๋ณด๋ฅผ ๋ฐํ์ผ๋ก ์ง๋ฌธ์ ๋ตํ์ธ์.
Iterative Prompt Develelopment
๋ฐ๋ณต ํ๋กฌํํธ ๊ฐ๋ฐ
์ ํ ํฉํธ ์ํธ์์ ๋ง์ผํ ๋ฌธ๊ตฌ๋ฅผ ์์ฑํ๊ธฐ ์ํด ๋ฐ๋ณต์ ์ผ๋ก ๋ฉ์์ง๋ฅผ ๋ถ์ํ๊ณ ๊ฐ์ ํ ์ ์์ต๋๋ค.

prompt guidlines
be cleare and spectific
analyze why result does not give desirded output
refine the idea and the prompt
Repeat
Issue 1: The text is too long
์ด๋ฐ์์ผ๋ก ํ๋ฉด ์์ํ์ด ์ ์ด์ง๋ค.
Issue 2. Text focuses on the wrong details
Ask it to focus on the aspects that are relevant to the intended audience.
Issue 3. Description needs a table of dimensions
html๋ก ์ธ์
Ask it to extract information and organize it in a table.
html๋ก ๋์จ๋ค. ์ด๊ฑธ Python์ผ๋ก ์ฐ์ผ๋ฉด html๋ธ๋ผ์ฐ์ ์์ ๋ณด์ธ๋ค.

try something
analyze where the result does not give what you want
clarify instructions , give more time to think
refine prompts with a batch of examples
๋ฌด์ธ๊ฐ๋ฅผ ์๋ํ์ญ์์ค.
๊ฒฐ๊ณผ๊ฐ ์ํ๋ ๊ฒ์ ์ ๊ณตํ์ง ์๋ ๋ถ๋ถ์ ๋ถ์ํ์ญ์์ค.
์ง์นจ ๋ช ํํํ๊ธฐ, ์๊ฐํ ์๊ฐ์ ๋ ๋ง์ด์ฃผ์ญ์์ค.
์์ ์ผ๊ด ์ฒ๋ฆฌ๋ก ํ๋กฌํํธ ๊ตฌ์ฒดํ
Summarizing
you will summarize text with a focus on specific topics.
prod_review = """ Got this panda plush toy for my daughter's birthday, who loves it and takes it everywhere. It's soft and super cute, and its face has a friendly look. It's a bit small for what I paid though. I think there might be other options that are bigger for the same price. It arrived a day earlier than expected, so I got to play with it myself before I gave it to her. """
Summarize with a word/sentence/character limit
Summarize with a focus on shipping and delivery
Summarize with a focus on price and value
Summaries include topics that are not related to the topic of focus.
Try "extract" instead of "summarize"
Summarize multiple product reviews
reviews = [review_1, review_2, review_3, review_4]
Inferring(์ถ๋ก )
infer sentiment: ๊ฐ์ ์ถ๋ก
In this lesson, you will infer sentiment and topics from product reviews and news articles.
์ด ์์ ์์๋ ์ ํ ๋ฆฌ๋ทฐ์ ๋ด์ค ๊ธฐ์ฌ์์ ๊ฐ์ฑ๊ณผ ์ฃผ์ ๋ฅผ ์ถ๋ก ํ ๊ฒ์ ๋๋ค.
Sentiment (positive/negative)
Identify types of emotions
Identify anger
Extract product and company name from customer reviews
Doing multiple tasks at once
Inferring topics
Infer 5 topics
Make a news alert for certain topics
trasforming (๋ณํ)
๋ฒ์ญ
ChatGPT๋ ๋ค์ํ ์ธ์ด์ ์์ค๋ก ํ์ต๋ฉ๋๋ค. ์ด๋ฅผ ํตํด ๋ชจ๋ธ์ ๋ฒ์ญ ๊ธฐ๋ฅ์ ์ ๊ณตํฉ๋๋ค. ๋ค์์ ์ด ๊ธฐ๋ฅ์ ์ฌ์ฉํ๋ ๋ฐฉ๋ฒ์ ๋ํ ๋ช ๊ฐ์ง ์์ ๋๋ค.
๋ค์ ํ ์คํธ๋ฅผ ๊ณต์ ๋ฐ ๋น๊ณต์ ํ์ ๋ชจ๋์์ ์คํ์ธ์ด๋ก ๋ฒ์ญํ์ธ์:
Universal Translator
Imagine you are in charge of IT at a large multinational e-commerce company. Users are messaging you with IT issues in all their native languages. Your staff is from all over the world and speaks only their native languages. You need a universal translator!
๋๊ท๋ชจ ๋ค๊ตญ์ ์ด์ปค๋จธ์ค ๊ธฐ์ ์์ IT๋ฅผ ๋ด๋นํ๊ณ ์๋ค๊ณ ๊ฐ์ ํด ๋ณด์ธ์. ์ฌ์ฉ์๋ค์ด ๊ฐ์์ ๋ชจ๊ตญ์ด๋ก IT ๋ฌธ์ ์ ๋ํด ๋ฉ์์ง๋ฅผ ๋ณด๋ด๊ณ ์์ต๋๋ค. ์ ์ธ๊ณ ๊ฐ์ง์์ ์จ ์ง์๋ค์ ๊ฐ์์ ๋ชจ๊ตญ์ด๋ง ๊ตฌ์ฌํฉ๋๋ค. ์ฌ๋ฌ๋ถ์๊ฒ๋ ๋ฒ์ฉ ๋ฒ์ญ๊ธฐ๊ฐ ํ์ํฉ๋๋ค!
Tone Transformation
Writing can vary based on the intended audience. ChatGPT can produce different tones. ๊ธ์ฐ๊ธฐ๋ ๋์์ ๋ฐ๋ผ ๋ฌ๋ผ์ง ์ ์์ต๋๋ค. ChatGPT๋ ๋ค์ํ ํค์ ์์ฑํ ์ ์์ต๋๋ค.
Format Conversion
ChatGPT can translate between formats. The prompt should describe the input and output formats.
ChatGPT๋ ํ์ ๊ฐ ๋ฒ์ญ์ด ๊ฐ๋ฅํฉ๋๋ค. ํ๋กฌํํธ์ ์ ๋ ฅ ๋ฐ ์ถ๋ ฅ ํ์์ด ์ค๋ช ๋์ด ์์ด์ผ ํฉ๋๋ค.
Spellcheck/Grammar check

expanding
In this lesson, you will generate customer service emails that are tailored to each customer's review.
์ด ๋จ์์์๋ ๊ฐ ๊ณ ๊ฐ์ ๋ฆฌ๋ทฐ์ ๋ง๋ ๊ณ ๊ฐ ์๋น์ค ์ด๋ฉ์ผ์ ์์ฑํฉ๋๋ค.
Customize the automated reply to a customer emailยถ
Remind the model to use details from the customer's email
temperature (์จ๋)




๋งค๋ฒ ํ ๋๋ง๋ค ์กฐ๊ธ์ฉ ๋ฌ๋ผ์ง๊ฒ ํ ์ ์๊ณ 0์ ๋๋ฅด๋ฉด ํญ์ ๊ฐ์์ง๋ค.
๊ฐ์ ๋ชจ๋ธ์ ์ ๋ฌํ๋ฉด๋๋ค.
chatbot
In this notebook, you will explore how you can utilize the chat format to have extended conversations with chatbots personalized or specialized for specific tasks or behaviors.
์ด ๋ ธํธ๋ถ์์๋ ์ฑํ ํ์์ ํ์ฉํ์ฌ ํน์ ์์ ์ด๋ ํ๋์ ๋ง๊ฒ ๋ง์ถคํ๋๊ฑฐ๋ ํนํ๋ ์ฑ๋ด๊ณผ ํ์ฅ๋ ๋ํ๋ฅผ ๋๋๋ ๋ฐฉ๋ฒ์ ์ดํด๋ด ๋๋ค.


orderbot
conclusion

Last updated
Was this helpful?