CoolFace
Modelpublic

bookbot/wav2vec2-ljspeech-gruut

sourceHugging Faceapache-2.0updated 3y agoView on Hugging Face
16likes6.2kdownloads
Model Card

Wav2Vec2 LJSpeech Gruut

Wav2Vec2 LJSpeech Gruut is an automatic speech recognition model based on the wav2vec 2.0 architecture. This model is a fine-tuned version of Wav2Vec2-Base on the LJSpech Phonemes dataset.

Instead of being trained to predict sequences of words, this model was trained to predict sequence of phonemes, e.g. ["h", "ɛ", "l", "ˈoʊ", "w", "ˈɚ", "l", "d"]. Therefore, the model's vocabulary contains the different IPA phonemes found in gruut.

This model was trained using HuggingFace's PyTorch framework. All training was done on a Google Cloud Engine VM with a Tesla A100 GPU. All necessary scripts used for training could be found in the Files and versions tab, as well as the Training metrics logged via Tensorboard.

Model

Model#paramsArch.Training/Validation data (text)
wav2vec2-ljspeech-gruut94Mwav2vec 2.0LJSpech Phonemes Dataset

Evaluation Results

The model achieves the following results on evaluation:

DatasetPER (w/o stress)CER (w/o stress)
LJSpech Phonemes Test Data0.99%0.58%

Usage

py
from transformers import AutoProcessor, AutoModelForCTC, Wav2Vec2Processor
import librosa
import torch
from itertools import groupby
from datasets import load_dataset

def decode_phonemes(
    ids: torch.Tensor, processor: Wav2Vec2Processor, ignore_stress: bool = False
) -> str:
    """CTC-like decoding. First removes consecutive duplicates, then removes special tokens."""
    # removes consecutive duplicates
    ids = [id_ for id_, _ in groupby(ids)]

    special_token_ids = processor.tokenizer.all_special_ids + [
        processor.tokenizer.word_delimiter_token_id
    ]
    # converts id to token, skipping special tokens
    phonemes = [processor.decode(id_) for id_ in ids if id_ not in special_token_ids]

    # joins phonemes
    prediction = " ".join(phonemes)

    # whether to ignore IPA stress marks
    if ignore_stress == True:
        prediction = prediction.replace("ˈ", "").replace("ˌ", "")

    return prediction

checkpoint = "bookbot/wav2vec2-ljspeech-gruut"

model = AutoModelForCTC.from_pretrained(checkpoint)
processor = AutoProcessor.from_pretrained(checkpoint)
sr = processor.feature_extractor.sampling_rate

# load dummy dataset and read soundfiles
ds = load_dataset("patrickvonplaten/librispeech_asr_dummy", "clean", split="validation")
audio_array = ds[0]["audio"]["array"]

# or, read a single audio file
# audio_array, _ = librosa.load("myaudio.wav", sr=sr)

inputs = processor(audio_array, return_tensors="pt", padding=True)

with torch.no_grad():
    logits = model(inputs["input_values"]).logits

predicted_ids = torch.argmax(logits, dim=-1)
prediction = decode_phonemes(predicted_ids[0], processor, ignore_stress=True)
# => should give 'b ɪ k ʌ z j u ɚ z s l i p ɪ ŋ ɪ n s t ɛ d ə v k ɔ ŋ k ɚ ɪ ŋ ð ə l ʌ v l i ɹ z p ɹ ɪ n s ə s h æ z b ɪ k ʌ m ə v f ɪ t ə l w ɪ θ n b oʊ p ɹ ə ʃ æ ɡ i s ɪ t s ð ɛ ɹ ə k u ɪ ŋ d ʌ v'

Training procedure

Training hyperparameters

The following hyperparameters were used during training:

  • learning_rate: 0.0001
  • train_batch_size: 16
  • eval_batch_size: 8
  • seed: 42
  • gradient_accumulation_steps: 2
  • total_train_batch_size: 32
  • optimizer: Adam with betas=(0.9,0.999) and epsilon=1e-08
  • lr_scheduler_type: linear
  • lr_scheduler_warmup_steps: 1000
  • num_epochs: 30.0
  • mixed_precision_training: Native AMP

Training results

Training LossEpochStepValidation LossWerCer
No log1.03482.28181.01.0
2.66922.06960.20450.05270.0299
0.22253.010440.11620.03190.0189
0.22254.013920.09270.02350.0147
0.08685.017400.07970.02180.0143
0.05986.020880.07150.01970.0128
0.05987.024360.06520.01600.0103
0.04478.027840.05710.01520.0095
0.03689.031320.06080.01630.0112
0.036810.034800.05860.01370.0083
0.030311.038280.06410.01410.0085
0.027312.041760.06560.01310.0079
0.023213.045240.06900.01330.0082
0.023214.048720.05980.01280.0079
0.018915.052200.06710.01210.0074
0.01716.055680.06540.01140.0069
0.01717.059160.07510.01180.0073
0.014618.062640.06530.01120.0068
0.012719.066120.06820.01120.0069
0.012720.069600.06780.01140.0068
0.011421.073080.06560.01110.0066
0.010122.076560.06690.01090.0066
0.009223.080040.06770.01080.0065
0.009224.083520.06530.01040.0063
0.008825.087000.06730.01020.0063
0.007426.090480.06690.01050.0064
0.007427.093960.07070.01010.0061
0.006628.097440.06730.01000.0060
0.005829.0100920.06890.01000.0059
0.005830.0104400.06830.00990.0058

Disclaimer

Do consider the biases which came from pre-training datasets that may be carried over into the results of this model.

Authors

Wav2Vec2 LJSpeech Gruut was trained and evaluated by Wilson Wongso. All computation and development are done on Google Cloud.

Framework versions

  • Transformers 4.26.0.dev0
  • Pytorch 1.10.0
  • Datasets 2.7.1
  • Tokenizers 0.13.2
  • Gruut 2.3.4