การปรับพารามิเตอร์ของ Llama 3

การทำงานกับ Llama 3

Imtihan Ahmed

Machine Learning Engineer

พารามิเตอร์มีไว้เพื่ออะไร?

from llama_cpp import Llama
llm = Llama(model_path="path/to/model.gguf")
output = llm("What are some ways to improve customer retention?")

ควบคุมคุณภาพ ความสุ่ม และความยาวของผลลัพธ์

การทำงานกับ Llama 3

พารามิเตอร์มีไว้เพื่ออะไร?

  • ตัวอย่าง: การสร้างคำอธิบายสินค้า

professional_site.png

→ ควรกระชับและตรงไปตรงมา

 

เว็บไซต์สไตล์ไลฟ์สไตล์

 

→ ควรน่าสนใจและสร้างสรรค์

การทำงานกับ Llama 3

Decoding parameters ของ Llama 3

$$

  • ปรับพฤติกรรมของ Llama

$$

  • ใช้ decoding parameters เพื่อปรับโทนให้เหมาะสม

$$

  • แปลงผลลัพธ์ดิบให้อ่านได้

การปรับพฤติกรรมของ Llama ด้วยพารามิเตอร์

การทำงานกับ Llama 3

Decoding parameters ของ Llama 3

$$

  • Temperature: ควบคุมความสุ่ม
  • Top-K: จำกัดการเลือก token ให้อยู่ในตัวเลือกที่น่าจะเป็นมากที่สุด
  • Top-P: ปรับการเลือก token ตามความน่าจะเป็นสะสม
  • Max tokens: จำกัดความยาวของคำตอบ

$$

Screenshot 2025-02-26 at 12.51.27.png

การทำงานกับ Llama 3

Temperature

  • ค่าโดยทั่วไปอยู่ระหว่าง 0 ถึง 1

  • Temperature ต่ำ (เช่น ใกล้ 0):

    • คำตอบคาดเดาได้มากขึ้น
      A smartwatch with a heart rate monitor, GPS, and a long-lasting battery 
      for all-day tracking.
      
  • Temperature สูง (เช่น ใกล้ 1):
    • คำตอบสร้างสรรค์มากขึ้น
      Your personal fitness coach on your wrist - track every heartbeat, every step, 
      and every adventure without limits.
      
การทำงานกับ Llama 3

Top-k

  • จำกัดจำนวนคำที่ Llama สามารถเลือกได้จากตัวเลือกที่น่าจะเป็นมากที่สุด

  • ค่า k ต่ำ (เช่น 1):

    • คำตอบคาดเดาได้มากขึ้น
      Track fitness, stream music, and receive notifications with our sleek smartwatch.
      
  • ค่า k สูง (เช่น 50):

    • คำตอบหลากหลายมากขึ้น
      Experience the future with our cutting-edge smartwatch, featuring fitness tracking, music streaming, customizable notifications, personalized insights, and seamless smartphone integration always.
      
การทำงานกับ Llama 3

Top-p

  • ควบคุมการเลือกคำในผลลัพธ์ตามระดับความมั่นใจ

  • ค่า top-p สูง (เช่น ใกล้ 1):

    • คำตอบหลากหลายมากขึ้น
      Stay connected with our sleek smartwatch, featuring fitness tracking,
      music, and customizable notifications, perfect for fitness 
      enthusiasts and busy professionals.
      
  • ค่า top-p ต่ำ (เช่น ใกล้ 0):

    • คำตอบหลากหลายน้อยลง
      Smartwatch with fitness tracking and music control, perfect for workouts.
      
การทำงานกับ Llama 3

Max tokens

  • ใช้จำกัดความยาวของคำตอบ
  • นับจำนวน token ซึ่งเป็นหน่วยของคำในคำตอบ

  • ค่า max_tokens ต่ำ:

    Stay connected with our sleek smartwatch, featuring fitness tracking 
    and music control.
    
  • ค่า max_tokens สูง:
    Stay connected with our sleek smartwatch, featuring fitness tracking, 
    music control, customizable notifications, and seamless smartphone 
    integration. Monitor your health, track your progress, and receive 
    alerts on your wrist. Perfect for fitness enthusiasts.
    
การทำงานกับ Llama 3

การใช้พารามิเตอร์หลายตัวร่วมกัน

llm = Llama(model_path="path/to/model.gguf")

output_concise = llm(
    "Describe an electric car.",

temperature=0.2,
top_k=1,
top_p=0.4,
max_tokens=20
)
A fast, eco-friendly electric car with a long range and cutting-edge technology.
การทำงานกับ Llama 3

การใช้พารามิเตอร์หลายตัวร่วมกัน

output_creative = llm(
    "Describe an electric car.",

temperature=0.8,
top_k=10,
top_p=0.9,
max_tokens=100
)
Glide into the future with an electric car that blends speed, luxury,
and sustainability. Silent yet powerful, it redefines the road ...
การทำงานกับ Llama 3

มาฝึกกันเถอะ!

การทำงานกับ Llama 3

Preparing Video For Download...