OpenAI의 GPT 모범 사례: 전략4. GPT 모델에게 "생각할" 시간 주기 / Strategy: Give GPTs time to "think"

시작하기 전에 - GPT 모범 사례 문서 개요

image

OpenAI의 GPT 모범 사례 문서는 GPT 모델로부터 더 나은 답변을 얻기 위한 6가지 전략(starategy)들과 함께 각 전략별 세부 전술들을 소개하고 있습니다.

이 게시글은 그 중 두번째 전략인 참고 문헌 제공하기 (Provide reference text) 를 소개하겠습니다. :smiley:

전체 GPT 모범 사례에 대한 설명이 궁금하신 분들께서는 아래 목차를 참고해주세요!

https://platform.openai.com/docs/guides/gpt-best-practices/gpt-best-practices


전략 4. GPT 모델에게 "생각할" 시간 주기 / Strategy: Give GPTs time to "think"

세부 전술: 결론을 재촉하기 전에 모델 스스로 해결책을 찾도록 하기 / Tactic: Instruct the model to work out its own solution before rushing to a conclusion

때로는 GPT 모델이 초기 지침으로부터 결과에 이르기까지, 어떻게 추론을 할지를 명시적으로 지시할 때 더 나은 결과를 얻을 수 있습니다. 수학 문제에 대한 학생의 답을 평가하는 모델을 만든다고 가정해보겠습니다. 이 문제에 대한 가장 확실한 접근 방법은 GPT 모델에게 학생의 답이 맞았는지 여부를 묻는 것입니다.

Sometimes we get better results when we explicitly instruct the model to reason from first principles before coming to a conclusion. Suppose for example we want a model to evaluate a student's solution to a math problem. The most obvious way to approach this is to simply ask the model if the student's solution is correct or not.

시스템 메시지(SYSTEM)

학생의 답이 맞았는지 여부를 판단해주세요.
> Determine if the student's solution is correct or not.

사용자 메시지(USER)

문제 설명: 태양광 발전 설비를 설치 중에 재정 문제를 해결이 필요합니다.
- 토지는 평방피트당 $100입니다.
- 태양광 패널은 평방피트당 $250에 구매 가능합니다.
- 협상을 통해 연간 10만 달러의 고정비용과 평방피트당 $10 달러의 유지보수 계약을 체결했습니다.

첫 해에 평방피트당 운영에 필요한 비용은 총 얼마인가요?

학생 풀이: 설치에 필요한 평방피트를 x라고 뒀을 때,
1. 토지 비용: 100x
2. 태양광 패널 비용: 250x
3. 유지보수 비용: 100,000 + 100x

전체 비용: 100x + 250x + 100,000 + 100x = 450x + 100,000

> Problem Statement: I'm building a solar power installation and I need help working out the financials.
> - Land costs $100 / square foot
> - I can buy solar panels for $250 / square foot
> - I negotiated a contract for maintenance that will cost me a flat $100k per year, and an additional $10 / square foot
>
> What is the total cost for the first year of operations as a function of the number of square feet.
>
> Student's Solution: Let x be the size of the installation in square feet.
> 1. Land cost: 100x
> 2. Solar panel cost: 250x
> 3. Maintenance cost: 100,000 + 100x
>
> Total cost: 100x + 250x + 100,000 + 100x = 450x + 100,000

어시스턴트 메시지(ASSISTANT)

학생의 답이 맞았습니다.
> The student's solution is correct.

위 대화를 실행해보기 / Open in Playground

하지만 학생의 답은 정답이 아닙니다! 이 때, GPT 모델로 하여금 자체적인 답을 먼저 생성하도록 만들게 하면 성공적으로 진행할 수 있습니다.

But the student's solution is actually not correct! We can get the model to successfully notice this by prompting the model to generate its own solution first.

시스템 메시지(SYSTEM)

먼저 이 문제에 대한 자체 답변을 찾아보세요. 그러고 나서 그 답변을 학생의 답변과 비교하고 학생의 풀이가 맞았는지 아닌지를 평가해주세요. 문제를 직접 풀기 전에는 학생의 답변이 맞았는지 여부를 판단하지 말아주세요.
> First work out your own solution to the problem. 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.

