Prompt Engineering เป็นศาสตร์ที่เกี่ยวกับการออกแบบ Prompt หรือคำสั่ง ที่จะชี้นำโมเดลภาษา (Language Model) ให้ผลิตผลลัพท์ที่เราต้องการ เวลาที่เราออกแบบ Prompt สำหรับงานที่ซับซ้อน เราจำเป็นต้องให้โมเดลมีเวลาในการคิด และแตกงานที่ซับซ้อนออกเป็นขั้นตอนย่อย เนื่องจากโมเดลภาษา LLM ต้องการเวลาในการประมวผลข้อมูล และตอบคำถาม เช่นเดียวกับมนุษย์

ยกตัวอย่างเช่น มนุษย์ ใช้เวลาในการ คุณเลข 5 x 6 แค่ 1 วินาที แต่ใช้เวลา 10 วินาที ในการคูณเลข 55 x 65 แล้วใช้เวลามากขึ้นเรื่อย ๆ สำหรับการคูณเลข 555 x 656 โมเดลภาษาก็ต้องการเวลาเพิ่มเช่นกัน แต่เราจะมีวิธีเขียน Prompt บอกโมเดลให้ใช้เวลาคิดเพิ่มเต็มที่เลยได้ยังไง

เทคนิคที่ 5 Chain of Thought Prompting

A common metal short-link chain. Credit: https://commons.wikimedia.org/wiki/File:Broad_chain_closeup.jpg
A common metal short-link chain. Credit: https://commons.wikimedia.org/wiki/File:Broad_chain_closeup.jpg

Chain-of-thought (CoT) Prompting เป็นเทคนิคที่ถูกใช้ใน Prompt Engineering เพื่อการชักนำโมเดลภาษา Language Model ผ่านขั้นตอนพินิจพิเคราะห์ พินิจพิจารณา วิเคราะห์อย่างถี่ถ้วน ก่อนที่จะไปถึงผลลัพท์ที่ต้องการ

CoT Prompt คือ การแตกงานเป็นขั้นย่อย ๆ แต่ละขั้นจะทำต่อจากขั้นตอนก่อนหน้า ในการที่จะช่วยให้โมเดลเข้าใจ ภาพรวมวัตถุประสงค์ของงาน และปะติดปะต่อคำตอบที่สอดคล้องได้

Chain-of-thought prompting enables large language models to tackle complex arithmetic, commonsense, and symbolic reasoning tasks. Chain-of-thought reasoning processes are highlighted. Credit: https://ar5iv.labs.arxiv.org/html/2201.11903
Chain-of-thought prompting enables large language models to tackle complex arithmetic, commonsense, and symbolic reasoning tasks. Chain-of-thought reasoning processes are highlighted. Credit: https://ar5iv.labs.arxiv.org/html/2201.11903

ด้วยการให้โมเดลมีเวลาคิดมากขึ้น และการใช้ CoT Prompt เราสามารถช่วยให้โมเดลเข้าใจงานได้ดีขึ้น และสร้างคำตอบที่แม่นยำ ตรงประเด็นมากขึ้น ช่วยเพิ่มประสิทธิภาพโดยรวมของโมเดล LLM ทำให้เหมาะสำหรับการนำไปประยุกต์ใช้ในงานที่หลากหลาย เช่น การประมวลผลภาษาธรรมชาติ Natural Language Process, ถามตอบ Question Answering และ การแปลภาษา Language Translation

Example inputs and outputs of GPT-3 with Zero-shot-CoT. Similar to Few-shot-CoT, Zero-shot-CoT facilitates multi-step reasoning (blue text) and reach correct answer where standard prompting fails. Credit: https://arxiv.org/abs/2205.11916
Example inputs and outputs of GPT-3 with Zero-shot-CoT. Similar to Few-shot-CoT, Zero-shot-CoT facilitates multi-step reasoning (blue text) and reach correct answer where standard prompting fails. Credit: https://arxiv.org/abs/2205.11916

