Downloads · 30 days
4
4% of all-time downloads
KaileyM/qwen2audio-lora-music-descriptor
qwen2audio-lora-music-descriptor is a text generation model from KaileyM. Use it when you need the model to write or continue text. It is set up for peft.
Fine-tuned Model for creating musical descriptions
Downloads · 30 days
4
4% of all-time downloads
All-time downloads
102
Public
Repo size
44.1 MB
Likes
1
Public
Click a slice to open those files.
.safetensors22.1 MB · 100%
From the Hugging Face model README
Fine-tuned Model for creating musical descriptions
Qwen2-Audio-7B was fine-tuned using LoRA for the task of music decription
Enter an audio file of music and get a textual description of how it sounds.
Use the code below to get started with the model.
Must load Qwen2-Audio-7B and apply this model as a PEFT adapter:
quantization_config = BitsAndBytesConfig(
load_in_4bit=True,
bnb_4bit_quant_type="nf4", # Or "fp4"
bnb_4bit_compute_dtype="float16",
bnb_4bit_use_double_quant=True
)
base_model = Qwen2AudioForConditionalGeneration.from_pretrained("Qwen/Qwen2-Audio-7B", quantization_config=quantization_config,
device_map="auto", trust_remote_code=True)
lora_model = PeftModel.from_pretrained(temp, "KaileyM/qwen2audio-lora-music-descriptor", device_map="auto")
processor = AutoProcessor.from_pretrained("Qwen/Qwen2-Audio-7B" ,trust_remote_code=True)
Making a description:
def describe_music(audio, model):
prompt = "<|audio_bos|><|AUDIO|><|audio_eos|>Describe the music thoroughly:"
inputs = processor(text=prompt, audio=audio, sampling_rate=16000, padding=False, return_tensors="pt")
inputs = {k: v.to(model.device) for k, v in inputs.items()}
with torch.no_grad():
generated_ids = model.generate(**inputs, max_new_tokens=128)
# remove prompt tokens from generation
generated_ids = generated_ids[:, inputs["input_ids"].size(1):]
description = processor.decode(
generated_ids, skip_special_tokens=True)
return description
Trained and tested on the MusicCaps dataset: https://huggingface.co/datasets/google/MusicCaps
training_args = TrainingArguments( output_dir="./audio-qwen-lora", save_strategy="epoch", eval_strategy="epoch", logging_strategy="epoch", learning_rate = 1e-4, per_device_train_batch_size=4, per_device_eval_batch_size=4, gradient_accumulation_steps=8, num_train_epochs=3, report_to="none", load_best_model_at_end=True, fp16=True, ) <!--fp32, fp16 mixed precision, bf16 mixed precision, bf16 non-mixed precision, fp16 non-mixed precision, fp8 mixed precision -->Evaluated using BLEU, METEOR, ROUGE, and BERT-Score to measure similarity with the original reference descriptions