Skip to main content

[LLM 4/10] DPO: When a Language Model Becomes Its Own Reward Model

· 7 min read
Kobkrit Viriyayudhakorn
CEO, iApp Technology

In the last chapter we did RLHF with PPO, and you saw how many moving parts it has — a separate reward model to train, four models resident in VRAM at once, a dozen-plus PPO hyperparameters to tune, and if the reward model is off, the policy finds a shortcut that games the score. In this chapter we'll accomplish the same thing with an ordinary supervised training loop — no reward model, no RL. And crucially, this is not an approximation. We'll prove algebraically that those two pieces genuinely cancel out.

[LLM 5/10] GRPO: Deleting the Value Network and Letting a Group of Answers Be Its Own Baseline

· 9 min read
Kobkrit Viriyayudhakorn
CEO, iApp Technology

The last chapter ended on DPO's gap: it can only rank answers someone prepared in a file. And chapter 3 paid PPO's full price: 4 models in VRAM, plus an entire value network to train on the side. This chapter combines the good halves of both — the model samples its own answers to learn from, genuine RL — but deletes the value network wholesale, using a statistical observation so simple it's almost irritating nobody framed it sooner: if you sample several answers to the same problem, the group's mean reward is already the baseline the value network was trying to estimate. And if the problem can be graded by code, we need no human preference data at all — zero pairs, zero baht.

[LLM 6/10] Context Distillation: Moving the System Prompt into the Model's Weights

· 8 min read
Kobkrit Viriyayudhakorn
CEO, iApp Technology

Every time a user messages your chatbot, you attach the same system prompt, hundreds of tokens long — every request, for the lifetime of the system, paid again and again with no end. This chapter moves that block of knowledge from the prompt into the model's weights, using a technique called Context Distillation in its on-policy version (OPCD). The most beautiful part: the teacher and the student are the exact same model — the only thing that differs is who gets to see the prompt.

[LLM 7/10] Model Distillation: The Teacher's Wrong Answers Are the Most Valuable Part

· 8 min read
Kobkrit Viriyayudhakorn
CEO, iApp Technology

In chapter 6 we distilled a context into the weights of the same model. In this chapter we distill an entire model into a smaller one. The two chapters are a deliberate pair: context distillation changes what the model knows without having to tell it anymore — model distillation changes the size of the model while trying not to change what it can do. And the heart of this chapter cuts hard against intuition: the most valuable thing a teacher can hand its student is not the right answer, but the way the teacher is wrong — and the dial called temperature is what makes that visible.

[LLM 8/10] Guardrails: The Real Safety Fence Isn't a Model, It's a Threshold

· 7 min read
Kobkrit Viriyayudhakorn
CEO, iApp Technology

The Thai chatbots my team and I deploy for real customers don't only meet polite questions — people ask for recipes for illegal things, people try to trick the bot into insulting others, and there was a day the model volunteered a customer's phone number all by itself. In this chapter we build protection in both directions: a classifier that checks incoming prompts for danger and an outbound PII filter. But the central point of the chapter isn't the model — it's the fact that a guardrail is a threshold decision under asymmetric costs, and the "94% accuracy" figure people love to show off is very nearly meaningless.

[LLM 9/10] Benchmarking: An Accuracy Number Without a Confidence Interval Is a Rumor

· 7 min read
Kobkrit Viriyayudhakorn
CEO, iApp Technology

Since chapter 1, this series has repeated the same sentence every time it reports a number: "accuracy without a confidence interval is not an experimental result, it's a rumor" — and promised a full explanation in chapter 9. This is that chapter. We won't train a single step. Instead we'll build a three-mode evaluation system from scratch, put every checkpoint trained across the series on real Thai exams, and prove that the settings nobody writes down in papers move the very same model's score by more than the leaderboard gaps people argue about.

[LLM 10/10] Deployment: You're Not Waiting on Compute, You're Waiting on Weights to Travel

· 8 min read
Kobkrit Viriyayudhakorn
CEO, iApp Technology

Across nine chapters we've injected knowledge, taught format, arranged preferences, distilled models, kept models from breaking, and measured honestly. But even our best model is still just a checkpoint file that nobody can call. This final chapter puts it into real service, and proves the single sentence that governs every decision in LLM serving: decoding one token at a time is not limited by compute power, it is limited by memory bandwidth — we'll compute the speed ceiling from the GPU's datasheet before writing a single line of code, then measure the real thing against it.

รวบรวม Link สำหรับเรียนรู้ Transformer สำหรับ SuperAIEngineer Season 3

