Share
Embed
Transcript
48 slides
-
Go와 GPT / PaLM2로 메시지 감정분류 해보기 한성민 / GDG
Golang Korea | ML GDE (feat. Go는 어떤 점이 좋을까?) Go to Busan 2023 -
- MLOps Lead at Riiid - GDE for ML -
GDG Golang Korea Organizer - Python Mentor at F-Lab - Former) Research Engineer at Naver Clova - Former) Software Engineer at 심심이 Speaker Golang Korea ML GDE -
Index • Large Language Model (LLM) • Generative AI •
Go Language • In-context Learning • Emotion Classification App • Q&A -
인간 피드백형 강화학습 (RLHF) 비지도 학습 지도 학습 & 파인튜닝
인간 피드백형 강화학습 Large Language Model (LLM) -
• 2022년 하반기 부터 수 많은 제품 릴리즈 • 대기업,
스타트업 불문하고 제품 출시 • 사람이 보조하고 AI가 주요 작업을 하는.. Landscape Generative AI -
Go언어의 특징 Go Language - Go routine을 이용한 경량 스레드
사용 가능 #코어가 많은 수록 빠름 - 학습 진입장벽이 낮음 #적은 문법 키워드 #직관적인 문법 구조 - 컴파일 속도가 매우매우 빠름! - 빠른 런타임 성능 -
Go언어 키워드 Go Language break default func interface select case
defer go map struct chan else goto package switch const fallthrough if range type continue for import return var 1 2 3 4 5 -
Goroutine Go Language goroutine goroutine goroutine Go Runtime OS Kernel
User Space System Space Syscall -
Goroutine Sample func f(from string) { for i := 0;
i < 3; i++ { fmt.Println(from, ":", i) } } func main() { f("direct") go f("goroutine") go func(msg string) { fmt.Println(msg) }("going") time.Sleep(time.Second) fmt.Println("done") } 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 -
Output $ go run goroutines.go direct : 0 direct :
1 direct : 2 goroutine : 0 going goroutine : 1 goroutine : 2 done 1 2 3 4 5 6 7 8 9 -
Output 1 2 3 4 5 6 7 8 9
$ go run goroutines.go direct : 0 direct : 1 direct : 2 goroutine : 0 going goroutine : 1 goroutine : 2 done -
너는 이제부터 감정 분류사의 역할을 하게 될거야. 입력으로 텍스트가 주어지면,
이를 바탕으로 감정을 예측해주면 돼. 감정은 “매우 긍정”, “긍정”, “매우 부정”, “부정”, “중립”으로 예측해 줘. INPUT: Golang Korea는 한국 고 언어 생태계를 가꾸어나가는 커뮤니티 정신이 바탕이 되는 단체입니다. OUTPUT: 긍정 INPUT: Go 언어 느리고 복잡해서 못써먹겠는 언어같아요. OUTPUT: 부정 감정 분류 Prompt -
System Prompt 너는 이제부터 감정 분류사의 역할을 하게 될거야. 입력으로
텍스트가 주어지면, 이를 바탕으로 감정을 예측해주면 돼. 감정은 “매우 긍정”, “긍정”, “매우 부정”, “부정”, “중립”으로 예측해 줘. INPUT: Golang Korea는 한국 고 언어 생태계를 가꾸어나가는 커뮤니티 정신이 바탕이 되는 단체입니다. OUTPUT: 긍정 INPUT: Go 언어 느리고 복잡해서 못써먹겠는 언어같아요. OUTPUT: 부정 -
Few shots 너는 이제부터 감정 분류사의 역할을 하게 될거야. 입력으로
텍스트가 주어지면, 이를 바탕으로 감정을 예측해주면 돼. 감정은 “매우 긍정”, “긍정”, “매우 부정”, “부정”, “중립”으로 예측해 줘. INPUT: Golang Korea는 한국 고 언어 생태계를 가꾸어나가는 커뮤니티 정신이 바탕이 되는 단체입니다. OUTPUT: 긍정 INPUT: Go 언어 느리고 복잡해서 못써먹겠는 언어같아요. OUTPUT: 부정 -
Test INPUT: Go to Busan은 부산에서 Go 언어를 알리고 정보를
공 유하기 위해 만들어진 지역 커뮤니티 활동입니다. OUTPUT: -
GPT based Emotion Classification Sample 1 2 3 4 5
6 7 8 9 10 11 12 13 14 15 16 17 func main() { api_key := "<REDACTED>" instruct := ` 너는 이제부터 감정 분류사의 역할을 하게 될거야. 입력으로 텍스트가 주어지면, 이를 바탕으로 감정을 예측해주면 돼. 감정은 “매우 긍정”, “긍정”, “매우 부정”, “부정”, “중립”으로 예측해 줘. INPUT: Golang Korea는 한국 고 언어 생태계를 가꾸어나가는 커뮤니티 정신이 바탕이 되는 단체입니다. OUTPUT: 긍정 INPUT: Go 언어 느리고 복잡해서 못써먹겠는 언어같아요. OUTPUT: 부정 ` -
18 19 20 21 22 23 24 25 26 27
28 29 30 31 32 33 34 35 c, _ := gpt35.NewClient(api_key) fmt.Println("INPUT:") in := bufio.NewReader(os.Stdin) line, err := in.ReadString('\n') fmt.Scanln(&line) req := &gpt35.Request{ Model: gpt35.ModelGpt35Turbo, Messages: []*gpt35.Message{ { Role: gpt35.RoleUser, Content: instruct, }, { Role: gpt35.RoleUser, Content: fmt.Sprintf("INPUT:\n%v", line), }, }, } GPT based Emotion Classification Sample -
resp, err := c.GetChat(req) if err != nil { panic(err)
} fmt.Printf("감정 분류 (From INPUT: %v):\n%v", line, resp.Choices[0].Message.Content) } 36 37 38 39 40 41 42 GPT based Emotion Classification Sample -
OUTPUT Emotion Classification App INPUT: 고랭코리아 너무 좋은 것 같아요!
감정 분류 (From INPUT: 고랭코리아 너무 좋은 것 같아요!): OUTPUT: 매우 긍정 -
너는 이제부터 감정 분류사의 역할을 하게 될거야. 입력으로 텍스트가 주어지면,
이를 바탕으로 감정을 예측해주면 돼. 감정은 “매우 긍정”, “긍정”, “매우 부정”, “부정”, “중립”으로 예측해 줘. INPUT: Golang Korea는 한국 고 언어 생태계를 가꾸어나가는 커뮤니티 정신이 바탕이 되는 단체입니다. OUTPUT: 긍정 INPUT: Go 언어 느리고 복잡해서 못써먹겠는 언어같아요. OUTPUT: 부정 Prompt -
You're about to take on the role of a sentiment
classifier. Given a piece of text as input, you'll predict a sentiment based on it. Predict the sentiment as "Very positive", "Positive", "Very negative", "Negative", or "Neutral". INPUT: Golang Korea is a community-minded group that cultivates Go Language ecosystem in Korea. OUTPUT: Positive INPUT: Go language is slow, complicated, and unusable. OUTPUT: Negative Prompt (English) -
PaLM2 on Golang Emotion Classification App Could you make a
golang to run above http request? Don't use aiplatform or VertexAI API, instead of it, Please use plain HTTP request by using Go. -
PaLM2 based Emotion Classification Sample 1 2 3 4 5
6 7 8 9 10 11 12 13 14 15 16 17 18 const ( apiEndpoint = "us-central1-aiplatform.googleapis.com" projectID = "key-utility-388704" modelID = "text-bison@001" ) func main() { // Create a new HTTP client. client := &http.Client{} // Create a new request. req, err := http.NewRequest("POST", fmt.Sprintf("https://%s/v1/projects/%s/locations/us- central1/publishers/google/models/%s:predict", apiEndpoint, projectID, modelID), nil) if err != nil { panic(err) } // Set the authorization header. req.Header.Add("Authorization", fmt.Sprintf("Bearer %s", os.Getenv("GOOGLE_APPLICATION_CREDENTIALS"))) -
PaLM2 based Emotion Classification Sample 19 20 21 22 23
24 25 26 27 28 29 30 31 33 34 35 36 37 req.Header.Add("Content-Type", "application/json") // Set the request body. data := []byte(`{ "instances": [ { "content": "You're about to take on the role of a sentiment classifier. Given a piece of text as input, you'll predict a sentiment based on it. Predict the sentiment as \"Very positive\", \"Positive\", \"Very negative\", \"Negative\", or \"Neutral\". INPUT: Golang Korea is a community-minded group that cultivates Go Language ecosystem in Korea. OUTPUT: Positive INPUT: Go language is slow, complicated, and unusable. -
PaLM2 based Emotion Classification Sample 38 39 40 41 42
43 44 45 46 47 48 49 50 51 52 53 54 OUTPUT: Negative INPUT: Go to Busan 2023 event seems very bad.. It was the worst session ever in my life. OUTPUT:" } ], "parameters": { "temperature": 0.2, "maxOutputTokens": 256, "topP": 0.8, "topK": 40 } }`) -
PaLM2 based Emotion Classification Sample 56 57 58 59 60
61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 req.Body = ioutil.NopCloser(bytes.NewReader(data)) // Send the request. resp, err := client.Do(req) if err != nil { panic(err) } // Close the response body. defer resp.Body.Close() // Read the response body. body, err := ioutil.ReadAll(resp.Body) if err != nil { panic(err) } // Print the response body. fmt.Println(string(body)) } -
{ "predictions": [ { "safetyAttributes": { "scores": [ 0.2, 0.1,
0.1 ], "blocked": false, "categories": [ "Finance", "Toxic", "War & Conflict" ] }, "content": "\n Very negative", "citationMetadata": { "citations": [] } } ] } 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 OUTPUT