FlagAlpha / Llama2-Chinese
- воскресенье, 23 июля 2023 г. в 00:00:01
最好的中文Llama大模型,完全开源可商用
最好的中文Llama大模型
Llama2-7B官网版本:https://pan.xunlei.com/s/VN_kR2fwuJdG1F3CoF33rwpIA1?pwd=z9kf
Llama2-7B-Chat官网版本:https://pan.xunlei.com/s/VN_kQa1_HBvV-X9QVI6jV2kOA1?pwd=xmra
Llama2-13B官网版本:https://pan.xunlei.com/s/VN_izibaMDoptluWodzJw4cRA1?pwd=2qqb
Llama2-13B-Chat官网版本:https://pan.xunlei.com/s/VN_iyyponyapjIDLXJCNfqy7A1?pwd=t3xw
Llama2-7B Huggingface版本:https://pan.xunlei.com/s/VN_t0dUikZqOwt-5DZWHuMvqA1?pwd=66ep
Llama2-7B-Chat Huggingface版本:https://pan.xunlei.com/s/VN_oaV4BpKFgKLto4KgOhBcaA1?pwd=ufir
Llama2-13B Huggingface版本:https://pan.xunlei.com/s/VN_yT_9G8xNOz0SDWQ7Mb_GZA1?pwd=yvgf
Llama2-13B-Chat Huggingface版本:https://pan.xunlei.com/s/VN_yA-9G34NGL9B79b3OQZZGA1?pwd=xqrg
欢迎来到Llama2中文社区!我们是一个专注于Llama2模型在中文方面的优化和上层建设的高级技术社区。 *基于大规模中文数据,从预训练开始对Llama2模型进行中文能力的持续迭代升级*。 我们热忱欢迎对大模型LLM充满热情的开发者和研究者加入我们的行列。
我们计划通过以下数据来优化Llama2的中文能力:
类型 | 描述 |
---|---|
网络数据 | 互联网上公开的网络数据,挑选出去重后的高质量中文数据,涉及到百科、书籍、博客、新闻、公告、小说等高质量长文本数据。 |
Wikipedia | 中文Wikipedia的数据 |
悟道 | 中文悟道开源的200G数据 |
Clue | Clue开放的中文预训练数据,进行清洗后的高质量中文长文本数据 |
竞赛数据集 | 近年来中文自然语言处理多任务竞赛数据集,约150个 |
MNBVC | MNBVC 中清洗出来的部分数据集 |
希望大家如果有较高质量的数据集能够提供给我们,不胜感激!
Meta在
Llama2预训练模型包含7B、13B和70B三个版本
模型名称 | 下载地址 | |
---|---|---|
Llama2-7B | meta-llama/Llama-2-7b-hf | 模型下载 |
Llama2-13B | meta-llama/Llama-2-13b-hf | 模型下载 |
Llama2-70B | meta-llama/Llama-2-70b-hf | 模型下载 |
Llama2-Chat模型基于预训练模型进行了监督微调,具备更强的对话能力
模型名称 | 下载地址 | |
---|---|---|
Llama2-7B-Chat | meta-llama/Llama-2-7b-chat-hf | 模型下载 |
Llama2-13B-Chat | meta-llama/Llama-2-13b-chat-hf | 模型下载 |
Llama2-70B-Chat | meta-llama/Llama-2-70b-chat-hf | 模型下载 |
from transformers import AutoTokenizer, AutoModelForCausalLM
model = AutoModelForCausalLM.from_pretrained('meta-llama/Llama-2-7b-chat-hf',device_map='auto',torch_dtype=torch.float16,load_in_8bit=True)
model =model.eval()
tokenizer = AutoTokenizer.from_pretrained('meta-llama/Llama-2-7b-chat-hf',use_fast=False)
tokenizer.pad_token = tokenizer.eos_token
input_ids = tokenizer(['<s>Human: 介绍一下中国\n</s><s>Assistant: '], return_tensors="pt",add_special_tokens=False).input_ids.to('cuda')
generate_input = {
"input_ids":input_ids,
"max_new_tokens":512,
"do_sample":True,
"top_k":50,
"top_p":0.95,
"temperature":0.3,
"repetition_penalty":1.3,
"eos_token_id":tokenizer.eos_token_id,
"bos_token_id":tokenizer.bos_token_id,
"pad_token_id":tokenizer.pad_token_id
}
generate_ids = model.generate(**generate_input)
text = tokenizer.decode(generate_ids[0])
print(text)
基于gradio搭建的问答界面,实现了流式的输出,将下面代码复制到控制台运行,以下代码以Llama2-7B-Chat模型为例,不同模型只需修改一下代码里的模型名称就好了
python examples/chat_gradio.py --model_name_or_path meta-llama/Llama-2-7b-chat
本仓库中提供了基于LoRA的微调代码,未来我们将会扩展更多的微调算法,敬请期待!关于LoRA的详细介绍可以参考论文“LoRA: Low-Rank Adaptation of Large Language Models”以及微软Github仓库LoRA。
根据requirements.txt安装对应的环境依赖。
在data目录下提供了一份用于模型sft的数据样例:
每个csv文件中包含一列“text”,每一行为一个训练样例,每个训练样例按照以下格式将问题和答案组织为模型输入,您可以按照以下格式自定义训练和验证数据集:
"<s>Human: "+问题+"\n</s><s>Assistant: "+答案
例如,
<s>Human: 用一句话描述地球为什么是独一无二的。</s><s>Assistant: 因为地球是目前为止唯一已知存在生命的行星。</s>
我们提供了用于微调的脚本train/sft/finetune.sh,通过修改脚本的部分参数实现模型的微调,关于微调的具体代码见train/sft/finetune_clm_lora.py。
为了能够更加清晰地了解Llama2模型的中文问答能力,我们筛选了一些具有代表性的中文问题,对Llama2模型进行提问。我们测试的模型包含Meta公开的Llama2-7B-Chat和Llama2-13B-Chat两个版本,没有做任何微调和训练。测试问题筛选自AtomBulb,共95个测试问题,包含:通用知识、语言理解、创作能力、逻辑推理、代码编程、工作技能、使用工具、人格特征八个大的类别。
测试中使用的Prompt如下,例如对于问题“列出5种可以改善睡眠质量的方法”:
[INST]
<<SYS>>
You are a helpful, respectful and honest assistant. Always answer as helpfully as possible, while being safe. Your answers should not include any harmful, unethical, racist, sexist, toxic, dangerous, or illegal content. Please ensure that your responses are socially unbiased and positive in nature. The answer always been translate into Chinese language.
If a question does not make any sense, or is not factually coherent, explain why instead of answering something not correct. If you don't know the answer to a question, please don't share false information.
The answer always been translate into Chinese language.
<</SYS>>
列出5种可以改善睡眠质量的方法
[/INST]
Llama2-7B-Chat的测试结果见meta_eval_7B.md,Llama2-13B-Chat的测试结果见meta_eval_13B.md。
通过测试我们发现,Meta原始的Llama2 Chat模型对于中文问答的对齐效果一般,大部分情况下都不能给出中文回答,或者是中英文混杂的形式。因此,基于中文数据对Llama2模型进行训练和微调十分必要,我们的中文版Llama2模型也已经在训练中,近期将对社区开放。
感谢原子回声AtomEcho团队的技术和资源支持!
感谢 @xzsGenius 对Llama2中文社区的贡献!
感谢 @Z Potentials社区对Llama2中文社区的支持!
如有问题,请在GitHub Issue中提交,在提交问题之前,请先查阅以往的issue是否能解决你的问题。
礼貌地提出问题,构建和谐的讨论社区。
加入飞书知识库,一起共建社区文档。
加入微信群讨论