Views
No views yet

facebook/wav2vec2-xls-r-2b checkpoint and
the decoder from the facebook/mbart-large-50 checkpoint.
Consequently, the encoder-decoder model was fine-tuned on {input_lang} -> {output_lang} translation pairs
of the Covost2 dataset.{input_lang} to the following written languages {output_lang}:{input_lang} -> {output_lang}{input_lang} one of:en, fr, de, es, ca, it, ru, zh-CN, pt, fa, et, mn, nl, tr, ar, sv-SE, lv, sl, ta, ja, id, cy}{output_lang}:en, de, tr, fa, sv-SE, mn, zh-CN, cy, ca, sl, et, id, ar, ta, lv, ja}generate method to generate the
transcripts by passing the speech features to the model.forced_bos_token_id to generate(...) to condition
the decoder on the correct target language.forced_bos_token_id given your choosen language id, please make use
of the following mapping:1MAPPING = {
2 "en": 250004,
3 "de": 250003,
4 "tr": 250023,
5 "fa": 250029,
6 "sv": 250042,
7 "mn": 250037,
8 "zh": 250025,
9 "cy": 250007,
10 "ca": 250005,
11 "sl": 250052,
12 "et": 250006,
13 "id": 250032,
14 "ar": 250001,
15 "ta": 250044,
16 "lv": 250017,
17 "ja": 250012,
18}1from datasets import load_dataset
2from transformers import pipeline
3
4# select correct `forced_bos_token_id`
5forced_bos_token_id = MAPPING["sv"]
6
7# replace following lines to load an audio file of your choice
8librispeech_en = load_dataset("patrickvonplaten/librispeech_asr_dummy", "clean", split="validation")
9audio_file = librispeech_en[0]["file"]
10
11asr = pipeline("automatic-speech-recognition", model="facebook/wav2vec2-xls-r-2b-22-to-16", feature_extractor="facebook/wav2vec2-xls-r-2b-22-to-16")
12
13translation = asr(audio_file, forced_bos_token_id=forced_bos_token_id)1import torch
2from transformers import Speech2Text2Processor, SpeechEncoderDecoderModel
3from datasets import load_dataset
4
5model = SpeechEncoderDecoderModel.from_pretrained("facebook/wav2vec2-xls-r-2b-22-to-16")
6processor = Speech2Text2Processor.from_pretrained("facebook/wav2vec2-xls-r-2b-22-to-16")
7
8ds = load_dataset("patrickvonplaten/librispeech_asr_dummy", "clean", split="validation")
9
10# select correct `forced_bos_token_id`
11forced_bos_token_id = MAPPING["sv"]
12
13inputs = processor(ds[0]["audio"]["array"], sampling_rate=ds[0]["audio"]["array"]["sampling_rate"], return_tensors="pt")
14generated_ids = model.generate(input_ids=inputs["input_features"], attention_mask=inputs["attention_mask"], forced_bos_token_id=forced_bos_token)
15transcription = processor.batch_decode(generated_ids){lang} -> en Speech Translation