DeepSeekMath:推进数学推理的极限
DeepSeekMath: Pushing the Limits of Mathematical Reasoning

原始链接: https://github.com/deepseek-ai/deepseek-math

DeepSeekMath 7B 是一个数学导向的语言模型,基于 DeepSeek-Coder-v1.5 7B 初始化,并在 500B token 上预训练,包括数学相关的网页、自然语言和代码数据。它在不使用工具或投票的情况下在 MATH 基准测试上得分 51.7%,接近 Gemini-Ultra/GPT-4,并在 MATH 少样本思维链上比开源基础模型高出超过 10% 的绝对值,超越了 Minerva 540B。基础模型还显示出强大的工具使用能力以及可比的推理/编码性能。DeepSeekMath-Instruct 7B 提供逐步推理,而使用 GRPO 训练的 DeepSeekMath-RL 7B 在使用工具的情况下在 MATH 上达到约 60%,超过了现有的开源模型。训练数据从 Common Crawl 迭代收集,得到 3550 万数学网页和 120B token。基础、指令和 RL 检查点在模型许可证下公开发布,供研究和商业使用。仓库采用 MIT 许可,提供了 Hugging Face Transformers 使用示例。

Hacker News 上的一篇帖子链接到 DeepSeekMath,这是 DeepSeek AI 的一个 GitHub 项目,专注于推进数学推理。该提交有 27 点和 7 条评论。评论者指出帖子来自 2024 年,因此是较旧的新闻,并讨论包含 “DeepSeek” 的标题如何吸引点赞。有些人称其为古老历史或批评盲目点赞,而另一些人则将它与更当前的首页帖子进行不利比较。提供的片段几乎不包含模型本身的技术细节。
相关文章

原文

Model Download | Evaluation Results | Quick Start | License | Citation

Paper Link👁️

DeepSeekMath is initialized with DeepSeek-Coder-v1.5 7B and continues pre-training on math-related tokens sourced from Common Crawl, together with natural language and code data for 500B tokens. DeepSeekMath 7B has achieved an impressive score of 51.7% on the competition-level MATH benchmark without relying on external toolkits and voting techniques, approaching the performance level of Gemini-Ultra and GPT-4. For research purposes, we release checkpoints of base, instruct, and RL models to the public.

table

We conduct a comprehensive assessment of the mathematical capabilities of DeepSeekMath-Base 7B, focusing on its ability to produce self-contained mathematical solutions without relying on external tools, solve math problems using tools, and conduct formal theorem proving. Beyond mathematics, we also provide a more general profile of the base model, including its performance of natural language understanding, reasoning, and programming skills.

  • Mathematical problem solving with step-by-step reasoning

table

  • Mathematical problem solving with tool use

table

  • Natural Language Understanding, Reasoning, and Code

table

The evaluation results from the tables above can be summarized as follows:

  • Superior Mathematical Reasoning: On the competition-level MATH dataset, DeepSeekMath-Base 7B outperforms existing open-source base models by more than 10% in absolute terms through few-shot chain-of-thought prompting, and also surpasses Minerva 540B.
  • Strong Tool Use Ability: Continuing pre-training with DeepSeekCoder-Base-7B-v1.5 enables DeepSeekMath-Base 7B to more effectively solve and prove mathematical problems by writing programs.
  • Comparable Reasoning and Coding Performance: DeepSeekMath-Base 7B achieves performance in reasoning and coding that is comparable to that of DeepSeekCoder-Base-7B-v1.5.

DeepSeekMath-Instruct and -RL 7B

DeepSeekMath-Instruct 7B is a mathematically instructed tuning model derived from DeepSeekMath-Base 7B, while DeepSeekMath-RL 7B is trained on the foundation of DeepSeekMath-Instruct 7B, utilizing our proposed Group Relative Policy Optimization (GRPO) algorithm.

We evaluate mathematical performance both without and with tool use, on 4 quantitative reasoning benchmarks in English and Chinese. As shown in Table, DeepSeekMath-Instruct 7B demonstrates strong performance of step-by-step reasoning, and DeepSeekMath-RL 7B approaches an accuracy of 60% on MATH with tool use, surpassing all existing open-source models.

table

  • Step 1: Select OpenWebMath, a collection of high-quality mathematical web texts, as our initial seed corpus for training a FastText model.
  • Step 2: Use the FastText model to retrieve mathematical web pages from the deduplicated Common Crawl database.
  • Step 3: Identify potential math-related domains through statistical analysis.
  • Step 4: Manually annotate URLs within these identified domains that are associated with mathematical content.
  • Step 5: Add web pages linked to these annotated URLs, but not yet collected, to the seed corpus. Jump to step 1 until four iterations.

table

After four iterations of data collection, we end up with 35.5M mathematical web pages, totaling 120B tokens.

We release the DeepSeekMath 7B, including base, instruct and RL models, to the public. To support a broader and more diverse range of research within both academic and commercial communities. Please note that the use of this model is subject to the terms outlined in License section. Commercial usage is permitted under these terms.

You can directly employ Huggingface's Transformers for model inference.

Text Completion

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)

Chat Completion

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)

Avoiding the use of the provided function apply_chat_template, you can also interact with our model following the sample template. Note that messages should be replaced by your input.

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

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

Assistant:

Note: By default (add_special_tokens=True), our tokenizer automatically adds a bos_token (<|begin▁of▁sentence|>) before the input text. Additionally, since the system prompt is not compatible with this version of our models, we DO NOT RECOMMEND including the system prompt in your input.

❗❗❗ Please use chain-of-thought prompt to test DeepSeekMath-Instruct and DeepSeekMath-RL:

  • English questions: {question}\nPlease reason step by step, and put your final answer within \boxed{}.

  • Chinese questions: {question}\n请通过逐步推理来解答问题,并把最终答案放置于\boxed{}中。

This code repository is licensed under the MIT License. The use of DeepSeekMath models is subject to the Model License. DeepSeekMath supports commercial use.

See the LICENSE-CODE and LICENSE-MODEL for more details.

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

If you have any questions, please raise an issue or contact us at [email protected].

联系我们 contact @ memedata.com