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)
? ? ? ? )
? ? ? )

