Giter VIP home page Giter VIP logo

finetune-llm's Introduction

Sentiment Analysis with Fine-tuned GPT-2

This project demonstrates the process of fine-tuning the GPT-2 model for sentiment analysis on movie reviews. Utilizing the IMDb dataset, we adjust GPT-2, a model originally designed for text generation, to classify text inputs into positive or negative sentiment categories. This README outlines the steps to prepare the data, fine-tune the model, evaluate its performance, and compare the fine-tuned model against the original GPT-2 model.

Requirements

  • Python 3.8 or later
  • PyTorch
  • Transformers library by Hugging Face
  • Datasets library by Hugging Face
  • Accelerate library for efficient training

Installation

First, ensure that Python and pip are already installed. Then, install the necessary Python packages using the following command:

pip install torch transformers datasets accelerate

Dataset

The IMDb dataset is used, comprising movie reviews labeled as either positive or negative. The dataset is split into training, validation, and test sets, with labels encoded as 0 (negative) and 1 (positive).

Model Training and Evaluation

Data Preparation: Load the IMDb dataset and prepare it for training by tokenizing the text data and encoding the labels.

Model Fine-tuning: Utilize the Trainer class from the Transformers library to fine-tune the GPT-2 model on the sentiment analysis task.

Evaluation: Assess the performance of the fine-tuned model on the test dataset, calculating metrics such as accuracy, precision, recall, and F1 score.

Comparison: Compare the performance of the fine-tuned GPT-2 model against the original, pre-trained GPT-2 model to understand the impact of fine-tuning.

Running the Code

To execute the project, run the Jupyter Notebook script provided, ensuring that the dataset path and other configurations are correctly set according to your environment.

Visualization

The project includes code for visualizing the performance comparison between the original and fine-tuned models, showcasing the effectiveness of the fine-tuning process.

Conclusion

This project highlights the adaptability of pre-trained models like GPT-2 for specific tasks such as sentiment analysis, demonstrating the power of fine-tuning in achieving significant improvements in model performance.

finetune-llm's People

Watchers

GuilleF avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.