본문 바로가기

practical AI/ChatGPT

[chatGPT Prompting] Prompting basics 프롬프트 작성법

[chatGPT Prompting] Prompting basics

프롬프팅의 가장 기본적인 내용들을 정리하였다.

prompting?

AI에게 일을 지시하는 일련의 과정

AI에게 프롬프트(지시)를 제공하여 AI가 일하게 한다.

프롬프트는 간단하게는 하나의 문장, 복잡하게는 여러 줄의 문단이 될 수 있다.

프롬프트를 통해 우리는 뉴스 기사 요약이나, 수학 문제를 해결할 수 있다. 그러나 같은 문제더라도 어떤 프롬프트를 사용하느냐에 따라 chatGPT의 답변이 달라진다.

예를 들어서

What is 965*590?

라는 프롬프트를 사용하면 틀린 정답을 말하지만,

Make sure your answer is exactly correct. What is 965*590? Make sure your answer is exactly correct:

라는 프롬프트를 사용하면 정답을 알려준다.


프롬프트 작성 방식

1. 지시하기

가장 쉬운 프롬프트 방법 중 하나.

일반적으로 사용하는 방식

2. 역할 프롬프팅

AI에게 역할을 부여하는 것

# AI 너는 수학자야
You are a brilliant mathematician who can solve any problem in the world.
Attempt to solve the following problem:

What is 100*100/400*56?

// highlight-start
The answer is 1400.
// highlight-end

# AI 너는 미친놈이야
I want you to act as a lunatic. 
The lunatic's sentences are meaningless. 
The words used by lunatic are completely arbitrary. 
The lunatic does not make logical sentences in any way.
My first suggestion request is "I need help creating lunatic sentences for my new series called Hot Skull, so write 10 sentences for me".

3. 퓨삿 프롬프팅 (few shot prompting)

https://learnprompting.org/ko/docs/basics/few_shot

  • 모델에 원하는 작업의 몇가지 예시(shot)를 구조화하여 제시함
  • 모델에게 설명하기 어려운 특별한 방법으로 구조화된 출력을 요구할 때 사용
  • 출력 포멧을 제공하여 ai가 일관성 있는 출력을 제공할 수 있도록 함
  • 종류
    • 제로 샷 프롬프팅: 모델에게 예제를 제공하지 않음
    • 원 샷 프롬프팅: 모델에게 1개의 예제를 제공
    • 퓨 샷 프롬프팅: 모델에게 2개 이상의 예제를 제공
종류 예시
제로 샷 프롬프팅 Add 2+2:
원 샷 프롬프팅 Add 3+3:6 Add 2+2:
퓨 샷 프롬프팅 Add 3+1:4 Add 3+3:6 Add 2+2:

지시하기, 역할프롬프팅, 퓨삿 프롬프팅 융합하기

https://learnprompting.org/ko/docs/basics/combining_techniques

세 가지를 융합하여 더 강력한 프롬프트를 만들 수 있다.

특히 맥락과 예시를 추가하면 AI의 성능을 개선시킬 수 있다.

Twitter is a social media platform where users can post short messages called "tweets".
Tweets can be positive or negative, and we would like to be able to classify tweets as
positive or negative. Here are some examples of positive and negative tweets. Make sure
to classify the last tweet correctly.

Q: Tweet: "What a beautiful day!"
Is this tweet positive or negative?

A: positive

Q: Tweet: "I hate this class"
Is this tweet positive or negative?

A: negative

Q: Tweet: "I love pockets on jeans"

A:

프롬프트 공식

위에서 공부한 프롬프트 작성방식들을 기반으로 프롬프트의 구성을 공식화하면 다음과 같이 표현할 수 있다.

  • 역할(role)
  • 지시(instruction/task)
  • 질문(question)
  • 문맥(Context)
  • 예시(few shot)

이 요소들이 프롬프트에 반드시 들어가야 하는 것은 아니며 또한 요소들의 순서도 상관없다.

그러나 일반적으로 '지시'를 마지막에 적는 형태가 더 선호된다. LLM의 특성상 잘못된 답변을 할 확률이 더 낮아지기 때문이다.

표준 프롬프트

각 프롬프트 유형에 대한 표준화된 사례가 있다.

# 표준 프롬프트
What is the capital of France?

# QA 포멧의 표준 프롬프트
Q: What is the capital of France?

A:

#퓨샷 표준 프롬프트
What is the capital of Spain?
Madrid
What is the capital of Italy?
Rome
What is the capital of France?

# 퓨샷 QA 표준 프롬프트
Q: What is the capital of Spain?
A: Madrid
Q: What is the capital of Italy?
A: Rome
Q: What is the capital of France?
A:

References

[🟢 프롬프팅 | Learn Prompting: Your Guide to Communicating with AI

이전 챕터에서 우리는 AI에 대해서 또 어떻게 AI에게 일을 지시할 지에 대해서 얘기했었습니다.

learnprompting.org](https://learnprompting.org/ko/docs/basics/prompting)