模型:
facebook/s2t-wav2vec2-large-en-de
s2t-wav2vec2-large-en-de是一个专为端到端语音翻译(ST)训练的语音到文本Transformer模型。S2T2模型在某某论文中提出,并在某某时正式发布。
S2T2是一个基于Transformer的序列到序列(语音编码器-解码器)模型,旨在进行端到端的自动语音识别(ASR)和语音翻译(ST)。它使用预训练的某某作为编码器和基于Transformer的解码器。该模型使用标准的自回归交叉熵损失进行训练,并自动逐步生成翻译。
该模型可以用于将英语语音转换为德语文本的端到端翻译。请查看某某寻找其他S2T2检查点。
由于这是一个标准的序列到序列Transformer模型,您可以使用generate方法通过将语音特征传递给模型来生成转录。
您可以通过ASR管道直接使用模型
from datasets import load_dataset from transformers import pipeline librispeech_en = load_dataset("patrickvonplaten/librispeech_asr_dummy", "clean", split="validation") asr = pipeline("automatic-speech-recognition", model="facebook/s2t-wav2vec2-large-en-de", feature_extractor="facebook/s2t-wav2vec2-large-en-de") translation_de = asr(librispeech_en[0]["file"])
或按照以下步骤逐步使用:
import torch from transformers import Speech2Text2Processor, SpeechEncoderDecoder from datasets import load_dataset import soundfile as sf model = SpeechEncoderDecoder.from_pretrained("facebook/s2t-wav2vec2-large-en-de") processor = Speech2Text2Processor.from_pretrained("facebook/s2t-wav2vec2-large-en-de") 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) inputs = processor(ds["speech"][0], sampling_rate=16_000, return_tensors="pt") generated_ids = model.generate(input_ids=inputs["input_features"], attention_mask=inputs["attention_mask"]) transcription = processor.batch_decode(generated_ids)
en-de的CoVoST-V2测试结果(BLEU分数):26.5
获取更多信息,请参阅某某,特别是表2的第10行。
@article{DBLP:journals/corr/abs-2104-06678, author = {Changhan Wang and Anne Wu and Juan Miguel Pino and Alexei Baevski and Michael Auli and Alexis Conneau}, title = {Large-Scale Self- and Semi-Supervised Learning for Speech Translation}, journal = {CoRR}, volume = {abs/2104.06678}, year = {2021}, url = {https://arxiv.org/abs/2104.06678}, archivePrefix = {arXiv}, eprint = {2104.06678}, timestamp = {Thu, 12 Aug 2021 15:37:06 +0200}, biburl = {https://dblp.org/rec/journals/corr/abs-2104-06678.bib}, bibsource = {dblp computer science bibliography, https://dblp.org} }