research notes

프롬프트 엔지니어링(Prompt Engineering) 본문

GPT/개념정의

프롬프트 엔지니어링(Prompt Engineering)

forest62590 2023. 2. 28. 22:47
728x90

1. 프롬프트 엔지니어링이란?

프롬프트 엔지니어링이란 챗 GPT(ChatGPT)와 같은 생성형 인공지능에(Generative AI) 사용되는 명령글인 '프롬프트(생성형 AI 모델에서 이미지나 텍스트 결과를 생성하기 위한 명령어를 의미)'를 다양한 방식으로 조작하고 지속적으로 개선하여 사용자가 원하는 최선의 답변을 생성하도록 돕는 것이다. 몇몇 기사에 따르면 현재 프롬프트를 전문적으로 만들어 내는 '프롬프트 엔지니어'라는 새 직업이 주목받고 있으며, 더 나아가 프롬프트를 전문적으로 판매하는 프롬프트베이스에서는 대략 700명의 프롬프트 엔지니어가 활동하고 있다고 한다 [1].

 

생각해보면 프롬프트는 ChatGPT와 같은 서비스를 이용할 때 사용자가 궁금한 내용에 대해 작성하는 단순한 텍스트 질문이기 때문에(예를 들어, "ChatGPT는 어떻게 학습이 이루어지는가?") 굳이 엔지니어링적 관점의 작업이 필요한지 의아해 할 수도 있다. 그 이유를 보자면 ChatGPT와 같은 대형 언어 모델은(Large Language Model, LLM) 세부적인 내용이 오픈되어 있지 않고 OpenAI에서 API 형태로만 제공하고 있다. 따라서, 연구자들이 동일하게 해당 서비스를 만들어 내고 운영하기 힘들 뿐만 아니라(주로 비용적 측면), 특정 API를 통해 제어할 수 있는것도 아니다.  따라서, 모델을 제어할 수 있는 유일한 방법인 프롬프트를 제어(활용)하여 최선을 결과를 도출하기 위한 프롬프트 엔지니어링에 대한 테크닉이 많이 연구되고 있다 [2]. 

 

아래 그림은 복잡한 수학 문제나 추론 문제를 풀 때 프롬프트의 예시로 추론의 과정을 넣어주면 언어 모델도 해당 추론을 이해하고 같은 방식으로 더 정확한 답변을 추론할 수 있다는 것을 보여주고 있다(by Google Research, Chain-of-Thought Prompting Elicits Reasoning in Large Language Models).

2. Best practices for prompt engineering with OpenAI API

OpenAI에서는 "Best practices for promt enginerring with OpenAI API"라는 블로그 포스팅을 통해 어떠한 방식으로 프롬프트를 작성해야 사용자가 원하는 최상의 결과물을 얻을 수 있을지에 대해 가이드를 작성해 놓았다 [3]. 이하 가이드에서 '{text input here}'는 실제 사용자가 작성하는 프롬프트가 적용되는 곳이다.

 

1. 최신의 모델 사용

최상의 결과를 얻기 위해 최신 모델을 사용하는 것이 좋다. 2022년 11월 기준으로 텍스트 생성을 위한 "text-davinci-003" 모델과 코드 생성을 위한 "code-davinci-002" 모델을 권장

 

2. 프롬프트 시작 부분에 명령을 입력하고 ### 또는 """를 사용하여 명령과 컨텍스트를 구분

Less effective ❌:

Summarize the text below as a bullet point list of the most important points.

{text input here}

Better ✅:

Summarize the text below as a bullet point list of the most important points.

Text: """
{text input here}
"""

 

3. 원하는 컨텍스트(context), 결과(outcome), 길이(length), 형식(format), 스타일(style) 등에 대해 가능한 구체적이고 명확하게 작성

Less effective ❌:

Write a poem about OpenAI.

Better ✅:

Write a short inspiring poem about OpenAI, focusing on the recent DALL-E product launch (DALL-E is a text to image ML model) in the style of a {famous poet}

 

4. 예제를 통해 원하는 출력 형식을 명시(Show and tell)

Less effective ❌:

Extract the entities mentioned in the text below. Extract the following 4 entity types: company names, people names, specific topics and themes.

Text: {text}

 

Better ✅:

Extract the important entities mentioned in the text below. First extract all company names, then extract all people names, then extract specific topics which fit the content and finally extract general overarching themes

Desired format:
Company names: <comma_separated_list_of_company_names>
People names: -||-
Specific topics: -||-
General themes: -||-

Text: {text}

 

5. 제로샷(Zero-shot), 퓨샷(Few-shot) 순서로 질의 후 둘 다 미흡 할 경우 미세조정(Fine-tune) 사용 

✅ Zero-shot

Extract keywords from the below text.

Text: {text}

Keywords:

✅ Few-shot - provide a couple of examples

Extract keywords from the corresponding texts below.

Text 1: Stripe provides APIs that web developers can use to integrate payment processing into their websites and mobile applications.
Keywords 1: Stripe, payment processing, APIs, web developers, websites, mobile applications
##
Text 2: OpenAI has trained cutting-edge language models that are very good at understanding and generating text. Our API provides access to these models and can be used to solve virtually any task that involves processing language.
Keywords 2: OpenAI, language models, text processing, API.
##
Text 3: {text}
Keywords 3:

 

6. 모호하고 부정확한 설명 줄이기

Less effective ❌:

The description for this product should be fairly short, a few sentences only, and not too much more.

Better ✅:

Use a 3 to 5 sentence paragraph to describe this product.

 

7. 단순히 안되는 것을 명시하는 것 뿐만 아니라 해야할 것을 함께 기술

Less effective ❌:

The following is a conversation between an Agent and a Customer. DO NOT ASK USERNAME OR PASSWORD. DO NOT REPEAT.

Customer: I can’t log in to my account.
Agent:

Better ✅:

The following is a conversation between an Agent and a Customer. The agent will attempt to diagnose the problem and suggest a solution, whilst refraining from asking any questions related to PII. Instead of asking for PII, such as username or password, refer the user to the help article www.samplewebsite.com/help/faq

Customer: I can’t log in to my account.
Agent:

3. 결론

초거대 언어 모델이 등장하고 주류로 자리 잡기 시작하면서 프롬프트 엔지니어링(Prompt Engineering)의 중요성도 더욱 더 커져가고 있는 것으로 보인다. 링크된 Github만 봐도(https://github.com/dair-ai/Prompt-Engineering-Guide) 프롬프트 엔지니어링 관련 다양한 강의와 논문들을 볼 수 있다. 그리고, 공격자가 시스템 출력을 조작하기 위해 악의적인 프롬프트를 주입하는 프롬프트 인젝션(Prompt Injection)이라고 하는 기술도 최근 언급되고 있는 것으로 보아 앞으로 프롬프트 엔지니어링 관련 활발한 연구가 예상된다.

References:

[1] https://www.aitimes.com/news/articleView.html?idxno=149692

[2] https://smilegate.ai/2022/07/14/%EC%86%8C-%EC%9E%A1%EB%8A%94-%EC%B9%BC%EB%A1%9C-%EB%8B%AD-%EC%9E%98-%EC%9E%A1%EC%95%84%EB%B3%B4%EA%B8%B0/

[3] https://help.openai.com/en/articles/6654000-best-practices-for-prompt-engineering-with-openai-api

[4] https://discuss.pytorch.kr/t/topic/877

[5] https://brunch.co.kr/@muralmural/6

728x90
Comments