본문 바로가기

Prompt/프롬프트 공부

효과적인 프롬프트 쓰기의 기본 규칙

처음에 챗 지피티를 썼을 때는 내가 편한 말투로 질문했고, '이런 주제로 글 작성해 줘' 등의 질문을 많이 했었다.

그러나 챗 지피티 API를 활용해 서비스할 만한 결과물을 내기 위해선 공부가 필요했다.

 

아는 만큼 어렵다.

알아가면 갈수록 챗지피티는 내 의도를 벗어난 대답을 해줬다.

프롬프트 작성법과 API 코드에 대해 이곳저곳 마구 검색하며 배운 얕은 방법론 때문에 더 이해하기 어려웠다.

뭐.. 거의 영어로 쓰여있었다.

챗 지피티 누가 공부하냐 하지만 거의 새로운 언어를 배워가는 느낌이다.

 

방법론부터 다시 차근차근.

 

프롬프트, 스킬보다 먼저 방법론에 대해 알아보자

Cot "chain of thought"+Self Consistency CoT 프롬프트의 출력에는 내용 오류가 포함되어 있지만 올바른 결론에 도달하고 모든 형태의 저작자 표시를 충족 zero샷 일 경우: 질문하고 let's think step by step문장

baksu-gi.tistory.com

 

효과적으로 프롬프트 작성하기

방법론에 대해 1차적으로 공부를 하고 난 뒤, DeepLearning.AI에서 강의를 듣기 시작했다.

오늘은 효과적인 프롬프트 쓰기를 위한 기본 규칙과 예시들을 정리해보려고 한다.

ps. 오역이 있을 수 있습니다아.
프롬프트는 영어로 입력하고 answer in korean이라고 추가하는 게 효과적으로 응답을 얻기 좋은 것 같습니다.

 

규칙 1: Write clear and specific instructions. 깔끔하게, 구체적인 지침을 적어라.

1. Use delimiters to clearly indicate distinct parts

#짧은 것과 명확한 것은 다르다. Delimiters(구분자)를 활용해 프롬프트와 입력될 내용을 분리시켜라.

 

Delimiters 예시 : ```, """, < >, <tag> </tag>, : 

Text =  You should express what you want providing instructions.....

 

PromptSummarize the txt delimited by into a single sentence. ‘’’{Text}’’’


2. Ask for a structed output (ex. JSON, HTML)

#출력될 결과에 대해 구체적으로 지시해라.

 

PromptGenerate a list of two made-up with their authors and genres.
Provide them in JSON format with bood_id, title, author, genre.

key: bood_id, title, author, genre

#만약 html코드로 작성하라고 한 결과를 바로 보려면
from IPython.display import display, HTML
display(HTML(response)) #response = GPT가 짜준 코드

3. Check whether conditions are satisfied

#프롬프트에 입력된 조건을 만족하는지 확인하기

 

Text1 =  Making a cup of tea is easy! You need get some...... And put......  #홍차 만들기 레시피(순서 있는 내용)

Text2 = “The sun is shining brightly today, and the birds are singing.   #날씨에 대한 서술(순서 없는 내용)

 

Prompt = You will be provided with text delimited by triple quotes. #입력될 내용 구분자로 표시 후 프롬프트에 명시

 

#만약 입력된 내용이 순서가 있는 내용이라면, 아래와 같은 포맷에 따라 출력할 것

If it contains a sequence of instructions,
re-write those instructions in the following format:
step 1 - …
step 2 - ,,,

......

 

#만약 입력된 내용에 순서가 없다면, "No steps provided."라고 출력할 것
If the text does not contain a sequence of instructions,
then simply write “No steps provided.”
“ ” ”{Text}” ” ”

<왼쪽>: 순서가 있는 문장이 입력됐을때 결과 <오른쪽>순서가 없는 문장이 들어왔을때 결과


규칙 2: Give the model time to think 챗 지피티가 생각할 시간을 줘라.

1. Specify the steps required to complete a task

#과제를 해결하기 위해 필요한 과정을 명확히 말해줘라.

 

Text = In a charming village, siblings Jack and Sam set out on a quest to fetch water from a hilltop well......

 #어느 마을에서 일어난 일에 대한 이야기

 

PromptPerform the following actions:

#이전 과정에서 나온 결과를 가지고 다음으로 갈 수 있도록 연결을 잘해야 한다.


1- Summarize the following text delimited by triple backticks with 1 sentence.

#구분자(‘’’ )로 입력된 내용을 한 문장으로 요약해라

 

2 - Translate the summary into French

#the summary (step1에서 요약한 내용)를 프랑스어로 번역해라

 

3 – List each name in the French summary.

#the French summary (step1에서 요약본을 step2에서 프랑스어로 번역한 내용)에서 등장인물을 말해라.

 

4 - Output a json object that contains the following keys: french_summary, num_names.

# 최종 결과물을 keys: french_summary, num_names. 인 JSON형태로 출력해라


Separate your answers with line breaks. #각 단계에 따른 답은 줄 바꿈으로 구분해라.
Text: ‘’’ {Text} ‘’’


2. Instruct the model to work out its own solution
before rushing to a conclusion.

#주어진 정보로만 급하게 결론 내리지 않고, 모델이 스스로 생각해서 결론을 내리게 만들어라.

 

틀린 정보를 그럴듯하게 적어놓으면 "Generated Knowledge Prompting" 때문에 주어진 정보가 옳다고 생각해

잘못된 결론을 내린다.

 

아래의 두 예시는 모두 학생이 틀린 답을 그럴듯한 설명과 함께 입력했을 때이다.

프롬프트에 따라 결과가 어떻게 바뀌는지 비교해 보자.

 

1. 학생의 답과 설명만 입력한 뒤 평가하라고 했을 때 : 틀린 답을 옳다고 잘못 판단함

 

2. 챗 지피티에게 스스로 생각한 뒤 단계를 거쳐 평가하라고 했을 때: 답이 틀렸다고 옳게 판단함

PromptYour task it to determine if the student’s solution is correct of not.
To solve the problem do the following:


- First, work out your own solution to the problem. #
먼저 GPT스스로 답을 만들고
- Then compare your solution to the student's solution and evaluate if the student's solution is correct or not.

#주어진 답과 비교해서 정답인지 평가
Don't decide if the student's solution is correct until you have done the problem yourself.
#
스스로 결론을 내리기 전까지 주어진 답에 영향받지 않도록 제어

#결과는 지정한 포맷에 맞게 출력하도록 제한

Use the following format:
Question:
```
question here
```
Student's solution:
```
student's solution here
```
Actual solution:
```
steps to work out the solution and your solution here
```
Is the student's solution the same as actual solution just calculated:

```
yes or no
```
Student grade:
```
correct or incorrect
```


느낀 점

기본규칙 두 가지에 대해 알아봤다.

규칙 1: Write clear and specific instructions. 깔끔하게, 구체적인 지침을 적어라.

규칙 2: Give the model time to think 챗 지피티가 생각할 시간을 줘라.

 

번외 같은 이야기가 될 것 같지만 영어 공부할 때도 전치사 하나만 잘못 써서 완전히 다른 문장을 만들어내는

경우가 많다. 챗 지피티에게 문장을 입력할 때도 같은 맥락인 것 같다.

올바른 문장과 명확한 지침이 생각지도 못한 되게 괜찮은 결과를 내는데 분명 도움이 된다고 생각한다.

아직도 공부할게 많다 많아.