반응형
블로그 이미지
개발자로서 현장에서 일하면서 새로 접하는 기술들이나 알게된 정보 등을 정리하기 위한 블로그입니다. 운 좋게 미국에서 큰 회사들의 프로젝트에서 컬설턴트로 일하고 있어서 새로운 기술들을 접할 기회가 많이 있습니다. 미국의 IT 프로젝트에서 사용되는 툴들에 대해 많은 분들과 정보를 공유하고 싶습니다.
솔웅

최근에 올라온 글

최근에 달린 댓글

최근에 받은 트랙백

글 보관함

카테고리


반응형

오늘 다룰 부분은 소스 코드는 없고 좀 이론적인 내용인 것 같습니다.

아래 페이지에 있는 내용을 공부해 보겠습니다.

 

https://github.com/openai/openai-cookbook/blob/main/how_to_work_with_large_language_models.md

 

GitHub - openai/openai-cookbook: Examples and guides for using the OpenAI API

Examples and guides for using the OpenAI API. Contribute to openai/openai-cookbook development by creating an account on GitHub.

github.com

 

 

How to work with large language models

How large language models work

 

Large language models  (대규모 언어 모델)은 텍스트대 텍스트를 매핑하는 기능입니다. 

입력된 텍스트를 가지고 large language 모델이 그 다음에 오는 텍스트를 예측하는 겁니다.

 

이 large language 모델의 마법은 방대한 양의 텍스트에 대한 예측 오류를 최소화 하도록 훈련함으로써 모델이 결국에는 이 예측을 위한 아주 유용한 개념을 배운다는 겁니다. 

예를 들어 그들은 이러한 것들을 배웁니다.

  • how to spell
  • how grammar works
  • how to paraphrase
  • how to answer questions
  • how to hold a conversation
  • how to write in many languages
  • how to code
  • etc.

이러한 기능 중 어느것도 명시적으로 프로그래밍 되어 있지 않으며 모두 교육의 결과로 나타납니다.

GPT-3 는 productive 앱, 교육용 앱, 게임 등 수백가지 종류의 소프트웨어 product들의 지원합니다.

 

How to control a large language model

Large language 모델의 모든 입력 중에서 지금까지 가장 영향력 있는 것은 text prompt 입니다.

Large language 모델은 몇가지 방법으로 output을 만들어 내기 위해 prompt 될 수 있습니다.

 

  • Instruction: Tell the model what you want
  • 지시 : 모델에게 원하는 것을 말합니다.
  • Completion: Induce the model to complete the beginning of what you want
  • 완료 : 당신이 원하는 것의 시작부분을 알려주고 그것을 모델이 완료하도록 합니다.
  • Demonstration: Show the model what you want, with either:
  • Demonstration : 아래 방법을 사용해 모델에게 당신이 무엇을 원하는지 보여 줍니다. 
    • A few examples in the prompt 
    • 프롬프트의 몇가지 예
    • Many hundreds or thousands of examples in a fine-tuning training dataset
    • fine-tuning (미세조정) 훈련 데이터세트를 수백개 혹은 수천개를 제공합니다.

각각에 대한 예제는 아래에 있습니다.

 

Instruction prompts

 

instruction-following model들은 (예 : text-davinci-003 혹은 test- 로 시작하는 모든 모델들) instruction을 따르도록 특별히 설계 되어 있습니다.

prompt 상단에 여러분의 instruction을 적으세요. (혹은 프롬프트 하단이나 상/하단 모두 다에 작성합니다.) 그러면 모델은 최선을 다해 지시를 따르고 나서 stop 합니다. instruction은 상세하게 해도 됩니다. 그러므로 여러분이 원하는 output을 위해 명시적이고 상세하게 작성하는 paragraph를 작성하는 것을 두려워하지 마세요.

 

Example instruction prompt

Extract the name of the author from the quotation below.

“Some humans theorize that intelligent species go extinct before they can expand into outer space. If they're correct, then the hush of the night sky is the silence of the graveyard.”
― Ted Chiang, Exhalation

Output

Ted Chiang

 

Completion prompt example

Completion 스타일의 프롬프트들은 Large Language 모델들이 그 다음에 올 수 있는 가장 확률이 높은 텍스트를 작성하도록 하는데 사용할 수 있는 모델입니다. 이 모델을 사용하려면 원하는 output으로 완성될 패턴이나 문장을 시작해 보세요.

instruction 처럼 직접 지시하는 것에 비해 이 mode를 사용하는 large lanuage 모델들은 더 많은 주의와 실험이 필요할 수 있습니다. 게다가 모델은 stop 지점을 정확하게  알 필요가 없으므로 여러분이 그 과정 중에 중지시키거나 원하는 것 이상의 output이 나왔을 경우 일부 잘라내 버리는 사후 처리가 필요한 경우가 있습니다.

 

Example completion prompt:

“Some humans theorize that intelligent species go extinct before they can expand into outer space. If they're correct, then the hush of the night sky is the silence of the graveyard.”
― Ted Chiang, Exhalation

