Điều chỉnh tham số Llama 3

Làm việc với Llama 3

Imtihan Ahmed

Machine Learning Engineer

Tham số dùng để làm gì?

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

Kiểm soát chất lượng, độ ngẫu nhiên và độ dài

Làm việc với Llama 3

Tham số dùng để làm gì?

  • Ví dụ: tạo mô tả sản phẩm

professional_site.png

→ Cần chính xác và súc tích

 

Trang theo phong cách sống

 

→ Cần hấp dẫn và sáng tạo

Làm việc với Llama 3

Tham số giải mã Llama 3

$$

  • Điều chỉnh hành vi của Llama

$$

  • Dùng tham số giải mã để phù hợp các giọng điệu khác nhau

$$

  • Biến đầu ra thô thành văn bản dễ đọc

Điều chỉnh hành vi Llama bằng tham số

Làm việc với Llama 3

Tham số giải mã Llama 3

$$

  • Temperature: kiểm soát độ ngẫu nhiên
  • Top-K: giới hạn chọn token ở các lựa chọn có xác suất cao nhất
  • Top-P: điều chỉnh chọn token theo xác suất tích lũy
  • Max tokens: giới hạn độ dài phản hồi

$$

Screenshot 2025-02-26 at 12.51.27.png

Làm việc với Llama 3

Temperature

  • Giá trị thường từ 0 đến 1

  • Nhiệt độ thấp (ví dụ, gần 0):

    • Phản hồi dự đoán hơn
      A smartwatch with a heart rate monitor, GPS, and a long-lasting battery 
      for all-day tracking.
      
  • Nhiệt độ cao (ví dụ, gần 1):
    • Phản hồi sáng tạo hơn
      Your personal fitness coach on your wrist - track every heartbeat, every step, 
      and every adventure without limits.
      
Làm việc với Llama 3

Top-k

  • Giới hạn số từ có khả năng cao nhất mà Llama có thể chọn

  • Giá trị k thấp (ví dụ, 1):

    • Phản hồi dự đoán hơn
      Track fitness, stream music, and receive notifications with our sleek smartwatch.
      
  • Giá trị k cao (ví dụ, 50):

    • Phản hồi đa dạng hơn
      Experience the future with our cutting-edge smartwatch, featuring fitness tracking, music streaming, customizable notifications, personalized insights, and seamless smartphone integration always.
      
Làm việc với Llama 3

Top-p

  • Kiểm soát chọn từ đầu ra dựa trên độ tự tin

  • Giá trị top-p cao (ví dụ, gần 1):

    • Phản hồi đa dạng hơn
      Stay connected with our sleek smartwatch, featuring fitness tracking,
      music, and customizable notifications, perfect for fitness 
      enthusiasts and busy professionals.
      
  • Giá trị top-p thấp (ví dụ, gần 0):

    • Ít biến thiên
      Smartwatch with fitness tracking and music control, perfect for workouts.
      
Làm việc với Llama 3

Max tokens

  • Dùng để giới hạn độ dài phản hồi
  • Số lượng token - đơn vị từ - trong phản hồi

  • Giá trị max_tokens thấp:

    Stay connected with our sleek smartwatch, featuring fitness tracking 
    and music control.
    
  • Giá trị max_tokens cao:
    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.
    
Làm việc với Llama 3

Kết hợp các tham số

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.
Làm việc với Llama 3

Kết hợp các tham số

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 ...
Làm việc với Llama 3

Ayo berlatih!

Làm việc với Llama 3

Preparing Video For Download...