AIFeed

DeepSeekMath:突破数学推理的极限

Translation(model translation, not the source's own text)

模型下载 | 评估结果 | 快速开始 | 许可证 | 引用

论文链接👁️

1. 引言

DeepSeekMath 以 DeepSeek-Coder-v1.5 7B 初始化,并在来源于 Common Crawl 的数学相关 token 上继续预训练,同时加入自然语言和代码数据,共 500B token。DeepSeekMath 7B 在竞赛级 MATH 基准上取得了 51.7% 的亮眼成绩,且未依赖外部工具包和投票技术,接近 Gemini-Ultra 和 GPT-4 的性能水平。出于研究目的,我们向公众发布了 base、instruct 和 RL 模型的 checkpoint。

table
table

2. 评估结果

DeepSeekMath-Base 7B

我们对 DeepSeekMath-Base 7B 的数学能力进行了全面评估,重点关注其在不依赖外部工具的情况下产出完整数学解答的能力、使用工具解决数学问题的能力,以及进行形式化定理证明的能力。除数学之外,我们还提供了该 base 模型更通用的画像,包括其在自然语言理解、推理和编程技能方面的表现。

  • 通过逐步推理解决数学问题
table
table
  • 通过使用工具解决数学问题
table
table
  • 自然语言理解、推理与代码
table
table

上表中的评估结果可总结如下:

  • 卓越的数学推理能力:在竞赛级 MATH 数据集上,DeepSeekMath-Base 7B 通过 few-shot 思维链提示,以绝对数值超过 10% 的优势优于现有开源 base 模型,并且还超过了 Minerva 540B。
  • 强大的工具使用能力:以 DeepSeekCoder-Base-7B-v1.5 继续预训练,使 DeepSeekMath-Base 7B 能够通过编写程序更有效地解决和证明数学问题。
  • 可比的推理与编码性能:DeepSeekMath-Base 7B 在推理和编码方面的性能与 DeepSeekCoder-Base-7B-v1.5 相当。

DeepSeekMath-Instruct 和 -RL 7B

DeepSeekMath-Instruct 7B 是源自 DeepSeekMath-Base 7B 的数学指令微调模型,而 DeepSeekMath-RL 7B 在 DeepSeekMath-Instruct 7B 的基础上训练,采用了我们提出的 Group Relative Policy Optimization (GRPO) 算法。

我们在不使用工具和使用工具两种情况下,于 4 个英文和中文的定量推理基准上评估数学性能。如表所示,DeepSeekMath-Instruct 7B 展现了强大的逐步推理性能,而 DeepSeekMath-RL 7B 在使用工具的情况下在 MATH 上接近 60% 的准确率,超越了所有现有开源模型。

table
table

3. 数据收集

  • 步骤 1:选择 OpenWebMath——一个高质量数学网页文本集合——作为我们的初始种子语料,用于训练 FastText 模型。
  • 步骤 2:使用 FastText 模型从去重后的 Common Crawl 数据库中检索数学网页。
  • 步骤 3:通过统计分析识别潜在的数学相关域名。
  • 步骤 4:人工标注这些识别出的域名中与数学内容相关的 URL。
  • 步骤 5:将链接到这些已标注但尚未收集的 URL 的网页加入种子语料。跳转到步骤 1,直到完成四次迭代。
table
table

经过四轮数据收集迭代,我们最终得到 35.5M 个数学网页,总计 120B token。

4. 模型下载

我们向公众发布 DeepSeekMath 7B,包括 base、instruct 和 RL 模型。以支持学术界和商业界更广泛、更多样化的研究。请注意,本模型的使用须遵守 License 部分所述条款。在这些条款下允许商业使用。

Huggingface

模型序列长度下载
DeepSeekMath-Base 7B4096🤗 HuggingFace
DeepSeekMath-Instruct 7B4096🤗 HuggingFace
DeepSeekMath-RL 7B4096🤗 HuggingFace

5. 快速开始

你可以直接使用 Huggingface 的 Transformers 进行模型推理。

文本补全


        import torch
from transformers import AutoTokenizer, AutoModelForCausalLM, GenerationConfig

model_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")
model.generation_config = GenerationConfig.from_pretrained(model_name)
model.generation_config.pad_token_id = model.generation_config.eos_token_id

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)

result = tokenizer.decode(outputs[0], skip_special_tokens=True)
print(result)
      

对话补全


        import torch
from transformers import AutoTokenizer, AutoModelForCausalLM, GenerationConfig

model_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")
model.generation_config = GenerationConfig.from_pretrained(model_name)
model.generation_config.pad_token_id = model.generation_config.eos_token_id

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)

result = tokenizer.decode(outputs[0][input_tensor.shape[1]:], skip_special_tokens=True)
print(result)
      

避免使用所提供的 apply_chat_template 函数,你也可以按照示例模板与我们的模型交互。请注意,messages 应替换为你的输入。


        User: {messages[0]['content']}

Assistant: {messages[1]['content']}<|end▁of▁sentence|>User: {messages[2]['content']}

Assistant:
      

注意:默认情况下(add_special_tokens=True),我们的 tokenizer 会自动在输入文本前添加一个 bos_token(<|begin▁of▁sentence|>)。此外,由于系统提示词与此版本的模型不兼容,我们不建议在输入中包含系统提示词。

❗❗❗ 请使用思维链提示来测试 DeepSeekMath-Instruct 和 DeepSeekMath-RL:

  • 英文问题:{question}\nPlease reason step by step, and put your final answer within \boxed{}.
  • 中文问题:{question}\n请通过逐步推理来解答问题,并把最终答案放置于\boxed{}中。

6. 许可证

本代码仓库基于 MIT License 授权。DeepSeekMath 模型的使用须遵守 Model License。DeepSeekMath 支持商业使用。

更多详情请参见 LICENSE-CODE 和 LICENSE-MODEL。

7. 引用


        @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},
}
      

8. 联系方式

如有任何问题,请提交 issue 或通过 [email protected] 联系我们。

The translation is machine-generated and individual terms may be off. Nothing is rewritten or cut; the original is authoritative.

Published by Hacker News
This site only summarises and aggregates; copyright stays with the original author. Headlines and summaries follow the source — where they differ, the original wins.
Read the original ↗