m3hrdadfi / wav2vec2-large-xlsr-turkish

huggingface.co
Total runs: 139
24-hour runs: 0
7-day runs: -19
30-day runs: -614
Model's Last Updated: July 06 2021
automatic-speech-recognition

Introduction of wav2vec2-large-xlsr-turkish

Model Details of wav2vec2-large-xlsr-turkish

Wav2Vec2-Large-XLSR-53-Turkish

Fine-tuned facebook/wav2vec2-large-xlsr-53 in Turkish using Common Voice . When using this model, make sure that your speech input is sampled at 16kHz.

Usage

The model can be used directly (without a language model) as follows:

Requirements

# requirement packages
!pip install git+https://github.com/huggingface/datasets.git
!pip install git+https://github.com/huggingface/transformers.git
!pip install torchaudio
!pip install librosa
!pip install jiwer

Prediction

import librosa
import torch
import torchaudio
from transformers import Wav2Vec2ForCTC, Wav2Vec2Processor
from datasets import load_dataset

import numpy as np
import re
import string

import IPython.display as ipd

chars_to_ignore = [
    ",", "?", ".", "!", "-", ";", ":", '""', "%", "'", '"', "�",
    "#", "!", "?", "«", "»", "(", ")", "؛", ",", "?", ".", "!", "-", ";", ":", '"', 
    "“", "%", "‘", "�", "–", "…", "_", "”", '“', '„'
]
chars_to_mapping = {
"\u200c": " ", "\u200d": " ", "\u200e": " ", "\u200f": " ", "\ufeff": " ",
}

def multiple_replace(text, chars_to_mapping):
    pattern = "|".join(map(re.escape, chars_to_mapping.keys()))
    return re.sub(pattern, lambda m: chars_to_mapping[m.group()], str(text))

def remove_special_characters(text, chars_to_ignore_regex):
    text = re.sub(chars_to_ignore_regex, '', text).lower() + " "
    return text

def normalizer(batch, chars_to_ignore, chars_to_mapping):
    chars_to_ignore_regex = f"""[{"".join(chars_to_ignore)}]"""
    text = batch["sentence"].lower().strip()
    
    text = text.replace("\u0307", " ").strip()
    text = multiple_replace(text, chars_to_mapping)
    text = remove_special_characters(text, chars_to_ignore_regex)

    batch["sentence"] = text
    return batch


def speech_file_to_array_fn(batch):
    speech_array, sampling_rate = torchaudio.load(batch["path"])
    speech_array = speech_array.squeeze().numpy()
    speech_array = librosa.resample(np.asarray(speech_array), sampling_rate, 16_000)

    batch["speech"] = speech_array
    return batch


def predict(batch):
    features = processor(batch["speech"], sampling_rate=16_000, return_tensors="pt", padding=True)

    input_values = features.input_values.to(device)
    attention_mask = features.attention_mask.to(device)

    with torch.no_grad():
        logits = model(input_values, attention_mask=attention_mask).logits 
        
    pred_ids = torch.argmax(logits, dim=-1)

    batch["predicted"] = processor.batch_decode(pred_ids)[0]
    return batch


device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
processor = Wav2Vec2Processor.from_pretrained("m3hrdadfi/wav2vec2-large-xlsr-turkish")
model = Wav2Vec2ForCTC.from_pretrained("m3hrdadfi/wav2vec2-large-xlsr-turkish").to(device)

dataset = load_dataset("common_voice", "et", split="test[:1%]")
dataset = dataset.map(
    normalizer, 
    fn_kwargs={"chars_to_ignore": chars_to_ignore, "chars_to_mapping": chars_to_mapping},
    remove_columns=list(set(dataset.column_names) - set(['sentence', 'path']))
)

dataset = dataset.map(speech_file_to_array_fn)
result = dataset.map(predict)

max_items = np.random.randint(0, len(result), 10).tolist()
for i in max_items:
    reference, predicted =  result["sentence"][i], result["predicted"][i]
    print("reference:", reference)
    print("predicted:", predicted)
    print('---')
