CoolFace
Modelpublic

NewComer00/wav2vec2-xlsr-multilingual-56-ONNX

sourceHugging Faceapache-2.0updated 5mo agoView on Hugging Face
0likes24downloads
Model Card

wav2vec2-xlsr-multilingual-56 (ONNX)

This is an ONNX version of voidful/wav2vec2-xlsr-multilingual-56. It was automatically converted and uploaded using this Hugging Face Space.

Usage with Transformers.js

See the pipeline documentation for automatic-speech-recognition: https://huggingface.co/docs/transformers.js/api/pipelines#module_pipelines.AutomaticSpeechRecognitionPipeline


Model Card for wav2vec2-xlsr-multilingual-56

Model Details

Model Description

  • —Developed by: voidful
  • —Shared by [Optional]: Hugging Face
  • —Model type: automatic-speech-recognition
  • —Language(s) (NLP): multilingual (56 language, 1 model Multilingual ASR)
  • —License: Apache-2.0
  • —Related Models:
  • —Parent Model: wav2vec
  • —Resources for more information:
  • —GitHub Repo
  • —Model Space

Uses

Direct Use

This model can be used for the task of automatic-speech-recognition

Downstream Use [Optional]

More information needed

Out-of-Scope Use

The model should not be used to intentionally create hostile or alienating environments for people.

Bias, Risks, and Limitations

Significant research has explored bias and fairness issues with language models (see, e.g., Sheng et al. (2021) and Bender et al. (2021)). Predictions generated by the model may include disturbing and harmful stereotypes across protected classes; identity characteristics; and sensitive, social, and occupational groups.

Recommendations

Users (both direct and downstream) should be made aware of the risks, biases and limitations of the model. More information needed for further recommendations.

Training Details

Training Data

See the common_voice dataset card Fine-tuned facebook/wav2vec2-large-xlsr-53 on 56 language using the Common Voice.

Training Procedure

Preprocessing

More information needed

Speeds, Sizes, Times

When using this model, make sure that your speech input is sampled at 16kHz.

Evaluation

Testing Data, Factors & Metrics

Testing Data

More information needed

Factors

Metrics

More information needed

Results

<details> <summary> Click to expand </summary>

Common Voice LanguagesNum. of dataHourWERCER
ar2174481.575.2931.23
as3941.195.3746.05
br47777.493.7941.16
ca301308692.824.8010.39
cnh15632.468.1123.10
cs977339.567.8612.57
cv17495.995.4334.03
cy11615106.767.0323.97
de262113822.827.036.50
dv475718.692.1630.15
el371711.194.4858.67
en5805011763.634.8714.84
eo28574162.337.776.23
es176902337.719.635.41
et547335.986.8720.79
eu1267790.244.807.32
fa12806290.653.8115.09
fi8752.693.7827.57
fr314745664.133.1613.94
fy-NL671727.272.5426.58
ga-IE10383.592.5751.02
hi2922.090.9557.43
hsb9802.389.4427.19
hu47829.397.1536.75
ia507810.452.0011.35
id39659.982.5022.82
it70943178.039.098.72
ja13088.299.2162.06
ka15854.090.5318.57
ky346612.276.5319.80
lg163417.198.9543.84
lt11753.992.6126.81
lv45546.390.3430.81
mn402011.682.6830.14
mt35527.884.1822.96
nl1439871.857.1819.01
or5170.990.9327.34
pa-IN2550.887.9542.03
pl12621112.056.1412.06
pt1110661.353.2416.32
rm-sursilv25895.978.1723.31
rm-vallader9312.373.6721.76
ro42578.783.8421.95
ru23444119.161.8315.18
sah18474.494.3838.46
sl25946.784.2120.54
sv-SE435020.883.6830.79
ta378818.484.1921.60
th483911.7141.8737.16
tr347822.366.7715.55
tt1333826.786.8033.57
uk727139.470.2314.34
vi4211.796.0666.25
zh-CN2728458.789.6723.96
zh-HK1267892.181.7718.82
zh-TW640256.685.0829.07

</details>

Model Examination

More information needed

Environmental Impact

Carbon emissions can be estimated using the Machine Learning Impact calculator presented in Lacoste et al. (2019).

  • —Hardware Type: More information needed
  • —Hours used: More information needed
  • —Cloud Provider: More information needed
  • —Compute Region: More information needed
  • —Carbon Emitted: More information needed

