Meta Prompting
Meta Prompting은 문제 해결 과정의 구조와 형식에 초점을 맞추는 기법이다.
구체적인 콘텐츠 (수치, 예제) 대신 문제의 양식, 해결 단계를 추상화해서 제시함으로써 모델이 형식을 우선적으로 인식하도록 유도한다.
Meta Prompting의 특징은 다음과 같다.
- Structure-Oriented: 문제 내용이 아니라 해결 과정의 문서 구조(문제 설명, 해결 단계, 최종 답)과 같은 형식에 집중한다.
- Syntax-Focused: 답변이 어떤 문법과 템플릿을 따라야 하는지 강조한다.
- Abstract Examples: 일반화된 예시를 통해, 특정 예시가 아닌 '이런 식으로 문제를 분석한다'라는 큰 틀을 보여준다.
- Versatile : 구체적인 예시 없이 형식을 공통적으로 제시하기 때문에 다양한 도메인에 적용 가능하다.
Few-Shot Prompting과의 차이점은 다음과 같다.
- Meta Prompting은 few-shot 처럼 '문제 해결을 위한 구체적인 예제' 대신 '문제와 해답의 구조'를 지정한다.
- 구체 사례 대신 추상적 템플릿을 강조함으로써 "일정한 형식에 대한 문제풀이"를 모델이 학습할 수 있다.
- 따라서 특정 예시에 대한 편향성을 배제하여 fair comparison이 가능하며, 토큰 절약이 가능하다.
Meta Prompting은 수학 문제, 코딩 문제, 이론적 쿼리 등이 유용하게 작용할 수 있다.
Self-Consistency
Self-Consistency는 Chain of Thought(CoT)의 추론 경로를 여러번 샘플링해서 가장 빈도가 높은 결과를 최종적으로 채택하는 방식이다. 즉, 한번의 CoT 추론 결과가 틀릴 수 있으므로 다양한 랜덤 시드나 샘플링 방식을 통해 여러개의 CoT 해석을 얻고 그 중 일관된 답을 최종 정답으로 하는 것이다.
예를 들어 다음과 같은 arithmetic reasoning 문제에 대한 프롬프트와 결과를 살펴보자.
# Prompt
Sam had 10 socks.If he threw away 3 old ones that didn’t
fit and bought 36 new ones, how many socks would he have?
# Output
Sam had 10 socks. He threw away 3 old ones that didn’t fit.
He bought 36 new ones. That means he has 10 + 36 - 3 = 41 socks.
The answer is 41.
단순 CoT 결과가 오답을 내는 경우가 발생한다. (정답은 43)
하지만 Self Consistency를 통해 여러 개의 답을 생성해보면 다음과 같이 정답을 맞춘 결과가 발생한다.
# Sampled Path 1
Sam had 10 socks. He threw away 3 old ones.
So now he has 7 left. Then he bought 36 new ones.
So now he has 7 + 36 = 43 socks.
The answer is 43.
# Sampled Path 2
He had 10 socks. He threw away 3 old ones that didn’t fit.
He bought 36 new ones. So in total he has 10 - 3 + 36 = 43 socks.
The answer is 43.
기존의 Output 1개와 추가로 sampling한 2개의 답변을 보았을 때 정답이 43인 답변이 더 많으므로 모델이 많이 확신하는 답이라고 할 수 있다. 이렇게 틀린 답을 한번 도출했다고 해서 오류가 확정되지 않도록 해준다.
즉 GPT의 답변은 임의적은 토큰 샘플링을 통해 어느정도 랜덤성을 가지게 되며, 이로 인해 한번씩 잘못된 답이 나오는 경우가 있다.
이를 방지하기 위해 여러번의 Few-shot CoT, Zero-shot CoT 과정을 통해 답변을 여러개 생성하는 "다중 추론"을 시행한 후 voting을 통해 신뢰성있는 답변을 획득할 수 있는 것이 Self-Consistency이다.
Generate Knowledge Prompting
Generate Knowledge Prompting은 모델이 필요한 지식을 사전에 직접 생성하게 하여, 그 지식을 다시 추론에 활용하도록 하는 접근이다. 즉 질문에 답하기 전에 관련된 배경지식을 한 두 문장으로 뽑아낸 뒤 본격적인 답변을 하라고 지시하는 프롬프트 기법이다.
어떤 문제들은 모델이 내재적으로 알고 있을 법한 지식이 있어도 이를 즉각적으로 활성화하지 못해 부정확한 답변을 한다.
예를 들어 골프의 점수 규칙 "타수가 낮아야 승리한다"는 모델이 이미 알고있는 지식이라고 할 수 있다.
따라서 이러한 지식을 모델이 직접 생성하도록 유도한 뒤 해당 지식을 다시 확인하여 답을 도출하면 오류가 줄어들게 된다.
# Prompt
Part of golf is trying to get a higher point total than others. Yes or No?
# Output
Yes.
이 처럼 모델이 골프 규칙을 알고있는 지식임에도 불구하고 올바르지 않은 답을 낸다.
따라서 프롬프트에 knowledge를 생성하도록 유도한다.
Generate some knowledge about the input. Examples:
Input: Greece is larger than mexico.
Knowledge: Greece is approximately 131,957 sq km, while Mexico is approximately 1,964,375
sq km, making Mexico 1,389% larger than Greece.
Input: Glasses always fog up.
Knowledge: Condensation occurs on eyeglass lenses when water vapor from your sweat, breath,
and ambient humidity lands on a cold surface, cools, and then changes into tiny drops of liquid,
forming a film that you see as fog. Your lenses will be relatively cool compared to your breath,
especially when the outside air is cold.
Input: A fish is capable of thinking.
Knowledge: Fish are more intelligent than they appear. In many areas, such as memory, their
cognitive powers match or exceed those of ’higher’ vertebrates including non-human primates.
Fish’s long-term memories help them keep track of complex social relationships.
Input: A common effect of smoking lots of cigarettes in one’s lifetime is a higher than
normal chance of getting lung cancer.
Knowledge: Those who consistently averaged less than one cigarette per day over their lifetime
had nine times the risk of dying from lung cancer than never smokers. Among people who smoked
between one and 10 cigarettes per day, the risk of dying from lung cancer was nearly 12 times
higher than that of never smokers.
Input: A rock is the same size as a pebble.
Knowledge: A pebble is a clast of rock with a particle size of 4 to 64 millimetres based on the
Udden-Wentworth scale of sedimentology. Pebbles are generally considered larger than granules
(2 to 4 millimetres diameter) and smaller than cobbles (64 to 256 millimetres diameter).
Input: Part of golf is trying to get a higher point total than others.
Knowledge:
이런 식으로 Input에 대한 knowledge를 생성하는 few-shot prompt를 작성한뒤, 마지막에 실제 물어보고자 하는 질문에 대한 knowledge 생성을 요구한다. 그러면 다음과 같은 답변을 생성할 수 있다.
The objective of golf is to play a set of holes in the least number of strokes.
A round of golf typically consists of 18 holes.
Each hole is played once in the round on a standard golf course.
Each stroke is counted as one point, and the total number of strokes is used to determine the winner of the game.
이렇게 골프에 대한 지식을 생성한 뒤, 원래 QA format에 해당 Knowledge를 프롬프트에 포함시켜 답변에 대한 가이드를 주는 것이다.
Question: Part of golf is trying to get a higher point total than others. Yes or No?
Knowledge: The objective of golf is to play a set of holes in the least number of strokes.
A round of golf typically consists of 18 holes.
Each hole is played once in the round on a standard golf course.
Each stroke is counted as one point, and the total number of strokes is used to determine the winner of the game.
Explain and Answer:
그러면 LLM이 해당 knowledge를 기반으로 답변과 그 이유를 생성해내는 것을 확인할 수 있다.
No, the objective of golf is not to get a higher point total than others.
Rather, the objective is to play a set of holes in the least number of strokes.
The total number of strokes is used to determine the winner of the game, not the total number of points.
결론
- Meta Prompting은 문제 해결 과정의 틀(Structure)을 정의해, 특정 예시에 의존하지 않는 추상적이고 범용적인 접근을 가능케 한다.
- Self-Consistency는 모델의 추론 경로를 여러 번 살펴보고, 다수결이나 일관된 답을 선택해 답변 안정성을 강화한다.
- Generate Knowledge Prompting은 필요한 지식을 사전에 모델에게 직접 생성하게 하여, 잘못된 상식이나 지식 부족 때문에 생기는 오류를 줄여준다.
이 세 기법은 각각 목적과 특징이 다르지만, 모두 CoT나 Few-shot 같은 기존 프롬프트 엔지니어링 방식과 유기적으로 결합될 수 있다.
- 좀 더 복잡한 문제 또는 사전 지식이 중요한 과제일수록, Meta Prompting과 Generate Knowledge Prompting을 사용해 모델이 문제 접근 방식을 구조화하고 배경지식을 활성화하도록 돕는다.
- Self-Consistency로 최종 답을 결정함으로써, 모델이 단일 추론 경로에서 발생할 수 있는 실수를 완화한다.
앞으로 LLM들이 더욱 정교해짐에 따라, 이러한 고급 프롬프트 엔지니어링 기법들은 모델의 최대 잠재력을 끌어내는 핵심 요소로 자리 잡을 것으로 보인다.