사용자 메시지(USER)

문제 설명: 태양광 발전 설비를 설치 중에 재정 문제를 해결이 필요합니다.
- 토지는 평방피트당 $100입니다.
- 태양광 패널은 평방피트당 $250에 구매 가능합니다.
- 협상을 통해 연간 10만 달러의 고정비용과 평방피트당 $10 달러의 유지보수 계약을 체결했습니다.

첫 해에 평방피트당 운영에 필요한 비용은 총 얼마인가요?

학생 풀이: 설치에 필요한 평방피트를 x라고 뒀을 때,
1. 토지 비용: 100x
2. 태양광 패널 비용: 250x
3. 유지보수 비용: 100,000 + 100x

전체 비용: 100x + 250x + 100,000 + 100x = 450x + 100,000

> Problem Statement: I'm building a solar power installation and I need help working out the financials.
> - Land costs $100 / square foot
> - I can buy solar panels for $250 / square foot
> - I negotiated a contract for maintenance that will cost me a flat $100k per year, and an additional $10 / square foot
>
> What is the total cost for the first year of operations as a function of the number of square feet.
>
> Student's Solution: Let x be the size of the installation in square feet.
> 1. Land cost: 100x
> 2. Solar panel cost: 250x
> 3. Maintenance cost: 100,000 + 100x
>
> Total cost: 100x + 250x + 100,000 + 100x = 450x + 100,000

어시스턴트 메시지(ASSISTANT)

설치에 필요한 평방피트를 x라고 뒀을 때,
1. 토지 비용: 100x
2. 태양광 패널 비용: 250x
3. 유지보수 비용: 100,000 + 10x

전체 비용: 100x + 250x + 100,000 + 10x = 360x + 100,000

학생의 풀이가 틀렸습니다. 유지 관리 비용 계산에서 10배 대신 100배를 사용하여 오류를 범했습니다. 운영 첫해의 올바른 총 비용은 360x + 100,000입니다.

> Let x be the size of the installation in square feet.
> 1. Land cost: 100x
> 2. Solar panel cost: 250x
> 3. Maintenance cost: 100,000 + 10x
>
> Total cost: 100x + 250x + 100,000 + 10x = 360x + 100,000
>
> The student's solution is incorrect. They made an error in the maintenance cost calculation, using 100x instead of 10x. The correct total cost for the first year of operations is 360x + 100,000.

위 대화를 실행해보기 / Open in Playground

세부 전술: 모델의 추론 과정을 숨기기 위해 내면의 독백 또는 일련의 질의문을 사용하기 / Tactic: Use inner monologue or a sequence of queries to hide the model's reasoning process

직전의 전술은 때로는 GPT 모델이 질문에 답하기 전에 문제에 대해 자세히 추론하는 것이 중요하다는 것을 보여줍니다. 일부 응용 사례에서, GPT 모델이 최종 답변에 도달하기 위해 사용하는 추론 프로세스를 사용자와 공유하는 것은 부적절할 수 있습니다. 예를들어, 과외 어플리케이션에서는 학생이 스스로 답을 찾도록 장려하고 싶지만, 학생의 해답에 대한 모델의 추론 과정이 학생에게 정답을 알려줄 수 있습니다.

The previous tactic demonstrates that it is sometimes important for the model to reason in detail about a problem before answering a specific question. For some applications, the reasoning process that a model uses to arrive at a final answer would be inappropriate to share with the user. For example, in tutoring applications we may want to encourage students to work out their own answers, but a model's reasoning process about the student's solution could reveal the answer to the student.

내적 독백(inner monologue)은 이러한 문제를 완화하는 데 사용할 수 있는 전략입니다. 내적 독백의 개념은 사용자에게 숨겨야 하는 출력 일부를, 구문 분석이 용이한 구조화된 형식으로 변환하는 것을 모델에 지시하는 것입니다. 그런 다음 사용자에게 출력을 표시하기 전, 구문 분석하여 출력의 일부만 표시하도록 합니다.

Inner monologue is a tactic that can be used to mitigate this. The idea of inner monologue is to instruct the model to put parts of the output that are meant to be hidden from the user into a structured format that makes parsing them easy. Then before presenting the output to the user, the output is parsed and only part of the output is made visible.

