Add missing attention mask in ASTFeatureExtractor
Author: lu-wo
Pull request: yes

The ASTFeatureExtractor has a return_attention_mask attribute, but even if set to true, the feature extractor does not return it, because the code to do so is missing. 

I added the code which checks the lengths of the raw audio arrays before computing the spectrograms and then creates the attention mask for each element in the batch accordingly. 

@sanchit-gandhi

- [ ] This PR fixes a typo or improves the docs (you can dismiss the other checks if that's the case).
- [x] Did you read the [contributor guideline](https://github.com/huggingface/transformers/blob/main/CONTRIBUTING.md#start-contributing-pull-requests),
      Pull Request section?
- [ ] Was this discussed/approved via a Github issue or the [forum](https://discuss.huggingface.co/)? Please add a link
      to it if that's the case.
- [x] Did you make sure to update the documentation with your changes? Here are the
      [documentation guidelines](https://github.com/huggingface/transformers/tree/main/docs), and
      [here are tips on formatting docstrings](https://github.com/huggingface/transformers/tree/main/docs#writing-source-documentation).
- [ ] Did you write any new necessary tests?


Comments:
The docs for this PR live [here](https://moon-ci-docs.huggingface.co/docs/transformers/pr_24738). All of your documentation changes will be reflected on that endpoint.

Hmm I believe this was omitted because Audio Spectrogram Transformer doesn't take a padding mask as input: https://github.com/huggingface/transformers/blob/cfc8a05305b4c89c5393766161d89ef24e72fdfa/src/transformers/models/audio_spectrogram_transformer/modeling_audio_spectrogram_transformer.py#L567
(only a head mask which is for masking out entire heads, not elements of the input sequence)

The way AST works is by padding / truncating all input audio samples to a fixed length, then computing the log-mel spectrogram on these adjusted inputs. Since we pad with zeros (silence), the model learns padding implicitly from the input features, and so doesn't require an attention mask. The same is done with the Whisper model, which also works directly on log-mel spectrograms: https://huggingface.co/blog/fine-tune-whisper#load-whisperfeatureextractor

So I don't think it's necessary to return the attention mask in the feature extractor, since we'll just discard this immediately anyways. Probably instead we can remove the attribute `return_attention_mask` from the init?

Also cc @NielsRogge 

Thank you @sanchit-gandhi, that makes sense! The way I encountered the issue is related to your explanation: I am using the ASTFeatureExtractor for another model, where it would be nice to have the attention mask, therefore I got confused that I didn't obtain the mask even though setting return_attention_mask=True in the ASTFeatureExtractor's init method. 

I think it would be nice to either add this functionality such that one could use it with attention masks (as the current documentation promises and as I tried to use it), or, as you said, remove it from the init. 

What do you think @NielsRogge ?

Hey @lu-wo! Interesting use case! Unfortunately we can't maintain all classes in `transformers` to be compatible with every other combination of model, i.e. the `ASTFeatureExtractor` is designed to work with the `ASTModel`, but we can't guarantee that it works for every other model that takes a log-mel spectrogram as input. To do so would be a large maintenance burden, since we'd have to check that every combination works, and would probably complicate the code by introducing additional complexity.

I would suggest trying one of two things here:
1. Use a similar log-mel feature extractor that does return an attention mask. The Whisper feature extractor also computes log-mel spectrograms, but we require the attention mask if we use SpecAug during fine-tuning, so it can return the attention mask if required. Note that you may have to change the spectrogram hyper parameters to get parity with the AST feature extractor
2. Copy the feature extractor code locally, and make the changes you require so that your use case works. If you subsequently train a new model is added to the `transformers` library, then the feature extractor we add for this model will use an attention mask since the model requires one!

Let me know if the above two don't work - happy to brainstorm some more solutions with you!

Thanks @sanchit-gandhi , I guess I can adapt the code for my purposes :) 

Thanks for understanding and looking forward to your next PR @lu-wo! 🤗