使用微調後的模型
模型已經完成微調。現在你可以在新資料上使用它並產生分類結果。來看看你的微調模型在將新互動標記為低風險或高風險流失時表現如何。
已為你載入微調後的 model 與 tokenizer。
本練習屬於課程
Python 的 LLM 入門
練習說明
- 將新資料做分詞與編碼(tokenize)。
- 在停用梯度的情況下,將分詞後的輸入傳入微調後的模型。
- 取出新的預測結果。
動手互動練習
試著完成這個範例程式碼,體驗一下這個練習。
input_text = ["I'd just like to say, I love the product! Thank you!"]
# Tokenize the new data
inputs = ____(____, return_tensors="pt", padding=True, truncation=True)
# Pass the tokenized inputs through the model
with ____:
outputs = ____
# Extract the new predictions
predicted_labels = ____.____(outputs.logits, dim=1).tolist()
label_map = {0: "Low risk", 1: "High risk"}
for i, predicted_label in enumerate(predicted_labels):
churn_label = label_map[predicted_label]
print(f"\n Input Text {i + 1}: {input_text[i]}")
print(f"Predicted Label: {predicted_label}")