CoolFace
Modelpublic

WisdomShell/Shell-7B-Chat

sourceHugging Faceupdated 2y agoView on Hugging Face
1likes16downloads
README.md184 linesDownload Raw Back to root
1---2language:3- zh4- en5tags:6- shell7- codeshell8- wisdomshell9- pku-kcl10- openbankai11---12 13## Introduction14 15Shell是[蚌壳智能](https://openbankai.com/)联合[北京大学知识计算实验室](http://se.pku.edu.cn/kcl/)在代码大模型[CodeShell](https://github.com/WisdomShell/codeshell)基础上训练的通用大模型基座。本仓库为Shell-7B-Chat模型仓库。16 17Shell在保留Codeshell优异的代码能力的同时,具有以下特性:18 19- **更全面的通用能力**:Shell在Codeshell的基础上继续预训练了1.5 T token的中英文语料,通用能力大幅提升。在语言、知识、推理等评测中,Shell均取得了优异的性能。20- **依旧强大的代码能力**:Shell在继续预训练的过程中,保留了20%高质量代码数据,使得Shell在获得通用能力的同时,依旧保留了CodeShell强大的代码能力。21- **更强大的语义理解能力**:Shell在继承Codeshell优异代码能力的同时,形成了强大的语义理解能力。相比LLaMA2-7B,Shell在RACE-Middle (+102%)、RACE-High(+98%)、OpenbookQA(+42%)等多个语义理解数据集取得更好的性能,达到同等规模开源大模型的领先水平。22 23本次我们同时发布了Shell-7B的base版本和chat版本,大家可以根据自身需求选择对应的模型。24 25- **[Shell-7B-Base](https://huggingface.co/WisdomShell/Shell-7B)**:具有强大语义理解能力的通用大模型,大家可以基于该模型微调自己的大模型。26- **[Shell-7B-Chat](https://huggingface.co/WisdomShell/Shell-7B-Chat)**:在Shell-7B-Base微调得到的对话预训练模型,直接下载使用即可获得流畅的对话体验。27 28 29## Performance30 31我们共选取了16个经典数据集对Shell进行了全面评测,评测脚本详见[模型评测](https://github.com/WisdomShell/shell/edit/main/evaluation/README.md)。具体评测结果如下。32| Dataset      | Baichuan2-7B-Base | LLaMA-2-7B | Shell-7B |33| ------------ | ----------------- | ---------- | -------- |34| C-Eval       | 56.3              | 32.5       | 50.13    |35| AGIEval      | 34.6              | 21.8       | 30.69    |36| MMLU         | 54.7              | 46.8       | 49.49    |37| CMMLU        | 57                | 31.8       | 50.4     |38| GAOKAO-Bench | 34.8              | 18.9       | 33       |39| WiC          | 50                | 50         | 50.47    |40| CHID         | 82.7              | 46.5       | 83.17    |41| AFQMC        | 58.4              | 69         | 69       |42| WSC          | 66.3              | 66.3       | 63.46    |43| RACE(Middle) | 50.9              | 40.2       | 82.66    |44| RACE(High)   | 52.5              | 37.5       | 74.24    |45| OpenbookQA   | 32.8              | 57         | 79       |46| GSM8K        | 24.6              | 16.7       | 20.7     |47| HumanEval    | 17.7              | 12.8       | 23.96    |48| MBPP         | 24                | 14.8       | 31.4     |49| BBH          | 41.8              | 38.2       | 38.16    |50 51## Requirements52 53- python 3.8 and above54- pytorch 2.0 and above are recommended55- transformers 4.32 and above56- CUDA 11.8 and above are recommended (this is for GPU users, flash-attention users, etc.)57 58## Quickstart59 60Shell系列模型已经上传至 <a href="https://huggingface.co/WisdomShell" target="_blank">Hugging Face</a>,开发者可以通过Transformers快速调用Shell-7B和Shell-Chat-7B。61 62在开始之前,请确保已经正确设置了环境,并安装了必要的代码包,以及满足上一小节的环境要求。你可以通过下列代码快速安装相关依赖。63 64```65pip install -r requirements.txt66```67 68接下来你可以通过Transformers使用Shell。69 70### 加载Shell-7B-Base71 72您可以通过Transformers加载Shell-7B-Base模型,Shell-7B-Base具备生成流畅自然语言的能力,您可以通过`generate`方法让模型生成相关的文字。73 74```python75import torch76from transformers import AutoModelForCausalLM, AutoTokenizer77 78device = 'cuda' if torch.cuda.is_available() else 'cpu'79tokenizer = AutoTokenizer.from_pretrained("WisdomShell/Shell-7B-Base")80model = AutoModelForCausalLM.from_pretrained("WisdomShell/Shell-7B-Base", trust_remote_code=True, torch_dtype=torch.bfloat16).to(device)81inputs = tokenizer('你好', return_tensors='pt').to(device)82outputs = model.generate(**inputs)83print(tokenizer.decode(outputs[0]))84```85 86### 加载Shell-7B-Chat87 88类似的,您可以通过Transformers加载Shell-7B-Chat模型,并通过`chat`方法与其进行对话。89 90```python91import torch92from transformers import AutoModelForCausalLM, AutoTokenizer93 94device = 'cuda' if torch.cuda.is_available() else 'cpu'95tokenizer = AutoTokenizer.from_pretrained("WisdomShell/Shell-7B-Chat")96model = AutoModelForCausalLM.from_pretrained("WisdomShell/Shell-7B-Chat", trust_remote_code=True, torch_dtype=torch.bfloat16).to(device)97history = []98output = model.chat('你是谁', history, tokenizer)99print(output)100```101 102### Shell in c/c++103 104由于大部分个人电脑没有GPU,Shell提供了C/C++版本的推理支持,开发者可以根据本地环境进行编译与使用,详见[Shell C/C++本地化版](https://github.com/WisdomShell/llama_cpp_for_codeshell)。105 106 107## Finetune108 109我们同样提供了模型微调相关代码,大家可以按照示例数据的格式准备自己的数据,进行快速微调,具体请参考[模型微调](https://github.com/WisdomShell/shell/edit/main/finetune/README.md)。110 111其中,多轮对话微调数据格式如下。112 113```json114[115  {116    "id": "identity_0",117    "conversations": [118      {119        "from": "human",120        "value": "你好"121      },122      {123        "from": "assistant",124        "value": "您好,我是Shell,请问有什么可以帮助您的吗?"125      }126    ]127  }128]129```130 131## Demo132 133我们提供了Web-UI、命令行、API三种形式的Demo。134 135### Web UI136 137开发者通过下列命令启动Web服务,服务启动后,可以通过`https://127.0.0.1:8000`进行访问。138 139```140python demos/web_demo.py141```142 143### CLI Demo144 145我们也提供了命令行交互的Demo版本,开发者可以通过下列命令运行。146 147```148python demos/cli_demo.py149```150 151### API152 153Shell也提供了基于OpenAI API的部署方法。154 155```156python demos/openai_api.py157```158 159启动后即可通过HTTP请求与Shell交互。160 161```162curl http://127.0.0.1:8000/v1/chat/completions \163  -H "Content-Type: application/json" \164  -d '{165    "model": "Shell-7B-Chat",166    "messages": [167      {168        "role": "user",169        "content": "你好"170      }171    ]172  }'173```174 175## License176 177社区使用Shell模型需要遵循[《Shell模型许可协议》](https://github.com/WisdomShell/shell/blob/main/License.pdf)及[Apache 2.0许可协议](https://www.apache.org/licenses/LICENSE-2.0)。Shell模型允许用于商业用途,但如果您计划将Shell模型或其派生产品用于商业用途,需要您确认主体符合以下条件:178 1791. 关联方的服务或产品的每日平均活跃用户数(DAU)不能超过100万。1802. 关联方不得是软件服务提供商或云服务提供商。1813. 关联方不存在将获得授予的商业许可,在未经许可的前提下将其再授权给其他第三方的可能性。182 183在满足上述条件的前提下,您需要通过向service@openbankai.com发送电子邮件,提交《Shell模型许可协议》要求的申请材料。经审核通过后,将授予您一个全球的、非排他的、不可转让的、不可再授权的商业版权许可。184