Skip to content

A Deep Learning model using Wav2Vec2 and PyTorch to classify English accents (Canadian vs British) from raw audio with over 97% accuracy.

License

Notifications You must be signed in to change notification settings

creativepurus/Accent_Classification

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

30 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

πŸŽ™οΈ Accent Classification using Wav2Vec2

A Deep Learning project that uses HuggingFace's Wav2Vec2 model to classify English audio accents as Canadian πŸ‡¨πŸ‡¦ or British (England) 🏴.

Built with PyTorch, Transformers, and Librosa, this project achieves high accuracy on voice-based accent prediction.


GitHub: Star the Repository GitHub forks Python Version Model

LinkedIn: Connect with Me


βœ… Results

πŸ”₯ Accuracy

🎯 Precision

πŸ” Recall

πŸ“ˆ F1_Score


πŸ€— Try the Live Demo on πŸ‘‰ Hugging Face Spaces

Accent Classification Demo 🧠 Live Accent Classification App deployed on Hugging Face !!


πŸ“Š Model Performance Visualizations

Below are various graphs and charts generated to evaluate and visualize the performance of the Wav2Vec2-based Accent Classifier:

πŸ”Ή Horizontal Bar Chart

Horizontal Bar Chart Class-wise prediction confidence of the model.


πŸ”Ή Training Loss Curve

Training Loss Curve Loss reduction over training epochs showing model learning progress.


πŸ”Ή Confusion Matrix

Confusion Matrix Matrix showing the number of correct and incorrect predictions per class.


πŸ–₯️ Gradio Web App

A sleek, dark-themed Gradio interface has been added to make accent classification interactive and user-friendly!

  • 🎀 Supports both microphone recording and file upload.
  • 🧠 Uses the fine-tuned Wav2Vec2 model for detecting Canadian or British English accents.
  • 🌌 Clean dark mode layout with colorful buttons for a smooth user experience.
  • βœ… Built with gradio==5.38.2.

πŸš€ Simply run app.py to launch the app locally:

python app.py

πŸ”Ή Gradio interface Before Prediction

Gradio interface Before Prediction

πŸ”Ή Gradio interface After Prediction

Gradio interface After Prediction

πŸš€ Features

  • Fine-tuned Wav2Vec2-Large-960h model
  • Custom classification head for binary accent classification
  • Achieved 97.83% Accuracy, 100% Precision, 97.62% F1 Score
  • Audio pre-processing with Librosa & Torchaudio
  • Exportable results in CSV + visualizations
  • Easy-to-use Jupyter Notebook interface

πŸ› οΈ Tech Stack

  • Python
  • PyTorch
  • HuggingFace Transformers
  • Librosa
  • Scikit-learn
  • Matplotlib / Seaborn
  • Git / GitHub

🧰 Setup Instructions

Follow these steps to set up the project on your local machine.

1️⃣ Prerequisites

2️⃣ Clone the Repository

git clone https://github.com/creativepurus/Accent_Classification.git
cd Accent_Classification

3️⃣ Create & Activate a Virtual Environment

# Create venv (do this only once)
python -m venv venv

# Activate venv
# On Windows:
venv\Scripts\activate
# On macOS/Linux:
source venv/bin/activate

4️⃣ Install Dependencies

pip install -r requirements.txt

5️⃣ Run the Jupyter Notebook

jupyter notebook

Open en_model.ipynb and run the cells step-by-step.


πŸ“Š Outputs

  • model_predictions.csv β†’ Stores predictions with confidence
  • Graphs folder β†’ Contains plots like confusion matrix, class-wise distribution
  • Trained model saved to wav2vec2-accent-classifier/

πŸ—‚οΈ Project Structure

Accent_Classification/
β”œβ”€β”€ .github/                      # GitHub workflows, actions, or templates
β”œβ”€β”€ assets/                      # Images or media assets for README or UI
β”œβ”€β”€ Data/                        # Audio + tsv files
β”œβ”€β”€ Graphs/                      # Evaluation plots
β”œβ”€β”€ Model/                       # Saved Model and processor files (auto-created after training)
β”œβ”€β”€ Accent_Detection_Model.ipynb # Main notebook
β”œβ”€β”€ app.py                       # Gradio-based UI Application
β”œβ”€β”€ Code_Explanation.md          # Detailed explanation of model and code
β”œβ”€β”€ LICENSE                      # Project license file
β”œβ”€β”€ README.md                    # Project overview and instructions
β”œβ”€β”€ requirements.txt             # Python dependencies
└── .gitignore                   # Git ignore rules for GitHub

⚠️ Notes

  • Don’t forget to activate your virtual environment before installing packages or running the notebook.
  • Make sure audio files and validated.tsv are placed correctly in the en/ folder.

πŸ§ͺ Future Improvements

  • Add support for more accents (e.g., Australian, Indian, American)
  • Deploy as a full-fledged web app
  • Integrate with Flask/FastAPI for production API

πŸ‘¨β€πŸ’» Author

Made with ❀️ by Anand Purushottam

LinkedIn | GitHub

Love My Work ? You can πŸ‘‰πŸ» BUY ME A COFFEE


πŸ“„ License

This project is licensed under the GNU GENERAL PUBLIC LICENSE.