This repository contains the code used for fine-tuning a pre-trained BERT model using the Hugging Face Transformers library for sentiment analysis.
- Introduction
- Setup
- Code Structure
- Usage
- Results
- Introduction
This project demonstrates the step-by-step process of fine-tuning a pre-trained BERT model using the Hugging Face Transformers library for sentiment analysis. We use the IMDB dataset and the bert-base-cased model to achieve state-of-the-art results.
- Clone this repository: git clone https://github.com/your-username/fine-tuning-bert.git
- Install the required libraries: pip install transformers torch
- Download the pre-trained bert-base-cased model from Hugging Face: huggingface_hub download bert-base-cased
The code is organized as follows:
- data: contains the IMDB dataset
- models: contains the pre-trained bert-base-cased model and the fine-tuned PEFT model
- train.py: contains the training code for the fine-tuned PEFT model
- inference.py: contains the inference code for the fine-tuned PEFT model
- Train the fine-tuned PEFT model: python train.py
- Run inference on a sample text: python inference.py
The accuracy of the fine-tuned PEFT model is:
- Foundational model without fine tuning: 0.496%
- Training #1: 0.88%
- Training #2: 0.899% Note: The results may vary depending on the system configuration and the dataset used.
This project is licensed under the MIT License.
This project was inspired by the Hugging Face Transformers library and the IMDB dataset.
This repository is used in the blog: Link to the blog
If you have any questions or would like to contribute to this project, please contact me at: m AT kerbachi dot com.