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

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

相关推荐
kailp1 小时前
云渲染技术解析与渲酷平台深度测评:如何实现高效3D创作?
人工智能·深度学习·3d·渲染·gpu算力
liuyang-neu2 小时前
目标检测 Lite-DETR(2023)详细解读
人工智能·目标检测·计算机视觉
Tech Synapse2 小时前
深度解析3D模型生成器:基于StyleGAN3与PyTorch3D的多风格生成工具开发实战
人工智能·pytorch·深度学习·3d
Qforepost2 小时前
英伟达有意入股 PsiQuantum,释放战略转向量子计算的重要信号
人工智能·量子计算·量子
Blossom.1182 小时前
量子计算在金融科技中的应用前景
大数据·人工智能·安全·机器学习·计算机视觉·金融·量子计算
旺仔溜溜没3 小时前
Autodl训练Faster-RCNN网络(自己的数据集)
人工智能·深度学习·神经网络·cnn
广州华锐视点3 小时前
VR 航天科普,沉浸式体验宇宙奥秘
人工智能·vr
纠结哥_Shrek3 小时前
ollama+open-webui搭建可视化大模型聊天
人工智能·电商·ollama·open-webui
熊猫在哪4 小时前
野火鲁班猫(arrch64架构debian)从零实现用MobileFaceNet算法进行实时人脸识别(一)conda环境搭建
linux·人工智能·python·嵌入式硬件·神经网络·机器学习·边缘计算
技能咖4 小时前
人工智能解析:技术革命下的认知重构
人工智能·重构