New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
can't use masks in multi-head-attention layer #2336
Comments
The layer's documentation for the forward pass says:
so I think you should reshape as. |
thanks now it's working |
@alerem18 which of the two reshaping is correct in your case? |
reshape(mask, (seq_len, 1, 1, batch_size)) |
however masking is wrong l = reduce(hcat, [[5, 2, 3, 1, 1], [4, 5, 6, 1, 1]])
mask = fill(true, 5, 5, 1, 2)
mask[4:5, :, :, :] .= 0
mask[:, 4:5, :, :] .= 0
emb_layer = Embedding(10, 128)
emb = emb_layer(l)
attn = MultiHeadAttention(128, nheads=2)
attn(emb, mask=mask)[2] result [:, :, 2, 1] = [:, :, 1, 2] = [:, :, 2, 2] = |
masking with shape (seq_len, 1, 1, batch_size) is ok but with shape (1, seq_len, 1, batch_size) return NaN |
Motivation and description
let's say we have an array of shape (embedding_size, seq_len, batch_size), our padding mask will have a shape of (seq_len, batch_size) which can't be used in multi-head-attension mask layer, we can only use casual masking which has the shape (seq_len, seq_len)
Possible Implementation
No response
The text was updated successfully, but these errors were encountered: