
DeepSeek 正式开源 DeepSeekMath 7B 系列模型,包括基础模型(Base)、指令微调模型(Instruct)及强化学习模型(RL)。该系列基于 DeepSeek-Coder-v1.5 7B 初始化,并在来自 Common Crawl 的数学相关词元、自然语言及代码数据上完成了 5000 亿(500B)词元的继续预训练。
在竞赛级 MATH 基准测试中,DeepSeekMath 7B 取得了51.7%的准确率。这一成绩在未依赖外部工具包或投票技术的情况下取得,性能已接近 Gemini-Ultra 和 GPT-4 水平。为促进学术界与产业界研究,DeepSeek 已向公众开放上述三个版本的模型检查点,并允许商业使用。
核心评估:推理能力超越同类开源模型
针对 DeepSeekMath-Base 7B 的评估显示,其在数学推理、工具使用及形式化定理证明方面表现优异。具体亮点包括:
卓越的数学推理:在 MATH 数据集上,通过少样本思维链(Chain-of-Thought)提示,DeepSeekMath-Base 7B 的绝对数值表现超越现有开源基础模型 10% 以上,并超过 Minerva 540B。
强大的工具协同:得益于基于 DeepSeekCoder-Base-7B-v1.5 的继续预训练,模型能通过编写程序更高效地解决和证明数学问题。
均衡的综合能力:在自然语言理解、推理及编码技能方面,其性能与 DeepSeekCoder-Base-7B-v1.5 相当。
在进阶版本中,DeepSeekMath-Instruct 7B 展现了强大的逐步推理能力;而基于组相对策略优化(GRPO)算法训练的 DeepSeekMath-RL 7B,在使用工具辅助的情况下,MATH 基准准确率接近 60%,超越了所有现有的开源模型。
数据工程:四轮迭代构建高质量语料
DeepSeek 团队采用四轮迭代方式收集训练数据,最终获得3550 万个数学网页,总计1200 亿(120B)词元。具体流程如下:
以 OpenWebMath 为初始种子语料库训练 FastText 模型;
利用该模型从去重后的 Common Crawl 数据库中检索数学网页;
通过统计分析识别潜在数学相关领域;
人工标注相关 URL,并将链接到的未收集网页加入种子库;
重复上述过程四次,确保数据覆盖度与质量。
快速上手与使用规范
开发者可通过 Hugging Face Transformers 库直接调用模型。目前提供的模型版本序列长度均为 4096。
代码调用示例
文本补全(Base 模型)
import torchfrom transformers import AutoTokenizer, AutoModelForCausalLMmodel_name = "deepseek-ai/deepseek-math-7b-base"tokenizer = AutoTokenizer.from_pretrained ( model_name ) model = AutoModelForCausalLM.from_pretrained ( model_name, torch_dtype=torch.bfloat16, device_map="auto" ) text = "The integral of x^2 from 0 to 2 is"inputs = tokenizer ( text, return_tensors="pt" ) outputs = model.generate ( **inputs.to ( model.device ) , max_new_tokens=100 ) print ( tokenizer.decode ( outputs [ 0 ] , skip_special_tokens=True ) )
对话补全(Instruct 模型)
建议使用思维链提示以获得最佳效果。英文提示模板:{question}nPlease reason step by step, and put your final answer within boxed{}.;中文提示模板:{question}n 请通过逐步推理来解答问题,并把最终答案放置于 boxed{} 中。
import torchfrom transformers import AutoTokenizer, AutoModelForCausalLMmodel_name = "deepseek-ai/deepseek-math-7b-instruct"tokenizer = AutoTokenizer.from_pretrained ( model_name ) model = AutoModelForCausalLM.from_pretrained ( model_name, torch_dtype=torch.bfloat16, device_map="auto" ) messages = [ {"role": "user", "content": "what is the integral of x^2 from 0 to 2?nPlease reason step by step, and put your final answer within boxed{}."} ] input_tensor = tokenizer.apply_chat_template ( messages, add_generation_prompt=True, return_tensors="pt" ) outputs = model.generate ( input_tensor.to ( model.device ) , max_new_tokens=100 ) print ( tokenizer.decode ( outputs [ 0 ] [ input_tensor.shape [ 1 ] : ] , skip_special_tokens=True ) )
注意事项:
分词器默认会在输入前自动添加 bos_token。
由于系统提示词与此版本模型不兼容,不建议在输入中包含系统提示词。
测试 Instruct 和 RL 模型时,请务必使用上述思维链提示模板。
许可证与引用
本代码仓库依据 MIT 许可证授权,模型使用受模型许可证约束,支持商业使用。详情请参阅 LICENSE-CODE 和 LICENSE-MODEL 文件。
如需引用,请参考以下 BibTeX:
@misc{deepseek-math, author = {Zhihong Shao, Peiyi Wang, Qihao Zhu, Runxin Xu, Junxiao Song, Mingchuan Zhang, Y.K. Li, Y. Wu, Daya Guo}, title = {DeepSeekMath: Pushing the Limits of Mathematical Reasoning in Open Language Models}, journal = {CoRR}, volume = {abs/2402.03300}, year = {2024}, url = {https://arxiv.org/abs/2402.03300},}
如有技术问题,可通过提交 Issue 或发送邮件至 service@deepseek.com 联系团队。
【星途科讯 图文丨踢三脚 首发于 ZAKER 科技,转载请注明出处】