数学に特化した言語モデル!NuminaMath-7B-TIRグラフの表示や数学の問題を解く

ふゅか
ふゅか
ねえ、ふゅか!最近話題の数学特化の言語モデル、NuminaMath-7B-TIRって知ってる?
はるか
はるか
うん、知ってるよ。AI-MOが開発したやつでしょ。

1. モデルの概要

NuminaMath-7B-TIRは、AI-MOによって開発された数式と関連タスクに特化した大規模言語モデルです。このモデルは、特に数学的推論、問題解決、および数式の生成や理解に優れています。

はるか
はるか
まず、NuminaMath-7B-TIRは、数式の生成や理解が得意なモデル。

ふゅか
ふゅか
そうね、例えば数学的証明や計算にも使えるのがポイントだよね!

1.1. 特徴

  • パラメータ数: 7B(70億)パラメータを持つモデル。
  • 用途: 数式の生成、数学的証明、問題解決、計算、数式の解釈など、様々な数学関連タスクに利用可能です。
  • ファインチューニング:deepseek-ai/deepseek-math-7b-baseを利用。
はるか
はるか
パラメータ数が7B。用途は数式生成、数学的証明、問題解決、計算、数式の解釈など。
ふゅか
ふゅか
deepseek-aiのモデルを使ってファインチューニングされてるんだね!

2. pythonコード

2.1. 実行環境

  • RTX 4070ti super VRAM 16GB
  • Windows11
  • memory 64GB
  • Python 3.11.9
  • transformers 4.42.4

2.2. モデルを直接読み込む方法

以下に、NuminaMath-7B-TIRの利用例を示します。

from transformers import AutoModelForCausalLM, AutoTokenizer,set_seed
set_seed(42)
tokenizer = AutoTokenizer.from_pretrained("AI-MO/NuminaMath-7B-TIR")
model = AutoModelForCausalLM.from_pretrained("AI-MO/NuminaMath-7B-TIR",
                                             device_map="auto",
                                             load_in_4bit=True)

input_text = "plot the function: y = x^2 - 4x + 4"
input_ids = tokenizer.encode(input_text, return_tensors="pt")
output = model.generate(input_ids, max_length=1024)

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

2.3. グラフのプロット

$y = x^2 - 4x + 4$のグラフをプロットするプログラムを生成すると$1\leq x \leq 5$の範囲で次のようになりました。

import numpy as np
import matplotlib.pyplot as plt

# Define the function
def f(x):
    return x**2 - 4*x + 4

# Define the range
x_min, x_max = 1, 5

# Create an array of x values within the range
x_values = np.linspace(x_min, x_max, 400)

# Calculate the corresponding y values
y_values = f(x_values)

# Plot the function
plt.plot(x_values, y_values, label='y = x^2 - 4x + 4')
plt.xlabel('x')
plt.ylabel('y')
plt.title('Plot of y = x^2 - 4x + 4 for x in [1, 5]')
plt.legend()
plt.grid(True)
plt.show()

はるか
はるか
最小値が2であることを確認できる。

2.4. まとめ

NuminaMath-7B-TIRは、数学的なタスクに特化した強力な言語モデルであり、研究者や開発者にとって非常に有用なツールです。その高い性能と柔軟性により、様々な数学関連のアプリケーションで活用することが期待されています。

PR