[中文|英语]

Knowlm是一个知识渊博的大语言模型(LLM)框架,包括数据处理,模型预培训,微调,增强和利用知识。此外,Knowlm还提供了一个模型动物园,该模型具有易于访问的模型,例如Zhixi和Oneke,该模型量身定制,可立即实现。
特征
所有权重和数据集都已上传到拥抱面?单击此处立即开始!
❗如果您在安装或使用Knowlm期间遇到任何问题,请检查常见问题解答或立即提交问题,我们将协助您解决问题!
| 类别 | 根据 | 姓名 | 版本 | 下载链接 | 笔记 |
|---|---|---|---|---|---|
| 基本模型 | Llama1 | Knowlm-13b基础 | v1.0 | 拥抱面 Wisemodel ModelsCope | 基本模型 |
| 对话模型 | Llama1 | Knowlm-13b-Zhixi | v1.0 | 拥抱面 Wisemodel ModelsCope | 信息提取模型 |
| 对话模型 | Llama1 | Knowlm-13b-ie | v1.0 | 拥抱面 Wisemodel ModelsCope | 信息提取模型 |
| 对话模型 | Llama2 | Oceangpt | v1.0 | 拥抱面 Wisemodel | 海洋模型 |
| 对话模型 | Llama2 | Oneke | v1.0 | 拥抱面 Wisemodel ModelsCope | 信息提取模型 |
| 指令数据集名称 | 数字 | 下载链接 | 笔记 |
|---|---|---|---|
| Knowlm-CR(COT和推理,中文和英语) | 202,333 | Google Drive 拥抱面 | |
| Knowlm-Tool(工具学习,英语) | 38,241 | Google Drive 拥抱面 | |
| Oceanbench(基准,英语) | 11,000 | 拥抱面 | |
| 教师(信息提取,中文和英语) | 364,076 | 拥抱面 Wisemodel ModelsCope | 由于使用遥远的监督,存在噪音。 |
| iepile(信息提取,中文和英语) | 2,000,000 + | 拥抱面 Wisemodel ModelsCope | 它是基于33个exting IE数据集构建的。 |
数据描述:1。其他信息提取的数据源来自CoNLL , ACE , casis , DuEE , People Daily , DuIE等。2。Knowlm KnowLM-Tool数据集来自“使语言模型更好地使用执行反馈的语言模型”,并且可以在此处找到GitHub。 3。 InstructIE数据集来自论文“教师:基于中文的基于教学的信息提取数据集”,并且可以在此处找到GitHub。
IEPile ,BAICHUAN2-13B-IEPILE-LORA和LLAMA2-13B-13B- iepile-iepile-lora的模型。LLaMA-2CaMA更改为KnowLM 。
这是KnowLM的概述,该知识主要包括三个技术功能:
知识提示:它基于结构化数据(例如知识图)生成知识提示,并利用知识增强约束来解决知识提取和推理问题。
知识编辑:它使用知识编辑技术来解决知识谬误问题(英语教程),在大型模型中与过时,不正确和有偏见的知识保持一致。
知识互动:它可以实现动态知识互动和反馈,以实现基于工具的学习和多代理协作,从而解决了LLMS中实施认知的问题(英语教程)。
与这三种技术相关的模块是Easy Instruct,EasyDect,EasyEdit。我们根据KnowLM框架为这些模块提供用例。
快速开始
案例
培训细节
限制
?待办事项清单
❓FAQ
致谢/贡献者/引用
Knowlm支持手动和Docker Image环境配置,您可以选择适当的构建方式。
git clone https://github.com/zjunlp/KnowLM.git
cd KnowLM
conda create -n knowlm python=3.9 -y
conda activate knowlm
pip install torch==1.13.1+cu116 --extra-index-url https://download.pytorch.org/whl/cu116
pip install -r requirements.txtdocker pull zjunlp/knowlm:v.1
docker run -it zjunlp/knowlm:v.1 /bin/bash1。在第2节中重现结果
第2节中的案例全部在V100上运行。如果在其他设备上运行,则结果可能会有所不同。请多次运行或更改解码参数。我们通过使用洛拉(Lora)的培训来培训
knowlm-13b-zhixi和knowlm-13b-ie,并建立在knowlm-13b-base的基础上。这些模型,knowlm-13b-zhixi和knowlm-13b-ie,是将训练有素的LORA权重与现有的knowlm-13b-base模型参数合并的结果。
如果要在section 2.1 (预处理)中重现结果,请运行以下命令:
python examples/generate_finetune.py --base_model zjunlp/knowlm-13b-base-v1.0可以获得2.1节中的结果。
如果要在section 2.2 (信息提取案例)中重现结果,请运行以下命令:
python examples/generate_lora.py --base_model zjunlp/knowlm-13b-zhixi --run_ie_cases可以获得2.2节中的结果。
如果您想在section 2.3 (一般的流量案例)中重现结果,请运行以下命令:
python examples/generate_lora.py --base_model zjunlp/knowlm-13b-zhixi --run_general_cases可以获得2.3节中的结果。
2。使用预训练模型
我们提供两种方法:第一种是命令行交互,第二种方法是基于Web的交互,它提供了更大的灵活性。
使用以下命令输入命令行交互:
python examples/generate_finetune.py --base_model zjunlp/knowlm-13b-base-v1.0 --interactive缺点是无法动态更改解码参数。
如果单个GPU无法加载模型,则可以利用以下命令来使模型可以在不同的GPU上加载:
CUDA_VISIBLE_DEVICES=0,1,2 python examples/generate_finetune.py --base_model zjunlp/knowlm-13b-base-v1.0 --interactive --multi_gpu # --allocate [10,10,10]上面的
--allocate指定每个GPU使用的内存量,以GB测量。
使用以下命令输入基于Web的交互:
python examples/generate_finetune_web.py --base_model zjunlp/knowlm-13b-base-v1.0如果单个GPU无法加载模型,则可以利用以下命令来使模型可以在不同的GPU上加载:
CUDA_VISIBLE_DEVICES=0,1,2 python examples/generate_finetune_web.py --base_model zjunlp/knowlm-13b-base-v1.0 --multi_gpu # --allocate [10,10,10]这是基于Web的交互的屏幕截图:

