🚀 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與我們聯繫。