0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

Fugaku-LLM-13BでのFew-Shot Promptingによる日本語品詞付与

Posted at

Terra Blevins, Hila Gonen, Luke Zettlemoyer『Prompting Language Models for Linguistic Structure』の手法をFugaku-LLM-13Bに適用して、国語研短単位でのUPOS (Universal Part-Of-Speech)品詞付与に挑戦してみた。5つの例文は、この記事と全く同じものを選んだ。

>>> class TextUPOSList(list):
...   __str__=lambda self:"\n".join("###text:"+"".join(t for t,u in s)+"\n###UPOS:"+"|".join(t+"_"+u for t,u in s) for s in self)+"\n"
...
>>> ex=TextUPOSList()
>>> ex.append([("一","NUM"),("直線","NOUN"),("に","ADP"),("伸びる","VERB"),("電撃","NOUN"),("を","ADP"),("放ち","VERB"),("、","PUNCT"),("電撃","NOUN"),("ダメージ","NOUN"),("を","ADP"),("与える","VERB"),("。","PUNCT")])
>>> ex.append([("色々","ADV"),("と","ADP"),("面白い","ADJ"),("メニュー","NOUN"),("の","ADP"),("ある","VERB"),("店","NOUN"),("。","PUNCT")])
>>> ex.append([("しかも","CCONJ"),("、","PUNCT"),("ここ","PRON"),("は","ADP"),("コース","NOUN"),("が","ADP"),("リーズナブル","ADJ"),("な","AUX"),("の","SCONJ"),("です","AUX"),("。","PUNCT")])
>>> ex.append([("彼","PRON"),("は","ADP"),("コンピュータ","NOUN"),("を","ADP"),("個人","NOUN"),("の","ADP"),("持ち物","NOUN"),("に","ADP"),("し","VERB"),("まし","AUX"),("た","AUX"),("。","PUNCT")])
>>> ex.append([("2007","NUM"),("年","NOUN"),("9","NUM"),("月","NOUN"),("現在","ADV"),("、","PUNCT"),("以下","NOUN"),("の","ADP"),("メーカー","NOUN"),("から","ADP"),("対応","NOUN"),("製品","NOUN"),("が","ADP"),("発売","VERB"),("さ","AUX"),("れ","AUX"),("て","SCONJ"),("いる","VERB"),("。","PUNCT")])
>>> from transformers import pipeline
>>> tgn=pipeline("text-generation","Fugaku-LLM/Fugaku-LLM-13B",max_new_tokens=128,token="hf_this_token_is_dummy_use_your_own_one")
>>> print("\n".join(tgn(str(ex)+"###text:国境の長いトンネルを抜けると雪国であった。\n###UPOS:")[0]["generated_text"].split("\n")[len(ex)*2:len(ex)*2+2]))
###text:国境の長いトンネルを抜けると雪国であった。
###UPOS:国境_NOUN|の_ADP|長い_NOUN|トンネル_NOUN|を_ADP|抜ける_VERB|と_ADP|雪国_NOUN|で_ADP|あった_VERB|。_PUNCT

『雪国』の冒頭文に品詞付与させてみたところ、私(安岡孝一)の手元では、Fugaku-LLM-13Bは「長い_ADJ」と「で_AUX|あっ_AUX|た_AUX」にうまく品詞付与できなかった。もう一度やってみよう。

>>> print("\n".join(tgn(str(ex)+"###text:国境の長いトンネルを抜けると雪国であった。\n###UPOS:")[0]["generated_text"].split("\n")[len(ex)*2:len(ex)*2+2]))
###text:国境の長いトンネルを抜けると雪国であった。
###UPOS:国境_NOUN|の_ADP|長い_NOUN|トンネル_NOUN|を_ADP|抜ける_VERB|と_ADP|雪国_NOUN|で_ADP|あった_VERB|。_PUNCT

どうやら同じ結果だ。ならば「予想に反して品詞付与の精度がイマイチ」という文はどうだろう。

>>> print("\n".join(tgn(str(ex)+"###text:予想に反して品詞付与の精度がイマイチ\n###UPOS:")[0]["generated_text"].split("\n")[len(ex)*2:len(ex)*2+2]))
###text:予想に反して品詞付与の精度がイマイチ
###UPOS:予想_ADV|に_ADP|反して_ADP|品詞_NOUN|付与_NOUN|の_ADP|精度_NOUN|が_ADP|イマイチ_NOUN|。_PUNCT

予想_NOUN」と「反し_VERB|て_SCONJ」にうまく品詞付与できていない上、「。_PUNCT」が勝手に追加されている。3月31日の記事に較べると、精度の点で見劣りがするようだ。Few-Shot Promptingによる品詞付与の精度って、どうすれば上げられるんだろう。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?