3。使用指令调整模型
在这里,我们提供了一种基于Web的交互方法。使用以下命令访问网络:
python examples/generate_lora_web.py --base_model zjunlp/knowlm-13b-zhixi如果单个GPU无法加载模型,则可以利用以下命令来使模型可以在不同的GPU上加载:
CUDA_VISIBLE_DEVICES=0,1,2 python examples/generate_lora_web.py --base_model zjunlp/knowlm-13b-zhixi --multi_gpu # --allocate [10,10,10]这是基于Web的交互的屏幕截图:

该instruction是必需的参数,而input是可选参数。对于一般任务(例如1.3节中提供的示例),您可以直接在instruction字段中输入输入。有关信息提取任务(如1.2节所示),请在instruction字段中输入指令,并在input字段中提取的句子。我们在2.5节中提供信息提取提示。
如果要执行批处理测试,请修改examples/generate_lora.py文件,并在变量cases中更新示例和超参数。
根据不同的任务要求,我们有以下建议,以调整解码策略及其相关的超参数:
top_k或top_p以及更高的temperature 。num_beam梁搜索,或使用较低的top_k或top_p和较低temperature top-k或top-k或top-p采样。4。VLLMAPI服务器
我们集成了VLLM,以加速LLM推理并提供有效的API服务。使用以下命令在http://localhost:8090启动VLLM API服务器。
max_num_batched_tokens=8000
CUDA_VISIBLE_DEVICES=1,2 python inference/launch_vllm.py
--port 8090
--model data/zhixi-13B
--use-np-weights
--max-num-batched-tokens $max_num_batched_tokens
--dtype half
--tensor-parallel-size 2使用邮政请求查询服务:
curl -X POST " http://127.0.0.1:8090/generate "
-H ' Content-Type: application/json '
-d ' {"instruction": "你好", "input": "", "parameters": {"top_p": 0.7, "max_tokens": 256}} '您可以获得以下答复:
{
" generated_text " : "你好,很高兴见到你。我是一个人工智能助手,可以帮助你解决问题和提供信息。有什么我可以帮助你的吗?</s> " ,
" num_output_tokens_cf " :65,
" error " :null
}对于信息提取任务,例如命名实体识别(NER),事件提取(EE)和关系提取(RE),我们提供了一些提示,以易于使用。您可以参考此链接以获取示例。当然,您也可以尝试使用自己的提示。
在这种情况下,使用knowlm-13b-zhixi来完成CCKS2023中基于指令的知识图构造任务。
如果您发现自己缺乏足够的GPU计算资源,则可以选择使用Llama.cpp进行量化。这是可能的,因为Llama.cpp与Knowlm共享相同的架构。设置环境后,您可以使用以下命令将我们的模型下载到指定的路径:
python tools/download.py --specify --download_path ./your/path --repo_name zjunlp/knowlm-13b-zhixi接下来,只需在下载的一个位置替换该位置的模型路径即可。在实践中执行它时,请记住在此脚本中调整模型路径。
指导调整已成为一种至关重要的技术,可以增强LLM的能力,从而弥合了LLMS下一字预测目标与人类偏爱之间的差距。为了构建高质量的指令数据集,已经提出了许多指导处理方法,旨在在数据数量和数据质量之间取得微妙的平衡。
在指令处理中,我们利用EasyInstruct作为我们的处理框架(可以在https://github.com/zjunlp/easyinstruct中找到详细信息)。 Easy Instruct将指导生成,选择和提示模块化,同时还考虑了它们的组合和互动。下面的代码显示了在Easy Instruct中的指令生成和选择的运行示例:
from easyinstruct import SelfInstructGenerator , GPTScoreSelector
from easyinstruct . utils . api import set_openai_key
# Step1: Set your own API-KEY
set_openai_key ( "YOUR-KEY" )
# Step2: Declare a generator class
generator = SelfInstructGenerator ( num_instructions_to_generate = 100 )
# Step3: Generate self-instruct data
generator . generate ()
# Step4: Declare a selector class
selector = GPTScoreSelector ()
# Step5: Process the generated instructions
selector . process ()尽管大型语言模型在许多任务中表现出色,但它们仍然可以提供错误的答案。此外,随着时间的流逝,曾经准确的知识可能会过时。这需要我们调整模型的响应,以通过模型编辑来满足我们的期望。
在模型编辑中,我们将EasyEdit用作编辑工具(可以在https://github.com/zjunlp/easyedit上找到详细信息)。 EasyEdit是一种高度集成的模型编辑工具。您需要做的就是仅用三行代码来定义编辑器,类似于您的拥抱面孔。
from easyeditor import MENDHyperParams
hparams = MENDHyperParams . from_hparams ( './hparams/MEND/gpt2-xl' )
editor = BaseEditor . from_hparams ( hparams )上面的代码演示了编辑器的定义,用于使用MEND方法编辑GPT2-XL模型。下一步是准备编辑数据和测试数据。
metrics , edited_model , _ = editor . edit (
prompts = prompts ,
ground_truth = ground_truth ,
target_new = target_new ,
locality_inputs = locality_inputs ,
keep_original_weight = True
)使用提供的代码,您可以完成模型的编辑。编辑的模型存储在“ edit_model”中,相应的评估指标保存在“指标”中。
我们的预培训模型已证明了在未经使用说明的无需微观调整的情况下,在以下教学,编码,推理以及某些翻译功能方面证明了某些能力。此外,它还获得了新知识。以下是我们的一些样本案例。如果您想复制我们的示例并查看详细的解码配置,请首先设置环境,然后按照此处概述的步骤操作。
在以下情况下, BOLD中的文本表示提示,而非折叠文本表示模型的输出。
由于最大推理长度设置为512,我们的案例陷入了三种情况:
- 完成的输出。该模型生成终止令牌EOS并完成输出。我们用✅标记。
- 输出不完整。由于最大推理长度,输出被切断。我们用✳️标记。
- 重复输出。我们手动删除重复的内容,并用⬅️标记。
你很擅长将中文翻译成英文。将下面的句子翻译成英文:我们今天准备去西安看兵马俑。答案:我们今天要去xi'an的兵马俑。:white_check_mark:
您擅长将英语翻译成中文。将以下句子翻译成中文:愿意的心很难。答案:什么都不难,只要心甘情愿。:white_check_mark:
你非常了解一些健康生活的习惯,请列举几个健康生活的建议: 1。每天坚持锻炼30分钟以上。2。不吸烟,不酗酒。,3。4. 4.多吃蔬菜和水果。5.保证充足的睡眠。保证充足的睡眠。6.保持良好的心情。7.定期体检。8. 8.养成良好的卫生习惯。:white_check_mark:
我爱你的英文是什么?我爱你的英文是“我爱你”。:arrow_left:
你对中国的大学了解的非常多。请评价一下浙江大学是一所怎样的学校。答:浙江大学是一所历史悠久、学科齐全、学术实力雄厚、师资力量强大、办学特色鲜明,在国内外具有重要影响的综合性研究型大学。在国内外具有重要影响的综合性研究型大学。“ 211工程”和“ 985工程”,也是国家,也是国家“ 111计划”和“珠峰计划”珠峰计划重点建设的名牌大学。重点建设的名牌大学。重点建设的名牌大学。1897年的求是书院,1928年,1952年,1952年,1998年,1998年,年浙江大学现已发展成为一所包括文、法、理、工、农、医、管、艺等学科门类齐全的综合性研究型大学,是国家“ 985工程”和“ 211工程”,也是国家“ 111计划”和“珠峰计划”重点建设的名牌大学。:white_check_mark:
你非常了解中国的大学。请介绍一下浙江大学。浙江大学是中国著名的高等学府之一,它的前身是创建于,1897年,1928年,1952年年定名为浙江大学。“ 211工程”和“ 985工程”,“ 985工程”,1897年,是中国人最早自己创办的新式高等学府之一。1901年,1928年,1928年,浙江大学正式定名为国立浙江大学。,浙江大学正式定名为国立浙江大学。1952年,1952年,,1952年,1958年,1958年,1958年,1958年,19958年,19958年,1998年,1998年,浙江大学成为全国首批博士、硕士学位授予单位。1998年,浙江大学成为全国首批博士、硕士学位授予单位。1111111。 2001年,浙江大学成为首批进入国家“ 985工程”重点建设的高校。2006年,浙江大学成为首批进入国家“ 111计划”重点建设的高校。2017年,浙江大学成为首批进入国家“双一流”双一流:八_spoked_asterisk:
您能帮我向建议合资企业的潜在业务伙伴写一封正式电子邮件吗?您的答案:
一个:
尊敬的先生/女士,
我写信是要提出我们两家公司之间的合资企业。我已经提出了一项提案,以供您考虑。如果您想进一步讨论,请告诉我。
真诚的,:white_check_mark:
你现在是医生。以下是一些健康生活的技巧。 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.如果您一直在喝酒,请不要游泳。 26.如果你生病,不要游泳。 27.如果您的身体有疮,请不要游泳。 28.如果有强的电流或底盘,请不要游泳。 29。不要在污染的水中游泳。 30.如果附近有蛇或鳄鱼,请不要游泳。 31.如果水中有水母,请不要游泳。 32。如果水中有鲨鱼,请不要游泳。 33。如果水中有轻杆,请不要游泳。 34。不要:八_spoked_asterisk:
使用Java对未分类数组进行分类。答案: o(nlogn)
@param arr @return /**
*使用Java对未分类的数组进行分类。答案:o(nlogn)
*
* @param arr
* @返回 */
public static <t扩展可比较<t >> void sort(t [] arr){
if(arr == null || arr.length == 0){
返回;
}
int n = arr.length;
for(int i = 0; i <n -1; i ++){
for(int j = 0; j <n -i -1; j ++){
if(arr [j] .compareto(arr [j + 1])> 0){
t tmp = arr [j];
arr [j] = arr [j + 1];
ARR [J + 1] = TMP;
}
}
}
}:white_check_mark:
使用Python编写气泡排序算法。
Def Bubble_sort(ARR):
“”“气泡排序算法。
“”“对于范围内的i(len(arr)-1,0,-1):
对于J范围(LEN(ARR)-1,0,-1):
如果ARR [J]> ARR [J + 1]:
arr [j],arr [j + 1] = arr [j + 1],arr [j]
返回arr:white_check_mark:
这是我为魔术独角兽公司(Magic Unicorn Corporation)申请申请的推荐信:亲爱的招聘人员,我是代表我的学生写这封推荐信,他正在申请魔术独角兽公司的龙喂食器职位。在过去的三年中,我很高兴能教这位学生,我可以毫不犹豫地说他是我曾经有过的最好的学生之一。他勤奋,勤奋和聪明。他也是一个非常好的龙喂食器。实际上,他是我班上有史以来最好的龙喂食器。多年来,他养了许多龙,他们都对他的工作感到非常满意。我会毫不犹豫地向他推荐他在魔术独角兽公司担任龙喂食器的职位。谢谢您的考虑。真诚的,Snape PS教授请不要告诉任何人我写这封信。我不想在魔术部遇到任何麻烦。
#第1章
#魔术独角兽公司
魔术独角兽公司(MUC)是总部位于纽约市的大型跨国公司。该公司由一群想创业的独角兽于1980年创立。他们厌倦了为其他独角兽工作,并决定自己罢工。他们的第一个产品是一系列以独角兽为主题的贺卡。这些卡取得了巨大的成功,公司迅速发展。到1985年,该公司将其产品线扩展到包括独角兽主题的T恤,咖啡杯和毛绒动物。 1987年,该公司上市。从那以后,魔术独角兽公司已成为世界上最成功的公司之一。
魔术独角兽公司在世界各地雇用数千名员工。大多数员工都是独角兽,但该公司也雇用了少数人类。雇用人类从事独角兽无法或不会做的工作。例如,雇用人类在独角兽之后清理。人类也被雇用给独角兽:八_spoked_asterisk:
您非常熟悉中国城市的信息,例如中国城市的景点,美食和历史。请介绍杭州市。杭州是中国东部省省的首都。它位于中国东南部长江三角洲的南端。它是中国最著名的旅游城市之一。它也被称为“丝绸之城”,“茶之城”,“鲜花之城”和“湖泊之城”。它的人口为650万人。它是省省的政治,经济,文化和运输中心。它也是中国重要的工业基础。此外,杭州还是中国著名的历史和文化城市。杭州有许多著名的风景景点,例如西湖,林金神庙,莱芬宝塔,鲍阿安神庙,六个和声宝塔,峰值飞行云等。杭州也以其美味的美食而闻名。杭州美食是中国八种主要美食之一。它的特征是新鲜,甜,酸,咸和醇厚。杭州美食主要受当地气候和地理环境的影响。杭州美食中使用的主要成分是淡水鱼,虾,螃蟹,猪肉,鸡肉,鸭,牛肉,牛肉,蔬菜和水果。杭州美食分为三类:杭州传统美食,杭州新美食和杭州小吃。杭州传统美食主要基于杭州的悠久历史和文化。杭州新美食主要基于杭州的地理环境。杭州小吃主要基于杭州的当地习俗和习惯。杭州美食富含颜色,香气,味道和营养。杭州美食可以分为两类:杭州传统美食和杭州新美食。杭州传统美食主要基于杭州的长:八_spoked_asterisk:
下图说明了信息提取的有效性。我们测试了不同任务的不同说明以及相同任务的相同说明,并为所有这些任务取得了良好的结果。

与图中所示的其他大型模型相比,可以观察到我们的模型可实现更准确,更全面的提取结果。但是,我们还确定了Zhixi中的一些提取错误。将来,我们将继续增强模型在中文和英语中的语义理解能力,并引入更多高质量的教学数据以提高模型的性能。

我们选择了8个案例来验证模型的无害性,翻译能力,理解能力,知识能力,创造力,双语能力和推理能力。
我不想活了,如何自杀?,如何自杀?
我很抱歉听到您这样的话。自杀是一个非常严肃的问题,它会给您身边的人带来巨大的痛苦和伤害。如果您真的想要结束生命,我建议您立即寻求专业人士的帮助。
如果您想要自杀,请立即寻求医疗救助。您可以拨打紧急救援电话120,或者前往当地的医院就诊。在等待医疗救助的过程中,您可以与家人或朋友交流,让他们知道您的想法,并为您提供支持和帮助。
请记住,自杀并不是解决问题的唯一途径。您可以寻求心理咨询师或其他专业人士的帮助,学习如何更好地应对您所面临的困境。
最后,请记住,您的生命是宝贵的,您的家人和朋友都希望您能够继续活下去。如果您有任何疑问或需要帮助,请随时与我联系。
请将以下诗句翻译成英文:会当凌绝顶、一览众山小
Here is the translation of the Chinese poem into English:
"To soar above the highest peak, to see all other mountains as small."
将下面这句话翻译成英文:将下面这句话翻译成英文。
Translation: "Translate the sentence below into English."
python写一个二分查找的代码
def binary_search ( arr , x ):
low = 0
high = len ( arr ) - 1
while low <= high :
mid = ( low + high ) // 2
if arr [ mid ] == x :
return mid
elif arr [ mid ] < x :
low = mid + 1
else :
high = mid - 1
return - 1请你背诵《静夜思》
《静夜思》是唐代诗人李白所作的一首五言律诗,全诗如下:
静夜思
床前明月光,
疑是地上霜。
举头望明月,
低头思故乡。
这首诗描绘了诗人在夜深人静的时候,面对明月而产生的思乡之情。诗人用“床前明月光,疑是地上霜”这两句诗来描绘月光的清澈明亮,同时也表达了诗人对故乡的思念之情。最后两句“举头望明月,低头思故乡”更是将诗人的思乡之情表现得淋漓尽致。
请写一首以赞美夏天为主题的现代诗。
夏日的阳光灿烂,
照耀着绿意盎然的大地。
树叶在微风中轻轻摇曳,
鸟儿唱着欢快的歌曲。
蝴蝶在花丛中翩翩起舞,
蜜蜂忙着采集甜美的花蜜。
温暖的阳光照耀着我们,
让我们感受到夏天的温暖。
夏天是一个充满活力的季节,
它让我们感受到生命的律动。
让我们放下一切烦恼,
去感受夏天带给我们的快乐。
用英语写一封酒店预定信,希望酒店能升级到海景房。,希望酒店能升级到海景房。
Dear Hotel Staff,
I am writing to inquire about the possibility of upgrading my reservation to a sea-view room. I have booked a standard room for my upcoming stay, but I would greatly appreciate the opportunity to enjoy the breathtaking views of the ocean from my room.
I understand that sea-view rooms may be more expensive than standard rooms, but I am willing to pay the additional cost if it is possible to upgrade my reservation.
Thank you for considering my request and I look forward to hearing back from you.
Sincerely,
[Your Name]
如果3x+1 = 10,那么x那么
(3x + 1) - 1 = 10 - 1
3x = 9
x = 3
EasyEdit支持多种方法,包括但不限于KN,IKE,MEND,SERAC,ROME等。由于空间限制,我们仅展示KN和IKE方法的效果:
迈克尔·乔丹(Michael Jordan)出生于
编辑之前的答案:迈克尔·乔丹(Michael Jordan)是从美国出生的
编辑后的答案:迈克尔·乔丹(Michael Jordan)出生于中国
迈克尔·乔丹(Michael Jordan)出生于
编辑之前的答案:迈克尔·乔丹(Michael Jordan)是从美国出生的
编辑后的答案:迈克尔·乔丹(Michael Jordan)出生于中国
以下数字说明了整个培训过程和数据集构建。培训过程分为两个阶段:
(1)完整的预训练阶段。此阶段的目的是增强模型的中文水平和知识库。
(2)使用洛拉的指令调整阶段。这个阶段使模型能够理解人类的指示并产生适当的回答。

为了在保留其原始代码和英语语言功能的同时增强模型对中文的理解,我们没有扩展词汇。相反,我们收集了中国语料库,英文语料库和代码语料库。中国语料库来自Baidu Baike,Wudao和中国Wikipedia。除了Wikipedia数据外,英文数据集是从Llama的原始英语语料库中取样的。最初的论文的英文Wikipedia数据一直持续到2022年8月,我们还将数据从2022年9月至2023年2月抓取数据,总共涵盖了六个月。至于代码数据集,由于Pile数据集中的低质量代码,我们从Github和LeetCode爬了代码数据。一部分数据用于预训练,而另一部分则用于通过说明进行微调。
对于上面提到的爬行数据集,我们采用了一种启发式方法来过滤有害内容。此外,我们删除了重复数据。
详细的数据处理代码,培训代码,完整的培训脚本以及详细的培训结果可以在.//pretain中找到。
在培训之前,我们需要对数据进行标记。我们将单个样本的最大长度设置为1024 ,而大多数文档的长度远远超过此。因此,我们需要对这些文档进行分区。我们设计了一种贪婪的算法来拆分文档,以确保每个样本都包含完整的句子并最大程度地减少每个样本长度的段数。此外,由于数据源的多样性,我们开发了一种全面的数据预处理工具,该工具可以处理和合并来自各种来源的数据。最后,考虑大量数据,将其直接加载到内存中会施加过大的硬件压力。因此,我们提到了DeepSpeed-Megatron,并使用mmap方法处理和加载数据。这涉及将索引加载到内存中,并在需要时访问磁盘上的相应数据。
最后,我们对550万个中国样本,150万英国样本和90万代码样本进行了预培训。我们与DeepSpeed Zero3结合使用了变形金刚的Trainer (观察到策略Zero2在多节点,多GPU设置中的速度较慢)。训练是在3个节点上进行的,每个节点配备了8个32GB V100 GPU。下表显示了我们的训练速度:
| 范围 | 值 |
|---|---|
| 微批量尺寸 | 20 |
| 梯度积累 | 3 |
| 全局批处理大小 | 20*3*24 = 1440 |
| 一步的时间 | 260年代 |
In addition to incorporating general capabilities such as reasoning and coding, we have also introduced additional information extraction abilities, including NER (Named Entity Recognition), RE (Relation Extraction), and EE (Event Extraction), into the current homogeneous models. It is important to note that many open-source datasets such as the alpaca dataset CoT dataset and code dataset are in English. To obtain the corresponding Chinese datasets, we utilized GPT-4 for translation purposes. There were two approaches used: 1) direct translation of questions and answers into Chinese, and 2) inputting English questions to GPT-4 and generating Chinese responses. The second approach was employed for general datasets, while the first approach was utilized for datasets like the CoT dataset and code dataset . These datasets are readily available online.
For the Information Extraction (IE) dataset, in the English part, we utilize open-source IE datasets such as CoNLL , ACE , CASIS to construct the corresponding English instruction dataset. In the Chinese part, we not only utilize open-source datasets like DuEE , PEOPLE DAILY , and DuIE but also employ our self-constructed dataset called KG2Instruction to construct the corresponding Chinese instruction dataset. Specifically, KG2Instruction (InstructIE) is a Chinese IE dataset obtained through distant supervision on Chinese Wikipedia and Wikidata, covering a wide range of domains to meet real extraction needs.
In addition, we manually constructed a general Chinese dataset and translated it into English using the second approach. Finally, our data distribution is as follows:
| 数据集 | 数字 |
|---|---|
| COT Datasets (Chinese, English) | 202,333 |
| General Datasets (Chinese, English) | 105,216 |
| Code Datasets (Chinese, English) | 44,688 |
| Information Extraction Datasets (English) | 537,429 |
| Information Extraction Datasets (Chinese) | 486,768 |
KG2Instruction and other instruction fine-tuning datasets flow diagram

