music generation

提供商metoonhathung
分类audio-generation
许可证mit
下载量11
星标0

简介

这是一个基于 MIT 协议的开源音乐生成模型,旨在将文本描述直接转化为音频片段。对于国内开发者而言,它提供了一个轻量级的音频创作方案,能够快速生成背景音乐或短音频素材,无需复杂的编曲知识即可上手。相比于 Suno 或 Udio 等闭源商业工具,该模型更适合集成到自己的应用中,或在本地环境下进行低成本的音频实验,是构建 AI 音乐插件或自动化内容生成流的理想选择。

核心亮点

  • 开源 MIT 协议,方便开发者自由集成与商用
  • 支持文本驱动生成,降低音乐创作门槛
  • 适用于短视频 BGM 或游戏音效快速原型开发
  • 部署灵活,适合构建自定义的音频生成管线

使用方法

安装依赖
# 安装 Hugging Face transformers
pip install transformers torch
SDK 使用
# 使用 transformers 加载模型
from transformers import AutoModel, AutoTokenizer

model = AutoModel.from_pretrained("metoonhathung/music-generation")
tokenizer = AutoTokenizer.from_pretrained("metoonhathung/music-generation")

Hugging Face 下载

我们推荐使用命令行或者 Hugging Face Hub SDK 来进行模型的下载。

操作指引:在下载前,请先通过如下命令安装 huggingface_hub:

操作指引
pip install -U huggingface_hub

命令行下载

下载完整模型库

下载完整模型库
huggingface-cli download metoonhathung/music-generation

下载单个文件到指定本地文件夹(以下载 config.json 到当前路径下 ./dir 目录为例)

下载单个文件到指定本地文件夹(以下载 config.json 到当前路径下 ./dir 目录为例)
huggingface-cli download metoonhathung/music-generation config.json --local-dir ./dir

更多命令行下载选项,可参见官方文档

SDK 下载

SDK 下载
# 模型下载
from huggingface_hub import snapshot_download
model_dir = snapshot_download('metoonhathung/music-generation')

Git 下载

请确保 lfs 已经被正确安装

Git 下载
git lfs install
git clone https://huggingface.co/metoonhathung/music-generation

如果您希望跳过 lfs 大文件下载,可以使用如下命令

跳过 LFS
GIT_LFS_SKIP_SMUDGE=1 git clone https://huggingface.co/metoonhathung/music-generation

模型文件托管在 Hugging Face Hub,使用 HF CLI / SDK / Git 直接下载,不经过本站。

PyTorch / Transformers 使用

安装 Transformers

安装 Transformers
pip install -U transformers torch

模型加载和推理

模型加载和推理
from transformers import AutoModelForCausalLM, AutoTokenizer

model = AutoModelForCausalLM.from_pretrained('metoonhathung/music-generation')
tokenizer = AutoTokenizer.from_pretrained('metoonhathung/music-generation')

完整文档

来源: HuggingFace

---
library_name: transformers
license: mit
base_model: gpt2
tags:

  • generated_from_trainer

model-index:
  • name: music-generation

results: []
---

<!-- This model card has been generated automatically according to the information the Trainer had access to. You
should probably proofread and complete it, then remove this comment. -->

music-generation

This model is a fine-tuned version of gpt2 on an unknown dataset.
It achieves the following results on the evaluation set:

  • Loss: 0.5312

Model description

More information needed

Intended uses & limitations

More information needed

Training and evaluation data

More information needed

Training procedure

Training hyperparameters

The following hyperparameters were used during training:

  • learning_rate: 0.0001

  • train_batch_size: 16

  • eval_batch_size: 16

  • seed: 42

  • gradient_accumulation_steps: 16

  • total_train_batch_size: 256

  • optimizer: Use OptimizerNames.ADAMW_TORCH with betas=(0.9,0.999) and epsilon=1e-08 and optimizer_args=No additional optimizer arguments

  • lr_scheduler_type: cosine

  • lr_scheduler_warmup_steps: 100

  • num_epochs: 20

  • mixed_precision_training: Native AMP

Training results

| Training Loss | Epoch | Step | Validation Loss |
|:-------------:|:-------:|:----:|:---------------:|
| 3.7238 | 0.9217 | 100 | 2.8460 |
| 2.4643 | 1.8387 | 200 | 1.8829 |
| 1.8339 | 2.7558 | 300 | 1.4234 |
| 1.5013 | 3.6728 | 400 | 1.2203 |
| 1.3125 | 4.5899 | 500 | 1.0966 |
| 1.1899 | 5.5069 | 600 | 1.0028 |
| 1.0982 | 6.4240 | 700 | 0.9353 |
| 1.0302 | 7.3410 | 800 | 0.8779 |
| 0.9766 | 8.2581 | 900 | 0.8276 |
| 0.9243 | 9.1751 | 1000 | 0.7757 |
| 0.8825 | 10.0922 | 1100 | 0.7345 |
| 0.845 | 11.0092 | 1200 | 0.7000 |
| 0.8083 | 11.9309 | 1300 | 0.6624 |
| 0.7784 | 12.8479 | 1400 | 0.6328 |
| 0.7502 | 13.7650 | 1500 | 0.6052 |
| 0.7281 | 14.6820 | 1600 | 0.5816 |
| 0.7072 | 15.5991 | 1700 | 0.5622 |
| 0.6903 | 16.5161 | 1800 | 0.5486 |
| 0.6796 | 17.4332 | 1900 | 0.5386 |
| 0.6705 | 18.3502 | 2000 | 0.5335 |
| 0.6646 | 19.2673 | 2100 | 0.5312 |

Framework versions

  • Transformers 4.55.0
  • Pytorch 2.6.0+cu124
  • Datasets 4.0.0
  • Tokenizers 0.21.4