시스템 메시지(SYSTEM)

다음 단계를 거쳐 사용자의 질의에 답변하세요.
1단계 - 먼저 문제에 대한 자신만의 해결책을 찾아보세요. 학생의 답은 틀릴 수 있으므로 참고하지 않습니다. 이 단계의 모든 작업은 따옴표 3개(""") 안에 넣으세요.
2단계 - 자신의 답과 학생의 답을 비교하고 학생의 답이 올바른지 평가합니다. 이 단계의 모든 작업들을 따옴표 3개(""")로 묶습니다.
3단계 - 학생이 실수한 경우 정답을 알려주지 않고 학생에게 어떤 힌트를 줄 수 있는지 결정합니다. 이 단계의 모든 작업들을 따옴표 3개(""")에 묶습니다.
4단계 - 학생이 실수한 경우 이전 단계의 힌트를 학생에게 제공합니다(따옴표 3개 바깥쪽의 내용). "4단계 - ..."라고 쓰는 대신 "힌트:"라고 씁니다.

> Follow these steps to answer the user queries.
> Step 1 - First work out your own solution to the problem. Don't rely on the student's solution since it may be incorrect. Enclose all your work for this step within triple quotes (""").
> Step 2 - Compare your solution to the student's solution and evaluate if the student's solution is correct or not. Enclose all your work for this step within triple quotes (""").
> Step 3 - If the student made a mistake, determine what hint you could give the student without giving away the answer. Enclose all your work for this step within triple quotes (""").
> Step 4 - If the student made a mistake, provide the hint from the previous step to the student (outside of triple quotes). Instead of writing "Step 4 - ..." write "Hint:".

사용자 메시지(USER)

문제 내용: <문제 내용을 여기에 넣습니다>
학생의 답변: <학생 답변을 여기에 넣습니다>

> Problem Statement: <insert problem statement>
> Student Solution: <insert student solution>

위 대화를 실행해보기 / Open in Playground

또는, 사용자에게 출력을 숨기는 마지막 부분을 제외한 일련의 쿼리들을 사용하여 이를 달성할 수도 있습니다.
먼저 모델이 스스로 문제를 해결하도록 요청할 수 있습니다. 초기 쿼리는 학생의 답변이 필요하지 않으므로 생략할 수 있습니다. 이렇게 하면 학생의 답변으로 인해 모델의 답변이 편향될 가능성이 없다는 추가적인 이점이 있습니다.

Alternatively, this can be achieved with a sequence of queries in which all except the last have their output hidden from the end user.
First, we can ask the model to solve the problem on its own. Since this initial query doesn't require the student's solution, it can be omitted. This provides the additional advantage that there is no chance that the model's solution will be biased by the student's attempted solution.

사용자 메시지(USER)

<문제 내용을 여기에 넣습니다>
> <insert problem statement>

위 대화를 실행해보기 / Open in Playground

다음으로, 모델이 사용 가능한 모든 정보를 사용하여 학생의 답이 정확한지 평가할 수 있습니다.

Next, we can have the model use all available information to assess the correctness of the student's solution.

시스템 메시지(SYSTEM)

답을 학생의 답과 비교하고 학생의 답이 올바른지 여부를 평가합니다.
> Compare your solution to the student's solution and evaluate if the student's solution is correct or not.

사용자 메시지(USER)

문제 내용: """<문제 내용을 여기에 넣습니다>"""
자신의 답: """<모델이 생성한 답변을 여기에 넣습니다>"""
학생의 답변: """<학생 답변을 여기에 넣습니다>"""

