模型概述
模型特點
模型能力
使用案例
🚀 Mathstral-7b-v0.1模型卡片
Mathstral 7B是一款專注於數學和科學任務的模型,它基於Mistral 7B開發。你可以在官方博客文章中瞭解更多信息。
🚀 快速開始
Mathstral 7B是基於Mistral 7B的模型,專注於解決數學和科學領域的任務。以下為你介紹該模型的使用方法。
📦 安裝指南
建議將mistralai/Mathstral-7b-v0.1
與mistral-inference結合使用。
pip install mistral_inference>=1.2.0
💻 使用示例
下載模型
from huggingface_hub import snapshot_download
from pathlib import Path
mistral_models_path = Path.home().joinpath('mistral_models', 'Mathstral-7b-v0.1')
mistral_models_path.mkdir(parents=True, exist_ok=True)
snapshot_download(repo_id="mistralai/Mathstral-7b-v0.1", allow_patterns=["params.json", "consolidated.safetensors", "tokenizer.model.v3"], local_dir=mistral_models_path)
聊天交互
安裝mistral_inference
後,你的環境中會有一個mistral-demo
命令行工具。
mistral-chat $HOME/mistral_models/Mathstral-7b-v0.1 --instruct --max_tokens 256
你可以開始與模型進行對話,例如向它提問:
"Albert likes to surf every week. Each surfing session lasts for 4 hours and costs $20 per hour. How much would Albert spend in 5 weeks?"
在transformers
庫中使用
要在transformers
庫中使用該模型,先使用pip install --upgrade transformers
安裝最新版本,然後運行以下代碼:
from transformers import pipeline
import torch
checkpoint = "mistralai/Mathstral-7b-v0.1"
pipe = pipeline("text-generation", checkpoint, device_map="auto", torch_dtype=torch.bfloat16)
prompt = [{"role": "user", "content": "What are the roots of unity?"}]
out = pipe(prompt, max_new_tokens = 512)
print(out[0]['generated_text'][-1])
>>> "{'role': 'assistant', 'content': ' The roots of unity are the complex numbers that satisfy the equation $z^n = 1$, where $n$ is a positive integer. These roots are evenly spaced around the unit circle in the complex plane, and they have a variety of interesting properties and applications in mathematics and physics.'}"
你也可以手動對輸入進行分詞,並從模型生成文本,而不是使用高級的pipeline:
from transformers import AutoTokenizer, AutoModelForCausalLM
import torch
checkpoint = "mistralai/Mathstral-7b-v0.1"
tokenizer = AutoTokenizer.from_pretrained(checkpoint)
model = AutoModelForCausalLM.from_pretrained(checkpoint, device_map="auto", torch_dtype=torch.bfloat16)
prompt = [{"role": "user", "content": "What are the roots of unity?"}]
tokenized_prompt = tokenizer.apply_chat_template(prompt, add_generation_prompt=True, return_dict=True, return_tensors="pt").to(model.device)
out = model.generate(**tokenized_prompt, max_new_tokens=512)
tokenizer.decode(out[0])
>>> '<s>[INST] What are the roots of unity?[/INST] The roots of unity are the complex numbers that satisfy the equation $z^n = 1$, where $n$ is a positive integer. These roots are evenly spaced around the unit circle in the complex plane, and they have a variety of interesting properties and applications in mathematics and physics.</s>'
📚 詳細文檔
評估結果
我們在行業標準基準測試中對Mathstral 7B和類似規模的開放權重模型進行了評估。
基準測試 | MATH | GSM8K (8-shot) | Odyssey Math maj@16 | GRE Math maj@16 | AMC 2023 maj@16 | AIME 2024 maj@16 |
---|---|---|---|---|---|---|
Mathstral 7B | 56.6 | 77.1 | 37.2 | 56.9 | 42.4 | 2/30 |
DeepSeek Math 7B | 44.4 | 80.6 | 27.6 | 44.6 | 28.0 | 0/30 |
Llama3 8B | 28.4 | 75.4 | 24.0 | 26.2 | 34.4 | 0/30 |
GLM4 9B | 50.2 | 48.8 | 18.9 | 46.2 | 36.0 | 1/30 |
QWen2 7B | 56.8 | 32.7 | 24.8 | 58.5 | 35.2 | 2/30 |
Gemma2 9B | 48.3 | 69.5 | 18.6 | 52.3 | 31.2 | 1/30 |
開發團隊
Mathstral 7B由Mistral AI團隊開發,團隊成員包括:Albert Jiang, Alexandre Sablayrolles, Alexis Tacnet, Alok Kothari, Antoine Roux, Arthur Mensch, Audrey Herblin-Stoop, Augustin Garreau, Austin Birky, Bam4d, Baptiste Bout, Baudouin de Monicault, Blanche Savary, Carole Rambaud, Caroline Feldman, Devendra Singh Chaplot, Diego de las Casas, Eleonore Arcelin, Emma Bou Hanna, Etienne Metzger, Gaspard Blanchet, Gianna Lengyel, Guillaume Bour, Guillaume Lample, Harizo Rajaona, Henri Roussez, Hichem Sattouf, Ian Mack, Jean-Malo Delignon, Jessica Chudnovsky, Justus Murke, Kartik Khandelwal, Lawrence Stewart, Louis Martin, Louis Ternon, Lucile Saulnier, Lélio Renard Lavaud, Margaret Jennings, Marie Pellat, Marie Torelli, Marie-Anne Lachaux, Marjorie Janiewicz, Mickaël Seznec, Nicolas Schuhl, Niklas Muhs, Olivier de Garrigues, Patrick von Platen, Paul Jacob, Pauline Buche, Pavan Kumar Reddy, Perry Savas, Pierre Stock, Romain Sauvestre, Sagar Vaze, Sandeep Subramanian, Saurabh Garg, Sophia Yang, Szymon Antoniak, Teven Le Scao, Thibault Schueller, Thibaut Lavril, Thomas Wang, Théophile Gervet, Timothée Lacroix, Valera Nemychnikova, Wendy Shang, William El Sayed, William Marshall
📄 許可證
本項目採用Apache-2.0許可證。
⚠️ 重要提示
如果你想了解更多關於我們如何處理你的個人數據的信息,請閱讀我們的隱私政策。



