A fine-tuned model is a variant of an existing model adapted with task-specific training data. For example, training on reviews paired with sentiment labels can produce a model specialized in classifying new reviews as positive or negative. It may outperform the original model on that task, but the improvement is not guaranteed. section 1.5.2
Specialization can change what you need to put in a prompt. A general-purpose model needs instructions explaining that a review should receive a class label. A model trained to map reviews to labels can instead receive just the review text. Give that same bare review to the original model, and it may write an analysis rather than return a label. section 9.10 section 9.7
To create and use one through OpenAI:
- Prepare task-specific training data, such as reviews with their intended classifications, and choose a base model. section 1.5.2 section 9.9
- Upload the training file, start a fine-tuning job, and use its job ID to check progress. Once the job succeeds, retrieve the new model ID. section 9.9
- Send the review as a user message through the OpenAI library, specifying the fine-tuned model ID instead of a standard model name. section 9.10
import openai
client = openai.OpenAI()
response = client.chat.completions.create(
model='[Fine-tuned model ID]',
messages=[
{'role':'user', 'content':prompt}
]
)
The request uses the fine-tuned model ID; the prompt variable holds the text to classify. section 9.10
Check the trade-off
In one review-classification run, the fine-tuned model got 7 of 10 labels right without task instructions or examples in each prompt. That was 70% accuracy versus 60% for the earlier version, with about 200 fewer tokens used. Compare results on your own task before committing: fine-tuning takes time and money, and using the resulting model can cost more per token than using its base model. section 9.10 section 9.7
