数学特化のローカルLLM、Xwin-Math-70BをGPT-4と比較する

2023/11/26に公開

はじめに

数学問題を解くためにLLaMA-2を教師あり転移学習させたローカルLLMが出てきている。その一部を示す。

最後に挙げたXwin-LM/Xwin-Math-70B-V1.0は、現在ベンチマーク上は最強[1]のローカルLLMであるXwin-LM-70B-V0.1を開発したチームが最近公開したものである。ベンチマーク上も既存の数学問題特化型LLMを上回っている。そのため性能が高いと期待できるため動かしてみた。

Xwin-LMはベンチマーク結果を以下に公開しており、ベンチマーク上はGPT-4を下回っていることもわかっているが、実際に出力を確認しておきたい。

https://github.com/Xwin-LM/Xwin-LM/tree/main/Xwin-Math

私の PC のスペック[2]

  • i7 13700K
  • 3090 24GB
  • DDR5 128GB

環境構築

Xwin-Math-70B-V1.0は70Bのモデルのため、私の環境で直接動かすことができない。また、現時点で、Xwin-Math-70B-V1.0を量子化したモデルは公開されていないため自分で量子化する必要がある。

以下の手順で、モデルを4bit量子化を実施した。

https://zenn.dev/derbuihan/articles/e1b60c180ee938

この記事の再現をする際は、上記の記事も参考にしてほしい。

実行

以下のコマンドを実行すれば、サーバーが起動する。

 ./build-cublas/bin/server -m ./models/Xwin-Math-70B-V1.0/ggml-model-Q4_K.gguf  -ngl 43 -t 8 -b 512

試す

まずは、以前の記事でXwin-LM-70Bにしたものと同じ質問をしてみて様子を伺う。

質問1

「素因数分解について説明してください。」

素因数分解 (prime factorization) とは、自然数をその最小冪零元である素数によって表現すること。

例: 12 = 2^2 * 3^1

  1. 12 が 2 と 6 からなる積の形式 (2*3) であることを見出し、
  2. 2 は 2 自身の冪零元 (prime factorization) であり,
  3. 6 も 2 3 からなる積の形式 (23) であることを見出し、
  4. 3 は 3 自身の冪零元 (prime factorization) であり,
  5. 2 も 2^1 2^1 = 2^2 からなる積の形式 (22) であることを見出し、
  6. 3 も 3^0 * 3^1 = 3^1 からなる積の形式 (3) であることを見出す。

So, the prime factorization of 12 is 2^2 * 3^1.

素因数分解は、自然数がどのように構成されているか (how a natural number is constructed) を説明する。

素因数分解の例:

  • 2 = 2^1
  • 3 = 3^1
  • 4 = 2

例しか答えてくれなかった。Xwin-LM-70Bは素因数分解の歴史まで説明してくれたので、Xwin-Math-70Bは精度が悪いように見える。

質問2

「コンピューターの基本的な構成要素は何ですか?」

コンピューターの基本的な構成要素は、CPU (Central Processing Unit)、メモリ (Memory)、入出力デバイス (Input/Output Devices) です。

  1. CPU: 計算を行う部分。コンピュータの中心的な役割を果たします。
  2. メモリ: 情報を保存する部分。CPUが必要とするデータやプログラム、計算結果等を記憶します。
  3. 入出力デバイス: コンピュータ内外の通信・接続に関わる部分。キーボードやマウスなどはこれに含まれます。

この質問はXwin-LM-70Bとあまり変わらない。

質問3

「素因数分解する Python コードを書いて」

To find the prime factorization of a number, we need to break it down into its smallest building blocks, which are prime numbers. Let's start by finding the prime factors of 12:

  1. Divide 12 by the smallest prime number (2):
    12 / 2 = 6
    We get a whole number, so we can continue dividing by 2:
    6 / 2 = 3
    Now we have reached another prime number and cannot divide any further. So, the prime factorization of 12 is 2 2 3.

Now let's write a Python code to find the prime factors of a given number n:

def prime_factorize(n):
    # Start by dividing the number by the smallest prime (2) and continue until we reach another prime or cannot divide any further.
    
    while True:
        if n % 2 == 0:
            result = '2' + result
            n /= 2
            
        else:
            break
        
    return result

Now let's test the code with some numbers:

  1. prime_factorize(12) = 2 2 3 (which is correct)
  2. prime_factorize(60) = 2 2 5 (which is correct)
  3. prime_factorize(84) = 2 7 (which is not correct, as it should be 2^2 3 * 7)

The current code only checks for divisibility by 2 and does not consider other prime numbers such as 3, 5, etc. To make the code more complete, we need to check for divisibility by all prime numbers up to the square root of n

英語で答えてくれた。コードは完全ではないし60の素因数分解が間違っている。

