BigBird
Source: transformers

# BigBird## OverviewThe BigBird model was proposed in [Big Bird: Transformers for Longer Sequences](https://arxiv.org/abs/2007.14062) byZaheer, Manzil and Guruganesh, Guru and Dubey, Kumar Avinava and Ainslie, Joshua and Alberti, Chris and Ontanon,Santiago and Pham, Philip and Ravula, Anirudh and Wang, Qifan and Yang, Li and others. BigBird, is a sparse-attentionbased transformer which extends Transformer based models, such as BERT to much longer sequences. In addition to sparseattention, BigBird also applies global attention as well as random attention to the input sequence. Theoretically, ithas been shown that applying sparse, global, and random attention approximates full attention, while beingcomputationally much more efficient for longer sequences. As a consequence of the capability to handle longer context,BigBird has shown improved performance on various long document NLP tasks, such as question answering andsummarization, compared to BERT or RoBERTa.The abstract from the paper is the following:*Transformers-based models, such as BERT, have been one of the most successful deep learning models for NLP.Unfortunately, one of their core limitations is the quadratic dependency (mainly in terms of memory) on the sequencelength due to their full attention mechanism. To remedy this, we propose, BigBird, a sparse attention mechanism thatreduces this quadratic dependency to linear. We show that BigBird is a universal approximator of sequence functions andis Turing complete, thereby preserving these properties of the quadratic, full attention model. Along the way, ourtheoretical analysis reveals some of the benefits of having O(1) global tokens (such as CLS), that attend to the entiresequence as part of the sparse attention mechanism. The proposed sparse attention can handle sequences of length up to8x of what was previously possible using similar hardware. As a consequence of the capability to handle longer context,BigBird drastically improves performance on various NLP tasks such as question answering and summarization. We alsopropose novel applications to genomics data.*This model was contributed by [vasudevgupta](https://huggingface.co/vasudevgupta). The original code can be found[here](https://github.com/google-research/bigbird).## Usage tips- For an in-detail explanation on how BigBird's attention works, see [this blog post](https://huggingface.co/blog/big-bird).- BigBird comes with 2 implementations: **original_full** & **block_sparse**. For the sequence length < 1024, using  **original_full** is advised as there is no benefit in using **block_sparse** attention.- The code currently uses window size of 3 blocks and 2 global blocks.- Sequence length must be divisible by block size.- Current implementation supports only **ITC**.- Current implementation doesn't support **num_random_blocks = 0**- BigBird is a model with absolute position embeddings so it's usually advised to pad the inputs on the right rather than  the left.## Resources- [Text classification task guide](../tasks/sequence_classification)- [Token classification task guide](../tasks/token_classification)- [Question answering task guide](../tasks/question_answering)- [Causal language modeling task guide](../tasks/language_modeling)- [Masked language modeling task guide](../tasks/masked_language_modeling)- [Multiple choice task guide](../tasks/multiple_choice)## BigBirdConfig[[autodoc]] BigBirdConfig## BigBirdTokenizer[[autodoc]] BigBirdTokenizer    - build_inputs_with_special_tokens    - get_special_tokens_mask    - create_token_type_ids_from_sequences    - save_vocabulary## BigBirdTokenizerFast[[autodoc]] BigBirdTokenizerFast## BigBird specific outputs[[autodoc]] models.big_bird.modeling_big_bird.BigBirdForPreTrainingOutput<frameworkcontent><pt>## BigBirdModel[[autodoc]] BigBirdModel    - forward## BigBirdForPreTraining[[autodoc]] BigBirdForPreTraining    - forward## BigBirdForCausalLM[[autodoc]] BigBirdForCausalLM    - forward## BigBirdForMaskedLM[[autodoc]] BigBirdForMaskedLM    - forward## BigBirdForSequenceClassification[[autodoc]] BigBirdForSequenceClassification    - forward## BigBirdForMultipleChoice[[autodoc]] BigBirdForMultipleChoice    - forward## BigBirdForTokenClassification[[autodoc]] BigBirdForTokenClassification    - forward## BigBirdForQuestionAnswering[[autodoc]] BigBirdForQuestionAnswering    - forward</pt><jax>## FlaxBigBirdModel[[autodoc]] FlaxBigBirdModel    - __call__## FlaxBigBirdForPreTraining[[autodoc]] FlaxBigBirdForPreTraining    - __call__## FlaxBigBirdForCausalLM[[autodoc]] FlaxBigBirdForCausalLM    - __call__## FlaxBigBirdForMaskedLM[[autodoc]] FlaxBigBirdForMaskedLM    - __call__## FlaxBigBirdForSequenceClassification[[autodoc]] FlaxBigBirdForSequenceClassification    - __call__## FlaxBigBirdForMultipleChoice[[autodoc]] FlaxBigBirdForMultipleChoice    - __call__## FlaxBigBirdForTokenClassification[[autodoc]] FlaxBigBirdForTokenClassification    - __call__## FlaxBigBirdForQuestionAnswering[[autodoc]] FlaxBigBirdForQuestionAnswering    - __call__</jax></frameworkcontent>