This repository contains Jupyter notebooks demonstrating the fine-tuning of various language models for different tasks. The notebooks cover the following:
- Fine-tuning BERT for Sentiment Analysis: This notebook demonstrates how to fine-tune the BERT model for sentiment classification on the Stanford IMDB reviews dataset. It covers standard fine-tuning and PEFT (Parameter-Efficient Fine-Tuning) with LoRA (Low-Rank Adaptation).
- Fine-tuning Llama-3 for Text Classification: This notebook showcases the fine-tuning of the Llama-3 model for text classification. It utilizes a custom trainer class to replace the default loss function with cross-entropy, suitable for classification tasks.
- Fine-tuning Llama-3 for Text Generation: This notebook explores fine-tuning the Llama-3 model for text generation using a dataset of English instructions. It combines quantization and LoRA (QLoRA) for efficient training with a minimal subset of parameters.
Quantization is a technique that reduces the precision of model weights to save memory and computational resources. In this context, it involves converting 32-bit floating-point weights to 4-bit integers. While this reduces precision, it often has a minimal impact on model performance.
LoRA (Low-Rank Adaptation) is a method for efficiently fine-tuning large language models. Instead of updating all model parameters, LoRA introduces low-rank matrices to specific layers. This allows for task-specific adjustments without modifying the original pre-trained weights, making it more efficient and less prone to overfitting.
QLoRA combines quantization and LoRA for even more efficient fine-tuning. By quantizing the model weights, QLoRA further reduces memory usage and computational cost, making it suitable for training large models on limited hardware.
To run these notebooks, you'll need the following libraries installed:
- transformers
- datasets
- evaluate
- torch
- trl (for some notebooks)
- huggingface_hub (for some notebooks)
- bitsandbytes (for some notebooks)
- Clone the repository:
git clone https://github.com/your-username/your-repository
- Install requirements:
pip install -r requirements.txt
- Obtain a Hugging Face API token: Create a Hugging Face account and generate an API token.
- Run the notebooks: Open the desired notebook in a Jupyter notebook environment and execute the cells.
- The notebooks use a combination of standard fine-tuning and PEFT techniques to achieve efficient training and improve model performance.
- Some notebooks require specific datasets and configurations. Refer to the individual notebook README files for detailed instructions.
- The code includes comments and explanations for each step to aid understanding.
Note: Replace your-username
and your-repository
with your actual GitHub username and repository name.