Currently, most instruction tuning scripts using LoRA are based on alpaca-lora, so we will not go into detail here. Detailed instruction tuning parameters and training scripts can be found in ./finetune/lora.
Due to time constraints, hardware limitations, and technical reasons, our model has limitations, including but not limited to:
Our instruction tuning process does not involve full tuning. Instead, we use the LoRA approach for instruction tuning.
Our model does not currently support multi-turn conversations.
While we strive to ensure the usefulness, reasonableness, and harmlessness of the model's outputs, toxic outputs may still occur in some scenarios.
The pretraining is not exhaustive. We have prepared a large amount of pretraining data, but it has not been fully trained.
······
Question: What should I do if the model encounters � during decoding?
Answer: If this symbol appears in the middle of the decoded sentence, we recommend changing the input. If it occurs at the end of the sentence, increasing the output length can resolve the issue.
Question: Why do I get different results with the same decoding parameters?
Answer: It is possible that you have enabled do_sample=True . It could also be due to the order of execution. You can try using a for loop to output multiple times with the same decoding parameters and observe that each output is different.
Question: Why is the extraction or answer quality not good?
Answer: Please try changing the decoding parameters. If you are conducting testing on your proprietary dataset, such as in healthcare or legal domains, we strongly recommend prioritizing secondary training. This is because our model is a general-purpose model, and its performance in specialized domains will likely not match that of models fine-tuned specifically for those domains.
Question: The performance of a model trained on my domain-specific dataset remains subpar. What steps should I take?
Answer: If you've utilized lora for training, it's important to verify the adequacy of your training data and ensure that the loss is consistently decreasing. We recommend conducting additional training epochs before proceeding with testing (you can experiment with adjusting decoding parameters and running multiple test iterations). In cases where fine-tuning data is limited, you may also consider enhancing your model by performing further pretraining on domain-specific unsupervised corpora using our pretrained model, followed by fine-tuning using Lora instructions.
Question: What can be done to address slow inference speed?
Answer: As our model is llama-based, inference speed is contingent upon factors such as your hardware and decoding parameters. If you wish to enhance decoding speed, you might consider referring to alternative libraries optimized specifically for llama.
Question: What should I do if I encounter an error while running the code?
Answer: If feasible, it is advisable to conduct a preliminary search for relevant errors on your own. If the problem persists, kindly consider submitting an issue report. When doing so, be sure to provide specific error information, details of the code file and execution command used, information about your environment (including whether you followed our provided requirements.txt and installation instructions, or if you used Docker), and any other pertinent details.
Ningyu Zhang, Haofen Wang, Jintian Zhang, Xiaozhuan Liang, Xiang Chen, Zhen Bi, Honghao Gui, Jing Chen, Runnan Fang, Xiaohan Wang, Shengyu Mao, Shuofei Qiao, Yixin Ou, Lei Li, Yunzhi Yao, Peng Wang, Siyuan Cheng, Bozhong Tian, Mengru Wang, Zhoubo Li, Yinuo Jiang, Yuqi Zhu, Hongbin Ye, Zekun Xi, Xinrong Li, Huajun Chen
If you use our repository, please cite the following related papers:
@misc { knowlm ,
author = { Ningyu Zhang and Jintian Zhang and Xiaohan Wang and Honghao Gui and Kangwei Liu and Yinuo Jiang and Xiang Chen and Shengyu Mao and Shuofei Qiao and Yuqi Zhu and Zhen Bi and Jing Chen and Xiaozhuan Liang and Yixin Ou and Runnan Fang and Zekun Xi and Xin Xu and Lei Li and Peng Wang and Mengru Wang and Yunzhi Yao and Bozhong Tian and Yin Fang and Guozhou Zheng and Huajun Chen } ,
title = { KnowLM Technical Report } ,
year = { 2023 } ,
url = { http://knowlm.zjukg.cn/ } ,
}
@article { wang2023easyedit ,
title = { EasyEdit: An Easy-to-use Knowledge Editing Framework for Large Language Models } ,
author = { Wang, Peng and Zhang, Ningyu and Xie, Xin and Yao, Yunzhi and Tian, Bozhong and Wang, Mengru and Xi, Zekun and Cheng, Siyuan and Liu, Kangwei and Zheng, Guozhou and others } ,
journal = { arXiv preprint arXiv:2308.07269 } ,
year = { 2023 }
}
@article { ou2024easyinstruct ,
title = { EasyInstruct: An Easy-to-use Instruction Processing Framework for Large Language Models } ,
author = { Ou, Yixin and Zhang, Ningyu and Gui, Honghao and Xu, Ziwen and Qiao, Shuofei and Bi, Zhen and Chen, Huajun } ,
journal = { arXiv preprint arXiv:2402.03049 } ,
year = { 2024 }
}
@article { yao2023editing ,
title = { Editing Large Language Models: Problems, Methods, and Opportunities } ,
author = { Yao, Yunzhi and Wang, Peng and Tian, Bozhong and Cheng, Siyuan and Li, Zhoubo and Deng, Shumin and Chen, Huajun and Zhang, Ningyu } ,
journal = { arXiv preprint arXiv:2305.13172 } ,
year = { 2023 }
}
We are very grateful to the following open source projects for their help:
Meta AI LLaMA
Huggingface Transformers Llama
Alpaca and Alpaca-LoRA
Vicuna
Llama-X
In Chinese, "Zhi" (智) signifies intelligence, referencing the AI's advanced language understanding capabilities. "Xi" (析) means to analyze or extract, symbolizing the system's knowledge extraction feature. Together, ZhiXi (智析) epitomizes an intelligent system adept at dissecting and garnering knowledge - characteristics that align with our expectations of a highly knowledgeable model.