全体的な印象として、普通のタスクを解かせる分にはXwin-LM-70Bより精度が悪いように見える。

GPT-4との比較

数学問題特化のLLMのベンチマークにはGSM8Kというデータセットが使われている。GSM8Kには以下のような問題が含まれている。

/ 原文 日本語訳
question Natalia sold clips to 48 of her friends in April, and then she sold half as many clips in May. How many clips did Natalia sell altogether in April and May? ナタリアは4月に48人の友人にクリップを売り、その後5月に半分のクリップを売りました。4月と5月にナタリアは全部で何個のクリップを売りましたか?
answer Natalia sold 48/2 = <<48/2=24>>24 clips in May. Natalia sold 48+24 = <<48+24=72>>72 clips altogether in April and May. #### 72 ナタリアは5月に48/2 = <<48/2=24>>24個のクリップを売りました。ナタリアは4月と5月に全部で48+24 = <<48+24=72>>72個のクリップを売りました。#### 72

小学校の算数の問題で評価している様子。

その上で、私は質問として3つ考えた。

id question 日本語訳
1 Please list and add up all prime numbers below 100. 100以下の素数をすべて挙げて足してください。
2 Is a metric space also a topological space? 距離空間ならば位相空間か?
3 Please prove that the identity element is unique in a group. 群において単位元が一意であることを証明してください。

1は計算の問題、2は知識の問題、3は証明の問題である。Xwin-Math-70Bは日本語が苦手なようなので英語で質問してみる。

質問1

「Please list and add up all prime numbers below 100.」

GPT-4

2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97

When added up, they sum to 1060.

シンプルかつ正しい答え。

Xwin-Math-70B

A prime number is a natural number greater than 1 that has no positive divisors other than 1 and itself. The first few prime numbers are:
2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, and so on.

To find all prime numbers below 100, we need to list all the prime numbers from 2 to 99. Now let's add them up:

2 + 3 + 5 + 7 + 11 + 13 + 17 + 19 + 23 + 29 + 31 + 37 + 41 + 43 + 47 + 53 + 59 + 61 + 67 + 71 + 73 + 79 + 83 + 89 = 888

So, the sum of all prime numbers below 100 is 888.

The answer is: 888.

97が抜けている。足し算も間違っており、888ではなく963が正しい。ただ、かなり惜しいので量子化していなかったら正しく答えてるかもしれない。

質問2

「Is a metric space also a topological space?」

GPT-4

Yes, a metric space is also a topological space. In fact, every metric space can naturally be considered as a topological space, because the concept of open sets in a metric space, used to define a topology, naturally arises from the concept of distances, which is defined by the metric in the metric space. So, a metric space comes with an inherent topology, known as the metric topology.

日本語訳:

はい、距離空間は位相空間でもあります。実際、すべての距離空間は自然に位相空間として考えることができます。なぜなら、距離空間における開集合の概念は、トポロジーを定義するのに使われ、距離の概念から自然に生じるからです。距離の概念は距離空間内の距離によって定義されます。したがって、距離空間には自己明示的な位相、すなわち距離位相が付随しています。

Xwin-Math-70B

A metric space is a type of space that has a distance function, which allows us to determine the distance between any two points in the space. A topological space, on the other hand, is a type of space where we can determine the closeness or openness of sets of points based on their relationships with one another.

The answer is yes: every metric space is also a topological space. This is because the distance function in a metric space allows us to define what it means for two points to be close, which is the fundamental building block of a topology.

In particular, we can use the following method to turn any given metric space into a topological space:

  1. Define an open set as any set that contains all its limit points (i.e., any point that can be arbitrarily closely approached by other points in the set).
  2. Use the distance function to determine when two points are close enough for one to be considered a limit point of the other.
  3. Apply these definitions and use the properties of the metric space to build up the rest of the topology.

