🚀 DeepSeekMath
DeepSeekMath是一款强大的数学模型,能够为用户提供专业的数学问题解答和推理服务,助力数学领域的研究与应用。
🚀 快速开始
若想了解更多关于DeepSeekMath的信息,请参阅简介。
💻 使用示例
基础用法
以下给出了一些如何使用我们模型的示例。
聊天完成
❗❗❗ 请使用思维链提示来测试DeepSeekMath-Instruct和DeepSeekMath-RL:
-
英文问题:{question}\nPlease reason step by step, and put your final answer within \boxed{}.
-
中文问题:{question}\n请通过逐步推理来解答问题,并把最终答案放置于\boxed{}中。
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
),我们的分词器会自动在输入文本前添加一个bos_token
(<|begin▁of▁sentence|>
)。此外,由于系统提示与我们此版本的模型不兼容,我们不建议在输入中包含系统提示。
📄 许可证
此代码仓库遵循MIT许可证。DeepSeekMath模型的使用需遵循模型许可证。DeepSeekMath支持商业使用。
更多详细信息请参阅LICENSE-MODEL。
📞 联系我们
如果您有任何问题,请提出问题或通过service@deepseek.com与我们联系。