How to generate an attention mask after padding?
After padding a tensor A which has 4 dimensions [4, 5, 129, 24] in second and third dimension to [4, 6, 136, 24], how can I generate its' attention mask?
I have figured out two solutions:

The first one is to create a zero-tensor A_attention that likes A_pad，and then traverse A to fill 1 to relevant position in A_attention.
The second one is to create attention mask in the padding procedure. But it seems a little troublesome because the initial tensor A has 4 dimensions.

Are there any ways to generate attention mask more efficiently after padding? Is there an API?
Thank you very much.

You can try to use the Transformers library from Hugging Face, which provides a really useful tokenizer.
I suggest you go through the entire quickstart, but in principle, this is the part you are interested in.
