模型简介
模型特点
模型能力
使用案例
🚀 dolly-v2-7b模型卡片
dolly-v2-7b
是Databricks在其机器学习平台上训练的一个遵循指令的大语言模型,可用于商业用途。该模型基于 pythia-6.9b
,在约15000条指令/响应微调记录上进行训练。虽然它并非最先进的模型,但在遵循指令方面表现出了令人惊讶的高质量。
🚀 快速开始
环境准备
要在配备GPU的机器上使用 transformers
库调用该模型,首先要确保安装了 transformers
和 accelerate
库。在Databricks笔记本中,可以运行以下命令:
%pip install "accelerate>=0.16.0,<1" "transformers[torch]>=4.28.1,<5" "torch>=1.13.1,<2"
加载指令遵循管道
可以使用 pipeline
函数加载指令遵循管道,示例如下。这里会加载模型仓库中的自定义 InstructionTextGenerationPipeline
,因此需要设置 trust_remote_code=True
。如果支持 torch.bfloat16
类型,建议设置该参数以减少内存使用,且这似乎不会影响输出质量。如果内存充足,也可以不设置该参数。
import torch
from transformers import pipeline
generate_text = pipeline(model="databricks/dolly-v2-7b", torch_dtype=torch.bfloat16, trust_remote_code=True, device_map="auto")
使用管道回答指令
加载完成后,就可以使用管道回答指令:
res = generate_text("Explain to me the difference between nuclear fission and fusion.")
print(res[0]["generated_text"])
不使用 trust_remote_code=True
的方法
如果不想使用 trust_remote_code=True
,可以下载 instruct_pipeline.py,将其与笔记本放在同一目录下,然后根据加载的模型和分词器自行构建管道:
import torch
from instruct_pipeline import InstructionTextGenerationPipeline
from transformers import AutoModelForCausalLM, AutoTokenizer
tokenizer = AutoTokenizer.from_pretrained("databricks/dolly-v2-7b", padding_side="left")
model = AutoModelForCausalLM.from_pretrained("databricks/dolly-v2-7b", device_map="auto", torch_dtype=torch.bfloat16)
generate_text = InstructionTextGenerationPipeline(model=model, tokenizer=tokenizer)
LangChain使用方法
要在LangChain中使用该管道,必须设置 return_full_text=True
,因为LangChain期望返回完整文本,而管道默认只返回新生成的文本。
import torch
from transformers import pipeline
generate_text = pipeline(model="databricks/dolly-v2-7b", torch_dtype=torch.bfloat16,
trust_remote_code=True, device_map="auto", return_full_text=True)
可以创建只包含指令或包含指令和上下文的提示:
from langchain import PromptTemplate, LLMChain
from langchain.llms import HuggingFacePipeline
# 无输入的指令模板
prompt = PromptTemplate(
input_variables=["instruction"],
template="{instruction}")
# 包含输入的指令模板
prompt_with_context = PromptTemplate(
input_variables=["instruction", "context"],
template="{instruction}\n\nInput:\n{context}")
hf_pipeline = HuggingFacePipeline(pipeline=generate_text)
llm_chain = LLMChain(llm=hf_pipeline, prompt=prompt)
llm_context_chain = LLMChain(llm=hf_pipeline, prompt=prompt_with_context)
简单指令预测示例
print(llm_chain.predict(instruction="Explain to me the difference between nuclear fission and fusion.").lstrip())
包含上下文的指令预测示例
context = """George Washington (February 22, 1732[b] - December 14, 1799) was an American military officer, statesman,
and Founding Father who served as the first president of the United States from 1789 to 1797."""
print(llm_context_chain.predict(instruction="When was George Washington president?", context=context).lstrip())
✨ 主要特性
- 商业可用:
dolly-v2-7b
模型获得了商业使用许可,可用于商业场景。 - 指令遵循:基于
pythia-6.9b
模型,在约15000条指令/响应微调记录上进行训练,能较好地遵循指令。 - 多模型规模可选:除了
dolly-v2-7b
,还有 dolly-v2-12b 和 dolly-v2-3b 等不同参数规模的模型可供选择。
📚 详细文档
模型概述
dolly-v2-7b
是由 Databricks 创建的一个具有69亿参数的因果语言模型。它基于 EleutherAI 的 Pythia-6.9b 模型,并在 约15000条指令语料库 上进行了微调。该语料库由Databricks员工生成,并在宽松的许可协议(CC - BY - SA)下发布。
已知局限性
性能局限性
dolly-v2-7b
并非最先进的生成式语言模型,目前正在进行定量基准测试,它的设计目标并非与更现代的模型架构或在更大预训练语料库上训练的模型竞争。该模型在处理语法复杂的提示、编程问题、数学运算、事实错误、日期和时间、开放式问答、幻觉、枚举特定长度的列表、风格模仿、幽默表达等方面存在困难。此外,它不具备原始模型中的一些能力,如格式良好的信件写作。
数据集局限性
- The Pile:GPT - J的预训练语料库主要从公共互联网收集内容,和大多数网络规模的数据集一样,其中包含许多用户可能认为令人反感的内容。因此,该模型可能会反映这些缺点,在明确要求生成令人反感的内容时可能会明显表现出来,有时也会以微妙的方式体现,如存在有偏见或有害的隐含关联。
databricks-dolly-15k
:dolly-v2-7b
进行指令微调的训练数据是由Databricks员工在2023年3月至4月期间生成的自然语言指令,其中包括来自维基百科的段落,作为封闭式问答和摘要等指令类别的参考段落。据了解,该数据集中不包含淫秽内容、知识产权或非公众人物的个人身份信息,但可能包含拼写错误和事实错误。该数据集也可能反映维基百科中的偏见,并且可能反映了Databricks员工的兴趣和语义选择,而这一群体并不能代表全球广大人口。
Databricks致力于持续的研发工作,以开发有益、诚实和无害的人工智能技术,充分发挥所有个人和组织的潜力。
基准指标
以下是各种模型在 EleutherAI LLM评估工具 上的基准性能表现,模型结果按几何平均值排序,以产生一个清晰的顺序。如前文所述,这些结果表明 dolly-v2-7b
并非最先进的模型,实际上在某些评估基准中表现不如 dolly-v1-6b
。我们认为这归因于底层微调数据集的组成和规模,但要对这些差异的来源做出有力的说明,还需要进一步研究。
模型 | 开放式问答 | 简单ARC | Winogrande | Hellaswag | 挑战性ARC | PIQA | BoolQ | 几何平均值 |
---|---|---|---|---|---|---|---|---|
EleutherAI/pythia - 2.8b | 0.348 | 0.585859 | 0.589582 | 0.591217 | 0.323379 | 0.73395 | 0.638226 | 0.523431 |
EleutherAI/pythia - 6.9b | 0.368 | 0.604798 | 0.608524 | 0.631548 | 0.343857 | 0.761153 | 0.6263 | 0.543567 |
databricks/dolly - v2 - 3b | 0.384 | 0.611532 | 0.589582 | 0.650767 | 0.370307 | 0.742655 | 0.575535 | 0.544886 |
EleutherAI/pythia - 12b | 0.364 | 0.627104 | 0.636148 | 0.668094 | 0.346416 | 0.760065 | 0.673394 | 0.559676 |
EleutherAI/gpt - j - 6B | 0.382 | 0.621633 | 0.651144 | 0.662617 | 0.363481 | 0.761153 | 0.655963 | 0.565936 |
databricks/dolly - v2 - 12b | 0.408 | 0.63931 | 0.616417 | 0.707927 | 0.388225 | 0.757889 | 0.568196 | 0.56781 |
databricks/dolly - v2 - 7b | 0.392 | 0.633838 | 0.607735 | 0.686517 | 0.406997 | 0.750816 | 0.644037 | 0.573487 |
databricks/dolly - v1 - 6b | 0.41 | 0.62963 | 0.643252 | 0.676758 | 0.384812 | 0.773667 | 0.687768 | 0.583431 |
EleutherAI/gpt - neox - 20b | 0.402 | 0.683923 | 0.656669 | 0.7142 | 0.408703 | 0.784004 | 0.695413 | 0.602236 |
📄 许可证
本项目采用MIT许可证。
📖 引用
@online{DatabricksBlog2023DollyV2,
author = {Mike Conover and Matt Hayes and Ankit Mathur and Jianwei Xie and Jun Wan and Sam Shah and Ali Ghodsi and Patrick Wendell and Matei Zaharia and Reynold Xin},
title = {Free Dolly: Introducing the World's First Truly Open Instruction-Tuned LLM},
year = {2023},
url = {https://www.databricks.com/blog/2023/04/12/dolly-first-open-commercially-viable-instruction-tuned-llm},
urldate = {2023-06-30}
}
😊 愉快开发!



