musiclm-pytorch

musiclm-pytorch

Pytorch实现的音乐生成模型MusicLM

MusicLM-Pytorch通过使用Google的新型SOTA音乐生成模型来生成音乐。该项目结合了文本条件的AudioLM和MuLan文本-音频对比学习模型。通过MuLaNEmbedQuantizer获取条件嵌入,用户可以在经过训练后,实现语义、粗粒度和细粒度的三种AudioLM转换器的音乐生成。项目包含详细的安装和使用指南,适合对AI音乐生成技术感兴趣的开发者。

MusicLMPytorchMuLaNAudioLM音乐生成Github开源项目

<img src="https://yellow-cdn.veclightyear.com/35dd4d3f/9803596a-1c91-4369-9714-56b4c44b3a14.png" width="450px"></img>

MusicLM - Pytorch

使用注意力网络在Pytorch中实现<a href="https://google-research.github.io/seanet/musiclm/examples/">MusicLM</a>,Google最新的SOTA音乐生成模型。

他们基本上是在使用文本条件的<a href="https://github.com/lucidrains/audiolm-pytorch">AudioLM</a>,但令人惊讶的是,使用了一个名为<a href="https://arxiv.org/abs/2208.12415">MuLan</a>的文本-音频对比学习模型的嵌入。本库将构建MuLan,并从另一个库中修改AudioLM以支持此处的音乐生成需求。

如果你对与<a href="https://laion.ai/">LAION</a>社区一起进行复现感兴趣,请加入<a href="https://discord.gg/xBPBXfcFHd"><img alt="Join us on Discord" src="https://yellow-cdn.veclightyear.com/35dd4d3f/5b6b230e-5a6e-4785-931c-662fafa70c5c.png"></a>

<a href="https://www.youtube.com/watch?v=jTrYIGxOuKQ">Louis Bouchard的What's AI</a>

感谢

  • 感谢<a href="https://stability.ai/">Stability.ai</a>慷慨赞助以研究和开源尖端的人工智能技术

  • 感谢<a href="https://huggingface.co/">🤗 Huggingface</a>提供的<a href="https://huggingface.co/docs/accelerate/index">accelerate</a>训练库

使用方法

$ pip install musiclm-pytorch

使用方法

首先需要训练MuLaN

import torch from musiclm_pytorch import MuLaN, AudioSpectrogramTransformer, TextTransformer audio_transformer = AudioSpectrogramTransformer( dim = 512, depth = 6, heads = 8, dim_head = 64, spec_n_fft = 128, spec_win_length = 24, spec_aug_stretch_factor = 0.8 ) text_transformer = TextTransformer( dim = 512, depth = 6, heads = 8, dim_head = 64 ) mulan = MuLaN( audio_transformer = audio_transformer, text_transformer = text_transformer ) # 获取大量<声音, 文本>对并进行训练 wavs = torch.randn(2, 1024) texts = torch.randint(0, 20000, (2, 256)) loss = mulan(wavs, texts) loss.backward() # 经过大量训练后,你可以将声音和文本嵌入到一个联合嵌入空间 # 用于条件音频LM embeds = mulan.get_audio_latents(wavs) # 训练期间 embeds = mulan.get_text_latents(texts) # 推理期间

要获取作为 AudioLM 部分的三个转换器的条件嵌入,你必须使用 MuLaNEmbedQuantizer 如下

from musiclm_pytorch import MuLaNEmbedQuantizer # 使用命名空间条件嵌入设置量化器,每个量化器和命名空间都是唯一的(每个变换器) quantizer = MuLaNEmbedQuantizer( mulan = mulan, # 传入上面训练好的Mulan conditioning_dims = (1024, 1024, 1024), # 假设所有三个转换器的模型维度均为1024 namespaces = ('semantic', 'coarse', 'fine') ) # 现在假设你需要语义转换器的条件嵌入 wavs = torch.randn(2, 1024) conds = quantizer(wavs = wavs, namespace = 'semantic') # (2, 8, 1024) - 8是量化器的数量

要训练(或微调)作为AudioLM部分的三个转换器,只需按照audiolm-pytorch的训练说明进行操作,但需要将MulanEmbedQuantizer实例传递给训练类中的audio_conditioner关键字

例如 SemanticTransformerTrainer

