File size: 4,978 Bytes
b4b0962 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 |
---
license: cc-by-nc-4.0
language:
- af
- am
- ar
- as
- az
- be
- bn
- bs
- bg
- ca
- cs
- zh
- cy
- da
- de
- el
- en
- et
- fi
- fr
- or
- om
- ga
- gl
- gu
- ha
- he
- hi
- hr
- hu
- hy
- ig
- id
- is
- it
- jv
- ja
- kn
- ka
- kk
- mn
- km
- ky
- ko
- lo
- ln
- lt
- lb
- lg
- lv
- ml
- mr
- mk
- mt
- mi
- my
- nl
- nb
- ne
- ny
- oc
- pa
- ps
- fa
- pl
- pt
- ro
- ru
- sk
- sl
- sn
- sd
- so
- es
- sr
- sv
- sw
- ta
- te
- tg
- tl
- th
- tr
- uk
- ur
- uz
- vi
- wo
- xh
- yo
- ms
- zu
- ary
- arz
- yue
- kea
tags:
- audio-to-audio
- text-to-speech
multilinguality:
- multilingual
task_categories:
- audio-classification
library_name: transformers
pretty_name: SeamlessM4Tv2-Large Speech Encoder
---
# SeamlessM4Tv2-Large Speech Encoder
This repository carves out the speech encoder from [SeamlessM4Tv2-Large](facebook/seamless-m4t-v2-large), which performs strongly on cross- and multilingual sequence-level audio classification tasks (cf. results on SIB-Fleurs available [here](https://huggingface.co/datasets/WueNLP/sib-fleurs#asr-results)\).
All credits go to the original SeamlessM4Tv2-Large Team.
## Example Usage
You can use both `AutoModel` and `AutoModelForAudioClassification` (or `AutoModelForSequenceClassification`, if you prefer) with this repository:
```python
# best to use both feature extractor and model with GPU!
from datasets import load_dataset
from transformers import (
AutoModel,
AutoModelForAudioClassification,
AutoFeatureExtractor,
)
import torch
import torchaudio
device = "cuda:0"
feature_extractor = AutoFeatureExtractor.from_pretrained(
"WueNLP/seamless-m4t-v2-large-speech-encoder", trust_remote_code=True
)
model = AutoModel.from_pretrained(
"WueNLP/seamless-m4t-v2-large-speech-encoder",
trust_remote_code=True,
torch_dtype=torch.bfloat16,
).to(device)
audio, orig_freq = torchaudio.load(
"https://www2.cs.uic.edu/~i101/SoundFiles/preamble10.wav"
)
audio = torchaudio.functional.resample(
audio, orig_freq=orig_freq, new_freq=16_000
) # must be a 16 kHz waveform array
# return_attention_mask=True for batching
audio_inputs = feature_extractor(audio, return_attention_mask=True, return_tensors="pt", device=device)
audio_inputs = audio_inputs.to(device)
with torch.autocast(dtype=torch.bfloat16, device_type="cuda"):
audio_hidden_states = model(**audio_inputs)[0].detach().cpu().numpy().squeeze()
# instantiate a model for AudioClassification
model = AutoModelForAudioClassification.from_pretrained(
"WueNLP/seamless-m4t-v2-large-speech-encoder",
trust_remote_code=True,
torch_dtype=torch.bfloat16,
# SIB-Fleurs has 7 labels
num_labels=7,
).to(device)
eng_Latn = load_dataset("wuenlp/sib-fleurs", "eng_Latn", split="train")
examples = [eng_Latn[i] for i in range(5)]
labels = torch.LongTensor([example["category"] for example in examples]).to(device)
batch = feature_extractor(
# [0] indexing here since there typically are multiple utterances per instance, we just ignore those
[example["audio"][0]["array"] for example in examples],
sampling_rate=16000,
device=device,
return_attention_mask=True,
return_tensors="pt",
).to(device)
batch["labels"] = labels
with torch.autocast(dtype=torch.bfloat16, device_type="cuda"):
# outputs comprises loss & logits
outputs = model(**batch)
```
## Citation
Should you be using this model, please cite the original SeamlessM4Tv2 paper.
```
@misc{communication2023seamlessmultilingualexpressivestreaming,
title={Seamless: Multilingual Expressive and Streaming Speech Translation},
author={Seamless Communication and Loïc Barrault and Yu-An Chung and Mariano Coria Meglioli and David Dale and Ning Dong and Mark Duppenthaler and Paul-Ambroise Duquenne and Brian Ellis and Hady Elsahar and Justin Haaheim and John Hoffman and Min-Jae Hwang and Hirofumi Inaguma and Christopher Klaiber and Ilia Kulikov and Pengwei Li and Daniel Licht and Jean Maillard and Ruslan Mavlyutov and Alice Rakotoarison and Kaushik Ram Sadagopan and Abinesh Ramakrishnan and Tuan Tran and Guillaume Wenzek and Yilin Yang and Ethan Ye and Ivan Evtimov and Pierre Fernandez and Cynthia Gao and Prangthip Hansanti and Elahe Kalbassi and Amanda Kallet and Artyom Kozhevnikov and Gabriel Mejia Gonzalez and Robin San Roman and Christophe Touret and Corinne Wong and Carleigh Wood and Bokai Yu and Pierre Andrews and Can Balioglu and Peng-Jen Chen and Marta R. Costa-jussà and Maha Elbayad and Hongyu Gong and Francisco Guzmán and Kevin Heffernan and Somya Jain and Justine Kao and Ann Lee and Xutai Ma and Alex Mourachko and Benjamin Peloquin and Juan Pino and Sravya Popuri and Christophe Ropers and Safiyyah Saleem and Holger Schwenk and Anna Sun and Paden Tomasello and Changhan Wang and Jeff Wang and Skyler Wang and Mary Williamson},
year={2023},
eprint={2312.05187},
archivePrefix={arXiv},
primaryClass={cs.CL},
url={https://arxiv.org/abs/2312.05187},
}
```
|