Products

Resources

Impact on AI

Company

Test your LLM's math skills with our benchmark for complex problems and step-by-step reasoning

Test your LLM's math skills with our benchmark for complex problems and step-by-step reasoning

Test your LLM's math skills with our benchmark for complex problems and step-by-step reasoning

Toloka Team

Sep 30, 2024

Sep 30, 2024

Essential ML Guide

Essential ML Guide

Meaningful Interactions with humans: how instruction tuning refines LLMs

Large language models (LLMs) have transformed natural language processing, enabling remarkable capabilities such as text generation, translation, summarization, and more. However, despite their powerful abilities, pre-trained models often struggle to understand user instructions and adapt to specific tasks effectively. Instruction tuning is a fine-tuning technique that enhances an AI's ability to serve as a helpful assistant by making it more responsive to user needs. It aligns LLMs more closely with human needs by training them on prompts and desired outputs datasets.

What is instruction tuning?

Instruction tuning arose from the need to make AI models more user-friendly and capable of handling a wide range of tasks. Traditional models may be great at generating language or performing specific tasks but may struggle to interpret a variety of user instructions effectively. Fine-tuning models on instruction-oriented datasets allows developers to create more versatile AI systems.

In contrast to, for example, supervised fine-tuning (SFT), where a pre-trained model is fine-tuned on a vast labeled dataset, instruction tuning focuses on training a model on a labeled dataset of instructional prompts and their corresponding results. This is done so that the model can follow natural language instructions from users.

The essence of instruction tuning lies not only in its ability to enhance the responsiveness and adaptability of LLMs but also in its ability to improve model performance when dealing with user prompts. The process emphasizes understanding and fulfilling user instructions effectively. It allows models to interpret diverse requests and generate relevant responses, making AI more intuitive and helpful.

All in all, fine-tuning pre-trained models on labeled datasets consisting of diverse instructions and matching outputs helps enhance the model’s general responsiveness and task-solving capabilities.

How instruction tuning works

Pre-trained LLMs simply add text to input prompts without any particular regard for the nature of the input. Instruction tuning modifies the model to understand that the user's input is a request that demands a useful and structured response. In that way, the output becomes more coherent, relevant, and aligned with the user's needs.

It helps make large language models like OpenAI's GPT or Meta's Llama 2 better at following instructions and having conversations. When these models are first trained, they aren't optimized to respond to prompts the way humans would expect. Instead, they’re trained to simply guess the next word in a sequence of text, which might lead to answers that are technically correct but not very helpful.

During pre-training on a vast corpus of training data through self-supervised learning LLMs learn to predict the next word in a sentence over and over. The pre-trained model learns to generate text that sounds natural, but it doesn't understand instructions or how to interact with users in a meaningful way.

Pre-trained models can complete sentences well, but they might not give useful answers. For instance, if you ask, "How do I plant a garden?", a pre-trained LLM may respond with something vague like "In your backyard". Thissentence, doesn't really help user because it's just completing the prompt rather than providing useful instructions.

This is where instruction tuning comes in. By fine-tuning the model on examples of tasks that look like user requests called instruction datasets (e.g., "How do I plant a garden?") and their correct responses (like actual instructions for planting a garden), the model learns to give more helpful, task-related answers.

Training a model from scratch for specific tasks like instruction following would take huge amounts of data, time, and energy. Instead, fine-tuning a model that’s already been trained is much easier and requires fewer resources. It adjusts the model’s behavior without needing to start from the beginning.

During instruction tuning, the model is trained on examples where the input is similar to user prompts (questions or tasks), and the output is what we want the model to say in response. For example, if the prompt is "How do I plant a garden?" the desired response would be an actual gardening instruction. The model becomes better at responding to user requests in practical ways by learning from these examples.

Steps for instruction tuning

LLMs, like OpenAI's GPT, Google's LaMDA-PT and Gemini, IBM's Granite, or Meta's Llama 2, are first trained on massive amounts of text using self-supervised learning, but this pre-training doesn't teach them how to follow specific instructions. Instruction tuning fine-tunes these models by training them on labeled instruction tuning datasets consisting of instruction-following tasks. This means that the model learns from examples where a prompt (or instruction) is paired with the desired response.

