1 of 55

ChatGPT สร้างขึ้นมาได้อย่างไร และจะนำไปใช้กับงานในอาชีพสาย Digital ได้อย่างไร

ดร. กอบกฤตย์ วิริยะยุทธกร

นายกสมาคม ผู้ประกอบการปัญญาประดิษฐ์ประเทศไทย (AIEAT)

บริษัท ไอแอพพ์เทคโนโลยี จำกัด (iApp)

https://aieat.or.th | https://iapp.co.th

2 of 55

ChatGPT Development Steps

  1. Empty Weight
  2. GPT-3
  3. InstructGPT
  4. Reinforcement Learning�With Human Feedback�(RLHF)
  5. ChatGPT
  6. Add Safety Net

https://lifearchitect.ai/chatgpt/

3 of 55

GPT-3 Pretraining

Decoder-only�Transformers Architecture

Large Language�Corpus (~600 Billion tokens)

WebText2

Large Language Model�(LLM)

Pretraining

My name is Julien and I like to

My name is Julien and I like to use C#, which is all I really know. In the C# universe, I have two C# friends, Dan and Kevin. I have two boys. Dan is obsessed with C# and when

Gen

4 of 55

Instruct GPT Finetuning

Large Language Model�(LLM)

Fine Tuned LLM that can�follow instruction.

InstructGPT

13K Training Set Prompts

Why is it important to eat socks after meditating?

Gen

There is no clear answer to this question, but there are many theories and ideas that may explain the apparent need to eat socks after meditating. …

Finetuning

https://arxiv.org/abs/2203.02155

5 of 55

Reward Model (RM)

RM dataset has 33k training prompts

Classifier

RM Model

Classify

  • 7: Great Response!
  • Appropriate
  • No Sexual Content
  • No insult

Training

https://arxiv.org/abs/2203.02155

6 of 55

Reinforcement Learning from Human Feedback (RLHF)

InstructGPT

RM Model�(Learned from Human Feedback)

Reinforcement Learning:�Proximal Policy

Optimization (PPO)

Adjust Gradient

Prompt�Input

Prompt�Output

  • 7: Great Response!
  • Appropriate
  • No Sexual Content
  • No insult

31K Prompt for PPO�Training

Generated�Human Feedback

Quality Score : 1.0��Finetuning

Inference

Inference

https://arxiv.org/abs/2203.02155

7 of 55

https://arxiv.org/abs/2203.02155

8 of 55

Deep Dive into Transformers

9 of 55

Transformer: Overview

10 of 55

Transformer: Overview

Nx

Nx

11 of 55

Transformer: Overview

Nx

Nx

12 of 55

Transformer: Overview

Attention is all You Need. https://arxiv.org/pdf/1706.03762.pdf

13 of 55

Transformer: Overview

Attention is all You Need. https://arxiv.org/pdf/1706.03762.pdf

14 of 55

Inputs Embedding & Positional Encoding

ช่วย

เขียน

จดหมาย

ให้

ฉัน

หน่อย

นะ

Input Text

<eos>

ช่วย

เขีย

จด

หมา

ให้

ฉัน

หน่อ

นะ

Byte Pair Encoding

Input Ids

[[ 8867, 358, 271, 385, 624, 284, 20436, 450, 274, 923, 278, 1488, 271, 406, 4746]]

Padding�max_legth=256

[[ 8867, 358, 271, 385, 624, 284, 20436, 450, 274, 923, 278, 1488, 271, 406, 4746, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, …, 0]]

Input Embedding

512 dim

0.56

-0.23

0.50

0.11

-0.45

….

0.30

-0.12

0.10

0.51

-0.25

….

0.56

-0.23

0.50

0.11

-0.45

….

0.30

-0.12

0.10

0.51

-0.25

….

0.56

-0.23

0.50

0.11

-0.45

….

0.30

-0.12

0.10

0.51

-0.25

….

512�(d)

256 (n)

0

0

0

0

0

….

0

0

0

0

0

….

0

0

0

0

0

….

15 of 55

Word Embedding

512 dim

0

1

0

1

..

0.30

-0.12

0.10

0.51

-0.25

….

0.56

-0.23

0.50

0.11

-0.45

….

0.30

-0.12

0.10

0.51

-0.25

….

0.56

-0.23

0.50

0.11

-0.45

….

0.30

-0.12

0.10

0.51

-0.25

….

512 (d)

256(n)

0

0

0

0

0

….

0

0

0

0

0

….

0

0

0

0

0

….

Positional�Encoding

0.56

-0.23

0.50

0.11

-0.45

….

0.8414

0.5403

0.8218

0.5696

+

+

Input Layer�Before Enter Encoder

0.56

0.77

0.50

1.11

..

1.1414

0.4203

0.9218

0.3196

..

=

=

...

...�...

...�...

16 of 55

Transformer: Softmax

Attention is all You Need. https://arxiv.org/pdf/1706.03762.pdf

17 of 55

Softmax and Output Probabilities

512 Dim x 256 Length

30,000 words �(Dictionary Size)

Words

Prob

la

0.1222

le

0.9513

lu

0.0211

….

30,000�words

18 of 55

Softmax and Output Probabilities

19 of 55

Softmax and Output Probabilities

Loop until reaching�<eos> or max_length

20 of 55

Transformer: Encoder Block

Attention is all You Need. https://arxiv.org/pdf/1706.03762.pdf

21 of 55

Encoder Block Internal: Self-Attention

Q K V

W1

W2

22 of 55

