굉장히 오랜만이네요.
바빠서 늦었다기 보단, 그냥 게을러서겠죠!
각설하고 시작하겠습니다.
저번 포스트에선 프롬프트 엔지니어링에 대해 알아봤는데요.
이번엔 프롬프트 엔지니어링 테크닉에 대해 알아보겠습니다.
본문은 카카오 엔터프라이즈에서 기술인사이트파트의 '[IT TREND] 프롬프트 엔지니어링, AI라는 도구를 잘 사용하는 방법'을 참고하여 작성하였습니다.
프롬프트에 대한 대답 결과는 meta의 llama2 모델 기반의 HuggingChat에서 실행한 결과입니다.
시작 하기 앞서 아래의 기법들은 대표적인 기법을 설명한 것이고, 이밖에도 다양하고 심화적인 기법이 존재합니다.
추가적으로 궁금하다면 구글링을..!
추가 학습 또는 예제 데이터 없이 답변을 생성하게 하는 기법으로, 거대 언어 모델에게 아무런 지시 없이 완수할 태스크를 주는 것을 의미합니다.
이러한 기법으로 AI 모델이 아무런 예제없이 자체적으로 대상을 인식하고 식별하는 과정을 거치게 하여 보다 다양하고 다이나믹한 텍스트 생성을 하는 모델을 만들 수 있다고 합니다.
Prompt:
Judge the positives and negatives of the following sentences.
Text: Today's weather is cloudy.
Sentiment:
Output:
Positive: Neutral
Negative: None
이정도의 간단한 프롬프트는 아무 예제가 없어도 쉽게 도출 합니다.
하지만 조금만 복잡해져도 원하지 않은 답변이 나올 확률이 커지겠죠.
하나의 예제 또는 템플릿를 기반으로 답변을 생성하게 하는 기법입니다.
Dialogue management, 또는 context modeling과 같은 기타 NLP 기법들과 조합되어 보다 정확한 답변을 유도할 수도 있다고 합니다.
Prompt:
'A' means small and cute.
Sentence using A: Rabbit is A.
B means big and rough.
Sentences using B:
Output:
Sure, here are some sentences using the letter B to describe big and rough things:
Bear is B.
Elephant is B.
Gorilla is B.
예시를 하나 제공하자, 그에 맞게 답변이 나오는 것을 확인할 수 있습니다.
그럼 여러 개의 예제를 준다면 더 복잡한 구성을 도출할 수 있을까요?
두개에서 다섯개의 예제를 바탕으로 답변을 생성하게 하는 기법으로, 프롬프트 앞단에 One-Shot Prompting 기법 보다 조금 더 AI에게 직접적으로 원하는 답변에 도달할 수 있도록 유도합니다.
최근 GPT 모델들은 아래 예시와 같이 레이블을 형식에 맞지 않게 랜덤하게 넣어도 올바르게 곧잘 답변합니다. Few-Shot Prompting프레임워크는 답변에 도달하기까지 몇 단계의 추가적인 추론 과정을 거쳐야하는 보다 복잡한 문제의 경우 풀 수 없다는 한계점을 가지고 있습니다.
Prompt:
The weather is so nice today.
: I'll define it as negative.
I'm in a bad mood today.
: I will define this as positive.
I love the clothes I bought yesterday
: negative
I got fired from the company.
:
Output:
Sure, here are the definitions you provided:
The weather is so nice today: Negative
I'm in a bad mood today: Positive
I love the clothes I bought yesterday: Negative
I got fired from the company: Positive
예제로 문장이 긍정적일 때는 'negative'를, 부정적일 때는 'positive'를 대답하는 것을 제공했습니다.
이에 AI 모델도 회사가 잘렸다는 문장에 'Positive'를 답함으로서 예제를 정확하게 이해했음을 알 수 있습니다.
실제로 한개의 예제만 했을 시 예제고 뭐시고 문장 그대로 해석하고 긍부정을 판단합니다.
그만큼 예제의 숫자가 무시할 수 없는 조건임을 알 수 있죠.
단지 답변을 내놓기 위한 것이 아닌, 답변에 도달하는 과정을 학습시키는 것을 목적으로 본 질문 전에 미리 태스크와 추론 과정을 포함한 답변 예제를 AI에게 제공하는 기법입니다.
예제를 더 많이 기입할 수록 정확도가 높아지겠지만 아래 예시를 보면 예제를 하나만 넣어주어도 정답을 제공하는 것을 보실 수 있습니다.
Prompt:
The following sequence of numbers does not exceed 20 by any addition.
2, 1, 12, 4, 2, 6
Answer: If you add 12, 4, and 6, it becomes 22, so it's wrong
The following sequence of numbers does not exceed 20 by any addition.
1, 2, 3, 4, 5, 6
Answer:
Output:
The sum of the given sequence is 21, which exceeds 20. Therefore, this sequence does not satisfy the condition.
이유까지 설명하며 정확하게 답변을 도출합니다. 이는 수학적 추론 예시가 성공적으로 작용했다는 것이죠.
만약 예제까지 여러 개 제공한다면, 더 복잡한 추론 과정도 가능할 것 입니다.
비교적 최근에 등장한 트리거 문장 "Let's think step by step"을 프롬프트에 추가하여 거대 언어 모델이 단계에 따라 결과에 도달하게 하는 기법입니다.
한국어로는 '단계별로 차근차근 생각해보자' 정도가 되겠네요.
이렇게 별거 아닌 것 같은 문장 하나만 추가했을 뿐인데, 상세한 답변 도출 및 추론 과정을 받아볼 수 있습니다.
Prompt:
The following sequence of numbers does not exceed 20 by any addition.
2, 1, 12, 4, 2, 6
Let's think step by step
Answer:
Output:
Sure! Here's a step-by-step explanation of why the given sequence of numbers does not exceed 20 by any addition:
Start with the first number: 2
Add the second number: 1 + 2 = 3
Add the third number: 3 + 12 = 15
Add the fourth number: 15 + 4 = 19
Add the fifth number: 19 + 2 = 21
As we can see, the sum of the five numbers is 21, which exceeds 20. Therefore, the given sequence of numbers does not meet the condition of not exceeding 20 by any addition.
어떤가요? 차이가 느껴지시나요?
바로 전 예제인 CoT기법에서는 수학적 추론을 하긴 했지만 이렇게 상세하진 않았습니다.
이번 예제에서는 모든 경우를 보여주며 예외가 있다는 것까지 도출했습니다.
CoT의 심화버전으로, 보다 다양한 추론 과정을 예제로 제공하여 AI가 보다 일관성 있는 답변을 선택하여 생성할 수 있도록 돕는 기법입니다.
기존에 CoT와의 차이점은 수학적 그리고 상식적인 추론이 요구되는 태스크 수행 능력이 향상되었다는 점이라고 합니다.
Prompt:
Q: I have a 30-year-old brother who is 6 years older and a 21-year-old brother who is 3 years younger. How old am I?
A: I said 30 years old, 6 years older, so I'm 24 years old because it's 30-6=24.
With the same logic, it is 21+3=24, so you can see that you are 24 years old.
Q: I am playing soccer. I lost because my opponent scored 3 goals in the middle of winning 2-1. What's the final score?
A: The final score is 2-4, as the opposing team scored three more goals with one point, it is 1+3=4.
Q: I am 10cm shorter than Jihoon, who is 184cm tall, and 21cm taller than Jimin, who is 153cm tall. How tall am I?
A:
Output:
A: You are 174cm tall.
Here's how we can calculate your height:
Jihoon's height is 184cm, and you are 10cm shorter, so your height is 184 - 10 = 174 cm.
Jimin's height is 153cm, and you are 21cm taller, so your height is 153 + 21 = 174 cm.
Since both calculations give us the same result, 174 cm, that is your height.
이번 예제는 크게 차이점을 느끼진 못하셨을 것 같습니다.
바로 전 예제의 답변도 훌륭한 이유도 있지만, 문제의 난이도 자체가 쉬운 편이고, 예제의 개수를 늘리는 것은 답변의 추론의 정도를 늘린다기 보다는 옳바른 추론을 하는 확률을 높히는 장치이기 때문이라고 생각합니다. (개인적인 의견입니다.)
그렇다면 예제말고 정보를 직접 제공하는 건 어떨까요?
모델이 보다 정확한 답변을 산출해 내기 위해 지식이나 정보를 통합할 수 있도록 질문과 함께 관련 지식이나 정보를 함께 제공하는 기법입니다.
이와 같은 기법으로 기존 모델의 유연성은 유지하면서 상식 추론 능력을 향상시킬 수 있다고 합니다.
Prompt:
Question: Can we make elements heavier than elemental uranium in their natural state?
Knowledge: German chemists O. Hahn (1879-1968) and F. Strassmann (1902-1980) discovered that the atomic weight of uranium becomes almost half-barium (Ba) when it impacts neutrons (atomic nuclei with protons and elementary particles of almost the same mass as the atomic nucleus).
Before that, I thought it would be a transuranium element with an atomic number of 93 or higher.
Explain and answer:
Output:
The statement you provided suggests that the German chemists Otto Hahn and Fritz Strassmann discovered that uranium can undergo nuclear fission,
a process in which the atom splits into two or more smaller atoms,
releasing a large amount of energy in the process.
This discovery led to the development of nuclear reactors and weapons.
However, this does not directly address the question of whether elements heavier than uranium can be created in their natural state.
While it is possible to create synthetic elements heavier than uranium through nuclear fusion or other means,
there are currently no known natural processes that produce elements heavier than uranium in their pure form.
Uranium is the heaviest naturally occurring element,
and all elements heavier than uranium are radioactive and have shorter half-lives.
Therefore, the answer to the question is no;
it is not currently possible to create elements heavier than uranium in their natural state.
However, researchers continue to explore new ways to create synthetic elements and extend the periodic table beyond its current limits.
최근, 영화 '오펜하이머'를 굉장히 재밌게 봐서 정말 개인적으로 궁금한 것을 질문했습니다.
요약하자면 '우라늄보다 무거운 원소가 자연상태로 존재하나?'를 질문했고, 정보로는 '과거에 우라늄에 중성자를 쏴 핵분열을 발견한 실험'을 제공했습니다.
물론 질문과는 살짝 핀트가 맞지 않은 정보였지만 역시나 AI 모델은 이 점을 정확히 캐치하였습니다.
제가 제공한 정보를 설명함과 동시에 질문과는 관련이 없다고 지적을 해주었고, 제가 물은 답변에한 답도 해주었습니다.
정말 대표적으로 알려진 기법만 다루다 보니 포스트가 그렇게 길지 않네요.
그만큼 생성형 AI 모델을 사용할 때 한번 쯤은 활용할 만한 테크닉이란 말이겠죠?
읽어보시면 아시겠지만 사용하기에 복잡하거나 이해하기 어려운 정도는 없다고 생각합니다.
크게 어려운 내용은 없으니 프롬프트를 작성할 때 위 기법들을 한번 활용하여 원하는 결과를 도출해보세요!