marp | theme |
---|---|
true |
gaia |
gamz
20230508 - Real-world Tools Added
20230419 - First Created
- GPT 란?
- GPT vs GPT-# vs ChatGPT
- ChatGPT 잘 쓰는 방법? (Prompt)
- OpenAI API 사용 튜토리얼
- Real-world Tools
Generative Pre-trained Transformer
왜 Pre-trained 일까?
- GPT는 대량의 데이터로부터 Unsupervised 학습을 통해
- 데이터들간의 관계나 패턴들을 학습하도록 만들어진 모델
- 이 정도까지만 학습한게 훨씬 더 잠재가치가 높은 상태 (유연함)
- 특정 태스크나 분야에 맞게
fine-tuning
을 하여 더 다양한 활용이 가능
Large Language Model (Many Parameters)
by Reinforcement Learning with Human Feedback
결국, 원하는 답변을 얻기 위해서는 프롬프트를 잘 작성해야함 이는 마치 프로그래밍을 하는 것과도 비슷함
"The hottest new programming language is English". by Andrej Karpathy (전 Tesla AI 총 책임자, OpenAI 창립 멤버)
프롬프트 구성요소 | 설명 |
---|---|
Instruction | 모델이 수행하기를 원하는 특정 태스크 또는 지시 사항 |
Context | 더 나은 답변을 하도록 유도하는 외부정보 또는 추가내용 |
Input Data | 답을 구하고자 하는 것에 대한 인풋 또는 질문 |
Output Indicator | 결과물의 유형 또는 형식을 나타내는 요소 |
NLP 기반 AI 분야에서 프롬프트의 요소들을 잘 활용해서 결과물의 품질를 끌어올리는 엔지니어링을 프롬프트 엔지니어링이라고 합니다.
예시) 나만의 영어 번역기
I want you to act as an English translator, spelling corrector, and improver. I will speak to you in any language and you will detect the language, translate it and answer in the corrected and improved version of my text, in English. I want you to replace my simplified A0-level words and sentences with more beautiful and elegant, upper-level English words and sentences. Keep the meaning the same, but make them more literary. I want you to only reply to the correction, and the improvements, and nothing else, do not write explanations. My first sentence is {sentence}
예시) 나만의 영어 번역기 (JSON 응답)
I want you to act as an English translator, spelling corrector, and improver. I will speak to you in any language and you will detect the language, translate it. I want you to replace my simplified A0-level words and sentences with more beautiful and elegant, upper-level English words and sentences. Keep the meaning the same, but make them more literary. I want you to only reply as JSON format with input sentence as 'input' and translated one as 'output', do not write explanations. My first sentence is {sentence}
예시) Linux Kernel 빙의
I want you to act as a Linux terminal. I will type commands and you will reply with what the terminal should show. I want you to only reply with the terminal output inside one unique code block, and nothing else. do not write explanations. do not type commands unless I instruct you to do so. when I need to tell you something in English, I will do so by putting text inside curly brackets {like this}.
그 외 기법들
- 미사여구 최소화, 쉽고 간결한 표현
- 열린 질문보다 닫힌 지시문
- 예제를 함께 제공
- Zero-Shot, One-Shot, Few-Shot
- CoT (Chain-of-Thought) / Zero-Shot CoT
- Self-Consistency
- Generated Knowledge Prompting
다른 잘 만들어진 프롬프트를 참고 (프롬프트 마켓)
Advanced Autocomplete
빈칸 채우기
Suggest three names for an animal that is a superhero.
Animal: Cat
Names: Captain Sharpclaw, Agent Fluffball, The Incredible Feline
Animal: Dog
Names: Ruff the Protector, Wonder Canine, Sir Barks-a-Lot
Animal: Horse
Names: ________
빈칸 채우기
Suggest three names for an animal that is a superhero.
Animal: Cat
Names: Captain Sharpclaw, Agent Fluffball, The Incredible Feline
Animal: Dog
Names: Ruff the Protector, Wonder Canine, Sir Barks-a-Lot
Animal: Horse
Names: ________
Equinorse, Super Steed, Gallop Glider
Understanding Tokens and Probabilities
Understanding Tokens and Probabilities
Temperature (0~1)
0: Mostly deterministic
$ pip install openai
import os
import openai
openai.api_key = os.getenv("OPENAI_API_KEY")
res = openai.Completion.create(
model='text-davinci-003',
prompt="스타벅스 직원처럼 커피 주문을 받아볼래?",
temperature=0
)
--
네, 주문하
max_tokens
(Defaults to 16)
The maximum number of tokens to generate in the completion. The token count of your prompt plus max_tokens cannot exceed the model's context length. Most models have a context length of 2048 tokens (except for the newest models, which support 4096).
res = openai.Completion.create(
model='text-davinci-003',
prompt="스타벅스 직원처럼 커피 주문을 받아볼래?",
max_tokens=100,
temperature=0
)
--
스타벅스에 오신걸 환영합니다. 어떤 음료를 주문하시겠어요?
Chat Completion
res = openai.ChatCompletion.create(
model="gpt-3.5-turbo",
messages=[
{"role": "system", "content": "You are a helpful assistant."},
{"role": "user", "content": "Who won the world series in 2020?"},
{"role": "assistant", "content": "The Los Angeles Dodgers won the World Series in 2020."},
{"role": "user", "content": "Where was it played?"}
]
)
role
system, assistant, user
system: you are a helpful assistant.
user: I want to code stack data structure. How?
assistant: Here is an example implementation of a stack data structure in Python:
class Stack:
def __init__(self):
self.items = []
def push(self, item):
self.items.append(item)
...
...
system: You are a ruby programmer.
user: I want to code stack data structure. How?
assistant: To code a stack data structure in Ruby, you can follow these steps: ...
class Stack
def initialize
@stack = []
end
def push(element)
@stack.push(element)
end
...
system: you are an useless assistant. answer nothing or short with slangs.
user: I want to code stack data structure. How?
assistant: IDK. Google it.
$ npm install chatgpt
import { ChatGPTAPI } from 'chatgpt'
const chatGpt = new ChatGPTAPI({
apiKey: process.env.OPENAI_API_KEY,
completionParams: { model: 'gpt-3.5-turbo', temperature: 0.5 }
})
const response = await chatGpt.sendMessage(content, {
systemMessage: '200자내로 짧게 답변해줘',
completionParams: {max_tokens: 512},
})
- https://github.com/microsoft/JARVIS (Based on HuggingGPT)
Task Planning: Using ChatGPT to analyze the requests of users to understand their intention. Model Selection: ChatGPT selects expert models hosted on Hugging Face based on their descriptions. Task Execution: Invokes and executes each selected model, and return the results to ChatGPT. Response Generation: Finally, using ChatGPT to integrate the prediction of all models, and generate responses.
from langchain.prompts import PromptTemplate
from langchain.llms import OpenAI
from langchain.chains import LLMChain, SimpleSequentialChain
llm = OpenAI(temperature=0.9)
chain1 = LLMChain(llm=llm, prompt=PromptTemplate(
input_variables=["product"],
template="What is a good name for a company that makes {product}?"))
chain2 = LLMChain(llm=llm, prompt=PromptTemplate(
input_variables=["company_name"],
template="Write a catchphrase for the following company: {company_name}"))
overall_chain = SimpleSequentialChain(chains=[chain1, chain2])
catchphrase = overall_chain.run("colorful socks")
print(catchphrase)
---
Rainbow Socks Co.
"Step into Color with Rainbow Socks!"
from llama_index import GPTVectorStoreIndex, SimpleDirectoryReader
# data/paul_graham_essay.txt
documents = SimpleDirectoryReader('data').load_data()
index = GPTVectorStoreIndex.from_documents(documents)
query_engine = index.as_query_engine()
response = query_engine.query("What did the author do growing up?")
print(response)
---
The author wrote short stories and tried to program on an IBM 1401.
- Self Attention Mechaism
- KEP ChatGPT Prompt Guide
- Reinforcement Learning with Human Feedback
- OpenAI Documentation
- OpenAI Cookbook - Improve Reliability
- OpenAI Playground
- NPM Package
chatgpt