🚀 語言模型Phi-1.5
Phi-1.5是一款參數達13億的Transformer語言模型。它使用與phi-1相同的數據源進行訓練,並新增了包含各種NLP合成文本的數據源。在常識、語言理解和邏輯推理等基準測試中,Phi-1.5在參數少於100億的模型中展現出近乎最先進的性能。該模型旨在為研究界提供一個無限制的小模型,以探索語言模型的安全性挑戰,如減少毒性、理解社會偏見、增強可控性等。
🚀 快速開始
Phi-1.5已集成在transformers
4.37.0版本中,請確保你使用的是該版本或更高版本。
✨ 主要特性
- 功能多樣:能夠寫詩、起草郵件、創作故事、總結文本、編寫Python代碼(例如下載Hugging Face的transformer模型)等。
- 訓練數據安全:訓練時排除了通用網絡爬取數據源(如common-crawl),在不使用基於人類反饋的強化學習(RLHF)的情況下增強了模型的安全性。
- 適合多種格式:適用於問答、聊天和代碼格式的提示。
📦 安裝指南
Phi-1.5已集成在transformers
版本4.37.0中,請確保你使用的版本等於或高於此版本。
💻 使用示例
基礎用法
import torch
from transformers import AutoModelForCausalLM, AutoTokenizer
torch.set_default_device("cuda")
model = AutoModelForCausalLM.from_pretrained("microsoft/phi-1_5", torch_dtype="auto")
tokenizer = AutoTokenizer.from_pretrained("microsoft/phi-1_5")
inputs = tokenizer('''def print_prime(n):
"""
Print all primes between 1 and n
"""''', return_tensors="pt", return_attention_mask=False)
outputs = model.generate(**inputs, max_length=200)
text = tokenizer.batch_decode(outputs)[0]
print(text)
高級用法
問答格式
Write a detailed analogy between mathematics and a lighthouse.
Answer: Mathematics is like a lighthouse, guiding us through the vast ocean of numbers and calculations. Just as a lighthouse illuminates the darkness, mathematics provides us with a clear path to navigate through complex problems. It helps us make sense of the world around us, just like a lighthouse helps ships find their way home.
聊天格式
Alice: I don't know why, I'm struggling to maintain focus while studying. Any suggestions?
Bob: Have you tried using a timer? It can help you stay on track and avoid distractions.
Alice: That's a good idea. I'll give it a try.
Charlie: Another thing that can help is to break up your study sessions into smaller chunks. It's easier to concentrate on one thing at a time.
Alice: That makes sense. I'll try that too.
Bob: And don't forget to take breaks! It's important to give your brain a rest so you can come back to your studies with a fresh perspective.
Alice: Thanks for the advice, guys. I feel more motivated now.
Charlie: No problem, Alice. We're all in this together.
Bob: Yeah, and remember that it's okay to ask for help if you need it. We're here to support each other.
代碼格式
def print_prime(n):
"""
Print all primes between 1 and n
"""
primes = []
for num in range(2, n+1):
is_prime = True
for i in range(2, int(math.sqrt(num))+1):
if num % i == 0:
is_prime = False
break
if is_prime:
primes.append(num)
print(primes)
📚 詳細文檔
預期用途
鑑於訓練數據的性質,Phi-1.5最適合問答格式、聊天格式和代碼格式的提示。需要注意的是,作為基礎模型,Phi-1.5在給出主要答案後往往會產生不相關的文本。
侷限性
- 生成不準確的代碼和事實:模型經常生成不正確的代碼片段和陳述。用戶應將這些輸出視為建議或起點,而非確定或準確的解決方案。
- 代碼範圍有限:如果模型生成使用不常見包的Python腳本或其他語言的腳本,強烈建議用戶手動驗證所有API的使用。
- 對指令的響應不可靠:模型未經過指令微調,可能難以或無法遵循用戶提供的複雜或細微的指令。
- 語言限制:模型主要設計用於理解標準英語。非正式英語、俚語或英語以外的任何其他語言可能會給其理解帶來挑戰,導致潛在的誤解或響應錯誤。
- 潛在的社會偏見:儘管使用了安全數據進行訓練,但模型並非完全沒有社會偏見。它有可能生成反映這些社會偏見的內容,特別是在受到相應提示或指令時。
- 毒性:儘管模型使用精心挑選的數據進行訓練,但如果明確提示或指令,模型仍可能產生有害內容。
🔧 技術細節
模型
屬性 |
詳情 |
模型類型 |
基於Transformer架構,目標為下一個詞預測 |
訓練數據集大小 |
300億個標記 |
訓練標記數 |
1500億個標記 |
精度 |
fp16 |
GPU |
32個A100 - 40G |
訓練時間 |
8天 |
軟件
📄 許可證
該模型遵循MIT許可證。
引用
你可以在https://arxiv.org/abs/2309.05463找到相關論文。請按以下格式引用:
@article{textbooks2,
title={Textbooks Are All You Need II: \textbf{phi-1.5} technical report},
author={Li, Yuanzhi and Bubeck, S{\'e}bastien and Eldan, Ronen and Del Giorno, Allie and Gunasekar, Suriya and Lee, Yin Tat},
journal={arXiv preprint arXiv:2309.05463},
year={2023}
}
商標
本項目可能包含項目、產品或服務的商標或標識。對微軟商標或標識的授權使用需遵循微軟商標和品牌指南。在本項目的修改版本中使用微軟商標或標識不得造成混淆或暗示微軟的贊助。任何第三方商標或標識的使用需遵循這些第三方的政策。
⚠️ 重要提示
- Phi-1.5生成的文本/代碼應被視為起點,而非潛在用例的確定解決方案。用戶在應用中使用這些模型時應謹慎。
- Phi-1.5尚未經過測試以確保其在任何生產級應用中能充分發揮作用。
💡 使用建議
- 當模型生成使用不常見包的Python腳本或其他語言的腳本時,手動驗證所有API的使用。
- 意識到模型可能存在的社會偏見和毒性,在解釋模型輸出時保持謹慎和批判性思維。