🚀 S2T-SMALL-MUSTC-EN-NL-ST
s2t-small-mustc-en-nl-st
是一个用于端到端语音翻译(ST)的语音转文本 Transformer(S2T)模型。该 S2T 模型在 这篇论文 中被提出,并在 这个仓库 中发布。
🚀 快速开始
本模型可用于端到端的英语语音到荷兰语文本的翻译。你可以在 模型中心 查找其他 S2T 检查点。
如何使用
由于这是一个标准的序列到序列的 Transformer 模型,你可以使用 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-small-mustc-en-nl-st")
processor = Speech2TextProcessor.from_pretrained("facebook/s2t-small-mustc-en-nl-st")
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"])
translation = processor.batch_decode(generated_ids, skip_special_tokens=True)
✨ 主要特性
S2T 是一个基于 Transformer 的序列到序列(编码器 - 解码器)模型,专为端到端的自动语音识别(ASR)和语音翻译(ST)而设计。它使用卷积下采样器,在将语音输入送入编码器之前,将其长度减少 3/4。该模型使用标准的自回归交叉熵损失进行训练,并自回归地生成转录文本/翻译内容。
📦 安装指南
你可以通过以下两种方式安装所需的依赖项:
- 作为额外的语音依赖项安装:
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-small-mustc-en-nl-st")
processor = Speech2TextProcessor.from_pretrained("facebook/s2t-small-mustc-en-nl-st")
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"])
translation = processor.batch_decode(generated_ids, skip_special_tokens=True)
🔧 技术细节
训练数据
s2t-small-mustc-en-nl-st
模型在 MuST-C 的英 - 荷子集上进行训练。MuST-C 是一个多语言语音翻译语料库,其规模和质量有助于训练从英语到多种语言的端到端语音翻译系统。对于每种目标语言,MuST-C 包含数百小时来自英语 TED 演讲的音频记录,这些记录在句子级别与手动转录和翻译自动对齐。
训练过程
预处理
语音数据通过 PyKaldi 或 torchaudio 从 WAV/FLAC 音频文件中自动提取符合 Kaldi 标准的 80 通道对数梅尔滤波器组特征进行预处理。此外,对每个示例应用了基于话语级别的 CMVN(倒谱均值和方差归一化)。
文本经过小写处理,并使用 SentencePiece 进行分词,词汇量大小为 8000。
训练
该模型使用标准的自回归交叉熵损失和 SpecAugment 进行训练。编码器接收语音特征,解码器自回归地生成转录文本。为了加速模型训练并获得更好的性能,编码器在英语 ASR 任务上进行了预训练。
📚 详细文档
评估结果
在 MuST-C 测试集上,英 - 荷翻译的 BLEU 分数为 27.3。
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 模型 |
训练数据 |
MuST-C 英 - 荷子集 |