# マスク位置の単語を予測 print(nlp(f'Once upon a time there was a young lady and an old {nlp.tokenizer.mask_token}.'))
単語の予測結果として次の情報が出力されます。
sequence 予測した単語を埋め込んだ文章
score スコア
token_str 予測した単語
[実行結果]
1 2 3 4 5
[{'sequence': 'Once upon a time there was a young lady and an old gentleman.', 'score': 0.49178990721702576, 'token': 22164, 'token_str': ' gentleman'}, {'sequence': 'Once upon a time there was a young lady and an old man.', 'score': 0.2817203998565674, 'token': 313, 'token_str': ' man'}, {'sequence': 'Once upon a time there was a young lady and an old boy.', 'score': 0.08439457416534424, 'token': 2143, 'token_str': ' boy'}, {'sequence': 'Once upon a time there was a young lady and an old lady.', 'score': 0.06599652022123337, 'token': 6429, 'token_str': ' lady'}, {'sequence': 'Once upon a time there was a young lady and an old woman.', 'score': 0.01124062854796648, 'token': 693, 'token_str': ' woman'}]
5つの単語が予測されました。
スコア 49 [gentleman] 「a young lady」に対して「an old gentleman」は自然な予測だと思います。
スコア 28 [man] 「a young lady」に対して「an old man」も自然な予測ではないでしょうか。
スコア 8 [boy] 「an old boy」は単語として不自然な感じがします。
スコア 6 [lady] 「a young lady」に対して「an old lady」も老若の女性ということで自然ですね。
スコア 1 [woman] 「a young lady」に対して「an old woman」も特に問題なさそうです。
Some weights of GPT2Model were not initialized from the model checkpoint at gpt2 and are newly initialized: ['h.0.attn.masked_bias', 'h.1.attn.masked_bias', 'h.2.attn.masked_bias', 'h.3.attn.masked_bias', 'h.4.attn.masked_bias', 'h.5.attn.masked_bias', 'h.6.attn.masked_bias', 'h.7.attn.masked_bias', 'h.8.attn.masked_bias', 'h.9.attn.masked_bias', 'h.10.attn.masked_bias', 'h.11.attn.masked_bias'] You should probably TRAIN this model on a down-stream task to be able to use it for predictions and inference. Setting `pad_token_id` to `eos_token_id`:50256 for open-end generation. [{'generated_text': 'Once upon a time there was an old man and an old woman. One was a very good maid on whom the women worked while the young men worked in the yard.\n\nThis time in the middle of the night, the young maid ran off the edge of the street, followed by several other girls, and as they approached the old maid came the other to speak to this man. He gave her a call and said he had come for someone. The young maid took the call, and found'}]
生成されたテキストを訳すとだいたい次のような感じです。
Once upon a time there was an old man and an old woman. 昔々、おじいさんとおばあさんがいました。
One was a very good maid on whom the women worked while the young men worked in the yard. 一人は、若い男性が庭で働いている間、女性が働いていたとても良いメイドでした。
This time in the middle of the night, the young maid ran off the edge of the street, followed by several other girls, and as they approached the old maid came the other to speak to this man. 今回は真夜中に、若いメイドが通りの端から逃げ出し、他の何人かの女の子が続き、彼らが近づくと、古いメイドがこの男と話すためにもう一人来ました。
He gave her a call and said he had come for someone. The young maid took the call, and found 彼は彼女に電話をかけ、誰かのために来たと言いました。若いメイドが電話に出て、見つけました。
# テキスト text = 'Huggingface Transformers is a deep learning framework provided by Huggingface that specializes in natural language processing. It supports both TensorFlow and PyTorch. You can use deep learning to solve natural language processing tasks such as text classification, question answering, and summary.'
# コンテキスト context = 'Huggingface Transformers is a deep learning framework provided by Huggingface that specializes in natural language processing. It supports both TensorFlow and PyTorch. You can use deep learning to solve natural language processing tasks such as text classification, question answering, and summary.'
# 質問 question = 'What is a natural language processing task?'