图片中的GPT-2(变形金刚语言模型的可视化)

openAI-GPT-2-3


在2019年,我们见证了机器学习的卓越应用。OpenAI GPT-2模型具有出色的书写连贯和情感文本的能力,这优于我们对现代语言模型可以生成的内容的理解。GPT-2并不是特别新颖的体系结构,它使人联想到Transformer-Decoder(仅解码器的Transformer)。GPT-2之间的区别在于,它是基于Transformer的真正庞大的语言模型,并在令人印象深刻的数据集上进行了训练。在本文中,我们将研究允许我们获得这种结果的模型的体系结构:我们将详细研究自我注意层以及解码Transformer用于超出语言建模的任务的用途。


内容



第1部分:GPT-2和语言建模


什么是语言建模?


什么是语言模型


Word2vec , – , , . – , .


快捷键键盘


, GPT-2 , , , . GPT-2 40 (WebText), OpenAI . , , SwiftKey, 78 , GPT-2 500 , GPT-2 – 13 ( 6,5 ).


gpt2尺寸


GPT-2 AllenAI GPT-2 Explorer. GPT-2 ( ), .



, – .. . – , - .


变压器-编码器-解码器


, , , , ( AlphaStar).


gpt-2-transformer-xl-bert-3


? , GPT-2 :


gpt2-sizes-hyperparameters-3


BERT'


:
, .

GPT-2 . BERT , , . . , GPT-2, , . , GPT-2 :


gpt-2-output


: , , . . «» (auto-regression) RNN .


gpt-2-autoregression-2


GPT-2 TransformerXL XLNet . BERT . . , BERT . XLNet , .



.



– :


transformer-encoder-block-2


(, 512 ). , .



– , . :


transformer-decoder-block-2


, [mask] , BERT', , , .


, , #4, , :


transformer-decoder-block-self-attention-2


, BERT, GPT-2. . :


self-attention-and-masked-self-attention



, «Generating Wikipedia by Summarizing Long Sequences» , : . «-». 6 :


transformer-decoder-intro


. , . , 4000 – 512 .


, , . « », / .


GPT-2 OpenAI .


- : GPT-2


, , . , , , , . (Budgie)

GPT-2 , .


gpt-2-layers-2


GPT-2 1024 . .


GPT-2 – ( ) (), (.. ). , ( <|endoftext|>; <|s|>).


gpt2-simple-output-2


, . , (score) – , (50 GPT-2). – «the». - – , , , , – . . GPT-2 top-k, , , (, , top-k = 1).


:


gpt-2-simple-output-3


, . GPT-2 ( ). GPT-2 .




. . NLP-, , – , .


gpt2-token-embeddings-wte-2


– , - . GPT-2. 768 /.


, <|s|> . , – , . , 1024 .


gpt2-positional-encoding


. , GPT-2.


gpt2-input-embedding-positional-encoding-3


#1.



, , . , . , , .


gpt2-transformer-block-vectors-2



. , :


, , , .

, . , . , , :


  • ;
  • (« »);
  • .

: , , ( ). , , .


, «a robot» «it». , , , .


gpt2-self-attention-example-2



. :


  • – , ( ). , ;
  • – . ;
  • – ; , , .

self-attention-example-folders-3


. – , . . , – . , .


(: ).


self-attention-example-folders-scores-3


, .


gpt2-value-vector-sum


, 50% «robot», 30% «a» 19% – «it». . .



( ), .


gpt2-output-projection-2


, . .


gpt2-output-scores-2


(top_k = 1). , . , , ( ). – top_k 40: 40 .


gpt2-output


, . , (1024 ) .


: GPT-2,


, , GPT-2. , , . , ( TransformerXL XLNet).


, :


  • «» «» ; GPT-2 (Byte Pair Encoding) . , .
  • GPT-2 / (inference/evaluation mode). . . (512), 1, .
  • / . .
  • , . Transformer , .
  • . «zoom in», :

zoom-in


2:


, «it»:


gpt2-self-attention-1-2


, . , , . , , .


( )


, . , 4 .


:


  1. , ;
  2. ;
  3. .

self-attention-summary


1 – ,


. . . ( «» ):


self-attention-1


, WQ, WK, WV


2 –


, , №2: .


self-attention-2


( ) ,


3 –


. , .


self-attention-3-2


 


, – , .


, , . ( ).



, , , . №2. , . . , :


masked-self-attention-2


, (attention mask). , , («robot must obey orders»). 4 : ( , – ). .. , 4 , ( 4 ) .


transformer-decoder-attention-mask-dataset


, . , , ( ), :


queries-keys-attention-mask


«» . , , – (-inf) (, -1 GPT-2):


transformer-attention-mask


, , , :


变压器注意屏蔽分数softmax


:


  • ( №1), («robot»), 100% .
  • ( №2), («robot must»), «must» 48% «robot» 52% «must».
  • ..

GPT-2


GPT-2.


:


, GPT-2 , . , , , .


( <|s|>).


gpt2-self-attention-qkv-1-2


GPT-2 «a». :


gpt2-self-attention-qkv-2-2


, «robot», , «a» – , :


gpt2-self-attention-qkv-3-2


GPT-2: 1 – ,


, «it». , «it» + #9:


gpt2-self-attention-1


( ), , .


gpt2-self-attention-2


(bias vector),


, , «it».


gpt2-self-attention-3


( ) ,


GPT-2: 1.5 – «»


, «» . . (Q), (K) (V). «» – . GPT-2 12 «» , :


gpt2自我注意分割注意力头1


, «» . «» , ( 12 «» ):


gpt2自我注意分割注意力头2


GPT-2: 2 –


( , «» ):


gpt2-自我注意得分


( «» #1 ):


gpt2-自我注意得分2


GPT-2: 3 –


, , , «» #1:


gpt2-self-attention-multihead-sum-1


GPT-2: 3.5 – «»


«» , , :


gpt2-self-attention-merge-heads-1


. .


GPT-2: 4 –


, , . , «» :


gpt2-self-attention-project-1


, , :


gpt2-self-attention-project-2


GPT-2: #1


– , , . . 4 ( GPT-2 768, 768*4 = 3072 ). ? ( 512 #1 – 2048). , , .


gpt2-mlp1


( )


GPT-2:


(768 GPT-2). .


gpt2-mlp-2


( )


!


, - . , . , , :


gpt2-transformer-block-weights-2


. , :


gpt2-weights-2


, :


gpt2-117参数


- 124 117. , , (, ).


3:


, . , . .



. :


解码器专用变压器翻译



, . , ( , ) . :


维基百科摘要


.


仅解码器摘要



Sample Efficient Text Summarization Using a Single Pre-Trained Transformer , . , , - .


GPT-2 .



. « » – (, « »).


, . , (), ( ). (, , ) «» – , .


音乐变压器性能编码3


– one-hot . midi . :


音乐表示示例


one-hot :


音乐变压器输入表示2


:


音乐变形金刚自我注意2


, . .



GPT-2 – . , , , , .




s



All Articles