Preparing the dataset

Instruction fine-tuning involves several key steps, starting with the preparation of the dataset. This dataset includes examples of natural language instructions, instruction-following tasks sometimes with additional context, paired with the desired output. These examples can either be created manually by humans or generated by other models. Data scientists can also use existing instruction datasets to fine-tune a language model. Each training sample in the instruction tuning dataset contains three parts:

  • Instruction: A clear, natural language request or task;

  • Optional context: Sometimes extra context is provided to help the model complete the task, such as a passage to be summarized or a question to be answered;

  • Desired output: The correct response that the model should generate. This serves as the "ground truth" for the model to learn from and optimize its predictions.

Model training

Afterwards, a pre-trained language model is selected as the base for fine-tuning. These models, which have already learned a lot of information from vast amounts of text data, serve as the foundation. During fine-tuning, the model learns by processing instructions and trying to generate the correct output.

When its predictions don't match the desired output, optimization algorithms adjust its parameters to improve performance. Throughout the process, the model’s performance is monitored using a validation set, which helps prevent overfitting or learning to perform well only on the training data.

In instruction tuning, it's possible to adjust only a subset of the model’s weights rather than updating all of them. This approach allows for more focused adaptation to a new task without disrupting the core knowledge that the model gained during pre-training. By freezing most of the model’s weights and fine-tuning only specific layers or parameters, the model can better maintain its general abilities while becoming specialized for a particular task.

The choice of whether to update all weights or just a portion depends on the specific needs of the task. If the goal is to make the model highly specialized for a new task, updating more weights might be necessary. However, if it’s important to preserve the model’s general capabilities while still improving performance on a specific task, fine-tuning only a subset of weights can strike the right balance.

Model testing

Once the fine-tuning is complete, the model is tested on the test set to evaluate how well it follows instructions it hasn’t seen before. Metrics such as accuracy or BLEU scores (for translation tasks) are used to assess how accurately the model performs. If the results aren’t as expected, the process might be repeated with tweaks to parameters or an expanded dataset to improve the model's ability to generalize to new tasks.

Fine-tuning doesn’t just optimize performance on the tasks used during training; it can also improve the model’s ability to handle instructions it hasn’t encountered before, which enables instruction tuned models to generalize to new types of prompts. Once the model performs satisfactorily, it can be deployed for real-world applications, and its performance can be monitored based on user feedback.

Advantages of instruction tuning

Improved instruction following

Instruction tuning trains models to better understand and respond to natural language instructions, which renders them more useful for task-specific interactions. As a consequence, users get more accurate and relevant results with less need for complex prompts.

Better human-like interaction

Instruction-tuned models exhibit more natural, conversational behavior. They are better at following step-by-step instructions and delivering results in a more human-friendly way, which improves the overall user experience, especially for applications like chatbots or virtual assistants.

Reduced need for prompt engineering

Instruction-tuned models require fewer examples or clarifications (i.e., prompt engineering) to produce high-quality responses. This simplifies interaction for users, while also making the models easier to use.

Flexibility with limited data

Even when a large dataset isn’t available for a specific task, instruction tuning can still improve a model’s ability to follow instructions effectively. Fine-tuning on a smaller, high-quality set of examples can significantly enhance performance.

Efficient use of resources

Instruction tuning typically requires much less data and computational resources than training an LLM from scratch. Fine-tuning on a pre-trained model allows for faster adaptation and task-specific optimization without the need for extensive retraining.

Generalization to new tasks

One of the key benefits of instruction tuning is that it enables models to generalize beyond the tasks they were trained on. A model fine-tuned with instructional data can perform well on novel tasks that weren’t explicitly part of its training, especially if they follow a similar pattern to those seen during fine-tuning.

Limitations of instruction tuning

Computational costs for large language models

