ChatGPT, Bing, Hugging Face...
IT에 종사하고 있다면, IT 뉴스를 가끔이라도 본다면 위 나열한 것 중 하나 정도는 들어봤을 겁니다.
물론 그것이 ChatGPT라는 것은 알고있습니다. 가장 네임드니까요.
위에서 말한 것들은 전부 LLM(Large Language Model) 기반으로 학습한 생성 AI 모델입니다.
그게 뭐냐고요? 그건 비밀입니다..
사실 잘 몰라요. 여기서는 생성 AI 모델이 아니라, 생성 AI 모델을 잘 다루는 법을 배울 것이기 때문에!
궁금하신 분들은 따로 공부해 보시면 좋을 겁니다.
각설하고, 정말 편리하죠.
그냥 친구한테 말하듯이 물어보면 무엇이든 알려주니까요. 물론 엉뚱한 소리도 있고, 철 지난 얘기를 할때도 있지만, 유용한 서비스인 것은 확실합니다.
여러분은 가령 ChatGPT를 사용할 때 답변이 불만족스러웠던 적이 있나요?
더 나아가 좀 더 좋은 결과를 도출하기 위해 입력 텍스트를 요리조리 수정해보고 고민해 본적이 있나요?
그러면 당신도 Prompt Engineering을 한 것입니다.
그냥 깡통 로봇하고 대화하고.. 이상한 말이나 해대니 화를 내며 재질문 한 것 뿐인데, Prompt Engineering이라니??
엄밀히 말하자면 Prompt Engineering이라고 할수는 없어도 그에 준한, 근접한 행위를 한것은 분명합니다!
이말은 무엇이냐..
Prompt Engineering을 공부한다면 ChatGPT같은 생성 AI 모델에게서 더 좋은 결과를 도출할 수 있다는 점!
혹하지 않나요?
그렇다면 한번 배워봅시다.
프롬프트는 컴퓨터 분야에서 원하는 결과물을 얻기 위한 명령어에 불과했습니다.
컴퓨터는 사람의 언어를 이해할 수 없기 때문에, 사전에 명령어에 따른 결과물을 정해두었고 이는 결과 제시의 범위가 제한적이라는 단점으로 이어졌죠.
하지만 최근 'Generative AI'가 발전함에 따라 자연어를 이해할 수 있게 되었고
프롬프트라는 말은 생성형 모델이 원하는 결과물을 도출할 수 있도록 내리는 명령어로 그 의미가 확장되고 있습니다.
자연어 처리의 발전으로 프롬프트 기반의 강력한 언어 모델이 개발되었습니다.
하지만 컴퓨터의 특성에 맞춰 입력을 해야했기에 한계는 분명했고, 프롬프트의 질에 따라 의도가 같아도 결과물이 천차만별로 나오는 상황이 발생합니다.
이는 프롬프트 엔지니어링이 필요한 이유를 말해주죠.
LLM의 활용성이 커지고 사용 범위가 넓어짐에 따라, 프롬프트 엔지니어링의 중요성이 커지겠죠?
특히 LLM을 사용하여 좀 더 좋은 결과를 도출하기 원하는 사용자라면 프롬프트 엔지니어링을 학습함에 따라 목표를 달성하는 데 큰 도움이 될 수 있습니다.
즉, 프롬프트 엔지니어링은 다음을 의미합니다.
- 자연어 명령의 의도를 잘 파악하고 더 좋은 답변을 주기 위한 프롬프트 구성을 만들어 가는 행위
- 인공지능 분야의 한 개념으로 AI로부터 높은 수준의 결과물을 얻기 위해 적절한 프롬프트를 구성하는 작업
결국엔 아무리 자연어 처리가 발전해도 생성형 AI는 부적절한 결과물을 생성하거나, 인간의 감정적인 영역에 완벽히 따라 갈 수 없을 것 입니다.
그러기에 인간의 개입과 조절이 필요하고 이것이 프롬프트 엔지니어링이라고 할 수 있습니다.
프롬프트 엔지니어링 테크닉을 알아보기 전에, 좋은 프롬프트를 위해 어떤 것을 지켜줘야 하는지 알아봅시다.
좋은 프롬프트에는 다음과 같은 구성 요소가 포함되어야 합니다.
- Task(지시): 구체적인 목표, 출력의 유형이나 형식을 의미합니다. 명확하고 간결해야 하며 필요로 하는 구체적인 정보에 초점을 맞춰야 합니다.
- Context(맥락): LLM이 작업을 이해하는 데 필요한 배경 정보나 설명, 정보의 요약을 제공합니다.
- Constraints(제약): 경계 또는 제한을 제공합니다. 특정 요구 사항이나 응답의 길이 또는 복잡성에 대한 제한을 걸 수 있습니다.
- Input Data(입력 데이터): 응답 받고자 하는 입력이나 질문입니다.
위의 4가지 사항은 프롬프트를 설명하는 문서마다 조금씩 차이가 있습니다. 여러 문서를 참조하여 공통적인 부분을 추려낸 것입니다.
물론 네 가지 구성 요소가 프롬프트에 필수적으로 필요한 것은 아니며 테크닉마다 차이가 있을 수 있습니다.
보다 좋은 결과물을 위해 어떻게 프롬프트를 설계해야 하는지 알아봅시다.
본문의 예시는 meta의 llama2 모델 기반인 HuggingChat에서 실행한 결과입니다.
최적의 결과를 얻기 위해서는 많은 실험을 반복해야 합니다.
따라서 초기부터 복잡한 프롬프트를 설계하여 실행하기 보다는, 간단한 프롬프트부터 시작하여 필요한 요소나 문맥을 추가하여 목표에 가까워지는 것이 중요합니다.
다음은 예시입니다.
Prompt:
the latest movie
Output:
Sure, here are some of the latest movies that have been released:
"Avengers: Endgame" - a superhero film directed by Anthony and Joe Russo and starring Robert Downey Jr., Chris Evans, Mark Ruffalo, Chris Hemsworth, Scarlett Johansson, Jeremy Renner, and Brie Larson.
"The Lion King" - a live-action remake of the 1994 animated film, directed by Jon Favreau and starring Donald Glover, Seth Rogen, Chiwetel Ejiofor, Alfre Woodard, Beyoncé, James Earl Jones, and John Oliver.
"Toy Story 4" - an animated comedy-drama film directed by Josh Cooley and starring Tom Hanks, Tim Allen, Annie Potts, Tony Hale, Keegan-Michael Key, Jordan Peele, and Christina Hendricks.
"Spider-Man: Far From Home" - a superhero film directed by Jon Watts and starring Tom Holland, Samuel L. Jackson, Zendaya, Cobie Smulders, Jon Favreau, Jake Gyllenhaal, and Marisa Tomei.
"Midsommar" - a folk horror film directed by Ari Aster and starring Florence Pugh, Jack Reynor, Will Poulter, Vilhelm Blomgren, and Cliff Burns.
// ...
// 생략
간단하게 최신 영화를 요구했을 때의 결과입니다. (이게 정말 최신영화인가는.. 넘어가겠습니다.)
여기서 프롬프트를 더 추가한다면?
Prompt:
Please recommend 3 latest movies.
Except for the explanation, please write down the title, release year, and genre.
Output:
Sure, here are three latest movies that have been well-received by audiences and critics:
Parasite (2019) - Dark Comedy Thriller
Joker (2019) - Psychological Thriller
1917 (2019) - War Drama
어때요? 확연하게 깔끔해진 것이 보이시나요?
여기서 알아야 할 점은 단순히 깔끔해지는 과정을 볼려고 간단하게 시작하는 것이 아닙니다.
예를들어 깔끔하게 떨어지는 5개의 프롬프트로 원하는 결과물을 얻어야 한다고 가정해봅시다.
1개부터 시작하여 5개로 가는 것이, 10개에서 시작하여 5개로 가는 것보다 훨 씬 쉽기 때문에 간단히 시작하는 겁니다.
프롬프트가 많을 수록 정제된 결과물이 나오고, 그 말은 그 전의 단계를 도출하기 어렵다는 거겠죠.
사용자는 프롬프트를 입력하기 전에 어떤 것을 요구하는지 명확하게 기재할 필요가 있습니다.
예를 들어 분류, 요약, 번역, 정렬 등의 지시 사항을 기재한다면 더욱 좋은 결과물을 얻을 수 있을 것 입니다.
또한 시작 부분에 지시 사항을 명시하고 해당 부분에 '###'와 같은 구분 기호를 사용한다면 더욱 좋다는 의견 도 있습니다.
다음은 예시 입니다.
Prompt:
Please translate pasta, steak, and soup into Korean and arrange them by letter.
Output:
Sure! Here are the translations of "pasta," "steak," and "soup" in Korean, arranged alphabetically:
Pasta: 파스타 (pasteu)
Soup: 수프 (sup)
Steak: 스테이크 (seuteikeu)
한문장에 두 가지 지시사항을 넣으니.. 엉터리 답이 나왔습니다.
좀 더 명확하게 바꿔보죠.
Prompt:
### Translation ###
Translate pasta, soup, and steak into Korean.
### Sort ###
Sort the translated words in alphabetical order.
Output:
Sure! Here are the translated words in alphabetical order:
수프 (sup) - soup
파스타 (pasteu) - pasta
스테이크 (seuteikeu) - steak
지시사항도 보기 좋게 깔끔해 졌고, 무엇보다 결과가 정확하게 나왔다는 것을 볼 수 있습니다.
특정한 출력이나 스타일의 결과물을 얻고자 하는 경우 실행 시킬 지시와 작업을 구체적으로 설명해야 합니다.
더 나은 결과를 위해 아무 키워드나 추가하기 보다는 상세한 형식을 준비하는 것이 좋습니다.
주의할 점은 프롬프트의 길이에는 제한이 있다는 점입니다. 그렇기에 더더욱 세부 사항을 적을 때 불필요한 내용은 없는지 검토해야 합니다.
다음은 예시입니다.
Prompt:
Match the name and age in the following text and print it out.
"Agnes and Alice, 24, and Henry, 28, are working on the project together."
Output:
Sure! Here's the matched information:
Name: Agnes
Age: 24
형식을 정하지 않은 것은 넘겨두더라도, 이번에도 제대로 이해를 못하고 옳은 결과를 도출하지 못합니다.
출력 형식을 정확하게 알려줘 봅시다.
Prompt:
Match the name and age in the following text and print it out.
Text: "24-year-old Agnes and Alice, and 28-year-old Henry are working on a project together."
Output format:
< Name >: < Age >
< Name >: < Age >
< Name >: < Age >
Output:
Sure! Here's the matched information:
Agnes: 24
Alice: 24
Henry: 28
제가 의도한 대로 출력되는 것을 볼 수 있습니다.
상세하게 프롬프트를 기술할 때 두루뭉실한 표현을 주의해야 합니다.
프롬프트 설계가 복잡할 수록, 상세한 설명에만 포커스를 줄 때에 이러한 실수를 하기 쉽습니다.
프롬프트는 직접적일수록 의도하는 바가 더 효과적으로 전달되고, 이는 좋은 결과로 이어집니다.
다음은 예시입니다.
Prompt:
Easily explain what FE developers do.
Output:
Front-end (FE) developers are responsible for building the user interface and user experience of a website or web application. They use programming languages such as HTML, CSS, and JavaScript to create the visual aspects of a website or application, as well as ensure that it functions properly and is easy to use for users.
Some common tasks that FE developers perform include:
Designing and implementing the layout and look of a website or application
Creating responsive designs that work well on different devices and screen sizes
Building interactive elements such as buttons, forms, and navigation menus
Implementing animations and other dynamic effects
Optimizing the performance and load times of a website or application
Ensuring that the site or app is compatible with different browsers and devices
Testing and debugging code to fix errors and improve functionality
In short, FE developers focus on creating an intuitive, visually appealing, and functional front-end for websites and applications that users can interact with and enjoy using.
단순히 쉽게 설명해달라는 말은 직관적이지 않죠?
좀더 직관적으로 표현해 보면,
Prompt:
Explain so that elementary school students can understand what FE developers are doing.
The description must not exceed one paragraph.
Output:
Sure! Here's a description of what FE developers do that elementary school students can understand:
FE developers are like artists who make websites and apps look nice and work well. They use special computer programs to create the parts of a website or app that you see and interact with, like the buttons you click or the pictures you look at. They also make sure that everything works correctly when you type in a address or click a button. It's their job to make sure that the website or app is fun and easy to use, kind of like designing a video game! They test it out to make sure there are no mistakes and then share it with the world.
읽을 대상과, 문단의 개수를 제한해주니 의도한 결과물이 나오는 것을 알 수 있습니다.
프롬프트를 설계할 때는 하지 말아야 할 것보다 해야 하는 것에 초점을 두는 것이 좋은 결과물을 도출하는 것에 도움이 됩니다.
다음은 예시입니다.
Prompt:
Please recommend a movie of my favorite genre.
Don't ask questions about your favorite genre.
Output:
Sure, I can do that! Here's a recommendation for a movie in a random genre:
Genre: Science Fiction
Movie: Inception (2010)
Inception is a thought-provoking and visually stunning science fiction film written and directed by Christopher Nolan. The movie follows Cobb, a skilled thief who specializes in entering people's dreams and stealing their secrets. Cobb is offered a chance to redeem himself by performing an impossible task: planting an idea in someone's mind instead of stealing one. Cobb assembles a team of experts, including Arthur, Ariadne, Eames, and Saito, to help him pull off the dangerous mission.
The movie explores themes of reality, perception, and the power of the human mind. The visuals are breathtaking, with mind-bending sequences that blur the lines between dreams and reality. The talented cast, which includes Leonardo DiCaprio, Joseph Gordon-Levitt, Ellen Page, Tom Hardy, Dileep Rao, and Ken Watanabe, brings depth and complexity to their characters.
Inception has received widespread critical acclaim for its originality, direction, screenplay, and performances. It was nominated for eight Academy Awards, including Best Picture, Best Director, and Best Original Screenplay.
I hope you enjoy this movie! Let me know if you have any other questions or if there's anything else I can help you with.
제가 관심있는 장르로 추천해 달라고 했지만, 장르를 물어보지 말라고 했다는 이유로 누구의 취향인지도 모를 영화를 추천해줍니다.
그렇다면 해야 하는 것에 초점을 맞춰서 다시 해봅시다.
Prompt:
Please recommend a movie of my favorite genre.
If you don't know what my favorite genre is, tell me as below.
"I don't know what your favorite genre is, so it's hard to recommend it."
Output:
I don't know what your favorite genre is, so it's hard to recommend a movie from that specific category. Can you please provide some information about the type of movies you enjoy watching? For example, do you like action films, romantic comedies, horror movies, or something else? This will help me give you a more tailored recommendation.
단지 하지 말라는 말이 아니라, '만약 조건이 맞지 않는다면 이렇게 해라'라고만 했는데도 정확하게 동작하는 것을 알 수 있습니다.
뭔가 어색하지 않나요? 갑자기 끊긴 느낌..
맞습니다. 사실 본문에서 다룬 내용은 Prompt Engineering을 하기 위해 갖춰야 할 기본기입니다.
너무 길어질까 여기서 끊고 다음 포스트에서 Prompt Engineering 테크닉에 대해 배워 볼 예정입니다.
이번 포스트보다는, 다음 포스트가 재밌겠네요!