Output: ```text reference: ülke şu anda iki federasyona üye predicted: ülke şu anda iki federasyona üye
reference: foruma dört yüzde fazla kişi katıldı predicted: soruma dört yüzden fazla kişi katıldı
reference: mobi altmış üç çalışanları da mutsuz predicted: mobia haltmış üç çalışanları da mutsur
reference: kentin mali esnekliğinin düşük olduğu bildirildi predicted: kentin mali esnekleğinin düşük olduğu bildirildi
reference: fouere iki ülkeyi sorunu abartmamaya çağırdı predicted: foor iki ülkeyi soruna abartmamaya çanayordı
reference: o ülkeden herhangi bir tepki geldi mi predicted: o ülkeden herhayın bir tepki geldi mi
reference: bunlara asla sırtımızı dönmeyeceğiz predicted: bunlara asla sırtımızı dönmeyeceğiz
reference: sizi ayakta tutan nedir predicted: sizi ayakta tutan nedir
reference: artık insanlar daha bireysel yaşıyor predicted: artık insanlar daha bir eyselli yaşıyor
reference: her ikisi de diyaloga hazır olduğunu söylüyor predicted: her ikisi de diyaloğa hazır olduğunu söylüyor
reference: merkez bankasının başlıca amacı düşük enflasyon predicted: merkez bankasının başlrıca anatı güşükyen flasyon
reference: firefox predicted: fair foks
reference: ülke halkı çok misafirsever ve dışa dönük predicted: ülke halktı çok isatirtever ve dışa dönük
reference: ancak kamuoyu bu durumu pek de affetmiyor predicted: ancak kamuonyulgukirmu pek deafıf etmiyor
reference: i ki madende iki bin beş yüzden fazla kişi çalışıyor predicted: i ki madende iki bin beş yüzden fazla kişi çalışıyor
reference: sunnyside park dışarıdan oldukça iyi görünüyor predicted: sani sahip park dışarıdan oldukça iyi görünüyor
reference: büyük ödül on beş bin avro predicted: büyük ödül on beş bin avro
reference: köyümdeki camiler depoya dönüştürüldü predicted: küyümdeki camiler depoya dönüştürüldü
reference: maç oldukça diplomatik bir sonuçla birbir bitti predicted: maç oldukça diplomatik bir sonuçla bir birbitti
reference: kuşların ikisi de karantinada öldüler predicted: kuşların ikiste karantinada özdüler


## Evaluation

The model can be evaluated as follows on the Turkish test data of Common Voice.

```python
import librosa
import torch
import torchaudio
from transformers import Wav2Vec2ForCTC, Wav2Vec2Processor
from datasets import load_dataset, load_metric

import numpy as np
import re
import string


chars_to_ignore = [
    ",", "?", ".", "!", "-", ";", ":", '""', "%", "'", '"', "�",
    "#", "!", "?", "«", "»", "(", ")", "؛", ",", "?", ".", "!", "-", ";", ":", '"', 
    "“", "%", "‘", "�", "–", "…", "_", "”", '“', '„'
]
chars_to_mapping = {
    "\u200c": " ", "\u200d": " ", "\u200e": " ", "\u200f": " ", "\ufeff": " ",
    "\u0307": " "
}

def multiple_replace(text, chars_to_mapping):
    pattern = "|".join(map(re.escape, chars_to_mapping.keys()))
    return re.sub(pattern, lambda m: chars_to_mapping[m.group()], str(text))

def remove_special_characters(text, chars_to_ignore_regex):
    text = re.sub(chars_to_ignore_regex, '', text).lower() + " "
    return text

def normalizer(batch, chars_to_ignore, chars_to_mapping):
    chars_to_ignore_regex = f"""[{"".join(chars_to_ignore)}]"""
    text = batch["sentence"].lower().strip()
    
    text = text.replace("\u0307", " ").strip()
    text = multiple_replace(text, chars_to_mapping)
    text = remove_special_characters(text, chars_to_ignore_regex)
    text = re.sub(" +", " ", text)
    text = text.strip() + " "

    batch["sentence"] = text
    return batch


def speech_file_to_array_fn(batch):
    speech_array, sampling_rate = torchaudio.load(batch["path"])
    speech_array = speech_array.squeeze().numpy()
    speech_array = librosa.resample(np.asarray(speech_array), sampling_rate, 16_000)

    batch["speech"] = speech_array
    return batch


