การเตรียมข้อมูลสำหรับ fine-tuning

Fine-Tuning กับ Llama 3

Francesca Donadoni

Curriculum Manager, DataCamp

การใช้ชุดข้อมูลสำหรับ fine-tuning

  • คุณภาพของข้อมูล คือหัวใจสำคัญ

  • Training Set:

    • สำหรับฝึกโมเดล
    • ใช้ข้อมูลส่วนใหญ่

แผนภาพชุดข้อมูลที่แสดง training set

Fine-Tuning กับ Llama 3

การใช้ชุดข้อมูลสำหรับ fine-tuning

  • คุณภาพของข้อมูล คือหัวใจสำคัญ

  • Training Set:

    • สำหรับฝึกโมเดล
    • ใช้ข้อมูลส่วนใหญ่
  • Validation Set:
    • สำหรับเลือกเวอร์ชันโมเดลที่ดีที่สุด

แผนภาพแสดง training set และ validation set

Fine-Tuning กับ Llama 3

การใช้ชุดข้อมูลสำหรับ fine-tuning

  • คุณภาพของข้อมูล คือหัวใจสำคัญ

  • Training Set:

    • สำหรับฝึกโมเดล
    • ใช้ข้อมูลส่วนใหญ่
  • Validation Set:
    • สำหรับเลือกเวอร์ชันโมเดลที่ดีที่สุด
  • Test Set:
    • สำหรับประเมินประสิทธิภาพของโมเดล

แผนภาพแสดง training set, validation set และ test set

Fine-Tuning กับ Llama 3

การเตรียมข้อมูลด้วยไลบรารี datasets

 

  • ไลบรารี Datasets
  • การเตรียมข้อมูล (Preprocessing)
  • การแบ่ง (Split)
  • การโหลด (Load)
  • การจัดการหน่วยความจำ

แผนภาพแสดงกระบวนการไหลของข้อมูล จากชุดข้อมูลเข้าสู่ไลบรารี datasets ซึ่งมี 3 กล่องสีเขียวสำหรับการเตรียมข้อมูล การโหลด/จัดการข้อมูล และการเชื่อมต่อ จากนั้นลูกศรชี้ไปยังผลลัพธ์ที่เป็นกล่องแสดงข้อมูลที่เตรียมพร้อมแล้ว

Fine-Tuning กับ Llama 3

การโหลดชุดข้อมูลบริการลูกค้า

from datasets import load_dataset

ds = load_dataset( 'bitext/Bitext-customer-support-llm-chatbot-training-dataset',
split="train"
)
print(ds.column_names)
['flags', 'instruction', 'category', 'intent', 'response']
Fine-Tuning กับ Llama 3

สำรวจข้อมูลเบื้องต้น

import pprint
pprint.pprint(ds[0])
{'category': 'ORDER',
 'flags': 'B',
 'instruction': 'question about cancelling order {{Order Number}}',
 'intent': 'cancel_order',
 'response': "I've understood you have a question regarding canceling order "
             "{{Order Number}}, and I'm here to provide you with the "
             'information you need. Please go ahead and ask your question, and '
             "I'll do my best to assist you."}
Fine-Tuning กับ Llama 3

การกรองชุดข้อมูล

from datasets import load_dataset, Dataset

ds = load_dataset(
    'bitext/Bitext-customer-support-llm-chatbot-training-dataset',
    split="train")

print(ds.shape)
(26872, 5)
first_thousand_points = ds[:1000]

ds = Dataset.from_dict(first_thousand_points)
Fine-Tuning กับ Llama 3

การเตรียมชุดข้อมูล

def merge_example(row):

row['conversation'] = f"Query: {row['instruction']}\nResponse: {row['response']}" return row
ds = ds.map(merge_example)
print(ds[0]['conversation'])
Query: question about cancelling order {{Order Number}}
Response: I've understood you have a question regarding canceling order {{Order Number}}, 
and I'm here to provide you with the information you need. Please go ahead and ask your 
question, and I'll do my best to assist you.
Fine-Tuning กับ Llama 3

การบันทึกชุดข้อมูลที่เตรียมแล้ว

ds.save_to_disk("preprocessed_dataset")
Saving the dataset (1/1 shards): 100%
26872/26872 [00:00<00:00, 383823.33 examples/s]
from datasets import load_from_disk
ds_preprocessed = load_from_disk("preprocessed_dataset")
Fine-Tuning กับ Llama 3

การใช้ชุดข้อมูล Hugging Face กับ TorchTune

 

  • สามารถใช้ชุดข้อมูล Hugging Face กับ TorchTune ได้
  • กำหนด path และการตั้งค่าชุดข้อมูล

 

tune run full_finetune_single_device --config llama3/8B_full_single_device \
dataset=preprocessed_dataset dataset.split=train
Fine-Tuning กับ Llama 3

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

Fine-Tuning กับ Llama 3

Preparing Video For Download...