> ## Documentation Index
> Fetch the complete documentation index at: https://docs.refuel.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# Overview

### What is LLM Finetuning?

Finetuning is the process of taking a pre-trained language model (LLM) and further training it on a specific dataset to adapt it to a particular task or domain. This involves adjusting the model's weights based on the new data, allowing it to learn patterns and nuances specific to the desired domain.

### Benefits of Finetuning

Finetuning offers several advantages when compared to using the base LLM directly:

* **Improved Performance**: By training the model on task-specific data, finetuning can significantly enhance the model's performance on that task, leading to more accurate and relevant outputs.
* **Customization**: Finetuning allows for the customization of the model to better align with specific requirements, such as industry jargon, user preferences, output style and format etc.
* **Efficiency**: Once finetuned, the model can generate more precise results without needing extensive context in the input. This means lower token usage, making it faster and cheaper.

### When to Finetune

Consider finetuning a base LLM in the following scenarios:

* **Specialized Tasks**: When the task requires domain-specific knowledge or terminology that the base model may not be familiar with.
* **High Accuracy Requirements**: When the application demands high accuracy and precision, such as in medical diagnosis, legal document analysis, or financial forecasting.
* **Consistent Output**: When consistent and reliable output is crucial, and in-context learning may not provide the necessary stability.

### Prompt engineering vs Few-shot learning vs Finetuning

When leveraging LLMs for specific tasks, you have multiple strategies to improve performance:

* **Prompt Engineering**: The practice of crafting precise and optimized input prompts to achieve desired model outputs without modifying the underlying model.
* **Few-shot Learning**: This involves providing the LLM with a few examples (input and expectedoutput pairs) along the guidelines in the prompt. One way to think about few-shot (in-context learning) is that it is a form of "reasoning by analogy".
* **Finetuning**: This involves adjusting the LLM’s parameters by training it on a domain-specific or task-specific dataset.

Each strategy has its own trade-offs and is best leveraged at different stages of development ([image credit](https://x.com/karpathy/status/1655994367033884672)):

<img src="https://mintcdn.com/refuelai/Ro4ZLj7W42QNS-H_/images/finetuning/finetuning.png?fit=max&auto=format&n=Ro4ZLj7W42QNS-H_&q=85&s=bd2e0db7480002ef1f5e6bf30fbc86e2" alt="Finetuning vs Prompt Engineering" width="2747" height="2023" data-path="images/finetuning/finetuning.png" />
