Prompt Engineering의 정의와 중요성
ChatGPT의 출시 이후 많은 산업군에서 대격변이 일어났다고 해도 과언이 아니다.
특히 제가 포함되어 있는 개발직군에도 많은 사람들이 ChatGPT를 이용해 업무를 진행하고,
더 나아가 ChatGPT를 활용한 서비스를 개발해 많은 스타트업들이 사업을 진행하고 있다.
ChatGPT를 활용한 서비스는 결국 프롬프트 엔지니어링이 핵심이고 프롬프트 엔지니어들의 연봉이 화제가 되기도 했다.
프롬프트 엔지니어링이 과연 무엇이고, 어떻게 ChatGPT를 잘 활용할 수 있는지 알아보자.
프롬프트 엔지니어링(Prompt Engineering)은 ChatGPT, LLaMa 등 대규모 언어모델, 즉 LLM의 성능을 최대화하기 위해 프롬프트 설계와 최적화를 연구하는 기술 분야이다. 여기서 프롬프트란 LLM에게 주어지는 입력 값이다. 다시 말해 AI가 자연어로 주어진 지시사항을 이해하고 정확, 효율적인 작업을 수행하도록 프롬프트를 설계하여 사용자가 기대하는 결과를 생성하도록 유도하는 것이다.
프롬프트 엔지니어링의 핵심을 정리하면 다음과 같다.
- 핵심 목표: 모델의 정확도와 일관성을 높이고 원하는 결과를 효율적으로 얻는 것
- 사용 분야: 텍스트 생성, 번역, 데이터 요약, 질의응답, 코드 생성
프롬프트의 주요 구성 요소
Prompt Engineering의 기본원칙은 다음과 같다.
- 명확성: 프롬프트는 작업을 명확하고 간결하게 설명해야 한다.
- 구체성: 구체적인 지침으로 AI가 불필요한 해석을 하지 않도록 유도한다.
- 컨텍스트 제공: 맥락을 정확히 설명해 모델의 응답 품질을 높인다.
위 원칙에 기반하여 프롬프트를 효과적으로 만들기 위해 다음 요소들을 포함해야 한다.
- 지시(Instruction): 모델이 수행해야 할 작업 특정하기.
- ex) 다음 문장을 간단히 요약해줘.
- 문맥(Context): 모델의 이해를 돕는 추가정보
- ex) 중학생 수준의 영어실력으로 다음 문장을 번역해줘.
- 입력 데이터(Input data): 답변을 얻고자 하는 사항에 대한 입력 값
- ex) 다음 문장에 대해 번역해줘. Input: "I'm supposed to study at 7"
- 출력 형식(Output Format): 결과물의 타입이나 형식을 지정
- ex) JSON format으로 답변을 생성해줘
아래는 프롬프트의 한 예시이다.
Classify the text into neutral, negative, or positive
Text: I think the food was okay.
Sentiment:
"Classify the text into neutral, negative, or positive"가 instruction으로 텍스트에 대한 classification 작업을 요구한다.
"Text: I think the food was okay"가 input data로 답변을 얻고자 하는 입력 값이다.
"Sentimet:"가 output format이 된다.
프롬프트의 설계 방법
단순하게 시작, Instruction 주기
#Prompt
### Instruction ###
Translate the text below to Spanish:
Text: "hello!"
#Output
¡Hola!
모델의 동작을 명세화 하기.
# Prompt
Extract the name of places in the following text.
Desired format:
Place: <comma_separated_list_of_places>
Input: "Although these developments are encouraging to researchers, much is still a mystery.
“We often have a black box between the brain and the effect we see in the periphery,” says Henrique Veiga-Fernandes,
a neuroimmunologist at the Champalimaud Centre for the Unknown in Lisbon.
“If we want to use it in the therapeutic context, we actually need to understand the mechanism.“"
# Output
Place: Champalimaud Centre for the Unknown, Lisbon
Instruction을 준 이후에는 해당 instruction의 수행 결과에 대해 명세화 한다.
위 예제에서는 output format을 명세화하여 지정된 형태의 output을 출력했다.
모호한 표현 피하기
# Imprecise Prompt
Explain the concept prompt engineering. Keep the explanation short, only a few sentences, and don't be too descriptive.
# Better Prompt
Use 2-3 sentences to explain the concept of prompt engineering to a high school student.
수치화 되지 않은 애매모호한 지시(few senteces)를 하지 않고 정확한 요구사항(2-3 sentences)을 프롬프트에 포함시킨다.
Not To Do 대신 To Do
하지 말아야 할 일을 말하지 말고 해야 할 일을 말해야 한다.
# Prompt of Not TO-DO
The following is an agent that recommends movies to a customer.
DO NOT ASK FOR INTERESTS. DO NOT ASK FOR PERSONAL INFORMATION.
Customer: Please recommend a movie based on my interests.
Agent:
# Output
Sure, I can recommend a movie based on your interests. What kind of movie would you like to watch? Do you prefer action, comedy, romance, or something else?
위는 Not TO-DO, 하지말아야 할 사항을 프롬프트로 줬음에도 불구하고 원하는 답변을 얻지 못했다.
# TO-DO Prompt
The following is an agent that recommends movies to a customer.
The agent is responsible to recommend a movie from the top global trending movies.
It should refrain from asking users for their preferences and avoid asking for personal information.
If the agent doesn't have a movie to recommend, it should respond "Sorry, couldn't find a movie to recommend today.".
Customer: Please recommend a movie based on my interests.
Agent:
# Output
Sorry, I don't have any information about your interests. However, here's a list of the top global trending movies right now: [list of movies].
I hope you find something you like!
상황에 따른 해야 할 일을 명확히 제시하는게 더 나은 프롬프트이다.