T5 Finetuning for SQuAD Question Answering by waqar ahmedT5 Finetuning for SQuAD Question Answering by waqar ahmed

T5 Finetuning for SQuAD Question Answering

waqar ahmed

waqar ahmed

T5 Finetuning for SQuAD Question Answering

This project demonstrates how to finetune a T5 model on the Stanford Question Answering Dataset (SQuAD) for question answering tasks. The code includes data loading, model training, and an interactive QA system.

Table of Contents

Prerequisites

Python 3.7+
pip (Python package installer)

Installation

Clone this repository:
Install the required packages:

Dataset

This project uses the Stanford Question Answering Dataset (SQuAD) v1.1. You need to download the dataset files and place them in the project root directory:
Download dev-v1.1.json

Project Structure

main.py: The main script to run the entire pipeline
data_loading.py: Functions for loading and preprocessing the SQuAD dataset
model_utils.py: Utility functions for initializing the model and tokenizer
training.py: Functions for training the model
qa_utils.py: Utilities for question answering, including an interactive QA system

Usage

To run the entire pipeline (data loading, model training, and interactive QA):
python main.py

This will:
Load the SQuAD dataset
Initialize the T5 model and tokenizer
Train the model on the SQuAD dataset
Save the trained model
Test the model with a sample question
Start an interactive QA session

How It Works

Data Loading: The load_squad function in data_loading.py reads the SQuAD JSON files and converts them into a format suitable for training.
Model Initialization: The initialize_model_and_tokenizer function in model_utils.py loads the pretrained T5 model and tokenizer.
Training: The train_model function in training.py sets up the training arguments, tokenizes the dataset, and trains the model using the Hugging Face Trainer class.
Question Answering: The answer_question function in qa_utils.py takes a question and context, processes them through the model, and returns the generated answer.
Interactive QA: The interactive_qa function in qa_utils.py provides a command-line interface for users to input contexts and questions, and receive answers from the model.

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

License

This project is open source and available under the MIT License.
Like this project

Posted Feb 11, 2025

different transfomers and their uses. Contribute to IM07813/Transformers development by creating an account on GitHub.