建立訓練樣本
你的團隊正在打造一個客服聊天機器人,你要建立一個前處理管線,將來會用來微調語言模型,讓模型能預測客戶問題的意圖,並把請求分派到正確的團隊處理。
你拿到一個資料集,客戶問題與意圖分在不同欄位。你想先前處理資料,將每個樣本的問題與意圖,依照你設計的提示格式合併成單一字串。
資料集已載入為 dataset。其中包含 instruction 欄位(客戶問題)與 intent 欄位(使用者意圖)。
本練習屬於課程
使用 Llama 3 進行微調
練習說明
- 建立一個提示字串,格式為
"Query: {instruction}\nIntent: {intent}"。 - 以資料集作為引數,完成函式呼叫,將
create_intent_example套用到每一列。 - 取出並印出資料集第 1 列中
intent_example欄位的值。
動手互動練習
試著完成這個範例程式碼,體驗一下這個練習。
def create_intent_example(row):
# Fill out the columns in the prompt
row['intent_example'] = ____
return row
# Call the ds method to apply our preprocessing function to all rows
processed_dataset = dataset.____(____)
# Print the intent_example in the first row of the processed data
print(processed_dataset[____][____])