BaşlayınÜcretsiz başlayın

Passing keyword arguments

In this exercise, you will learn how to pass keyword arguments to model functions when used inside a pipeline.

For this you will be using the MusicGen small model from Meta, which is capable of generating music samples based on text descriptions or audio prompts.

The pipeline module has been loaded, and the soundfile library is available as sf.

Bu egzersiz, kursun bir parçasıdır

Multi-Modal Models with Hugging Face

Kursa Göz Atın

Egzersiz talimatları

  • Load a text-to-audio pipeline using the facebook/musicgen-small model in the PyTorch framework.
  • Make a dictionary called generate_kwargs to set the generation temperature to 0.8 and max_new_tokens to 1.
  • Generate an audio array using the "Classic rock riff" prompt, adjusting the generation parameters with your generate_kwargs dictionary.

Uygulamalı etkileşimli egzersiz

Bu egzersizi bu örnek kodu tamamlayarak deneyin.

# Load a text-to-audio pipeline
musicgen = pipeline(task="____", model="____", framework="pt")

# Make a dictionary to set the generation temperature to 0.8 and max_new_tokens to 1
generate_kwargs = {"____": ____, "____": ____}

# Generate an audio array passing the arguments
outputs = ____("____", ____=____)
sf.write("output.wav", outputs["audio"][0][0], outputs["sampling_rate"])
Kodu Düzenle ve Çalıştır