模型概述
模型特點
模型能力
使用案例
🚀 dolly-v2-3b模型卡片
dolly-v2-3b
是由Databricks基於 pythia-2.8b
開發的指令跟隨大語言模型,在Databricks機器學習平臺上訓練,可用於商業用途。它在約15k條指令/響應微調記錄上進行訓練,展現出了較高質量的指令跟隨能力。
🚀 快速開始
若要在配備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
。若GPU支持 torch.bfloat16
類型,建議添加 torch_dtype=torch.bfloat16
以減少內存使用,且不會影響輸出質量。若內存充足,也可移除該參數。
import torch
from transformers import pipeline
generate_text = pipeline(model="databricks/dolly-v2-3b", 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
,可以下載 instruct_pipeline.py,將其與你的筆記本放在同一目錄下,並使用加載的模型和分詞器自行構建管道:
import torch
from instruct_pipeline import InstructionTextGenerationPipeline
from transformers import AutoModelForCausalLM, AutoTokenizer
tokenizer = AutoTokenizer.from_pretrained("databricks/dolly-v2-3b", padding_side="left")
model = AutoModelForCausalLM.from_pretrained("databricks/dolly-v2-3b", 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-3b", 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-3b
基於Databricks機器學習平臺訓練,可用於商業用途。 - 指令跟隨能力:在約15k條指令/響應微調記錄上進行訓練,展現出較高質量的指令跟隨行為。
- 多模型可選:Dolly v2還有其他更大規模的模型可供選擇,如 dolly-v2-12b 和 dolly-v2-7b。
📚 詳細文檔
模型概述
dolly-v2-3b
是由 Databricks 創建的一個具有28億參數的因果語言模型,它基於 EleutherAI 的 Pythia-2.8b 模型,並在Databricks員工生成的約15K條指令語料庫(點擊查看)上進行微調,該語料庫以寬鬆的許可證(CC-BY-SA)發佈。
已知侷限性
性能侷限性
dolly-v2-3b
並非最先進的生成式語言模型,儘管正在進行定量基準測試,但它的設計並非為了與更現代的模型架構或經過更大預訓練語料庫訓練的模型競爭。
Dolly模型家族正在積極開發中,因此任何缺點列表都不太可能詳盡無遺,但我們在此列出已知的侷限性和失誤,以便向社區記錄和分享我們的初步發現。特別是,dolly-v2-3b
在處理以下方面存在困難:語法複雜的提示、編程問題、數學運算、事實性錯誤、日期和時間、開放式問答、幻覺、枚舉特定長度的列表、風格模仿、幽默感等。此外,我們發現 dolly-v2-3b
不具備原始模型中的某些能力,如格式規範的信件寫作。
數據集侷限性
與所有語言模型一樣,dolly-v2-3b
反映了其訓練語料庫的內容和侷限性。
- The Pile:GPT-J的預訓練語料庫主要包含從公共互聯網收集的內容,與大多數網絡規模的數據集一樣,它包含許多用戶可能會反感的內容。因此,該模型可能會反映這些缺點,在明確要求生成反感內容時可能會明顯表現出來,有時也會微妙地表現出來,如存在有偏見或有害的隱含關聯。
databricks-dolly-15k
:dolly-v2-3b
進行指令微調的訓練數據代表了Databricks員工在2023年3月至4月期間生成的自然語言指令,其中包括來自維基百科的段落,作為封閉式問答和摘要等指令類別的參考段落。據我們所知,它不包含淫穢內容、知識產權或非公眾人物的個人身份信息,但可能包含拼寫錯誤和事實性錯誤。該數據集也可能反映維基百科中存在的偏見。最後,該數據集可能反映了Databricks員工的興趣和語義選擇,這一群體並不能代表全球廣大人口。 Databricks致力於持續的研究和開發工作,以開發有用、誠實和無害的人工智能技術,最大限度地發揮所有個人和組織的潛力。
基準指標
以下是各種模型在 EleutherAI LLM Evaluation Harness 上的基準測試性能;模型結果按幾何平均值排序,以產生可理解的順序。如上所述,這些結果表明 dolly-v2-3b
並非最先進的模型。在評估基準測試中,它的表現不如 dolly-v1-6b
,考慮到它的參數數量只有後者的一半,這並不奇怪。
模型 | openbookqa | arc_easy | winogrande | hellaswag | arc_challenge | piqa | boolq | gmean |
---|---|---|---|---|---|---|---|---|
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}
}
😊 愉快地使用!



