Transformers¶
State-of-the-art Natural Language Processing for Pytorch and TensorFlow 2.0.
🤗 Transformers (formerly known as pytorch-transformers and pytorch-pretrained-bert) provides general-purpose architectures (BERT, GPT-2, RoBERTa, XLM, DistilBert, XLNet…) for Natural Language Understanding (NLU) and Natural Language Generation (NLG) with over 32+ pretrained models in 100+ languages and deep interoperability between TensorFlow 2.0 and PyTorch.
This is the documentation of our repository transformers.
Features¶
High performance on NLU and NLG tasks
Low barrier to entry for educators and practitioners
State-of-the-art NLP for everyone:
Deep learning researchers
Hands-on practitioners
AI/ML/NLP teachers and educators
Lower compute costs, smaller carbon footprint:
Researchers can share trained models instead of always retraining
Practitioners can reduce compute time and production costs
8 architectures with over 30 pretrained models, some in more than 100 languages
Choose the right framework for every part of a model’s lifetime:
Train state-of-the-art models in 3 lines of code
Deep interoperability between TensorFlow 2.0 and PyTorch models
Move a single model between TF2.0/PyTorch frameworks at will
Seamlessly pick the right framework for training, evaluation, production
Contents¶
The documentation is organized in five parts:
GET STARTED contains a quick tour, the installation instructions and some useful information about our philosophy and a glossary.
USING 🤗 TRANSFORMERS contains general tutorials on how to use the library.
ADVANCED GUIDES contains more advanced guides that are more specific to a given script or part of the library.
RESEARCH focuses on tutorials that have less to do with how to use the library but more about general resarch in transformers model
- The three last section contain the documentation of each public class and function, grouped in:
MAIN CLASSES for the main classes exposing the important APIs of the library.
MODELS for the classes and functions related to each model implemented in the library.
INTERNAL HELPERS for the classes and functions we use internally.
The library currently contains PyTorch and Tensorflow implementations, pre-trained model weights, usage scripts and conversion utilities for the following models:
BERT (from Google) released with the paper BERT: Pre-training of Deep Bidirectional Transformers for Language Understanding by Jacob Devlin, Ming-Wei Chang, Kenton Lee, and Kristina Toutanova.
GPT (from OpenAI) released with the paper Improving Language Understanding by Generative Pre-Training by Alec Radford, Karthik Narasimhan, Tim Salimans, and Ilya Sutskever.
GPT-2 (from OpenAI) released with the paper Language Models are Unsupervised Multitask Learners by Alec Radford, Jeffrey Wu, Rewon Child, David Luan, Dario Amodei, and Ilya Sutskever.
Transformer-XL (from Google/CMU) released with the paper Transformer-XL: Attentive Language Models Beyond a Fixed-Length Context by Zihang Dai, Zhilin Yang, Yiming Yang, Jaime Carbonell, Quoc V. Le, and Ruslan Salakhutdinov.
XLNet (from Google/CMU) released with the paper XLNet: Generalized Autoregressive Pretraining for Language Understanding by Zhilin Yang, Zihang Dai, Yiming Yang, Jaime Carbonell, Ruslan Salakhutdinov, and Quoc V. Le.
XLM (from Facebook) released together with the paper Cross-lingual Language Model Pretraining by Guillaume Lample and Alexis Conneau.
RoBERTa (from Facebook), released together with the paper a Robustly Optimized BERT Pretraining Approach by Yinhan Liu, Myle Ott, Naman Goyal, Jingfei Du, Mandar Joshi, Danqi Chen, Omer Levy, Mike Lewis, Luke Zettlemoyer, and Veselin Stoyanov.
DistilBERT (from HuggingFace) released together with the paper DistilBERT, a distilled version of BERT: smaller, faster, cheaper and lighter by Victor Sanh, Lysandre Debut, and Thomas Wolf. The same method has been applied to compress GPT2 into DistilGPT2.
CTRL (from Salesforce), released together with the paper CTRL: A Conditional Transformer Language Model for Controllable Generation by Nitish Shirish Keskar, Bryan McCann, Lav R. Varshney, Caiming Xiong, and Richard Socher.
CamemBERT (from FAIR, Inria, Sorbonne Université) released together with the paper CamemBERT: a Tasty French Language Model by Louis Martin, Benjamin Muller, Pedro Javier Ortiz Suarez, Yoann Dupont, Laurent Romary, Eric Villemonte de la Clergerie, Djame Seddah, and Benoît Sagot.
ALBERT (from Google Research), released together with the paper ALBERT: A Lite BERT for Self-supervised Learning of Language Representations by Zhenzhong Lan, Mingda Chen, Sebastian Goodman, Kevin Gimpel, Piyush Sharma, and Radu Soricut.
T5 (from Google) released with the paper Exploring the Limits of Transfer Learning with a Unified Text-to-Text Transformer by Colin Raffel, Noam Shazeer, Adam Roberts, Katherine Lee, Sharan Narang, Michael Matena, Yanqi Zhou, Wei Li, and Peter J. Liu.
XLM-RoBERTa (from Facebook AI), released together with the paper Unsupervised Cross-lingual Representation Learning at Scale by Alexis Conneau, Kartikay Khandelwal, Naman Goyal, Vishrav Chaudhary, Guillaume Wenzek, Francisco Guzmán, Edouard Grave, Myle Ott, Luke Zettlemoyer, and Veselin Stoyanov.
MMBT (from Facebook), released together with the paper a Supervised Multimodal Bitransformers for Classifying Images and Text by Douwe Kiela, Suvrat Bhooshan, Hamed Firooz, and Davide Testuggine.
FlauBERT (from CNRS) released with the paper FlauBERT: Unsupervised Language Model Pre-training for French by Hang Le, Loïc Vial, Jibril Frej, Vincent Segonne, Maximin Coavoux, Benjamin Lecouteux, Alexandre Allauzen, Benoît Crabbé, Laurent Besacier, and Didier Schwab.
BART (from Facebook) released with the paper BART: Denoising Sequence-to-Sequence Pre-training for Natural Language Generation, Translation, and Comprehension by Mike Lewis, Yinhan Liu, Naman Goyal, Marjan Ghazvininejad, Abdelrahman Mohamed, Omer Levy, Ves Stoyanov, and Luke Zettlemoyer.
ELECTRA (from Google Research/Stanford University) released with the paper ELECTRA: Pre-training text encoders as discriminators rather than generators by Kevin Clark, Minh-Thang Luong, Quoc V. Le, and Christopher D. Manning.
DialoGPT (from Microsoft Research) released with the paper DialoGPT: Large-Scale Generative Pre-training for Conversational Response Generation by Yizhe Zhang, Siqi Sun, Michel Galley, Yen-Chun Chen, Chris Brockett, Xiang Gao, Jianfeng Gao, Jingjing Liu, and Bill Dolan.
Reformer (from Google Research) released with the paper Reformer: The Efficient Transformer by Nikita Kitaev, Łukasz Kaiser, and Anselm Levskaya.
MarianMT (developed by the Microsoft Translator Team) machine translation models trained using OPUS pretrained_models data by Jörg Tiedemann.
Longformer (from AllenAI) released with the paper Longformer: The Long-Document Transformer by Iz Beltagy, Matthew E. Peters, and Arman Cohan.
DPR (from Facebook) released with the paper Dense Passage Retrieval for Open-Domain Question Answering by Vladimir Karpukhin, Barlas Oğuz, Sewon Min, Patrick Lewis, Ledell Wu, Sergey Edunov, Danqi Chen, and Wen-tau Yih.
Pegasus (from Google) released with the paper PEGASUS: Pre-training with Extracted Gap-sentences for Abstractive Summarization by Jingqing Zhang, Yao Zhao, Mohammad Saleh and Peter J. Liu.
MBart (from Facebook) released with the paper Multilingual Denoising Pre-training for Neural Machine Translation by Yinhan Liu, Jiatao Gu, Naman Goyal, Xian Li, Sergey Edunov, Marjan Ghazvininejad, Mike Lewis, Luke Zettlemoyer.
LXMERT (from UNC Chapel Hill) released with the paper LXMERT: Learning Cross-Modality Encoder Representations from Transformers for Open-Domain Question Answering by Hao Tan and Mohit Bansal.
Funnel Transformer (from CMU/Google Brain) released with the paper Funnel-Transformer: Filtering out Sequential Redundancy for Efficient Language Processing by Zihang Dai, Guokun Lai, Yiming Yang, Quoc V. Le.
Bert For Sequence Generation (from Google) released with the paper Leveraging Pre-trained Checkpoints for Sequence Generation Tasks by Sascha Rothe, Shashi Narayan, Aliaksei Severyn.
LayoutLM (from Microsoft Research Asia) released with the paper LayoutLM: Pre-training of Text and Layout for Document Image Understanding by Yiheng Xu, Minghao Li, Lei Cui, Shaohan Huang, Furu Wei, Ming Zhou.
Other community models, contributed by the community.
- Configuration
- Logging
- Models
- Optimization
- Model outputs
- ModelOutput
- BaseModelOutput
- BaseModelOutputWithPooling
- BaseModelOutputWithPast
- Seq2SeqModelOutput
- CausalLMOutput
- CausalLMOutputWithPast
- MaskedLMOutput
- Seq2SeqLMOutput
- NextSentencePredictorOutput
- SequenceClassifierOutput
- Seq2SeqSequenceClassifierOutput
- MultipleChoiceModelOutput
- TokenClassifierOutput
- QuestionAnsweringModelOutput
- Seq2SeqQuestionAnsweringModelOutput
- TFBaseModelOutput
- TFBaseModelOutputWithPooling
- TFBaseModelOutputWithPast
- TFSeq2SeqModelOutput
- TFCausalLMOutput
- TFCausalLMOutputWithPast
- TFMaskedLMOutput
- TFSeq2SeqLMOutput
- TFNextSentencePredictorOutput
- TFSequenceClassifierOutput
- TFSeq2SeqSequenceClassifierOutput
- TFMultipleChoiceModelOutput
- TFTokenClassifierOutput
- TFQuestionAnsweringModelOutput
- TFSeq2SeqQuestionAnsweringModelOutput
- Pipelines
- Processors
- Tokenizer
- Trainer
- ALBERT
- Overview
- AlbertConfig
- AlbertTokenizer
- Albert specific outputs
- AlbertModel
- AlbertForPreTraining
- AlbertForMaskedLM
- AlbertForSequenceClassification
- AlbertForMultipleChoice
- AlbertForTokenClassification
- AlbertForQuestionAnswering
- TFAlbertModel
- TFAlbertForPreTraining
- TFAlbertForMaskedLM
- TFAlbertForSequenceClassification
- TFAlbertForMultipleChoice
- TFAlbertForTokenClassification
- TFAlbertForQuestionAnswering
- AutoClasses
- AutoConfig
- AutoTokenizer
- AutoModel
- AutoModelForPreTraining
- AutoModelWithLMHead
- AutoModelForSequenceClassification
- AutoModelForMultipleChoice
- AutoModelForTokenClassification
- AutoModelForQuestionAnswering
- TFAutoModel
- TFAutoModelForPreTraining
- TFAutoModelWithLMHead
- TFAutoModelForSequenceClassification
- TFAutoModelForMultipleChoice
- TFAutoModelForTokenClassification
- TFAutoModelForQuestionAnswering
- Bart
- BERT
- Overview
- BertConfig
- BertTokenizer
- BertTokenizerFast
- Bert specific outputs
- BertModel
- BertForPreTraining
- BertModelLMHeadModel
- BertForMaskedLM
- BertForNextSentencePrediction
- BertForSequenceClassification
- BertForMultipleChoice
- BertForTokenClassification
- BertForQuestionAnswering
- TFBertModel
- TFBertForPreTraining
- TFBertModelLMHeadModel
- TFBertForMaskedLM
- TFBertForNextSentencePrediction
- TFBertForSequenceClassification
- TFBertForMultipleChoice
- TFBertForTokenClassification
- TFBertForQuestionAnswering
- BertGeneration
- CamemBERT
- Overview
- CamembertConfig
- CamembertTokenizer
- CamembertModel
- CamembertForCausalLM
- CamembertForMaskedLM
- CamembertForSequenceClassification
- CamembertForMultipleChoice
- CamembertForTokenClassification
- CamembertForQuestionAnswering
- TFCamembertModel
- TFCamembertForMaskedLM
- TFCamembertForSequenceClassification
- TFCamembertForMultipleChoice
- TFCamembertForTokenClassification
- TFCamembertForQuestionAnswering
- CTRL
- DialoGPT
- DistilBERT
- Overview
- DistilBertConfig
- DistilBertTokenizer
- DistilBertTokenizerFast
- DistilBertModel
- DistilBertForMaskedLM
- DistilBertForSequenceClassification
- DistilBertForMultipleChoice
- DistilBertForTokenClassification
- DistilBertForQuestionAnswering
- TFDistilBertModel
- TFDistilBertForMaskedLM
- TFDistilBertForSequenceClassification
- TFDistilBertForMultipleChoice
- TFDistilBertForTokenClassification
- TFDistilBertForQuestionAnswering
- DPR
- ELECTRA
- Overview
- ElectraConfig
- ElectraTokenizer
- ElectraTokenizerFast
- Electra specific outputs
- ElectraModel
- ElectraForPreTraining
- ElectraForMaskedLM
- ElectraForSequenceClassification
- ElectraForMultipleChoice
- ElectraForTokenClassification
- ElectraForQuestionAnswering
- TFElectraModel
- TFElectraForPreTraining
- TFElectraForMaskedLM
- TFElectraForSequenceClassification
- TFElectraForMultipleChoice
- TFElectraForTokenClassification
- TFElectraForQuestionAnswering
- Encoder Decoder Models
- FlauBERT
- Overview
- FlaubertConfig
- FlaubertTokenizer
- FlaubertModel
- FlaubertWithLMHeadModel
- FlaubertForSequenceClassification
- FlaubertForMultipleChoice
- FlaubertForTokenClassification
- FlaubertForQuestionAnsweringSimple
- FlaubertForQuestionAnswering
- TFFlaubertModel
- TFFlaubertWithLMHeadModel
- TFFlaubertForSequenceClassification
- TFFlaubertForMultipleChoice
- TFFlaubertForTokenClassification
- TFFlaubertForQuestionAnsweringSimple
- FSMT
- Funnel Transformer
- Overview
- FunnelConfig
- FunnelTokenizer
- FunnelTokenizerFast
- Funnel specific outputs
- FunnelBaseModel
- FunnelModel
- FunnelModelForPreTraining
- FunnelForMaskedLM
- FunnelForSequenceClassification
- FunnelForMultipleChoice
- FunnelForTokenClassification
- FunnelForQuestionAnswering
- TFFunnelBaseModel
- TFFunnelModel
- TFFunnelModelForPreTraining
- TFFunnelForMaskedLM
- TFFunnelForSequenceClassification
- TFFunnelForMultipleChoice
- TFFunnelForTokenClassification
- TFFunnelForQuestionAnswering
- LayoutLM
- Longformer
- Overview
- Longformer Self Attention
- Training
- LongformerConfig
- LongformerTokenizer
- LongformerTokenizerFast
- LongformerModel
- LongformerForMaskedLM
- LongformerForSequenceClassification
- LongformerForMultipleChoice
- LongformerForTokenClassification
- LongformerForQuestionAnswering
- TFLongformerModel
- TFLongformerForMaskedLM
- TFLongformerForQuestionAnswering
- LXMERT
- MarianMT
- MBart
- MobileBERT
- Overview
- MobileBertConfig
- MobileBertTokenizer
- MobileBertTokenizerFast
- MobileBert specific outputs
- MobileBertModel
- MobileBertForPreTraining
- MobileBertForMaskedLM
- MobileBertForNextSentencePrediction
- MobileBertForSequenceClassification
- MobileBertForMultipleChoice
- MobileBertForTokenClassification
- MobileBertForQuestionAnswering
- TFMobileBertModel
- TFMobileBertForPreTraining
- TFMobileBertForMaskedLM
- TFMobileBertForNextSentencePrediction
- TFMobileBertForSequenceClassification
- TFMobileBertForMultipleChoice
- TFMobileBertForTokenClassification
- TFMobileBertForQuestionAnswering
- OpenAI GPT
- OpenAI GPT2
- Pegasus
- RAG
- Reformer
- RetriBERT
- RoBERTa
- Overview
- RobertaConfig
- RobertaTokenizer
- RobertaTokenizerFast
- RobertaModel
- RobertaForCausalLM
- RobertaForMaskedLM
- RobertaForSequenceClassification
- RobertaForMultipleChoice
- RobertaForTokenClassification
- RobertaForQuestionAnswering
- TFRobertaModel
- TFRobertaForMaskedLM
- TFRobertaForSequenceClassification
- TFRobertaForMultipleChoice
- TFRobertaForTokenClassification
- TFRobertaForQuestionAnswering
- T5
- Transformer XL
- XLM
- Overview
- XLMConfig
- XLMTokenizer
- XLM specific outputs
- XLMModel
- XLMWithLMHeadModel
- XLMForSequenceClassification
- XLMForMultipleChoice
- XLMForTokenClassification
- XLMForQuestionAnsweringSimple
- XLMForQuestionAnswering
- TFXLMModel
- TFXLMWithLMHeadModel
- TFXLMForSequenceClassification
- TFXLMForMultipleChoice
- TFXLMForTokenClassification
- TFXLMForQuestionAnsweringSimple
- XLM-RoBERTa
- Overview
- XLMRobertaConfig
- XLMRobertaTokenizer
- XLMRobertaModel
- XLMRobertaForCausalLM
- XLMRobertaForMaskedLM
- XLMRobertaForSequenceClassification
- XLMRobertaForMultipleChoice
- XLMRobertaForTokenClassification
- XLMRobertaForQuestionAnswering
- TFXLMRobertaModel
- TFXLMRobertaForMaskedLM
- TFXLMRobertaForSequenceClassification
- TFXLMRobertaForMultipleChoice
- TFXLMRobertaForTokenClassification
- TFXLMRobertaForQuestionAnswering
- XLNet
- Overview
- XLNetConfig
- XLNetTokenizer
- XLNet specific outputs
- XLNetModel
- XLNetLMHeadModel
- XLNetForSequenceClassification
- XLNetForMultipleChoice
- XLNetForTokenClassification
- XLNetForQuestionAnsweringSimple
- XLNetForQuestionAnswering
- TFXLNetModel
- TFXLNetLMHeadModel
- TFXLNetForSequenceClassification
- TFLNetForMultipleChoice
- TFXLNetForTokenClassification
- TFXLNetForQuestionAnsweringSimple