🚀 Wav2Vec2-Large-XLSR-53-lg
このモデルは、Common Voiceデータセットを使用してLuganda言語でfacebook/wav2vec2-large-xlsr-53をファインチューニングしたものです。訓練、検証、およびその他のデータセット(テストセットに含まれる音声を除く)を使用し、テストデータは検証とテストの両方に使用されています。
このモデルを使用する際には、音声入力が16kHzでサンプリングされていることを確認してください。
📦 モデル情報
属性 |
详情 |
言語 |
lg |
データセット |
common_voice |
評価指標 |
wer |
タグ |
audio, automatic-speech-recognition, speech, xlsr-fine-tuning-week |
ライセンス |
apache-2.0 |
モデルインデックス
- 名前: XLSR Wav2Vec2 Large Luganda by Lucio
- 結果:
- タスク:
- 名前: 音声認識
- タイプ: automatic-speech-recognition
- データセット:
- 名前: Common Voice lg
- タイプ: common_voice
- 引数: lg
- 評価指標:
- 名前: Test WER
- タイプ: wer
- 値: 29.52
💻 使用例
基本的な使用法
import torch
import torchaudio
from datasets import load_dataset
from transformers import Wav2Vec2ForCTC, Wav2Vec2Processor
test_dataset = load_dataset("common_voice", "lg", split="test[:2%]")
processor = Wav2Vec2Processor.from_pretrained("lucio/wav2vec2-large-xlsr-luganda")
model = Wav2Vec2ForCTC.from_pretrained("lucio/wav2vec2-large-xlsr-luganda")
resampler = torchaudio.transforms.Resample(48_000, 16_000)
def speech_file_to_array_fn(batch):
speech_array, sampling_rate = torchaudio.load(batch["path"])
batch["speech"] = resampler(speech_array).squeeze().numpy()
return batch
test_dataset = test_dataset.map(speech_file_to_array_fn)
inputs = processor(test_dataset[:2]["speech"], sampling_rate=16_000, return_tensors="pt", padding=True)
with torch.no_grad():
logits = model(inputs.input_values, attention_mask=inputs.attention_mask).logits
predicted_ids = torch.argmax(logits, dim=-1)
print("Prediction:", processor.batch_decode(predicted_ids))
print("Reference:", test_dataset["sentence"][:2])
📚 評価
このモデルは、Common VoiceのLugandaのテストデータで以下のように評価できます。(Colabでの実行はこちら)
import torch
import torchaudio
from datasets import load_dataset, load_metric
from transformers import Wav2Vec2ForCTC, Wav2Vec2Processor
import re
import unidecode
test_dataset = load_dataset("common_voice", "lg", split="test")
wer = load_metric("wer")
processor = Wav2Vec2Processor.from_pretrained("lucio/wav2vec2-large-xlsr-luganda")
model = Wav2Vec2ForCTC.from_pretrained("lucio/wav2vec2-large-xlsr-luganda")
model.to("cuda")
chars_to_ignore_regex = '[\[\],?.!;:%"“”(){}‟ˮʺ″«»/…‽�–]'
resampler = torchaudio.transforms.Resample(48_000, 16_000)
def speech_file_to_array_fn(batch):
speech_array, sampling_rate = torchaudio.load(batch["path"])
batch["speech"] = resampler(speech_array).squeeze().numpy()
return batch
def remove_special_characters(batch):
batch["norm_text"] = re.sub(r'[‘’´`]', r"'", batch["sentence"])
batch["norm_text"] = re.sub(chars_to_ignore_regex, "", batch["norm_text"]).lower().strip()
batch["norm_text"] = re.sub(r"(-|' | '| +)", " ", batch["norm_text"])
batch["norm_text"] = unidecode.unidecode(batch["norm_text"])
return batch
test_dataset = test_dataset.map(speech_file_to_array_fn)
test_dataset = test_dataset.map(remove_special_characters)
def evaluate(batch):
inputs = processor(batch["speech"], sampling_rate=16_000, return_tensors="pt", padding=True)
with torch.no_grad():
logits = model(inputs.input_values.to("cuda"), attention_mask=inputs.attention_mask.to("cuda")).logits
pred_ids = torch.argmax(logits, dim=-1)
batch["pred_strings"] = processor.batch_decode(pred_ids)
return batch
result = test_dataset.map(evaluate, batched=True, batch_size=8)
print("WER: {:2f}".format(100 * wer.compute(predictions=result["pred_strings"], references=result["norm_text"])))
テスト結果: 29.52 %
🔧 訓練
訓練にはCommon Voiceのtrain
、validation
、other
データセットが使用され、other
とtest
データセットの両方に含まれる音声は除外されました。データは、ノイズの追加、ピッチ、位相、強度の操作により元のサイズの2倍に拡張されました。
訓練は、OVHcloudが提供する1台のV100 GPUで60エポック行われました。test
データは検証に使用されました。
訓練に使用されたスクリプトは、transformersリポジトリに提供されているサンプルスクリプトを改変したものです。
📄 ライセンス
このモデルは、Apache 2.0ライセンスの下で提供されています。