复现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可以多加利用

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

相关推荐
chenquan25 分钟前
ArkFlow 流处理引擎 0.4.0-rc1 发布
人工智能·后端·github
Se7en25831 分钟前
使用 Higress AI 网关代理 vLLM 推理服务
人工智能
AI大模型技术社36 分钟前
PyTorch手撕CNN:可视化卷积过程+ResNet18训练代码详解
人工智能·神经网络
明明跟你说过2 小时前
FastChat 架构拆解:打造类 ChatGPT 私有化部署解决方案的基石
人工智能·语言模型·chatgpt·openai
Listennnn2 小时前
Text2SQL、Text2API基础
数据库·人工智能
钒星物联网3 小时前
256bps!卫星物联网极低码率语音压缩算法V3.0发布!
人工智能·语音识别
Listennnn3 小时前
迁移学习基础
人工智能·迁移学习
Ven%3 小时前
语言模型进化论:从“健忘侦探”到“超级大脑”的破案之旅
人工智能·语言模型·自然语言处理
tryCbest3 小时前
MoneyPrinterTurbo根据关键词自动生成视频
人工智能·ai
飞凌嵌入式3 小时前
基于RK3588,飞凌教育品牌推出嵌入式人工智能实验箱EDU-AIoT ELF 2
linux·人工智能·嵌入式硬件·arm·nxp