LLM [科学、数学]
今週末は、土日とも雨になってしまいましたので、先週の桜の写真を
先週、google/flan-t5-xxlというLLM(Large Language Model)を試しましたが、今回は、それよりも小さなメモリで動くgoogle/flan-ul2 (https://huggingface.co/google/flan-ul2 ) というのを使ってみました。
huggingfaseのサイトの使い方
https://huggingface.co/google/flan-ul2#using-the-model
を見ると、簡単な計算問題もできるらしいです。
Answer the following question by reasoning step by step. The cafeteria had 23 apples. If they used 20 for lunch, and bought 6 more, how many apple do they have?
に対して、
They have 23 - 20 = 3 apples left. They have 3 + 6 = 9 apples. Therefore, the answer is 9.
と、答える例が書かれていました。
このままのデーターが学習データに入っているのではなく、ちゃんと文を理解して計算してるのか、数字を変えて質問してみました。
Q: Answer the following question by reasoning step by step. The cafeteria had 23 apples. If they used 19 for lunch, and bought 6 more, how many apple do they have?
A: They have 23 - 19 = 4 apples left. They have 4 + 6 = 10 apples. Therefore, the answer is 10.
ちゃんとできてます。
ちなみに、flan-t5では、
The cafeteria has 23 - 19 = 4 apples. They have 4 + 6 = 10 apples. Therefore, the answer is 10.
という答えが返ってきます。
Q: "Why Do Japanese People Love Sakura so Much?"
A: Sakura is a symbol of the beauty of life and the transience of life.
flan-t5では、Japanese people love cherry blossomstという、そっけない答えだったけど、
「桜は、命の美しさと儚さのシンボルだから」って、どこで、こんなこと覚えたのでしょう?
手塚治虫の「アドルフに告ぐ」で、大和魂って知ってるのかと聞かれたアドルフ・カミルが、「ひさかたのォ、光のどけき春の日に、しず心なく花の散るらん、でっしゃろ」って答えたのを思い出してしまいました。
Q: How do you investigate vitamin C content in food and drinks?
A: You can look at the label on the package.
食品や飲料品にビタミンCが入っているかどうか調べる方法は?
「パッケージのラベルを見ろ」って、 「spectrophotometer ( 分光光度計 )を使え」って答えたflan-t5より上手かもしれない。
次は、イギリスの中学生の学力テストGCSEの例題
Q: Why did the discoveries of the Renaissance make little practical difference to medical treatment in the period c1500-c1700?
( ルネサンス期の発見が、1500年から1700年の間、医療にほとんど実用的な進歩をもたらさなかったのはなぜか?)
これは、flan-t5では、
syphilis was cured
( 梅毒が治ったから )
という、意味不明な答えでしたが、
flan-ul2は、
the medical profession was dominated by quacks
( 医療の専門家がヤブ医者ばっかりだったから ) って、なんかすごいぞ flan-ul2
( ちなみに、GCSEでは回答として、ルネッサンス期の発見は、解剖学とか外科的なものが中心だったので、医療の進歩には、あまり貢献しなかった。のようなものを期待しています。)
先週、google/flan-t5-xxlというLLM(Large Language Model)を試しましたが、今回は、それよりも小さなメモリで動くgoogle/flan-ul2 (https://huggingface.co/google/flan-ul2 ) というのを使ってみました。
huggingfaseのサイトの使い方
https://huggingface.co/google/flan-ul2#using-the-model
を見ると、簡単な計算問題もできるらしいです。
Answer the following question by reasoning step by step. The cafeteria had 23 apples. If they used 20 for lunch, and bought 6 more, how many apple do they have?
に対して、
They have 23 - 20 = 3 apples left. They have 3 + 6 = 9 apples. Therefore, the answer is 9.
と、答える例が書かれていました。
このままのデーターが学習データに入っているのではなく、ちゃんと文を理解して計算してるのか、数字を変えて質問してみました。
Q: Answer the following question by reasoning step by step. The cafeteria had 23 apples. If they used 19 for lunch, and bought 6 more, how many apple do they have?
A: They have 23 - 19 = 4 apples left. They have 4 + 6 = 10 apples. Therefore, the answer is 10.
ちゃんとできてます。
ちなみに、flan-t5では、
The cafeteria has 23 - 19 = 4 apples. They have 4 + 6 = 10 apples. Therefore, the answer is 10.
という答えが返ってきます。
Q: "Why Do Japanese People Love Sakura so Much?"
A: Sakura is a symbol of the beauty of life and the transience of life.
flan-t5では、Japanese people love cherry blossomstという、そっけない答えだったけど、
「桜は、命の美しさと儚さのシンボルだから」って、どこで、こんなこと覚えたのでしょう?
手塚治虫の「アドルフに告ぐ」で、大和魂って知ってるのかと聞かれたアドルフ・カミルが、「ひさかたのォ、光のどけき春の日に、しず心なく花の散るらん、でっしゃろ」って答えたのを思い出してしまいました。
Q: How do you investigate vitamin C content in food and drinks?
A: You can look at the label on the package.
食品や飲料品にビタミンCが入っているかどうか調べる方法は?
「パッケージのラベルを見ろ」って、 「spectrophotometer ( 分光光度計 )を使え」って答えたflan-t5より上手かもしれない。
次は、イギリスの中学生の学力テストGCSEの例題
Q: Why did the discoveries of the Renaissance make little practical difference to medical treatment in the period c1500-c1700?
( ルネサンス期の発見が、1500年から1700年の間、医療にほとんど実用的な進歩をもたらさなかったのはなぜか?)
これは、flan-t5では、
syphilis was cured
( 梅毒が治ったから )
という、意味不明な答えでしたが、
flan-ul2は、
the medical profession was dominated by quacks
( 医療の専門家がヤブ医者ばっかりだったから ) って、なんかすごいぞ flan-ul2
( ちなみに、GCSEでは回答として、ルネッサンス期の発見は、解剖学とか外科的なものが中心だったので、医療の進歩には、あまり貢献しなかった。のようなものを期待しています。)
さくらさく [相鉄沿線]
こども自然公園の桜山の桜
一分咲きぐらいになっていました。
一本桜は、七分咲きぐらいかな?
大きなヤマザクラ
大きな猫
最近、大きなCatGPTじゃなくて、ChatGPTなどの大規模言語モデル(LLM:Large Language Model)が話題になっていますね。
MetaのLLaMAやGoogleのFlan-T5のように、モデルが公開されていて、メモリの大きなパソコンなら動かせるようなものもあるんですね。
メモリ48GBのGPUを使える機会があったので、Flan-T5のXXL( https://huggingface.co/google/flan-t5-xxl )というのを試してみました。
PyTorchとtransformers, sentencepiece, accelerateがインストールしてある環境だとたった3行でmodelを読み込んで使えるらしいです。
from transformers import T5Tokenizer, T5ForConditionalGeneration
tokenizer = T5Tokenizer.from_pretrained("google/flan-t5-xxl")
model = T5ForConditionalGeneration.from_pretrained("google/flan-t5-xxl", device_map="auto")
メモリは、40GBぐらい使うので、まだ普通のノートパソコンで動かすのは無理そうですね。
input_text = "What is the National Flower of Japan?"
input_ids = tokenizer(input_text, return_tensors="pt").input_ids.to("cuda")
outputs = model.generate(input_ids, max_length=200, bos_token_id=0)
result = tokenizer.decode(outputs[0], skip_special_tokens=True)
print(result)
sakura
CPU times: user 323 ms, sys: 5.6 ms, total: 329 ms
Wall time: 324 ms
日本の花は、sakuraって0.3秒で返ってきました。
Q.: "Why Do Japanese People Love Sakura so Much?"
A : Japanese people love cherry blossoms
日本人は、なぜそんなに桜がすきなの?って聞いたら、桜の花が好きだからって言うから、子供のなぜなぜ攻撃じゃないけど、
Q : "Why Do Japanese people love cherry blossoms?"
A : they are a symbol of spring
Q : "Why are cherry blossoms a symbol of spring ?"
A : they bloom in spring
なんか、きりがないですね...
Q : "How to enjoy Japanese cherry blossoms ?"
A : Go to a park and look for the cherry blossoms
LLMすごい。
翻訳もできるみたいなので、家にあったフランス語のテキストから
Q : "translate French to English: 'Quel est le plus long fleuve du monde ?' "
A : What is the longest river in the world?
簡単すぎたかな?
Q : "translate French to English: Il ramona soigneusement ses volcans en activite."
A : He carefully monitors his volcanoes in action.
星の王子様が、火山の灰を注意深く、お掃除するお話なのですが、火山の活動を注意深く観測するっていう、常識的な意味になるような意訳をしてきました。
学力テストとかは、どうかな、
英国の学力テストKey Stage 5 の問題例
Q : "How do you investigate vitamin C content in food and drinks?"
A : To determine the vitamin C content of food and drinks, you can use a spectrophotometer.
Key Stage 5 では、回答としてDCPIP(ジクロロフェノールインドフェノール)を使った方法を期待しているのですが(参考: https://practicalbiology.org/health-and-disease/what-s-in-our-food/measuring-the-vitamin-c-content-of-foods-and-fruit-juices ) 、 spectrophotometer (分光光度計)って答えられてしまうと、日本だと学校で教えてないことはバツですってなっちゃいますね。
大学入試レベルのCCEA test questionsの例
Q : "What is a plasmid?"
A : a small circular molecule of DNA
なんか、くやしいな...
Q : "What is the smallest country in the world ?"
A : san marino
初めて、間違えました。
Q : "Which country is smaller than San Marino?"
A : switzerland
Q: "Which is a smaller country, Switzerland or San Marino ?"
A : San Marino
今日は、このへんにしておきましょう。
一分咲きぐらいになっていました。
一本桜は、七分咲きぐらいかな?
大きなヤマザクラ
大きな猫
最近、大きなCatGPTじゃなくて、ChatGPTなどの大規模言語モデル(LLM:Large Language Model)が話題になっていますね。
MetaのLLaMAやGoogleのFlan-T5のように、モデルが公開されていて、メモリの大きなパソコンなら動かせるようなものもあるんですね。
メモリ48GBのGPUを使える機会があったので、Flan-T5のXXL( https://huggingface.co/google/flan-t5-xxl )というのを試してみました。
PyTorchとtransformers, sentencepiece, accelerateがインストールしてある環境だとたった3行でmodelを読み込んで使えるらしいです。
from transformers import T5Tokenizer, T5ForConditionalGeneration
tokenizer = T5Tokenizer.from_pretrained("google/flan-t5-xxl")
model = T5ForConditionalGeneration.from_pretrained("google/flan-t5-xxl", device_map="auto")
メモリは、40GBぐらい使うので、まだ普通のノートパソコンで動かすのは無理そうですね。
input_text = "What is the National Flower of Japan?"
input_ids = tokenizer(input_text, return_tensors="pt").input_ids.to("cuda")
outputs = model.generate(input_ids, max_length=200, bos_token_id=0)
result = tokenizer.decode(outputs[0], skip_special_tokens=True)
print(result)
sakura
CPU times: user 323 ms, sys: 5.6 ms, total: 329 ms
Wall time: 324 ms
日本の花は、sakuraって0.3秒で返ってきました。
Q.: "Why Do Japanese People Love Sakura so Much?"
A : Japanese people love cherry blossoms
日本人は、なぜそんなに桜がすきなの?って聞いたら、桜の花が好きだからって言うから、子供のなぜなぜ攻撃じゃないけど、
Q : "Why Do Japanese people love cherry blossoms?"
A : they are a symbol of spring
Q : "Why are cherry blossoms a symbol of spring ?"
A : they bloom in spring
なんか、きりがないですね...
Q : "How to enjoy Japanese cherry blossoms ?"
A : Go to a park and look for the cherry blossoms
LLMすごい。
翻訳もできるみたいなので、家にあったフランス語のテキストから
Q : "translate French to English: 'Quel est le plus long fleuve du monde ?' "
A : What is the longest river in the world?
簡単すぎたかな?
Q : "translate French to English: Il ramona soigneusement ses volcans en activite."
A : He carefully monitors his volcanoes in action.
星の王子様が、火山の灰を注意深く、お掃除するお話なのですが、火山の活動を注意深く観測するっていう、常識的な意味になるような意訳をしてきました。
学力テストとかは、どうかな、
英国の学力テストKey Stage 5 の問題例
Q : "How do you investigate vitamin C content in food and drinks?"
A : To determine the vitamin C content of food and drinks, you can use a spectrophotometer.
Key Stage 5 では、回答としてDCPIP(ジクロロフェノールインドフェノール)を使った方法を期待しているのですが(参考: https://practicalbiology.org/health-and-disease/what-s-in-our-food/measuring-the-vitamin-c-content-of-foods-and-fruit-juices ) 、 spectrophotometer (分光光度計)って答えられてしまうと、日本だと学校で教えてないことはバツですってなっちゃいますね。
大学入試レベルのCCEA test questionsの例
Q : "What is a plasmid?"
A : a small circular molecule of DNA
なんか、くやしいな...
Q : "What is the smallest country in the world ?"
A : san marino
初めて、間違えました。
Q : "Which country is smaller than San Marino?"
A : switzerland
Q: "Which is a smaller country, Switzerland or San Marino ?"
A : San Marino
今日は、このへんにしておきましょう。