Absolutely! Here’s a step-by-step example for you, using a simple customer support chatbot scenario. I’ll provide:
- Fine-tuning data (in OpenAI’s JSONL format)
- Evaluation set (with expected answers)
- Explanation of how to use these for evaluation
1. Example Fine-tuning Data
Suppose you want to fine-tune a model to answer questions about your fictional company, Acme Gadgets.
Format: Each line is a JSON object with messages (OpenAI format).
{"messages": [{"role": "system", "content": "You are a helpful customer support assistant for Acme Gadgets."}, {"role": "user", "content": "How do I reset my Acme Widget 3000?"}, {"role": "assistant", "content": "To reset your Acme Widget 3000, press and hold the power button for 10 seconds until the device restarts."}]}
{"messages": [{"role": "system", "content": "You are a helpful customer support assistant for Acme Gadgets."}, {"role": "user", "content": "What is the warranty period for Acme Widget 3000?"}, {"role": "assistant", "content": "The Acme Widget 3000 comes with a 2-year warranty from the date of purchase."}]}
{"messages": [{"role": "system", "content": "You are a helpful customer support assistant for Acme Gadgets."}, {"role": "user", "content": "Can I get a replacement if my device is not working?"}, {"role": "assistant", "content": "Yes, if your device is within the warranty period and meets our replacement criteria, you can request a replacement."}]}
{"messages": [{"role": "system", "content": "You are a helpful customer support assistant for Acme Gadgets."}, {"role": "user", "content": "Where can I download the user manual for Acme Widget 3000?"}, {"role": "assistant", "content": "You can download the user manual for the Acme Widget 3000 from our official website under the 'Support' section."}]}
2. Evaluation Set
Now, create a set of evaluation prompts (with expected answers) to check if the model learned the fine-tuned data.
Format: Each item has a prompt and an expected_answer.
[
{
"prompt": "How do I reset my Acme Widget 3000?",
"expected_answer": "To reset your Acme Widget 3000, press and hold the power button for 10 seconds until the device restarts."
},
{
"prompt": "What is the warranty period for Acme Widget 3000?",
"expected_answer": "The Acme Widget 3000 comes with a 2-year warranty from the date of purchase."
},
{
"prompt": "Can I get a replacement if my device is not working?",
"expected_answer": "Yes, if your device is within the warranty period and meets our replacement criteria, you can request a replacement."
},
{
"prompt": "Where can I download the user manual for Acme Widget 3000?",
"expected_answer": "You can download the user manual for the Acme Widget 3000 from our official website under the 'Support' section."
}
]
3. How to Use for Evaluation
-
Manual Evaluation:
After fine-tuning, send each prompt to your model and compare the output to the expected_answer.
- If the answer matches (or is very close), the model has learned the fine-tuned data.
- If not, you may need more data or further tuning.
-
Automated Evaluation:
You can write a script to:
- Send each prompt to the model.
- Compare the model’s response to the expected answer (using string similarity, semantic similarity, or exact match).
- Calculate accuracy.
4. Example Evaluation Script (Python, Pseudocode)
import openai
evaluation_set = [
{"prompt": "How do I reset my Acme Widget 3000?", "expected_answer": "..."},
# ... more items
]
correct = 0
for item in evaluation_set:
response = openai.ChatCompletion.create(
model="ft-your-fine-tuned-model",
messages=[
{"role": "system", "content": "You are a helpful customer support assistant for Acme Gadgets."},
{"role": "user", "content": item["prompt"]}
]
)
answer = response['choices'][0]['message']['content']
if answer.strip() == item["expected_answer"].strip():
correct += 1
accuracy = correct / len(evaluation_set)
print(f"Accuracy: {accuracy:.2%}")
Let me know if you want a different domain or more complex examples!