퓨샷 프롬프팅

OpenAI API로 배우는 프롬프트 엔지니어링

Fouad Trad

Machine Learning Engineer

퓨샷 프롬프팅

  • 모델에 예시(질문-답변 쌍) 제공

예시 질문과 답변, 그리고 모델에 묻고 싶은 질문을 포함한 퓨샷 프롬프트 구조를 시각적으로 나타낸 그림.

OpenAI API로 배우는 프롬프트 엔지니어링

퓨샷 프롬프팅

  • 모델에 예시(질문-답변 쌍) 제공

퓨샷 프롬프트를 LLM에 전송하는 방법을 나타낸 시각적 다이어그램.

OpenAI API로 배우는 프롬프트 엔지니어링

퓨샷 프롬프팅

  • 모델에 예시(질문-답변 쌍) 제공

퓨샷 프롬프트를 LLM에 전송하고 답변을 받는 과정을 나타낸 시각적 다이어그램.

OpenAI API로 배우는 프롬프트 엔지니어링

퓨샷 프롬프팅

  • 모델에 예시(질문-답변 쌍) 제공

퓨샷 프롬프트를 LLM에 전송하고 답변을 받는 과정을 나타낸 시각적 다이어그램.

  • 예시 수:
    • 0개 -> 제로샷 프롬프팅
    • 1개 -> 원샷 프롬프팅
    • 2개 이상 -> 퓨샷 프롬프팅
OpenAI API로 배우는 프롬프트 엔지니어링

제로샷 프롬프팅

  • 예시 없이 프롬프트 제공
  • 모델이 학습된 지식을 바탕으로 응답 생성
  • 빠르고 간단한 작업에 적합
prompt = "What is prompt engineering?"
print(get_response(prompt))
Prompt engineering refers to designing and refining prompts or instructions given 
to a language model like ChatGPT to elicit desired responses or behaviors. It 
involves formulating specific guidelines or hints to guide the model's output 
towards a desired outcome.
OpenAI API로 배우는 프롬프트 엔지니어링

원샷 프롬프팅

  • 모델에 예시 하나 제공
  • 일관된 형식 또는 스타일에 유용
prompt =  """ 
Q: Sum the numbers 3, 5, and 6. A: 3+5+6=14
Q: Sum the numbers 2, 4, and 7. A: 
"""
print(get_response(prompt))
2+4+7=13
OpenAI API로 배우는 프롬프트 엔지니어링

원샷 프롬프팅

prompt = """
Q: Sum the numbers 3, 5, and 6. A: The sum of 3, 5, and 6 is 14
Q: Sum the numbers 2, 4, and 7. A: 
"""
print(get_response(prompt))
The sum of 2, 4, and 7 is 13
OpenAI API로 배우는 프롬프트 엔지니어링

퓨샷 프롬프팅

  • 두 개 이상의 예시 제공
  • 맥락적 작업에 강력
prompt = """
Text: Today the weather is fantastic -> Classification: positive
Text: The furniture is small -> Classification: neutral
Text: I don't like your attitude -> Classification: negative

"""

OpenAI API로 배우는 프롬프트 엔지니어링

퓨샷 프롬프팅

  • 두 개 이상의 예시 제공
  • 맥락적 작업에 강력
prompt = """
Text: Today the weather is fantastic -> Classification: positive
Text: The furniture is small -> Classification: neutral
Text: I don't like your attitude -> Classification: negative
Text: That shot selection was awful -> Classification: 
"""
print(get_response(prompt))
negative
OpenAI API로 배우는 프롬프트 엔지니어링

채팅 모델을 이용한 퓨샷 프롬프팅

response = client.chat.completions.create(
  model = "gpt-4o-mini",

messages = [{"role": "user", "content": "Today the weather is fantastic"},
{"role": "assistant", "content": "positive"},
{"role": "user", "content": "I don't like your attitude"}, {"role": "assistant", "content": "negative"},
{"role": "user", "content": "That shot selection was awful"} ], temperature = 0 )
print(response.choices[0].message.content)
negative
OpenAI API로 배우는 프롬프트 엔지니어링

고려 사항

  • 작업 복잡도에 따라 샷 수 선택
    • 샷 수 적음 -> 기본 작업
    • 다양한 샷 -> 복잡한 작업

고민하는 사람을 나타낸 이미지.

OpenAI API로 배우는 프롬프트 엔지니어링

연습해 봅시다!

OpenAI API로 배우는 프롬프트 엔지니어링

Preparing Video For Download...