Skip to content

Latest commit

 

History

History
89 lines (66 loc) · 4.44 KB

File metadata and controls

89 lines (66 loc) · 4.44 KB

Code Explanation

Importing Libraries and Modules 📚🔧

  • Imports essential libraries and modules for subsequent machine learning tasks.
  • Includes tools for data manipulation (os, pandas), audio processing (torchaudio), model training (torch, transformers), and visualization (tqdm, seaborn, matplotlib).
  • Imports the Wav2Vec2 model from Hugging Face's Transformers library.

Data Preprocessing 🎛️🔍

  • Loads a TSV file containing information about audio files.
  • Defines a function to load audio files using the torchaudio library.
  • Example usage loads an audio file for demonstration.

Balance the Dataset ⚖️

  • Balances the dataset by selecting specific accents and resampling the data.
  • Class distribution of the balanced dataset is printed.

Data Exploration 📊🔍

  • Explores the dataset by understanding the distribution of classes and listening to audio samples.
  • Provides insights into the distribution of accents and allows for a qualitative understanding of the dataset.

Split the Data 🔄

  • Splits the dataset into training and testing sets.
  • Drops rows with missing values.

Model Selection Code 🤖🔍

  • Loads a pre-trained Wav2Vec2 model and configures it for the classification task.
  • Sets the number of output classes based on the selected accents.

Checking Data Shapes and Imbalance 📊🧐

  • Examines various data-related aspects, including dataset head, shape, and the presence of missing values.
  • Checks the distribution of the "locale" column for insights into potential dataset imbalances.

Data Visualization - Distribution Plot 📊🔍

  • Creates a distribution plot using seaborn to visualize the distribution of the "locale" column in the balanced dataset.

Data Visualization - Distribution Plot (for validated_df) 📊🔍

  • Creates a distribution plot, this time for the original, unbalanced dataset (validated_df).
  • Allows for a comparison of language distribution before and after balancing.

Print All Columns in a Table Format 📊💻

  • Prints all columns in a table format for the filtered dataset.
  • Provides a comprehensive overview of the dataset's structure and content.

Definition of CustomAudioDataset 🎛️🎶

  • Defines a custom dataset class (CustomAudioDataset) to handle audio data.
  • Uses the LabelEncoder to convert string labels to numerical values, facilitating model training.

Create Training Dataset 🎛️🔍

  • Creates a training dataset (train_dataset) using the defined CustomAudioDataset class and the loaded processor.

Create a DataLoader with a Custom Collate Function 🎛️🔍

  • Creates a DataLoader for the training dataset using a custom collate function.
  • The function pads input tensors to the same size and stacks labels, preparing the data for model training.

Split the Data Again 🔄

  • Splits the data again into training and testing sets without stratification.
  • Resulting sets are stored in train_df and test_df.

Create the Test Dataset 🎛️🔍

  • Creates a test dataset (test_dataset) from the testing dataframe (test_df).

Create DataLoader for the Test Set 🎛️🔍

  • Creates a DataLoader for the test dataset using the same custom collate function.

Fine-tuning Setup 🤖⚙️

  • Configures training arguments for fine-tuning.
  • Specifies the output directory, batch size, number of epochs, and saving options.

Create Trainer 🤖🎓

  • Creates a Trainer instance, incorporating the Wav2Vec2 model, training arguments, and the training dataset.
  • Sets the stage for model fine-tuning.

Training Loop with Metric Calculation 🔄🎓📊

  • Initiates the training loop, iterating through epochs and batches.
  • Calculates training metrics, including accuracy, precision, and F1 score.

Final Training Step 🤖🎓

  • Executes the final training step, completing the fine-tuning of the Wav2Vec2 model.

Evaluate Model on the Test Set 🤖🔍🎓

  • Evaluates the trained model on the test set.
  • Collects predictions for further metric calculation and analysis.

Calculate Metrics for the Test Set 📊🎓🔍

  • Calculates metrics, including accuracy, precision, and F1 score based on the model's performance on the test set.

Plot Confusion Matrix for the Test Set 📊🔍

  • Generates a confusion matrix using seaborn and matplotlib.
  • Visually represents the model's classification performance on the test set.