Views
No views yet
1git clone https://gitlab.com/horizon-europe-voxreality/multilingual-translation/speech-translation-demo.git
2cd speech-translation-demo
3# You might need to switch to dev branch
4pip install -e transformersuse_adapters is used to decide whether we will use the adapters or not. It needs to be set to True only in the case of Greek.1from transformers import WhisperProcessor, WhisperForConditionalGenerationWithAdapters
2from datasets import Audio, load_dataset
3
4# load model and processor
5processor = WhisperProcessor.from_pretrained("voxreality/whisper-small-el-adapters")
6model = WhisperForConditionalGenerationWithAdapters.from_pretrained("voxreality/whisper-small-el-adapters")
7forced_decoder_ids = processor.get_decoder_prompt_ids(language="greek", task="transcribe")
8
9# load streaming dataset and read first audio sample
10ds = load_dataset("mozilla-foundation/common_voice_11_0", "el", split="test", streaming=True)
11ds = ds.cast_column("audio", Audio(sampling_rate=16_000))
12input_speech = next(iter(ds))["audio"]
13input_features = processor(input_speech["array"], sampling_rate=input_speech["sampling_rate"], return_tensors="pt").input_features
14
15# Set use_adapters to False for languages other than Greek.
16# generate token ids
17predicted_ids = model.generate(input_features, forced_decoder_ids=forced_decoder_ids, use_adapters=True)
18
19# decode token ids to text
20transcription = processor.batch_decode(predicted_ids, skip_special_tokens=True)1from transformers import pipeline
2from datasets import Audio, load_dataset
3
4ds = load_dataset("mozilla-foundation/common_voice_11_0", "el", split="test", streaming=True)
5ds = ds.cast_column("audio", Audio(sampling_rate=16_000))
6input_speech = next(iter(ds))["audio"]
7
8model = WhisperForConditionalGenerationWithAdapters.from_pretrained("voxreality/whisper-small-el-adapters")
9
10pipe = pipeline("automatic-speech-recognition", model=model, tokenizer="voxreality/whisper-small-el-adapters",
11 "voxreality/whisper-small-el-adapters", device='cpu', batch_size=32)
12
13transcription = pipe(input_speech['array'], generate_kwargs = {"language":f"<|el|>","task": "transcribe", "use_adapters": True})