Even though instruction tuning is more efficient than training from scratch, fine-tuning very large language models (e.g., with billions of parameters) can still be resource-intensive in terms of GPU/TPU computation and memory usage.

Dependence on quality and diversity of instruction datasets

The success of instruction tuning heavily relies on the quality and variety of the instruction dataset. Creating large, high-quality instruction datasets for fine-tuning is resource-intensive, leading to reliance on a few open-source datasets, which limits model diversity. If the dataset lacks diversity or contains poorly labeled examples, the model’s ability to generalize and follow different types of instructions can be hindered.

Using proprietary models for instruction generation

To mitigate the costs of manual dataset creation, researchers have used larger proprietary LLMs to generate instruction datasets for smaller models. While this approach is more efficient and reduces expenses, it introduces a potential risk: the biases and limitations of the larger models could be inherited by the smaller ones.

Imitation vs. genuine Improvement

A technical concern is whether instruction-tuned smaller models are genuinely improving in their capabilities or merely imitating larger models. When instruction tuning is performed using datasets generated by larger models, smaller models might simply copy stylistic patterns of the larger models, making it seem as though they have improved.

Need for better base models

Rather than relying on instruction tuning as a shortcut to improve models, some researchers argue that the focus should be on developing stronger base models. Fine-tuning techniques can help models specialize, but if the underlying base model lacks strong reasoning, comprehension, or adaptability, then instruction tuning can only go so far.

Future fine-tuning methods will likely be more effective and lead to more genuine performance gains through improving the foundational architecture and training of base models. In other words, this method of improving AI models shouldn’t be seen as a fix for weak base models but rather as an enhancement for strong ones.

Conclusion

Instruction tuning has led to significant advances in LLMs' ability to follow instructions and perform specific tasks. Unlike the initial pre-training phase, which focuses on predicting the next word in a sequence, this type of fine-tuning hones the model's ability to understand and execute detailed instructions. As a result, models become not only more responsive to user requests but also more capable of handling a wide variety of tasks with minimal guidance.

Tuning with instruction data also has limitations. The challenges include the high cost of creating diverse datasets, the risk of reinforcing biases from proprietary models, and the possibility of superficial improvements rather than deeper gains in reasoning. Addressing these challenges may require a shift toward building better base models and more rigorous evaluation methods so that instruction tuning yields genuine, long-lasting improvements in model performance.

The challenges surrounding dataset creation and model biases still exist, but instruction tuning has already proven to be an essential tool for improving language models. As this technique matures and we develop more diverse and high-quality datasets, we can expect even greater advancements in how LLMs interact with, understand, and assist users in an abundance of tasks.

 

Article written by:

Toloka Team

Updated:

Sep 30, 2024

Subscribe to Toloka News

Case studies, product news, and other articles straight to your inbox.

Subscribe

Subscribe
to Toloka News

Case studies, product news, and other articles straight to your inbox.

Subscribe

Subscribe to Toloka News

Case studies, product news, and other articles straight to your inbox.

Subscribe

More about Toloka

What is Toloka’s mission?

Where is Toloka located?

What is Toloka’s key area of expertise?

How long has Toloka been in the AI market?

How does Toloka ensure the quality and accuracy of the data collected?

How does Toloka source and manage its experts and AI tutors?

What types of projects or tasks does Toloka typically handle?

What industries and use cases does Toloka focus on?

What is Toloka’s mission?

Where is Toloka located?

What is Toloka’s key area of expertise?

How long has Toloka been in the AI market?

How does Toloka ensure the quality and accuracy of the data collected?

How does Toloka source and manage its experts and AI tutors?

What types of projects or tasks does Toloka typically handle?

What industries and use cases does Toloka focus on?

What is Toloka’s mission?

Where is Toloka located?

What is Toloka’s key area of expertise?

How long has Toloka been in the AI market?

How does Toloka ensure the quality and accuracy of the data collected?

How does Toloka source and manage its experts and AI tutors?

What types of projects or tasks does Toloka typically handle?

What industries and use cases does Toloka focus on?