def predict(batch):
    features = processor(batch["speech"], sampling_rate=16_000, return_tensors="pt", padding=True)

    input_values = features.input_values.to(device)
    attention_mask = features.attention_mask.to(device)

    with torch.no_grad():
        logits = model(input_values, attention_mask=attention_mask).logits 
        
    pred_ids = torch.argmax(logits, dim=-1)

    batch["predicted"] = processor.batch_decode(pred_ids)[0]
    return batch


device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
processor = Wav2Vec2Processor.from_pretrained("m3hrdadfi/wav2vec2-large-xlsr-turkish")
model = Wav2Vec2ForCTC.from_pretrained("m3hrdadfi/wav2vec2-large-xlsr-turkish").to(device)

dataset = load_dataset("common_voice", "tr", split="test")
dataset = dataset.map(
    normalizer, 
    fn_kwargs={"chars_to_ignore": chars_to_ignore, "chars_to_mapping": chars_to_mapping},
    remove_columns=list(set(dataset.column_names) - set(['sentence', 'path']))
)

dataset = dataset.map(speech_file_to_array_fn)
result = dataset.map(predict)

wer = load_metric("wer")

print("WER: {:.2f}".format(100 * wer.compute(predictions=result["predicted"], references=result["sentence"])))

]

Test Result :

  • WER: 27.51%
Training & Report

The Common Voice train , validation datasets were used for training.

You can see the training states here

The script used for training can be found here

Runs of m3hrdadfi wav2vec2-large-xlsr-turkish on huggingface.co

139
Total runs
0
24-hour runs
0
3-day runs
-19
7-day runs
-614
30-day runs

More Information About wav2vec2-large-xlsr-turkish huggingface.co Model

More wav2vec2-large-xlsr-turkish license Visit here:

https://choosealicense.com/licenses/apache-2.0

wav2vec2-large-xlsr-turkish huggingface.co

wav2vec2-large-xlsr-turkish huggingface.co is an AI model on huggingface.co that provides wav2vec2-large-xlsr-turkish's model effect (), which can be used instantly with this m3hrdadfi wav2vec2-large-xlsr-turkish model. huggingface.co supports a free trial of the wav2vec2-large-xlsr-turkish model, and also provides paid use of the wav2vec2-large-xlsr-turkish. Support call wav2vec2-large-xlsr-turkish model through api, including Node.js, Python, http.

wav2vec2-large-xlsr-turkish huggingface.co Url

https://huggingface.co/m3hrdadfi/wav2vec2-large-xlsr-turkish

m3hrdadfi wav2vec2-large-xlsr-turkish online free

wav2vec2-large-xlsr-turkish huggingface.co is an online trial and call api platform, which integrates wav2vec2-large-xlsr-turkish's modeling effects, including api services, and provides a free online trial of wav2vec2-large-xlsr-turkish, you can try wav2vec2-large-xlsr-turkish online for free by clicking the link below.

m3hrdadfi wav2vec2-large-xlsr-turkish online free url in huggingface.co:

https://huggingface.co/m3hrdadfi/wav2vec2-large-xlsr-turkish

wav2vec2-large-xlsr-turkish install

wav2vec2-large-xlsr-turkish is an open source model from GitHub that offers a free installation service, and any user can find wav2vec2-large-xlsr-turkish on GitHub to install. At the same time, huggingface.co provides the effect of wav2vec2-large-xlsr-turkish install, users can directly use wav2vec2-large-xlsr-turkish installed effect in huggingface.co for debugging and trial. It also supports api for free installation.

wav2vec2-large-xlsr-turkish install url in huggingface.co:

https://huggingface.co/m3hrdadfi/wav2vec2-large-xlsr-turkish

Url of wav2vec2-large-xlsr-turkish

wav2vec2-large-xlsr-turkish huggingface.co Url

Provider of wav2vec2-large-xlsr-turkish huggingface.co

m3hrdadfi
ORGANIZATIONS

Other API from m3hrdadfi

huggingface.co

Total runs: 26
Run Growth: 17
Growth Rate: 65.38%
Updated:August 11 2021
huggingface.co

Total runs: 2
Run Growth: -8
Growth Rate: -400.00%
Updated:April 03 2024