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

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

相关推荐
SunsPlanter13 分钟前
机器学习期末
人工智能·机器学习
吹风看太阳15 分钟前
机器学习02——RNN
人工智能·rnn·机器学习
视觉&物联智能17 分钟前
【杂谈】-自动驾驶变革:货运革新与机器人出租车崛起
人工智能·ai·机器人·自动驾驶·agi
独立开阀者_FwtCoder25 分钟前
一口气讲清楚:LLM、MCP、EMB
前端·javascript·人工智能
蚝油菜花25 分钟前
让AI听懂你的建模需求!BlenderMCP:自然语言指令直接操控 Blender,一句话生成复杂3D场景
人工智能·开源
蚝油菜花27 分钟前
自然语言生成代码一键搞定!Codex CLI:OpenAI开源终端AI编程助手,代码重构+测试全自动
人工智能·开源
独立开阀者_FwtCoder30 分钟前
Cursor MCP推荐
前端·javascript·人工智能
三道杠卷胡34 分钟前
【AI News | 20250417】每日AI进展
人工智能·pytorch·python·语言模型·github
Tech Synapse36 分钟前
基于OpenCV与PyTorch的智能相册分类器全栈实现教程
人工智能·pytorch·opencv
BIOS菜鸟工程师40 分钟前
UEFI Spec 学习笔记---12 - Protocols —CONSOLE SUPPORT(一)
人工智能·笔记·学习