🚀 Wav2vec2 Large 100k Voxpopuli 在俄语上微调模型
本项目基于 Wav2vec2 Large 100k Voxpopuli 模型,使用 Common Voice 7.0、M - AILABS 数据集,结合基于 TTS 和语音转换的数据增强方法,在俄语数据上进行了微调。
🚀 快速开始
安装依赖
本项目使用 Python 和 PyTorch,你可以通过以下方式安装所需的库:
pip install transformers torchaudio datasets jiwer
使用模型
from transformers import AutoTokenizer, Wav2Vec2ForCTC
tokenizer = AutoTokenizer.from_pretrained("Edresson/wav2vec2-large-100k-voxpopuli-ft-Common_Voice_plus_TTS-Dataset_plus_Data_Augmentation-russian")
model = Wav2Vec2ForCTC.from_pretrained("Edresson/wav2vec2-large-100k-voxpopuli-ft-Common_Voice_plus_TTS-Dataset_plus_Data_Augmentation-russian")
💻 使用示例
基础用法
from transformers import AutoTokenizer, Wav2Vec2ForCTC
tokenizer = AutoTokenizer.from_pretrained("Edresson/wav2vec2-large-100k-voxpopuli-ft-Common_Voice_plus_TTS-Dataset_plus_Data_Augmentation-russian")
model = Wav2Vec2ForCTC.from_pretrained("Edresson/wav2vec2-large-100k-voxpopuli-ft-Common_Voice_plus_TTS-Dataset_plus_Data_Augmentation-russian")
高级用法
使用 Common Voice 数据集进行测试
from datasets import load_dataset
import torchaudio
import re
from jiwer import wer
dataset = load_dataset("common_voice", "ru", split="test", data_dir="./cv-corpus-7.0-2021-07-21")
resampler = torchaudio.transforms.Resample(orig_freq=48_000, new_freq=16_000)
chars_to_ignore_regex = '[\,\?\.\!\-\;\:\"]'
def map_to_array(batch):
speech, _ = torchaudio.load(batch["path"])
batch["speech"] = resampler.forward(speech.squeeze(0)).numpy()
batch["sampling_rate"] = resampler.new_freq
batch["sentence"] = re.sub(chars_to_ignore_regex, '', batch["sentence"]).lower().replace("’", "'")
return batch
ds = dataset.map(map_to_array)
def map_to_pred(batch):
features = tokenizer(batch["speech"], return_tensors="pt", padding="longest")
input_values = features.input_values
attention_mask = features.attention_mask
with torch.no_grad():
logits = model(input_values, attention_mask=attention_mask).logits
predicted_ids = torch.argmax(logits, dim=-1)
batch["predicted"] = tokenizer.batch_decode(predicted_ids)
batch["target"] = batch["sentence"]
return batch
result = ds.map(map_to_pred, batched=True, batch_size=1, remove_columns=list(ds.features.keys()))
print(wer.compute(predictions=result["predicted"], references=result["target"]))
📚 详细文档
模型信息
属性 |
详情 |
模型类型 |
基于 Wav2vec2 Large 100k Voxpopuli 微调的语音识别模型 |
训练数据 |
Common Voice 7.0、M - AILABS 数据集,结合基于 TTS 和语音转换的数据增强方法 |
评估指标 |
词错误率(WER) |
模型结果
模型在俄语语音识别任务上的测试结果可查看 论文 。
📄 许可证
本项目采用 Apache - 2.0 许可证。