模型:
dragonSwing/wav2vec2-base-vn-270h
在包含来自多个数据集的约270小时标记数据的基础上,对越南语言识别任务进行了Wav2Vec2模型的微调,其中包括 Common Voice 、 VIVOS 和 VLSP2020 。该模型使用SpeechBrain工具包进行了微调,并使用了自定义的分词器。为了获得更好的体验,我们鼓励您了解一下 SpeechBrain 。在使用此模型时,请确保语音输入采样频率为16kHz。有关如何在特定语言上微调Wav2Vec2模型的方法,请参阅 huggingface blog 或 speechbrain 。
| 1239321 | 12310321 | 12311321 | |
|---|---|---|---|
| without LM | 8.23 | 12.15 | 12.15 |
| with 4-grams LM | 3.70 | 5.57 | 5.76 |
该语言模型使用 OSCAR 数据集进行了训练,训练文本大小约为32GB。
要使用该模型,您应安装speechbrain > 0.5.10
可以直接使用该模型(无需语言模型),如下所示:
from speechbrain.pretrained import EncoderASR
model = EncoderASR.from_hparams(source="dragonSwing/wav2vec2-base-vn-270h", savedir="pretrained_models/asr-wav2vec2-vi")
model.transcribe_file('dragonSwing/wav2vec2-base-vn-270h/example.mp3')
# Output: được hồ chí minh coi là một động lực lớn của sự phát triển đất nước
要在GPU上执行推理,请在调用from_hparams方法时添加run_opts={"device":"cuda"}
可以如下所示对Common Voice 8.0的越南语测试数据进行评估。
import torch
import torchaudio
from datasets import load_dataset, load_metric, Audio
from transformers import Wav2Vec2FeatureExtractor
from speechbrain.pretrained import EncoderASR
import re
test_dataset = load_dataset("mozilla-foundation/common_voice_8_0", "vi", split="test", use_auth_token=True)
test_dataset = test_dataset.cast_column("audio", Audio(sampling_rate=16_000))
device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
wer = load_metric("wer")
extractor = Wav2Vec2FeatureExtractor.from_pretrained("dragonSwing/wav2vec2-base-vn-270h")
model = EncoderASR.from_hparams(source="dragonSwing/wav2vec2-base-vn-270h", savedir="pretrained_models/asr-wav2vec2-vi", run_opts={'device': device})
chars_to_ignore_regex = r'[,?.!\-;:"“%\'�]'
# Preprocessing the datasets.
# We need to read the audio files as arrays
def speech_file_to_array_fn(batch):
audio = batch["audio"]
batch["target_text"] = re.sub(chars_to_ignore_regex, '', batch["sentence"]).lower()
batch['speech'] = audio['array']
return batch
test_dataset = test_dataset.map(speech_file_to_array_fn)
def evaluate(batch):
# For padding inputs only
inputs = extractor(
batch['speech'],
sampling_rate=16000,
return_tensors="pt",
padding=True,
do_normalize=False
).input_values
input_lens = torch.ones(inputs.shape[0])
pred_str, pred_tokens = model.transcribe_batch(inputs, input_lens)
batch["pred_strings"] = pred_str
return batch
result = test_dataset.map(evaluate, batched=True, batch_size=1)
print("WER: {:2f}".format(100 * wer.compute(predictions=result["pred_strings"], references=result["target_text"])))
测试结果:12.155553%
Citation@misc{SB2021,
author = {Ravanelli, Mirco and Parcollet, Titouan and Rouhe, Aku and Plantinga, Peter and Rastorgueva, Elena and Lugosch, Loren and Dawalatabad, Nauman and Ju-Chieh, Chou and Heba, Abdel and Grondin, Francois and Aris, William and Liao, Chien-Feng and Cornell, Samuele and Yeh, Sung-Lin and Na, Hwidong and Gao, Yan and Fu, Szu-Wei and Subakan, Cem and De Mori, Renato and Bengio, Yoshua },
title = {SpeechBrain},
year = {2021},
publisher = {GitHub},
journal = {GitHub repository},
howpublished = {\\\\url{https://github.com/speechbrain/speechbrain}},
}
About SpeechBrain SpeechBrain是一个开源的一体化语音工具包。它设计简单、极其灵活和用户友好。在各个领域取得了有竞争力或达到最新技术水平的性能。网站: https://speechbrain.github.io GitHub: https://github.com/speechbrain/speechbrain