模型概述
模型特點
模型能力
使用案例
🚀 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}
}
😊 愉快開發!



