🚀 语言模型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的使用。
- 意识到模型可能存在的社会偏见和毒性,在解释模型输出时保持谨慎和批判性思维。