Skip to main content

Use Fine-Tuning to Improve Performance

Learning Objectives

After completing this unit, you’ll be able to:

  • List the benefits of fine-tuning.
  • Explain the challenges of fine-tuning.
  • Describe when to use fine-tuning.

Why Fine-Tuning?

Smaller, fine-tuned models can sometimes perform better than larger, more expensive models at the specific tasks they are trained for. They can also enhance the performance of the original model. Here are some benefits of using fine-tuning.

Task-Specific Expertise

Use Specialized Vocabulary

LLMs come with a broad vocabulary from their pretraining. However, specialized tasks often have unique terms and jargon. Fine-tuning introduces and reinforces such vocabulary, ensuring the model understands and uses it appropriately.

Consider an LLM used for diagnosing diseases based on medical transcripts. This LLM, fine-tuned with medical data, will offer far superior performance compared to the base model, which lacks the required medical knowledge. Therefore, fine-tuning becomes indispensable when dealing with specialized fields, sensitive data, or unique information that isn't well-represented in the general training data.

Utilize Contextual Understanding

General models might lack depth in specific subjects. By fine-tuning on task-specific content, the model gains a deeper, more nuanced understanding of the subject, enabling more accurate and insightful responses.

Cost Efficiency

Promote Computational Savings

Training a model on the scale of GPT-4 from scratch requires significant computational resources and time. By leveraging a pretrained model and fine-tuning it, you’re effectively reusing most of the computation done during the pretraining phase, saving time and resources.

Increase Data Efficiency

Fine-tuning typically requires a smaller dataset than training from scratch. This is crucial, especially in unique tasks where gathering vast amounts of data is challenging or expensive.

Customization and Flexibility

Tailor to Specific Applications

Every business or application might have unique requirements. Fine-tuning allows for customization, ensuring the model aligns well with the specific use-cases, such as generating personalized marketing content or understanding user-generated content on their platform.

Promote Data Sensitivity and Compliance

Businesses handling sensitive data or operating under strict regulatory environments might need to fine-tune a model to ensure it respects privacy requirements, adheres to content guidelines, and generates appropriate responses that comply with industry regulations.

Adapt to a Tone and Style

If a company wants a model to communicate in a specific tone (such as formal, playful, or empathetic), fine-tuning on data with that tone can help achieve this.

Improve the User Experience

A fine-tuned model can offer a better user experience by generating more accurate, relevant, and context-aware responses leading to increased customer satisfaction, in applications like:

  • Chatbots
  • Virtual assistants
  • Customer support systems

Ethical and Safety Considerations

Mitigate Biases

When a model’s general behavior or outputs are found to be biased or problematic, fine-tuning on curated datasets can help in reducing such biases.

Filter Unwanted Outputs

For applications where certain outputs are undesirable, for instance, child-friendly applications, fine-tuning can help in refining the model’s outputs to stay within safe bounds.

Exclude Sensitive data

Be careful when creating your dataset that no sensitive data is included. Although this may give better results it exposes the data to be used in the wrong way or circumstance.

Continuous Improvement

Iterate Feedback Loops

Post-deployment, user interactions with the model can be collected (while respecting privacy norms) and used as feedback. Periodic fine-tuning based on this feedback ensures the model remains aligned with user needs and continuously improves.

Competitive Advantage

Enable Differentiation

In a market where multiple entities might be using similar base models, fine-tuning offers a way to stand out, creating a model variant that’s unique and possibly better suited to a specific clientele or task.

When to Use Fine-Tuning?

The decision to fine-tune an LLM hinges on several factors, including your specific use case, the associated costs, and the desired level of domain specificity.

For general tasks such as answering questions or summarizing documents, pretrained models like GPT-3.5, which are readily available via APIs, yield satisfactory results. Moreover, leveraging these APIs is a cost-effective solution.

However, for tasks involving heavy data processing or requiring a specific level of expertise, fine-tuning may be the way to go. It empowers the model to comprehend and generate text in alignment with a specific field’s expert knowledge, thereby enhancing the quality of outputs significantly.

Challenges and Considerations

If fine-tuning is so great, why isn’t every LLM fine-tuned for every specialization you can think of? The answer is that there is a lot that goes into the process and criteria for fine-tuning. Here are some of the cons that should be considered.

Overfitting

A major concern in fine-tuning is when a model is trained too closely on a small dataset. It might perform exceptionally well on that dataset but poorly on unseen data.

Catastrophic Forgetting

Incorrect fine-tuning might cause the model to “forget” some of its previous general knowledge, making it less effective outside the specialized domain.

Dataset Bias

If the fine-tuning dataset contains biases, these can be passed on to the model. This causes the model to learn the same inaccuracies and biases. Biases can come from different sources, such as selection, sampling, label, or historical bias.

  • Selection bias: The data selected for fine-tuning does not represent the full diversity of the problem space.
  • Sampling bias: The data is collected in a way that some members of the intended population are less likely to be included than others.
  • Label bias: The annotations or labels provided in the fine-tuning dataset are influenced by subjective opinions or stereotypes.
  • Historical bias: The data reflects historical or societal inequities that are inherently unfair or problematic.

Hyperparameter Selection

The wrong hyperparameter settings used while fine-tuning can hinder the model’s performance or even make it untrainable.

Sum It Up

Fine-tuning isn’t just about making a model “work” for a specific task; it’s about optimizing performance, ensuring relevance, achieving cost efficiencies, and tailoring outputs for both functional and ethical reasons. Here are the main factors to look at when considering fine-tuning.

  • Does your task need specialized expertise?
  • Do you have the specialized dataset for the fine-tuning?
  • Do you have the resources, time, and computing power?

Resources

Share your Trailhead feedback over on Salesforce Help.

We'd love to hear about your experience with Trailhead - you can now access the new feedback form anytime from the Salesforce Help site.

Learn More Continue to Share Feedback