· 3 min read
Kobkrit Viriyayudhakorn
CEO, iApp Technology

Schedule​

27 Feb 2023

13:00–13:05 แนะนำว่าโจทย์ QA คืออะไร และ Transformer เอาไปอะไรได้บ้าง
13:05–14:00 NLP Core Knowledge
14:00–14:05 — — Brain Break — —
14:05–15:00 Transformer Core Knowledge
15:00–15:05 — — Brain Break — —
15:05–16:00 Colab 1 (Preprocessing + Text Class) + Colab สร้าง QA
16:00–16:15 Q/A Session

— —

28 Feb 2023
09:00–10:00 Colab 2 (NE + POS+ WS + SS)
10:00–10:05 — — Brain Break — —
10:05–11:00 How ChatGPT Build and Works?
11:00–11:05 — — Brain Break — —
11:05–12:00 Colab: Making Your Own ChatGPT (As the way we did on OpenThaiGPT 0.0.1) + Colab: Reinforcement Learning with Human Feedback (RLHF)
12:00–12:15 Q/A Session + OpenThaiGPT Open for Volunteers.

โจทย์ QA​

อะไรคือ QA: https://ai.iapp.co.th/product/thai_automatic_qa
Colab สร้าง QA: https://colab.research.google.com/drive/1inDOJzCh-iG3_aAU-73tq3FzlCwM8nvY

NLP Core Knowledge​

Slide (Basic NLP -> Word Embbeding -> LSTM): https://drive.google.com/file/d/14AVefnJvgaNXWw6wo-kpmHQyjLAikMgp/view?usp=sharing

Transformer Core Knowledge​

Slide​

Slide (Thai NLP in Transformers Era): https://drive.google.com/file/d/1-V-Gy45c7vHQ4GejvWDBHk0w9oJ4z18I/view?usp=sharing

Colab​

Colab 1 (Preprocessing + Text Class): https://colab.research.google.com/drive/1fGKoS1WH6dbw3mYffOgTtdmPN2Wi9doF?usp=sharing
Colab 2 (NE + POS+ WS + SS): https://colab.research.google.com/drive/1CWamaQH1Lgd7mSZ0UZ4jx2AUMAGDpsfq?usp=sharing#scrollTo=cvrnEG4mOm1p

ChatGPT Core Knowledge​

Website​

https://openthaigpt.aieat.or.th/

Slide​

Slide (ChatGPT: How it works?): https://docs.google.com/presentation/d/1Q6_S_GDWHuNC0DfprNMn9EH0kyqK_y-RbdK5fJB6EUk/edit#slide=id.g1f3418062d6_0_156

Slide (OpenThaiGPT):
https://docs.google.com/presentation/d/1JJxtwo1pCJC3u6aSfslSp1FJSb5ZS5xBKIiQ-6Kip_g/edit?usp=sharing

Colab
Finetuning OpenThaiGPT version POC 0.0.1:
https://colab.research.google.com/drive/1MA1FHwknrs6mVstOHcSyFTnDNWrus-G-?usp=sharing

RLHF: สอนให้ Model Generate ข้อความเชิงบวก (Positive Sentiment) ได้มากขึ้นด้วย PPO https://colab.research.google.com/drive/1qce78Q00SY7CKXLVtiSGFbP5C1V_nypn?usp=sharing


รวบรวม Link สำหรับเรียนรู้ Transformer สำหรับ SuperAIEngineer Season 3 was originally published in Kobkrit on Medium, where people are continuing the conversation by highlighting and responding to this story.

แจกวิธี Train Thai Question Answering AI ใช้ Wangchanberta บน Dataset iApp QA โดย Simple Transformer

· 2 min read
Kobkrit Viriyayudhakorn
CEO, iApp Technology

แจกวิธี Train Thai Question Answering AI ใช้ Wangchanberta บน Dataset iApp QA โดย Simple Transformer​

How to make Thai QA System using SimpleTransformer

Colab:

https://colab.research.google.com/drive/1inDOJzCh-iG3_aAU-73tq3FzlCwM8nvY#scrollTo=vLChKnukd3gC


แจกวิธี Train Thai Question Answering AI ใช้ Wangchanberta บน Dataset iApp QA โดย Simple… was originally published in Kobkrit on Medium, where people are continuing the conversation by highlighting and responding to this story.

แจกไบเบิ้ล วิธีการ Finetune BERT, Roberta, Wangchanberta สำหรับงาน NLP ภาษาไทยแบบง่าย พร้อมแจกโค้ดบน Colab!!

