复现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)聊天的官方仓库和由阿里云提出的预训练大型音频语言模型。https://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 复制下面代码

python 复制代码
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可以多加利用

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

相关推荐
Allen_LVyingbo5 分钟前
Scrum方法论指导下的Deepseek R1医疗AI部署开发
人工智能·健康医疗·scrum
Watermelo61720 分钟前
从DeepSeek大爆发看AI革命困局:大模型如何突破算力囚笼与信任危机?
人工智能·深度学习·神经网络·机器学习·ai·语言模型·自然语言处理
Donvink22 分钟前
【DeepSeek-R1背后的技术】系列九:MLA(Multi-Head Latent Attention,多头潜在注意力)
人工智能·深度学习·语言模型·transformer
计算机软件程序设计28 分钟前
深度学习在图像识别中的应用-以花卉分类系统为例
人工智能·深度学习·分类
Ainnle34 分钟前
企业级RAG开源项目分享:Quivr、MaxKB、Dify、FastGPT、RagFlow
人工智能·开源
小天努力学java1 小时前
AI赋能传统系统:Spring AI Alibaba如何用大模型重构机票预订系统?
人工智能·spring
Fuweizn1 小时前
在工业生产中,物料搬运环节至关重要,搬运机器人开启新篇章
人工智能·智能机器人·复合机器人
技术员阿伟2 小时前
《AI赋能星际探索:机器人如何开启宇宙新征程!》
人工智能
技术员阿伟2 小时前
《解锁AI密码,机器人精准感知环境不再是梦!》
人工智能
AL.千灯学长3 小时前
DeepSeek接入Siri(已升级支持苹果手表)完整版硅基流动DeepSeek-R1部署
人工智能·gpt·ios·ai·苹果vision pro