Technical Specifications [optional]

Model Architecture and Objective

More information needed

Compute Infrastructure

More information needed

Hardware

More information needed

Software

More information needed

Citation

BibTeX:

More information needed

APA:

More information needed

Glossary [optional]

More information needed

More Information [optional]

More information needed

Model Card Authors [optional]

voidful in collaboration with Ezi Ozoani and the Hugging Face team

Model Card Contact

More information needed

How to Get Started with the Model

Use the code below to get started with the model.

<details> <summary> Click to expand </summary>

Env setup:

!pip install torchaudio
!pip install datasets transformers
!pip install asrp
!wget -O lang_ids.pk https://huggingface.co/voidful/wav2vec2-xlsr-multilingual-56/raw/main/lang_ids.pk

Usage

import torchaudio
from datasets import load_dataset, load_metric
from transformers import (
    Wav2Vec2ForCTC,
    Wav2Vec2Processor,
    AutoTokenizer, 
    AutoModelWithLMHead 
)
import torch
import re
import sys
import soundfile as sf
model_name = "voidful/wav2vec2-xlsr-multilingual-56"
device = "cuda"
processor_name = "voidful/wav2vec2-xlsr-multilingual-56"
 
import pickle
with open("lang_ids.pk", 'rb') as output:
    lang_ids = pickle.load(output)
    
model = Wav2Vec2ForCTC.from_pretrained(model_name).to(device)
processor = Wav2Vec2Processor.from_pretrained(processor_name)
 
model.eval()
 
def load_file_to_data(file,sampling_rate=16_000):
    batch = {}
    speech, _ = torchaudio.load(file)
    if sampling_rate != '16_000' or sampling_rate != '16000':
        resampler = torchaudio.transforms.Resample(orig_freq=sampling_rate, new_freq=16_000)
        batch["speech"] = resampler.forward(speech.squeeze(0)).numpy()
        batch["sampling_rate"] = resampler.new_freq
    else:
        batch["speech"] = speech.squeeze(0).numpy()
        batch["sampling_rate"] = '16000'
    return batch
 
 
def predict(data):
    features = processor(data["speech"], sampling_rate=data["sampling_rate"], padding=True, return_tensors="pt")
    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
        decoded_results = []
        for logit in logits:
            pred_ids = torch.argmax(logit, dim=-1)
            mask = pred_ids.ge(1).unsqueeze(-1).expand(logit.size())
            vocab_size = logit.size()[-1]
            voice_prob = torch.nn.functional.softmax((torch.masked_select(logit, mask).view(-1,vocab_size)),dim=-1)
            comb_pred_ids = torch.argmax(voice_prob, dim=-1)
            decoded_results.append(processor.decode(comb_pred_ids))
 
    return decoded_results
 
def predict_lang_specific(data,lang_code):
    features = processor(data["speech"], sampling_rate=data["sampling_rate"], padding=True, return_tensors="pt")
    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
        decoded_results = []
        for logit in logits:
            pred_ids = torch.argmax(logit, dim=-1)
            mask = ~pred_ids.eq(processor.tokenizer.pad_token_id).unsqueeze(-1).expand(logit.size())
            vocab_size = logit.size()[-1]
            voice_prob = torch.nn.functional.softmax((torch.masked_select(logit, mask).view(-1,vocab_size)),dim=-1)
            filtered_input = pred_ids[pred_ids!=processor.tokenizer.pad_token_id].view(1,-1).to(device)
            if len(filtered_input[0]) == 0:
                decoded_results.append("")
            else:
                lang_mask = torch.empty(voice_prob.shape[-1]).fill_(0)
                lang_index = torch.tensor(sorted(lang_ids[lang_code]))
                lang_mask.index_fill_(0, lang_index, 1)
                lang_mask = lang_mask.to(device)
                comb_pred_ids = torch.argmax(lang_mask*voice_prob, dim=-1)
                decoded_results.append(processor.decode(comb_pred_ids))
                
    return decoded_results
 
 
predict(load_file_to_data('audio file path',sampling_rate=16_000)) # beware of the audio file sampling rate
 
predict_lang_specific(load_file_to_data('audio file path',sampling_rate=16_000),'en') # beware of the audio file sampling rate
 
python
{{ get_started_code | default("More information needed", true)}}

</details>