Text-to-speech मॉडलों का फाइन-ट्यूनिंग

Hugging Face के साथ मल्टी-मोडल मॉडल्स

James Chapman

Curriculum Manager, DataCamp

Text-to-speech का फाइन-ट्यूनिंग क्यों?

 

  • नई भाषाओं और बोलियों की ध्वनियाँ सीखें
  • नए संदर्भों में लागू करें

उदा., बड़ा English भाषा general pretraining मॉडल ⇏ यथार्थवादी Italian स्पीच

कार्टून अंग्रेज़ी और इतालवी स्पीच बबल्स

Hugging Face के साथ मल्टी-मोडल मॉडल्स

Text-to-speech का फाइन-ट्यूनिंग क्यों?

स्पीच एम्बेडिंग स्पीच जेनरेशन पाइपलाइन में कैसे फिट होती है, इसका डायग्राम

  • Speaker embedding + text-to-speech मॉडल फीचर्स → जेनरेटिव मॉडल
  • केवल नए speaker embedding पर्याप्त नहीं होते, फाइन-ट्यूनिंग चाहिए
Hugging Face के साथ मल्टी-मोडल मॉडल्स

ऑडियो डेटासेट तैयार करना

VoxPopuli डेटासेट: EU संसद से 18 भाषाओं के ट्रांसक्राइब्ड स्पीच डेटा

from datasets import load_dataset
dataset = load_dataset("facebook/voxpopuli", "it", split="train", 
                       trust_remote_code=True)
print(dataset.features)
['audio', 'raw_text', 'normalized_text', 'gender', 'speaker_id', ... ]
  • ऑडियो को प्रीप्रोसेस करना है + स्पीच एम्बेडिंग जोड़नी हैं:
speaker_model = EncoderClassifier.from_hparams(source="speechbrain/spkrec-xvect-voxceleb", 
                                       savedir="pretrained_models/spkrec-xvect-voxceleb")
Hugging Face के साथ मल्टी-मोडल मॉडल्स

ऑडियो प्रीप्रोसेसिंग

from transformers import SpeechT5Processor
processor = SpeechT5Processor.from_pretrained("microsoft/speecht5_tts")


def prepare_dataset(example): audio = example["audio"] example = processor(text=example["normalized_text"], audio_target=audio["array"], sampling_rate=audio["sampling_rate"], return_attention_mask=False)
example["labels"] = example["labels"][0]
with torch.no_grad(): speaker_embeddings = speaker_model.encode_batch(torch.tensor(audio["array"])) speaker_embeddings = torch.nn.functional.normalize(speaker_embeddings, dim=2) example["speaker_embeddings"] = speaker_embeddings.squeeze().cpu().numpy() return example
dataset = dataset.map(prepare_dataset)
Hugging Face के साथ मल्टी-मोडल मॉडल्स

ट्रेनिंग आर्ग्यूमेंट्स

from transformers import Seq2SeqTrainingArguments


training_args = Seq2SeqTrainingArguments( per_device_train_batch_size=4,
gradient_accumulation_steps=8,
learning_rate=1e-5,
warmup_steps=500,
label_names=["labels"],
data_collator=data_collator )
Hugging Face के साथ मल्टी-मोडल मॉडल्स

सब कुछ जोड़ना

model = SpeechT5ForTextToSpeech.from_pretrained("microsoft/speecht5_tts")
processor = SpeechT5Processor.from_pretrained("microsoft/speecht5_tts")
vocoder = SpeechT5HifiGan.from_pretrained("microsoft/speecht5_hifigan")

Trainer:

trainer = Seq2SeqTrainer(args=training_args, model=model,
    train_dataset=dataset["train"], eval_dataset=dataset["test"],
                         tokenizer=processor)

ट्रेनिंग चलाएँ: trainer.train()

Hugging Face के साथ मल्टी-मोडल मॉडल्स

नए मॉडल का उपयोग

text = "se sono italiano posso cantare l'opera lirica"


speaker_embedding = torch.tensor(dataset[5]["speaker_embeddings"]).unsqueeze(0)
inputs = processor(text=text, return_tensors="pt")
speech = model.generate_speech(inputs["input_ids"], speaker_embedding, vocoder=vocoder)
make_spectrogram(speech)
Hugging Face के साथ मल्टी-मोडल मॉडल्स

नए मॉडल का उपयोग

इतालवी स्पीच का स्पेक्ट्रोग्राम

Hugging Face के साथ मल्टी-मोडल मॉडल्स

अभ्यास करते हैं!

Hugging Face के साथ मल्टी-मोडल मॉडल्स

Preparing Video For Download...