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} }

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

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

编辑推荐精选

Vora

Vora

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

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

Refly.AI

Refly.AI

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

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

酷表ChatExcel

酷表ChatExcel

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

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

AI工具酷表ChatExcelAI智能客服AI营销产品使用教程
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工具博思AIPPTAI生成PPT智能排版海量精品模板AI创作热门
潮际好麦

潮际好麦

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

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

iTerms

iTerms

企业专属的AI法律顾问

iTerms是法大大集团旗下法律子品牌,基于最先进的大语言模型(LLM)、专业的法律知识库和强大的智能体架构,帮助企业扫清合规障碍,筑牢风控防线,成为您企业专属的AI法律顾问。

SimilarWeb流量提升

SimilarWeb流量提升

稳定高效的流量提升解决方案,助力品牌曝光

稳定高效的流量提升解决方案,助力品牌曝光

Sora2视频免费生成

Sora2视频免费生成

最新版Sora2模型免费使用,一键生成无水印视频

最新版Sora2模型免费使用,一键生成无水印视频

下拉加载更多