The author of this quote is

Output:

 Ted Chiang

 

Demonstration prompt example (few-shot learning)

Completion 스타일 prompt와 비슷하게 Demonstration은 여러분이 모델이 하기를 원하는 것을 보여 줄 수 있습니다. 이 접근 방식은 few-shot 학습이라고도 불립니다. 모델이 prompt에 제공된 몇가지 예제들로부터 배우는 겁니다.

 

Example demonstration prompt:

 

Quote:
“When the reasoning mind is forced to confront the impossible again and again, it has no choice but to adapt.”
― N.K. Jemisin, The Fifth Season
Author: N.K. Jemisin

Quote:
“Some humans theorize that intelligent species go extinct before they can expand into outer space. If they're correct, then the hush of the night sky is the silence of the graveyard.”
― Ted Chiang, Exhalation
Author:

Output:

 Ted Chiang

 

Fine-tuned prompt example

충분한 training 예제들을 사용하면 여러분은 custom model을 fine-tune(미세 조정) 할 수 있습니다.

이 경우 instruction은 필요하지 않게 됩니다. 모델이 제공된 training 데이터를 통해서 자신의 임무를 배울 수 있기 때문입니다. 

이 경우 separator sequences (e.g., -> or ### or any string that doesn't commonly appear in your inputs)를 사용하여 prompt가 종료되는 지점과 output이 시작되어야 할 때를 모델에게 알리는 것이 도움이 될 수 있습니다.

이 separator sequences가 없으면 여러분이 원하는 답을 시작하지 않고 input text에 대해 계속 더 상세화하는 작업을 할 리스크가 있습니다.

 

Example fine-tuned prompt (유사한 prompt-completion 쌍에 대해 이미 custom 훈련 돼 있는 모델의 경우 ):

“Some humans theorize that intelligent species go extinct before they can expand into outer space. If they're correct, then the hush of the night sky is the silence of the graveyard.”
― Ted Chiang, Exhalation

###

Output:

 Ted Chiang

 

Code Capabilities

Large language 모델들은 텍스트에서만 훌륭하게 작동하는게 아닙니다. 이 모델은 코딩에서도 훌륭하게 사용할 수 있습니다. OpenAI에서 만든 코딩 모델은 Codex라고 합니다.

Codex

 

OpenAI Codex

We’ve created an improved version of OpenAI Codex, our AI system that translates natural language to code, and we are releasing it through our API in private beta starting today.

openai.com

 

Codex는 다음을 포함한 70여가지가 넘는 products들을 지원합니다.

  • GitHub Copilot (autocompletes code in VS Code and other IDEs)
  • Pygma (turns Figma designs into code)
  • Replit (has an 'Explain code' button and other features)
  • Warp (a smart terminal with AI command search)
  • Machinet (writes Java unit test templates)

Note : instruction-following text 모델들과는 다르게 (e.g. text-davinci-002), Codex는 instruction을 따르도록 훈련되지 않습니다. 결과적으로 이 모델을 사용하려면 좋은 prompt를 디자인 하는 것에 더 심경을 써야 합니다.

 

More prompt advice

다른 prompt 예제들은 이곳을 방문하세요. OpenAI Examples.

 

일반적으로 input prompt는 모델의 output을 더 좋게 만드는데 가장 중요한 수단입니다.

더 좋게 만들기 위해 다음과 같은 트릭을 사용할 수 있습니다.

 

* 지시를 더 명확히 하세요. 예를 들어 output을 쉼표로 구분된 리스트로 만들려면 쉼표로 구분된 리스트를 달라고 명시적으로 요청하세요. 모델이 답을 모를 때 "모르겠습니다" 유사한 다른 답을 내지 않고 그냥 "모르겠습니다" 라는 답을 하기를원한다면 확실하지 않으면 "모르겠습니다" 라고 말하라고 지시를 하세요.

 

* 더 나은 예를 제공하세요. prompt에서 example을 보여주는 경우 이 예제가 다양한 경우를 커버하고 있는지 그리고 고품질인지를 한번 더 살펴 보세요.

 

* 모델에게 전문가 처럼 대답하라고 요청하세요. (그런 답변 스타일을 원한다면). 전문가가 output을 작성하라고 모델에게 명시적으로 요청하면 모델은 전문가가 작성할 것 같은 형태로 답변을 하려고 합니다. 그렇게 함으로서 모델로부터 좀 더 전문가 스러운 답변을 얻을 수 있습니다. 

 

* 모델에게 그 이유를 단계적으로 설명하도록 prompt에 요청하세요. 예를 들어 너의 대답에 "Let's think step by step" 을 답 앞에 붙이라고 할 수 있습니다. 답변전에 모델이 추론한 내용에 대해 그 이유를 설명하고 근거를 제공하도록 모델에게 prompt 하면 최종 답변이 일관되고 정확할 가능성이 높아집니다.

 

 

반응형