🚀 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 許可證。