使用微调后的模型
模型已经完成微调。现在,您可以在新数据上使用它并生成分类结果。让我们看看微调后的模型在将新的交互打标为低或高流失风险时表现如何。
已为您加载微调后的 model 和 tokenizer。
本练习是课程的一部分
Python 中的 LLM 入门
练习说明
- 对新数据进行分词。
- 将分词后的输入传入微调模型,并禁用梯度。
- 提取新的预测结果。
交互式实操练习
通过完成这段示例代码来试试这个练习。
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}")