语言: 英文
数据集:
- librispeech_asr
标签:
- 音频
- 自动语音识别
- hf-asr排行榜
许可证: mit
模型索引:
- 名称: hubert-large-ls960-ft
结果:
- 任务:
名称: 自动语音识别
类型: automatic-speech-recognition
数据集:
名称: LibriSpeech (clean)
类型: librispeech_asr
配置: clean
分割: test
参数:
语言: en
指标:
- 任务:
名称: 自动语音识别
类型: automatic-speech-recognition
数据集:
名称: LibriSpeech (other)
类型: librispeech_asr
配置: other
分割: test
参数:
语言: en
指标:
S2T-LARGE-LIBRISPEECH-ASR
s2t-large-librispeech-asr
是一个用于自动语音识别(ASR)的语音到文本转换器(S2T)模型。该S2T模型在这篇论文中提出,并在此代码库中发布。
模型描述
S2T是一个端到端的序列到序列转换器模型。它使用标准的自回归交叉熵损失进行训练,并自回归地生成转录文本。
预期用途与限制
该模型可用于端到端的语音识别(ASR)。查看模型中心以寻找其他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-large-librispeech-asr")
processor = Speech2TextProcessor.from_pretrained("facebook/s2t-large-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_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
import soundfile as sf
librispeech_eval = load_dataset("librispeech_asr", "clean", split="test")
wer = load_metric("wer")
model = Speech2TextForConditionalGeneration.from_pretrained("facebook/s2t-large-librispeech-asr").to("cuda")
processor = Speech2TextProcessor.from_pretrained("facebook/s2t-large-librispeech-asr", do_upper_case=True)
def map_to_array(batch):
speech, _ = sf.read(batch["file"])
batch["speech"] = speech
return batch
librispeech_eval = librispeech_eval.map(map_to_array)
def map_to_pred(batch):
features = processor(batch["speech"], 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):