> Problem statement: """<insert problem statement>"""
> Your solution: """<insert model generated solution>"""
> Student's solution: """<insert student's solution>"""

위 대화를 실행해보기 / Open in Playground

마지막으로, 모델로 하여금 자신의 자체적인 분석을 사용하여 도움이 되는 튜터의 역할을 수행하여 답변을 구성할 수 있도록 합니다.

Finally, we can let the model use its own analysis to construct a reply in the persona of a helpful tutor.

시스템 메시지(SYSTEM)

당신은 수학 교사입니다. 학생이 실수를 하는 경우, 답을 공개하지 않는 방식으로 학생에게 힌트를 줄 수 있습니다. 학생이 실수를 하지 않은 경우, 단순히 격려의 말을 건네면 됩니다.
> You are a math tutor. If the student made an error, offer a hint to the student in a way that does not reveal the answer. If the student did not make an error, simply offer them an encouraging comment.

사용자 메시지(USER)

문제 내용: """<문제 내용을 여기에 넣습니다>"""
자신의 답: """<모델이 생성한 답변을 여기에 넣습니다>"""
학생의 답변: """<학생 답변을 여기에 넣습니다>"""
분석: """<이전 단계에서 모델이 생성한 분석을 여기에 넣습니다>"""

> Problem statement: """<insert problem statement>"""
> Your solution: """<insert model generated solution>"""
> Student's solution: """<insert student's solution>"""
> Analysis: """<insert model generated analysis from previous step>"""

위 대화를 실행해보기 / Open in Playground

세부 전략: 모델이 이전 단계들에서 놓친 것이 있는지 물어보세요 / Tactic: Ask the model if it missed anything on previous passes

특정 질문과 관련한 소스에서 발췌한 내용(excerpt)을 나열하는 모델을 사용한다고 가정해보겠습니다. 각 발췌물을 나열한 뒤, 다른 발췌물을 작성할지 또는 중단할지 여부를 모델이 결정해야 합니다. 소스 문서가 큰 경우, 모델이 너무 일찍 중단하고 모든 관련 발췌물을 나열하지 못할 수 있습니다. 이 경우, 모델이 이전 단계에서 놓친 발췌물을 찾기 위해 후속 질의를 사용하도록 하면 더 나은 성능을 얻을 수 있습니다.

Suppose that we are using a model to list excerpts from a source which are relevant to a particular question. After listing each excerpt the model needs to determine if it should start writing another or if it should stop. If the source document is large, it is common for a model to stop too early and fail to list all relevant excerpts. In that case, better performance can often be obtained by prompting the model with followup queries to find any excerpts it missed on previous passes.


시스템 메시지(SYSTEM)

세 개의 따옴표로 구분된 문서가 제공됩니다. 당신의 임무는 다음 질문과 관련한 발췌물을 선택하세요: "인공지능의 역사에서 중요한 패러다임의 변화는 어떠한 것들이 있었나요?"
발췌문에 해석이 필요한 모든 관련 문맥이 포함되었는지, 즉, 중요한 문맥이 누락된 작은 스니펫을 추출하지 않도록 주의하세요. JSON 형식으로 다음과 같이 출력하세요:
[{"excerpt(발췌문)": "..."},
...
{"excerpt(발췌문)": "..."}]

> You will be provided with a document delimited by triple quotes. Your task is to select excerpts which pertain to the following question: "What significant paradigm shifts have occurred in the history of artificial intelligence."
> Ensure that excerpts contain all relevant context needed to interpret them - in other words don't extract small snippets that are missing important context. Provide output in JSON format as follows:
> [{"excerpt": "..."},
> ...
> {"excerpt": "..."}]

사용자 메시지(USER)

"""<문서를 여기에 넣습니다>"""
> """<insert document here>"""

어시스턴트 메시지(ASSISTANT)

[{"excerpt(발췌문)": "모델이 작성한 발췌문이 여기에 나열됩니다"},
...
{"excerpt(발췌문)": "모델이 작성한 발췌문이 여기에 나열됩니다"}]
> [{"excerpt": "the model writes an excerpt here"},
> ...
> {"excerpt": "the model writes another excerpt here"}]

사용자 메시지(USER)

더 관련성 있는 발췌문이 있나요? 발췌문을 반복하지 않도록 주의하세요. 또한 발췌문을 이해하기 위해 필요한 모든 관련한 문맥(context)이 포함되어 있는지, 즉 중요한 문맥이 누락된 작은 스니펫을 추출하지 않는지 확인하세요.
> Are there more relevant excerpts? Take care not to repeat excerpts. Also ensure that excerpts contain all relevant context needed to interpret them - in other words don't extract small snippets that are missing important context.

위 대화를 실행해보기 / Open in Playground