🚀 S2T-SMALL-LIBRISPEECH-ASR
s2t-small-librispeech-asr
は、自動音声認識(ASR)用に学習された音声テキスト変換トランスフォーマー(S2T)モデルです。S2Tモデルは この論文 で提案され、このリポジトリ で公開されました。
🚀 クイックスタート
このモデルは、標準的なシーケンス-to-シーケンストランスフォーマーモデルであり、音声特徴をモデルに渡すことで generate
メソッドを使用して文字起こしを生成できます。
⚠️ 重要提示
Speech2TextProcessor
オブジェクトは torchaudio を使用してフィルタバンク特徴を抽出します。この例を実行する前に torchaudio
パッケージをインストールしてください。また、特徴抽出器は torchaudio に依存し、トークナイザーは sentencepiece に依存するため、サンプルコードを実行する前にこれらのパッケージをインストールしてください。
これらのパッケージは、pip install transformers"[speech, sentencepiece]"
で追加の音声依存関係としてインストールするか、pip install torchaudio sentencepiece
で個別にインストールできます。
import torch
from transformers import Speech2TextProcessor, Speech2TextForConditionalGeneration
from datasets import load_dataset
model = Speech2TextForConditionalGeneration.from_pretrained("facebook/s2t-small-librispeech-asr")
processor = Speech2TextProcessor.from_pretrained("facebook/s2t-small-librispeech-asr")
ds = load_dataset(
"patrickvonplaten/librispeech_asr_dummy",
"clean",
split="validation"
)
input_features = processor(
ds[0]["audio"]["array"],
sampling_rate=16_000,
return_tensors="pt"
).input_features
generated_ids = model.generate(input_ids=input_features)
transcription = processor.batch_decode(generated_ids)
✨ 主な機能
- エンドツーエンドの音声認識(ASR)に使用できます。
- 標準的な自己回帰型の交差エントロピー損失を使用して学習され、文字起こしを自己回帰的に生成します。
📦 インストール
依存パッケージをインストールするには、以下のコマンドを実行します。
pip install transformers"[speech, sentencepiece]"
pip install torchaudio sentencepiece
💻 使用例
基本的な使用法
import torch
from transformers import Speech2TextProcessor, Speech2TextForConditionalGeneration
from datasets import load_dataset
model = Speech2TextForConditionalGeneration.from_pretrained("facebook/s2t-small-librispeech-asr")
processor = Speech2TextProcessor.from_pretrained("facebook/s2t-small-librispeech-asr")
ds = load_dataset(
"patrickvonplaten/librispeech_asr_dummy",
"clean",
split="validation"
)
input_features = processor(
ds[0]["audio"]["array"],
sampling_rate=16_000,
return_tensors="pt"
).input_features
generated_ids = model.generate(input_ids=input_features)
transcription = processor.batch_decode(generated_ids)
高度な使用法
LibriSpeechテストデータセットでの評価
以下のスクリプトは、このモデルを LibriSpeech の "clean" および "other" テストデータセットで評価する方法を示しています。
from datasets import load_dataset, load_metric
from transformers import Speech2TextForConditionalGeneration, Speech2TextProcessor
librispeech_eval = load_dataset("librispeech_asr", "clean", split="test")
wer = load_metric("wer")
model = Speech2TextForConditionalGeneration.from_pretrained("facebook/s2t-small-librispeech-asr").to("cuda")
processor = Speech2TextProcessor.from_pretrained("facebook/s2t-small-librispeech-asr", do_upper_case=True)
librispeech_eval = librispeech_eval.map(map_to_array)
def map_to_pred(batch):
features = processor(batch["audio"]["array"], sampling_rate=16000, padding=True, return_tensors="pt")
input_features = features.input_features.to("cuda")
attention_mask = features.attention_mask.to("cuda")
gen_tokens = model.generate(input_ids=input_features, attention_mask=attention_mask)
batch["transcription"] = processor.batch_decode(gen_tokens, skip_special_tokens=True)
return batch
result = librispeech_eval.map(map_to_pred, batched=True, batch_size=8, remove_columns=["speech"])
print("WER:", wer(predictions=result["transcription"], references=result["text"]))
結果(WER):
📚 ドキュメント
モデルの説明
S2Tは、エンドツーエンドのシーケンス-to-シーケンストランスフォーマーモデルです。標準的な自己回帰型の交差エントロピー損失を使用して学習され、文字起こしを自己回帰的に生成します。
想定される用途と制限
このモデルは、エンドツーエンドの音声認識(ASR)に使用できます。他のS2Tチェックポイントを探すには、モデルハブ を参照してください。
🔧 技術詳細
前処理
音声データは、PyKaldiまたはtorchaudioを介してWAV/FLACオーディオファイルから自動的にKaldi互換の80チャネルのログメルフィルタバンク特徴を抽出することで前処理されます。さらに、各サンプルに対して発話レベルのCMVN(ケプストラム平均と分散正規化)が適用されます。
テキストは小文字に変換され、SentencePieceを使用して語彙サイズ10,000でトークン化されます。
学習
モデルは、標準的な自己回帰型の交差エントロピー損失を使用し、SpecAugment を用いて学習されます。エンコーダは音声特徴を受け取り、デコーダは文字起こしを自己回帰的に生成します。
学習データ
S2T-SMALL-LIBRISPEECH-ASRは、LibriSpeech ASRコーパス で学習されています。このデータセットは、約1000時間の16kHzの読み上げ英語音声で構成されています。
BibTeXエントリと引用情報
@inproceedings{wang2020fairseqs2t,
title = {fairseq S2T: Fast Speech-to-Text Modeling with fairseq},
author = {Changhan Wang and Yun Tang and Xutai Ma and Anne Wu and Dmytro Okhonko and Juan Pino},
booktitle = {Proceedings of the 2020 Conference of the Asian Chapter of the Association for Computational Linguistics (AACL): System Demonstrations},
year = {2020},
}
📄 ライセンス
このモデルはMITライセンスの下で提供されています。