🚀 S2T-MEDIUM-LIBRISPEECH-ASR
s2t-medium-librispeech-asr
是一個用於自動語音識別(ASR)的語音轉文本變換器(S2T)模型。S2T 模型在 這篇論文 中被提出,並在 這個倉庫 中發佈。
🚀 快速開始
本模型可用於端到端語音識別(ASR)。你可以訪問 模型中心 查找其他 S2T 檢查點。
✨ 主要特性
S2T 是一個端到端的序列到序列變換器模型。它使用標準的自迴歸交叉熵損失進行訓練,並自迴歸地生成轉錄文本。
📦 安裝指南
由於這是一個標準的序列到序列變換器模型,你可以使用 generate
方法,將語音特徵傳遞給模型來生成轉錄文本。
⚠️ 重要提示
Speech2TextProcessor
對象使用 torchaudio 提取濾波器組特徵。在運行此示例之前,請確保安裝 torchaudio
包。
你可以通過以下命令將這些作為額外的語音依賴項進行安裝:
pip install transformers"[speech, sentencepiece]"
或者分別安裝這些包:
pip install torchaudio sentencepiece
💻 使用示例
基礎用法
import torch
from transformers import Speech2TextProcessor, Speech2TextForConditionalGeneration
from datasets import load_dataset
import soundfile as sf
model = Speech2TextForConditionalGeneration.from_pretrained("facebook/s2t-medium-librispeech-asr")
processor = Speech2Textprocessor.from_pretrained("facebook/s2t-medium-librispeech-asr")
def map_to_array(batch):
speech, _ = sf.read(batch["file"])
batch["speech"] = speech
return batch
ds = load_dataset(
"patrickvonplaten/librispeech_asr_dummy",
"clean",
split="validation"
)
ds = ds.map(map_to_array)
input_features = processor(
ds["speech"][0],
sampling_rate=16_000,
return_tensors="pt"
).input_features
generated_ids = model.generate(input_features=input_features)
transcription = processor.batch_decode(generated_ids)
高級用法
以下腳本展示瞭如何在 LibriSpeech 的 "clean" 和 "other" 測試數據集上評估該模型。
from datasets import load_dataset
from evaluate import load
from transformers import Speech2TextForConditionalGeneration, Speech2TextProcessor
librispeech_eval = load_dataset("librispeech_asr", "clean", split="test")
wer = load("wer")
model = Speech2TextForConditionalGeneration.from_pretrained("facebook/s2t-medium-librispeech-asr").to("cuda")
processor = Speech2TextProcessor.from_pretrained("facebook/s2t-medium-librispeech-asr", do_upper_case=True)
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_features=input_features, attention_mask=attention_mask)
batch["transcription"] = processor.batch_decode(gen_tokens, skip_special_tokens=True)[0]
return batch
result = librispeech_eval.map(map_to_pred, remove_columns=["audio"])
print("WER:", wer.compute(predictions=result["transcription"], references=result["text"]))
結果(WER):
📚 詳細文檔
訓練數據
S2T-MEDIUM-LIBRISPEECH-ASR 在 LibriSpeech ASR 語料庫 上進行訓練,該數據集包含大約 1000 小時的 16kHz 英語朗讀語音。
訓練過程
預處理
語音數據通過 PyKaldi 或 torchaudio 從 WAV/FLAC 音頻文件中自動提取符合 Kaldi 標準的 80 通道對數梅爾濾波器組特徵進行預處理。此外,對每個示例應用了基於語句級的 CMVN(倒譜均值和方差歸一化)。
文本進行小寫處理,並使用 SentencePiece 進行分詞,詞彙表大小為 10000。
訓練
該模型使用標準的自迴歸交叉熵損失進行訓練,並採用 SpecAugment 方法。編碼器接收語音特徵,解碼器自迴歸地生成轉錄文本。
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 許可證。