{"id":19260949,"url":"https://github.com/learnprompt/llama2-chinese","last_synced_at":"2026-06-30T00:30:15.921Z","repository":{"id":190355268,"uuid":"681430319","full_name":"LearnPrompt/Llama2-Chinese","owner":"LearnPrompt","description":null,"archived":false,"fork":false,"pushed_at":"2023-08-24T07:53:47.000Z","size":167,"stargazers_count":10,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-01-05T09:44:38.823Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":null,"has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/LearnPrompt.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null}},"created_at":"2023-08-22T02:13:06.000Z","updated_at":"2024-08-01T13:11:16.000Z","dependencies_parsed_at":"2023-08-24T09:09:47.857Z","dependency_job_id":null,"html_url":"https://github.com/LearnPrompt/Llama2-Chinese","commit_stats":null,"previous_names":["learnprompt/llama2-chinese"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/LearnPrompt%2FLlama2-Chinese","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/LearnPrompt%2FLlama2-Chinese/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/LearnPrompt%2FLlama2-Chinese/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/LearnPrompt%2FLlama2-Chinese/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/LearnPrompt","download_url":"https://codeload.github.com/LearnPrompt/Llama2-Chinese/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":240357654,"owners_count":19788751,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-09T19:23:49.075Z","updated_at":"2026-06-30T00:30:15.829Z","avatar_url":"https://github.com/LearnPrompt.png","language":null,"funding_links":[],"categories":[],"sub_categories":[],"readme":"\u003cdiv align= \"center\"\u003e\n    \u003ch1\u003e 🦙Llama2-Chinese🦙 \u003c/h1\u003e\n\u003c/div\u003e\n\n这个项目旨在构建**开源、大规模、高质量**的预训练/指令调整SFT/领域垂直/RLHF数据，进一步增强Llama2大模型的中文能力以及打造多种垂直领域模型。我们提供数据集、相应的训练和评估脚本，以及经过微调的强大模型Llama2-Chinese。\n\n这个工作的独特之处\n- **中文化只是开始**：Llama2中文化只是第一步！我们的目标是在Llama2-Chinese基础上持续加强数学能力\u0026插件调用能力。\n- **开源与透明**：采用开源的预训练数据、指令微调数据、以及RLHF数据，致力于构建可复现的、透明的研究生态。\n- **一站式训练方法**：实现二次预训练，词表扩充，LoRA / QLoRA微调，全参数指令微调，奖励建模、强化学习训练。\n\n## 🚀 更新日志\n\n- [2023.08.18] [Llama2-13b-Chinese-chat](https://huggingface.co/carlAIwarts/Llama2-13b-Chinese-chat)发布🎉🎉🎉🎉；采用中英文开源指令微调数据\n⏳ **Llama2-7b-Chinese-chat**: Llama2-7b-Chinese-chat正在飞奔而来！\n⏳ **Llama2-Chinese**: 使用中英文语料对Llama 2进行增量预训练\n同时，我们将会围绕 Llama2-Chinese 打造各种垂直领域模型\n\n## 效果演示\n\n## 🔧 模型微调\n\n本仓库中提供了基于QLoRA的微调代码\n\n我们的训练代码基于[FastChat](https://github.com/lm-sys/FastChat)开发.您可以使用以下命令用两张A100（80G）训练, 训练数据是我们已经处理好的[数据]\n```bash\nexport PYTHONPATH=./\ndeepspeed --master_port=20001 train/sft/train_lora.py \\\n    --model_name_or_path huggyllama/llama-7b  \\\n    --data_path  data/instruction/dummy_data.jsonl \\\n    --conv_template llama-single-round \\\n    --bf16 True \\\n    --output_dir lora \\\n    --num_train_epochs 5 \\\n    --per_device_train_batch_size 4 \\\n    --per_device_eval_batch_size 2 \\\n    --gradient_accumulation_steps 2 \\\n    --evaluation_strategy \"epoch\" \\\n    --prediction_loss_only \\\n    --save_strategy \"epoch\" \\\n    --save_total_limit 8 \\\n    --learning_rate 5e-5 \\\n    --weight_decay 0. \\\n    --warmup_ratio 0.04 \\\n    --lr_scheduler_type \"cosine\" \\\n    --logging_steps 1 \\\n    --model_max_length 8192 \\\n    --gradient_checkpointing True \\\n    --lazy_preprocess True \\    \n    --deepspeed stage2.json \\\n    --report_to none\n```\n\n## 数据清洗\n* 仅中英文：使用fasttext的语言识别模型来按语言标记内容，仅留下中英文数据\n* 网络数据：大多数开放语言模型（如Llama 1/2、Falcon、T5、MPT）都是基于预处理的网络文本的一个重要部分进行训练的。\n* 质量过滤：网络爬取的数据中有很大一部分不适合语言模型训练（例如，格式不正确的文本、自动生成的网站文本）。这些通常通过“质量”过滤方法来移除，这里选择使用简单的启发式方法和正则表达式来过滤段落。这些过滤器的效果是去除从HTML转换为纯文本时产生的错误。\n* 去重：最近的研究表明，数据去重可以使语言模型更有效地训练。遵循这一原则，我选择在每个来源中去重数据。\n* 多样化的来源：我加入了更多的网络SFT数据，如InstructionWild\n\n## 数据发布\n\n使用下面链接下载我们的数据集\n- \n\n\n## 增量预训练数据\n\n| 类型                                                       | 描述                                                         |\n| ---------------------------------------------------------- | ------------------------------------------------------------ |\n| [CLUECorpus2020](https://github.com/CLUEbenchmark/CLUECorpus2020) | 通过对Common Crawl的中文部分进行语料清洗，最终得到100GB的高质量中文预训练语料，可直接用于预训练、语言模型或语言生成任务以及专用于简体中文NLP任务的小词表。 |\n| [Wikipedia](https://github.com/goldsmith/Wikipedia)        | 中文Wikipedia的数据                                          |\n| [MNBVC（part）](https://github.com/esbatmop/MNBVC)                 | 超大规模中文语料集，不但包括主流文化，也包括各个小众文化甚至火星文的数据。MNBVC数据集包括新闻、作文、小说、书籍、杂志、论文、台词、帖子、wiki、古诗、歌词、商品介绍、笑话、糗事、聊天记录等一切形式的纯文本中文数据。数据均来源于互联网收集|\n\n### SFT数据\n\n| 类型                                                       | 描述                                                         |\n| ---------------------------------------------------------- | ------------------------------------------------------------ |\n| [ShareChat](https://huggingface.co/datasets/shareAI/ShareGPT-Chinese-English-90k) | 中英文平行双语优质人机问答数据集，覆盖真实复杂场景下的用户提问。 |\n| [alpaca-gpt4](https://huggingface.co/datasets/vicgalle/alpaca-gpt4)        | Alpaca-GPT-4 是一个使用 self-instruct 技术，基于 175 条中文种子任务和 GPT-4 接口生成的 50K 的指令微调数据集。                                          |\n| [BELLE-data-1.5M](https://github.com/LianjiaTech/BELLE/tree/main/data/1.5M)        | 通过self-instruct生成，使用了中文种子任务，以及openai的text-davinci-003接口,涉及175个种子任务|\n| [InstructionWild](https://github.com/XueFuzhao/InstructionWild)        | InstructionWild 是一个从网络上收集自然指令并过滤之后使用自然指令结合 ChatGPT 接口生成指令微调数据集的项目。主要的指令来源：Twitter、CookUp.AI、Github 和 Discard。|\n| [COIG(part)](https://huggingface.co/datasets/BAAI/COIG)| 一套无害、有用且多样化的中文指令语料库，包括一个人工验证翻译的通用指令语料库、一个人工标注的考试指令语料库、一个人类价值对齐指令语料库、一个多轮反事实修正聊天语料库和一个 leetcode 指令语料库。|\n\n### 垂直领域数据\n\n| 类型                                                       | 描述                                                         |\n| ---------------------------------------------------------- | ------------------------------------------------------------ |\n| [Chinese medical dialogue data](https://github.com/Toyhom/Chinese-medical-dialogue-data) | 中文医疗对话数据集，包括：\u003cAndriatria_男科\u003e 94596个问答对 \u003cIM_内科\u003e 220606个问答对 \u003cOAGD_妇产科\u003e 183751个问答对 \u003cOncology_肿瘤科\u003e 75553个问答对 \u003cPediatric_儿科\u003e 101602个问答对 \u003cSurgical_外科\u003e 115991个问答对 总计 792099个问答对。 |\n| [Huatuo-26M](https://github.com/FreedomIntelligence/Huatuo-26M)        | Huatuo-26M 是一个中文医疗问答数据集，此数据集包含了超过2600万个高质量的医疗问答对，涵盖了各种疾病、症状、治疗方式、药品信息等多个方面。 |\n| [ToolBench](https://github.com/OpenBMB/ToolBench)        | ToolBench 包括单工具和多工具场景，从 RapidAPI 中获取 16,000 多个真实世界的API，并整理出涉及这些API的真实世界人类指令。多工具场景可进一步分为类别内多工具和集合内多工具。 |\n| [moss-003-sft-plugin-data](https://github.com/OpenLMLab/MOSS/tree/main/SFT_data/conversations/conversation_with_plugins)        | 使用的插件增强的多轮对话数据，包含支持搜索引擎、文生图、计算器、解方程等四个插件在内的约30万条多轮对话数据。 |\n\n### RLHF数据\n\n| 类型                                                       | 描述                                                         |\n| ---------------------------------------------------------- | ------------------------------------------------------------ |\n| [GPT-4-LLM](https://github.com/Instruction-Tuning-with-GPT-4/GPT-4-LLM) | 该项目开源了由GPT4生成的多种数据集，包括通过GPT4生成的中英PPO数据，可以用于奖励模型的训练。 |\n\n\n## 模型下载\n\nMeta在🤗Hugging Face上提供了所有模型的下载链接：https://huggingface.co/meta-llama\n\n### Llama2 模型\n\nLlama2 预训练模型包含7B、13B和70B三个版本；Llama2-Chat模型基于预训练模型进行了监督微调，具备更强的对话能力。\n\n| 模型名称   | 🤗模型加载名称             | 下载地址                                                     |\n| ---------- | ------------------------- | ------------------------------------------------------------ |\n| Llama2-7B  | meta-llama/Llama-2-7b-hf  | [模型下载](https://huggingface.co/meta-llama/Llama-2-7b-hf)  |\n| Llama2-13B | meta-llama/Llama-2-13b-hf | [模型下载](https://huggingface.co/meta-llama/Llama-2-13b-hf) |\n| Llama2-70B | meta-llama/Llama-2-70b-hf | [模型下载](https://huggingface.co/meta-llama/Llama-2-70b-hf) |\n| Llama2-7B-Chat  | meta-llama/Llama-2-7b-chat-hf  | [模型下载](https://huggingface.co/meta-llama/Llama-2-7b-chat-hf) |\n| Llama2-13B-Chat | meta-llama/Llama-2-13b-chat-hf | [模型下载](https://huggingface.co/meta-llama/Llama-2-13b-chat-hf) |\n| Llama2-70B-Chat | meta-llama/Llama-2-70b-chat-hf | [模型下载](https://huggingface.co/meta-llama/Llama-2-70b-chat-hf) |\n| Llama2-13b-Chinese-chat | carlAIwarts/Llama2-13b-Chinese-chat | [模型下载](https://huggingface.co/carlAIwarts/Llama2-13b-Chinese-chat) |\n\n### 模型推理\n\n**常用生成**\n```python\nfrom transformers import LlamaForCausalLM, LlamaTokenizer\n\nmodel_path = 'carlAIwarts/Llama2-13b-Chinese-chat'\n\ntokenizer = LlamaTokenizer.from_pretrained(model_path)\nmodel = LlamaForCausalLM.from_pretrained(model_path)\nprompt = \"用中文介绍一下你自己\"\ninput_ids = tokenizer(prompt, return_tensors=\"pt\").input_ids\ngen_tokens = model.generate(\n    input_ids,\n    do_sample=True,\n    temperature=0.6,\n    max_length=512,\n)\ngen_text = tokenizer.batch_decode(gen_tokens)[0]\nprint(gen_text)\n```\n\n**流式生成**\n```python\nfrom transformers import AutoTokenizer, AutoModelForCausalLM, TextStreamer\n\nmodel_path = 'carlAIwarts/Llama2-13b-Chinese-chat'\n\ntokenizer = LlamaTokenizer.from_pretrained(model_path)\nmodel = LlamaForCausalLM.from_pretrained(model_path)\n\nstreamer = TextStreamer(tokenizer, skip_prompt=True, skip_special_tokens=True)\nprompt = \"用中文介绍一下你自己\"\ngenerate_ids = model.generate(tokenizer(prompt, return_tensors='pt').input_ids.cuda(), max_new_tokens=4096, streamer=streamer)\n```\n\n### Gradio快速搭建问答平台\n\n- [ ] 基于gradio搭建的问答界面，实现流式的输出\n\n## 🏆 模型评测\n为了能够更加清晰地了解Llama2模型的中文问答能力，我们实现了对应的评估数据和代码\n\n| 类型                                                       | 描述                                                         |\n| ---------------------------------------------------------- | ------------------------------------------------------------ |\n| [C-Eval](https://github.com/SJTU-LIT/ceval) | 构造了一个覆盖人文，社科，理工，其他专业四个大方向，52 个学科（微积分，线代 …），从中学到大学研究生以及职业考试，一共 13948 道题目的中文知识和推理型测试集。此外还给出了当前主流中文LLM的评测结果。 |\n| [MMCU](https://github.com/Felixgithub2017/MMCU) | 该项目提供对中文大模型语义理解能力的测试，评测方式、评测数据集、评测记录都公开，确保可以复现。该项目旨在帮助各位研究者们评测自己的模型性能，并验证训练策略是否有效。 |\n| [MMLU](https://github.com/hendrclycks/test) | 包含 57 个多选任务的英文评测数据集，涵盖了初等数学、美国历史、计算机科学、法律等，难度覆盖高中水平到专家水平 |\n\n## 📚 Llama论文\n* [LLaMA: Open and Efficient Foundation Language Models](https://arxiv.org/abs/2302.13971)\n* [Llama 2: Open Foundation and Fine-Tuned Chat Models](https://arxiv.org/abs/2307.09288)\n\n## 🤔 入群交流\n\n加入微信群讨论；图片过期的话也欢迎加我的微信：carl_like_travel\n\n\u003cp align=\"center\" width=\"60%\"\u003e\n\u003cimg src=\"./assets/wechat.jpeg\" alt=\"Wechat\" style=\"width: 60%; display: block; margin: auto;\"\u003e\n\u003c/p\u003e\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flearnprompt%2Fllama2-chinese","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Flearnprompt%2Fllama2-chinese","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flearnprompt%2Fllama2-chinese/lists"}