#目的
BERTに続いてXLNetを、ちょっと、動かしてみたいと思い、
ぐぐって、一瞬で動きそうな例を試してみた。
#選んだ例
あまり良いサイトに出会えなく、
以下のgithubのコードを動かしてみた。
https://github.com/zihangdai/xlnet
RACE(Reading Comprehension Dataset)という問題を解くための以下のコードを実行した。
run_race.py
#RACEの説明
以下は、RACEの一つの問題です。文章を理解して質問に答える(選択肢あり)。
{"answers": ["C", "D", "A", "A"], "options": [["take care of the whole group", "make sure that everybody finishes homework", "make sure that nobody chats in class", "collect all the homework and hand it in to teachers"], ["chat with each other", "listen to the teacher", "make friends", "communicate"], ["get benefits from", "are tired of", "cannot get used to", "hate"], ["Three.", "Four.", "Two.", "Five or six."]], "questions": ["A discipline leader is supposed to _ .", "The new way of learning is said to give students more chances to _ .", "We can see from the story that some students _ this new way of learning.", "How many leaders are there in one group?"], "article": "Take a class at Dulangkou School, and you'll see lots of things different from other schools, You can see the desks are not in rows and students sit in groups. They put their desks together so they're facing each other. How can they see the blackboard? There are three blackboards on the three walls of the classroom!\nThe school calls the new way of learning "Tuantuanzuo", meaning sitting in groups. Wei Liying, a Junior 3 teacher, said it was to give students more chances to communicate.\nEach group has five or six students, according to Wei, and they play different roles .There is a team leader who takes care of the whole group. There is a "study leader"who makes sure that everyone finishes their homework. And there is a discipline leader who makes sure that nobody chats in class.\nWang Lin is a team leader. The 15-year-old said that having to deal with so many things was tiring.\n"I just looked after my own business before,"said Wang. "But now I have to think about my five group members."\nBut Wang has got used to it and can see the benefits now.\n"I used to speak too little. But being a team leader means you have to talk a lot. You could even call me an excellent speaker today."\nZhang Qi, 16, was weak in English. She used to get about 70 in English tests. But in a recent test, Zhang got a grade of more than 80.\n"I rarely asked others when I had problems with my English tests. But now I can ask the team leader or study leader. They are really helpful."", "id": "middle1.txt"}
RACEは、
https://www.cs.cmu.edu/~glai1/data/race/
などからデータをダウンロードできると思います。
#run_race.py を実行させるためには
- RACEのダウンロード
- xlnet_cased_L-12_H-768_A-12のダウンロード
usageがないので、適当に、以下のオプションで実行しました。
内容、全く理解していません。エラーが出ないように適当にオプションを足したり
減らしたりしました。
python run_race.py --do_eval=True
--model_dir="./xlnet_cased_L-12_H-768_A-12"
--spiece_model_file="./xlnet_cased_L-12_H-768_A-12/spiece.model"
--data_dir="./data"
--model_config_path="./xlnet_cased_L-12_H-768_A-12/xlnet_config.json" --output_dir="./output"
--eval_batch_size=1
--train_eval=False --uncased=False
役立つかもしれない情報は以下。
(1)
メモリが足らないというようなエラーが出ましたので、
バッチサイズを最小にして逃げました。
--eval_batch_size=1
(2)
tensorflowのバージョンは、以下です。2.0.0以降はエラーになるのではないでしょうか。
tensorflow 1.15.3
#実行結果
以下の結果になりました。4択なので、出鱈目でも0.25なので、全く、正しく動作していないです!!!(問題数は、大半の問題を消して、数問にしました。。。)
⇒ 失敗
eval_accuracy = 0.22
I0806 18:16:47.620249 10828 evaluation.py:167] Evaluation [45/50]
INFO:tensorflow:Evaluation [50/50]
I0806 18:17:51.467021 10828 evaluation.py:167] Evaluation [50/50]
INFO:tensorflow:Finished evaluation at 2020-08-06-18:17:52
I0806 18:17:52.105508 10828 evaluation.py:275] Finished evaluation at 2020-08-06-18:17:52
INFO:tensorflow:Saving dict for global step 0: eval_accuracy = 0.22, eval_loss = 1.3860148, global_step = 0, loss = 1.3860148
I0806 18:17:52.121129 10828 estimator.py:2049] Saving dict for global step 0: eval_accuracy = 0.22, eval_loss = 1.3860148, global_step = 0, loss = 1.3860148
INFO:tensorflow:================================================================================
I0806 18:17:53.214434 10828 run_race.py:546] ================================================================================
INFO:tensorflow:Eval | eval_accuracy 0.2199999988079071 | eval_loss 1.3860148191452026 | loss 1.3860148191452026 | global_step 0 |
I0806 18:17:53.229773 10828 run_race.py:550] Eval | eval_accuracy 0.2199999988079071 | eval_loss 1.3860148191452026 | loss 1.3860148191452026 | global_step 0 |
INFO:tensorflow:================================================================================
I0806 18:17:53.229773 10828 run_race.py:551] ================================================================================
C:\_qiita\___xlnet\xlnet-master>
#まとめ
とりあえず、XLNetを動かしてみようとトライしましたが、提示したサイトのrun_race.pyで
まともな結果は出ませんでした。
多くの方が参照しているサイトなので、使い方が間違えていることは自明です。
役立つ情報としては、
(0)
XLNet、簡単に動かせないかも。
(1)
メモリ不足は、
--eval_batch_size=1
で回避できる。
(2)
提示のサイト(github)の場合、
tensorflowのバージョンは、2.0.0以降はエラーになる(?)。
ぐらいでしょうか。
コメントなどあれば、お願いします。