So, while not all topological spaces are necessarily metric spaces (because they don's always have a defined distance function), every metric space can indeed be a topological space by using its distance function in this way.

The answer is: Yes.

日本語訳:

距離空間は、空間内の任意の2点間の距離を決定する距離関数がある種類の空間です。一方、位相空間は、点の集合の閉じた性質あるいは開いた性質を、相互の関係に基づいて決定することができる種類の空間です。

答えは「はい」で、全ての距離空間は位相空間でもあります。これは、距離空間の距離関数が2つの点が近いという意味を定義することを可能にし、これは位相の基本的な構成要素であるためです。

特に、以下の方法を使用して任意の与えられた距離空間を位相空間に変換することができます:

  1. 開集合を、その集合内の他の点によって任意に近付けることができる任意の点(つまり、すべての極限点)を含む任意の集合として定義します。
  2. 2つの点が他方が一方の極限点と見なされるほど近いときに、距離関数を使用して決定します。
  3. これらの定義を適用し、距離空間の性質を使用してトポロジーの残りの部分を構築します。

したがって、全ての位相空間が必ずしも距離空間であるわけではありません(なぜなら、必ずしも定義された距離関数を持っているわけではないからです)、しかし全ての距離空間はこのように距離関数を使用することにより確かに位相空間になることができます。

答えは「はい」です。

正しそう。知識系の問題は得意なようだ。

質問3

「Please prove that the identity element is unique in a group.」

GPT-4

A group by definition is a set G equipped with an operation * that combines any two elements a and b to form another element denoted a * b. The operation satisfies four conditions including the existence of an identity element. The identity element, sometimes denoted as e or 1, is a special element of G such that for every a in G, the equations e * a and a * e return a.

Now we prove the identity element is unique.

Suppose there are two identity elements, e and e'.
By the definition of an identity, e * e' should be both equal to e (since e'* e gives e by the definition of identity e') and to e' (since e * e' gives e' by the definition of identity e).
So we have e = e * e' = e', showing that the two identity elements are actually the same.

Therefore, the identity in a group is unique.

日本語訳:

群は、定義により、2つの要素aとbを組み合わせて別の要素a * bを形成する演算*を備えた集合Gです。この演算は、単位元の存在を含む4つの条件を満たします。単位元は、時折eまたは1と記され、全てのG内のaに対して、方程式e * a と a * eがaを返す特別な要素です。

次に、単位元が一意であることを証明します。

単位元が2つ、e と e' が存在すると仮定しましょう。
単位元の定義により、e * e' は、e (単位元e'の定義により、e' * e はeを返すから)とe' (単位元eの定義により、e * e' はe'を返すから)の両方に等しくなければなりません。
したがって、e = e * e' = e' となり、2つの単位元が実際には同じであることが示されます。

したがって、群における単位元は一意です。

Xwin-Math-70B

To prove that the identity element is unique in a group, we need to show that there is only one element that satisfies the properties of an identity element.

An identity element has two main properties:

  1. When multiplied by any other element in the group, it does not change the original element (i.e., it is self-inverse). In mathematical terms, for every a in G, we have a e = a and e a = a, where e is the identity element.
  2. It has no multiplicative inverse other than itself. In mathematical terms, if a * b = e, then a and b are equal to each other and also equal to e.

Let's assume there exists another element f in the group that satisfies these properties as well:

  1. For every a in G, we have a f = a and f a = a.
  2. It has no multiplicative inverse other than itself, i.e., if a * b = f, then a and b are equal to each other and also equal to f.

Now let's consider the following:
If e * f = e (as both e and f are self-inverse), we have two cases:

  1. If e = f, which means that there is only one identity element in the group.
  2. If e ≠ f, then their product should be equal to a third distinct identity element, but this contradicts our assumption of having only two unique elements (e and f) with these properties.

Therefore, we can conclude that the identity element must be unique in any group.

The answer is: 1234567890.

日本語訳:

群内で単位元が一意であることを証明するためには、単位元の性質を満たす要素が一つだけであることを示す必要があります。

単位元は2つの主要な性質を持っています:

  1. 群内の任意の他の要素によって掛けられても元の要素は変わらない(つまり、自己反転です)。数学的な用語で言えば、G内の全てのaに対して、ae = a および ea = a が成り立ており、ここでeは単位元です。
  2. それ自体以外の乗法逆数はありません。数学的な用語で言えば、ab = e の場合、aとbは互いに等しく、eにも等しい。

さらに、これらの性質を満たす群内の別の要素fが存在すると仮定してみましょう:

  1. G内の全てのaに対して、af = a および fa = a が成り立つ。
  2. それ自身以外の乗法逆数はありません、つまり、a * b = f の場合、a と b は互いに等しく、fにも等しい。

次に以下の考え方を行ってみましょう:
e * f = e (eとfは自己反転なので)を満たす場合、以下の2つのケースがあります:

  1. e = f の場合、これは群内に単位元が一つだけであることを意味します。
  2. e ≠ f の場合、それらの積は第三の異なる単位元に等しくなければならないが、これはこれらの性質を持つ2つのユニークな要素(eとf)が存在するという仮定に反します。

したがって、群の単位元は一意でなければならないと結論付けることができます。

答えは: 1234567890です。

正しそうだが余計な情報を含んでいるように見える。

おわりに

Xwin-Math-70Bを試してみた。数学特化型LLMには証明が正しくできるように発展してほしいなぁ。今後に期待。

脚注
  1. https://tatsu-lab.github.io/alpaca_eval/ ↩︎

  2. https://zenn.dev/derbuihan/articles/928ae5f279afbc ↩︎

Discussion