【transformer各函數(shù)功能2encoderlayer】2021-04-08

1.輸入的維度為模型的維度,是上一層線性轉(zhuǎn)化之后的模型維度,輸出的維度是d_k=d_q 乘上頭數(shù)

1024

64*16=1024


(layer_stack): ModuleList(

? ? ? (0): EncoderLayer(

? ? ? ? (slf_attn): MultiHeadAttention(

? ? ? ? ? (w_qs): Linear(in_features=256, out_features=1024, bias=True)

? ? ? ? ? (w_ks): Linear(in_features=256, out_features=1024, bias=True)

? ? ? ? ? (w_vs): Linear(in_features=256, out_features=1024, bias=True)

? ? ? ? ? (attention): ScaledDotProductAttention(

? ? ? ? ? ? (dropout): Dropout(p=0.1, inplace=False)

? ? ? ? ? ? (softmax): Softmax(dim=2)

? ? ? ? ? )

? ? ? ? ? (layer_norm): LayerNorm((256,), eps=1e-05, elementwise_affine=True)

? ? ? ? ? (fc): Linear(in_features=1024, out_features=256, bias=True)

? ? ? ? ? (dropout): Dropout(p=0.1, inplace=False)

? ? ? ? )

2.1280是d_inner 在計算attention之后用一個全連接轉(zhuǎn)為256模型維度


模型維度做一個前饋傳播(也是自己設(shè)定中間的維度)(看函數(shù)好像是做了一個殘差連接最后的out put 加上了殘差)

? (pos_ffn): PositionwiseFeedForward(

? ? ? ? ? (w_1): Linear(in_features=256, out_features=1280, bias=True)

? ? ? ? ? (w_2): Linear(in_features=1280, out_features=256, bias=True)

? ? ? ? ? (dropout): Dropout(p=0.1, inplace=False)

? ? ? ? ? (layer_norm): LayerNorm((256,), eps=1e-05, elementwise_affine=True)

? ? ? ? )

? ? ? )












3.返回的是enc_output,和 enc_slf_attn

?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容