import torch from audiolm_pytorch import HubertWithKmeans, SemanticTransformer, SemanticTransformerTrainer wav2vec = HubertWithKmeans( checkpoint_path = './hubert/hubert_base_ls960.pt', kmeans_path = './hubert/hubert_base_ls960_L9_km500.bin' ) semantic_transformer = SemanticTransformer( num_semantic_tokens = wav2vec.codebook_size, dim = 1024, depth = 6, audio_text_condition = True # 该设置必须为True(CoarseTransformer和FineTransformers也一样) ).cuda() trainer = SemanticTransformerTrainer( transformer = semantic_transformer, wav2vec = wav2vec, audio_conditioner = quantizer, # 传入上面的MulanEmbedQuantizer实例 folder ='/path/to/audio/files', batch_size = 1, data_max_length = 320 * 32, num_train_steps = 1 ) trainer.train()

在对所有三个转换器(语义,粗略,精细)进行大量训练后,你将把微调或从头开始训练的AudioLM和用 MuLaNEmbedQuantizer 包装的MuLaN传给MusicLM

# 你需要从上面训练好的AudioLM(audio_lm) # 与MulanEmbedQuantizer(mulan_embed_quantizer) from musiclm_pytorch import MusicLM musiclm = MusicLM( audio_lm = audio_lm, # `AudioLM`来自https://github.com/lucidrains/audiolm-pytorch mulan_embed_quantizer = quantizer # 上面的`MuLaNEmbedQuantizer` ) music = musiclm('the crystalline sounds of the piano in a ballroom', num_samples = 4) # 采样4个并使用Mulan选取最佳匹配

待办事项

  • mulan似乎在使用解耦的对比学习,提供该选项

  • 用mulan包装器包装mulan并量化输出,将其投射到audiolm维度

  • 修改audiolm以接受条件嵌入,可以选择通过单独的投影处理不同的维度

  • audiolm和mulan进入musiclm进行生成,并用mulan过滤

  • 给AST中的自注意力赋予动态位置偏置

  • 实现MusicLM生成多个样本并选择与MuLan最匹配的样本

  • 支持音频变长度,使用音频转换器中的掩模

  • <a href="https://github.com/mlfoundations/open_clip">open clip</a>添加一个版本的mulan

  • 设置所有适当的声谱图超参数

引用

@inproceedings{Agostinelli2023MusicLMGM, title = {MusicLM: Generating Music From Text}, author = {Andrea Agostinelli and Timo I. Denk and Zal{\'a}n Borsos and Jesse Engel and Mauro Verzetti and Antoine Caillon and Qingqing Huang and Aren Jansen and Adam Roberts and Marco Tagliasacchi and Matthew Sharifi and Neil Zeghidour and C. Frank}, year = {2023} }
@article{Huang2022MuLanAJ, title = {MuLan: A Joint Embedding of Music Audio and Natural Language}, author = {Qingqing Huang and Aren Jansen and Joonseok Lee and Ravi Ganti and Judith Yue Li and Daniel P. W. Ellis}, journal = {ArXiv}, year = {2022}, volume = {abs/2208.12415} }
@misc{https://doi.org/10.48550/arxiv.2302.01327, doi = {10.48550/ARXIV.2302.01327}, url = {https://arxiv.org/abs/2302.01327}, author = {Kumar, Manoj and Dehghani, Mostafa and Houlsby, Neil}, title = {Dual PatchNorm}, publisher = {arXiv}, year = {2023}, copyright = {Creative Commons Attribution 4.0 International} }
@article{Liu2022PatchDropoutEV, title = {PatchDropout: Economizing Vision Transformers Using Patch Dropout}, author = {Yue Liu and Christos Matsoukas and Fredrik Strand and Hossein Azizpour and Kevin Smith}, journal = {ArXiv}, year = {2022}, volume = {abs/2208.07220} }
@misc{liu2021swin, title = {Swin Transformer V2: Scaling Up Capacity and Resolution}, author = {Ze Liu and Han Hu and Yutong Lin and Zhuliang Yao and Zhenda Xie and Yixuan Wei and Jia Ning and Yue Cao and Zheng Zhang and Li Dong and Furu Wei and Baining Guo}, year = {2021}, eprint = {2111.09883}, archivePrefix = {arXiv}, primaryClass = {cs.CV} }
@misc{gilmer2023intriguing title = {Intriguing Properties of Transformer Training Instabilities}, author = {Justin Gilmer, Andrea Schioppa, and Jeremy Cohen}, year = {2023}, status = {to be published - one attention stabilization technique is circulating within Google Brain, being used by multiple teams} }
@inproceedings{Shukor2022EfficientVP, title = {Efficient Vision-Language Pretraining with Visual Concepts and Hierarchical Alignment}, author = {Mustafa Shukor and Guillaume Couairon and Matthieu Cord}, booktitle = {British Machine Vision Conference}, year = {2022} }
@inproceedings{Zhai2023SigmoidLF, title = {Sigmoid Loss for Language Image Pre-Training}, author = {Xiaohua Zhai and Basil Mustafa and Alexander Kolesnikov and Lucas Beyer}, year = {2023} }

唯一的真理是音乐。 - 杰克·凯鲁亚克

音乐是人类的通用语言。 - 亨利·沃兹沃斯·朗费罗

编辑推荐精选

扣子-AI办公

扣子-AI办公

职场AI,就用扣子

AI办公助手,复杂任务高效处理。办公效率低?扣子空间AI助手支持播客生成、PPT制作、网页开发及报告写作,覆盖科研、商业、舆情等领域的专家Agent 7x24小时响应,生活工作无缝切换,提升50%效率!

堆友

堆友

多风格AI绘画神器

堆友平台由阿里巴巴设计团队创建,作为一款AI驱动的设计工具,专为设计师提供一站式增长服务。功能覆盖海量3D素材、AI绘画、实时渲染以及专业抠图,显著提升设计品质和效率。平台不仅提供工具,还是一个促进创意交流和个人发展的空间,界面友好,适合所有级别的设计师和创意工作者。

图像生成热门AI工具AI图像AI反应堆AI工具箱AI绘画GOAI艺术字堆友相机
码上飞

码上飞

零代码AI应用开发平台

零代码AI应用开发平台,用户只需一句话简单描述需求,AI能自动生成小程序、APP或H5网页应用,无需编写代码。

Vora

Vora

免费创建高清无水印Sora视频

Vora是一个免费创建高清无水印Sora视频的AI工具

Refly.AI

Refly.AI

最适合小白的AI自动化工作流平台

无需编码,轻松生成可复用、可变现的AI自动化工作流

酷表ChatExcel

酷表ChatExcel

大模型驱动的Excel数据处理工具

基于大模型交互的表格处理系统,允许用户通过对话方式完成数据整理和可视化分析。系统采用机器学习算法解析用户指令,自动执行排序、公式计算和数据透视等操作,支持多种文件格式导入导出。数据处理响应速度保持在0.8秒以内,支持超过100万行数据的即时分析。

AI工具使用教程AI营销产品酷表ChatExcelAI智能客服
TRAE编程

TRAE编程

AI辅助编程,代码自动修复

Trae是一种自适应的集成开发环境(IDE),通过自动化和多元协作改变开发流程。利用Trae,团队能够更快速、精确地编写和部署代码,从而提高编程效率和项目交付速度。Trae具备上下文感知和代码自动完成功能,是提升开发效率的理想工具。

热门AI工具生产力协作转型TraeAI IDE
AIWritePaper论文写作

AIWritePaper论文写作

AI论文写作指导平台

AIWritePaper论文写作是一站式AI论文写作辅助工具,简化了选题、文献检索至论文撰写的整个过程。通过简单设定,平台可快速生成高质量论文大纲和全文,配合图表、参考文献等一应俱全,同时提供开题报告和答辩PPT等增值服务,保障数据安全,有效提升写作效率和论文质量。

数据安全AI助手热门AI工具AI辅助写作AI论文工具论文写作智能生成大纲
博思AIPPT

博思AIPPT

AI一键生成PPT,就用博思AIPPT!

博思AIPPT,新一代的AI生成PPT平台,支持智能生成PPT、AI美化PPT、文本&链接生成PPT、导入Word/PDF/Markdown文档生成PPT等,内置海量精美PPT模板,涵盖商务、教育、科技等不同风格,同时针对每个页面提供多种版式,一键自适应切换,完美适配各种办公场景。

热门AI工具AI办公办公工具智能排版AI生成PPT博思AIPPT海量精品模板AI创作
潮际好麦

潮际好麦

AI赋能电商视觉革命,一站式智能商拍平台

潮际好麦深耕服装行业,是国内AI试衣效果最好的软件。使用先进AIGC能力为电商卖家批量提供优质的、低成本的商拍图。合作品牌有Shein、Lazada、安踏、百丽等65个国内外头部品牌,以及国内10万+淘宝、天猫、京东等主流平台的品牌商家,为卖家节省将近85%的出图成本,提升约3倍出图效率,让品牌能够快速上架。

下拉加载更多