🚀 S2T-SMALL-LIBRISPEECH-ASR
s2t-small-librispeech-asr
是一個用於自動語音識別(ASR)的語音轉文本Transformer(S2T)模型。S2T模型在這篇論文中被提出,並在這個倉庫中發佈。
✨ 主要特性
- S2T是一個端到端的序列到序列Transformer模型。
- 該模型使用標準的自迴歸交叉熵損失進行訓練,並自迴歸地生成轉錄文本。
🚀 快速開始
此模型可用於端到端語音識別(ASR)。你可以查看模型中心來查找其他S2T檢查點。
如何使用
由於這是一個標準的序列到序列Transformer模型,你可以通過將語音特徵傳遞給模型,使用generate
方法生成轉錄文本。
⚠️ 重要提示
💡 使用建議
你可以使用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-SMALL-LIBRISPEECH-ASR在LibriSpeech ASR語料庫上進行訓練,該數據集包含大約1000小時的16kHz英語朗讀語音。
訓練過程
預處理
語音數據通過PyKaldi或torchaudio自動從WAV/FLAC音頻文件中提取符合Kaldi標準的80通道對數梅爾濾波器組特徵進行預處理。此外,對每個示例應用了基於話語級別的CMVN(倒譜均值和方差歸一化)。
文本被轉換為小寫,並使用SentencePiece進行分詞,詞彙表大小為10,000。
訓練
該模型使用標準的自迴歸交叉熵損失進行訓練,並使用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許可證。
信息表格
屬性 |
詳情 |
模型類型 |
語音轉文本Transformer(S2T)模型 |
訓練數據 |
LibriSpeech ASR語料庫,包含約1000小時的16kHz英語朗讀語音 |
許可證 |
MIT |
任務類型 |
自動語音識別(ASR) |
數據集 |
LibriSpeech(clean和other) |
評估指標 |
詞錯誤率(WER) |
"clean"測試集WER |
4.3 |
"other"測試集WER |
9.0 |