검색
검색
공개 노트 검색
회원가입로그인

앤드류 응 교수님 + Isa의 프롬프트 강의 정리

page thumbnail

프롬프팅 원리

  • 원리 1 : 명확하고 구체적인 지시를 쓰라.

  • 원리 2 : 모델에게 생각할 시간을 주자.

원리 1 : Write clear and specific instructions

전략 1 : 구분자 (delimiters) 를 사용해서 입력값을 명확하게 구분한다.

  • 구분자는 어떤 것이든 될 수 있다. 예를 들면 ```(delimited by triple backticks), """ (delimited by triple quotes), < >, <tag> </tag>, : 와 같은 것들이 될 수 있다.

예시

prompt = f"""
Summarize the text delimited by triple backticks \ 
into a single sentence.
```{text}```
"""
  • 짧다고 명확한 것은 아니다. 길어도 더 정확한 요청이 응답이 좋을 수 도 있다.

전략 2 : 구조적인 output을 요청하라.

  • JSON, HTML

전략 3 : model이 조건이 만족되었는지 확인할 수 있는 체크할 수 있게 물어봐라. 예를 들어 일련의 구체적인 스텝이 있을 때만 Step 1, Step 2와 같이 표시하기.

전략 4 : Few-shot 프롬프팅 (짧은 예시를 넣기)

원리 2 : Give the model time to “think”

전략 1 : 일을 마치기 위한 구체적인 스텝 제공하기

예시 (응답에 특정한 포맷 추가)

prompt_2 = f"""
Your task is to perform the following actions: 

1 - Summarize the following text delimited by 
  <> with 1 sentence.
2 - Translate the summary into French.
3 - List each name in the French summary.
4 - Output a json object that contains the 
  following keys: french_summary, num_names.

Use the following format:
Text: <text to summarize>
Summary: <summary>
Translation: <summary translation>
Names: <list of names in Italian summary>
Output JSON: <json with summary and num_names>

Text:
```{text}```
"""
response = get_completion(prompt_2)
print("\nCompletion for prompt 2:")
print(response)

전략 2 : 모델에게 성급하게 결론에 이르기 전에 자신의 해결책을 먼저 고려하게 하기.

예를 들어 학생의 대답이 맞는지 확인하기 전에 먼저 자신의 해결책을 생각한 후 비교하게 하기.

모델의 한계 : 할루시네이션 (지어내기 현상)


  • 프롬프트 개발은 한 번에 끝나는 것이 아니라 반복적으로 테스트하면서 수정하는 과정임.

예를 들어 특정한 변수를 할당하는 템플릿을 반복적으로 수정하여 최적의 결과를 내는 것을 찾는다.

대표적인 사용 사례들

  • 요약

  • 추론 (inferring) : 리뷰나 뉴스 기사의 토픽이나 감정 추론하기.

  • 변환 (Transforming) : 번역, 철자나 문법 교정 (spelling and grammar checking), 톤 변화, 포맷 변환

  • 확장하기 (Expanding) : 각 사용자의 리뷰에 맞는 이메일 쓰기. (인공지능으로 생성했다는 것을 명시해주는 것을 권장!)


챗봇 만들기

예시

주문봇 (OrderBot)

context = [ {'role':'system', 'content':"""
You are OrderBot, an automated service to collect orders for a pizza restaurant. \
You first greet the customer, then collects the order, \
and then asks if it's a pickup or delivery. \
You wait to collect the entire order, then summarize it and check for a final \
time if the customer wants to add anything else. \
If it's a delivery, you ask for an address. \
Finally you collect the payment.\
Make sure to clarify all options, extras and sizes to uniquely \
identify the item from the menu.\
You respond in a short, very conversational friendly style. \
The menu includes \
pepperoni pizza  12.95, 10.00, 7.00 \
cheese pizza   10.95, 9.25, 6.50 \
eggplant pizza   11.95, 9.75, 6.75 \
fries 4.50, 3.50 \
greek salad 7.25 \
Toppings: \
extra cheese 2.00, \
mushrooms 1.50 \
sausage 3.00 \
canadian bacon 3.50 \
AI sauce 1.50 \
peppers 1.00 \
Drinks: \
coke 3.00, 2.00, 1.00 \
sprite 3.00, 2.00, 1.00 \
bottled water 5.00 \
"""} ]  # accumulate messages
messages =  context.copy()
messages.append(
{'role':'system', 'content':'create a json summary of the previous food order. Itemize the price for each item\
 The fields should be 1) pizza, include size 2) list of toppings 3) list of drinks, include size   4) list of sides include size  5)total price '},    
)

제가 보려고 정리했습니다.

강의는 ChatGPT Prompt Engineering for Developers 에서 볼 수 있습니다.

공유하기
카카오로 공유하기
페이스북 공유하기
트위터로 공유하기
url 복사하기
조회수 : 693
heart
T
페이지 기반 대답
AI Chat