Upload README.md
Browse files
README.md
CHANGED
@@ -1,30 +1,81 @@
|
|
1 |
-
|
2 |
-
|
3 |
-
|
4 |
-
|
5 |
-
|
6 |
-
|
7 |
-
##
|
8 |
-
|
9 |
-
|
10 |
-
|
11 |
-
|
12 |
-
##
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
25 |
```python
|
26 |
import torch
|
27 |
-
from transformers import
|
28 |
|
29 |
device = torch.device("cuda:0") if torch.cuda.is_available() else torch.device("cpu")
|
30 |
|
@@ -32,9 +83,63 @@ model_path = "itpossible/Chinese-Mistral-7B-v0.1"
|
|
32 |
tokenizer = AutoTokenizer.from_pretrained(model_path)
|
33 |
model = AutoModelForCausalLM.from_pretrained(model_path, torch_dtype=torch.bfloat16, device_map=device)
|
34 |
|
35 |
-
text = "
|
36 |
inputs = tokenizer(text, return_tensors="pt").to(device)
|
37 |
|
38 |
-
outputs = model.generate(**inputs, max_new_tokens=
|
39 |
print(tokenizer.decode(outputs[0], skip_special_tokens=True))
|
40 |
-
```
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<div align="center">
|
2 |
+
<h1>
|
3 |
+
Chinese-Mistral
|
4 |
+
</h1>
|
5 |
+
</div>
|
6 |
+
|
7 |
+
## 🎉 新闻
|
8 |
+
|
9 |
+
- [2024-04-04] 发布Chinese-Mistral指令精调模型。
|
10 |
+
- [2024-03-31] 发布Chinese-Mistral基座模型。
|
11 |
+
|
12 |
+
## 🚀 介绍
|
13 |
+
|
14 |
+
随着Mistral AI公司开源其七十亿参数模型[Mistral-7B](https://huggingface.co/meta-llama/Llama-2-7b-hf),该模型超越[Llama](https://huggingface.co/meta-llama),成为当前最强大的开源模型之一。Mistral-7B在各类基准测试中,不仅超过了Llama2-13B,而且在推理、数学、代码生成任务中超过Llama2-34B。
|
15 |
+
然而,Mistral-7B的训练语料主要为英文文本,其中文能力较为欠缺。其次,Mistral-7B的词表不支持中文,导致其对中文的编码和解码效率较低,限制了在中文场景的应用。<br>
|
16 |
+
为了克服这一局限,清华大学地球系统科学系地球和空间信息科学实验室基于Mistral-7B进行了中文词表扩充和增量预训练,增强了Mistral-7B在中文任务上的表现,并提高了其对中文文本的编解码效率。<br>
|
17 |
+
项目地址:https://github.com/THU-ESIS/Chinese-Mistral
|
18 |
+
|
19 |
+
## 📥 模型下载
|
20 |
+
|
21 |
+
本项目开源了Chinese-Mistral-7B与Chinese-Mistral-7B-instruct:
|
22 |
+
|
23 |
+
| 模型 | 下载地址 | 说明 |
|
24 |
+
|:-----------------------------:|:------------------------------------------------------------------------------:|:-------------------------------------------------------------------------------------------------------------------:|
|
25 |
+
| Chinese-Mistral-7B | [HuggingFace](https://huggingface.co/itpossible/Chinese-Mistral-7B-v0.1)<br>[wisemodel](https://wisemodel.cn/models/itpossible/Chinese-Mistral-7B-v0.1)<br>[ModelScope](https://www.modelscope.cn/models/itpossible/Chinese-Mistral-7B-v0.1) | 完整基座模型 |
|
26 |
+
| Chinese-Mistral-7B-Instruct | [HuggingFace](https://huggingface.co/itpossible/Chinese-Mistral-7B-Instruct-v0.1)<br>[wisemodel](https://wisemodel.cn/models/itpossible/Chinese-Mistral-7B-Instruct-v0.1)<br>[ModelScope](https://www.modelscope.cn/models/itpossible/Chinese-Mistral-7B-Instruct-v0.1) | 完整指令精调模型<br>中英文alpaca_gpt4进行lora微调|
|
27 |
+
|
28 |
+
## 📈 模型性能
|
29 |
+
|
30 |
+
### 模型综合能力
|
31 |
+
|
32 |
+
我们采用C-Eval、CMMLU和MMLU三个评测数据集全面评估Chinese-Mistral-7B:
|
33 |
+
|
34 |
+
- C-Eval:它是一个全面的中文基础模型评估套件。包含13948个多项选择题,涵盖52个学科和四个难度级别。它旨在评估模型在人文、社科、理工等多个学科大类上的知识和推理能力。
|
35 |
+
- CMMLU:它是一个综合性的中文评估基准。涵盖了从基础学科到高级专业水平的67个主题。它专门用于评估语言模型在中文语境下的知识和推理能力。
|
36 |
+
- MMLU:它是一个包含了57个子任务的英文评测数据集。涵盖了从初等数学、美国历史、计算机科学到法律等多个领域,难度覆盖高中水平到专家水平,有效地衡量了模型在人文、社科和理工等多个学科大类中的综合知识能力。
|
37 |
+
|
38 |
+
下表展示了���源社区较流行的中文Llama2、中文Mistral与我们发布的Chinese-Mistral-7B的评测结果。评测方式采用5-shot,采用opencompass在相同的实验条件下进行评测。
|
39 |
+
|
40 |
+
| 模型名称 | C-Eval | CMMLU | MMLU | 平均得分 |
|
41 |
+
|:-----------------------------------------------------------------------------------------------:|:-------------:|:-------------:|:------------:|:-----------------:|
|
42 |
+
| [Linly-Al/Chinese-LLaMA-2-7B-hf](https://huggingface.co/Linly-Al/Chinese-LLaMA-2-7B-hf) | 31.2 | 30.14 | 35.09 | 32.14 |
|
43 |
+
| [hfl/chinese-llama-2-7b](https://huggingface.co/hfl/chinese-llama-2-7b) | 27.4 | 33.38 | 37.25 | 32.68 |
|
44 |
+
| [Linly-Al/Chinese-LLaMA-2-13B-hf](https://huggingface.co/Linly-Al/Chinese-LLaMA-2-13B-hf) | 39.9 | 42.48 | 52.54 | 44.97 |
|
45 |
+
| [hfl/chinese-llama-2-13b](https://huggingface.co/hfl/chinese-llama-2-13b) | 41.0 | 43.25 | 52.94 | 45.73 |
|
46 |
+
| [gywy/Mistral-7B-v0.1-chinese](https://huggingface.co/gywy/Mistral-7B-v0.1-chinese) | 37.4 | 36.45 | 37.38 | 37.08 |
|
47 |
+
|[OpenBuddy/openbuddy-mistral-7b-v13-base](https://huggingface.co/OpenBuddy/openbuddy-mistral-7b-v13-base)| 44.4 | 46.32 | 57.79 | 49.50 |
|
48 |
+
| **[Chinese-Mistral-7B (本模型)](https://huggingface.co/itpossible/Chinese-Mistral-7B-v0.1)** | **47.5** | **47.52** | **58.29** | **51.10** |
|
49 |
+
|
50 |
+
由上表可知,Chinese-Mistral-7B的中文和英文通识能力不仅超过同等参数量的中文Llama2模型,而且在多项评测中优于130亿参数量的中文Llama2。同时,Chinese-Mistral-7B的评测表现高于开源社区其他同等参数量的中文Mistral。
|
51 |
+
|
52 |
+
### 中文编解码效率
|
53 |
+
|
54 |
+
我们从WuDaoCorpus2中采样训练数据,使用sentencepiece训练中文BPE词表,并人工选取部分其他优秀中文词表进行词表融合。经过严格的人工审核,最终形成的词表大小为63776。为了提高模型计算效率,我们在词表末尾添加<|sym1|>、……、<|sym96|>,使得词表大小为128的倍数,最终得到的词表大小为63872。
|
55 |
+
我们随机选取了WuDaoCorpus2_part-2021278643作为测试数据以评测分词效果。经统计,测试数据包括67013857个单词,我们用单词数量除以分词后的Token数量,计算压缩率。压缩率越大,表明分词效果越好,在中文场景的编解码效率越高。
|
56 |
+
|
57 |
+
| 模型名称 | 模型类型 | 词表大小 | Token数量 | 压缩率 |
|
58 |
+
|:-----------------------------------------------------------------------------------------------:|:-------------:|:-------------:|:------------:|:-----------------:|
|
59 |
+
| [meta-llama/Llama-2-7b-hf](https://huggingface.co/meta-llama/Llama-2-7b-hf) | Llama | 32000 | 97406876 | 0.6880 |
|
60 |
+
| [mistralai/Mistral-7B-v0.1](https://huggingface.co/mistralai/Mistral-7B-v0.1) | Mistral | 32000 | 76269008 | 0.8787 |
|
61 |
+
| [THUDM/chatglm2-6b](https://huggingface.co/THUDM/chatglm2-6b) | GLM | 64789 | 43487673 | 1.5410 |
|
62 |
+
| [Linly-Al/Chinese-LLaMA-2-13B-hf](https://huggingface.co/Linly-Al/Chinese-LLaMA-2-13B-hf) | Llama | 40076 | 65402900 | 1.0246 |
|
63 |
+
| [hfl/chinese-llama-2-13b](https://huggingface.co/hfl/chinese-llama-2-13b) | Llama | 55296 | 45763513 | 1.4644 |
|
64 |
+
| [OpenBuddy/openbuddy-mistral-7b-v13-base](https://huggingface.co/OpenBuddy/openbuddy-mistral-7b-v13-base) | Mistral | 36608 | 65329642 | 1.0256 |
|
65 |
+
|[gywy/Mistral-7B-v0.1-chinese](https://huggingface.co/gywy/Mistral-7B-v0.1-chinese)| Mistral | 48593 | 46670146 | 1.4359 |
|
66 |
+
| **[Chinese-Mistral-7B (本模型)](https://huggingface.co/itpossible/Chinese-Mistral-7B-v0.1)** | Mistral | 63872 | **43044156** | **1.5569** |
|
67 |
+
|
68 |
+
|
69 |
+
|
70 |
+
由上表可知,Chinese-Mistral-7B在可观的词表大小条件下,取得了最高的压缩率,表明其能够高效处理中文文本。
|
71 |
+
|
72 |
+
## 💻 模型推理
|
73 |
+
|
74 |
+
如下是使用Chinese-Mistral-7B进行推理的代码示例。
|
75 |
+
|
76 |
```python
|
77 |
import torch
|
78 |
+
from transformers import AutoTokenizer, AutoModelForCausalLM
|
79 |
|
80 |
device = torch.device("cuda:0") if torch.cuda.is_available() else torch.device("cpu")
|
81 |
|
|
|
83 |
tokenizer = AutoTokenizer.from_pretrained(model_path)
|
84 |
model = AutoModelForCausalLM.from_pretrained(model_path, torch_dtype=torch.bfloat16, device_map=device)
|
85 |
|
86 |
+
text = "我是一个人工智能助手,我能够帮助你做如下这些事情:"
|
87 |
inputs = tokenizer(text, return_tensors="pt").to(device)
|
88 |
|
89 |
+
outputs = model.generate(**inputs, max_new_tokens=120, do_sample=True)
|
90 |
print(tokenizer.decode(outputs[0], skip_special_tokens=True))
|
91 |
+
```
|
92 |
+
|
93 |
+
如下是使用Chinese-Mistral-7B-Instruct进行推理的代码示例。
|
94 |
+
```python
|
95 |
+
import torch
|
96 |
+
from transformers import AutoTokenizer, AutoModelForCausalLM
|
97 |
+
|
98 |
+
device = torch.device("cuda:0") if torch.cuda.is_available() else torch.device("cpu")
|
99 |
+
|
100 |
+
model_path = "itpossible/Chinese-Mistral-7B-Instruct-v0.1"
|
101 |
+
tokenizer = AutoTokenizer.from_pretrained(model_path)
|
102 |
+
model = AutoModelForCausalLM.from_pretrained(model_path, torch_dtype=torch.bfloat16, device_map=device)
|
103 |
+
|
104 |
+
text = "请为我推荐中国三座比较著名的山"
|
105 |
+
messages = [{"role": "user", "content": text}]
|
106 |
+
|
107 |
+
inputs = tokenizer.apply_chat_template(messages, return_tensors="pt").to(device)
|
108 |
+
outputs = model.generate(inputs, max_new_tokens=300, do_sample=True)
|
109 |
+
outputs = tokenizer.batch_decode(outputs, skip_special_tokens=True)[0]
|
110 |
+
print(outputs)
|
111 |
+
```
|
112 |
+
Chinese-Mistral-7B 与Chinese-Mistral-7B-Instruct生成效果示例如下:
|
113 |
+
|
114 |
+
| 模型名称 | Chinese-Mistral-7B | Chinese-Mistral-7B-Instruct |
|
115 |
+
|--- |--- |--- |
|
116 |
+
| 用户输入 | <div style="width: 270pt">我是一个人工智能助手,我能够帮助你做如下这些事情: | <div style="width: 270pt">请为我推荐中国三座比较著名的山 |
|
117 |
+
| 模型输出 | <div style="width: 270pt">1、搜索资料,我可以帮你搜索任何你需要的资料。比如搜索某本书的内容,搜索某某地的地图,搜索某部电影的播放地址等。<br>2、计算,我可以帮你计算各种数学题,比如加法,减法,乘积,除法等等。计算各种不同科目的公式,比如化学方程式的计算,物理公式的计算等。<br>3、做笔记,你可以把你的想法记录在我的字典里面,或者记录日程安排。<br>4、翻译,你可以把的设置为你的即时翻译器,将你要翻译的内容放到信息框里面,然后点击发送就可以。 | <div style="width: 270pt">中国的山川风景十分美丽,以下三座山是国内比较著名的景点:<br>1.泰山:泰山,位于山东省泰安市北部,历史悠久,是我国五大名山之一,海拔约1545米,其雄伟的地势和壮丽的风光吸引了不少游客前来游览。<br>2.黄山:黄山位于安徽省东南部,因独特的山水风光和丰富的文化和历史积淀而闻名于世,这里悬崖峭壁,奇峰怪石,云海雾海,景色奇特秀丽,被誉为“天下第一奇山”。<br>3.峨眉山:峨眉山位于四川省峨眉山市东北部,是中国四大佛教名山之一,因雄伟壮观的山峰和丰富多彩的森林资源而闻名于世。这里气候湿润,植被覆盖率极高,景色秀丽,被赞誉为“峨眉天下秀”。 |
|
118 |
+
|
119 |
+
## 📝 训练数据
|
120 |
+
|
121 |
+
训练数据采样于WanJuan、baike2018qa、Dolma、gutenberg-books等高质量开源数据集。我们对这些数据集进行细粒度清洗,并充分考虑训练数据集中不同类别数据的占比。
|
122 |
+
|
123 |
+
## ⚠️ 局限性
|
124 |
+
|
125 |
+
Chinese-Mistral-7B的开发旨在为开源社区提供一个性能优越的中文大语言模型。请注意,由于模型大小及训练数据规模限制,本模型仍可能生成误导性内容或者有害内容。因此,在部署任何由Chinese-Mistral系列模型驱动的应用程序之前,开发人员必须进行安全测试,对模型进行相应调整,以满足安全性需求。
|
126 |
+
|
127 |
+
## ✒️ 引用
|
128 |
+
|
129 |
+
如果您觉得本项目对您的研究有所帮助或使用了本项目的模型,请引用本项目:
|
130 |
+
|
131 |
+
```bibtex
|
132 |
+
@misc{Chinese-Mistral,
|
133 |
+
author = {Zhou, Chen and Yiqi, Bai},
|
134 |
+
title = {Chinese-Mistral: An Efficient and Effective Chinese Large Language Model},
|
135 |
+
year = {2024},
|
136 |
+
publisher = {GitHub},
|
137 |
+
journal = {GitHub repository},
|
138 |
+
howpublished = {\url{https://github.com/THU-ESIS/Chinese-Mistral}}
|
139 |
+
}
|
140 |
+
```
|
141 |
+
|
142 |
+
## 结语
|
143 |
+
我们欢迎社区的支持和合作,共同推动通用大语言模型和领域大语言模型的发展。联系方式:<br>
|
144 |
+
白玉琪,清华大学地球系统科学系长聘教授,实验室负责人,[email protected]<br>
|
145 |
+
陈舟,清华大学地球系统科学系博士生,大语言模型组组长,[email protected]
|