Lola Le Breton, Quentin Fournier, Mariam El Mezouar, Sarath Chandar『NeoBERT: A Next-Generation BERT』を横目に、NeoBERTを使ってみることにした。Google Colaboratoryだと、こんな感じ。
!pip install -U transformers xformers torchvision
from transformers import AutoTokenizer,AutoModelForMaskedLM,FillMaskPipeline
tkz=AutoTokenizer.from_pretrained("chandar-lab/NeoBERT")
mdl=AutoModelForMaskedLM.from_pretrained("chandar-lab/NeoBERT",trust_remote_code=True)
fmp=FillMaskPipeline(tokenizer=tkz,model=mdl)
print(fmp("It don't [MASK] a thing if it ain't got that swing"))
「It don't [MASK] a thing if it ain't got that swing」の[MASK]に何を埋めてくるのか試したところ、私(安岡孝一)の手元では以下の結果が得られた。
[{'score': 0.9794992804527283, 'token': 2812, 'token_str': 'mean', 'sequence': "it don ' t mean a thing if it ain ' t got that swing"}, {'score': 0.0026010603178292513, 'token': 2342, 'token_str': 'need', 'sequence': "it don ' t need a thing if it ain ' t got that swing"}, {'score': 0.002511243801563978, 'token': 3465, 'token_str': 'cost', 'sequence': "it don ' t cost a thing if it ain ' t got that swing"}, {'score': 0.002277001040056348, 'token': 17042, 'token_str': 'weigh', 'sequence': "it don ' t weigh a thing if it ain ' t got that swing"}, {'score': 0.002097407588735223, 'token': 2965, 'token_str': 'means', 'sequence': "it don ' t means a thing if it ain ' t got that swing"}]
「mean」が98%でダントツなあたり、この英文をNeoBERTは知っているのだろう。ただ、NeoBERTのmodel.pyには、系列ラベリング(token classification)が見当たらない。https://github.com/chandar-lab/NeoBERT も、今のところリンクが繋がらない。いくら入出力幅4096トークンとは言っても、係り受け解析に使うには情報がなさすぎるのだけど、待てば何とかなるのかしら。