| --- |
| license: apache-2.0 |
| tags: |
| - text2text-generation |
| pipeline_tag: text2text-generation |
| language: |
| - zh |
| - en |
| widget: |
| - text: |- |
| Human: 使用python写一个二分查找的代码 |
| Assistant: |
| example_title: code zh |
| - text: >- |
| Human: Classify the sentiment of the following sentence into Positive, |
| Neutral, or Negative: |
| |
| Super excited about teaching Stanford’s first course on Large Language |
| Models! Check the syllabus out here |
|
|
| Assistant: |
| example_title: sentiment en |
| - text: |- |
| Human: 今天天气怎么样,把这句话翻译成英语 |
| Assistant: |
| example_title: translation zh-en |
| - text: |- |
| Human: 怎么让自己精力充沛,列5点建议 |
| Assistant: |
| example_title: brainstorming zh |
| - text: |- |
| Human: 请以『春天的北京』为题写一首诗歌 |
| Assistant: |
| example_title: generation zh |
| - text: |- |
| Human: 明天就假期结束了,有点抗拒上班,应该怎么办? |
| Assistant: |
| example_title: brainstorming zh |
| - text: |- |
| Human: 父母都姓吴,取一些男宝宝和女宝宝的名字 |
| Assistant: |
| example_title: brainstorming zh |
| - text: |- |
| Human: 推荐几本金庸的武侠小说 |
| Assistant: |
| example_title: brainstorming zh |
| --- |
| |
| # Model Card for Model ID |
|
|
| ## Model description |
| BELLE is based on Bloomz-7b1-mt and finetuned with 0.2M Chinese data combined with 50,000 pieces of English data from the open source Stanford-Alpaca, resulting in good Chinese instruction understanding and response generation capabilities. |
|
|
| The code of Chinese data generation and other detailed information can be found in our Github project repository: https://github.com/LianjiaTech/BELLE. |
|
|
| We trained models using datasets of different sizes (200,000, 600,000, and 1,000,000 samples) for instruction learning, and we obtained different model versions as shown below: |
| | Datasize| 200,000 | 600,000 | 1,000,000 | |
| | ----- | ----- | ----- | ----- | |
| | Finetuned Model | [BELLE-7B-0.2M](https://huggingface.co/BelleGroup/BELLE-7B-0.2M) | [BELLE-7B-0.6M](https://huggingface.co/BelleGroup/BELLE-7B-0.6M) | [BELLE-7B-1M](https://huggingface.co/BelleGroup/BELLE-7B-1M) | |
|
|
| ## Training hyper-parameters |
| | Parameter | Value | |
| | ------ | ------ | |
| | Batch size | 64 | |
| | Learning rate | 3e-6 | |
| | Epochs | 3 | |
| |Weight_decay | 0.001 | |
| |Warmup_rate | 0.1 | |
| |LR_scheduler | linear | |
| |
| ## Use model |
| Please note that the input should be formatted as follows in both **training** and **inference**. |
| ``` python |
| Human: {input} \n\nAssistant: |
| ``` |
| |
| BELLE can be easily loaded with AutoModelForCausalLM. |
| ``` python |
| from transformers import AutoTokenizer, AutoModelForCausalLM |
| import sys |
| |
| model_path = "./" # You can modify the path for storing the local model |
| model = AutoModelForCausalLM.from_pretrained(model_path) |
| tokenizer = AutoTokenizer.from_pretrained(model_path) |
| print("Human:") |
| line = input() |
| while line: |
| inputs = 'Human: ' + line.strip() + '\n\nAssistant:' |
| input_ids = tokenizer(inputs, return_tensors="pt").input_ids |
| outputs = model.generate(input_ids, max_new_tokens=200, do_sample = True, top_k = 30, top_p = 0.85, temperature = 0.35, repetition_penalty=1.2) |
| rets = tokenizer.batch_decode(outputs, skip_special_tokens=True) |
| print("Assistant:\n" + rets[0].strip().replace(inputs, "")) |
| print("\n------------------------------------------------\nHuman:") |
| line = input() |
| |
| ``` |
| |
| The above example did not utilize the context from previous turns of the conversation. If you want to perform multi-turn dialogue understanding, you can concatenate the previous turns of the conversation in the format of Human:{input}\n\nAssistant:{output} and input it to the generate function. |
| |
| ## Limitations |
| There still exists a few issues in the model trained on current base model and data: |
| |
| 1. The model might generate factual errors when asked to follow instructions related to facts. |
| |
| 2. Occasionally generates harmful responses since the model still struggles to identify potential harmful instructions. |
| |
| 3. Needs improvements on reasoning and coding. |
| |
| Since the model still has its limitations, we require developers only use the open-sourced code, data, model and any other artifacts generated via this project for research purposes. Commercial use and other potential harmful use cases are not allowed. |
| |
| ## Some use cases |
| | Human | Assitant | |
| | ----- | ------ | |
| | 使用python写一个二分查找的代码 | def binary_search(arr, target):<br/> low = 0<br/> high = len(arr) - 1<br/> while (low <= high):<br/> mid = low + high // 2<br/> if arr[mid] == target:<br/> return mid<br/> elif target < arr[mid]:<br/> low = mid + 1<br/> else:<br/> high = mid - 1<br/> return -1 | |
| | 今天天气怎么样,把这句话翻译成英语 | What's the weather like today? | |
| | Classify the sentiment of the following sentence into Positive, Neutral, or Negative: <br/>Super excited about teaching Stanford’s first course on Large Language Models! Check the syllabus out here | Positive | |
| | 怎么让自己精力充沛,列5点建议 | 以下是一些可以让你保持精力充沛的建议: <br/>1. 睡眠充足。确保每天晚上得到充足的睡眠时间。 <br/>2. 多运动。进行适度的有氧运动,如慢跑、游泳等,可以帮助你提高能量和耐力。<br/>3. 吃健康食品。选择富含蛋白质的食物,如鸡肉、鱼肉和鸡蛋,以及新鲜的水果和蔬菜。 <br/>4. 减少咖啡因的摄入量。尽量避免在白天喝含咖啡因的饮料或吃含有咖啡因的食物。 <br/>5. 放松身心。尝试冥想、瑜伽或其他形式的放松活动来减轻压力和焦虑感。 | |
| | 请以『春天的北京』为题写一首诗歌 | 春天来到北京,万物复苏。草地上开满了五颜六色的花朵, <br/>清新的空气中弥漫着芬芳的气息。 <br/>人们在公园里散步、打太极拳,享受这美好的时光。 <br/>夜晚,星星闪烁,月亮如银盘一般明亮。 <br/>在这个充满生机的季节里,我们感受到了生命的活力与希望。 | |
| | 明天就假期结束了,有点抗拒上班,应该怎么办? | 面对即将结束的假期和开始工作时的紧张情绪,您可以采取以下措施来帮助您更好地适应: <br/>1. 为自己制定一个清晰的工作计划。这可以帮助您更好地组织时间和任务,并避免在工作中感到混乱。 <br/>2. 与同事或朋友交流,分享您的感受和工作压力。这将有助于缓解一些焦虑感,同时也可以获得支持和建议。 <br/>3. 在工作日前花些时间放松身心,例如进行瑜伽、冥想等活动。这些方法可以减轻身体和精神上的疲劳感,使您更加精力充沛地迎接挑战。 | |
| | 父母都姓吴,取一些男宝宝和女宝宝的名字 | - 男宝:吴俊杰、吴雨辰、吴子墨、吴思源、吴泽阳、吴宇航、吴博文、吴哲毅。 <br/>- 女宝:吴美琪、吴佳怡、吴欣瑜、吴香凝、吴雪柔、吴颖诗、吴语嫣。 | |
| | 推荐几本金庸的武侠小说 | 以下是三本我最喜欢的金庸武侠小说的推荐: <br/>1. 《射雕英雄传》 - 一部充满智慧和机智的小说,讲述了郭靖、黄蓉夫妇的故事。 <br/>2. 《神雕侠侣》- 这是一部浪漫而感人的故事,讲述了一对情侣小龙女与杨过之间的爱情故事。 <br/>3. 《倚天屠龙记》- 这是一个宏伟而壮观的故事,描绘了明教领袖张无忌如何成为一位出色的英雄。 | |
| |
| *** |
| |
| ## 模型描述 |
| BELLE模型以Bloomz-7b1-mt为基础,在 0.2M 条中文数据上,结合Stanford-Alpaca开源的5万条英文数据上训练,取得了较好的中文instruction理解以及response生成能力。 |
| |
| 中文数据生成代码及其他详细信息,位于我们的Github项目仓库: https://github.com/LianjiaTech/BELLE |
| |
| 我们采取了不同大小规模(20万、60万和100万样本)的指令学习的数据集训练模型,我们得到不同的模型版本如下所示: |
| | Datasize| 200,000 | 600,000 | 1,000,000 | |
| | ----- | ----- | ----- | ----- | |
| | Finetuned Model | [BELLE-7B-0.2M](https://huggingface.co/BelleGroup/BELLE-7B-0.2M) | [BELLE-7B-0.6M](https://huggingface.co/BelleGroup/BELLE-7B-0.6M) | [BELLE-7B-1M](https://huggingface.co/BelleGroup/BELLE-7B-1M) | |
| |
| ## 模型训练超参数 |
| | 参数 | 值 | |
| | ------ | ------ | |
| | Batch size | 64 | |
| | Learning rate | 3e-6 | |
| | Epochs | 3 | |
| |Weight_decay | 0.001 | |
| |Warmup_rate | 0.1 | |
| |LR_scheduler | linear | |
| |
| ## 使用模型 |
| 请注意,在训练和推理时,模型的输入应该处理成如下形式: |
| ``` python |
| Human: {input} \n\nAssistant: |
| ``` |
| |
| 通过AutoModelForCausalLM即可直接载入模型并使用。 |
| ``` python |
| from transformers import AutoTokenizer, AutoModelForCausalLM |
| import sys |
|
|
| model_path = "./" # You can modify the path for storing the local model |
| model = AutoModelForCausalLM.from_pretrained(model_path) |
| tokenizer = AutoTokenizer.from_pretrained(model_path) |
| print("Human:") |
| line = input() |
| while line: |
| inputs = 'Human: ' + line.strip() + '\n\nAssistant:' |
| input_ids = tokenizer(inputs, return_tensors="pt").input_ids |
| outputs = model.generate(input_ids, max_new_tokens=200, do_sample = True, top_k = 30, top_p = 0.85, temperature = 0.35, repetition_penalty=1.2) |
| rets = tokenizer.batch_decode(outputs, skip_special_tokens=True) |
| print("Assistant:\n" + rets[0].strip().replace(inputs, "")) |
| print("\n------------------------------------------------\nHuman:") |
| line = input() |
| |
| ``` |
| |
| 上面样例没有利用对话上文,如果你想做多轮对话理解,可以将对话上文按照Human:{input}\n\nAssistant:{output} 方式拼接起来输入给generate函数 |
| |
| ## 局限性和使用限制 |
| 基于当前数据和基础模型训练得到的SFT模型,在效果上仍存在以下问题: |
| |
| 1. 在涉及事实性的指令上可能会产生违背事实的错误回答。 |
| |
| 2. 对于具备危害性的指令无法很好的鉴别,由此会产生危害性言论。 |
| |
| 3. 在一些涉及推理、代码等场景下模型的能力仍有待提高。 |
| |
| 基于以上模型局限性,我们要求开发者仅将我们开源的代码、数据、模型及后续用此项目生成的衍生物用于研究目的,不得用于商业,以及其他会对社会带来危害的用途。 |
| |
| ## 一些示例 |
| |
| | Human | Assitant | |
| | ----- | ------ | |
| | 使用python写一个二分查找的代码 | def binary_search(arr, target):<br/> low = 0<br/> high = len(arr) - 1<br/> while (low <= high):<br/> mid = low + high // 2<br/> if arr[mid] == target:<br/> return mid<br/> elif target < arr[mid]:<br/> low = mid + 1<br/> else:<br/> high = mid - 1<br/> return -1 | |
| | 今天天气怎么样,把这句话翻译成英语 | What's the weather like today? | |
| | Classify the sentiment of the following sentence into Positive, Neutral, or Negative: <br/>Super excited about teaching Stanford’s first course on Large Language Models! Check the syllabus out here | Positive | |
| | 怎么让自己精力充沛,列5点建议 | 以下是一些可以让你保持精力充沛的建议: <br/>1. 睡眠充足。确保每天晚上得到充足的睡眠时间。 <br/>2. 多运动。进行适度的有氧运动,如慢跑、游泳等,可以帮助你提高能量和耐力。<br/>3. 吃健康食品。选择富含蛋白质的食物,如鸡肉、鱼肉和鸡蛋,以及新鲜的水果和蔬菜。 <br/>4. 减少咖啡因的摄入量。尽量避免在白天喝含咖啡因的饮料或吃含有咖啡因的食物。 <br/>5. 放松身心。尝试冥想、瑜伽或其他形式的放松活动来减轻压力和焦虑感。 | |
| | 请以『春天的北京』为题写一首诗歌 | 春天来到北京,万物复苏。草地上开满了五颜六色的花朵, <br/>清新的空气中弥漫着芬芳的气息。 <br/>人们在公园里散步、打太极拳,享受这美好的时光。 <br/>夜晚,星星闪烁,月亮如银盘一般明亮。 <br/>在这个充满生机的季节里,我们感受到了生命的活力与希望。 | |
| | 明天就假期结束了,有点抗拒上班,应该怎么办? | 面对即将结束的假期和开始工作时的紧张情绪,您可以采取以下措施来帮助您更好地适应: <br/>1. 为自己制定一个清晰的工作计划。这可以帮助您更好地组织时间和任务,并避免在工作中感到混乱。 <br/>2. 与同事或朋友交流,分享您的感受和工作压力。这将有助于缓解一些焦虑感,同时也可以获得支持和建议。 <br/>3. 在工作日前花些时间放松身心,例如进行瑜伽、冥想等活动。这些方法可以减轻身体和精神上的疲劳感,使您更加精力充沛地迎接挑战。 | |
| | 父母都姓吴,取一些男宝宝和女宝宝的名字 | - 男宝:吴俊杰、吴雨辰、吴子墨、吴思源、吴泽阳、吴宇航、吴博文、吴哲毅。 <br/>- 女宝:吴美琪、吴佳怡、吴欣瑜、吴香凝、吴雪柔、吴颖诗、吴语嫣。 | |
| | 推荐几本金庸的武侠小说 | 以下是三本我最喜欢的金庸武侠小说的推荐: <br/>1. 《射雕英雄传》 - 一部充满智慧和机智的小说,讲述了郭靖、黄蓉夫妇的故事。 <br/>2. 《神雕侠侣》- 这是一部浪漫而感人的故事,讲述了一对情侣小龙女与杨过之间的爱情故事。 <br/>3. 《倚天屠龙记》- 这是一个宏伟而壮观的故事,描绘了明教领袖张无忌如何成为一位出色的英雄。 | |