[{"data":1,"prerenderedAt":-1},["ShallowReactive",2],{"similar-ElectricAlexis--NotaGen":3,"tool-ElectricAlexis--NotaGen":64},[4,17,25,39,48,56],{"id":5,"name":6,"github_repo":7,"description_zh":8,"stars":9,"difficulty_score":10,"last_commit_at":11,"category_tags":12,"status":16},1381,"everything-claude-code","affaan-m\u002Feverything-claude-code","everything-claude-code 是一套专为 AI 编程助手（如 Claude Code、Codex、Cursor 等）打造的高性能优化系统。它不仅仅是一组配置文件，而是一个经过长期实战打磨的完整框架，旨在解决 AI 代理在实际开发中面临的效率低下、记忆丢失、安全隐患及缺乏持续学习能力等核心痛点。\n\n通过引入技能模块化、直觉增强、记忆持久化机制以及内置的安全扫描功能，everything-claude-code 能显著提升 AI 在复杂任务中的表现，帮助开发者构建更稳定、更智能的生产级 AI 代理。其独特的“研究优先”开发理念和针对 Token 消耗的优化策略，使得模型响应更快、成本更低，同时有效防御潜在的攻击向量。\n\n这套工具特别适合软件开发者、AI 研究人员以及希望深度定制 AI 工作流的技术团队使用。无论您是在构建大型代码库，还是需要 AI 协助进行安全审计与自动化测试，everything-claude-code 都能提供强大的底层支持。作为一个曾荣获 Anthropic 黑客大奖的开源项目，它融合了多语言支持与丰富的实战钩子（hooks），让 AI 真正成长为懂上",140436,2,"2026-04-05T23:32:43",[13,14,15],"开发框架","Agent","语言模型","ready",{"id":18,"name":19,"github_repo":20,"description_zh":21,"stars":22,"difficulty_score":10,"last_commit_at":23,"category_tags":24,"status":16},3704,"NextChat","ChatGPTNextWeb\u002FNextChat","NextChat 是一款轻量且极速的 AI 助手，旨在为用户提供流畅、跨平台的大模型交互体验。它完美解决了用户在多设备间切换时难以保持对话连续性，以及面对众多 AI 模型不知如何统一管理的痛点。无论是日常办公、学习辅助还是创意激发，NextChat 都能让用户随时随地通过网页、iOS、Android、Windows、MacOS 或 Linux 端无缝接入智能服务。\n\n这款工具非常适合普通用户、学生、职场人士以及需要私有化部署的企业团队使用。对于开发者而言，它也提供了便捷的自托管方案，支持一键部署到 Vercel 或 Zeabur 等平台。\n\nNextChat 的核心亮点在于其广泛的模型兼容性，原生支持 Claude、DeepSeek、GPT-4 及 Gemini Pro 等主流大模型，让用户在一个界面即可自由切换不同 AI 能力。此外，它还率先支持 MCP（Model Context Protocol）协议，增强了上下文处理能力。针对企业用户，NextChat 提供专业版解决方案，具备品牌定制、细粒度权限控制、内部知识库整合及安全审计等功能，满足公司对数据隐私和个性化管理的高标准要求。",87618,"2026-04-05T07:20:52",[13,15],{"id":26,"name":27,"github_repo":28,"description_zh":29,"stars":30,"difficulty_score":10,"last_commit_at":31,"category_tags":32,"status":16},2268,"ML-For-Beginners","microsoft\u002FML-For-Beginners","ML-For-Beginners 是由微软推出的一套系统化机器学习入门课程，旨在帮助零基础用户轻松掌握经典机器学习知识。这套课程将学习路径规划为 12 周，包含 26 节精炼课程和 52 道配套测验，内容涵盖从基础概念到实际应用的完整流程，有效解决了初学者面对庞大知识体系时无从下手、缺乏结构化指导的痛点。\n\n无论是希望转型的开发者、需要补充算法背景的研究人员，还是对人工智能充满好奇的普通爱好者，都能从中受益。课程不仅提供了清晰的理论讲解，还强调动手实践，让用户在循序渐进中建立扎实的技能基础。其独特的亮点在于强大的多语言支持，通过自动化机制提供了包括简体中文在内的 50 多种语言版本，极大地降低了全球不同背景用户的学习门槛。此外，项目采用开源协作模式，社区活跃且内容持续更新，确保学习者能获取前沿且准确的技术资讯。如果你正寻找一条清晰、友好且专业的机器学习入门之路，ML-For-Beginners 将是理想的起点。",84991,"2026-04-05T10:45:23",[33,34,35,36,14,37,15,13,38],"图像","数据工具","视频","插件","其他","音频",{"id":40,"name":41,"github_repo":42,"description_zh":43,"stars":44,"difficulty_score":45,"last_commit_at":46,"category_tags":47,"status":16},3128,"ragflow","infiniflow\u002Fragflow","RAGFlow 是一款领先的开源检索增强生成（RAG）引擎，旨在为大语言模型构建更精准、可靠的上下文层。它巧妙地将前沿的 RAG 技术与智能体（Agent）能力相结合，不仅支持从各类文档中高效提取知识，还能让模型基于这些知识进行逻辑推理和任务执行。\n\n在大模型应用中，幻觉问题和知识滞后是常见痛点。RAGFlow 通过深度解析复杂文档结构（如表格、图表及混合排版），显著提升了信息检索的准确度，从而有效减少模型“胡编乱造”的现象，确保回答既有据可依又具备时效性。其内置的智能体机制更进一步，使系统不仅能回答问题，还能自主规划步骤解决复杂问题。\n\n这款工具特别适合开发者、企业技术团队以及 AI 研究人员使用。无论是希望快速搭建私有知识库问答系统，还是致力于探索大模型在垂直领域落地的创新者，都能从中受益。RAGFlow 提供了可视化的工作流编排界面和灵活的 API 接口，既降低了非算法背景用户的上手门槛，也满足了专业开发者对系统深度定制的需求。作为基于 Apache 2.0 协议开源的项目，它正成为连接通用大模型与行业专有知识之间的重要桥梁。",77062,3,"2026-04-04T04:44:48",[14,33,13,15,37],{"id":49,"name":50,"github_repo":51,"description_zh":52,"stars":53,"difficulty_score":45,"last_commit_at":54,"category_tags":55,"status":16},519,"PaddleOCR","PaddlePaddle\u002FPaddleOCR","PaddleOCR 是一款基于百度飞桨框架开发的高性能开源光学字符识别工具包。它的核心能力是将图片、PDF 等文档中的文字提取出来，转换成计算机可读取的结构化数据，让机器真正“看懂”图文内容。\n\n面对海量纸质或电子文档，PaddleOCR 解决了人工录入效率低、数字化成本高的问题。尤其在人工智能领域，它扮演着连接图像与大型语言模型（LLM）的桥梁角色，能将视觉信息直接转化为文本输入，助力智能问答、文档分析等应用场景落地。\n\nPaddleOCR 适合开发者、算法研究人员以及有文档自动化需求的普通用户。其技术优势十分明显：不仅支持全球 100 多种语言的识别，还能在 Windows、Linux、macOS 等多个系统上运行，并灵活适配 CPU、GPU、NPU 等各类硬件。作为一个轻量级且社区活跃的开源项目，PaddleOCR 既能满足快速集成的需求，也能支撑前沿的视觉语言研究，是处理文字识别任务的理想选择。",74939,"2026-04-05T23:16:38",[15,33,13,37],{"id":57,"name":58,"github_repo":59,"description_zh":60,"stars":61,"difficulty_score":45,"last_commit_at":62,"category_tags":63,"status":16},2181,"OpenHands","OpenHands\u002FOpenHands","OpenHands 是一个专注于 AI 驱动开发的开源平台，旨在让智能体（Agent）像人类开发者一样理解、编写和调试代码。它解决了传统编程中重复性劳动多、环境配置复杂以及人机协作效率低等痛点，通过自动化流程显著提升开发速度。\n\n无论是希望提升编码效率的软件工程师、探索智能体技术的研究人员，还是需要快速原型验证的技术团队，都能从中受益。OpenHands 提供了灵活多样的使用方式：既可以通过命令行（CLI）或本地图形界面在个人电脑上轻松上手，体验类似 Devin 的流畅交互；也能利用其强大的 Python SDK 自定义智能体逻辑，甚至在云端大规模部署上千个智能体并行工作。\n\n其核心技术亮点在于模块化的软件智能体 SDK，这不仅构成了平台的引擎，还支持高度可组合的开发模式。此外，OpenHands 在 SWE-bench 基准测试中取得了 77.6% 的优异成绩，证明了其解决真实世界软件工程问题的能力。平台还具备完善的企业级功能，支持与 Slack、Jira 等工具集成，并提供细粒度的权限管理，适合从个人开发者到大型企业的各类用户场景。",70626,"2026-04-05T22:51:36",[15,14,13,36],{"id":65,"github_repo":66,"name":67,"description_en":68,"description_zh":69,"ai_summary_zh":69,"readme_en":70,"readme_zh":71,"quickstart_zh":72,"use_case_zh":73,"hero_image_url":74,"owner_login":75,"owner_name":76,"owner_avatar_url":77,"owner_bio":78,"owner_company":79,"owner_location":79,"owner_email":78,"owner_twitter":78,"owner_website":78,"owner_url":80,"languages":81,"stars":90,"forks":91,"last_commit_at":92,"license":93,"difficulty_score":45,"env_os":94,"env_gpu":95,"env_ram":96,"env_deps":97,"category_tags":104,"github_topics":78,"view_count":105,"oss_zip_url":78,"oss_zip_packed_at":78,"status":16,"created_at":106,"updated_at":107,"faqs":108,"releases":142},213,"ElectricAlexis\u002FNotaGen","NotaGen","NotaGen: Advancing Musicality in Symbolic Music Generation with Large Language Model Training Paradigms","NotaGen 是一个专注于生成高质量古典乐谱的符号音乐生成模型。它借鉴大语言模型的成功经验，致力于提升生成音乐的音乐性，解决传统算法难以创作出结构严谨、风格地道的古典音乐的问题。\n\nNotaGen 采用独特的三阶段训练范式：首先在 160 万首乐曲上进行预训练，随后基于时期、作曲家等提示词在约 9000 首古典作品上微调，最后通过创新的 CLaMP-DPO 强化学习方法进一步优化，无需人工标注即可显著提升作品质量。项目提供了从小型到大型等多种规模的模型权重，甚至推出了优化版 NotaGen-X，方便不同需求的用户部署。\n\n无论是音乐人工智能领域的研究人员、希望集成音乐生成功能的开发者，还是寻找创作灵感的音乐人，都能通过 NotaGen 获得专业的乐谱生成能力。项目开源了代码与权重，并提供了在线演示空间，欢迎体验由 AI 创作的古典乐章。","# 🎵 NotaGen: Advancing Musicality in Symbolic Music Generation with Large Language Model Training Paradigms\n\n\u003Cp align=\"center\">\n  \u003C!-- ArXiv -->\n  \u003Ca href=\"https:\u002F\u002Farxiv.org\u002Fabs\u002F2502.18008\">\n    \u003Cimg src=\"https:\u002F\u002Fimg.shields.io\u002Fbadge\u002FNotaGen_Paper-ArXiv-%23B31B1B?logo=arxiv&logoColor=white\" alt=\"Paper\">\n  \u003C\u002Fa>\n  &nbsp;&nbsp;\n  \u003C!-- HuggingFace -->\n  \u003Ca href=\"https:\u002F\u002Fhuggingface.co\u002FElectricAlexis\u002FNotaGen\">\n    \u003Cimg src=\"https:\u002F\u002Fimg.shields.io\u002Fbadge\u002FNotaGen_Weights-HuggingFace-%23FFD21F?logo=huggingface&logoColor=white\" alt=\"Weights\">\n  \u003C\u002Fa>\n  &nbsp;&nbsp;\n  \u003C!-- HuggingFace Space -->\n  \u003Ca href=\"https:\u002F\u002Fhuggingface.co\u002Fspaces\u002FElectricAlexis\u002FNotaGen\">\n    \u003Cimg src=\"https:\u002F\u002Fimg.shields.io\u002Fbadge\u002FNotaGen_Space-Huggingface-✨️?logo=huggingface&logoColor=white\" alt=\"Space\">\n  \u003C\u002Fa>\n  &nbsp;&nbsp;\n  \u003C!-- Web Demo -->\n  \u003Ca href=\"https:\u002F\u002Felectricalexis.github.io\u002Fnotagen-demo\u002F\">\n    \u003Cimg src=\"https:\u002F\u002Fimg.shields.io\u002Fbadge\u002FNotaGen_Demo-Web-%23007ACC?logo=google-chrome&logoColor=white\" alt=\"Demo\">\n  \u003C\u002Fa>\n\u003C\u002Fp>\n\n\u003Cp align=\"center\">\n  \u003Cimg src=\"https:\u002F\u002Foss.gittoolsai.com\u002Fimages\u002FElectricAlexis_NotaGen_readme_62e00887cba6.png\" alt=\"NotaGen\" width=\"50%\">\n\u003C\u002Fp>\n\n\n## 📖 Overview\n**NotaGen** is a symbolic music generation model that explores the potential of producing **high-quality classical sheet music**. Inspired by the success of Large Language Models (LLMs), NotaGen adopts a three-stage training paradigm:\n- 🧠 **Pre-training** on 1.6M musical pieces\n- 🎯 **Fine-tuning** on ~9K classical compositions with `period-composer-instrumentation` prompts\n- 🚀 **Reinforcement Learning** using our novel **CLaMP-DPO** method (no human annotations or pre-defined rewards required.)\n\nCheck our [demo page](https:\u002F\u002Felectricalexis.github.io\u002Fnotagen-demo\u002F) and enjoy music composed by NotaGen!\n\n## ⚙️ Environment Setup\n\n```bash\nconda create --name notagen python=3.10\nconda activate notagen\nconda install pytorch==2.3.0 pytorch-cuda=11.8 -c pytorch -c nvidia\npip install accelerate\npip install optimum\npip install -r requirements.txt\n```\n\n## 🏋️ NotaGen Model Weights\n\n### Pre-training\nWe provide pre-trained weights of different scales:\n|  Models         |  Parameters  |  Patch-level Decoder Layers  |  Character-level Decoder Layers  |  Hidden Size  |  Patch Length (Context Length)  |\n|  ----           |  ----  |  ---- |  ----  |  ----  |  ----  |\n|  [NotaGen-small](https:\u002F\u002Fhuggingface.co\u002FElectricAlexis\u002FNotaGen\u002Fblob\u002Fmain\u002Fweights_notagen_pretrain_p_size_16_p_length_2048_p_layers_12_c_layers_3_h_size_768_lr_0.0002_batch_8.pth)  | 110M   |  12   |  3     |  768   |  2048  |\n|  [NotaGen-medium](https:\u002F\u002Fhuggingface.co\u002FElectricAlexis\u002FNotaGen\u002Fblob\u002Fmain\u002Fweights_notagen_pretrain_p_size_16_p_length_2048_p_layers_16_c_layers_3_h_size_1024_lr_0.0001_batch_4.pth) | 244M   |  16   |  3     |  1024  |  2048  |\n|  [NotaGen-large](https:\u002F\u002Fhuggingface.co\u002FElectricAlexis\u002FNotaGen\u002Fblob\u002Fmain\u002Fweights_notagen_pretrain_p_size_16_p_length_1024_p_layers_20_c_layers_6_h_size_1280_lr_0.0001_batch_4.pth)  | 516M   |  20   |  6     |  1280  |  1024  |\n\n**Notice**: The pre-trained weights cannot be used for conditional generation based on 'period-composer-instrumentation'.\n\n### Fine-tuning\n\nWe fine-tuned NotaGen-large on a corpus of approximately 9k classical pieces. You can download the weights [here](https:\u002F\u002Fhuggingface.co\u002FElectricAlexis\u002FNotaGen\u002Fblob\u002Fmain\u002Fweights_notagen_pretrain-finetune_p_size_16_p_length_1024_p_layers_c_layers_6_20_h_size_1280_lr_1e-05_batch_1.pth).\n\n### Reinforcement-Learning\n\nAfter pre-training and fine-tuning, we optimized NotaGen-large with 3 iterations of CLaMP-DPO. You can download the weights [here](https:\u002F\u002Fhuggingface.co\u002FElectricAlexis\u002FNotaGen\u002Fblob\u002Fmain\u002Fweights_notagen_pretrain-finetune-RL3_beta_0.1_lambda_10_p_size_16_p_length_1024_p_layers_20_c_layers_6_h_size_1280_lr_1e-06_batch_1.pth).\n\n### 🌟 NotaGen-X\n\nInspired by Deepseek-R1, we further optimized the training procedures of NotaGen and released a better version --- [NotaGen-X](https:\u002F\u002Fhuggingface.co\u002FElectricAlexis\u002FNotaGen\u002Fblob\u002Fmain\u002Fweights_notagenx_p_size_16_p_length_1024_p_layers_20_h_size_1280.pth). Compared to the version in the paper, NotaGen-X incorporates the following improvements:\n\n- We introduced a post-training stage between pre-training and fine-tuning, refining the model with a classical-style subset of the pre-training dataset.\n- We removed the key augmentation in the Fine-tune stage, making the instrument range of the generated compositions more reasonable.\n- After RL, we utilized the resulting checkpoint to gather a new set of post-training data. Starting from the pre-trained checkpoint, we conducted another round of post-training, fine-tuning, and reinforcement learning.\n\nIf you want to add a new composer style to NotaGen-X, please refer to issue [#18](https:\u002F\u002Fgithub.com\u002FElectricAlexis\u002FNotaGen\u002Fissues\u002F18) for more instructions :D\n\n## 🎹 Demo\n\n### Online Gradio Demo\n\nWe developed an [online gradio demo](https:\u002F\u002Fhuggingface.co\u002Fspaces\u002FElectricAlexis\u002FNotaGen) on Huggingface Space for NotaGen-X. You can input **\"Period-Composer-Instrumentation\"** as the prompt to have NotaGen generate music, preview the audio \u002F pdf scores, and download them :D\n\n\u003Cp align=\"center\">\n  \u003Cimg src=\"https:\u002F\u002Foss.gittoolsai.com\u002Fimages\u002FElectricAlexis_NotaGen_readme_73af7631cd9a.png\" alt=\"NotaGen Gradio Demo\">\n\u003C\u002Fp>\n\n### Local Gradio Demo\n\nWe developed a local Gradio demo for NotaGen-X. You can input **\"Period-Composer-Instrumentation\"** as the prompt to have NotaGen generate music！\n\n\u003Cp align=\"center\">\n  \u003Cimg src=\"https:\u002F\u002Foss.gittoolsai.com\u002Fimages\u002FElectricAlexis_NotaGen_readme_7b72cf78c5b9.png\" alt=\"NotaGen Gradio Demo\">\n\u003C\u002Fp>\n\nDeploying NotaGen-X inference locally may require 8GB of GPU memory. For implementation details, please view [gradio\u002FREADME.md](https:\u002F\u002Fgithub.com\u002FElectricAlexis\u002FNotaGen\u002Fblob\u002Fmain\u002Fgradio\u002FREADME.md). We are also working on developing an online demo.\n\n### Online Colab Notebook\n\nThanks for [@deeplearn-art](https:\u002F\u002Fgithub.com\u002Fdeeplearn-art\u002FNotaGen)'s contribution of a [Google Colab notebook for NotaGen](https:\u002F\u002Fcolab.research.google.com\u002Fdrive\u002F1yJA1wG0fiwNeehdQxAUw56i4bTXzoVVv?usp=sharing)! You can run it and access to a Gradio public link to play with this demo. 🤩\n\n### ComfyUI\n\nThanks for [@billwuhao](https:\u002F\u002Fgithub.com\u002Fbillwuhao\u002FComfyUI_NotaGen)'s contribution of [a ComfyUI node for NotaGen](https:\u002F\u002Fgithub.com\u002Fbillwuhao\u002FComfyUI_NotaGen)! It can automatically convert generated .abc to .xml, .mp3, and .png formats. You can listen to the generated music and see the sheet music too! Please visit the [repository page](https:\u002F\u002Fgithub.com\u002Fbillwuhao\u002FComfyUI_NotaGen) for more information. 🤩 \n\n\u003Cp align=\"center\">\n  \u003Cimg src=\"https:\u002F\u002Foss.gittoolsai.com\u002Fimages\u002FElectricAlexis_NotaGen_readme_09482e88a8f6.png\" alt=\"NotaGen ComfyUI\">\n\u003C\u002Fp>\n\n\n## 🛠️ Data Pre-processing & Post-processing\n\nFor converting **ABC notation** files from \u002F to **MusicXML** files, please view [data\u002FREADME.md](https:\u002F\u002Fgithub.com\u002FElectricAlexis\u002FNotaGen\u002Fblob\u002Fmain\u002Fdata\u002FREADME.md) for instructions.\n\nTo illustrate the specific data format, we provide a small dataset of **Schubert's lieder** compositions from the [OpenScore Lieder](https:\u002F\u002Fgithub.com\u002FOpenScore\u002FLieder), which includes:\n- 🗂️ Interleaved ABC folders\n- 🗂️ Augmented ABC folders\n- 📄 Data index files for training and evaluation\n\nYou can download it [here](https:\u002F\u002Fdrive.google.com\u002Fdrive\u002Ffolders\u002F1iVLkcywzXGcHFodce9nDQyEmK4UDmBtY?usp=sharing) and put it under ```data\u002F```.\n\nIn the instructions of **Fine-tuning** and **Reinforcement Learning** below, we will use this dataset as an example of our implementation. **It won't include the \"period-composer-instrumentation\" conditioning**, just for showing how to adapt the pretrained NotaGen to a specific music style.\n\n\n## 🧠 Pre-train\nIf you want to use your own data to pre-train a blank **NotaGen** model, please:\n1. Preprocess the data and generate the data index files following the instructions in [data\u002FREADME.md](https:\u002F\u002Fgithub.com\u002FElectricAlexis\u002FNotaGen\u002Fblob\u002Fmain\u002Fdata\u002FREADME.md)\n2. Modify the parameters in ```pretrain\u002Fconfig.py```\n\nUse this command for pre-training:\n```bash\ncd pretrain\u002F\naccelerate launch --multi_gpu --mixed_precision fp16 train-gen.py\n```\n\n## 🎯 Fine-tune\n\nHere we give an example on fine-tuning **NotaGen-large** with the **Schubert's lieder** data mentioned above.\n\n**Notice:** The use of **NotaGen-large** requires at least **24GB of GPU memory** for training and inference. Alternatively, you may use **NotaGen-small** or **NotaGen-medium** and change the configuration of models in ```finetune\u002Fconfig.py```.\n\n### Configuration\n- In ```finetune\u002Fconfig.py```:\n  - Modify the ```DATA_TRAIN_INDEX_PATH``` and ```DATA_EVAL_INDEX_PATH```:\n    ```python\n    # Configuration for the data\n    DATA_TRAIN_INDEX_PATH = \"..\u002Fdata\u002Fschubert_augmented_train.jsonl\" \n    DATA_EVAL_INDEX_PATH  = \"..\u002Fdata\u002Fschubert_augmented_eval.jsonl\"\n    ```\n  - Download pre-trained NotaGen weights, and modify the ```PRETRAINED_PATH```:\n    ```python\n    PRETRAINED_PATH = \"..\u002Fpretrain\u002Fweights_notagen_pretrain_p_size_16_p_length_1024_p_layers_20_c_layers_6_h_size_1280_lr_0.0001_batch_4.pth\"  # Use NotaGen-large\n    ```\n  - ```EXP_TAG``` is for differentiating the models. It will be integrated into the ckpt's name. Here we set it to ```schubert```.\n  - You can also modify other parameters like the learning rate.\n\n### Execution\nUse this command for fine-tuning:\n```bash\ncd finetune\u002F\nCUDA_VISIBLE_DEVICES=0 python train-gen.py\n```\n\n## 🚀 Reinforcement Learning (CLaMP-DPO)\n\nHere we give an example on how to use **CLaMP-DPO** to enhance the model fine-tuned with **Schubert's lieder** data.\n\n### ⚙️ [CLaMP 2](https:\u002F\u002Fgithub.com\u002Fsanderwood\u002Fclamp2) Setup\n\nDownload model weights and put them under the ```clamp2\u002F```folder:\n- [CLaMP 2 Model Weights](https:\u002F\u002Fhuggingface.co\u002Fsander-wood\u002Fclamp2\u002Fblob\u002Fmain\u002Fweights_clamp2_h_size_768_lr_5e-05_batch_128_scale_1_t_length_128_t_model_FacebookAI_xlm-roberta-base_t_dropout_True_m3_True.pth)\n- [M3 Model Weights](https:\u002F\u002Fhuggingface.co\u002Fsander-wood\u002Fclamp2\u002Fblob\u002Fmain\u002Fweights_m3_p_size_64_p_length_512_t_layers_3_p_layers_12_h_size_768_lr_0.0001_batch_16_mask_0.45.pth)\n\n### 🔍 Extract Ground Truth Features\nModify ```input_dir``` and ```output_dir``` in ```clamp2\u002Fextract_clamp2.py```:\n```python\ninput_dir = '..\u002Fdata\u002Fschubert_interleaved'  # interleaved abc folder\noutput_dir = 'feature\u002Fschubert_interleaved'  # feature folder\n```\nExtract the features:\n```\ncd clamp2\u002F\npython extract_clamp2.py\n```\n\n### 🔄 CLaMP-DPO\n\nHere we give an example of an iteration of **CLaMP-DPO** from the initial model fine-tuned on **Schubert's lieder** data.\n\n#### 1. Inference\n- Modify the ```INFERENCE_WEIGHTS_PATH``` to path of the fine-tuned weights and ```NUM_SAMPLES``` to generate in ```inference\u002Fconfig.py```:\n  ```python\n    INFERENCE_WEIGHTS_PATH = '..\u002Ffinetune\u002Fweights_notagen_schubert_p_size_16_p_length_1024_p_layers_20_c_layers_6_h_size_1280_lr_1e-05_batch_1.pth'              \n    NUM_SAMPLES = 1000                                               \n  ```\n- Inference:\n  ```\n  cd inference\u002F\n  python inference.py\n  ```\n  This will generate an ```output\u002F```folder with two subfolders: ```original``` and ```interleaved```. The ```original\u002F``` subdirectory stores the raw inference outputs from the model, while the ```interleaved\u002F``` subdirectory contains data post-processed with rest measure completion, compatible with CLaMP 2. Each of these subdirectories will contain a model-specific folder, named as a combination of the model's name and its sampling parameters.\n\n#### 2. Extract Generated Data Features\n\nModify ```input_dir``` and ```output_dir``` in ```clamp2\u002Fextract_clamp2.py```:\n```python\ninput_dir = '..\u002Foutput\u002Finterleaved\u002Fweights_notagen_schubert_p_size_16_p_length_1024_p_layers_20_c_layers_6_h_size_1280_lr_1e-05_batch_1_k_9_p_0.9_temp_1.2'  # interleaved abc folder\noutput_dir = 'feature\u002Fweights_notagen_schubert_p_size_16_p_length_1024_p_layers_20_c_layers_6_h_size_1280_lr_1e-05_batch_1_k_9_p_0.9_temp_1.2'  # feature folder\n```\nExtract the features:\n```\ncd clamp2\u002F\npython extract_clamp2.py\n```\n\n#### 3. Statistics on Averge CLaMP 2 Score (Optional)\nIf you're interested in the **Average CLaMP 2 Score** of the current model, modify the parameters in ```clamp2\u002Fstatistics.py```:\n```python\ngt_feature_folder = 'feature\u002Fschubert_interleaved'\noutput_feature_folder = 'feature\u002Fweights_notagen_schubert_p_size_16_p_length_1024_p_layers_20_c_layers_6_h_size_1280_lr_1e-05_batch_1_k_9_p_0.9_temp_1.2'\n```\nThen run this script:\n```\ncd clamp2\u002F\npython statistics.py\n```\n\n#### 4. Construct Preference Data\nModify the parameters in ```RL\u002Fdata.py```:\n```python\ngt_feature_folder = '..\u002Fclamp2\u002Ffeature\u002Fschubert_interleaved'\noutput_feature_folder = '..\u002Fclamp2\u002Ffeature\u002Fweights_notagen_schubert_p_size_16_p_length_1024_p_layers_20_c_layers_6_h_size_1280_lr_1e-05_batch_1_k_9_p_0.9_temp_1.2'\noutput_original_abc_folder = '..\u002Foutput\u002Foriginal\u002Fweights_notagen_schubert_p_size_16_p_length_1024_p_layers_20_c_layers_6_h_size_1280_lr_1e-05_batch_1_k_9_p_0.9_temp_1.2'\noutput_interleaved_abc_folder = '..\u002Foutput\u002Finterleaved\u002Fweights_notagen_schubert_p_size_16_p_length_1024_p_layers_20_c_layers_6_h_size_1280_lr_1e-05_batch_1_k_9_p_0.9_temp_1.2'\ndata_index_path = 'schubert_RL1.json'  # Data for the first iteration of RL\ndata_select_portion = 0.1              \n```\nIn this script, the **CLaMP 2 Score** of each generated piece will be calculated and sorted. The portion of data in the chosen and rejected sets is determined by ```data_select_portion```. Additionally, there are also three rules to exclude problematic sheets from the chosen set: \n- Sheets with duration alignment problems are excluded; \n- Sheets that may plagiarize from ground truth data (ld_sim>0.95) are excluded; \n- Sheets where staves for the same instrument are not grouped together are excluded.\n\nThe prefence data file will be names as ```data_index_path```, which records the file paths in chosen and rejected sets.\n\nRun this script:\n```\ncd RL\u002F\npython data.py\n```\n\n#### 5. DPO Training\n\nModify the parameters in ```RL\u002Fconfig.py```:\n```python\nDATA_INDEX_PATH = 'schubert_RL1.json'  # Preference data path\nPRETRAINED_PATH = '..\u002Ffinetune\u002Fweights_notagen_schubert_p_size_16_p_length_1024_p_layers_20_c_layers_6_h_size_1280_lr_1e-05_batch_1.pth'  # The model to go through DPO optimization\nEXP_TAG = 'schubert-RL1'              # Model tag for differentiation\n```\nYou can also modify other parameters like ```OPTIMATION_STEPS``` and DPO hyper-parameters.\n\nRun this script:\n```\ncd RL\u002F\nCUDA_VISIBLE_DEVICES=0 python train.py\n```\nAfter training, a model named ```weights_notagen_schubert-RL1_beta_0.1_lambda_10_p_size_16_p_length_1024_p_layers_20_c_layers_6_h_size_1280_lr_1e-06.pth``` will be saved under ```RL\u002F```. For the second round of CLaMP-DPO, please go back to the first inference stage, and let the new model to generate pieces.\n\nFor this small experiment on **Schubert's lieder** data, we post our **Average CLaMP 2 Score** here for the fine-tuned model and models after each iteration of CLaMP-DPO, as a reference:\n\n|  CLaMP-DPO Iteration (K) |  Average CLaMP 2 Score  | \n|  ----           |  ----  | \n|  0 (fine-tuned) | 0.324  |  \n|  1              | 0.579  |\n|  2              | 0.778  |\n\nIf you are interested in this method, have a try on your own style-specific dataset :D\n\n## 📚 Citation\n\nIf you find **NotaGen** or **CLaMP-DPO** useful in your work, please cite our paper.\n\n```bibtex\n@misc{wang2025notagenadvancingmusicalitysymbolic,\n      title={NotaGen: Advancing Musicality in Symbolic Music Generation with Large Language Model Training Paradigms}, \n      author={Yashan Wang and Shangda Wu and Jianhuai Hu and Xingjian Du and Yueqi Peng and Yongxin Huang and Shuai Fan and Xiaobing Li and Feng Yu and Maosong Sun},\n      year={2025},\n      eprint={2502.18008},\n      archivePrefix={arXiv},\n      primaryClass={cs.SD},\n      url={https:\u002F\u002Farxiv.org\u002Fabs\u002F2502.18008}, \n}\n```\n","# 🎵 NotaGen：利用大语言模型训练范式推进符号音乐生成 (Symbolic Music Generation) 中的音乐性\n\n\u003Cp align=\"center\">\n  \u003C!-- ArXiv -->\n  \u003Ca href=\"https:\u002F\u002Farxiv.org\u002Fabs\u002F2502.18008\">\n    \u003Cimg src=\"https:\u002F\u002Fimg.shields.io\u002Fbadge\u002FNotaGen_Paper-ArXiv-%23B31B1B?logo=arxiv&logoColor=white\" alt=\"Paper\">\n  \u003C\u002Fa>\n  &nbsp;&nbsp;\n  \u003C!-- HuggingFace -->\n  \u003Ca href=\"https:\u002F\u002Fhuggingface.co\u002FElectricAlexis\u002FNotaGen\">\n    \u003Cimg src=\"https:\u002F\u002Fimg.shields.io\u002Fbadge\u002FNotaGen_Weights-HuggingFace-%23FFD21F?logo=huggingface&logoColor=white\" alt=\"Weights\">\n  \u003C\u002Fa>\n  &nbsp;&nbsp;\n  \u003C!-- HuggingFace Space -->\n  \u003Ca href=\"https:\u002F\u002Fhuggingface.co\u002Fspaces\u002FElectricAlexis\u002FNotaGen\">\n    \u003Cimg src=\"https:\u002F\u002Fimg.shields.io\u002Fbadge\u002FNotaGen_Space-Huggingface-✨️?logo=huggingface&logoColor=white\" alt=\"Space\">\n  \u003C\u002Fa>\n  &nbsp;&nbsp;\n  \u003C!-- Web Demo -->\n  \u003Ca href=\"https:\u002F\u002Felectricalexis.github.io\u002Fnotagen-demo\u002F\">\n    \u003Cimg src=\"https:\u002F\u002Fimg.shields.io\u002Fbadge\u002FNotaGen_Demo-Web-%23007ACC?logo=google-chrome&logoColor=white\" alt=\"Demo\">\n  \u003C\u002Fa>\n\u003C\u002Fp>\n\n\u003Cp align=\"center\">\n  \u003Cimg src=\"https:\u002F\u002Foss.gittoolsai.com\u002Fimages\u002FElectricAlexis_NotaGen_readme_62e00887cba6.png\" alt=\"NotaGen\" width=\"50%\">\n\u003C\u002Fp>\n\n\n## 📖 概述\n**NotaGen** 是一个**符号音乐生成 (Symbolic Music Generation)** 模型，旨在探索生成**高质量古典乐谱**的潜力。受大语言模型 (Large Language Models, LLMs) 成功的启发，NotaGen 采用了三阶段训练范式：\n- 🧠 在 160 万首音乐作品上进行**预训练 (Pre-training)**\n- 🎯 在约 9000 首古典作品上进行**微调 (Fine-tuning)**，使用 `period-composer-instrumentation`（时期 - 作曲家 - 配器）提示词\n- 🚀 使用我们新颖的 **CLaMP-DPO** 方法进行**强化学习 (Reinforcement Learning)**（无需人工标注或预定义奖励。）\n\n查看我们的 [演示页面](https:\u002F\u002Felectricalexis.github.io\u002Fnotagen-demo\u002F) 并欣赏由 NotaGen 创作的音乐！\n\n## ⚙️ 环境设置\n\n```bash\nconda create --name notagen python=3.10\nconda activate notagen\nconda install pytorch==2.3.0 pytorch-cuda=11.8 -c pytorch -c nvidia\npip install accelerate\npip install optimum\npip install -r requirements.txt\n```\n\n## 🏋️ NotaGen 模型权重\n\n### 预训练\n我们提供了不同规模的预训练权重：\n|  模型 (Models)         |  参数量 (Parameters)  |  Patch 级解码器层数 (Patch-level Decoder Layers)  |  Character 级解码器层数 (Character-level Decoder Layers)  |  隐藏层大小 (Hidden Size)  |  Patch 长度 (上下文长度) (Patch Length (Context Length))  |\n|  ----           |  ----  |  ---- |  ----  |  ----  |  ----  |\n|  [NotaGen-small](https:\u002F\u002Fhuggingface.co\u002FElectricAlexis\u002FNotaGen\u002Fblob\u002Fmain\u002Fweights_notagen_pretrain_p_size_16_p_length_2048_p_layers_12_c_layers_3_h_size_768_lr_0.0002_batch_8.pth)  | 110M   |  12   |  3     |  768   |  2048  |\n|  [NotaGen-medium](https:\u002F\u002Fhuggingface.co\u002FElectricAlexis\u002FNotaGen\u002Fblob\u002Fmain\u002Fweights_notagen_pretrain_p_size_16_p_length_2048_p_layers_16_c_layers_3_h_size_1024_lr_0.0001_batch_4.pth) | 244M   |  16   |  3     |  1024  |  2048  |\n|  [NotaGen-large](https:\u002F\u002Fhuggingface.co\u002FElectricAlexis\u002FNotaGen\u002Fblob\u002Fmain\u002Fweights_notagen_pretrain_p_size_16_p_length_1024_p_layers_20_c_layers_6_h_size_1280_lr_0.0001_batch_4.pth)  | 516M   |  20   |  6     |  1280  |  1024  |\n\n**注意**：预训练权重不能用于基于 'period-composer-instrumentation' 的条件生成。\n\n### 微调\n\n我们在约 9000 首古典作品的语料库上对 NotaGen-large 进行了微调。您可以 [此处](https:\u002F\u002Fhuggingface.co\u002FElectricAlexis\u002FNotaGen\u002Fblob\u002Fmain\u002Fweights_notagen_pretrain-finetune_p_size_16_p_length_1024_p_layers_c_layers_6_20_h_size_1280_lr_1e-05_batch_1.pth) 下载权重。\n\n### 强化学习\n\n在预训练和微调之后，我们使用 3 次迭代的 CLaMP-DPO 优化了 NotaGen-large。您可以 [此处](https:\u002F\u002Fhuggingface.co\u002FElectricAlexis\u002FNotaGen\u002Fblob\u002Fmain\u002Fweights_notagen_pretrain-finetune-RL3_beta_0.1_lambda_10_p_size_16_p_length_1024_p_layers_20_c_layers_6_h_size_1280_lr_1e-06_batch_1.pth) 下载权重。\n\n### 🌟 NotaGen-X\n\n受 Deepseek-R1 启发，我们进一步优化了 NotaGen 的训练流程，并发布了一个更好的版本 --- [NotaGen-X](https:\u002F\u002Fhuggingface.co\u002FElectricAlexis\u002FNotaGen\u002Fblob\u002Fmain\u002Fweights_notagenx_p_size_16_p_length_1024_p_layers_20_h_size_1280.pth)。与论文中的版本相比，NotaGen-X 包含了以下改进：\n\n- 我们在预训练和微调之间引入了一个**后训练 (post-training)** 阶段，使用预训练数据集中的古典风格子集对模型进行优化。\n- 我们在微调阶段移除了调性增强 (key augmentation)，使得生成作品的乐器范围更加合理。\n- 在强化学习 (RL) 之后，我们利用生成的检查点 (checkpoint) 收集了一组新的后训练数据。从预训练检查点开始，我们进行了另一轮后训练、微调和强化学习。\n\n如果您想为 NotaGen-X 添加新的作曲家风格，请参阅 issue [#18](https:\u002F\u002Fgithub.com\u002FElectricAlexis\u002FNotaGen\u002Fissues\u002F18) 获取更多说明 :D\n\n## 🎹 演示\n\n### 在线 Gradio 演示\n\n我们在 Huggingface Space 上为 NotaGen-X 开发了一个 [在线 gradio 演示](https:\u002F\u002Fhuggingface.co\u002Fspaces\u002FElectricAlexis\u002FNotaGen)。您可以输入 **\"Period-Composer-Instrumentation\"（时期 - 作曲家 - 配器）** 作为提示词，让 NotaGen 生成音乐，预览音频\u002F乐谱 PDF，并下载它们 :D\n\n\u003Cp align=\"center\">\n  \u003Cimg src=\"https:\u002F\u002Foss.gittoolsai.com\u002Fimages\u002FElectricAlexis_NotaGen_readme_73af7631cd9a.png\" alt=\"NotaGen Gradio Demo\">\n\u003C\u002Fp>\n\n### 本地 Gradio 演示\n\n我们为 NotaGen-X 开发了一个本地 Gradio 演示。您可以输入 **\"Period-Composer-Instrumentation\"（时期 - 作曲家 - 配器）** 作为提示词，让 NotaGen 生成音乐！\n\n\u003Cp align=\"center\">\n  \u003Cimg src=\"https:\u002F\u002Foss.gittoolsai.com\u002Fimages\u002FElectricAlexis_NotaGen_readme_7b72cf78c5b9.png\" alt=\"NotaGen Gradio Demo\">\n\u003C\u002Fp>\n\n本地部署 NotaGen-X 推理可能需要 8GB 显存 (GPU memory)。有关实现细节，请查看 [gradio\u002FREADME.md](https:\u002F\u002Fgithub.com\u002FElectricAlexis\u002FNotaGen\u002Fblob\u002Fmain\u002Fgradio\u002FREADME.md)。我们也在努力开发在线演示。\n\n### 在线 Colab 笔记本\n\n感谢 [@deeplearn-art](https:\u002F\u002Fgithub.com\u002Fdeeplearn-art\u002FNotaGen) 贡献的 [NotaGen Google Colab 笔记本](https:\u002F\u002Fcolab.research.google.com\u002Fdrive\u002F1yJA1wG0fiwNeehdQxAUw56i4bTXzoVVv?usp=sharing)! 您可以运行它并访问 Gradio 公共链接来体验此演示。🤩\n\n### ComfyUI\n\n感谢 [@billwuhao](https:\u002F\u002Fgithub.com\u002Fbillwuhao\u002FComfyUI_NotaGen) 贡献的 [NotaGen ComfyUI 节点](https:\u002F\u002Fgithub.com\u002Fbillwuhao\u002FComfyUI_NotaGen)! 它可以自动将生成的 .abc 文件转换为 .xml、.mp3 和 .png 格式。您也可以聆听生成的音乐并查看乐谱！请访问 [仓库页面](https:\u002F\u002Fgithub.com\u002Fbillwuhao\u002FComfyUI_NotaGen) 获取更多信息。🤩 \n\n\u003Cp align=\"center\">\n  \u003Cimg src=\"https:\u002F\u002Foss.gittoolsai.com\u002Fimages\u002FElectricAlexis_NotaGen_readme_09482e88a8f6.png\" alt=\"NotaGen ComfyUI\">\n\u003C\u002Fp>\n\n## 🛠️ 数据预处理与后处理\n\n关于 **ABC 记谱法（ABC notation）** 文件与 **MusicXML（音乐标记语言）** 文件之间的互转，请查看 [data\u002FREADME.md](https:\u002F\u002Fgithub.com\u002FElectricAlexis\u002FNotaGen\u002Fblob\u002Fmain\u002Fdata\u002FREADME.md) 获取说明。\n\n为了说明具体的数据格式，我们提供了一个来自 [OpenScore Lieder](https:\u002F\u002Fgithub.com\u002FOpenScore\u002FLieder) 的 **舒伯特艺术歌曲（Schubert's lieder）** 作曲小型数据集，其中包括：\n- 🗂️ 交错 ABC 文件夹（Interleaved ABC folders）\n- 🗂️ 增强 ABC 文件夹（Augmented ABC folders）\n- 📄 用于训练和评估的数据索引文件\n\n您可以 [此处](https:\u002F\u002Fdrive.google.com\u002Fdrive\u002Ffolders\u002F1iVLkcywzXGcHFodce9nDQyEmK4UDmBtY?usp=sharing) 下载并将其放在 ```data\u002F``` 目录下。\n\n在下方的 **微调（Fine-tuning）** 和 **强化学习（Reinforcement Learning）** 说明中，我们将使用此数据集作为我们实现的示例。**它不包含“时期 - 作曲家 - 配器（period-composer-instrumentation）”条件控制（conditioning）**，仅用于展示如何将预训练的 NotaGen 适配到特定的音乐风格。\n\n\n## 🧠 预训练\n\n如果您想使用自己的数据预训练一个空白的 **NotaGen** 模型，请：\n1. 按照 [data\u002FREADME.md](https:\u002F\u002Fgithub.com\u002FElectricAlexis\u002FNotaGen\u002Fblob\u002Fmain\u002Fdata\u002FREADME.md) 中的说明预处理数据并生成数据索引文件\n2. 修改 ```pretrain\u002Fconfig.py``` 中的参数\n\n使用以下命令进行预训练：\n```bash\ncd pretrain\u002F\naccelerate launch --multi_gpu --mixed_precision fp16 train-gen.py\n```\n\n## 🎯 微调\n\n这里我们提供一个使用上述 **舒伯特艺术歌曲（Schubert's lieder）** 数据微调 **NotaGen-large** 的示例。\n\n**注意：** 使用 **NotaGen-large** 进行训练和推理至少需要 **24GB 显存（GPU memory）**。或者，您可以使用 **NotaGen-small** 或 **NotaGen-medium** 并在 ```finetune\u002Fconfig.py``` 中更改模型配置。\n\n### 配置\n- 在 ```finetune\u002Fconfig.py``` 中：\n  - 修改 ```DATA_TRAIN_INDEX_PATH``` 和 ```DATA_EVAL_INDEX_PATH```：\n    ```python\n    # Configuration for the data\n    DATA_TRAIN_INDEX_PATH = \"..\u002Fdata\u002Fschubert_augmented_train.jsonl\" \n    DATA_EVAL_INDEX_PATH  = \"..\u002Fdata\u002Fschubert_augmented_eval.jsonl\"\n    ```\n  - 下载预训练的 NotaGen 权重（weights），并修改 ```PRETRAINED_PATH```：\n    ```python\n    PRETRAINED_PATH = \"..\u002Fpretrain\u002Fweights_notagen_pretrain_p_size_16_p_length_1024_p_layers_20_c_layers_6_h_size_1280_lr_0.0001_batch_4.pth\"  # Use NotaGen-large\n    ```\n  - ```EXP_TAG``` 用于区分模型。它将整合进 **检查点（ckpt）** 的名称中。这里我们将其设置为 ```schubert```。\n  - 您也可以修改其他参数，如学习率。\n\n### 执行\n使用以下命令进行微调：\n```bash\ncd finetune\u002F\nCUDA_VISIBLE_DEVICES=0 python train-gen.py\n```\n\n## 🚀 强化学习（CLaMP-DPO）\n\n这里我们提供一个如何使用 **CLaMP-DPO** 增强使用 **舒伯特艺术歌曲（Schubert's lieder）** 数据微调后的模型的示例。\n\n### ⚙️ [CLaMP 2](https:\u002F\u002Fgithub.com\u002Fsanderwood\u002Fclamp2) 设置\n\n下载模型权重并将它们放在 ```clamp2\u002F``` 文件夹下：\n- [CLaMP 2 模型权重](https:\u002F\u002Fhuggingface.co\u002Fsander-wood\u002Fclamp2\u002Fblob\u002Fmain\u002Fweights_clamp2_h_size_768_lr_5e-05_batch_128_scale_1_t_length_128_t_model_FacebookAI_xlm-roberta-base_t_dropout_True_m3_True.pth)\n- [M3 模型权重](https:\u002F\u002Fhuggingface.co\u002Fsander-wood\u002Fclamp2\u002Fblob\u002Fmain\u002Fweights_m3_p_size_64_p_length_512_t_layers_3_p_layers_12_h_size_768_lr_0.0001_batch_16_mask_0.45.pth)\n\n### 🔍 提取真实值（Ground Truth）特征\n修改 ```clamp2\u002Fextract_clamp2.py``` 中的 ```input_dir``` 和 ```output_dir```：\n```python\ninput_dir = '..\u002Fdata\u002Fschubert_interleaved'  # interleaved abc folder\noutput_dir = 'feature\u002Fschubert_interleaved'  # feature folder\n```\n提取特征：\n```\ncd clamp2\u002F\npython extract_clamp2.py\n```\n\n### 🔄 CLaMP-DPO\n\n这里我们提供一个 **CLaMP-DPO**（基于 CLaMP 的直接偏好优化 Direct Preference Optimization）迭代示例，起始模型是在 **Schubert's lieder**（舒伯特艺术歌曲）数据上进行 **fine-tuned**（微调）的模型。\n\n#### 1. Inference（推理）\n- 在 ```inference\u002Fconfig.py``` 中将 ```INFERENCE_WEIGHTS_PATH``` 修改为 **fine-tuned**（微调）权重的路径，并将 ```NUM_SAMPLES``` 修改为要生成的样本数量：\n  ```python\n    INFERENCE_WEIGHTS_PATH = '..\u002Ffinetune\u002Fweights_notagen_schubert_p_size_16_p_length_1024_p_layers_20_c_layers_6_h_size_1280_lr_1e-05_batch_1.pth'              \n    NUM_SAMPLES = 1000                                               \n  ```\n- 执行 **Inference**（推理）：\n  ```\n  cd inference\u002F\n  python inference.py\n  ```\n  这将生成一个 ```output\u002F``` 文件夹，包含两个子文件夹：```original``` 和 ```interleaved```。```original\u002F``` 子目录存储模型的原始推理输出，而 ```interleaved\u002F``` 子目录包含经过 **rest measure completion**（休止符小节补全）后处理的数据，兼容 CLaMP 2。每个子目录都将包含一个特定于模型的文件夹，命名为模型名称与其采样参数的组合。\n\n#### 2. 提取生成数据特征\n\n修改 ```clamp2\u002Fextract_clamp2.py``` 中的 ```input_dir``` 和 ```output_dir```：\n```python\ninput_dir = '..\u002Foutput\u002Finterleaved\u002Fweights_notagen_schubert_p_size_16_p_length_1024_p_layers_20_c_layers_6_h_size_1280_lr_1e-05_batch_1_k_9_p_0.9_temp_1.2'  # interleaved abc folder\noutput_dir = 'feature\u002Fweights_notagen_schubert_p_size_16_p_length_1024_p_layers_20_c_layers_6_h_size_1280_lr_1e-05_batch_1_k_9_p_0.9_temp_1.2'  # feature folder\n```\n提取特征：\n```\ncd clamp2\u002F\npython extract_clamp2.py\n```\n\n#### 3. 平均 CLaMP 2 Score（得分）统计（可选）\n如果您关心当前模型的 **平均 CLaMP 2 Score**（Average CLaMP 2 Score），请修改 ```clamp2\u002Fstatistics.py``` 中的参数：\n```python\ngt_feature_folder = 'feature\u002Fschubert_interleaved'\noutput_feature_folder = 'feature\u002Fweights_notagen_schubert_p_size_16_p_length_1024_p_layers_20_c_layers_6_h_size_1280_lr_1e-05_batch_1_k_9_p_0.9_temp_1.2'\n```\n然后运行此脚本：\n```\ncd clamp2\u002F\npython statistics.py\n```\n\n#### 4. 构建偏好数据\n修改 ```RL\u002Fdata.py``` 中的参数：\n```python\ngt_feature_folder = '..\u002Fclamp2\u002Ffeature\u002Fschubert_interleaved'\noutput_feature_folder = '..\u002Fclamp2\u002Ffeature\u002Fweights_notagen_schubert_p_size_16_p_length_1024_p_layers_20_c_layers_6_h_size_1280_lr_1e-05_batch_1_k_9_p_0.9_temp_1.2'\noutput_original_abc_folder = '..\u002Foutput\u002Foriginal\u002Fweights_notagen_schubert_p_size_16_p_length_1024_p_layers_20_c_layers_6_h_size_1280_lr_1e-05_batch_1_k_9_p_0.9_temp_1.2'\noutput_interleaved_abc_folder = '..\u002Foutput\u002Finterleaved\u002Fweights_notagen_schubert_p_size_16_p_length_1024_p_layers_20_c_layers_6_h_size_1280_lr_1e-05_batch_1_k_9_p_0.9_temp_1.2'\ndata_index_path = 'schubert_RL1.json'  # Data for the first iteration of RL\ndata_select_portion = 0.1              \n```\n在此脚本中，将计算并排序每个生成乐曲的 **CLaMP 2 Score**（CLaMP 2 得分）。**chosen**（选中）和 **rejected**（拒绝）集中的数据比例由 ```data_select_portion``` 决定。此外，还有三条规则用于从选中集中排除有问题的乐谱：\n- 排除存在时长对齐问题的乐谱；\n- 排除可能抄袭 **ground truth data**（真实数据）的乐谱（ld_sim>0.95）；\n- 排除同一仪器的 **staves**（谱表）未分组在一起的乐谱。\n\n偏好数据文件将命名为 ```data_index_path```，记录选中集和拒绝集中的文件路径。\n\n运行此脚本：\n```\ncd RL\u002F\npython data.py\n```\n\n#### 5. DPO（Direct Preference Optimization，直接偏好优化）训练\n\n修改 ```RL\u002Fconfig.py``` 中的参数：\n```python\nDATA_INDEX_PATH = 'schubert_RL1.json'  # Preference data path\nPRETRAINED_PATH = '..\u002Ffinetune\u002Fweights_notagen_schubert_p_size_16_p_length_1024_p_layers_20_c_layers_6_h_size_1280_lr_1e-05_batch_1.pth'  # The model to go through DPO optimization\nEXP_TAG = 'schubert-RL1'              # Model tag for differentiation\n```\n您也可以修改其他参数，如 ```OPTIMATION_STEPS``` 和 **DPO** **hyper-parameters**（超参数）。\n\n运行此脚本：\n```\ncd RL\u002F\nCUDA_VISIBLE_DEVICES=0 python train.py\n```\n训练完成后，一个名为 ```weights_notagen_schubert-RL1_beta_0.1_lambda_10_p_size_16_p_length_1024_p_layers_20_c_layers_6_h_size_1280_lr_1e-06.pth``` 的模型将保存在 ```RL\u002F``` 下。对于第二轮 CLaMP-DPO，请回到第一个推理阶段，让新模型生成乐曲。\n\n对于这个基于 **Schubert's lieder**（舒伯特艺术歌曲）数据的小型实验，我们在此发布 **fine-tuned**（微调）模型及每次 CLaMP-DPO 迭代后模型的 **平均 CLaMP 2 Score**（Average CLaMP 2 Score），以供参考：\n\n|  CLaMP-DPO 迭代次数 (K) |  平均 CLaMP 2 Score  | \n|  ----           |  ----  | \n|  0 (微调后) | 0.324  |  \n|  1              | 0.579  |\n|  2              | 0.778  |\n\n如果您对此方法感兴趣，欢迎在您自己的风格特定数据集上尝试 :D\n\n## 📚 引用\n\n如果您在工作中发现 **NotaGen** 或 **CLaMP-DPO** 有用，请引用我们的论文。\n\n```bibtex\n@misc{wang2025notagenadvancingmusicalitysymbolic,\n      title={NotaGen: Advancing Musicality in Symbolic Music Generation with Large Language Model Training Paradigms}, \n      author={Yashan Wang and Shangda Wu and Jianhuai Hu and Xingjian Du and Yueqi Peng and Yongxin Huang and Shuai Fan and Xiaobing Li and Feng Yu and Maosong Sun},\n      year={2025},\n      eprint={2502.18008},\n      archivePrefix={arXiv},\n      primaryClass={cs.SD},\n      url={https:\u002F\u002Farxiv.org\u002Fabs\u002F2502.18008}, \n}\n```","# NotaGen 快速上手指南\n\nNotaGen 是一个基于大语言模型（LLM）训练范式的符号音乐生成模型，旨在生成高质量的古典乐谱。它采用三阶段训练范式：预训练、微调和使用 CLaMP-DPO 方法的强化学习。\n\n## 环境准备\n\n在开始之前，请确保您的系统满足以下要求：\n\n*   **操作系统**: Linux \u002F Windows\n*   **Python**: 3.10\n*   **GPU**: \n    *   **推理\u002F本地 Demo**: 至少 8GB 显存\n    *   **训练 (NotaGen-large)**: 至少 24GB 显存（或使用 small\u002Fmedium 版本）\n*   **CUDA**: 11.8\n*   **PyTorch**: 2.3.0\n\n## 安装步骤\n\n建议使用 Conda 创建独立环境并安装依赖：\n\n```bash\nconda create --name notagen python=3.10\nconda activate notagen\nconda install pytorch==2.3.0 pytorch-cuda=11.8 -c pytorch -c nvidia\npip install accelerate\npip install optimum\npip install -r requirements.txt\n```\n\n## 基本使用\n\n### 1. 在线体验 (无需安装)\n\n最快速的使用方式是通过 HuggingFace Space 或 Web Demo 在线生成音乐：\n\n*   **HuggingFace Space**: [https:\u002F\u002Fhuggingface.co\u002Fspaces\u002FElectricAlexis\u002FNotaGen](https:\u002F\u002Fhuggingface.co\u002Fspaces\u002FElectricAlexis\u002FNotaGen)\n*   **Web Demo**: [https:\u002F\u002Felectricalexis.github.io\u002Fnotagen-demo\u002F](https:\u002F\u002Felectricalexis.github.io\u002Fnotagen-demo\u002F)\n\n在提示框中输入 **\"Period-Composer-Instrumentation\"**（时期 - 作曲家 - 配器）格式的提示词即可生成乐谱和音频。\n\n### 2. 本地部署与推理\n\n如果您已本地安装环境，可以下载模型权重进行推理或微调。\n\n#### 下载模型权重\n根据需求选择以下权重（通过 HuggingFace 下载）：\n*   **NotaGen-X (推荐)**: [下载链接](https:\u002F\u002Fhuggingface.co\u002FElectricAlexis\u002FNotaGen\u002Fblob\u002Fmain\u002Fweights_notagenx_p_size_16_p_length_1024_p_layers_20_h_size_1280.pth)\n*   **NotaGen-large (微调版)**: [下载链接](https:\u002F\u002Fhuggingface.co\u002FElectricAlexis\u002FNotaGen\u002Fblob\u002Fmain\u002Fweights_notagen_pretrain-finetune_p_size_16_p_length_1024_p_layers_c_layers_6_20_h_size_1280_lr_1e-05_batch_1.pth)\n\n#### 运行本地 Gradio Demo\n本地部署 Gradio 界面可生成音乐并预览音频\u002FPDF 乐谱。具体实现细节请参考 `gradio\u002FREADME.md`。部署 NotaGen-X 推理本地版约需 8GB 显存。\n\n#### 运行推理脚本 (示例)\n若需通过脚本进行推理（例如在强化学习流程中），可配置 `inference\u002Fconfig.py` 后运行：\n\n```bash\ncd inference\u002F\npython inference.py\n```\n\n#### 微调模型 (示例)\n若需使用自有数据微调模型（例如舒伯特艺术歌曲数据集），配置 `finetune\u002Fconfig.py` 后运行：\n\n```bash\ncd finetune\u002F\nCUDA_VISIBLE_DEVICES=0 python train-gen.py\n```\n\n> **注意**: 微调前请确保已按照 `data\u002FREADME.md` 完成数据预处理（ABC  notation 与 MusicXML 转换）。","独立游戏开发者正在为一款历史策略游戏制作配乐，急需符合特定时期风格且可编辑的高质量古典乐谱。\n\n### 没有 NotaGen 时\n- 传统 AI 生成的音频无法提供符号乐谱，后期修改难度极大，无法调整具体音符。\n- 手动创作古典乐谱耗时耗力，开发者往往缺乏深厚的乐理知识，难以保证质量。\n- 难以精准控制音乐风格，如区分巴洛克与浪漫主义时期的和声特点与配器。\n- 现有模型生成的旋律缺乏长期连贯性，容易出现重复片段或逻辑断裂。\n\n### 使用 NotaGen 后\n- NotaGen 直接生成符号音乐，方便在 DAW 中进一步编辑和调整乐器轨道。\n- 利用预训练和微调范式，只需输入提示词即可快速产出专业级初稿，效率倍增。\n- 支持通过“时期 - 作曲家 - 配器”提示词，精准锁定目标音乐风格与情感色彩。\n- 引入 CLaMP-DPO 强化学习，无需人工标注即可优化音乐性，旋律流畅自然且富有变化。\n\nNotaGen 通过大语言模型训练范式，将古典音乐创作门槛大幅降低，同时保证了专业级的乐理质量与艺术表现力。","https:\u002F\u002Foss.gittoolsai.com\u002Fimages\u002FElectricAlexis_NotaGen_73af7631.png","ElectricAlexis","Yashan Wang","https:\u002F\u002Foss.gittoolsai.com\u002Favatars\u002FElectricAlexis_58613f94.png",null,"Central Conservatory of Music, China","https:\u002F\u002Fgithub.com\u002FElectricAlexis",[82,86],{"name":83,"color":84,"percentage":85},"Python","#3572A5",94.7,{"name":87,"color":88,"percentage":89},"Jupyter Notebook","#DA5B0B",5.3,1177,128,"2026-04-01T03:51:19","MIT","Linux, Windows","必需 NVIDIA GPU，推理需 8GB+ 显存 (NotaGen-X)，训练或运行 NotaGen-large 需 24GB+ 显存，CUDA 11.8","未说明",{"notes":98,"python":99,"dependencies":100},"预训练权重不可直接用于条件生成，需微调；强化学习阶段需单独下载配置 CLaMP 2 模型；数据需预处理为 ABC 格式；提供 Colab 和 ComfyUI 替代运行方案。","3.10",[101,102,103],"torch==2.3.0","accelerate","optimum",[38,15],4,"2026-03-27T02:49:30.150509","2026-04-06T08:09:01.694554",[109,114,118,123,128,132,137],{"id":110,"question_zh":111,"answer_zh":112,"source_url":113},590,"如何添加新的作曲家风格进行模型微调？","需要收集该作曲家的 `.abc` 格式乐谱文件。注意在数据预处理时，需在 Prompt 和 ABC 乐谱之间添加 `%end` 分隔符。维护者指出代码中曾有关于数据表示的错误，建议在每个 `.abc` 文件头部添加 `%Period`, `%Composer`, `%Instrumentation`, `%end` 等行。确保数据格式正确可避免微调时的潜在问题。","https:\u002F\u002Fgithub.com\u002FElectricAlexis\u002FNotaGen\u002Fissues\u002F18",{"id":115,"question_zh":116,"answer_zh":117,"source_url":113},591,"24GB 显存能否微调 NotaGen 大模型？","微调大模型（NotaGen-X）在 24GB 显存（如 L4 GPU）上可能会报 `torch.cuda.OutOfMemoryError`。用户反馈小模型（Small pretrained model）可以在 24GB 显存上成功微调，但会占用几乎所有显存。建议显存不足时使用小模型，或检查数据格式错误（如缺少 `%end`）是否导致显存异常。",{"id":119,"question_zh":120,"answer_zh":121,"source_url":122},592,"如何在 macOS (Apple Silicon) 上安装运行？","支持 macOS 推理，但训练可能受限。安装时不要安装 CUDA 版本 PyTorch。推荐命令：\n1. `conda create --name notagen python=3.10`\n2. `conda activate notagen`\n3. `conda install pytorch==2.3.0` (勿加 pytorch-cuda)\n4. `pip install accelerate optimum`\n5. `pip install -r requirements.txt`","https:\u002F\u002Fgithub.com\u002FElectricAlexis\u002FNotaGen\u002Fissues\u002F17",{"id":124,"question_zh":125,"answer_zh":126,"source_url":127},593,"在 RTX 4090 上生成一首乐曲需要多长时间？","大约需要 20 秒，具体时间可能有所变动。生成的 ABC 记谱法偶尔会有语法错误，可使用 `abc2midi` 命令行工具转换为 MIDI 或使用辅助函数修复。","https:\u002F\u002Fgithub.com\u002FElectricAlexis\u002FNotaGen\u002Fissues\u002F3",{"id":129,"question_zh":130,"answer_zh":131,"source_url":127},594,"NotaGen-X 大模型能在 24GB 显存上进行推理吗？","可以。用户反馈即使使用大模型，在 RTX 4090 \u002F 24 GB 显存上无需任何修改即可开箱即用且运行速度较快。这与微调所需的显存不同，推理需求较低。",{"id":133,"question_zh":134,"answer_zh":135,"source_url":136},595,"生成结果缺少乐谱头部信息或陷入循环怎么办？","这可能是 Windows 系统特有的问题。有用户反馈在 Windows 11 上生成结果错误（缺少 `%%score` 等头部信息）。建议在 Ubuntu 虚拟机中运行，或参考社区仓库（如 AI-Orchestra-Gen-Play）的解决方案。配置参数本身通常是正确的。","https:\u002F\u002Fgithub.com\u002FElectricAlexis\u002FNotaGen\u002Fissues\u002F13",{"id":138,"question_zh":139,"answer_zh":140,"source_url":141},596,"是否有 ComfyUI 的集成节点可用？","有社区开发者制作了 ComfyUI 节点 (ComfyUI_NotaGen)。功能支持自动生成 .abc 并转换为 .xml, .mp3, 和 .png 格式，方便直接聆听音乐和查看乐谱。维护者已确认并将此功能添加到了 README 中。","https:\u002F\u002Fgithub.com\u002FElectricAlexis\u002FNotaGen\u002Fissues\u002F15",[]]