模型简介
模型特点
模型能力
使用案例
SpeechGPT:赋予大型语言模型内在跨模态对话能力
简介
SpeechGPT是一个具备内在跨模态对话能力的大型语言模型,能够根据人类指令感知和生成多模态内容。通过离散语音表征,我们首先构建了SpeechInstruct——一个大规模的跨模态语音指令数据集。此外,我们采用三阶段训练策略,包括模态适应预训练、跨模态指令微调和模态链式指令微调。实验结果表明,SpeechGPT具有出色的多模态人类指令跟随能力,并展现了单一模型处理多模态任务的潜力。
SpeechGPT的演示展示在我们的项目主页上。如演示所示,SpeechGPT具备强大的跨模态指令跟随能力和口语对话能力。它可以成为会说话的百科全书、您的个人助理、聊天伙伴、诗人、心理医生和教育助手...
SpeechGPT处理多种跨模态任务的能力
左:SpeechInstruct构建流程。右:SpeechGPT模型结构
发布
- [2023/9/15] 我们发布了SpeechGPT代码、检查点及SpeechInstruct数据集。
- [2023/9/1] 我们提出SpeechTokenizer:语音语言模型的统一语音分词器。我们发布了SpeechTokenizer的代码和检查点。查看论文、演示和GitHub。
- [2023/5/18] 我们发布SpeechGPT:赋予大型语言模型内在跨模态对话能力。我们提出SpeechGPT,这是首个能够根据多模态人类指令感知和生成多模态内容的多模态LLM。查看论文和演示。
目录
开源列表
模型
- SpeechGPT-7B-ma:第一阶段模态适应预训练后获得的模型,该模型以LLaMA-7B初始化,并在LibriLight语音单元上进一步预训练。
- SpeechGPT-7B-cm:第二阶段跨模态指令微调后获得的模型,该模型以SpeechGPT-7B-ma初始化,并在SpeechInstruct跨模态指令集上进一步微调。这是一个强大的基础模型,能够对齐语音和文本。
- SpeechGPT-7B-com:第三阶段模态链式指令微调后获得的模型,该模型以SpeechGPT-7B-cm初始化,并在SpeechInstruct模态链式指令集上进一步LoRA微调。这是SpeechGPT-7B-cm的适配器模型,用于口语对话。
数据集
- SpeechInstruct-cross-modal:跨模态指令集,约900万对由mHuBERT从大规模英语ASR数据集标记化的单元-文本数据对。数据格式:
- SpeechInstruct-chain-of-modality:针对四种输入-输出格式的思维链式指令,即语音指令-语音响应、语音指令-文本响应、文本指令-语音响应和文本指令-文本响应。
SpeechInstruct-cross-modal数据格式:
[
{
"prefix": "You are an AI assistant whose name is SpeechGPT.\n- SpeechGPT is a intrinsic cross-modal conversational language model that is developed by Fudan University. SpeechGPT can understand and communicate fluently with human through speech or text chosen by the user.\n- It can perceive cross-modal inputs and generate cross-modal outputs.\n",
"plain_text": "[Human]: Try to speak out this sentence, please. This is input: The alchemist rode in front, with the falcon on his shoulder.<eoh> [SpeechGPT]: <sosp><661><588><604><157><596><499><596><106><596><189><63><189><665><991><162><202><393><946><327><905><907><597><660><351><557><794><788><59><754><12><977><877><333><873><835><67><940><118><686><613><169><72><644><553><535><935><101><741><384><173><894><787><380><787><196><555><721><944><250><56><812><222><915><143><390><479><330><435><647><246><650><816><325><506><686><208><613><417><755><193><411><452><111><735><6><735><63><665><644><991><535><271><333><196><918><29><202><393><946><734><390><479><330><776><167><761><907><597><660><351><557><794><75><788><15><366><896><627><168><654><659><177><183><609><710><187><493><361><470><821><59><56><198><912><742><840><431><531><76><668><576><803><791><380><660><325><801><549><366><377><164><309><584><605><193><71><39><eosp><eoa> "
},
]
SpeechInstruct-chain-of-modality数据格式:
[
{
"prefix": "You are an AI assistant whose name is SpeechGPT.\n- SpeechGPT is a intrinsic cross-modal conversational language model that is developed by Fudan University. SpeechGPT can understand and communicate fluently with human through speech or text chosen by the user.\n- It can perceive cross-modal inputs and generate cross-modal outputs.\n",
"plain_text": "[Human]: <sosp><661><987><511><732><951><997><111><982><189><63><665><991><535><101><741><173><945><944><503><641><124><565><734><870><290><978><833><238><761><907><430><901><185><403><557><244><583><788><663><969><896><627><143><515><663><969><660><691><251><412><260><41><740><677><253><380><382><268><506><876><417><755><16><819><80><651><80><651><80><987><588><eosp><eoh>. [SpeechGPT]: What is a bad term for poop?; [ta] A bad term for poop is excrement. It is usually used as a polite way to refer to fecal waste.; [ua] <sosp><497><63><264><644><710><823><565><577><154><331><384><173><945><29><244><326><583><728><576><663><969><896><627><143><38><515><663><24><382><251><676><412><260><41><740><677><253><382><268><876><233><878><609><389><771><865><641><124><878><609><423><384><879><487><219><522><589><337><126><119><663><748><12><671><877><377><385><902><819><619><842><419><997><829><111><666><42><277><63><665><644><389><771><685><437><641><124><258><436><139><340><11><59><518><56><948><86><258><436><139><340><347><376><940><118><944><878><173><641><124><362><734><179><961><931><878><609><423><384><879><219><522><866><337><243><935><101><741><822><89><194><630><86><555><105><79><868><220><156><824><998><870><390><422><330><776><663><969><523><105><79><799><220><357><390><479><422><330><776><485><165><86><501><119><716><205><521><787><935><101><741><89><194><664><835><67><940><118><613><417><755><902><415><772><497><eosp><eoa>."
},
]
与SpeechGPT对话
由于训练数据和资源有限,开源版SpeechGPT目前性能尚未达到最优。可能会出现任务识别错误、语音识别不准确等问题。由于本项目主要为研究探索性质,我们未通过增加预训练和SFT数据量或训练步数来提升性能。我们希望SpeechGPT能作为基础模型,推动语音语言模型领域的研究探索。
安装
git clone https://github.com/0nutation/SpeechGPT
cd SpeechGPT
conda create --name SpeechGPT python=3.8
conda activate SpeechGPT
pip install -r requirements.txt
下载
要与SpeechGPT对话,您需要下载SpeechGPT-7B-cm和SpeechGPT-7B-com到本地。
您需要下载mHuBERT模型至utils/speech2unit/
。详情请参阅Speech2unit。
s2u_dir="uitls/speech2unit"
cd ${s2u_dir}
wget https://dl.fbaipublicfiles.com/hubert/mhubert_base_vp_en_es_fr_it3.pt
wget https://dl.fbaipublicfiles.com/hubert/mhubert_base_vp_en_es_fr_it3_L11_km1000.bin
您需要下载单元声码器至utils/vocoder/
。详情请参阅声码器。
vocoder_dir="utils/vocoder/"
cd ${vocoder_dir}
wget https://dl.fbaipublicfiles.com/fairseq/speech_to_speech/vocoder/code_hifigan/mhubert_vp_en_es_fr_it3_400k_layer11_km1000_lj/config.json -O config.json
wget https://dl.fbaipublicfiles.com/fairseq/speech_to_speech/vocoder/code_hifigan/mhubert_vp_en_es_fr_it3_400k_layer11_km1000_lj/g_00500000 -O vocoder.pt
命令行推理
python3 speechgpt/src/infer/cli_infer.py \
--model-name-or-path "path/to/SpeechGPT-7B-cm" \
--lora-weights "path/to/SpeechGPT-7B-com" \
--s2u-dir "${s2u_dir}" \
--vocoder-dir "${vocoder_dir} \
--output-dir "output"
注意
对于语音输入,您可以提供音频文件路径。对于ASR或TTS任务,必须在语音或文本前加上this is input:
前缀,否则可能识别错误。
语音响应将保存为.wav
文件,详细响应将保存在JSON文件中。响应中将指示这些文件的路径。
以下是与SpeechGPT对话的示例:
文本对话示例
请与SpeechGPT对话:
勒布朗·詹姆斯是谁?
响应:
勒布朗·詹姆斯是美国职业篮球运动员,效力于NBA洛杉矶湖人队。他被认为是有史以来最伟大的篮球运动员之一,以其运动能力、得分能力和领导才能闻名。他是四次NBA MVP、14次NBA全明星、13次入选NBA最佳阵容和两次奥运会金牌得主。
响应json保存在output/responses.json
语音对话示例
请与SpeechGPT对话:
prompts/0.wav
转录: 气候变化的主要原因是什么?
文本响应: 气候变化的主要原因是人类活动,如燃烧化石燃料、森林砍伐和农业实践。这些活动释放温室气体,如二氧化碳和甲烷,到大气中,这些气体会捕获热量并导致地球温度上升。
语音响应保存在output/wav/answer_0.wav
响应json保存在output/responses.json
ASR示例
请与SpeechGPT对话:
识别这段语音,this is input: prompts/1.wav
响应:
今天是个晴天。
响应json保存在output/responses.json
TTS示例
请与SpeechGPT对话:
朗读这句话,this is input: 今天是个晴天。
响应:
<sosp> <661> <987> <520> <982> <681> <982> <681> <982> <681> <982> <681> <982> <189> <63> <662> <79> <868> <220> <196> <166> <549> <822> <89> <194> <633> <14> <855> <183> <609> <389> <771> <865> <641> <124> <362> <734> <742> <98> <519> <26> <204> <280> <668> <167> <104> <650> <179> <961> <428> <950> <82> <165> <196> <166> <549> <822> <89> <194> <458> <726> <603> <819> <651> <133> <651> <133> <186> <133> <186> <133> <186> <511> <186> <511> <eosp>
语音响应保存在output/wav/answer_1.wav
响应json保存在output/responses.json
Gradio网页界面
python3 speechgpt/src/infer/web_infer.py \
--model-name-or-path "path/to/SpeechGPT-7B-cm" \
--lora-weights "path/to/SpeechGPT-7B-com" \
--s2u-dir "${s2u_dir}" \
--vocoder-dir "${vocoder_dir}" \
--output-dir "output/"
训练SpeechGPT
阶段1:模态适应预训练
首先,使用mHuBERT对LibriLight数据集进行离散化,获得阶段1训练所需的离散单元序列。您可以参考Speech2unit中的数据处理方法。
其次,将离散单元划分为训练集和开发集,并按以下格式保存在文件data/stage1/train.txt
和data/stage1/dev.txt
中:
<sosp><189><247><922><991><821><258><485><974><284><466><969><523><196><202><881><331><822><853><432><32><742><98><519><26><204><280><576><384><879><901><555><944><366><641><124><362><734><156><824><462><761><907><430><81><597><716><205><521><470><821><677><355><483><641><124><243><290><978><82><620><915><470><821><576><384><466><398><212><455><931><579><969><778><45><914><445><469><576><803><6><803><791><377><506><835><67><940><613><417><755><237><224><452><121><736><eosp>
<sosp><300><189><63><6><665><991><881><331><6><384><879><945><29><244><583><874><655><837><81><627><545><124><337><850><412><213><260><41><740><797><211><488><961><428><6><196><555><944><873><32><683><700><955><812><328><915><166><250><56><903><86><233><479><330><776><167><104><764><259><921><366><663><432><431><531><976><314><822><89><664><377><611><479><417><eosp>
<sosp><189><735><991><39><565><734><32><742><98><519><26><204><280><668><576><803><791><660><555><233><787><101><741><466><969><219><107><459><491><556><384><733><219><501><445><137><910><523><793><50><981><230><534><321><948><86><116><281><62><462><104><70><918><743><15><212><455><143><836><173><944><958><390><422><66><776><258><436><139><663><432><742><98><519><589><243><126><260><41><444><6><655><764><969><219><727><85><297><700><362><493><6><493><361><393><946><6><470><821><246><655><837><81><969><916><584><819><544><452><158><452><736><eosp>
第三,您需要下载LLaMA 7B(HuggingFace)至llama/hf/7B
。
现在您可以开始阶段1训练:
要进行分布式训练,必须为NNODE
、NODE_RANK
、MASTER_ADDR
和MASTER_PORT
指定正确的值。
bash scripts/ma_pretrain.sh ${NNODE} ${NODE_RANK} ${MASTER_ADDR} ${MASTER_PORT}
阶段2:跨模态指令微调
您需要下载SpeechInstruct跨模态指令集至data/stage2/
。
如果想跳过阶段1训练,可以下载SpeechGPT-7B-ma
至output/stage1/
。
现在您可以开始阶段2训练:
要进行分布式训练,必须为NNODE
、NODE_RANK
、MASTER_ADDR
和MASTER_PORT
指定正确的值。
bash scripts/cm_sft.sh ${NNODE} ${NODE_RANK} ${MASTER_ADDR} ${MASTER_PORT}
阶段3:模态链式指令微调
您需要下载SpeechInstruct模态链式指令集至data/stage3/
。
如果想跳过阶段1和阶段2,可以下载SpeechGPT-7B-cm
至output/stage2/
。
现在您可以开始阶段3训练:
要进行分布式训练,必须为NNODE
、NODE_RANK
、MASTER_ADDR
和MASTER_PORT
指定正确的值。
bash scripts/com_sft.sh ${NNODE} ${NODE_RANK} ${MASTER_ADDR} ${MASTER_PORT}
微调SpeechGPT
Speech-7B-cm
是一个基础模型,具有强大的语音和文本对齐能力。我们鼓励基于此模型微调SpeechGPT。
步骤1:按照SpeechInstruct跨模态指令集中的格式准备您的数据。
步骤2:下载SpeechGPT-7B-cm到本地。
步骤3:修改scripts/cm_sft.sh
脚本中的METAROOT
、DATAROOT
和OUTROOT
参数为您的路径,然后运行。对于LoRA微调,更新scripts/com_sft.sh
脚本中的METAROOT
、DATAROOT
和OUTROOT
参数并运行。
致谢
- MOSS:我们使用了moss-sft-002-data。
- stanford_alpaca:我们基于的代码库。
引用
如果您发现SpeechGPT对您的研究和应用有帮助,请使用以下BibTex引用:
@misc{zhang2023speechgpt,
title={SpeechGPT: Empowering Large Language Models with Intrinsic Cross-Modal Conversational Abilities},
author={张东 and 李诗敏 and 张欣 and 占俊 and 王鹏宇 and 周雅倩 and 邱锡鹏},
year={2023},
eprint={2305.11000},
archivePrefix={arXiv},
primaryClass={cs.CL}
}











