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

llama 프롬프트 엔지니어링

llama-recipes/examples/Prompt_Engineering_with_Llama_2.ipynb at main · facebookresearch/llama-recipes

메타에서 공개한 라마의 프롬프트 엔지니어링에 대한 자료입니다. 자세한 내용은 본문을 참고해 주세요. 간단하게만 정리합니다.

  • 명백한 지시 : 자세하고 명백한 지시가 좋은 결과를 출력. (규칙, 제한 등을 더하는 것이라고 생각해도 됨)

    • 예시 : Describe quantum physics in one short sentence of no more than 12 words.

  • Zero-Shot Prompting 과 Few-Shot Prompting : 퓨샷 프롬프팅은 예시를 제공하는 것.

퓨샷 프롬프팅 예시

def sentiment(text):
    response = chat_completion(messages=[
        user("You are a sentiment classifier. For each message, give the percentage of positive/netural/negative."),
        user("I liked it"),
        assistant("70% positive 30% neutral 0% negative"),
        user("It could be better"),
        assistant("0% positive 50% neutral 50% negative"),
        user("It's fine"),
        assistant("25% positive 50% neutral 25% negative"),
        user(text),
    ])
    return response
  • 역할 프롬프팅

  • Chain of Thought : 중간 추론 (생각) 단계를 제공하는 것.

  • Self-Consistency : 대답을 여러번 생성해서 가장 많이 나온 대답을 고르는 것.

  • Retrieval-Augmented Generation : 외부 지식을 검색 및 결합해서 대답.

  • Program-Aided Language Models : 산수가 약한 LLM을 위해 코드를 생성해서 문제를 풀기 (예 : ChatGPT 코드 인터프리터)

  • 관계없는 토큰 출력하기 않기 (Limiting Extraneous Tokens) : 대답에 쓸데없는 문장을 추가하지 않고 (ex. "Sure! Here's more information on...") 출력하기. 예) JSON 으로만 응답하기.

complete_and_print(
    "Give me the zip code for Menlo Park in JSON format with the field 'zip_code'",
    model = LLAMA2_70B_CHAT,
)
# Likely returns the JSON and also "Sure! Here's the JSON..."

complete_and_print(
    """
    You are a robot that only outputs JSON.
    You reply in JSON format with the field 'zip_code'.
    Example question: What is the zip code of the Empire State Building? Example answer: {'zip_code': 10118}
    Now here is my question: What is the zip code of Menlo Park?
    """,
    model = LLAMA2_70B_CHAT,
)
# "{'zip_code': 94025}"

생각보다 새로운 것은 없는 것 같다. 퓨샷(예시)이나 역할, 세부사항 더하기 등의 기본기가 중요하다는 것을 확인할 수 있었다. Self-Consistency 는 처음 보는 개념인 것 같다. 이와 마찬가지로 여러 LLM의 결과를 조합하는 기법도 있을 것 같다.

deeplearning.ai 에 강의도 공개되어 있다. Prompt Engineering with Llama 2 위의 문서와 내용은 다르다. 기본적인 라마 모델 사용 방법을 다루고 있다.

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