微調整用の前処理

Llama 3 のファインチューニング

Francesca Donadoni

Curriculum Manager, DataCamp

微調整にデータセットを使う

  • データ品質が重要

  • 学習用セット:

    • モデル学習に使用
    • データの大半

学習用セットのあるデータセットの図。

Llama 3 のファインチューニング

微調整にデータセットを使う

  • データ品質が重要

  • 学習用セット:

    • モデル学習に使用
    • データの大半
  • 検証用セット:
    • 最良モデルの選択に使用

学習用セットと検証用セットの図。

Llama 3 のファインチューニング

微調整にデータセットを使う

  • データ品質が重要

  • 学習用セット:

    • モデル学習に使用
    • データの大半
  • 検証用セット:
    • 最良モデルの選択に使用
  • テストセット:
    • モデル性能の評価に使用

学習・検証・テスト各セットの図。

Llama 3 のファインチューニング

datasets ライブラリでデータを準備する

 

  • Datasets ライブラリ
  • 前処理
  • 分割
  • 読み込み
  • メモリ管理

データの流れの図。データセットが datasets ライブラリに流れ、前処理・読み込み/管理・統合の緑の3ボックスを経て、準備済みデータの出力ボックスに矢印が向かう。

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']
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."}
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)
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.
Llama 3 のファインチューニング

前処理済みデータセットを保存する

ds.save_to_disk("preprocessed_dataset")
データセットを保存中 (1/1 シャード): 100%
26872/26872 [00:00<00:00, 383823.33 examples/s]
from datasets import load_from_disk
ds_preprocessed = load_from_disk("preprocessed_dataset")
Llama 3 のファインチューニング

Hugging Face データセットを TorchTune で使う

 

  • Hugging Face のデータセットを TorchTune で使用可能
  • データセットパスと設定を指定

 

tune run full_finetune_single_device --config llama3/8B_full_single_device \
dataset=preprocessed_dataset dataset.split=train
Llama 3 のファインチューニング

Let's practice!

Llama 3 のファインチューニング

Preparing Video For Download...