Zero Shot Chain of Thought (Zero-shot-CoT) Prompting คือ Chain of Thought แต่แทนที่เราจะต้องเป็นคนเขียน Prompt ยาว ๆ แตกงานให้โมเดลทำทีละขั้น เราก็สั่งให้โมเดลเป็นคนแตกงานเอง โดยให้แสดงวิธีทำ หรือ Let’s think step by step

Prompt แบบปกติทั่วไป

ในงานที่มีการวิเคราะห์ ใช้เหตุผล อย่างซับซ้อน หลายขึ้นตอน

A card is chosen at random from a deck of 52 playing cards.

There are 4 Queens and 4 Kings in a deck of playing cards.

What is the probability the card chosen is a Queen or a King?

โมเดลถึงกับไม่เข้าใจคำถาม คิดออกทะเลไปเรื่อย

There are 8 cards in total that are either a Queen or a King in a standard deck of 52 playing cards.

The probability of choosing a Queen or a King can be calculated as the sum of the probabilities of choosing a Queen and choosing a King, minus the probability of choosing both a Queen and a King (since there are 4 cards that are both a Queen and a King).

So, the probability of choosing a Queen or a King is:

P(Queen or King) = P(Queen) + P(King) - P(Queen and King)

P(Queen or King) = (4/52) + (4/52) - (4/52 × 4/51)

P(Queen or King) = 8/52 - 16/2652

P(Queen or King) = 8/52 - 2/663

P(Queen or King) = 2/13 - 1/331.5

P(Queen or King) ≈ 0.3077

Therefore, the probability of choosing a Queen or a King from a deck of 52 playing cards is approximately 0.3077.

Prompt จงแสดงวิธีทำ Step by Step

บอกโมเดลว่า จงแสดงวิธีทำ หรือ Let’s think step by step เรียกว่า Zero Shot Chain of Thought (Zero-shot-CoT) prompting

A card is chosen at random from a deck of 52 playing cards.

There are 4 Queens and 4 Kings in a deck of playing cards.

What is the probability the card chosen is a Queen or a King?

Let's think step by step.

เมื่อเราสั่งอย่างชัดเจนว่า ให้คิดทีละขั้นทีละสเต็ป โมเดลจะมีเวลาคิดมากขึ้น ก็จะวิเคราะห์โจทย์อย่างถี่ถ้วน แตกงานเป็นขั้นตอนย่อย ๆ เอง

Sure, let's break down the problem into steps:

Step 1: Find the total number of cards in a deck.

A standard deck of playing cards has 52 cards.

Step 2: Find the number of Queens and Kings in a deck.

There are 4 Queens and 4 Kings in a deck.

Step 3: Find the number of cards that are either Queens or Kings.

To find the number of cards that are either Queens or Kings, we need to add the number of Queens and the number of Kings:

Number of Queens or Kings = Number of Queens + Number of Kings = 4 + 4 = 8

Step 4: Find the probability of drawing a Queen or a King.

The probability of drawing a Queen or a King is equal to the number of cards that are either Queens or Kings divided by the total number of cards in the deck:

Probability of drawing a Queen or a King = Number of Queens or Kings / Total number of cards
= 8 / 52
= 2 / 13

Therefore, the probability of drawing a Queen or a King from a deck of 52 playing cards is 2/13.

จนกระทั่ง ปะติดปะต่อคำตอบที่ถูกต้อง ออกมาในที่สุด

เรามาเริ่มกันเลยดีกว่า

Open In Colab

Credit

แชร์ให้เพื่อน:

Surapong Kanoktipsatharporn on FacebookSurapong Kanoktipsatharporn on LinkedinSurapong Kanoktipsatharporn on Rss
Surapong Kanoktipsatharporn
Solutions Architect at Bua Labs
The ultimate test of your knowledge is your capacity to convey it to another.

Published by Surapong Kanoktipsatharporn

The ultimate test of your knowledge is your capacity to convey it to another.