Weight แปลง Text → Query ปรับให้ it เข้าใกล้ animal

Weight แปลง Text → Key ให้ animal ปรับให้เข้าใกล้ it

For example:

“The animal didn’t …..”

The animal

Weight Value ปรับให้การเชื่อมโยงให้เด่นชัดหาก Concept Q,K ใกล้กัน

https://jalammar.github.io/illustrated-transformer/

23 of 55

Ref: Secrets of ChatGPT (Prachya Boonkwan)

24 of 55

Ref: Secrets of ChatGPT (Prachya Boonkwan)

25 of 55

Ref: Secrets of ChatGPT (Prachya Boonkwan)

26 of 55

Encoder Block Internal:�Self-Attention

https://storrs.io/multihead-attention/#:~:text=Multi%2Dhead%20attention%20allows%20for,quite%20simple.

27 of 55

Ref: Secrets of ChatGPT (Prachya Boonkwan)

28 of 55

Ref: Secrets of ChatGPT (Prachya Boonkwan)

29 of 55

Ref: Secrets of ChatGPT (Prachya Boonkwan)

30 of 55

Transformer: Encoder Block

Attention is all You Need. https://arxiv.org/pdf/1706.03762.pdf

31 of 55

Ref: Secrets of ChatGPT (Prachya Boonkwan)

32 of 55

Ref: Secrets of ChatGPT (Prachya Boonkwan)

33 of 55

Ref: Secrets of ChatGPT (Prachya Boonkwan)

34 of 55

Ref: Secrets of ChatGPT (Prachya Boonkwan)

35 of 55

Ref: Secrets of ChatGPT (Prachya Boonkwan)

36 of 55

Softmax and Output Probabilities (Revisited)

Loop until reaching�<eos> or max_length

37 of 55

Three Types of Transformer Architectures

BERT

Masked Language Model�

  • Extractive QA
  • Sequence Classification
  • Inference
  • Token Classification

GPT

Casual Language Model

  • Predict Next Word
  • Can be conditional training

BART

Neural Machine Translation

  • Machine Translation

Ref: Secrets of ChatGPT (Prachya Boonkwan)

38 of 55

BERT

  • BERT (Bidirectional Encoder Representation from Transformer) is a language model developed by Google, capable of natural language processing and supervised classifier.
  • Encoder-Only Architecture
  • 340 Million parameters
  • Sequence Classification, Token Classification, Extractive QA, etc…

https://arxiv.org/abs/1810.04805

39 of 55

GPT-3

  • GPT-3 (Generative Pre-trained Transformer 3) is a language model developed by OpenAI, capable of natural language processing and generation.
  • Decoder-Only Architecture
  • 175 billion parameters
  • Text completion, Question-answering, Language translation, Summarization

https://dzlab.github.io/ml/2020/07/25/gpt3-overview/

40 of 55

InstructGPT

41 of 55

InstructGPT

https://arxiv.org/abs/2203.02155

42 of 55

InstructGPT

https://arxiv.org/abs/2203.02155

43 of 55

InstructGPT

https://arxiv.org/abs/2203.02155

44 of 55

InstructGPT

https://arxiv.org/abs/2203.02155

45 of 55

InstructGPT

https://arxiv.org/abs/2203.02155

46 of 55

Reward Model Training

https://arxiv.org/abs/2203.02155

47 of 55

48 of 55

สายอาชีพ Digital ใช้ยังไง?

ให้ช่วยเราให้เร็วที่สุด

49 of 55

Project Manager / Software Analyst : JSON → Table

50 of 55

Customer Service: Bullet → Email

51 of 55

Customer Service: Code Refactoring

52 of 55

Customer Service: Fixing Bugs

53 of 55

Write down Stable Diffusion Prompt

Prompt: “Beautiful car”

Prompt: “Generate an image of a beautiful car in a mid-journey setting that looks realistic and evokes a sense of adventure and freedom. The car should be moving on a scenic road, with a natural environment and beautiful landscapes in the background. The lighting and weather conditions should be appropriate for the location and time of day, creating a …”

https://ai.iapp.co.th/product/image_generation

54 of 55

Open Thai ChatGPT?

  • คนไทยเราควรมี Technology นี้ของตัวเอง
  • สมาคม AIEAT + AIAT กำลังเริ่มต้นทำร่วมกันโดย Open Dataset, Open Weight, Open Model Architecture ให้ใครๆไปใช้ต่อยอดได้ (PoC กำลังออกเร็วๆนี้)
  • ที่ขาดอยู่
    • Pretraining Model ขนาดใหญ่ที่ Train บนภาษาไทยที่เป็นแบบ Auto-regressive
      • รวบรวม Corpus ภาษาไทยที่มีคุณภาพขนาดใหญ่ เป็นข้อมูล Pre-training Dataset
      • GPU Training Server
    • InstructGPT Dataset ภาษาไทย
      • อย่างน้อย 30K คู่ Prompt
      • เว็บไซด์ช่วย Tags
    • Reward Model Classifier
      • อย่างน้อย 30K คู่ Prompt
      • เว็บไซด์ช่วย Tags
  • สนใจช่วย ลงทะเบียน?�

55 of 55

Q/A

ดร. กอบกฤตย์ วิริยะยุทธกร

kobkrit@iapp.co.th / kobkrit@aieat.or.th

นายกสมาคม ผู้ประกอบการปัญญาประดิษฐ์ประเทศไทย

บริษัท ไอแอพพ์เทคโนโลยี จำกัด