language: zh
datasets:
- librispeech_asr
tags:
- 语音
- 音频
- 自动语音识别
- hf-asr-leaderboard
license: mit
pipeline_tag: automatic-speech-recognition
widget:
- example_title: Librispeech样本1
src: https://cdn-media.huggingface.co/speech_samples/sample1.flac
- example_title: Librispeech样本2
src: https://cdn-media.huggingface.co/speech_samples/sample2.flac
model-index:
- name: s2t-small-librispeech-asr
results:
- task:
name: 自动语音识别
type: automatic-speech-recognition
dataset:
name: LibriSpeech (clean)
type: librispeech_asr
config: clean
split: test
args:
language: en
metrics:
- name: 测试WER
type: wer
value: 4.3
- task:
name: 自动语音识别
type: automatic-speech-recognition
dataset:
name: LibriSpeech (other)
type: librispeech_asr
config: other
split: test
args:
language: en
metrics:
- name: 测试WER
type: wer
value: 9.0
S2T-SMALL-LIBRISPEECH-ASR
s2t-small-librispeech-asr
是一个基于语音到文本转换器(S2T)训练的自动语音识别(ASR)模型。该S2T模型在这篇论文中提出,并在此代码库中发布。
模型描述
S2T是一个端到端的序列到序列变换器模型。它使用标准的自回归交叉熵损失进行训练,并以自回归方式生成转录文本。
预期用途与限制
该模型可用于端到端语音识别(ASR)。查看模型中心以寻找其他S2T检查点。
使用方法
由于这是一个标准的序列到序列变换器模型,您可以通过将语音特征传递给模型并使用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)
在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):