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?

DiffLlama-1Bは『雪国』の続きをどう生成するのか

Posted at

日本語DiffLlamaモデル「DiffLlama-1B」がリリースされていたので、Google Colaboratory (GPU版)で試しに動かしてみた。

!pip install transformers flash-attn
from transformers import pipeline
tgn=pipeline("text-generation","kajuma/DiffLlama-1B",max_new_tokens=128)
nlp=lambda txt:tgn(txt)[0]["generated_text"]
print(nlp("国境の長いトンネルを抜けると雪国であった。夜の底が白くなった。"))

『雪国』冒頭部の続きを生成させてみたところ、私(安岡孝一)の手元では以下の結果が出力された。

国境の長いトンネルを抜けると雪国であった。夜の底が白くなった。
「雪国」
「雪国」
「雪国」
「雪国」
「雪国」
「雪国」
「雪国」
「雪国」
「雪国」
「雪国」
「雪国」
「雪国」
「雪国」
「雪国」
「雪国」
「雪国」
「雪国」
「雪国」
「雪国」
「雪国」
「雪国」
「雪国」
「雪国」
「雪国」
「雪国」
「雪

あまりうまく動いていないように見える。2024年6月11日の記事の手法で、Few-Shot Promptingによる品詞付与も試してみよう。

!pip install transformers flash-attn
model="kajuma/DiffLlama-1B"
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",model,max_new_tokens=128)
nlp=lambda t:"\n".join(tgn(str(ex)+f"###text:{t}\n###UPOS:")[0]["generated_text"].split("\n")[len(ex)*2:len(ex)*2+2])
print(nlp("国境の長いトンネルを抜けると雪国であった。"))

私の手元では、以下の結果が得られた。

###text:国境の長いトンネルを抜けると雪国であった。
###UPOS:しかし、そのトンネルを抜けると雪国ではなかった。

品詞付与もうまくできないようだ。うーん、私の使い方が間違ってるのかしら。

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?