复现Qwen-Audio 千问

Qwen-Audio(Qwen 大型音频语言模型)是阿里云提出的大型模型系列 Qwen(简称通义千文)的多模态版本。Qwen-Audio 接受各种音频(人类语音、自然声音、音乐和歌曲)和文本作为输入、输出文本。Qwen-Audio 的贡献包括:

  • 基础音频模型:Qwen-Audio 是一种基础的多任务音频语言模型,支持各种任务、语言和音频类型,是通用的音频理解模型。在 Qwen-Audio 的基础上,我们通过指令微调开发了 Qwen-Audio-Chat,实现了多回合对话,并支持多样化的音频场景。
  • 适用于所有类型音频的多任务学习框架:为了扩大音频语言预训练的规模,我们通过提出多任务训练框架来解决与不同数据集相关的文本标签变化的挑战,实现知识共享并避免一对多干扰。我们的模型包含 30 多个任务,广泛的实验表明该模型取得了强大的性能。
  • 性能强劲:实验结果表明,Qwen-Audio 在各种基准测试任务中都取得了令人印象深刻的性能,无需任何特定于任务的微调,超越了同类产品。具体来说,Qwen-Audio 在 Aishell1、cochlscene、ClothoAQA 和 VocalSound 的测试集上取得了最先进的结果。
  • 从音频和文本输入灵活地进行多次运行聊天:Qwen-Audio 支持多音频分析、声音理解和推理、音乐欣赏和工具使用。

QwenLM/Qwen-Audio:Qwen-Audio(通义千问-Audio)聊天的官方仓库和由阿里云提出的预训练大型音频语言模型。icon-default.png?t=O83Ahttps://github.com/QwenLM/Qwen-Audio

1、下载仓库并解压

2、安装环境

  • Python 3.8 及更高版本
  • 建议使用 PyTorch 1.12 及以上版本、2.0 及以上版本
  • 建议使用 CUDA 11.4 及更高版本(适用于 GPU 用户)
  • FFmpeg
  • pip install -r requirements.txt

 3、新建test.py 复制下面代码

from transformers import AutoModelForCausalLM, AutoTokenizer
from transformers.generation import GenerationConfig
import torch
torch.manual_seed(1234)

# Note: The default behavior now has injection attack prevention off.
tokenizer = AutoTokenizer.from_pretrained("Qwen/Qwen-Audio-Chat", trust_remote_code=True)

# use bf16
# model = AutoModelForCausalLM.from_pretrained("Qwen/Qwen-Audio-Chat", device_map="auto", trust_remote_code=True, bf16=True).eval()
# use fp16
# model = AutoModelForCausalLM.from_pretrained("Qwen/Qwen-Audio-Chat", device_map="auto", trust_remote_code=True, fp16=True).eval()
# use cpu only
# model = AutoModelForCausalLM.from_pretrained("Qwen/Qwen-Audio-Chat", device_map="cpu", trust_remote_code=True).eval()
# use cuda device
model = AutoModelForCausalLM.from_pretrained("Qwen/Qwen-Audio-Chat", device_map="cuda", trust_remote_code=True).eval()

# Specify hyperparameters for generation (No need to do this if you are using transformers>4.32.0)
# model.generation_config = GenerationConfig.from_pretrained("Qwen/Qwen-Audio-Chat", trust_remote_code=True)

# 1st dialogue turn
query = tokenizer.from_list_format([
    {'audio': 'assets/audio/1272-128104-0000.flac'}, # Either a local path or an url
    {'text': 'what does the person say?'},
])
response, history = model.chat(tokenizer, query=query, history=None)
print(response)
# The person says: "mister quilter is the apostle of the middle classes and we are glad to welcome his gospel".

# 2nd dialogue turn
response, history = model.chat(tokenizer, 'Find the start time and end time of the word "middle classes"', history=history)
print(response)
# The word "middle classes" starts at <|2.33|> seconds and ends at <|3.26|> seconds.

query 传入的是音频地址,text是提示词 ,因为可以连续问答,所有history可以多加利用

复现没遇到什么问题,如果遇到问题,请留言

评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

请站在我身后

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值