· 4 min read
Kobkrit Viriyayudhakorn
CEO, iApp Technology

แจกไบเบิ้ล วิธีการ Finetune BERT, Roberta, Wangchanberta สำหรับงาน NLP ภาษาไทยแบบง่าย พร้อมแจกโค้ดบน Colab!!​

ชุดซอฟต์แวร์ Transformer จาก Huggingface (https://huggingface.co/) เป็นศูนย์รวม Software, Model และ Datasets ในการใช้ Transformer ทางด้าน NLP ที่ยอดนิยมที่สุดในโลก สนับสนุนทางภาษาไทยและภาษาอังกฤษ และทุกภาษาทั่วโลก

การใช้งานชุดซอฟต์แวร์ Transformer จาก Huggingface นี้ ต้องมีความรู้เฉพาะทางของแต่ละ Model ในตระกูล Transformer และต้องเรียนรู้ API ของ Huggingface ต่างๆ อาทิเช่น Datasets, Trainer, Tokenizer, Inference API ที่ต้องใช้เวลาและการเรียนรู้ค่อนข้างนาน (แต่ก็ดีกว่าไป Clone GIT Repo ของ Transformer แต่ละตัวมาแล้วมาเรียนรู้และเล่นเอง ไปหลายขุมแล้ว)

เพื่อที่จะให้ผู้ที่ทำการเรียนรู้ สามารถนำ Model Transformer นำไปใช้งานได้อย้างรวดเร็ว โดยที่เข้าใจถึงพัฒนาการของงาน NLP จาก One-hot Encoding, Word2Vec, LSTM, Encoder & Decoder และ Transformers ได้ด้วยนั้น

สอน NLP Processing + Toolkits ที่ค่าย Super AI Engineer Season 2 ระหว่างวันที่ 14–15 กุมภาพันธ์ 2565

ทางผมได้รับเชิญ ให้สอนวิธีการพัฒนา AI เหล่านี้ในค่าย Super AI Engineer Season 2 ผู้เข้าร่วมประมาณ 130 ท่าน จัดโดยสมาคมปัญญาประดิษฐ์ประเทศไทย (AIAT) ระหว่างวันที่ 14–15 กุมภาพันธ์ 2565โดยสอนวิธีการสร้าง Model AI ด้าน NLP ตั้งแต่วิธี Basic จนถึงการใช้ Word2Vec, LSTM, BERT, Roberta และสอน Finetune โมโดลโดยการใช้ Tensorflow Keras, Pytorch และสุดท้าย Finetune บนซอฟต์แวร์ชุด Simple Transformer (https://simpletransformers.ai)/ซึ่งเป็นชุดซอฟต์แวร์ที่ที่ทำให้เรา Finetune Model บนข้อมูลบน Pandas ได้โดยง่าย โดยไม่ต้องเขียน Data Class หรือใช้ Data loader บนงาน NLP ภาษาไทยและอังกฤษได้ ซึ่งใน Colab มีตัวอย่างตั้งแต่

  1. Text Cleaning
  2. Text Classification
  3. Text Similarity
  4. Word Segmentation
  5. Name Entity Recognition (NER)
  6. Part of Speech Tagging (POS)
  7. Sentence Segmentation

พร้อมตัวอย่างใช้งานได้จริงผ่าน Notebook บน Google Colaboratory ใน 2 Links นี้

NLP Preprocessing + Text Classification (Monday 14 Feburary)
https://bit.ly/sai2-nlp1

NE + POS + WS + SS (Tuesday 15 Feburary)
https://bit.ly/sai2-nlp2

และสุดท้ายสอนการ Upload Model และ Tokenizer ขึ้นที่หน้าเว็บไซด์ของ Huggingface อีกด้วย ในท้ายของวันที่ 15 Faburary

ใครสนใจลองเข้าไปเรียนรู้ดูได้ หากเจอข้อผิดพลาดอะไร สามารถแจ้งมาที่ได้เลย มาจะทำการ Update แก้ไขให้ครับ

Colab ตัวนี้เป็นแบบ MIT license สามารถใช้ในการแจกจ่าย ดัดแปลง ไปใช้ในทางธุรกิจ อะไรได้หมดเลยครับ ทางผมยินดีครับ ขอบคุณครับ


แจกไบเบิ้ล วิธีการ Finetune BERT, Roberta, Wangchanberta สำหรับงาน NLP ภาษาไทยแบบง่าย… was originally published in Kobkrit on Medium, where people are continuing the conversation by highlighting and responding to this story.