Auto ClassesΒΆ
In many cases, the architecture you want to use can be guessed from the name or the path of the pretrained model you
are supplying to the from_pretrained() method. AutoClasses are here to do this job for you so that you
automatically retrieve the relevant model given the name/path to the pretrained weights/config/vocabulary.
Instantiating one of AutoConfig, AutoModel, and
AutoTokenizer will directly create a class of the relevant architecture. For instance
model = AutoModel.from_pretrained('bert-base-cased')
will create a model that is an instance of BertModel.
There is one class of AutoModel for each task, and for each backend (PyTorch or TensorFlow).
AutoConfigΒΆ
-
class
transformers.AutoConfig[source]ΒΆ This is a generic configuration class that will be instantiated as one of the configuration classes of the library when created with the
from_pretrained()class method.This class cannot be instantiated directly using
__init__()(throws an error).-
classmethod
from_pretrained(pretrained_model_name_or_path, **kwargs)[source]ΒΆ Instantiate one of the configuration classes of the library from a pretrained model configuration.
The configuration class to instantiate is selected based on the
model_typeproperty of the config object that is loaded, or when itβs missing, by falling back to using pattern matching onpretrained_model_name_or_path:albert β
AlbertConfig(ALBERT model)bart β
BartConfig(BART model)bert β
BertConfig(BERT model)bert-generation β
BertGenerationConfig(Bert Generation model)big_bird β
BigBirdConfig(BigBird model)bigbird_pegasus β
BigBirdPegasusConfig(BigBirdPegasus model)blenderbot β
BlenderbotConfig(Blenderbot model)blenderbot-small β
BlenderbotSmallConfig(BlenderbotSmall model)camembert β
CamembertConfig(CamemBERT model)canine β
CanineConfig(Canine model)clip β
CLIPConfig(CLIP model)convbert β
ConvBertConfig(ConvBERT model)ctrl β
CTRLConfig(CTRL model)deberta β
DebertaConfig(DeBERTa model)deberta-v2 β
DebertaV2Config(DeBERTa-v2 model)deit β
DeiTConfig(DeiT model)detr β
DetrConfig(DETR model)distilbert β
DistilBertConfig(DistilBERT model)dpr β
DPRConfig(DPR model)electra β
ElectraConfig(ELECTRA model)encoder-decoder β
EncoderDecoderConfig(Encoder decoder model)flaubert β
FlaubertConfig(FlauBERT model)fsmt β
FSMTConfig(FairSeq Machine-Translation model)funnel β
FunnelConfig(Funnel Transformer model)gpt2 β
GPT2Config(OpenAI GPT-2 model)gpt_neo β
GPTNeoConfig(GPT Neo model)hubert β
HubertConfig(Hubert model)ibert β
IBertConfig(I-BERT model)layoutlm β
LayoutLMConfig(LayoutLM model)led β
LEDConfig(LED model)longformer β
LongformerConfig(Longformer model)luke β
LukeConfig(LUKE model)lxmert β
LxmertConfig(LXMERT model)m2m_100 β
M2M100Config(M2M100 model)marian β
MarianConfig(Marian model)mbart β
MBartConfig(mBART model)megatron-bert β
MegatronBertConfig(MegatronBert model)mobilebert β
MobileBertConfig(MobileBERT model)mpnet β
MPNetConfig(MPNet model)mt5 β
MT5Config(mT5 model)openai-gpt β
OpenAIGPTConfig(OpenAI GPT model)pegasus β
PegasusConfig(Pegasus model)prophetnet β
ProphetNetConfig(ProphetNet model)rag β
RagConfig(RAG model)reformer β
ReformerConfig(Reformer model)retribert β
RetriBertConfig(RetriBERT model)roberta β
RobertaConfig(RoBERTa model)roformer β
RoFormerConfig(RoFormer model)speech_to_text β
Speech2TextConfig(Speech2Text model)squeezebert β
SqueezeBertConfig(SqueezeBERT model)t5 β
T5Config(T5 model)tapas β
TapasConfig(TAPAS model)transfo-xl β
TransfoXLConfig(Transformer-XL model)visual_bert β
VisualBertConfig(VisualBert model)vit β
ViTConfig(ViT model)wav2vec2 β
Wav2Vec2Config(Wav2Vec2 model)xlm β
XLMConfig(XLM model)xlm-prophetnet β
XLMProphetNetConfig(XLMProphetNet model)xlm-roberta β
XLMRobertaConfig(XLM-RoBERTa model)xlnet β
XLNetConfig(XLNet model)
- Parameters
pretrained_model_name_or_path (
stroros.PathLike) βCan be either:
A string, the model id of a pretrained model configuration hosted inside a model repo on huggingface.co. Valid model ids can be located at the root-level, like
bert-base-uncased, or namespaced under a user or organization name, likedbmdz/bert-base-german-cased.A path to a directory containing a configuration file saved using the
save_pretrained()method, or thesave_pretrained()method, e.g.,./my_model_directory/.A path or url to a saved configuration JSON file, e.g.,
./my_model_directory/configuration.json.
cache_dir (
stroros.PathLike, optional) β Path to a directory in which a downloaded pretrained model configuration should be cached if the standard cache should not be used.force_download (
bool, optional, defaults toFalse) β Whether or not to force the (re-)download the model weights and configuration files and override the cached versions if they exist.resume_download (
bool, optional, defaults toFalse) β Whether or not to delete incompletely received files. Will attempt to resume the download if such a file exists.proxies (
Dict[str, str], optional) β A dictionary of proxy servers to use by protocol or endpoint, e.g.,{'http': 'foo.bar:3128', 'http://hostname': 'foo.bar:4012'}. The proxies are used on each request.revision (
str, optional, defaults to"main") β The specific model version to use. It can be a branch name, a tag name, or a commit id, since we use a git-based system for storing models and other artifacts on huggingface.co, sorevisioncan be any identifier allowed by git.return_unused_kwargs (
bool, optional, defaults toFalse) βIf
False, then this function returns just the final configuration object.If
True, then this functions returns aTuple(config, unused_kwargs)where unused_kwargs is a dictionary consisting of the key/value pairs whose keys are not configuration attributes: i.e., the part ofkwargswhich has not been used to updateconfigand is otherwise ignored.kwargs (additional keyword arguments, optional) β The values in kwargs of any keys which are configuration attributes will be used to override the loaded values. Behavior concerning key/value pairs whose keys are not configuration attributes is controlled by the
return_unused_kwargskeyword parameter.
Examples:
>>> from transformers import AutoConfig >>> # Download configuration from huggingface.co and cache. >>> config = AutoConfig.from_pretrained('bert-base-uncased') >>> # Download configuration from huggingface.co (user-uploaded) and cache. >>> config = AutoConfig.from_pretrained('dbmdz/bert-base-german-cased') >>> # If configuration file is in a directory (e.g., was saved using `save_pretrained('./test/saved_model/')`). >>> config = AutoConfig.from_pretrained('./test/bert_saved_model/') >>> # Load a specific configuration file. >>> config = AutoConfig.from_pretrained('./test/bert_saved_model/my_configuration.json') >>> # Change some config attributes when loading a pretrained config. >>> config = AutoConfig.from_pretrained('bert-base-uncased', output_attentions=True, foo=False) >>> config.output_attentions True >>> config, unused_kwargs = AutoConfig.from_pretrained('bert-base-uncased', output_attentions=True, foo=False, return_unused_kwargs=True) >>> config.output_attentions True >>> config.unused_kwargs {'foo': False}
-
classmethod
AutoTokenizerΒΆ
-
class
transformers.AutoTokenizer[source]ΒΆ This is a generic tokenizer class that will be instantiated as one of the tokenizer classes of the library when created with the
AutoTokenizer.from_pretrained()class method.This class cannot be instantiated directly using
__init__()(throws an error).-
classmethod
from_pretrained(pretrained_model_name_or_path, *inputs, **kwargs)[source]ΒΆ Instantiate one of the tokenizer classes of the library from a pretrained model vocabulary.
The tokenizer class to instantiate is selected based on the
model_typeproperty of the config object (either passed as an argument or loaded frompretrained_model_name_or_pathif possible), or when itβs missing, by falling back to using pattern matching onpretrained_model_name_or_path:albert β
AlbertTokenizer(ALBERT model)bart β
BartTokenizer(BART model)bert β
BertTokenizer(BERT model)bert-generation β
BertGenerationTokenizer(Bert Generation model)big_bird β
BigBirdTokenizer(BigBird model)bigbird_pegasus β
PegasusTokenizer(BigBirdPegasus model)blenderbot β
BlenderbotTokenizer(Blenderbot model)blenderbot-small β
BlenderbotSmallTokenizer(BlenderbotSmall model)camembert β
CamembertTokenizer(CamemBERT model)canine β
CanineTokenizer(Canine model)convbert β
ConvBertTokenizer(ConvBERT model)ctrl β
CTRLTokenizer(CTRL model)deberta β
DebertaTokenizer(DeBERTa model)deberta-v2 β
DebertaV2Tokenizer(DeBERTa-v2 model)distilbert β
DistilBertTokenizer(DistilBERT model)dpr β
DPRQuestionEncoderTokenizer(DPR model)electra β
ElectraTokenizer(ELECTRA model)flaubert β
FlaubertTokenizer(FlauBERT model)fsmt β
FSMTTokenizer(FairSeq Machine-Translation model)funnel β
FunnelTokenizer(Funnel Transformer model)gpt2 β
GPT2Tokenizer(OpenAI GPT-2 model)gpt_neo β
GPT2Tokenizer(GPT Neo model)hubert β
Wav2Vec2CTCTokenizer(Hubert model)ibert β
RobertaTokenizer(I-BERT model)layoutlm β
LayoutLMTokenizer(LayoutLM model)led β
LEDTokenizer(LED model)longformer β
LongformerTokenizer(Longformer model)luke β
LukeTokenizer(LUKE model)lxmert β
LxmertTokenizer(LXMERT model)m2m_100 β
M2M100Tokenizer(M2M100 model)marian β
MarianTokenizer(Marian model)mbart β
MBartTokenizer(mBART model)mobilebert β
MobileBertTokenizer(MobileBERT model)mpnet β
MPNetTokenizer(MPNet model)mt5 β
T5Tokenizer(mT5 model)openai-gpt β
OpenAIGPTTokenizer(OpenAI GPT model)pegasus β
PegasusTokenizer(Pegasus model)prophetnet β
ProphetNetTokenizer(ProphetNet model)rag β
RagTokenizer(RAG model)reformer β
ReformerTokenizer(Reformer model)retribert β
RetriBertTokenizer(RetriBERT model)roberta β
RobertaTokenizer(RoBERTa model)roformer β
RoFormerTokenizer(RoFormer model)speech_to_text β
Speech2TextTokenizer(Speech2Text model)squeezebert β
SqueezeBertTokenizer(SqueezeBERT model)t5 β
T5Tokenizer(T5 model)tapas β
TapasTokenizer(TAPAS model)transfo-xl β
TransfoXLTokenizer(Transformer-XL model)wav2vec2 β
Wav2Vec2CTCTokenizer(Wav2Vec2 model)xlm β
XLMTokenizer(XLM model)xlm-prophetnet β
XLMProphetNetTokenizer(XLMProphetNet model)xlm-roberta β
XLMRobertaTokenizer(XLM-RoBERTa model)xlnet β
XLNetTokenizer(XLNet model)
- Params:
- pretrained_model_name_or_path (
stroros.PathLike): Can be either:
A string, the model id of a predefined tokenizer hosted inside a model repo on huggingface.co. Valid model ids can be located at the root-level, like
bert-base-uncased, or namespaced under a user or organization name, likedbmdz/bert-base-german-cased.A path to a directory containing vocabulary files required by the tokenizer, for instance saved using the
save_pretrained()method, e.g.,./my_model_directory/.A path or url to a single saved vocabulary file if and only if the tokenizer only requires a single vocabulary file (like Bert or XLNet), e.g.:
./my_model_directory/vocab.txt. (Not applicable to all derived classes)
- inputs (additional positional arguments, optional):
Will be passed along to the Tokenizer
__init__()method.- config (
PreTrainedConfig, optional) The configuration object used to dertermine the tokenizer class to instantiate.
- cache_dir (
stroros.PathLike, optional): Path to a directory in which a downloaded pretrained model configuration should be cached if the standard cache should not be used.
- force_download (
bool, optional, defaults toFalse): Whether or not to force the (re-)download the model weights and configuration files and override the cached versions if they exist.
- resume_download (
bool, optional, defaults toFalse): Whether or not to delete incompletely received files. Will attempt to resume the download if such a file exists.
- proxies (
Dict[str, str], optional): A dictionary of proxy servers to use by protocol or endpoint, e.g.,
{'http': 'foo.bar:3128', 'http://hostname': 'foo.bar:4012'}. The proxies are used on each request.- revision(
str, optional, defaults to"main"): The specific model version to use. It can be a branch name, a tag name, or a commit id, since we use a git-based system for storing models and other artifacts on huggingface.co, so
revisioncan be any identifier allowed by git.- subfolder (
str, optional): In case the relevant files are located inside a subfolder of the model repo on huggingface.co (e.g. for facebook/rag-token-base), specify it here.
- use_fast (
bool, optional, defaults toTrue): Whether or not to try to load the fast version of the tokenizer.
- kwargs (additional keyword arguments, optional):
Will be passed to the Tokenizer
__init__()method. Can be used to set special tokens likebos_token,eos_token,unk_token,sep_token,pad_token,cls_token,mask_token,additional_special_tokens. See parameters in the__init__()for more details.
- pretrained_model_name_or_path (
Examples:
>>> from transformers import AutoTokenizer >>> # Download vocabulary from huggingface.co and cache. >>> tokenizer = AutoTokenizer.from_pretrained('bert-base-uncased') >>> # Download vocabulary from huggingface.co (user-uploaded) and cache. >>> tokenizer = AutoTokenizer.from_pretrained('dbmdz/bert-base-german-cased') >>> # If vocabulary files are in a directory (e.g. tokenizer was saved using `save_pretrained('./test/saved_model/')`) >>> tokenizer = AutoTokenizer.from_pretrained('./test/bert_saved_model/')
-
classmethod
AutoFeatureExtractorΒΆ
-
class
transformers.AutoFeatureExtractor[source]ΒΆ This is a generic feature extractor class that will be instantiated as one of the feature extractor classes of the library when created with the
AutoFeatureExtractor.from_pretrained()class method.This class cannot be instantiated directly using
__init__()(throws an error).-
classmethod
from_pretrained(pretrained_model_name_or_path, **kwargs)[source]ΒΆ Instantiate one of the feature extractor classes of the library from a pretrained model vocabulary.
The tokenizer class to instantiate is selected based on the
model_typeproperty of the config object (either passed as an argument or loaded frompretrained_model_name_or_pathif possible), or when itβs missing, by falling back to using pattern matching onpretrained_model_name_or_path:deit β
DeiTFeatureExtractor(DeiT model)speech_to_text β
Speech2TextFeatureExtractor(Speech2Text model)vit β
ViTFeatureExtractor(ViT model)wav2vec2 β
Wav2Vec2FeatureExtractor(Wav2Vec2 model)
- Params:
- pretrained_model_name_or_path (
stroros.PathLike): This can be either:
a string, the model id of a pretrained feature_extractor hosted inside a model repo on huggingface.co. Valid model ids can be located at the root-level, like
bert-base-uncased, or namespaced under a user or organization name, likedbmdz/bert-base-german-cased.a path to a directory containing a feature extractor file saved using the
save_pretrained()method, e.g.,./my_model_directory/.a path or url to a saved feature extractor JSON file, e.g.,
./my_model_directory/preprocessor_config.json.
- cache_dir (
stroros.PathLike, optional): Path to a directory in which a downloaded pretrained model feature extractor should be cached if the standard cache should not be used.
- force_download (
bool, optional, defaults toFalse): Whether or not to force to (re-)download the feature extractor files and override the cached versions if they exist.
- resume_download (
bool, optional, defaults toFalse): Whether or not to delete incompletely received file. Attempts to resume the download if such a file exists.
- proxies (
Dict[str, str], optional): A dictionary of proxy servers to use by protocol or endpoint, e.g.,
{'http': 'foo.bar:3128', 'http://hostname': 'foo.bar:4012'}.The proxies are used on each request.- use_auth_token (
stror bool, optional): The token to use as HTTP bearer authorization for remote files. If
True, will use the token generated when runningtransformers-cli login(stored inhuggingface).- revision(
str, optional, defaults to"main"): The specific model version to use. It can be a branch name, a tag name, or a commit id, since we use a git-based system for storing models and other artifacts on huggingface.co, so
revisioncan be any identifier allowed by git.- return_unused_kwargs (
bool, optional, defaults toFalse): If
False, then this function returns just the final feature extractor object. IfTrue, then this functions returns aTuple(feature_extractor, unused_kwargs)where unused_kwargs is a dictionary consisting of the key/value pairs whose keys are not feature extractor attributes: i.e., the part ofkwargswhich has not been used to updatefeature_extractorand is otherwise ignored.- kwargs (
Dict[str, Any], optional): The values in kwargs of any keys which are feature extractor attributes will be used to override the loaded values. Behavior concerning key/value pairs whose keys are not feature extractor attributes is controlled by the
return_unused_kwargskeyword parameter.
- pretrained_model_name_or_path (
Note
Passing
use_auth_token=Trueis required when you want to use a private model.Examples:
>>> from transformers import AutoFeatureExtractor >>> # Download vocabulary from huggingface.co and cache. >>> feature_extractor = AutoFeatureExtractor.from_pretrained('facebook/wav2vec2-base-960h') >>> # If vocabulary files are in a directory (e.g. feature extractor was saved using `save_pretrained('./test/saved_model/')`) >>> feature_extractor = AutoFeatureExtractor.from_pretrained('./test/saved_model/')
-
classmethod
AutoModelΒΆ
-
class
transformers.AutoModel(*args, **kwargs)[source]ΒΆ This is a generic model class that will be instantiated as one of the base model classes of the library when created with the
from_pretrained()class method or thefrom_config()class method.This class cannot be instantiated directly using
__init__()(throws an error).-
classmethod
from_config(config, **kwargs)ΒΆ Instantiates one of the base model classes of the library from a configuration.
Note
Loading a model from its configuration file does not load the model weights. It only affects the modelβs configuration. Use
from_pretrained()to load the model weights.- Parameters
config (
PretrainedConfig) βThe model class to instantiate is selected based on the configuration class:
AlbertConfigconfiguration class:AlbertModel(ALBERT model)BartConfigconfiguration class:BartModel(BART model)BertConfigconfiguration class:BertModel(BERT model)BertGenerationConfigconfiguration class:BertGenerationEncoder(Bert Generation model)BigBirdConfigconfiguration class:BigBirdModel(BigBird model)BigBirdPegasusConfigconfiguration class:BigBirdPegasusModel(BigBirdPegasus model)BlenderbotConfigconfiguration class:BlenderbotModel(Blenderbot model)BlenderbotSmallConfigconfiguration class:BlenderbotSmallModel(BlenderbotSmall model)CLIPConfigconfiguration class:CLIPModel(CLIP model)CTRLConfigconfiguration class:CTRLModel(CTRL model)CamembertConfigconfiguration class:CamembertModel(CamemBERT model)CanineConfigconfiguration class:CanineModel(Canine model)ConvBertConfigconfiguration class:ConvBertModel(ConvBERT model)DPRConfigconfiguration class:DPRQuestionEncoder(DPR model)DebertaConfigconfiguration class:DebertaModel(DeBERTa model)DebertaV2Configconfiguration class:DebertaV2Model(DeBERTa-v2 model)DeiTConfigconfiguration class:DeiTModel(DeiT model)DetrConfigconfiguration class:DetrModel(DETR model)DistilBertConfigconfiguration class:DistilBertModel(DistilBERT model)ElectraConfigconfiguration class:ElectraModel(ELECTRA model)FSMTConfigconfiguration class:FSMTModel(FairSeq Machine-Translation model)FlaubertConfigconfiguration class:FlaubertModel(FlauBERT model)FunnelConfigconfiguration class:FunnelModelorFunnelBaseModel(Funnel Transformer model)GPT2Configconfiguration class:GPT2Model(OpenAI GPT-2 model)GPTNeoConfigconfiguration class:GPTNeoModel(GPT Neo model)HubertConfigconfiguration class:HubertModel(Hubert model)IBertConfigconfiguration class:IBertModel(I-BERT model)LayoutLMConfigconfiguration class:LayoutLMModel(LayoutLM model)LongformerConfigconfiguration class:LongformerModel(Longformer model)LukeConfigconfiguration class:LukeModel(LUKE model)LxmertConfigconfiguration class:LxmertModel(LXMERT model)M2M100Configconfiguration class:M2M100Model(M2M100 model)MBartConfigconfiguration class:MBartModel(mBART model)MPNetConfigconfiguration class:MPNetModel(MPNet model)MarianConfigconfiguration class:MarianModel(Marian model)MegatronBertConfigconfiguration class:MegatronBertModel(MegatronBert model)MobileBertConfigconfiguration class:MobileBertModel(MobileBERT model)OpenAIGPTConfigconfiguration class:OpenAIGPTModel(OpenAI GPT model)PegasusConfigconfiguration class:PegasusModel(Pegasus model)ProphetNetConfigconfiguration class:ProphetNetModel(ProphetNet model)ReformerConfigconfiguration class:ReformerModel(Reformer model)RetriBertConfigconfiguration class:RetriBertModel(RetriBERT model)RoFormerConfigconfiguration class:RoFormerModel(RoFormer model)RobertaConfigconfiguration class:RobertaModel(RoBERTa model)Speech2TextConfigconfiguration class:Speech2TextModel(Speech2Text model)SqueezeBertConfigconfiguration class:SqueezeBertModel(SqueezeBERT model)TapasConfigconfiguration class:TapasModel(TAPAS model)TransfoXLConfigconfiguration class:TransfoXLModel(Transformer-XL model)VisualBertConfigconfiguration class:VisualBertModel(VisualBert model)Wav2Vec2Configconfiguration class:Wav2Vec2Model(Wav2Vec2 model)XLMProphetNetConfigconfiguration class:XLMProphetNetModel(XLMProphetNet model)XLMRobertaConfigconfiguration class:XLMRobertaModel(XLM-RoBERTa model)XLNetConfigconfiguration class:XLNetModel(XLNet model)
Examples:
>>> from transformers import AutoConfig, AutoModel >>> # Download configuration from huggingface.co and cache. >>> config = AutoConfig.from_pretrained('bert-base-cased') >>> model = AutoModel.from_config(config)
-
classmethod
from_pretrained(pretrained_model_name_or_path, *model_args, **kwargs)ΒΆ Instantiate one of the base model classes of the library from a pretrained model.
The model class to instantiate is selected based on the
model_typeproperty of the config object (either passed as an argument or loaded frompretrained_model_name_or_pathif possible), or when itβs missing, by falling back to using pattern matching onpretrained_model_name_or_path:albert β
AlbertModel(ALBERT model)bart β
BartModel(BART model)bert β
BertModel(BERT model)bert-generation β
BertGenerationEncoder(Bert Generation model)big_bird β
BigBirdModel(BigBird model)bigbird_pegasus β
BigBirdPegasusModel(BigBirdPegasus model)blenderbot β
BlenderbotModel(Blenderbot model)blenderbot-small β
BlenderbotSmallModel(BlenderbotSmall model)camembert β
CamembertModel(CamemBERT model)canine β
CanineModel(Canine model)clip β
CLIPModel(CLIP model)convbert β
ConvBertModel(ConvBERT model)ctrl β
CTRLModel(CTRL model)deberta β
DebertaModel(DeBERTa model)deberta-v2 β
DebertaV2Model(DeBERTa-v2 model)deit β
DeiTModel(DeiT model)detr β
DetrModel(DETR model)distilbert β
DistilBertModel(DistilBERT model)dpr β
DPRQuestionEncoder(DPR model)electra β
ElectraModel(ELECTRA model)flaubert β
FlaubertModel(FlauBERT model)fsmt β
FSMTModel(FairSeq Machine-Translation model)funnel β
FunnelModelorFunnelBaseModel(Funnel Transformer model)gpt2 β
GPT2Model(OpenAI GPT-2 model)gpt_neo β
GPTNeoModel(GPT Neo model)hubert β
HubertModel(Hubert model)ibert β
IBertModel(I-BERT model)layoutlm β
LayoutLMModel(LayoutLM model)led β
LEDModel(LED model)longformer β
LongformerModel(Longformer model)luke β
LukeModel(LUKE model)lxmert β
LxmertModel(LXMERT model)m2m_100 β
M2M100Model(M2M100 model)marian β
MarianModel(Marian model)mbart β
MBartModel(mBART model)megatron-bert β
MegatronBertModel(MegatronBert model)mobilebert β
MobileBertModel(MobileBERT model)mpnet β
MPNetModel(MPNet model)mt5 β
MT5Model(mT5 model)openai-gpt β
OpenAIGPTModel(OpenAI GPT model)pegasus β
PegasusModel(Pegasus model)prophetnet β
ProphetNetModel(ProphetNet model)reformer β
ReformerModel(Reformer model)retribert β
RetriBertModel(RetriBERT model)roberta β
RobertaModel(RoBERTa model)roformer β
RoFormerModel(RoFormer model)speech_to_text β
Speech2TextModel(Speech2Text model)squeezebert β
SqueezeBertModel(SqueezeBERT model)t5 β
T5Model(T5 model)tapas β
TapasModel(TAPAS model)transfo-xl β
TransfoXLModel(Transformer-XL model)visual_bert β
VisualBertModel(VisualBert model)vit β
ViTModel(ViT model)wav2vec2 β
Wav2Vec2Model(Wav2Vec2 model)xlm β
XLMModel(XLM model)xlm-prophetnet β
XLMProphetNetModel(XLMProphetNet model)xlm-roberta β
XLMRobertaModel(XLM-RoBERTa model)xlnet β
XLNetModel(XLNet model)
The model is set in evaluation mode by default using
model.eval()(so for instance, dropout modules are deactivated). To train the model, you should first set it back in training mode withmodel.train()- Parameters
pretrained_model_name_or_path (
stroros.PathLike) βCan be either:
A string, the model id of a pretrained model hosted inside a model repo on huggingface.co. Valid model ids can be located at the root-level, like
bert-base-uncased, or namespaced under a user or organization name, likedbmdz/bert-base-german-cased.A path to a directory containing model weights saved using
save_pretrained(), e.g.,./my_model_directory/.A path or url to a tensorflow index checkpoint file (e.g,
./tf_model/model.ckpt.index). In this case,from_tfshould be set toTrueand a configuration object should be provided asconfigargument. This loading path is slower than converting the TensorFlow checkpoint in a PyTorch model using the provided conversion scripts and loading the PyTorch model afterwards.
model_args (additional positional arguments, optional) β Will be passed along to the underlying model
__init__()method.config (
PretrainedConfig, optional) βConfiguration for the model to use instead of an automatically loaded configuration. Configuration can be automatically loaded when:
The model is a model provided by the library (loaded with the model id string of a pretrained model).
The model was saved using
save_pretrained()and is reloaded by supplying the save directory.The model is loaded by supplying a local directory as
pretrained_model_name_or_pathand a configuration JSON file named config.json is found in the directory.
state_dict (Dict[str, torch.Tensor], optional) β
A state dictionary to use instead of a state dictionary loaded from saved weights file.
This option can be used if you want to create a model from a pretrained configuration but load your own weights. In this case though, you should check if using
save_pretrained()andfrom_pretrained()is not a simpler option.cache_dir (
stroros.PathLike, optional) β Path to a directory in which a downloaded pretrained model configuration should be cached if the standard cache should not be used.from_tf (
bool, optional, defaults toFalse) β Load the model weights from a TensorFlow checkpoint save file (see docstring ofpretrained_model_name_or_pathargument).force_download (
bool, optional, defaults toFalse) β Whether or not to force the (re-)download of the model weights and configuration files, overriding the cached versions if they exist.resume_download (
bool, optional, defaults toFalse) β Whether or not to delete incompletely received files. Will attempt to resume the download if such a file exists.proxies (
Dict[str, str], `optional) β A dictionary of proxy servers to use by protocol or endpoint, e.g.,{'http': 'foo.bar:3128', 'http://hostname': 'foo.bar:4012'}. The proxies are used on each request.output_loading_info (
bool, optional, defaults toFalse) β Whether ot not to also return a dictionary containing missing keys, unexpected keys and error messages.local_files_only (
bool, optional, defaults toFalse) β Whether or not to only look at local files (e.g., not try downloading the model).revision (
str, optional, defaults to"main") β The specific model version to use. It can be a branch name, a tag name, or a commit id, since we use a git-based system for storing models and other artifacts on huggingface.co, sorevisioncan be any identifier allowed by git.kwargs (additional keyword arguments, optional) β
Can be used to update the configuration object (after it being loaded) and initiate the model (e.g.,
output_attentions=True). Behaves differently depending on whether aconfigis provided or automatically loaded:If a configuration is provided with
config,**kwargswill be directly passed to the underlying modelβs__init__method (we assume all relevant updates to the configuration have already been done)If a configuration is not provided,
kwargswill be first passed to the configuration class initialization function (from_pretrained()). Each key ofkwargsthat corresponds to a configuration attribute will be used to override said attribute with the suppliedkwargsvalue. Remaining keys that do not correspond to any configuration attribute will be passed to the underlying modelβs__init__function.
Examples:
>>> from transformers import AutoConfig, AutoModel >>> # Download model and configuration from huggingface.co and cache. >>> model = AutoModel.from_pretrained('bert-base-cased') >>> # Update configuration during loading >>> model = AutoModel.from_pretrained('bert-base-cased', output_attentions=True) >>> model.config.output_attentions True >>> # Loading from a TF checkpoint file instead of a PyTorch model (slower) >>> config = AutoConfig.from_pretrained('./tf_model/bert_tf_model_config.json') >>> model = AutoModel.from_pretrained('./tf_model/bert_tf_checkpoint.ckpt.index', from_tf=True, config=config)
-
classmethod
AutoModelForPreTrainingΒΆ
-
class
transformers.AutoModelForPreTraining(*args, **kwargs)[source]ΒΆ This is a generic model class that will be instantiated as one of the model classes of the library (with a pretraining head) when created with the
from_pretrained()class method or thefrom_config()class method.This class cannot be instantiated directly using
__init__()(throws an error).-
classmethod
from_config(config, **kwargs)ΒΆ Instantiates one of the model classes of the library (with a pretraining head) from a configuration.
Note
Loading a model from its configuration file does not load the model weights. It only affects the modelβs configuration. Use
from_pretrained()to load the model weights.- Parameters
config (
PretrainedConfig) βThe model class to instantiate is selected based on the configuration class:
AlbertConfigconfiguration class:AlbertForPreTraining(ALBERT model)BartConfigconfiguration class:BartForConditionalGeneration(BART model)BertConfigconfiguration class:BertForPreTraining(BERT model)BigBirdConfigconfiguration class:BigBirdForPreTraining(BigBird model)CTRLConfigconfiguration class:CTRLLMHeadModel(CTRL model)CamembertConfigconfiguration class:CamembertForMaskedLM(CamemBERT model)DebertaConfigconfiguration class:DebertaForMaskedLM(DeBERTa model)DebertaV2Configconfiguration class:DebertaV2ForMaskedLM(DeBERTa-v2 model)DistilBertConfigconfiguration class:DistilBertForMaskedLM(DistilBERT model)ElectraConfigconfiguration class:ElectraForPreTraining(ELECTRA model)FSMTConfigconfiguration class:FSMTForConditionalGeneration(FairSeq Machine-Translation model)FlaubertConfigconfiguration class:FlaubertWithLMHeadModel(FlauBERT model)FunnelConfigconfiguration class:FunnelForPreTraining(Funnel Transformer model)GPT2Configconfiguration class:GPT2LMHeadModel(OpenAI GPT-2 model)IBertConfigconfiguration class:IBertForMaskedLM(I-BERT model)LayoutLMConfigconfiguration class:LayoutLMForMaskedLM(LayoutLM model)LongformerConfigconfiguration class:LongformerForMaskedLM(Longformer model)LxmertConfigconfiguration class:LxmertForPreTraining(LXMERT model)MPNetConfigconfiguration class:MPNetForMaskedLM(MPNet model)MegatronBertConfigconfiguration class:MegatronBertForPreTraining(MegatronBert model)MobileBertConfigconfiguration class:MobileBertForPreTraining(MobileBERT model)OpenAIGPTConfigconfiguration class:OpenAIGPTLMHeadModel(OpenAI GPT model)RetriBertConfigconfiguration class:RetriBertModel(RetriBERT model)RobertaConfigconfiguration class:RobertaForMaskedLM(RoBERTa model)SqueezeBertConfigconfiguration class:SqueezeBertForMaskedLM(SqueezeBERT model)T5Configconfiguration class:T5ForConditionalGeneration(T5 model)TapasConfigconfiguration class:TapasForMaskedLM(TAPAS model)TransfoXLConfigconfiguration class:TransfoXLLMHeadModel(Transformer-XL model)VisualBertConfigconfiguration class:VisualBertForPreTraining(VisualBert model)Wav2Vec2Configconfiguration class:Wav2Vec2ForPreTraining(Wav2Vec2 model)XLMConfigconfiguration class:XLMWithLMHeadModel(XLM model)XLMRobertaConfigconfiguration class:XLMRobertaForMaskedLM(XLM-RoBERTa model)XLNetConfigconfiguration class:XLNetLMHeadModel(XLNet model)
Examples:
>>> from transformers import AutoConfig, AutoModelForPreTraining >>> # Download configuration from huggingface.co and cache. >>> config = AutoConfig.from_pretrained('bert-base-cased') >>> model = AutoModelForPreTraining.from_config(config)
-
classmethod
from_pretrained(pretrained_model_name_or_path, *model_args, **kwargs)ΒΆ Instantiate one of the model classes of the library (with a pretraining head) from a pretrained model.
The model class to instantiate is selected based on the
model_typeproperty of the config object (either passed as an argument or loaded frompretrained_model_name_or_pathif possible), or when itβs missing, by falling back to using pattern matching onpretrained_model_name_or_path:albert β
AlbertForPreTraining(ALBERT model)bart β
BartForConditionalGeneration(BART model)bert β
BertForPreTraining(BERT model)big_bird β
BigBirdForPreTraining(BigBird model)camembert β
CamembertForMaskedLM(CamemBERT model)ctrl β
CTRLLMHeadModel(CTRL model)deberta β
DebertaForMaskedLM(DeBERTa model)deberta-v2 β
DebertaV2ForMaskedLM(DeBERTa-v2 model)distilbert β
DistilBertForMaskedLM(DistilBERT model)electra β
ElectraForPreTraining(ELECTRA model)flaubert β
FlaubertWithLMHeadModel(FlauBERT model)fsmt β
FSMTForConditionalGeneration(FairSeq Machine-Translation model)funnel β
FunnelForPreTraining(Funnel Transformer model)gpt2 β
GPT2LMHeadModel(OpenAI GPT-2 model)ibert β
IBertForMaskedLM(I-BERT model)layoutlm β
LayoutLMForMaskedLM(LayoutLM model)longformer β
LongformerForMaskedLM(Longformer model)lxmert β
LxmertForPreTraining(LXMERT model)megatron-bert β
MegatronBertForPreTraining(MegatronBert model)mobilebert β
MobileBertForPreTraining(MobileBERT model)mpnet β
MPNetForMaskedLM(MPNet model)openai-gpt β
OpenAIGPTLMHeadModel(OpenAI GPT model)retribert β
RetriBertModel(RetriBERT model)roberta β
RobertaForMaskedLM(RoBERTa model)squeezebert β
SqueezeBertForMaskedLM(SqueezeBERT model)t5 β
T5ForConditionalGeneration(T5 model)tapas β
TapasForMaskedLM(TAPAS model)transfo-xl β
TransfoXLLMHeadModel(Transformer-XL model)visual_bert β
VisualBertForPreTraining(VisualBert model)wav2vec2 β
Wav2Vec2ForPreTraining(Wav2Vec2 model)xlm β
XLMWithLMHeadModel(XLM model)xlm-roberta β
XLMRobertaForMaskedLM(XLM-RoBERTa model)xlnet β
XLNetLMHeadModel(XLNet model)
The model is set in evaluation mode by default using
model.eval()(so for instance, dropout modules are deactivated). To train the model, you should first set it back in training mode withmodel.train()- Parameters
pretrained_model_name_or_path (
stroros.PathLike) βCan be either:
A string, the model id of a pretrained model hosted inside a model repo on huggingface.co. Valid model ids can be located at the root-level, like
bert-base-uncased, or namespaced under a user or organization name, likedbmdz/bert-base-german-cased.A path to a directory containing model weights saved using
save_pretrained(), e.g.,./my_model_directory/.A path or url to a tensorflow index checkpoint file (e.g,
./tf_model/model.ckpt.index). In this case,from_tfshould be set toTrueand a configuration object should be provided asconfigargument. This loading path is slower than converting the TensorFlow checkpoint in a PyTorch model using the provided conversion scripts and loading the PyTorch model afterwards.
model_args (additional positional arguments, optional) β Will be passed along to the underlying model
__init__()method.config (
PretrainedConfig, optional) βConfiguration for the model to use instead of an automatically loaded configuration. Configuration can be automatically loaded when:
The model is a model provided by the library (loaded with the model id string of a pretrained model).
The model was saved using
save_pretrained()and is reloaded by supplying the save directory.The model is loaded by supplying a local directory as
pretrained_model_name_or_pathand a configuration JSON file named config.json is found in the directory.
state_dict (Dict[str, torch.Tensor], optional) β
A state dictionary to use instead of a state dictionary loaded from saved weights file.
This option can be used if you want to create a model from a pretrained configuration but load your own weights. In this case though, you should check if using
save_pretrained()andfrom_pretrained()is not a simpler option.cache_dir (
stroros.PathLike, optional) β Path to a directory in which a downloaded pretrained model configuration should be cached if the standard cache should not be used.from_tf (
bool, optional, defaults toFalse) β Load the model weights from a TensorFlow checkpoint save file (see docstring ofpretrained_model_name_or_pathargument).force_download (
bool, optional, defaults toFalse) β Whether or not to force the (re-)download of the model weights and configuration files, overriding the cached versions if they exist.resume_download (
bool, optional, defaults toFalse) β Whether or not to delete incompletely received files. Will attempt to resume the download if such a file exists.proxies (
Dict[str, str], `optional) β A dictionary of proxy servers to use by protocol or endpoint, e.g.,{'http': 'foo.bar:3128', 'http://hostname': 'foo.bar:4012'}. The proxies are used on each request.output_loading_info (
bool, optional, defaults toFalse) β Whether ot not to also return a dictionary containing missing keys, unexpected keys and error messages.local_files_only (
bool, optional, defaults toFalse) β Whether or not to only look at local files (e.g., not try downloading the model).revision (
str, optional, defaults to"main") β The specific model version to use. It can be a branch name, a tag name, or a commit id, since we use a git-based system for storing models and other artifacts on huggingface.co, sorevisioncan be any identifier allowed by git.kwargs (additional keyword arguments, optional) β
Can be used to update the configuration object (after it being loaded) and initiate the model (e.g.,
output_attentions=True). Behaves differently depending on whether aconfigis provided or automatically loaded:If a configuration is provided with
config,**kwargswill be directly passed to the underlying modelβs__init__method (we assume all relevant updates to the configuration have already been done)If a configuration is not provided,
kwargswill be first passed to the configuration class initialization function (from_pretrained()). Each key ofkwargsthat corresponds to a configuration attribute will be used to override said attribute with the suppliedkwargsvalue. Remaining keys that do not correspond to any configuration attribute will be passed to the underlying modelβs__init__function.
Examples:
>>> from transformers import AutoConfig, AutoModelForPreTraining >>> # Download model and configuration from huggingface.co and cache. >>> model = AutoModelForPreTraining.from_pretrained('bert-base-cased') >>> # Update configuration during loading >>> model = AutoModelForPreTraining.from_pretrained('bert-base-cased', output_attentions=True) >>> model.config.output_attentions True >>> # Loading from a TF checkpoint file instead of a PyTorch model (slower) >>> config = AutoConfig.from_pretrained('./tf_model/bert_tf_model_config.json') >>> model = AutoModelForPreTraining.from_pretrained('./tf_model/bert_tf_checkpoint.ckpt.index', from_tf=True, config=config)
-
classmethod
AutoModelForCausalLMΒΆ
-
class
transformers.AutoModelForCausalLM(*args, **kwargs)[source]ΒΆ This is a generic model class that will be instantiated as one of the model classes of the library (with a causal language modeling head) when created with the
from_pretrained()class method or thefrom_config()class method.This class cannot be instantiated directly using
__init__()(throws an error).-
classmethod
from_config(config, **kwargs)ΒΆ Instantiates one of the model classes of the library (with a causal language modeling head) from a configuration.
Note
Loading a model from its configuration file does not load the model weights. It only affects the modelβs configuration. Use
from_pretrained()to load the model weights.- Parameters
config (
PretrainedConfig) βThe model class to instantiate is selected based on the configuration class:
BartConfigconfiguration class:BartForCausalLM(BART model)BertConfigconfiguration class:BertLMHeadModel(BERT model)BertGenerationConfigconfiguration class:BertGenerationDecoder(Bert Generation model)BigBirdConfigconfiguration class:BigBirdForCausalLM(BigBird model)BigBirdPegasusConfigconfiguration class:BigBirdPegasusForCausalLM(BigBirdPegasus model)BlenderbotConfigconfiguration class:BlenderbotForCausalLM(Blenderbot model)BlenderbotSmallConfigconfiguration class:BlenderbotSmallForCausalLM(BlenderbotSmall model)CTRLConfigconfiguration class:CTRLLMHeadModel(CTRL model)CamembertConfigconfiguration class:CamembertForCausalLM(CamemBERT model)GPT2Configconfiguration class:GPT2LMHeadModel(OpenAI GPT-2 model)GPTNeoConfigconfiguration class:GPTNeoForCausalLM(GPT Neo model)MBartConfigconfiguration class:MBartForCausalLM(mBART model)MarianConfigconfiguration class:MarianForCausalLM(Marian model)MegatronBertConfigconfiguration class:MegatronBertForCausalLM(MegatronBert model)OpenAIGPTConfigconfiguration class:OpenAIGPTLMHeadModel(OpenAI GPT model)PegasusConfigconfiguration class:PegasusForCausalLM(Pegasus model)ProphetNetConfigconfiguration class:ProphetNetForCausalLM(ProphetNet model)ReformerConfigconfiguration class:ReformerModelWithLMHead(Reformer model)RoFormerConfigconfiguration class:RoFormerForCausalLM(RoFormer model)RobertaConfigconfiguration class:RobertaForCausalLM(RoBERTa model)TransfoXLConfigconfiguration class:TransfoXLLMHeadModel(Transformer-XL model)XLMConfigconfiguration class:XLMWithLMHeadModel(XLM model)XLMProphetNetConfigconfiguration class:XLMProphetNetForCausalLM(XLMProphetNet model)XLMRobertaConfigconfiguration class:XLMRobertaForCausalLM(XLM-RoBERTa model)XLNetConfigconfiguration class:XLNetLMHeadModel(XLNet model)
Examples:
>>> from transformers import AutoConfig, AutoModelForCausalLM >>> # Download configuration from huggingface.co and cache. >>> config = AutoConfig.from_pretrained('bert-base-cased') >>> model = AutoModelForCausalLM.from_config(config)
-
classmethod
from_pretrained(pretrained_model_name_or_path, *model_args, **kwargs)ΒΆ Instantiate one of the model classes of the library (with a causal language modeling head) from a pretrained model.
The model class to instantiate is selected based on the
model_typeproperty of the config object (either passed as an argument or loaded frompretrained_model_name_or_pathif possible), or when itβs missing, by falling back to using pattern matching onpretrained_model_name_or_path:bart β
BartForCausalLM(BART model)bert β
BertLMHeadModel(BERT model)bert-generation β
BertGenerationDecoder(Bert Generation model)big_bird β
BigBirdForCausalLM(BigBird model)bigbird_pegasus β
BigBirdPegasusForCausalLM(BigBirdPegasus model)blenderbot β
BlenderbotForCausalLM(Blenderbot model)blenderbot-small β
BlenderbotSmallForCausalLM(BlenderbotSmall model)camembert β
CamembertForCausalLM(CamemBERT model)ctrl β
CTRLLMHeadModel(CTRL model)gpt2 β
GPT2LMHeadModel(OpenAI GPT-2 model)gpt_neo β
GPTNeoForCausalLM(GPT Neo model)marian β
MarianForCausalLM(Marian model)mbart β
MBartForCausalLM(mBART model)megatron-bert β
MegatronBertForCausalLM(MegatronBert model)openai-gpt β
OpenAIGPTLMHeadModel(OpenAI GPT model)pegasus β
PegasusForCausalLM(Pegasus model)prophetnet β
ProphetNetForCausalLM(ProphetNet model)reformer β
ReformerModelWithLMHead(Reformer model)roberta β
RobertaForCausalLM(RoBERTa model)roformer β
RoFormerForCausalLM(RoFormer model)transfo-xl β
TransfoXLLMHeadModel(Transformer-XL model)xlm β
XLMWithLMHeadModel(XLM model)xlm-prophetnet β
XLMProphetNetForCausalLM(XLMProphetNet model)xlm-roberta β
XLMRobertaForCausalLM(XLM-RoBERTa model)xlnet β
XLNetLMHeadModel(XLNet model)
The model is set in evaluation mode by default using
model.eval()(so for instance, dropout modules are deactivated). To train the model, you should first set it back in training mode withmodel.train()- Parameters
pretrained_model_name_or_path (
stroros.PathLike) βCan be either:
A string, the model id of a pretrained model hosted inside a model repo on huggingface.co. Valid model ids can be located at the root-level, like
bert-base-uncased, or namespaced under a user or organization name, likedbmdz/bert-base-german-cased.A path to a directory containing model weights saved using
save_pretrained(), e.g.,./my_model_directory/.A path or url to a tensorflow index checkpoint file (e.g,
./tf_model/model.ckpt.index). In this case,from_tfshould be set toTrueand a configuration object should be provided asconfigargument. This loading path is slower than converting the TensorFlow checkpoint in a PyTorch model using the provided conversion scripts and loading the PyTorch model afterwards.
model_args (additional positional arguments, optional) β Will be passed along to the underlying model
__init__()method.config (
PretrainedConfig, optional) βConfiguration for the model to use instead of an automatically loaded configuration. Configuration can be automatically loaded when:
The model is a model provided by the library (loaded with the model id string of a pretrained model).
The model was saved using
save_pretrained()and is reloaded by supplying the save directory.The model is loaded by supplying a local directory as
pretrained_model_name_or_pathand a configuration JSON file named config.json is found in the directory.
state_dict (Dict[str, torch.Tensor], optional) β
A state dictionary to use instead of a state dictionary loaded from saved weights file.
This option can be used if you want to create a model from a pretrained configuration but load your own weights. In this case though, you should check if using
save_pretrained()andfrom_pretrained()is not a simpler option.cache_dir (
stroros.PathLike, optional) β Path to a directory in which a downloaded pretrained model configuration should be cached if the standard cache should not be used.from_tf (
bool, optional, defaults toFalse) β Load the model weights from a TensorFlow checkpoint save file (see docstring ofpretrained_model_name_or_pathargument).force_download (
bool, optional, defaults toFalse) β Whether or not to force the (re-)download of the model weights and configuration files, overriding the cached versions if they exist.resume_download (
bool, optional, defaults toFalse) β Whether or not to delete incompletely received files. Will attempt to resume the download if such a file exists.proxies (
Dict[str, str], `optional) β A dictionary of proxy servers to use by protocol or endpoint, e.g.,{'http': 'foo.bar:3128', 'http://hostname': 'foo.bar:4012'}. The proxies are used on each request.output_loading_info (
bool, optional, defaults toFalse) β Whether ot not to also return a dictionary containing missing keys, unexpected keys and error messages.local_files_only (
bool, optional, defaults toFalse) β Whether or not to only look at local files (e.g., not try downloading the model).revision (
str, optional, defaults to"main") β The specific model version to use. It can be a branch name, a tag name, or a commit id, since we use a git-based system for storing models and other artifacts on huggingface.co, sorevisioncan be any identifier allowed by git.kwargs (additional keyword arguments, optional) β
Can be used to update the configuration object (after it being loaded) and initiate the model (e.g.,
output_attentions=True). Behaves differently depending on whether aconfigis provided or automatically loaded:If a configuration is provided with
config,**kwargswill be directly passed to the underlying modelβs__init__method (we assume all relevant updates to the configuration have already been done)If a configuration is not provided,
kwargswill be first passed to the configuration class initialization function (from_pretrained()). Each key ofkwargsthat corresponds to a configuration attribute will be used to override said attribute with the suppliedkwargsvalue. Remaining keys that do not correspond to any configuration attribute will be passed to the underlying modelβs__init__function.
Examples:
>>> from transformers import AutoConfig, AutoModelForCausalLM >>> # Download model and configuration from huggingface.co and cache. >>> model = AutoModelForCausalLM.from_pretrained('bert-base-cased') >>> # Update configuration during loading >>> model = AutoModelForCausalLM.from_pretrained('bert-base-cased', output_attentions=True) >>> model.config.output_attentions True >>> # Loading from a TF checkpoint file instead of a PyTorch model (slower) >>> config = AutoConfig.from_pretrained('./tf_model/bert_tf_model_config.json') >>> model = AutoModelForCausalLM.from_pretrained('./tf_model/bert_tf_checkpoint.ckpt.index', from_tf=True, config=config)
-
classmethod
AutoModelForMaskedLMΒΆ
-
class
transformers.AutoModelForMaskedLM(*args, **kwargs)[source]ΒΆ This is a generic model class that will be instantiated as one of the model classes of the library (with a masked language modeling head) when created with the
from_pretrained()class method or thefrom_config()class method.This class cannot be instantiated directly using
__init__()(throws an error).-
classmethod
from_config(config, **kwargs)ΒΆ Instantiates one of the model classes of the library (with a masked language modeling head) from a configuration.
Note
Loading a model from its configuration file does not load the model weights. It only affects the modelβs configuration. Use
from_pretrained()to load the model weights.- Parameters
config (
PretrainedConfig) βThe model class to instantiate is selected based on the configuration class:
AlbertConfigconfiguration class:AlbertForMaskedLM(ALBERT model)BartConfigconfiguration class:BartForConditionalGeneration(BART model)BertConfigconfiguration class:BertForMaskedLM(BERT model)BigBirdConfigconfiguration class:BigBirdForMaskedLM(BigBird model)CamembertConfigconfiguration class:CamembertForMaskedLM(CamemBERT model)ConvBertConfigconfiguration class:ConvBertForMaskedLM(ConvBERT model)DebertaConfigconfiguration class:DebertaForMaskedLM(DeBERTa model)DebertaV2Configconfiguration class:DebertaV2ForMaskedLM(DeBERTa-v2 model)DistilBertConfigconfiguration class:DistilBertForMaskedLM(DistilBERT model)ElectraConfigconfiguration class:ElectraForMaskedLM(ELECTRA model)FlaubertConfigconfiguration class:FlaubertWithLMHeadModel(FlauBERT model)FunnelConfigconfiguration class:FunnelForMaskedLM(Funnel Transformer model)IBertConfigconfiguration class:IBertForMaskedLM(I-BERT model)LayoutLMConfigconfiguration class:LayoutLMForMaskedLM(LayoutLM model)LongformerConfigconfiguration class:LongformerForMaskedLM(Longformer model)MBartConfigconfiguration class:MBartForConditionalGeneration(mBART model)MPNetConfigconfiguration class:MPNetForMaskedLM(MPNet model)MegatronBertConfigconfiguration class:MegatronBertForMaskedLM(MegatronBert model)MobileBertConfigconfiguration class:MobileBertForMaskedLM(MobileBERT model)ReformerConfigconfiguration class:ReformerForMaskedLM(Reformer model)RoFormerConfigconfiguration class:RoFormerForMaskedLM(RoFormer model)RobertaConfigconfiguration class:RobertaForMaskedLM(RoBERTa model)SqueezeBertConfigconfiguration class:SqueezeBertForMaskedLM(SqueezeBERT model)TapasConfigconfiguration class:TapasForMaskedLM(TAPAS model)Wav2Vec2Configconfiguration class:Wav2Vec2ForMaskedLM(Wav2Vec2 model)XLMConfigconfiguration class:XLMWithLMHeadModel(XLM model)XLMRobertaConfigconfiguration class:XLMRobertaForMaskedLM(XLM-RoBERTa model)
Examples:
>>> from transformers import AutoConfig, AutoModelForMaskedLM >>> # Download configuration from huggingface.co and cache. >>> config = AutoConfig.from_pretrained('bert-base-cased') >>> model = AutoModelForMaskedLM.from_config(config)
-
classmethod
from_pretrained(pretrained_model_name_or_path, *model_args, **kwargs)ΒΆ Instantiate one of the model classes of the library (with a masked language modeling head) from a pretrained model.
The model class to instantiate is selected based on the
model_typeproperty of the config object (either passed as an argument or loaded frompretrained_model_name_or_pathif possible), or when itβs missing, by falling back to using pattern matching onpretrained_model_name_or_path:albert β
AlbertForMaskedLM(ALBERT model)bart β
BartForConditionalGeneration(BART model)bert β
BertForMaskedLM(BERT model)big_bird β
BigBirdForMaskedLM(BigBird model)camembert β
CamembertForMaskedLM(CamemBERT model)convbert β
ConvBertForMaskedLM(ConvBERT model)deberta β
DebertaForMaskedLM(DeBERTa model)deberta-v2 β
DebertaV2ForMaskedLM(DeBERTa-v2 model)distilbert β
DistilBertForMaskedLM(DistilBERT model)electra β
ElectraForMaskedLM(ELECTRA model)flaubert β
FlaubertWithLMHeadModel(FlauBERT model)funnel β
FunnelForMaskedLM(Funnel Transformer model)ibert β
IBertForMaskedLM(I-BERT model)layoutlm β
LayoutLMForMaskedLM(LayoutLM model)longformer β
LongformerForMaskedLM(Longformer model)mbart β
MBartForConditionalGeneration(mBART model)megatron-bert β
MegatronBertForMaskedLM(MegatronBert model)mobilebert β
MobileBertForMaskedLM(MobileBERT model)mpnet β
MPNetForMaskedLM(MPNet model)reformer β
ReformerForMaskedLM(Reformer model)roberta β
RobertaForMaskedLM(RoBERTa model)roformer β
RoFormerForMaskedLM(RoFormer model)squeezebert β
SqueezeBertForMaskedLM(SqueezeBERT model)tapas β
TapasForMaskedLM(TAPAS model)wav2vec2 β
Wav2Vec2ForMaskedLM(Wav2Vec2 model)xlm β
XLMWithLMHeadModel(XLM model)xlm-roberta β
XLMRobertaForMaskedLM(XLM-RoBERTa model)
The model is set in evaluation mode by default using
model.eval()(so for instance, dropout modules are deactivated). To train the model, you should first set it back in training mode withmodel.train()- Parameters
pretrained_model_name_or_path (
stroros.PathLike) βCan be either:
A string, the model id of a pretrained model hosted inside a model repo on huggingface.co. Valid model ids can be located at the root-level, like
bert-base-uncased, or namespaced under a user or organization name, likedbmdz/bert-base-german-cased.A path to a directory containing model weights saved using
save_pretrained(), e.g.,./my_model_directory/.A path or url to a tensorflow index checkpoint file (e.g,
./tf_model/model.ckpt.index). In this case,from_tfshould be set toTrueand a configuration object should be provided asconfigargument. This loading path is slower than converting the TensorFlow checkpoint in a PyTorch model using the provided conversion scripts and loading the PyTorch model afterwards.
model_args (additional positional arguments, optional) β Will be passed along to the underlying model
__init__()method.config (
PretrainedConfig, optional) βConfiguration for the model to use instead of an automatically loaded configuration. Configuration can be automatically loaded when:
The model is a model provided by the library (loaded with the model id string of a pretrained model).
The model was saved using
save_pretrained()and is reloaded by supplying the save directory.The model is loaded by supplying a local directory as
pretrained_model_name_or_pathand a configuration JSON file named config.json is found in the directory.
state_dict (Dict[str, torch.Tensor], optional) β
A state dictionary to use instead of a state dictionary loaded from saved weights file.
This option can be used if you want to create a model from a pretrained configuration but load your own weights. In this case though, you should check if using
save_pretrained()andfrom_pretrained()is not a simpler option.cache_dir (
stroros.PathLike, optional) β Path to a directory in which a downloaded pretrained model configuration should be cached if the standard cache should not be used.from_tf (
bool, optional, defaults toFalse) β Load the model weights from a TensorFlow checkpoint save file (see docstring ofpretrained_model_name_or_pathargument).force_download (
bool, optional, defaults toFalse) β Whether or not to force the (re-)download of the model weights and configuration files, overriding the cached versions if they exist.resume_download (
bool, optional, defaults toFalse) β Whether or not to delete incompletely received files. Will attempt to resume the download if such a file exists.proxies (
Dict[str, str], `optional) β A dictionary of proxy servers to use by protocol or endpoint, e.g.,{'http': 'foo.bar:3128', 'http://hostname': 'foo.bar:4012'}. The proxies are used on each request.output_loading_info (
bool, optional, defaults toFalse) β Whether ot not to also return a dictionary containing missing keys, unexpected keys and error messages.local_files_only (
bool, optional, defaults toFalse) β Whether or not to only look at local files (e.g., not try downloading the model).revision (
str, optional, defaults to"main") β The specific model version to use. It can be a branch name, a tag name, or a commit id, since we use a git-based system for storing models and other artifacts on huggingface.co, sorevisioncan be any identifier allowed by git.kwargs (additional keyword arguments, optional) β
Can be used to update the configuration object (after it being loaded) and initiate the model (e.g.,
output_attentions=True). Behaves differently depending on whether aconfigis provided or automatically loaded:If a configuration is provided with
config,**kwargswill be directly passed to the underlying modelβs__init__method (we assume all relevant updates to the configuration have already been done)If a configuration is not provided,
kwargswill be first passed to the configuration class initialization function (from_pretrained()). Each key ofkwargsthat corresponds to a configuration attribute will be used to override said attribute with the suppliedkwargsvalue. Remaining keys that do not correspond to any configuration attribute will be passed to the underlying modelβs__init__function.
Examples:
>>> from transformers import AutoConfig, AutoModelForMaskedLM >>> # Download model and configuration from huggingface.co and cache. >>> model = AutoModelForMaskedLM.from_pretrained('bert-base-cased') >>> # Update configuration during loading >>> model = AutoModelForMaskedLM.from_pretrained('bert-base-cased', output_attentions=True) >>> model.config.output_attentions True >>> # Loading from a TF checkpoint file instead of a PyTorch model (slower) >>> config = AutoConfig.from_pretrained('./tf_model/bert_tf_model_config.json') >>> model = AutoModelForMaskedLM.from_pretrained('./tf_model/bert_tf_checkpoint.ckpt.index', from_tf=True, config=config)
-
classmethod
AutoModelForSeq2SeqLMΒΆ
-
class
transformers.AutoModelForSeq2SeqLM(*args, **kwargs)[source]ΒΆ This is a generic model class that will be instantiated as one of the model classes of the library (with a sequence-to-sequence language modeling head) when created with the
from_pretrained()class method or thefrom_config()class method.This class cannot be instantiated directly using
__init__()(throws an error).-
classmethod
from_config(config, **kwargs)ΒΆ Instantiates one of the model classes of the library (with a sequence-to-sequence language modeling head) from a configuration.
Note
Loading a model from its configuration file does not load the model weights. It only affects the modelβs configuration. Use
from_pretrained()to load the model weights.- Parameters
config (
PretrainedConfig) βThe model class to instantiate is selected based on the configuration class:
BartConfigconfiguration class:BartForConditionalGeneration(BART model)BigBirdPegasusConfigconfiguration class:BigBirdPegasusForConditionalGeneration(BigBirdPegasus model)BlenderbotConfigconfiguration class:BlenderbotForConditionalGeneration(Blenderbot model)BlenderbotSmallConfigconfiguration class:BlenderbotSmallForConditionalGeneration(BlenderbotSmall model)EncoderDecoderConfigconfiguration class:EncoderDecoderModel(Encoder decoder model)FSMTConfigconfiguration class:FSMTForConditionalGeneration(FairSeq Machine-Translation model)LEDConfigconfiguration class:LEDForConditionalGeneration(LED model)M2M100Configconfiguration class:M2M100ForConditionalGeneration(M2M100 model)MBartConfigconfiguration class:MBartForConditionalGeneration(mBART model)MT5Configconfiguration class:MT5ForConditionalGeneration(mT5 model)MarianConfigconfiguration class:MarianMTModel(Marian model)PegasusConfigconfiguration class:PegasusForConditionalGeneration(Pegasus model)ProphetNetConfigconfiguration class:ProphetNetForConditionalGeneration(ProphetNet model)T5Configconfiguration class:T5ForConditionalGeneration(T5 model)XLMProphetNetConfigconfiguration class:XLMProphetNetForConditionalGeneration(XLMProphetNet model)
Examples:
>>> from transformers import AutoConfig, AutoModelForSeq2SeqLM >>> # Download configuration from huggingface.co and cache. >>> config = AutoConfig.from_pretrained('t5-base') >>> model = AutoModelForSeq2SeqLM.from_config(config)
-
classmethod
from_pretrained(pretrained_model_name_or_path, *model_args, **kwargs)ΒΆ Instantiate one of the model classes of the library (with a sequence-to-sequence language modeling head) from a pretrained model.
The model class to instantiate is selected based on the
model_typeproperty of the config object (either passed as an argument or loaded frompretrained_model_name_or_pathif possible), or when itβs missing, by falling back to using pattern matching onpretrained_model_name_or_path:bart β
BartForConditionalGeneration(BART model)bigbird_pegasus β
BigBirdPegasusForConditionalGeneration(BigBirdPegasus model)blenderbot β
BlenderbotForConditionalGeneration(Blenderbot model)blenderbot-small β
BlenderbotSmallForConditionalGeneration(BlenderbotSmall model)encoder-decoder β
EncoderDecoderModel(Encoder decoder model)fsmt β
FSMTForConditionalGeneration(FairSeq Machine-Translation model)led β
LEDForConditionalGeneration(LED model)m2m_100 β
M2M100ForConditionalGeneration(M2M100 model)marian β
MarianMTModel(Marian model)mbart β
MBartForConditionalGeneration(mBART model)mt5 β
MT5ForConditionalGeneration(mT5 model)pegasus β
PegasusForConditionalGeneration(Pegasus model)prophetnet β
ProphetNetForConditionalGeneration(ProphetNet model)t5 β
T5ForConditionalGeneration(T5 model)xlm-prophetnet β
XLMProphetNetForConditionalGeneration(XLMProphetNet model)
The model is set in evaluation mode by default using
model.eval()(so for instance, dropout modules are deactivated). To train the model, you should first set it back in training mode withmodel.train()- Parameters
pretrained_model_name_or_path (
stroros.PathLike) βCan be either:
A string, the model id of a pretrained model hosted inside a model repo on huggingface.co. Valid model ids can be located at the root-level, like
bert-base-uncased, or namespaced under a user or organization name, likedbmdz/bert-base-german-cased.A path to a directory containing model weights saved using
save_pretrained(), e.g.,./my_model_directory/.A path or url to a tensorflow index checkpoint file (e.g,
./tf_model/model.ckpt.index). In this case,from_tfshould be set toTrueand a configuration object should be provided asconfigargument. This loading path is slower than converting the TensorFlow checkpoint in a PyTorch model using the provided conversion scripts and loading the PyTorch model afterwards.
model_args (additional positional arguments, optional) β Will be passed along to the underlying model
__init__()method.config (
PretrainedConfig, optional) βConfiguration for the model to use instead of an automatically loaded configuration. Configuration can be automatically loaded when:
The model is a model provided by the library (loaded with the model id string of a pretrained model).
The model was saved using
save_pretrained()and is reloaded by supplying the save directory.The model is loaded by supplying a local directory as
pretrained_model_name_or_pathand a configuration JSON file named config.json is found in the directory.
state_dict (Dict[str, torch.Tensor], optional) β
A state dictionary to use instead of a state dictionary loaded from saved weights file.
This option can be used if you want to create a model from a pretrained configuration but load your own weights. In this case though, you should check if using
save_pretrained()andfrom_pretrained()is not a simpler option.cache_dir (
stroros.PathLike, optional) β Path to a directory in which a downloaded pretrained model configuration should be cached if the standard cache should not be used.from_tf (
bool, optional, defaults toFalse) β Load the model weights from a TensorFlow checkpoint save file (see docstring ofpretrained_model_name_or_pathargument).force_download (
bool, optional, defaults toFalse) β Whether or not to force the (re-)download of the model weights and configuration files, overriding the cached versions if they exist.resume_download (
bool, optional, defaults toFalse) β Whether or not to delete incompletely received files. Will attempt to resume the download if such a file exists.proxies (
Dict[str, str], `optional) β A dictionary of proxy servers to use by protocol or endpoint, e.g.,{'http': 'foo.bar:3128', 'http://hostname': 'foo.bar:4012'}. The proxies are used on each request.output_loading_info (
bool, optional, defaults toFalse) β Whether ot not to also return a dictionary containing missing keys, unexpected keys and error messages.local_files_only (
bool, optional, defaults toFalse) β Whether or not to only look at local files (e.g., not try downloading the model).revision (
str, optional, defaults to"main") β The specific model version to use. It can be a branch name, a tag name, or a commit id, since we use a git-based system for storing models and other artifacts on huggingface.co, sorevisioncan be any identifier allowed by git.kwargs (additional keyword arguments, optional) β
Can be used to update the configuration object (after it being loaded) and initiate the model (e.g.,
output_attentions=True). Behaves differently depending on whether aconfigis provided or automatically loaded:If a configuration is provided with
config,**kwargswill be directly passed to the underlying modelβs__init__method (we assume all relevant updates to the configuration have already been done)If a configuration is not provided,
kwargswill be first passed to the configuration class initialization function (from_pretrained()). Each key ofkwargsthat corresponds to a configuration attribute will be used to override said attribute with the suppliedkwargsvalue. Remaining keys that do not correspond to any configuration attribute will be passed to the underlying modelβs__init__function.
Examples:
>>> from transformers import AutoConfig, AutoModelForSeq2SeqLM >>> # Download model and configuration from huggingface.co and cache. >>> model = AutoModelForSeq2SeqLM.from_pretrained('t5-base') >>> # Update configuration during loading >>> model = AutoModelForSeq2SeqLM.from_pretrained('t5-base', output_attentions=True) >>> model.config.output_attentions True >>> # Loading from a TF checkpoint file instead of a PyTorch model (slower) >>> config = AutoConfig.from_pretrained('./tf_model/t5_tf_model_config.json') >>> model = AutoModelForSeq2SeqLM.from_pretrained('./tf_model/t5_tf_checkpoint.ckpt.index', from_tf=True, config=config)
-
classmethod
AutoModelForSequenceClassificationΒΆ
-
class
transformers.AutoModelForSequenceClassification(*args, **kwargs)[source]ΒΆ This is a generic model class that will be instantiated as one of the model classes of the library (with a sequence classification head) when created with the
from_pretrained()class method or thefrom_config()class method.This class cannot be instantiated directly using
__init__()(throws an error).-
classmethod
from_config(config, **kwargs)ΒΆ Instantiates one of the model classes of the library (with a sequence classification head) from a configuration.
Note
Loading a model from its configuration file does not load the model weights. It only affects the modelβs configuration. Use
from_pretrained()to load the model weights.- Parameters
config (
PretrainedConfig) βThe model class to instantiate is selected based on the configuration class:
AlbertConfigconfiguration class:AlbertForSequenceClassification(ALBERT model)BartConfigconfiguration class:BartForSequenceClassification(BART model)BertConfigconfiguration class:BertForSequenceClassification(BERT model)BigBirdConfigconfiguration class:BigBirdForSequenceClassification(BigBird model)BigBirdPegasusConfigconfiguration class:BigBirdPegasusForSequenceClassification(BigBirdPegasus model)CTRLConfigconfiguration class:CTRLForSequenceClassification(CTRL model)CamembertConfigconfiguration class:CamembertForSequenceClassification(CamemBERT model)CanineConfigconfiguration class:CanineForSequenceClassification(Canine model)ConvBertConfigconfiguration class:ConvBertForSequenceClassification(ConvBERT model)DebertaConfigconfiguration class:DebertaForSequenceClassification(DeBERTa model)DebertaV2Configconfiguration class:DebertaV2ForSequenceClassification(DeBERTa-v2 model)DistilBertConfigconfiguration class:DistilBertForSequenceClassification(DistilBERT model)ElectraConfigconfiguration class:ElectraForSequenceClassification(ELECTRA model)FlaubertConfigconfiguration class:FlaubertForSequenceClassification(FlauBERT model)FunnelConfigconfiguration class:FunnelForSequenceClassification(Funnel Transformer model)GPT2Configconfiguration class:GPT2ForSequenceClassification(OpenAI GPT-2 model)GPTNeoConfigconfiguration class:GPTNeoForSequenceClassification(GPT Neo model)IBertConfigconfiguration class:IBertForSequenceClassification(I-BERT model)LEDConfigconfiguration class:LEDForSequenceClassification(LED model)LayoutLMConfigconfiguration class:LayoutLMForSequenceClassification(LayoutLM model)LongformerConfigconfiguration class:LongformerForSequenceClassification(Longformer model)MBartConfigconfiguration class:MBartForSequenceClassification(mBART model)MPNetConfigconfiguration class:MPNetForSequenceClassification(MPNet model)MegatronBertConfigconfiguration class:MegatronBertForSequenceClassification(MegatronBert model)MobileBertConfigconfiguration class:MobileBertForSequenceClassification(MobileBERT model)OpenAIGPTConfigconfiguration class:OpenAIGPTForSequenceClassification(OpenAI GPT model)ReformerConfigconfiguration class:ReformerForSequenceClassification(Reformer model)RoFormerConfigconfiguration class:RoFormerForSequenceClassification(RoFormer model)RobertaConfigconfiguration class:RobertaForSequenceClassification(RoBERTa model)SqueezeBertConfigconfiguration class:SqueezeBertForSequenceClassification(SqueezeBERT model)TapasConfigconfiguration class:TapasForSequenceClassification(TAPAS model)TransfoXLConfigconfiguration class:TransfoXLForSequenceClassification(Transformer-XL model)XLMConfigconfiguration class:XLMForSequenceClassification(XLM model)XLMRobertaConfigconfiguration class:XLMRobertaForSequenceClassification(XLM-RoBERTa model)XLNetConfigconfiguration class:XLNetForSequenceClassification(XLNet model)
Examples:
>>> from transformers import AutoConfig, AutoModelForSequenceClassification >>> # Download configuration from huggingface.co and cache. >>> config = AutoConfig.from_pretrained('bert-base-cased') >>> model = AutoModelForSequenceClassification.from_config(config)
-
classmethod
from_pretrained(pretrained_model_name_or_path, *model_args, **kwargs)ΒΆ Instantiate one of the model classes of the library (with a sequence classification head) from a pretrained model.
The model class to instantiate is selected based on the
model_typeproperty of the config object (either passed as an argument or loaded frompretrained_model_name_or_pathif possible), or when itβs missing, by falling back to using pattern matching onpretrained_model_name_or_path:albert β
AlbertForSequenceClassification(ALBERT model)bart β
BartForSequenceClassification(BART model)bert β
BertForSequenceClassification(BERT model)big_bird β
BigBirdForSequenceClassification(BigBird model)bigbird_pegasus β
BigBirdPegasusForSequenceClassification(BigBirdPegasus model)camembert β
CamembertForSequenceClassification(CamemBERT model)canine β
CanineForSequenceClassification(Canine model)convbert β
ConvBertForSequenceClassification(ConvBERT model)ctrl β
CTRLForSequenceClassification(CTRL model)deberta β
DebertaForSequenceClassification(DeBERTa model)deberta-v2 β
DebertaV2ForSequenceClassification(DeBERTa-v2 model)distilbert β
DistilBertForSequenceClassification(DistilBERT model)electra β
ElectraForSequenceClassification(ELECTRA model)flaubert β
FlaubertForSequenceClassification(FlauBERT model)funnel β
FunnelForSequenceClassification(Funnel Transformer model)gpt2 β
GPT2ForSequenceClassification(OpenAI GPT-2 model)gpt_neo β
GPTNeoForSequenceClassification(GPT Neo model)ibert β
IBertForSequenceClassification(I-BERT model)layoutlm β
LayoutLMForSequenceClassification(LayoutLM model)led β
LEDForSequenceClassification(LED model)longformer β
LongformerForSequenceClassification(Longformer model)mbart β
MBartForSequenceClassification(mBART model)megatron-bert β
MegatronBertForSequenceClassification(MegatronBert model)mobilebert β
MobileBertForSequenceClassification(MobileBERT model)mpnet β
MPNetForSequenceClassification(MPNet model)openai-gpt β
OpenAIGPTForSequenceClassification(OpenAI GPT model)reformer β
ReformerForSequenceClassification(Reformer model)roberta β
RobertaForSequenceClassification(RoBERTa model)roformer β
RoFormerForSequenceClassification(RoFormer model)squeezebert β
SqueezeBertForSequenceClassification(SqueezeBERT model)tapas β
TapasForSequenceClassification(TAPAS model)transfo-xl β
TransfoXLForSequenceClassification(Transformer-XL model)xlm β
XLMForSequenceClassification(XLM model)xlm-roberta β
XLMRobertaForSequenceClassification(XLM-RoBERTa model)xlnet β
XLNetForSequenceClassification(XLNet model)
The model is set in evaluation mode by default using
model.eval()(so for instance, dropout modules are deactivated). To train the model, you should first set it back in training mode withmodel.train()- Parameters
pretrained_model_name_or_path (
stroros.PathLike) βCan be either:
A string, the model id of a pretrained model hosted inside a model repo on huggingface.co. Valid model ids can be located at the root-level, like
bert-base-uncased, or namespaced under a user or organization name, likedbmdz/bert-base-german-cased.A path to a directory containing model weights saved using
save_pretrained(), e.g.,./my_model_directory/.A path or url to a tensorflow index checkpoint file (e.g,
./tf_model/model.ckpt.index). In this case,from_tfshould be set toTrueand a configuration object should be provided asconfigargument. This loading path is slower than converting the TensorFlow checkpoint in a PyTorch model using the provided conversion scripts and loading the PyTorch model afterwards.
model_args (additional positional arguments, optional) β Will be passed along to the underlying model
__init__()method.config (
PretrainedConfig, optional) βConfiguration for the model to use instead of an automatically loaded configuration. Configuration can be automatically loaded when:
The model is a model provided by the library (loaded with the model id string of a pretrained model).
The model was saved using
save_pretrained()and is reloaded by supplying the save directory.The model is loaded by supplying a local directory as
pretrained_model_name_or_pathand a configuration JSON file named config.json is found in the directory.
state_dict (Dict[str, torch.Tensor], optional) β
A state dictionary to use instead of a state dictionary loaded from saved weights file.
This option can be used if you want to create a model from a pretrained configuration but load your own weights. In this case though, you should check if using
save_pretrained()andfrom_pretrained()is not a simpler option.cache_dir (
stroros.PathLike, optional) β Path to a directory in which a downloaded pretrained model configuration should be cached if the standard cache should not be used.from_tf (
bool, optional, defaults toFalse) β Load the model weights from a TensorFlow checkpoint save file (see docstring ofpretrained_model_name_or_pathargument).force_download (
bool, optional, defaults toFalse) β Whether or not to force the (re-)download of the model weights and configuration files, overriding the cached versions if they exist.resume_download (
bool, optional, defaults toFalse) β Whether or not to delete incompletely received files. Will attempt to resume the download if such a file exists.proxies (
Dict[str, str], `optional) β A dictionary of proxy servers to use by protocol or endpoint, e.g.,{'http': 'foo.bar:3128', 'http://hostname': 'foo.bar:4012'}. The proxies are used on each request.output_loading_info (
bool, optional, defaults toFalse) β Whether ot not to also return a dictionary containing missing keys, unexpected keys and error messages.local_files_only (
bool, optional, defaults toFalse) β Whether or not to only look at local files (e.g., not try downloading the model).revision (
str, optional, defaults to"main") β The specific model version to use. It can be a branch name, a tag name, or a commit id, since we use a git-based system for storing models and other artifacts on huggingface.co, sorevisioncan be any identifier allowed by git.kwargs (additional keyword arguments, optional) β
Can be used to update the configuration object (after it being loaded) and initiate the model (e.g.,
output_attentions=True). Behaves differently depending on whether aconfigis provided or automatically loaded:If a configuration is provided with
config,**kwargswill be directly passed to the underlying modelβs__init__method (we assume all relevant updates to the configuration have already been done)If a configuration is not provided,
kwargswill be first passed to the configuration class initialization function (from_pretrained()). Each key ofkwargsthat corresponds to a configuration attribute will be used to override said attribute with the suppliedkwargsvalue. Remaining keys that do not correspond to any configuration attribute will be passed to the underlying modelβs__init__function.
Examples:
>>> from transformers import AutoConfig, AutoModelForSequenceClassification >>> # Download model and configuration from huggingface.co and cache. >>> model = AutoModelForSequenceClassification.from_pretrained('bert-base-cased') >>> # Update configuration during loading >>> model = AutoModelForSequenceClassification.from_pretrained('bert-base-cased', output_attentions=True) >>> model.config.output_attentions True >>> # Loading from a TF checkpoint file instead of a PyTorch model (slower) >>> config = AutoConfig.from_pretrained('./tf_model/bert_tf_model_config.json') >>> model = AutoModelForSequenceClassification.from_pretrained('./tf_model/bert_tf_checkpoint.ckpt.index', from_tf=True, config=config)
-
classmethod
AutoModelForMultipleChoiceΒΆ
-
class
transformers.AutoModelForMultipleChoice(*args, **kwargs)[source]ΒΆ This is a generic model class that will be instantiated as one of the model classes of the library (with a multiple choice head) when created with the
from_pretrained()class method or thefrom_config()class method.This class cannot be instantiated directly using
__init__()(throws an error).-
classmethod
from_config(config, **kwargs)ΒΆ Instantiates one of the model classes of the library (with a multiple choice head) from a configuration.
Note
Loading a model from its configuration file does not load the model weights. It only affects the modelβs configuration. Use
from_pretrained()to load the model weights.- Parameters
config (
PretrainedConfig) βThe model class to instantiate is selected based on the configuration class:
AlbertConfigconfiguration class:AlbertForMultipleChoice(ALBERT model)BertConfigconfiguration class:BertForMultipleChoice(BERT model)BigBirdConfigconfiguration class:BigBirdForMultipleChoice(BigBird model)CamembertConfigconfiguration class:CamembertForMultipleChoice(CamemBERT model)CanineConfigconfiguration class:CanineForMultipleChoice(Canine model)ConvBertConfigconfiguration class:ConvBertForMultipleChoice(ConvBERT model)DistilBertConfigconfiguration class:DistilBertForMultipleChoice(DistilBERT model)ElectraConfigconfiguration class:ElectraForMultipleChoice(ELECTRA model)FlaubertConfigconfiguration class:FlaubertForMultipleChoice(FlauBERT model)FunnelConfigconfiguration class:FunnelForMultipleChoice(Funnel Transformer model)IBertConfigconfiguration class:IBertForMultipleChoice(I-BERT model)LongformerConfigconfiguration class:LongformerForMultipleChoice(Longformer model)MPNetConfigconfiguration class:MPNetForMultipleChoice(MPNet model)MegatronBertConfigconfiguration class:MegatronBertForMultipleChoice(MegatronBert model)MobileBertConfigconfiguration class:MobileBertForMultipleChoice(MobileBERT model)RoFormerConfigconfiguration class:RoFormerForMultipleChoice(RoFormer model)RobertaConfigconfiguration class:RobertaForMultipleChoice(RoBERTa model)SqueezeBertConfigconfiguration class:SqueezeBertForMultipleChoice(SqueezeBERT model)XLMConfigconfiguration class:XLMForMultipleChoice(XLM model)XLMRobertaConfigconfiguration class:XLMRobertaForMultipleChoice(XLM-RoBERTa model)XLNetConfigconfiguration class:XLNetForMultipleChoice(XLNet model)
Examples:
>>> from transformers import AutoConfig, AutoModelForMultipleChoice >>> # Download configuration from huggingface.co and cache. >>> config = AutoConfig.from_pretrained('bert-base-cased') >>> model = AutoModelForMultipleChoice.from_config(config)
-
classmethod
from_pretrained(pretrained_model_name_or_path, *model_args, **kwargs)ΒΆ Instantiate one of the model classes of the library (with a multiple choice head) from a pretrained model.
The model class to instantiate is selected based on the
model_typeproperty of the config object (either passed as an argument or loaded frompretrained_model_name_or_pathif possible), or when itβs missing, by falling back to using pattern matching onpretrained_model_name_or_path:albert β
AlbertForMultipleChoice(ALBERT model)bert β
BertForMultipleChoice(BERT model)big_bird β
BigBirdForMultipleChoice(BigBird model)camembert β
CamembertForMultipleChoice(CamemBERT model)canine β
CanineForMultipleChoice(Canine model)convbert β
ConvBertForMultipleChoice(ConvBERT model)distilbert β
DistilBertForMultipleChoice(DistilBERT model)electra β
ElectraForMultipleChoice(ELECTRA model)flaubert β
FlaubertForMultipleChoice(FlauBERT model)funnel β
FunnelForMultipleChoice(Funnel Transformer model)ibert β
IBertForMultipleChoice(I-BERT model)longformer β
LongformerForMultipleChoice(Longformer model)megatron-bert β
MegatronBertForMultipleChoice(MegatronBert model)mobilebert β
MobileBertForMultipleChoice(MobileBERT model)mpnet β
MPNetForMultipleChoice(MPNet model)roberta β
RobertaForMultipleChoice(RoBERTa model)roformer β
RoFormerForMultipleChoice(RoFormer model)squeezebert β
SqueezeBertForMultipleChoice(SqueezeBERT model)xlm β
XLMForMultipleChoice(XLM model)xlm-roberta β
XLMRobertaForMultipleChoice(XLM-RoBERTa model)xlnet β
XLNetForMultipleChoice(XLNet model)
The model is set in evaluation mode by default using
model.eval()(so for instance, dropout modules are deactivated). To train the model, you should first set it back in training mode withmodel.train()- Parameters
pretrained_model_name_or_path (
stroros.PathLike) βCan be either:
A string, the model id of a pretrained model hosted inside a model repo on huggingface.co. Valid model ids can be located at the root-level, like
bert-base-uncased, or namespaced under a user or organization name, likedbmdz/bert-base-german-cased.A path to a directory containing model weights saved using
save_pretrained(), e.g.,./my_model_directory/.A path or url to a tensorflow index checkpoint file (e.g,
./tf_model/model.ckpt.index). In this case,from_tfshould be set toTrueand a configuration object should be provided asconfigargument. This loading path is slower than converting the TensorFlow checkpoint in a PyTorch model using the provided conversion scripts and loading the PyTorch model afterwards.
model_args (additional positional arguments, optional) β Will be passed along to the underlying model
__init__()method.config (
PretrainedConfig, optional) βConfiguration for the model to use instead of an automatically loaded configuration. Configuration can be automatically loaded when:
The model is a model provided by the library (loaded with the model id string of a pretrained model).
The model was saved using
save_pretrained()and is reloaded by supplying the save directory.The model is loaded by supplying a local directory as
pretrained_model_name_or_pathand a configuration JSON file named config.json is found in the directory.
state_dict (Dict[str, torch.Tensor], optional) β
A state dictionary to use instead of a state dictionary loaded from saved weights file.
This option can be used if you want to create a model from a pretrained configuration but load your own weights. In this case though, you should check if using
save_pretrained()andfrom_pretrained()is not a simpler option.cache_dir (
stroros.PathLike, optional) β Path to a directory in which a downloaded pretrained model configuration should be cached if the standard cache should not be used.from_tf (
bool, optional, defaults toFalse) β Load the model weights from a TensorFlow checkpoint save file (see docstring ofpretrained_model_name_or_pathargument).force_download (
bool, optional, defaults toFalse) β Whether or not to force the (re-)download of the model weights and configuration files, overriding the cached versions if they exist.resume_download (
bool, optional, defaults toFalse) β Whether or not to delete incompletely received files. Will attempt to resume the download if such a file exists.proxies (
Dict[str, str], `optional) β A dictionary of proxy servers to use by protocol or endpoint, e.g.,{'http': 'foo.bar:3128', 'http://hostname': 'foo.bar:4012'}. The proxies are used on each request.output_loading_info (
bool, optional, defaults toFalse) β Whether ot not to also return a dictionary containing missing keys, unexpected keys and error messages.local_files_only (
bool, optional, defaults toFalse) β Whether or not to only look at local files (e.g., not try downloading the model).revision (
str, optional, defaults to"main") β The specific model version to use. It can be a branch name, a tag name, or a commit id, since we use a git-based system for storing models and other artifacts on huggingface.co, sorevisioncan be any identifier allowed by git.kwargs (additional keyword arguments, optional) β
Can be used to update the configuration object (after it being loaded) and initiate the model (e.g.,
output_attentions=True). Behaves differently depending on whether aconfigis provided or automatically loaded:If a configuration is provided with
config,**kwargswill be directly passed to the underlying modelβs__init__method (we assume all relevant updates to the configuration have already been done)If a configuration is not provided,
kwargswill be first passed to the configuration class initialization function (from_pretrained()). Each key ofkwargsthat corresponds to a configuration attribute will be used to override said attribute with the suppliedkwargsvalue. Remaining keys that do not correspond to any configuration attribute will be passed to the underlying modelβs__init__function.
Examples:
>>> from transformers import AutoConfig, AutoModelForMultipleChoice >>> # Download model and configuration from huggingface.co and cache. >>> model = AutoModelForMultipleChoice.from_pretrained('bert-base-cased') >>> # Update configuration during loading >>> model = AutoModelForMultipleChoice.from_pretrained('bert-base-cased', output_attentions=True) >>> model.config.output_attentions True >>> # Loading from a TF checkpoint file instead of a PyTorch model (slower) >>> config = AutoConfig.from_pretrained('./tf_model/bert_tf_model_config.json') >>> model = AutoModelForMultipleChoice.from_pretrained('./tf_model/bert_tf_checkpoint.ckpt.index', from_tf=True, config=config)
-
classmethod
AutoModelForNextSentencePredictionΒΆ
-
class
transformers.AutoModelForNextSentencePrediction(*args, **kwargs)[source]ΒΆ This is a generic model class that will be instantiated as one of the model classes of the library (with a next sentence prediction head) when created with the
from_pretrained()class method or thefrom_config()class method.This class cannot be instantiated directly using
__init__()(throws an error).-
classmethod
from_config(config, **kwargs)ΒΆ Instantiates one of the model classes of the library (with a next sentence prediction head) from a configuration.
Note
Loading a model from its configuration file does not load the model weights. It only affects the modelβs configuration. Use
from_pretrained()to load the model weights.- Parameters
config (
PretrainedConfig) βThe model class to instantiate is selected based on the configuration class:
BertConfigconfiguration class:BertForNextSentencePrediction(BERT model)MegatronBertConfigconfiguration class:MegatronBertForNextSentencePrediction(MegatronBert model)MobileBertConfigconfiguration class:MobileBertForNextSentencePrediction(MobileBERT model)
Examples:
>>> from transformers import AutoConfig, AutoModelForNextSentencePrediction >>> # Download configuration from huggingface.co and cache. >>> config = AutoConfig.from_pretrained('bert-base-cased') >>> model = AutoModelForNextSentencePrediction.from_config(config)
-
classmethod
from_pretrained(pretrained_model_name_or_path, *model_args, **kwargs)ΒΆ Instantiate one of the model classes of the library (with a next sentence prediction head) from a pretrained model.
The model class to instantiate is selected based on the
model_typeproperty of the config object (either passed as an argument or loaded frompretrained_model_name_or_pathif possible), or when itβs missing, by falling back to using pattern matching onpretrained_model_name_or_path:bert β
BertForNextSentencePrediction(BERT model)megatron-bert β
MegatronBertForNextSentencePrediction(MegatronBert model)mobilebert β
MobileBertForNextSentencePrediction(MobileBERT model)
The model is set in evaluation mode by default using
model.eval()(so for instance, dropout modules are deactivated). To train the model, you should first set it back in training mode withmodel.train()- Parameters
pretrained_model_name_or_path (
stroros.PathLike) βCan be either:
A string, the model id of a pretrained model hosted inside a model repo on huggingface.co. Valid model ids can be located at the root-level, like
bert-base-uncased, or namespaced under a user or organization name, likedbmdz/bert-base-german-cased.A path to a directory containing model weights saved using
save_pretrained(), e.g.,./my_model_directory/.A path or url to a tensorflow index checkpoint file (e.g,
./tf_model/model.ckpt.index). In this case,from_tfshould be set toTrueand a configuration object should be provided asconfigargument. This loading path is slower than converting the TensorFlow checkpoint in a PyTorch model using the provided conversion scripts and loading the PyTorch model afterwards.
model_args (additional positional arguments, optional) β Will be passed along to the underlying model
__init__()method.config (
PretrainedConfig, optional) βConfiguration for the model to use instead of an automatically loaded configuration. Configuration can be automatically loaded when:
The model is a model provided by the library (loaded with the model id string of a pretrained model).
The model was saved using
save_pretrained()and is reloaded by supplying the save directory.The model is loaded by supplying a local directory as
pretrained_model_name_or_pathand a configuration JSON file named config.json is found in the directory.
state_dict (Dict[str, torch.Tensor], optional) β
A state dictionary to use instead of a state dictionary loaded from saved weights file.
This option can be used if you want to create a model from a pretrained configuration but load your own weights. In this case though, you should check if using
save_pretrained()andfrom_pretrained()is not a simpler option.cache_dir (
stroros.PathLike, optional) β Path to a directory in which a downloaded pretrained model configuration should be cached if the standard cache should not be used.from_tf (
bool, optional, defaults toFalse) β Load the model weights from a TensorFlow checkpoint save file (see docstring ofpretrained_model_name_or_pathargument).force_download (
bool, optional, defaults toFalse) β Whether or not to force the (re-)download of the model weights and configuration files, overriding the cached versions if they exist.resume_download (
bool, optional, defaults toFalse) β Whether or not to delete incompletely received files. Will attempt to resume the download if such a file exists.proxies (
Dict[str, str], `optional) β A dictionary of proxy servers to use by protocol or endpoint, e.g.,{'http': 'foo.bar:3128', 'http://hostname': 'foo.bar:4012'}. The proxies are used on each request.output_loading_info (
bool, optional, defaults toFalse) β Whether ot not to also return a dictionary containing missing keys, unexpected keys and error messages.local_files_only (
bool, optional, defaults toFalse) β Whether or not to only look at local files (e.g., not try downloading the model).revision (
str, optional, defaults to"main") β The specific model version to use. It can be a branch name, a tag name, or a commit id, since we use a git-based system for storing models and other artifacts on huggingface.co, sorevisioncan be any identifier allowed by git.kwargs (additional keyword arguments, optional) β
Can be used to update the configuration object (after it being loaded) and initiate the model (e.g.,
output_attentions=True). Behaves differently depending on whether aconfigis provided or automatically loaded:If a configuration is provided with
config,**kwargswill be directly passed to the underlying modelβs__init__method (we assume all relevant updates to the configuration have already been done)If a configuration is not provided,
kwargswill be first passed to the configuration class initialization function (from_pretrained()). Each key ofkwargsthat corresponds to a configuration attribute will be used to override said attribute with the suppliedkwargsvalue. Remaining keys that do not correspond to any configuration attribute will be passed to the underlying modelβs__init__function.
Examples:
>>> from transformers import AutoConfig, AutoModelForNextSentencePrediction >>> # Download model and configuration from huggingface.co and cache. >>> model = AutoModelForNextSentencePrediction.from_pretrained('bert-base-cased') >>> # Update configuration during loading >>> model = AutoModelForNextSentencePrediction.from_pretrained('bert-base-cased', output_attentions=True) >>> model.config.output_attentions True >>> # Loading from a TF checkpoint file instead of a PyTorch model (slower) >>> config = AutoConfig.from_pretrained('./tf_model/bert_tf_model_config.json') >>> model = AutoModelForNextSentencePrediction.from_pretrained('./tf_model/bert_tf_checkpoint.ckpt.index', from_tf=True, config=config)
-
classmethod
AutoModelForTokenClassificationΒΆ
-
class
transformers.AutoModelForTokenClassification(*args, **kwargs)[source]ΒΆ This is a generic model class that will be instantiated as one of the model classes of the library (with a token classification head) when created with the
from_pretrained()class method or thefrom_config()class method.This class cannot be instantiated directly using
__init__()(throws an error).-
classmethod
from_config(config, **kwargs)ΒΆ Instantiates one of the model classes of the library (with a token classification head) from a configuration.
Note
Loading a model from its configuration file does not load the model weights. It only affects the modelβs configuration. Use
from_pretrained()to load the model weights.- Parameters
config (
PretrainedConfig) βThe model class to instantiate is selected based on the configuration class:
AlbertConfigconfiguration class:AlbertForTokenClassification(ALBERT model)BertConfigconfiguration class:BertForTokenClassification(BERT model)BigBirdConfigconfiguration class:BigBirdForTokenClassification(BigBird model)CamembertConfigconfiguration class:CamembertForTokenClassification(CamemBERT model)CanineConfigconfiguration class:CanineForTokenClassification(Canine model)ConvBertConfigconfiguration class:ConvBertForTokenClassification(ConvBERT model)DebertaConfigconfiguration class:DebertaForTokenClassification(DeBERTa model)DebertaV2Configconfiguration class:DebertaV2ForTokenClassification(DeBERTa-v2 model)DistilBertConfigconfiguration class:DistilBertForTokenClassification(DistilBERT model)ElectraConfigconfiguration class:ElectraForTokenClassification(ELECTRA model)FlaubertConfigconfiguration class:FlaubertForTokenClassification(FlauBERT model)FunnelConfigconfiguration class:FunnelForTokenClassification(Funnel Transformer model)IBertConfigconfiguration class:IBertForTokenClassification(I-BERT model)LayoutLMConfigconfiguration class:LayoutLMForTokenClassification(LayoutLM model)LongformerConfigconfiguration class:LongformerForTokenClassification(Longformer model)MPNetConfigconfiguration class:MPNetForTokenClassification(MPNet model)MegatronBertConfigconfiguration class:MegatronBertForTokenClassification(MegatronBert model)MobileBertConfigconfiguration class:MobileBertForTokenClassification(MobileBERT model)RoFormerConfigconfiguration class:RoFormerForTokenClassification(RoFormer model)RobertaConfigconfiguration class:RobertaForTokenClassification(RoBERTa model)SqueezeBertConfigconfiguration class:SqueezeBertForTokenClassification(SqueezeBERT model)XLMConfigconfiguration class:XLMForTokenClassification(XLM model)XLMRobertaConfigconfiguration class:XLMRobertaForTokenClassification(XLM-RoBERTa model)XLNetConfigconfiguration class:XLNetForTokenClassification(XLNet model)
Examples:
>>> from transformers import AutoConfig, AutoModelForTokenClassification >>> # Download configuration from huggingface.co and cache. >>> config = AutoConfig.from_pretrained('bert-base-cased') >>> model = AutoModelForTokenClassification.from_config(config)
-
classmethod
from_pretrained(pretrained_model_name_or_path, *model_args, **kwargs)ΒΆ Instantiate one of the model classes of the library (with a token classification head) from a pretrained model.
The model class to instantiate is selected based on the
model_typeproperty of the config object (either passed as an argument or loaded frompretrained_model_name_or_pathif possible), or when itβs missing, by falling back to using pattern matching onpretrained_model_name_or_path:albert β
AlbertForTokenClassification(ALBERT model)bert β
BertForTokenClassification(BERT model)big_bird β
BigBirdForTokenClassification(BigBird model)camembert β
CamembertForTokenClassification(CamemBERT model)canine β
CanineForTokenClassification(Canine model)convbert β
ConvBertForTokenClassification(ConvBERT model)deberta β
DebertaForTokenClassification(DeBERTa model)deberta-v2 β
DebertaV2ForTokenClassification(DeBERTa-v2 model)distilbert β
DistilBertForTokenClassification(DistilBERT model)electra β
ElectraForTokenClassification(ELECTRA model)flaubert β
FlaubertForTokenClassification(FlauBERT model)funnel β
FunnelForTokenClassification(Funnel Transformer model)ibert β
IBertForTokenClassification(I-BERT model)layoutlm β
LayoutLMForTokenClassification(LayoutLM model)longformer β
LongformerForTokenClassification(Longformer model)megatron-bert β
MegatronBertForTokenClassification(MegatronBert model)mobilebert β
MobileBertForTokenClassification(MobileBERT model)mpnet β
MPNetForTokenClassification(MPNet model)roberta β
RobertaForTokenClassification(RoBERTa model)roformer β
RoFormerForTokenClassification(RoFormer model)squeezebert β
SqueezeBertForTokenClassification(SqueezeBERT model)xlm β
XLMForTokenClassification(XLM model)xlm-roberta β
XLMRobertaForTokenClassification(XLM-RoBERTa model)xlnet β
XLNetForTokenClassification(XLNet model)
The model is set in evaluation mode by default using
model.eval()(so for instance, dropout modules are deactivated). To train the model, you should first set it back in training mode withmodel.train()- Parameters
pretrained_model_name_or_path (
stroros.PathLike) βCan be either:
A string, the model id of a pretrained model hosted inside a model repo on huggingface.co. Valid model ids can be located at the root-level, like
bert-base-uncased, or namespaced under a user or organization name, likedbmdz/bert-base-german-cased.A path to a directory containing model weights saved using
save_pretrained(), e.g.,./my_model_directory/.A path or url to a tensorflow index checkpoint file (e.g,
./tf_model/model.ckpt.index). In this case,from_tfshould be set toTrueand a configuration object should be provided asconfigargument. This loading path is slower than converting the TensorFlow checkpoint in a PyTorch model using the provided conversion scripts and loading the PyTorch model afterwards.
model_args (additional positional arguments, optional) β Will be passed along to the underlying model
__init__()method.config (
PretrainedConfig, optional) βConfiguration for the model to use instead of an automatically loaded configuration. Configuration can be automatically loaded when:
The model is a model provided by the library (loaded with the model id string of a pretrained model).
The model was saved using
save_pretrained()and is reloaded by supplying the save directory.The model is loaded by supplying a local directory as
pretrained_model_name_or_pathand a configuration JSON file named config.json is found in the directory.
state_dict (Dict[str, torch.Tensor], optional) β
A state dictionary to use instead of a state dictionary loaded from saved weights file.
This option can be used if you want to create a model from a pretrained configuration but load your own weights. In this case though, you should check if using
save_pretrained()andfrom_pretrained()is not a simpler option.cache_dir (
stroros.PathLike, optional) β Path to a directory in which a downloaded pretrained model configuration should be cached if the standard cache should not be used.from_tf (
bool, optional, defaults toFalse) β Load the model weights from a TensorFlow checkpoint save file (see docstring ofpretrained_model_name_or_pathargument).force_download (
bool, optional, defaults toFalse) β Whether or not to force the (re-)download of the model weights and configuration files, overriding the cached versions if they exist.resume_download (
bool, optional, defaults toFalse) β Whether or not to delete incompletely received files. Will attempt to resume the download if such a file exists.proxies (
Dict[str, str], `optional) β A dictionary of proxy servers to use by protocol or endpoint, e.g.,{'http': 'foo.bar:3128', 'http://hostname': 'foo.bar:4012'}. The proxies are used on each request.output_loading_info (
bool, optional, defaults toFalse) β Whether ot not to also return a dictionary containing missing keys, unexpected keys and error messages.local_files_only (
bool, optional, defaults toFalse) β Whether or not to only look at local files (e.g., not try downloading the model).revision (
str, optional, defaults to"main") β The specific model version to use. It can be a branch name, a tag name, or a commit id, since we use a git-based system for storing models and other artifacts on huggingface.co, sorevisioncan be any identifier allowed by git.kwargs (additional keyword arguments, optional) β
Can be used to update the configuration object (after it being loaded) and initiate the model (e.g.,
output_attentions=True). Behaves differently depending on whether aconfigis provided or automatically loaded:If a configuration is provided with
config,**kwargswill be directly passed to the underlying modelβs__init__method (we assume all relevant updates to the configuration have already been done)If a configuration is not provided,
kwargswill be first passed to the configuration class initialization function (from_pretrained()). Each key ofkwargsthat corresponds to a configuration attribute will be used to override said attribute with the suppliedkwargsvalue. Remaining keys that do not correspond to any configuration attribute will be passed to the underlying modelβs__init__function.
Examples:
>>> from transformers import AutoConfig, AutoModelForTokenClassification >>> # Download model and configuration from huggingface.co and cache. >>> model = AutoModelForTokenClassification.from_pretrained('bert-base-cased') >>> # Update configuration during loading >>> model = AutoModelForTokenClassification.from_pretrained('bert-base-cased', output_attentions=True) >>> model.config.output_attentions True >>> # Loading from a TF checkpoint file instead of a PyTorch model (slower) >>> config = AutoConfig.from_pretrained('./tf_model/bert_tf_model_config.json') >>> model = AutoModelForTokenClassification.from_pretrained('./tf_model/bert_tf_checkpoint.ckpt.index', from_tf=True, config=config)
-
classmethod
AutoModelForQuestionAnsweringΒΆ
-
class
transformers.AutoModelForQuestionAnswering(*args, **kwargs)[source]ΒΆ This is a generic model class that will be instantiated as one of the model classes of the library (with a question answering head) when created with the
from_pretrained()class method or thefrom_config()class method.This class cannot be instantiated directly using
__init__()(throws an error).-
classmethod
from_config(config, **kwargs)ΒΆ Instantiates one of the model classes of the library (with a question answering head) from a configuration.
Note
Loading a model from its configuration file does not load the model weights. It only affects the modelβs configuration. Use
from_pretrained()to load the model weights.- Parameters
config (
PretrainedConfig) βThe model class to instantiate is selected based on the configuration class:
AlbertConfigconfiguration class:AlbertForQuestionAnswering(ALBERT model)BartConfigconfiguration class:BartForQuestionAnswering(BART model)BertConfigconfiguration class:BertForQuestionAnswering(BERT model)BigBirdConfigconfiguration class:BigBirdForQuestionAnswering(BigBird model)BigBirdPegasusConfigconfiguration class:BigBirdPegasusForQuestionAnswering(BigBirdPegasus model)CamembertConfigconfiguration class:CamembertForQuestionAnswering(CamemBERT model)CanineConfigconfiguration class:CanineForQuestionAnswering(Canine model)ConvBertConfigconfiguration class:ConvBertForQuestionAnswering(ConvBERT model)DebertaConfigconfiguration class:DebertaForQuestionAnswering(DeBERTa model)DebertaV2Configconfiguration class:DebertaV2ForQuestionAnswering(DeBERTa-v2 model)DistilBertConfigconfiguration class:DistilBertForQuestionAnswering(DistilBERT model)ElectraConfigconfiguration class:ElectraForQuestionAnswering(ELECTRA model)FlaubertConfigconfiguration class:FlaubertForQuestionAnsweringSimple(FlauBERT model)FunnelConfigconfiguration class:FunnelForQuestionAnswering(Funnel Transformer model)IBertConfigconfiguration class:IBertForQuestionAnswering(I-BERT model)LEDConfigconfiguration class:LEDForQuestionAnswering(LED model)LongformerConfigconfiguration class:LongformerForQuestionAnswering(Longformer model)LxmertConfigconfiguration class:LxmertForQuestionAnswering(LXMERT model)MBartConfigconfiguration class:MBartForQuestionAnswering(mBART model)MPNetConfigconfiguration class:MPNetForQuestionAnswering(MPNet model)MegatronBertConfigconfiguration class:MegatronBertForQuestionAnswering(MegatronBert model)MobileBertConfigconfiguration class:MobileBertForQuestionAnswering(MobileBERT model)ReformerConfigconfiguration class:ReformerForQuestionAnswering(Reformer model)RoFormerConfigconfiguration class:RoFormerForQuestionAnswering(RoFormer model)RobertaConfigconfiguration class:RobertaForQuestionAnswering(RoBERTa model)SqueezeBertConfigconfiguration class:SqueezeBertForQuestionAnswering(SqueezeBERT model)XLMConfigconfiguration class:XLMForQuestionAnsweringSimple(XLM model)XLMRobertaConfigconfiguration class:XLMRobertaForQuestionAnswering(XLM-RoBERTa model)XLNetConfigconfiguration class:XLNetForQuestionAnsweringSimple(XLNet model)
Examples:
>>> from transformers import AutoConfig, AutoModelForQuestionAnswering >>> # Download configuration from huggingface.co and cache. >>> config = AutoConfig.from_pretrained('bert-base-cased') >>> model = AutoModelForQuestionAnswering.from_config(config)
-
classmethod
from_pretrained(pretrained_model_name_or_path, *model_args, **kwargs)ΒΆ Instantiate one of the model classes of the library (with a question answering head) from a pretrained model.
The model class to instantiate is selected based on the
model_typeproperty of the config object (either passed as an argument or loaded frompretrained_model_name_or_pathif possible), or when itβs missing, by falling back to using pattern matching onpretrained_model_name_or_path:albert β
AlbertForQuestionAnswering(ALBERT model)bart β
BartForQuestionAnswering(BART model)bert β
BertForQuestionAnswering(BERT model)big_bird β
BigBirdForQuestionAnswering(BigBird model)bigbird_pegasus β
BigBirdPegasusForQuestionAnswering(BigBirdPegasus model)camembert β
CamembertForQuestionAnswering(CamemBERT model)canine β
CanineForQuestionAnswering(Canine model)convbert β
ConvBertForQuestionAnswering(ConvBERT model)deberta β
DebertaForQuestionAnswering(DeBERTa model)deberta-v2 β
DebertaV2ForQuestionAnswering(DeBERTa-v2 model)distilbert β
DistilBertForQuestionAnswering(DistilBERT model)electra β
ElectraForQuestionAnswering(ELECTRA model)flaubert β
FlaubertForQuestionAnsweringSimple(FlauBERT model)funnel β
FunnelForQuestionAnswering(Funnel Transformer model)ibert β
IBertForQuestionAnswering(I-BERT model)led β
LEDForQuestionAnswering(LED model)longformer β
LongformerForQuestionAnswering(Longformer model)lxmert β
LxmertForQuestionAnswering(LXMERT model)mbart β
MBartForQuestionAnswering(mBART model)megatron-bert β
MegatronBertForQuestionAnswering(MegatronBert model)mobilebert β
MobileBertForQuestionAnswering(MobileBERT model)mpnet β
MPNetForQuestionAnswering(MPNet model)reformer β
ReformerForQuestionAnswering(Reformer model)roberta β
RobertaForQuestionAnswering(RoBERTa model)roformer β
RoFormerForQuestionAnswering(RoFormer model)squeezebert β
SqueezeBertForQuestionAnswering(SqueezeBERT model)xlm β
XLMForQuestionAnsweringSimple(XLM model)xlm-roberta β
XLMRobertaForQuestionAnswering(XLM-RoBERTa model)xlnet β
XLNetForQuestionAnsweringSimple(XLNet model)
The model is set in evaluation mode by default using
model.eval()(so for instance, dropout modules are deactivated). To train the model, you should first set it back in training mode withmodel.train()- Parameters
pretrained_model_name_or_path (
stroros.PathLike) βCan be either:
A string, the model id of a pretrained model hosted inside a model repo on huggingface.co. Valid model ids can be located at the root-level, like
bert-base-uncased, or namespaced under a user or organization name, likedbmdz/bert-base-german-cased.A path to a directory containing model weights saved using
save_pretrained(), e.g.,./my_model_directory/.A path or url to a tensorflow index checkpoint file (e.g,
./tf_model/model.ckpt.index). In this case,from_tfshould be set toTrueand a configuration object should be provided asconfigargument. This loading path is slower than converting the TensorFlow checkpoint in a PyTorch model using the provided conversion scripts and loading the PyTorch model afterwards.
model_args (additional positional arguments, optional) β Will be passed along to the underlying model
__init__()method.config (
PretrainedConfig, optional) βConfiguration for the model to use instead of an automatically loaded configuration. Configuration can be automatically loaded when:
The model is a model provided by the library (loaded with the model id string of a pretrained model).
The model was saved using
save_pretrained()and is reloaded by supplying the save directory.The model is loaded by supplying a local directory as
pretrained_model_name_or_pathand a configuration JSON file named config.json is found in the directory.
state_dict (Dict[str, torch.Tensor], optional) β
A state dictionary to use instead of a state dictionary loaded from saved weights file.
This option can be used if you want to create a model from a pretrained configuration but load your own weights. In this case though, you should check if using
save_pretrained()andfrom_pretrained()is not a simpler option.cache_dir (
stroros.PathLike, optional) β Path to a directory in which a downloaded pretrained model configuration should be cached if the standard cache should not be used.from_tf (
bool, optional, defaults toFalse) β Load the model weights from a TensorFlow checkpoint save file (see docstring ofpretrained_model_name_or_pathargument).force_download (
bool, optional, defaults toFalse) β Whether or not to force the (re-)download of the model weights and configuration files, overriding the cached versions if they exist.resume_download (
bool, optional, defaults toFalse) β Whether or not to delete incompletely received files. Will attempt to resume the download if such a file exists.proxies (
Dict[str, str], `optional) β A dictionary of proxy servers to use by protocol or endpoint, e.g.,{'http': 'foo.bar:3128', 'http://hostname': 'foo.bar:4012'}. The proxies are used on each request.output_loading_info (
bool, optional, defaults toFalse) β Whether ot not to also return a dictionary containing missing keys, unexpected keys and error messages.local_files_only (
bool, optional, defaults toFalse) β Whether or not to only look at local files (e.g., not try downloading the model).revision (
str, optional, defaults to"main") β The specific model version to use. It can be a branch name, a tag name, or a commit id, since we use a git-based system for storing models and other artifacts on huggingface.co, sorevisioncan be any identifier allowed by git.kwargs (additional keyword arguments, optional) β
Can be used to update the configuration object (after it being loaded) and initiate the model (e.g.,
output_attentions=True). Behaves differently depending on whether aconfigis provided or automatically loaded:If a configuration is provided with
config,**kwargswill be directly passed to the underlying modelβs__init__method (we assume all relevant updates to the configuration have already been done)If a configuration is not provided,
kwargswill be first passed to the configuration class initialization function (from_pretrained()). Each key ofkwargsthat corresponds to a configuration attribute will be used to override said attribute with the suppliedkwargsvalue. Remaining keys that do not correspond to any configuration attribute will be passed to the underlying modelβs__init__function.
Examples:
>>> from transformers import AutoConfig, AutoModelForQuestionAnswering >>> # Download model and configuration from huggingface.co and cache. >>> model = AutoModelForQuestionAnswering.from_pretrained('bert-base-cased') >>> # Update configuration during loading >>> model = AutoModelForQuestionAnswering.from_pretrained('bert-base-cased', output_attentions=True) >>> model.config.output_attentions True >>> # Loading from a TF checkpoint file instead of a PyTorch model (slower) >>> config = AutoConfig.from_pretrained('./tf_model/bert_tf_model_config.json') >>> model = AutoModelForQuestionAnswering.from_pretrained('./tf_model/bert_tf_checkpoint.ckpt.index', from_tf=True, config=config)
-
classmethod
AutoModelForTableQuestionAnsweringΒΆ
-
class
transformers.AutoModelForTableQuestionAnswering(*args, **kwargs)[source]ΒΆ This is a generic model class that will be instantiated as one of the model classes of the library (with a table question answering head) when created with the
from_pretrained()class method or thefrom_config()class method.This class cannot be instantiated directly using
__init__()(throws an error).-
classmethod
from_config(config, **kwargs)ΒΆ Instantiates one of the model classes of the library (with a table question answering head) from a configuration.
Note
Loading a model from its configuration file does not load the model weights. It only affects the modelβs configuration. Use
from_pretrained()to load the model weights.- Parameters
config (
PretrainedConfig) βThe model class to instantiate is selected based on the configuration class:
TapasConfigconfiguration class:TapasForQuestionAnswering(TAPAS model)
Examples:
>>> from transformers import AutoConfig, AutoModelForTableQuestionAnswering >>> # Download configuration from huggingface.co and cache. >>> config = AutoConfig.from_pretrained('google/tapas-base-finetuned-wtq') >>> model = AutoModelForTableQuestionAnswering.from_config(config)
-
classmethod
from_pretrained(pretrained_model_name_or_path, *model_args, **kwargs)ΒΆ Instantiate one of the model classes of the library (with a table question answering head) from a pretrained model.
The model class to instantiate is selected based on the
model_typeproperty of the config object (either passed as an argument or loaded frompretrained_model_name_or_pathif possible), or when itβs missing, by falling back to using pattern matching onpretrained_model_name_or_path:tapas β
TapasForQuestionAnswering(TAPAS model)
The model is set in evaluation mode by default using
model.eval()(so for instance, dropout modules are deactivated). To train the model, you should first set it back in training mode withmodel.train()- Parameters
pretrained_model_name_or_path (
stroros.PathLike) βCan be either:
A string, the model id of a pretrained model hosted inside a model repo on huggingface.co. Valid model ids can be located at the root-level, like
bert-base-uncased, or namespaced under a user or organization name, likedbmdz/bert-base-german-cased.A path to a directory containing model weights saved using
save_pretrained(), e.g.,./my_model_directory/.A path or url to a tensorflow index checkpoint file (e.g,
./tf_model/model.ckpt.index). In this case,from_tfshould be set toTrueand a configuration object should be provided asconfigargument. This loading path is slower than converting the TensorFlow checkpoint in a PyTorch model using the provided conversion scripts and loading the PyTorch model afterwards.
model_args (additional positional arguments, optional) β Will be passed along to the underlying model
__init__()method.config (
PretrainedConfig, optional) βConfiguration for the model to use instead of an automatically loaded configuration. Configuration can be automatically loaded when:
The model is a model provided by the library (loaded with the model id string of a pretrained model).
The model was saved using
save_pretrained()and is reloaded by supplying the save directory.The model is loaded by supplying a local directory as
pretrained_model_name_or_pathand a configuration JSON file named config.json is found in the directory.
state_dict (Dict[str, torch.Tensor], optional) β
A state dictionary to use instead of a state dictionary loaded from saved weights file.
This option can be used if you want to create a model from a pretrained configuration but load your own weights. In this case though, you should check if using
save_pretrained()andfrom_pretrained()is not a simpler option.cache_dir (
stroros.PathLike, optional) β Path to a directory in which a downloaded pretrained model configuration should be cached if the standard cache should not be used.from_tf (
bool, optional, defaults toFalse) β Load the model weights from a TensorFlow checkpoint save file (see docstring ofpretrained_model_name_or_pathargument).force_download (
bool, optional, defaults toFalse) β Whether or not to force the (re-)download of the model weights and configuration files, overriding the cached versions if they exist.resume_download (
bool, optional, defaults toFalse) β Whether or not to delete incompletely received files. Will attempt to resume the download if such a file exists.proxies (
Dict[str, str], `optional) β A dictionary of proxy servers to use by protocol or endpoint, e.g.,{'http': 'foo.bar:3128', 'http://hostname': 'foo.bar:4012'}. The proxies are used on each request.output_loading_info (
bool, optional, defaults toFalse) β Whether ot not to also return a dictionary containing missing keys, unexpected keys and error messages.local_files_only (
bool, optional, defaults toFalse) β Whether or not to only look at local files (e.g., not try downloading the model).revision (
str, optional, defaults to"main") β The specific model version to use. It can be a branch name, a tag name, or a commit id, since we use a git-based system for storing models and other artifacts on huggingface.co, sorevisioncan be any identifier allowed by git.kwargs (additional keyword arguments, optional) β
Can be used to update the configuration object (after it being loaded) and initiate the model (e.g.,
output_attentions=True). Behaves differently depending on whether aconfigis provided or automatically loaded:If a configuration is provided with
config,**kwargswill be directly passed to the underlying modelβs__init__method (we assume all relevant updates to the configuration have already been done)If a configuration is not provided,
kwargswill be first passed to the configuration class initialization function (from_pretrained()). Each key ofkwargsthat corresponds to a configuration attribute will be used to override said attribute with the suppliedkwargsvalue. Remaining keys that do not correspond to any configuration attribute will be passed to the underlying modelβs__init__function.
Examples:
>>> from transformers import AutoConfig, AutoModelForTableQuestionAnswering >>> # Download model and configuration from huggingface.co and cache. >>> model = AutoModelForTableQuestionAnswering.from_pretrained('google/tapas-base-finetuned-wtq') >>> # Update configuration during loading >>> model = AutoModelForTableQuestionAnswering.from_pretrained('google/tapas-base-finetuned-wtq', output_attentions=True) >>> model.config.output_attentions True >>> # Loading from a TF checkpoint file instead of a PyTorch model (slower) >>> config = AutoConfig.from_pretrained('./tf_model/tapas_tf_model_config.json') >>> model = AutoModelForTableQuestionAnswering.from_pretrained('./tf_model/tapas_tf_checkpoint.ckpt.index', from_tf=True, config=config)
-
classmethod
AutoModelForImageClassificationΒΆ
-
class
transformers.AutoModelForImageClassification(*args, **kwargs)[source]ΒΆ This is a generic model class that will be instantiated as one of the model classes of the library (with a image classification head) when created with the
from_pretrained()class method or thefrom_config()class method.This class cannot be instantiated directly using
__init__()(throws an error).-
classmethod
from_config(config, **kwargs)ΒΆ Instantiates one of the model classes of the library (with a image classification head) from a configuration.
Note
Loading a model from its configuration file does not load the model weights. It only affects the modelβs configuration. Use
from_pretrained()to load the model weights.- Parameters
config (
PretrainedConfig) βThe model class to instantiate is selected based on the configuration class:
DeiTConfigconfiguration class:DeiTForImageClassificationorDeiTForImageClassificationWithTeacher(DeiT model)ViTConfigconfiguration class:ViTForImageClassification(ViT model)
Examples:
>>> from transformers import AutoConfig, AutoModelForImageClassification >>> # Download configuration from huggingface.co and cache. >>> config = AutoConfig.from_pretrained('bert-base-cased') >>> model = AutoModelForImageClassification.from_config(config)
-
classmethod
from_pretrained(pretrained_model_name_or_path, *model_args, **kwargs)ΒΆ Instantiate one of the model classes of the library (with a image classification head) from a pretrained model.
The model class to instantiate is selected based on the
model_typeproperty of the config object (either passed as an argument or loaded frompretrained_model_name_or_pathif possible), or when itβs missing, by falling back to using pattern matching onpretrained_model_name_or_path:deit β
DeiTForImageClassificationorDeiTForImageClassificationWithTeacher(DeiT model)vit β
ViTForImageClassification(ViT model)
The model is set in evaluation mode by default using
model.eval()(so for instance, dropout modules are deactivated). To train the model, you should first set it back in training mode withmodel.train()- Parameters
pretrained_model_name_or_path (
stroros.PathLike) βCan be either:
A string, the model id of a pretrained model hosted inside a model repo on huggingface.co. Valid model ids can be located at the root-level, like
bert-base-uncased, or namespaced under a user or organization name, likedbmdz/bert-base-german-cased.A path to a directory containing model weights saved using
save_pretrained(), e.g.,./my_model_directory/.A path or url to a tensorflow index checkpoint file (e.g,
./tf_model/model.ckpt.index). In this case,from_tfshould be set toTrueand a configuration object should be provided asconfigargument. This loading path is slower than converting the TensorFlow checkpoint in a PyTorch model using the provided conversion scripts and loading the PyTorch model afterwards.
model_args (additional positional arguments, optional) β Will be passed along to the underlying model
__init__()method.config (
PretrainedConfig, optional) βConfiguration for the model to use instead of an automatically loaded configuration. Configuration can be automatically loaded when:
The model is a model provided by the library (loaded with the model id string of a pretrained model).
The model was saved using
save_pretrained()and is reloaded by supplying the save directory.The model is loaded by supplying a local directory as
pretrained_model_name_or_pathand a configuration JSON file named config.json is found in the directory.
state_dict (Dict[str, torch.Tensor], optional) β
A state dictionary to use instead of a state dictionary loaded from saved weights file.
This option can be used if you want to create a model from a pretrained configuration but load your own weights. In this case though, you should check if using
save_pretrained()andfrom_pretrained()is not a simpler option.cache_dir (
stroros.PathLike, optional) β Path to a directory in which a downloaded pretrained model configuration should be cached if the standard cache should not be used.from_tf (
bool, optional, defaults toFalse) β Load the model weights from a TensorFlow checkpoint save file (see docstring ofpretrained_model_name_or_pathargument).force_download (
bool, optional, defaults toFalse) β Whether or not to force the (re-)download of the model weights and configuration files, overriding the cached versions if they exist.resume_download (
bool, optional, defaults toFalse) β Whether or not to delete incompletely received files. Will attempt to resume the download if such a file exists.proxies (
Dict[str, str], `optional) β A dictionary of proxy servers to use by protocol or endpoint, e.g.,{'http': 'foo.bar:3128', 'http://hostname': 'foo.bar:4012'}. The proxies are used on each request.output_loading_info (
bool, optional, defaults toFalse) β Whether ot not to also return a dictionary containing missing keys, unexpected keys and error messages.local_files_only (
bool, optional, defaults toFalse) β Whether or not to only look at local files (e.g., not try downloading the model).revision (
str, optional, defaults to"main") β The specific model version to use. It can be a branch name, a tag name, or a commit id, since we use a git-based system for storing models and other artifacts on huggingface.co, sorevisioncan be any identifier allowed by git.kwargs (additional keyword arguments, optional) β
Can be used to update the configuration object (after it being loaded) and initiate the model (e.g.,
output_attentions=True). Behaves differently depending on whether aconfigis provided or automatically loaded:If a configuration is provided with
config,**kwargswill be directly passed to the underlying modelβs__init__method (we assume all relevant updates to the configuration have already been done)If a configuration is not provided,
kwargswill be first passed to the configuration class initialization function (from_pretrained()). Each key ofkwargsthat corresponds to a configuration attribute will be used to override said attribute with the suppliedkwargsvalue. Remaining keys that do not correspond to any configuration attribute will be passed to the underlying modelβs__init__function.
Examples:
>>> from transformers import AutoConfig, AutoModelForImageClassification >>> # Download model and configuration from huggingface.co and cache. >>> model = AutoModelForImageClassification.from_pretrained('bert-base-cased') >>> # Update configuration during loading >>> model = AutoModelForImageClassification.from_pretrained('bert-base-cased', output_attentions=True) >>> model.config.output_attentions True >>> # Loading from a TF checkpoint file instead of a PyTorch model (slower) >>> config = AutoConfig.from_pretrained('./tf_model/bert_tf_model_config.json') >>> model = AutoModelForImageClassification.from_pretrained('./tf_model/bert_tf_checkpoint.ckpt.index', from_tf=True, config=config)
-
classmethod
TFAutoModelΒΆ
-
class
transformers.TFAutoModel(*args, **kwargs)[source]ΒΆ This is a generic model class that will be instantiated as one of the base model classes of the library when created with the
from_pretrained()class method or thefrom_config()class method.This class cannot be instantiated directly using
__init__()(throws an error).-
classmethod
from_config(config, **kwargs)ΒΆ Instantiates one of the base model classes of the library from a configuration.
Note
Loading a model from its configuration file does not load the model weights. It only affects the modelβs configuration. Use
from_pretrained()to load the model weights.- Parameters
config (
PretrainedConfig) βThe model class to instantiate is selected based on the configuration class:
AlbertConfigconfiguration class:TFAlbertModel(ALBERT model)BartConfigconfiguration class:TFBartModel(BART model)BertConfigconfiguration class:TFBertModel(BERT model)BlenderbotConfigconfiguration class:TFBlenderbotModel(Blenderbot model)BlenderbotSmallConfigconfiguration class:TFBlenderbotSmallModel(BlenderbotSmall model)CTRLConfigconfiguration class:TFCTRLModel(CTRL model)CamembertConfigconfiguration class:TFCamembertModel(CamemBERT model)ConvBertConfigconfiguration class:TFConvBertModel(ConvBERT model)DPRConfigconfiguration class:TFDPRQuestionEncoder(DPR model)DistilBertConfigconfiguration class:TFDistilBertModel(DistilBERT model)ElectraConfigconfiguration class:TFElectraModel(ELECTRA model)FlaubertConfigconfiguration class:TFFlaubertModel(FlauBERT model)FunnelConfigconfiguration class:TFFunnelModelorTFFunnelBaseModel(Funnel Transformer model)GPT2Configconfiguration class:TFGPT2Model(OpenAI GPT-2 model)HubertConfigconfiguration class:TFHubertModel(Hubert model)LEDConfigconfiguration class:TFLEDModel(LED model)LayoutLMConfigconfiguration class:TFLayoutLMModel(LayoutLM model)LongformerConfigconfiguration class:TFLongformerModel(Longformer model)LxmertConfigconfiguration class:TFLxmertModel(LXMERT model)MBartConfigconfiguration class:TFMBartModel(mBART model)MPNetConfigconfiguration class:TFMPNetModel(MPNet model)MT5Configconfiguration class:TFMT5Model(mT5 model)MarianConfigconfiguration class:TFMarianModel(Marian model)MobileBertConfigconfiguration class:TFMobileBertModel(MobileBERT model)OpenAIGPTConfigconfiguration class:TFOpenAIGPTModel(OpenAI GPT model)PegasusConfigconfiguration class:TFPegasusModel(Pegasus model)RoFormerConfigconfiguration class:TFRoFormerModel(RoFormer model)RobertaConfigconfiguration class:TFRobertaModel(RoBERTa model)TransfoXLConfigconfiguration class:TFTransfoXLModel(Transformer-XL model)Wav2Vec2Configconfiguration class:TFWav2Vec2Model(Wav2Vec2 model)XLMConfigconfiguration class:TFXLMModel(XLM model)XLMRobertaConfigconfiguration class:TFXLMRobertaModel(XLM-RoBERTa model)XLNetConfigconfiguration class:TFXLNetModel(XLNet model)
Examples:
>>> from transformers import AutoConfig, TFAutoModel >>> # Download configuration from huggingface.co and cache. >>> config = AutoConfig.from_pretrained('bert-base-cased') >>> model = TFAutoModel.from_config(config)
-
classmethod
from_pretrained(pretrained_model_name_or_path, *model_args, **kwargs)ΒΆ Instantiate one of the base model classes of the library from a pretrained model.
The model class to instantiate is selected based on the
model_typeproperty of the config object (either passed as an argument or loaded frompretrained_model_name_or_pathif possible), or when itβs missing, by falling back to using pattern matching onpretrained_model_name_or_path:albert β
TFAlbertModel(ALBERT model)bart β
TFBartModel(BART model)bert β
TFBertModel(BERT model)blenderbot β
TFBlenderbotModel(Blenderbot model)blenderbot-small β
TFBlenderbotSmallModel(BlenderbotSmall model)camembert β
TFCamembertModel(CamemBERT model)convbert β
TFConvBertModel(ConvBERT model)ctrl β
TFCTRLModel(CTRL model)distilbert β
TFDistilBertModel(DistilBERT model)dpr β
TFDPRQuestionEncoder(DPR model)electra β
TFElectraModel(ELECTRA model)flaubert β
TFFlaubertModel(FlauBERT model)funnel β
TFFunnelModelorTFFunnelBaseModel(Funnel Transformer model)gpt2 β
TFGPT2Model(OpenAI GPT-2 model)hubert β
TFHubertModel(Hubert model)layoutlm β
TFLayoutLMModel(LayoutLM model)led β
TFLEDModel(LED model)longformer β
TFLongformerModel(Longformer model)lxmert β
TFLxmertModel(LXMERT model)marian β
TFMarianModel(Marian model)mbart β
TFMBartModel(mBART model)mobilebert β
TFMobileBertModel(MobileBERT model)mpnet β
TFMPNetModel(MPNet model)mt5 β
TFMT5Model(mT5 model)openai-gpt β
TFOpenAIGPTModel(OpenAI GPT model)pegasus β
TFPegasusModel(Pegasus model)roberta β
TFRobertaModel(RoBERTa model)roformer β
TFRoFormerModel(RoFormer model)t5 β
TFT5Model(T5 model)transfo-xl β
TFTransfoXLModel(Transformer-XL model)wav2vec2 β
TFWav2Vec2Model(Wav2Vec2 model)xlm β
TFXLMModel(XLM model)xlm-roberta β
TFXLMRobertaModel(XLM-RoBERTa model)xlnet β
TFXLNetModel(XLNet model)
- Parameters
pretrained_model_name_or_path (
stroros.PathLike) βCan be either:
A string, the model id of a pretrained model hosted inside a model repo on huggingface.co. Valid model ids can be located at the root-level, like
bert-base-uncased, or namespaced under a user or organization name, likedbmdz/bert-base-german-cased.A path to a directory containing model weights saved using
save_pretrained(), e.g.,./my_model_directory/.A path or url to a PyTorch state_dict save file (e.g,
./pt_model/pytorch_model.bin). In this case,from_ptshould be set toTrueand a configuration object should be provided asconfigargument. This loading path is slower than converting the PyTorch model in a TensorFlow model using the provided conversion scripts and loading the TensorFlow model afterwards.
model_args (additional positional arguments, optional) β Will be passed along to the underlying model
__init__()method.config (
PretrainedConfig, optional) βConfiguration for the model to use instead of an automatically loaded configuration. Configuration can be automatically loaded when:
The model is a model provided by the library (loaded with the model id string of a pretrained model).
The model was saved using
save_pretrained()and is reloaded by supplying the save directory.The model is loaded by supplying a local directory as
pretrained_model_name_or_pathand a configuration JSON file named config.json is found in the directory.
cache_dir (
stroros.PathLike, optional) β Path to a directory in which a downloaded pretrained model configuration should be cached if the standard cache should not be used.from_pt (
bool, optional, defaults toFalse) β Load the model weights from a PyTorch checkpoint save file (see docstring ofpretrained_model_name_or_pathargument).force_download (
bool, optional, defaults toFalse) β Whether or not to force the (re-)download of the model weights and configuration files, overriding the cached versions if they exist.resume_download (
bool, optional, defaults toFalse) β Whether or not to delete incompletely received files. Will attempt to resume the download if such a file exists.proxies (
Dict[str, str], `optional) β A dictionary of proxy servers to use by protocol or endpoint, e.g.,{'http': 'foo.bar:3128', 'http://hostname': 'foo.bar:4012'}. The proxies are used on each request.output_loading_info (
bool, optional, defaults toFalse) β Whether ot not to also return a dictionary containing missing keys, unexpected keys and error messages.local_files_only (
bool, optional, defaults toFalse) β Whether or not to only look at local files (e.g., not try downloading the model).revision (
str, optional, defaults to"main") β The specific model version to use. It can be a branch name, a tag name, or a commit id, since we use a git-based system for storing models and other artifacts on huggingface.co, sorevisioncan be any identifier allowed by git.kwargs (additional keyword arguments, optional) β
Can be used to update the configuration object (after it being loaded) and initiate the model (e.g.,
output_attentions=True). Behaves differently depending on whether aconfigis provided or automatically loaded:If a configuration is provided with
config,**kwargswill be directly passed to the underlying modelβs__init__method (we assume all relevant updates to the configuration have already been done)If a configuration is not provided,
kwargswill be first passed to the configuration class initialization function (from_pretrained()). Each key ofkwargsthat corresponds to a configuration attribute will be used to override said attribute with the suppliedkwargsvalue. Remaining keys that do not correspond to any configuration attribute will be passed to the underlying modelβs__init__function.
Examples:
>>> from transformers import AutoConfig, TFAutoModel >>> # Download model and configuration from huggingface.co and cache. >>> model = TFAutoModel.from_pretrained('bert-base-cased') >>> # Update configuration during loading >>> model = TFAutoModel.from_pretrained('bert-base-cased', output_attentions=True) >>> model.config.output_attentions True >>> # Loading from a PyTorch checkpoint file instead of a TensorFlow model (slower) >>> config = AutoConfig.from_pretrained('./pt_model/bert_pt_model_config.json') >>> model = TFAutoModel.from_pretrained('./pt_model/bert_pytorch_model.bin', from_pt=True, config=config)
-
classmethod
TFAutoModelForPreTrainingΒΆ
-
class
transformers.TFAutoModelForPreTraining(*args, **kwargs)[source]ΒΆ This is a generic model class that will be instantiated as one of the model classes of the library (with a pretraining head) when created with the
from_pretrained()class method or thefrom_config()class method.This class cannot be instantiated directly using
__init__()(throws an error).-
classmethod
from_config(config, **kwargs)ΒΆ Instantiates one of the model classes of the library (with a pretraining head) from a configuration.
Note
Loading a model from its configuration file does not load the model weights. It only affects the modelβs configuration. Use
from_pretrained()to load the model weights.- Parameters
config (
PretrainedConfig) βThe model class to instantiate is selected based on the configuration class:
AlbertConfigconfiguration class:TFAlbertForPreTraining(ALBERT model)BartConfigconfiguration class:TFBartForConditionalGeneration(BART model)BertConfigconfiguration class:TFBertForPreTraining(BERT model)CTRLConfigconfiguration class:TFCTRLLMHeadModel(CTRL model)CamembertConfigconfiguration class:TFCamembertForMaskedLM(CamemBERT model)DistilBertConfigconfiguration class:TFDistilBertForMaskedLM(DistilBERT model)ElectraConfigconfiguration class:TFElectraForPreTraining(ELECTRA model)FlaubertConfigconfiguration class:TFFlaubertWithLMHeadModel(FlauBERT model)FunnelConfigconfiguration class:TFFunnelForPreTraining(Funnel Transformer model)GPT2Configconfiguration class:TFGPT2LMHeadModel(OpenAI GPT-2 model)LayoutLMConfigconfiguration class:TFLayoutLMForMaskedLM(LayoutLM model)LxmertConfigconfiguration class:TFLxmertForPreTraining(LXMERT model)MPNetConfigconfiguration class:TFMPNetForMaskedLM(MPNet model)MobileBertConfigconfiguration class:TFMobileBertForPreTraining(MobileBERT model)OpenAIGPTConfigconfiguration class:TFOpenAIGPTLMHeadModel(OpenAI GPT model)RobertaConfigconfiguration class:TFRobertaForMaskedLM(RoBERTa model)T5Configconfiguration class:TFT5ForConditionalGeneration(T5 model)TransfoXLConfigconfiguration class:TFTransfoXLLMHeadModel(Transformer-XL model)XLMConfigconfiguration class:TFXLMWithLMHeadModel(XLM model)XLMRobertaConfigconfiguration class:TFXLMRobertaForMaskedLM(XLM-RoBERTa model)XLNetConfigconfiguration class:TFXLNetLMHeadModel(XLNet model)
Examples:
>>> from transformers import AutoConfig, TFAutoModelForPreTraining >>> # Download configuration from huggingface.co and cache. >>> config = AutoConfig.from_pretrained('bert-base-cased') >>> model = TFAutoModelForPreTraining.from_config(config)
-
classmethod
from_pretrained(pretrained_model_name_or_path, *model_args, **kwargs)ΒΆ Instantiate one of the model classes of the library (with a pretraining head) from a pretrained model.
The model class to instantiate is selected based on the
model_typeproperty of the config object (either passed as an argument or loaded frompretrained_model_name_or_pathif possible), or when itβs missing, by falling back to using pattern matching onpretrained_model_name_or_path:albert β
TFAlbertForPreTraining(ALBERT model)bart β
TFBartForConditionalGeneration(BART model)bert β
TFBertForPreTraining(BERT model)camembert β
TFCamembertForMaskedLM(CamemBERT model)ctrl β
TFCTRLLMHeadModel(CTRL model)distilbert β
TFDistilBertForMaskedLM(DistilBERT model)electra β
TFElectraForPreTraining(ELECTRA model)flaubert β
TFFlaubertWithLMHeadModel(FlauBERT model)funnel β
TFFunnelForPreTraining(Funnel Transformer model)gpt2 β
TFGPT2LMHeadModel(OpenAI GPT-2 model)layoutlm β
TFLayoutLMForMaskedLM(LayoutLM model)lxmert β
TFLxmertForPreTraining(LXMERT model)mobilebert β
TFMobileBertForPreTraining(MobileBERT model)mpnet β
TFMPNetForMaskedLM(MPNet model)openai-gpt β
TFOpenAIGPTLMHeadModel(OpenAI GPT model)roberta β
TFRobertaForMaskedLM(RoBERTa model)t5 β
TFT5ForConditionalGeneration(T5 model)transfo-xl β
TFTransfoXLLMHeadModel(Transformer-XL model)xlm β
TFXLMWithLMHeadModel(XLM model)xlm-roberta β
TFXLMRobertaForMaskedLM(XLM-RoBERTa model)xlnet β
TFXLNetLMHeadModel(XLNet model)
- Parameters
pretrained_model_name_or_path (
stroros.PathLike) βCan be either:
A string, the model id of a pretrained model hosted inside a model repo on huggingface.co. Valid model ids can be located at the root-level, like
bert-base-uncased, or namespaced under a user or organization name, likedbmdz/bert-base-german-cased.A path to a directory containing model weights saved using
save_pretrained(), e.g.,./my_model_directory/.A path or url to a PyTorch state_dict save file (e.g,
./pt_model/pytorch_model.bin). In this case,from_ptshould be set toTrueand a configuration object should be provided asconfigargument. This loading path is slower than converting the PyTorch model in a TensorFlow model using the provided conversion scripts and loading the TensorFlow model afterwards.
model_args (additional positional arguments, optional) β Will be passed along to the underlying model
__init__()method.config (
PretrainedConfig, optional) βConfiguration for the model to use instead of an automatically loaded configuration. Configuration can be automatically loaded when:
The model is a model provided by the library (loaded with the model id string of a pretrained model).
The model was saved using
save_pretrained()and is reloaded by supplying the save directory.The model is loaded by supplying a local directory as
pretrained_model_name_or_pathand a configuration JSON file named config.json is found in the directory.
cache_dir (
stroros.PathLike, optional) β Path to a directory in which a downloaded pretrained model configuration should be cached if the standard cache should not be used.from_pt (
bool, optional, defaults toFalse) β Load the model weights from a PyTorch checkpoint save file (see docstring ofpretrained_model_name_or_pathargument).force_download (
bool, optional, defaults toFalse) β Whether or not to force the (re-)download of the model weights and configuration files, overriding the cached versions if they exist.resume_download (
bool, optional, defaults toFalse) β Whether or not to delete incompletely received files. Will attempt to resume the download if such a file exists.proxies (
Dict[str, str], `optional) β A dictionary of proxy servers to use by protocol or endpoint, e.g.,{'http': 'foo.bar:3128', 'http://hostname': 'foo.bar:4012'}. The proxies are used on each request.output_loading_info (
bool, optional, defaults toFalse) β Whether ot not to also return a dictionary containing missing keys, unexpected keys and error messages.local_files_only (
bool, optional, defaults toFalse) β Whether or not to only look at local files (e.g., not try downloading the model).revision (
str, optional, defaults to"main") β The specific model version to use. It can be a branch name, a tag name, or a commit id, since we use a git-based system for storing models and other artifacts on huggingface.co, sorevisioncan be any identifier allowed by git.kwargs (additional keyword arguments, optional) β
Can be used to update the configuration object (after it being loaded) and initiate the model (e.g.,
output_attentions=True). Behaves differently depending on whether aconfigis provided or automatically loaded:If a configuration is provided with
config,**kwargswill be directly passed to the underlying modelβs__init__method (we assume all relevant updates to the configuration have already been done)If a configuration is not provided,
kwargswill be first passed to the configuration class initialization function (from_pretrained()). Each key ofkwargsthat corresponds to a configuration attribute will be used to override said attribute with the suppliedkwargsvalue. Remaining keys that do not correspond to any configuration attribute will be passed to the underlying modelβs__init__function.
Examples:
>>> from transformers import AutoConfig, TFAutoModelForPreTraining >>> # Download model and configuration from huggingface.co and cache. >>> model = TFAutoModelForPreTraining.from_pretrained('bert-base-cased') >>> # Update configuration during loading >>> model = TFAutoModelForPreTraining.from_pretrained('bert-base-cased', output_attentions=True) >>> model.config.output_attentions True >>> # Loading from a PyTorch checkpoint file instead of a TensorFlow model (slower) >>> config = AutoConfig.from_pretrained('./pt_model/bert_pt_model_config.json') >>> model = TFAutoModelForPreTraining.from_pretrained('./pt_model/bert_pytorch_model.bin', from_pt=True, config=config)
-
classmethod
TFAutoModelForCausalLMΒΆ
-
class
transformers.TFAutoModelForCausalLM(*args, **kwargs)[source]ΒΆ This is a generic model class that will be instantiated as one of the model classes of the library (with a causal language modeling head) when created with the
from_pretrained()class method or thefrom_config()class method.This class cannot be instantiated directly using
__init__()(throws an error).-
classmethod
from_config(config, **kwargs)ΒΆ Instantiates one of the model classes of the library (with a causal language modeling head) from a configuration.
Note
Loading a model from its configuration file does not load the model weights. It only affects the modelβs configuration. Use
from_pretrained()to load the model weights.- Parameters
config (
PretrainedConfig) βThe model class to instantiate is selected based on the configuration class:
BertConfigconfiguration class:TFBertLMHeadModel(BERT model)CTRLConfigconfiguration class:TFCTRLLMHeadModel(CTRL model)GPT2Configconfiguration class:TFGPT2LMHeadModel(OpenAI GPT-2 model)OpenAIGPTConfigconfiguration class:TFOpenAIGPTLMHeadModel(OpenAI GPT model)RoFormerConfigconfiguration class:TFRoFormerForCausalLM(RoFormer model)TransfoXLConfigconfiguration class:TFTransfoXLLMHeadModel(Transformer-XL model)XLMConfigconfiguration class:TFXLMWithLMHeadModel(XLM model)XLNetConfigconfiguration class:TFXLNetLMHeadModel(XLNet model)
Examples:
>>> from transformers import AutoConfig, TFAutoModelForCausalLM >>> # Download configuration from huggingface.co and cache. >>> config = AutoConfig.from_pretrained('bert-base-cased') >>> model = TFAutoModelForCausalLM.from_config(config)
-
classmethod
from_pretrained(pretrained_model_name_or_path, *model_args, **kwargs)ΒΆ Instantiate one of the model classes of the library (with a causal language modeling head) from a pretrained model.
The model class to instantiate is selected based on the
model_typeproperty of the config object (either passed as an argument or loaded frompretrained_model_name_or_pathif possible), or when itβs missing, by falling back to using pattern matching onpretrained_model_name_or_path:bert β
TFBertLMHeadModel(BERT model)ctrl β
TFCTRLLMHeadModel(CTRL model)gpt2 β
TFGPT2LMHeadModel(OpenAI GPT-2 model)openai-gpt β
TFOpenAIGPTLMHeadModel(OpenAI GPT model)roformer β
TFRoFormerForCausalLM(RoFormer model)transfo-xl β
TFTransfoXLLMHeadModel(Transformer-XL model)xlm β
TFXLMWithLMHeadModel(XLM model)xlnet β
TFXLNetLMHeadModel(XLNet model)
- Parameters
pretrained_model_name_or_path (
stroros.PathLike) βCan be either:
A string, the model id of a pretrained model hosted inside a model repo on huggingface.co. Valid model ids can be located at the root-level, like
bert-base-uncased, or namespaced under a user or organization name, likedbmdz/bert-base-german-cased.A path to a directory containing model weights saved using
save_pretrained(), e.g.,./my_model_directory/.A path or url to a PyTorch state_dict save file (e.g,
./pt_model/pytorch_model.bin). In this case,from_ptshould be set toTrueand a configuration object should be provided asconfigargument. This loading path is slower than converting the PyTorch model in a TensorFlow model using the provided conversion scripts and loading the TensorFlow model afterwards.
model_args (additional positional arguments, optional) β Will be passed along to the underlying model
__init__()method.config (
PretrainedConfig, optional) βConfiguration for the model to use instead of an automatically loaded configuration. Configuration can be automatically loaded when:
The model is a model provided by the library (loaded with the model id string of a pretrained model).
The model was saved using
save_pretrained()and is reloaded by supplying the save directory.The model is loaded by supplying a local directory as
pretrained_model_name_or_pathand a configuration JSON file named config.json is found in the directory.
cache_dir (
stroros.PathLike, optional) β Path to a directory in which a downloaded pretrained model configuration should be cached if the standard cache should not be used.from_pt (
bool, optional, defaults toFalse) β Load the model weights from a PyTorch checkpoint save file (see docstring ofpretrained_model_name_or_pathargument).force_download (
bool, optional, defaults toFalse) β Whether or not to force the (re-)download of the model weights and configuration files, overriding the cached versions if they exist.resume_download (
bool, optional, defaults toFalse) β Whether or not to delete incompletely received files. Will attempt to resume the download if such a file exists.proxies (
Dict[str, str], `optional) β A dictionary of proxy servers to use by protocol or endpoint, e.g.,{'http': 'foo.bar:3128', 'http://hostname': 'foo.bar:4012'}. The proxies are used on each request.output_loading_info (
bool, optional, defaults toFalse) β Whether ot not to also return a dictionary containing missing keys, unexpected keys and error messages.local_files_only (
bool, optional, defaults toFalse) β Whether or not to only look at local files (e.g., not try downloading the model).revision (
str, optional, defaults to"main") β The specific model version to use. It can be a branch name, a tag name, or a commit id, since we use a git-based system for storing models and other artifacts on huggingface.co, sorevisioncan be any identifier allowed by git.kwargs (additional keyword arguments, optional) β
Can be used to update the configuration object (after it being loaded) and initiate the model (e.g.,
output_attentions=True). Behaves differently depending on whether aconfigis provided or automatically loaded:If a configuration is provided with
config,**kwargswill be directly passed to the underlying modelβs__init__method (we assume all relevant updates to the configuration have already been done)If a configuration is not provided,
kwargswill be first passed to the configuration class initialization function (from_pretrained()). Each key ofkwargsthat corresponds to a configuration attribute will be used to override said attribute with the suppliedkwargsvalue. Remaining keys that do not correspond to any configuration attribute will be passed to the underlying modelβs__init__function.
Examples:
>>> from transformers import AutoConfig, TFAutoModelForCausalLM >>> # Download model and configuration from huggingface.co and cache. >>> model = TFAutoModelForCausalLM.from_pretrained('bert-base-cased') >>> # Update configuration during loading >>> model = TFAutoModelForCausalLM.from_pretrained('bert-base-cased', output_attentions=True) >>> model.config.output_attentions True >>> # Loading from a PyTorch checkpoint file instead of a TensorFlow model (slower) >>> config = AutoConfig.from_pretrained('./pt_model/bert_pt_model_config.json') >>> model = TFAutoModelForCausalLM.from_pretrained('./pt_model/bert_pytorch_model.bin', from_pt=True, config=config)
-
classmethod
TFAutoModelForMaskedLMΒΆ
-
class
transformers.TFAutoModelForMaskedLM(*args, **kwargs)[source]ΒΆ This is a generic model class that will be instantiated as one of the model classes of the library (with a masked language modeling head) when created with the
from_pretrained()class method or thefrom_config()class method.This class cannot be instantiated directly using
__init__()(throws an error).-
classmethod
from_config(config, **kwargs)ΒΆ Instantiates one of the model classes of the library (with a masked language modeling head) from a configuration.
Note
Loading a model from its configuration file does not load the model weights. It only affects the modelβs configuration. Use
from_pretrained()to load the model weights.- Parameters
config (
PretrainedConfig) βThe model class to instantiate is selected based on the configuration class:
AlbertConfigconfiguration class:TFAlbertForMaskedLM(ALBERT model)BertConfigconfiguration class:TFBertForMaskedLM(BERT model)CamembertConfigconfiguration class:TFCamembertForMaskedLM(CamemBERT model)ConvBertConfigconfiguration class:TFConvBertForMaskedLM(ConvBERT model)DistilBertConfigconfiguration class:TFDistilBertForMaskedLM(DistilBERT model)ElectraConfigconfiguration class:TFElectraForMaskedLM(ELECTRA model)FlaubertConfigconfiguration class:TFFlaubertWithLMHeadModel(FlauBERT model)FunnelConfigconfiguration class:TFFunnelForMaskedLM(Funnel Transformer model)LayoutLMConfigconfiguration class:TFLayoutLMForMaskedLM(LayoutLM model)LongformerConfigconfiguration class:TFLongformerForMaskedLM(Longformer model)MPNetConfigconfiguration class:TFMPNetForMaskedLM(MPNet model)MobileBertConfigconfiguration class:TFMobileBertForMaskedLM(MobileBERT model)RoFormerConfigconfiguration class:TFRoFormerForMaskedLM(RoFormer model)RobertaConfigconfiguration class:TFRobertaForMaskedLM(RoBERTa model)XLMConfigconfiguration class:TFXLMWithLMHeadModel(XLM model)XLMRobertaConfigconfiguration class:TFXLMRobertaForMaskedLM(XLM-RoBERTa model)
Examples:
>>> from transformers import AutoConfig, TFAutoModelForMaskedLM >>> # Download configuration from huggingface.co and cache. >>> config = AutoConfig.from_pretrained('bert-base-cased') >>> model = TFAutoModelForMaskedLM.from_config(config)
-
classmethod
from_pretrained(pretrained_model_name_or_path, *model_args, **kwargs)ΒΆ Instantiate one of the model classes of the library (with a masked language modeling head) from a pretrained model.
The model class to instantiate is selected based on the
model_typeproperty of the config object (either passed as an argument or loaded frompretrained_model_name_or_pathif possible), or when itβs missing, by falling back to using pattern matching onpretrained_model_name_or_path:albert β
TFAlbertForMaskedLM(ALBERT model)bert β
TFBertForMaskedLM(BERT model)camembert β
TFCamembertForMaskedLM(CamemBERT model)convbert β
TFConvBertForMaskedLM(ConvBERT model)distilbert β
TFDistilBertForMaskedLM(DistilBERT model)electra β
TFElectraForMaskedLM(ELECTRA model)flaubert β
TFFlaubertWithLMHeadModel(FlauBERT model)funnel β
TFFunnelForMaskedLM(Funnel Transformer model)layoutlm β
TFLayoutLMForMaskedLM(LayoutLM model)longformer β
TFLongformerForMaskedLM(Longformer model)mobilebert β
TFMobileBertForMaskedLM(MobileBERT model)mpnet β
TFMPNetForMaskedLM(MPNet model)roberta β
TFRobertaForMaskedLM(RoBERTa model)roformer β
TFRoFormerForMaskedLM(RoFormer model)xlm β
TFXLMWithLMHeadModel(XLM model)xlm-roberta β
TFXLMRobertaForMaskedLM(XLM-RoBERTa model)
- Parameters
pretrained_model_name_or_path (
stroros.PathLike) βCan be either:
A string, the model id of a pretrained model hosted inside a model repo on huggingface.co. Valid model ids can be located at the root-level, like
bert-base-uncased, or namespaced under a user or organization name, likedbmdz/bert-base-german-cased.A path to a directory containing model weights saved using
save_pretrained(), e.g.,./my_model_directory/.A path or url to a PyTorch state_dict save file (e.g,
./pt_model/pytorch_model.bin). In this case,from_ptshould be set toTrueand a configuration object should be provided asconfigargument. This loading path is slower than converting the PyTorch model in a TensorFlow model using the provided conversion scripts and loading the TensorFlow model afterwards.
model_args (additional positional arguments, optional) β Will be passed along to the underlying model
__init__()method.config (
PretrainedConfig, optional) βConfiguration for the model to use instead of an automatically loaded configuration. Configuration can be automatically loaded when:
The model is a model provided by the library (loaded with the model id string of a pretrained model).
The model was saved using
save_pretrained()and is reloaded by supplying the save directory.The model is loaded by supplying a local directory as
pretrained_model_name_or_pathand a configuration JSON file named config.json is found in the directory.
cache_dir (
stroros.PathLike, optional) β Path to a directory in which a downloaded pretrained model configuration should be cached if the standard cache should not be used.from_pt (
bool, optional, defaults toFalse) β Load the model weights from a PyTorch checkpoint save file (see docstring ofpretrained_model_name_or_pathargument).force_download (
bool, optional, defaults toFalse) β Whether or not to force the (re-)download of the model weights and configuration files, overriding the cached versions if they exist.resume_download (
bool, optional, defaults toFalse) β Whether or not to delete incompletely received files. Will attempt to resume the download if such a file exists.proxies (
Dict[str, str], `optional) β A dictionary of proxy servers to use by protocol or endpoint, e.g.,{'http': 'foo.bar:3128', 'http://hostname': 'foo.bar:4012'}. The proxies are used on each request.output_loading_info (
bool, optional, defaults toFalse) β Whether ot not to also return a dictionary containing missing keys, unexpected keys and error messages.local_files_only (
bool, optional, defaults toFalse) β Whether or not to only look at local files (e.g., not try downloading the model).revision (
str, optional, defaults to"main") β The specific model version to use. It can be a branch name, a tag name, or a commit id, since we use a git-based system for storing models and other artifacts on huggingface.co, sorevisioncan be any identifier allowed by git.kwargs (additional keyword arguments, optional) β
Can be used to update the configuration object (after it being loaded) and initiate the model (e.g.,
output_attentions=True). Behaves differently depending on whether aconfigis provided or automatically loaded:If a configuration is provided with
config,**kwargswill be directly passed to the underlying modelβs__init__method (we assume all relevant updates to the configuration have already been done)If a configuration is not provided,
kwargswill be first passed to the configuration class initialization function (from_pretrained()). Each key ofkwargsthat corresponds to a configuration attribute will be used to override said attribute with the suppliedkwargsvalue. Remaining keys that do not correspond to any configuration attribute will be passed to the underlying modelβs__init__function.
Examples:
>>> from transformers import AutoConfig, TFAutoModelForMaskedLM >>> # Download model and configuration from huggingface.co and cache. >>> model = TFAutoModelForMaskedLM.from_pretrained('bert-base-cased') >>> # Update configuration during loading >>> model = TFAutoModelForMaskedLM.from_pretrained('bert-base-cased', output_attentions=True) >>> model.config.output_attentions True >>> # Loading from a PyTorch checkpoint file instead of a TensorFlow model (slower) >>> config = AutoConfig.from_pretrained('./pt_model/bert_pt_model_config.json') >>> model = TFAutoModelForMaskedLM.from_pretrained('./pt_model/bert_pytorch_model.bin', from_pt=True, config=config)
-
classmethod
TFAutoModelForSeq2SeqLMΒΆ
-
class
transformers.TFAutoModelForSeq2SeqLM(*args, **kwargs)[source]ΒΆ This is a generic model class that will be instantiated as one of the model classes of the library (with a sequence-to-sequence language modeling head) when created with the
from_pretrained()class method or thefrom_config()class method.This class cannot be instantiated directly using
__init__()(throws an error).-
classmethod
from_config(config, **kwargs)ΒΆ Instantiates one of the model classes of the library (with a sequence-to-sequence language modeling head) from a configuration.
Note
Loading a model from its configuration file does not load the model weights. It only affects the modelβs configuration. Use
from_pretrained()to load the model weights.- Parameters
config (
PretrainedConfig) βThe model class to instantiate is selected based on the configuration class:
BartConfigconfiguration class:TFBartForConditionalGeneration(BART model)BlenderbotConfigconfiguration class:TFBlenderbotForConditionalGeneration(Blenderbot model)BlenderbotSmallConfigconfiguration class:TFBlenderbotSmallForConditionalGeneration(BlenderbotSmall model)LEDConfigconfiguration class:TFLEDForConditionalGeneration(LED model)MBartConfigconfiguration class:TFMBartForConditionalGeneration(mBART model)MT5Configconfiguration class:TFMT5ForConditionalGeneration(mT5 model)MarianConfigconfiguration class:TFMarianMTModel(Marian model)PegasusConfigconfiguration class:TFPegasusForConditionalGeneration(Pegasus model)T5Configconfiguration class:TFT5ForConditionalGeneration(T5 model)
Examples:
>>> from transformers import AutoConfig, TFAutoModelForSeq2SeqLM >>> # Download configuration from huggingface.co and cache. >>> config = AutoConfig.from_pretrained('t5-base') >>> model = TFAutoModelForSeq2SeqLM.from_config(config)
-
classmethod
from_pretrained(pretrained_model_name_or_path, *model_args, **kwargs)ΒΆ Instantiate one of the model classes of the library (with a sequence-to-sequence language modeling head) from a pretrained model.
The model class to instantiate is selected based on the
model_typeproperty of the config object (either passed as an argument or loaded frompretrained_model_name_or_pathif possible), or when itβs missing, by falling back to using pattern matching onpretrained_model_name_or_path:bart β
TFBartForConditionalGeneration(BART model)blenderbot β
TFBlenderbotForConditionalGeneration(Blenderbot model)blenderbot-small β
TFBlenderbotSmallForConditionalGeneration(BlenderbotSmall model)led β
TFLEDForConditionalGeneration(LED model)marian β
TFMarianMTModel(Marian model)mbart β
TFMBartForConditionalGeneration(mBART model)mt5 β
TFMT5ForConditionalGeneration(mT5 model)pegasus β
TFPegasusForConditionalGeneration(Pegasus model)t5 β
TFT5ForConditionalGeneration(T5 model)
- Parameters
pretrained_model_name_or_path (
stroros.PathLike) βCan be either:
A string, the model id of a pretrained model hosted inside a model repo on huggingface.co. Valid model ids can be located at the root-level, like
bert-base-uncased, or namespaced under a user or organization name, likedbmdz/bert-base-german-cased.A path to a directory containing model weights saved using
save_pretrained(), e.g.,./my_model_directory/.A path or url to a PyTorch state_dict save file (e.g,
./pt_model/pytorch_model.bin). In this case,from_ptshould be set toTrueand a configuration object should be provided asconfigargument. This loading path is slower than converting the PyTorch model in a TensorFlow model using the provided conversion scripts and loading the TensorFlow model afterwards.
model_args (additional positional arguments, optional) β Will be passed along to the underlying model
__init__()method.config (
PretrainedConfig, optional) βConfiguration for the model to use instead of an automatically loaded configuration. Configuration can be automatically loaded when:
The model is a model provided by the library (loaded with the model id string of a pretrained model).
The model was saved using
save_pretrained()and is reloaded by supplying the save directory.The model is loaded by supplying a local directory as
pretrained_model_name_or_pathand a configuration JSON file named config.json is found in the directory.
cache_dir (
stroros.PathLike, optional) β Path to a directory in which a downloaded pretrained model configuration should be cached if the standard cache should not be used.from_pt (
bool, optional, defaults toFalse) β Load the model weights from a PyTorch checkpoint save file (see docstring ofpretrained_model_name_or_pathargument).force_download (
bool, optional, defaults toFalse) β Whether or not to force the (re-)download of the model weights and configuration files, overriding the cached versions if they exist.resume_download (
bool, optional, defaults toFalse) β Whether or not to delete incompletely received files. Will attempt to resume the download if such a file exists.proxies (
Dict[str, str], `optional) β A dictionary of proxy servers to use by protocol or endpoint, e.g.,{'http': 'foo.bar:3128', 'http://hostname': 'foo.bar:4012'}. The proxies are used on each request.output_loading_info (
bool, optional, defaults toFalse) β Whether ot not to also return a dictionary containing missing keys, unexpected keys and error messages.local_files_only (
bool, optional, defaults toFalse) β Whether or not to only look at local files (e.g., not try downloading the model).revision (
str, optional, defaults to"main") β The specific model version to use. It can be a branch name, a tag name, or a commit id, since we use a git-based system for storing models and other artifacts on huggingface.co, sorevisioncan be any identifier allowed by git.kwargs (additional keyword arguments, optional) β
Can be used to update the configuration object (after it being loaded) and initiate the model (e.g.,
output_attentions=True). Behaves differently depending on whether aconfigis provided or automatically loaded:If a configuration is provided with
config,**kwargswill be directly passed to the underlying modelβs__init__method (we assume all relevant updates to the configuration have already been done)If a configuration is not provided,
kwargswill be first passed to the configuration class initialization function (from_pretrained()). Each key ofkwargsthat corresponds to a configuration attribute will be used to override said attribute with the suppliedkwargsvalue. Remaining keys that do not correspond to any configuration attribute will be passed to the underlying modelβs__init__function.
Examples:
>>> from transformers import AutoConfig, TFAutoModelForSeq2SeqLM >>> # Download model and configuration from huggingface.co and cache. >>> model = TFAutoModelForSeq2SeqLM.from_pretrained('t5-base') >>> # Update configuration during loading >>> model = TFAutoModelForSeq2SeqLM.from_pretrained('t5-base', output_attentions=True) >>> model.config.output_attentions True >>> # Loading from a PyTorch checkpoint file instead of a TensorFlow model (slower) >>> config = AutoConfig.from_pretrained('./pt_model/t5_pt_model_config.json') >>> model = TFAutoModelForSeq2SeqLM.from_pretrained('./pt_model/t5_pytorch_model.bin', from_pt=True, config=config)
-
classmethod
TFAutoModelForSequenceClassificationΒΆ
-
class
transformers.TFAutoModelForSequenceClassification(*args, **kwargs)[source]ΒΆ This is a generic model class that will be instantiated as one of the model classes of the library (with a sequence classification head) when created with the
from_pretrained()class method or thefrom_config()class method.This class cannot be instantiated directly using
__init__()(throws an error).-
classmethod
from_config(config, **kwargs)ΒΆ Instantiates one of the model classes of the library (with a sequence classification head) from a configuration.
Note
Loading a model from its configuration file does not load the model weights. It only affects the modelβs configuration. Use
from_pretrained()to load the model weights.- Parameters
config (
PretrainedConfig) βThe model class to instantiate is selected based on the configuration class:
AlbertConfigconfiguration class:TFAlbertForSequenceClassification(ALBERT model)BertConfigconfiguration class:TFBertForSequenceClassification(BERT model)CTRLConfigconfiguration class:TFCTRLForSequenceClassification(CTRL model)CamembertConfigconfiguration class:TFCamembertForSequenceClassification(CamemBERT model)ConvBertConfigconfiguration class:TFConvBertForSequenceClassification(ConvBERT model)DistilBertConfigconfiguration class:TFDistilBertForSequenceClassification(DistilBERT model)ElectraConfigconfiguration class:TFElectraForSequenceClassification(ELECTRA model)FlaubertConfigconfiguration class:TFFlaubertForSequenceClassification(FlauBERT model)FunnelConfigconfiguration class:TFFunnelForSequenceClassification(Funnel Transformer model)GPT2Configconfiguration class:TFGPT2ForSequenceClassification(OpenAI GPT-2 model)LayoutLMConfigconfiguration class:TFLayoutLMForSequenceClassification(LayoutLM model)LongformerConfigconfiguration class:TFLongformerForSequenceClassification(Longformer model)MPNetConfigconfiguration class:TFMPNetForSequenceClassification(MPNet model)MobileBertConfigconfiguration class:TFMobileBertForSequenceClassification(MobileBERT model)OpenAIGPTConfigconfiguration class:TFOpenAIGPTForSequenceClassification(OpenAI GPT model)RoFormerConfigconfiguration class:TFRoFormerForSequenceClassification(RoFormer model)RobertaConfigconfiguration class:TFRobertaForSequenceClassification(RoBERTa model)TransfoXLConfigconfiguration class:TFTransfoXLForSequenceClassification(Transformer-XL model)XLMConfigconfiguration class:TFXLMForSequenceClassification(XLM model)XLMRobertaConfigconfiguration class:TFXLMRobertaForSequenceClassification(XLM-RoBERTa model)XLNetConfigconfiguration class:TFXLNetForSequenceClassification(XLNet model)
Examples:
>>> from transformers import AutoConfig, TFAutoModelForSequenceClassification >>> # Download configuration from huggingface.co and cache. >>> config = AutoConfig.from_pretrained('bert-base-cased') >>> model = TFAutoModelForSequenceClassification.from_config(config)
-
classmethod
from_pretrained(pretrained_model_name_or_path, *model_args, **kwargs)ΒΆ Instantiate one of the model classes of the library (with a sequence classification head) from a pretrained model.
The model class to instantiate is selected based on the
model_typeproperty of the config object (either passed as an argument or loaded frompretrained_model_name_or_pathif possible), or when itβs missing, by falling back to using pattern matching onpretrained_model_name_or_path:albert β
TFAlbertForSequenceClassification(ALBERT model)bert β
TFBertForSequenceClassification(BERT model)camembert β
TFCamembertForSequenceClassification(CamemBERT model)convbert β
TFConvBertForSequenceClassification(ConvBERT model)ctrl β
TFCTRLForSequenceClassification(CTRL model)distilbert β
TFDistilBertForSequenceClassification(DistilBERT model)electra β
TFElectraForSequenceClassification(ELECTRA model)flaubert β
TFFlaubertForSequenceClassification(FlauBERT model)funnel β
TFFunnelForSequenceClassification(Funnel Transformer model)gpt2 β
TFGPT2ForSequenceClassification(OpenAI GPT-2 model)layoutlm β
TFLayoutLMForSequenceClassification(LayoutLM model)longformer β
TFLongformerForSequenceClassification(Longformer model)mobilebert β
TFMobileBertForSequenceClassification(MobileBERT model)mpnet β
TFMPNetForSequenceClassification(MPNet model)openai-gpt β
TFOpenAIGPTForSequenceClassification(OpenAI GPT model)roberta β
TFRobertaForSequenceClassification(RoBERTa model)roformer β
TFRoFormerForSequenceClassification(RoFormer model)transfo-xl β
TFTransfoXLForSequenceClassification(Transformer-XL model)xlm β
TFXLMForSequenceClassification(XLM model)xlm-roberta β
TFXLMRobertaForSequenceClassification(XLM-RoBERTa model)xlnet β
TFXLNetForSequenceClassification(XLNet model)
- Parameters
pretrained_model_name_or_path (
stroros.PathLike) βCan be either:
A string, the model id of a pretrained model hosted inside a model repo on huggingface.co. Valid model ids can be located at the root-level, like
bert-base-uncased, or namespaced under a user or organization name, likedbmdz/bert-base-german-cased.A path to a directory containing model weights saved using
save_pretrained(), e.g.,./my_model_directory/.A path or url to a PyTorch state_dict save file (e.g,
./pt_model/pytorch_model.bin). In this case,from_ptshould be set toTrueand a configuration object should be provided asconfigargument. This loading path is slower than converting the PyTorch model in a TensorFlow model using the provided conversion scripts and loading the TensorFlow model afterwards.
model_args (additional positional arguments, optional) β Will be passed along to the underlying model
__init__()method.config (
PretrainedConfig, optional) βConfiguration for the model to use instead of an automatically loaded configuration. Configuration can be automatically loaded when:
The model is a model provided by the library (loaded with the model id string of a pretrained model).
The model was saved using
save_pretrained()and is reloaded by supplying the save directory.The model is loaded by supplying a local directory as
pretrained_model_name_or_pathand a configuration JSON file named config.json is found in the directory.
cache_dir (
stroros.PathLike, optional) β Path to a directory in which a downloaded pretrained model configuration should be cached if the standard cache should not be used.from_pt (
bool, optional, defaults toFalse) β Load the model weights from a PyTorch checkpoint save file (see docstring ofpretrained_model_name_or_pathargument).force_download (
bool, optional, defaults toFalse) β Whether or not to force the (re-)download of the model weights and configuration files, overriding the cached versions if they exist.resume_download (
bool, optional, defaults toFalse) β Whether or not to delete incompletely received files. Will attempt to resume the download if such a file exists.proxies (
Dict[str, str], `optional) β A dictionary of proxy servers to use by protocol or endpoint, e.g.,{'http': 'foo.bar:3128', 'http://hostname': 'foo.bar:4012'}. The proxies are used on each request.output_loading_info (
bool, optional, defaults toFalse) β Whether ot not to also return a dictionary containing missing keys, unexpected keys and error messages.local_files_only (
bool, optional, defaults toFalse) β Whether or not to only look at local files (e.g., not try downloading the model).revision (
str, optional, defaults to"main") β The specific model version to use. It can be a branch name, a tag name, or a commit id, since we use a git-based system for storing models and other artifacts on huggingface.co, sorevisioncan be any identifier allowed by git.kwargs (additional keyword arguments, optional) β
Can be used to update the configuration object (after it being loaded) and initiate the model (e.g.,
output_attentions=True). Behaves differently depending on whether aconfigis provided or automatically loaded:If a configuration is provided with
config,**kwargswill be directly passed to the underlying modelβs__init__method (we assume all relevant updates to the configuration have already been done)If a configuration is not provided,
kwargswill be first passed to the configuration class initialization function (from_pretrained()). Each key ofkwargsthat corresponds to a configuration attribute will be used to override said attribute with the suppliedkwargsvalue. Remaining keys that do not correspond to any configuration attribute will be passed to the underlying modelβs__init__function.
Examples:
>>> from transformers import AutoConfig, TFAutoModelForSequenceClassification >>> # Download model and configuration from huggingface.co and cache. >>> model = TFAutoModelForSequenceClassification.from_pretrained('bert-base-cased') >>> # Update configuration during loading >>> model = TFAutoModelForSequenceClassification.from_pretrained('bert-base-cased', output_attentions=True) >>> model.config.output_attentions True >>> # Loading from a PyTorch checkpoint file instead of a TensorFlow model (slower) >>> config = AutoConfig.from_pretrained('./pt_model/bert_pt_model_config.json') >>> model = TFAutoModelForSequenceClassification.from_pretrained('./pt_model/bert_pytorch_model.bin', from_pt=True, config=config)
-
classmethod
TFAutoModelForMultipleChoiceΒΆ
-
class
transformers.TFAutoModelForMultipleChoice(*args, **kwargs)[source]ΒΆ This is a generic model class that will be instantiated as one of the model classes of the library (with a multiple choice head) when created with the
from_pretrained()class method or thefrom_config()class method.This class cannot be instantiated directly using
__init__()(throws an error).-
classmethod
from_config(config, **kwargs)ΒΆ Instantiates one of the model classes of the library (with a multiple choice head) from a configuration.
Note
Loading a model from its configuration file does not load the model weights. It only affects the modelβs configuration. Use
from_pretrained()to load the model weights.- Parameters
config (
PretrainedConfig) βThe model class to instantiate is selected based on the configuration class:
AlbertConfigconfiguration class:TFAlbertForMultipleChoice(ALBERT model)BertConfigconfiguration class:TFBertForMultipleChoice(BERT model)CamembertConfigconfiguration class:TFCamembertForMultipleChoice(CamemBERT model)ConvBertConfigconfiguration class:TFConvBertForMultipleChoice(ConvBERT model)DistilBertConfigconfiguration class:TFDistilBertForMultipleChoice(DistilBERT model)ElectraConfigconfiguration class:TFElectraForMultipleChoice(ELECTRA model)FlaubertConfigconfiguration class:TFFlaubertForMultipleChoice(FlauBERT model)FunnelConfigconfiguration class:TFFunnelForMultipleChoice(Funnel Transformer model)LongformerConfigconfiguration class:TFLongformerForMultipleChoice(Longformer model)MPNetConfigconfiguration class:TFMPNetForMultipleChoice(MPNet model)MobileBertConfigconfiguration class:TFMobileBertForMultipleChoice(MobileBERT model)RoFormerConfigconfiguration class:TFRoFormerForMultipleChoice(RoFormer model)RobertaConfigconfiguration class:TFRobertaForMultipleChoice(RoBERTa model)XLMConfigconfiguration class:TFXLMForMultipleChoice(XLM model)XLMRobertaConfigconfiguration class:TFXLMRobertaForMultipleChoice(XLM-RoBERTa model)XLNetConfigconfiguration class:TFXLNetForMultipleChoice(XLNet model)
Examples:
>>> from transformers import AutoConfig, TFAutoModelForMultipleChoice >>> # Download configuration from huggingface.co and cache. >>> config = AutoConfig.from_pretrained('bert-base-cased') >>> model = TFAutoModelForMultipleChoice.from_config(config)
-
classmethod
from_pretrained(pretrained_model_name_or_path, *model_args, **kwargs)ΒΆ Instantiate one of the model classes of the library (with a multiple choice head) from a pretrained model.
The model class to instantiate is selected based on the
model_typeproperty of the config object (either passed as an argument or loaded frompretrained_model_name_or_pathif possible), or when itβs missing, by falling back to using pattern matching onpretrained_model_name_or_path:albert β
TFAlbertForMultipleChoice(ALBERT model)bert β
TFBertForMultipleChoice(BERT model)camembert β
TFCamembertForMultipleChoice(CamemBERT model)convbert β
TFConvBertForMultipleChoice(ConvBERT model)distilbert β
TFDistilBertForMultipleChoice(DistilBERT model)electra β
TFElectraForMultipleChoice(ELECTRA model)flaubert β
TFFlaubertForMultipleChoice(FlauBERT model)funnel β
TFFunnelForMultipleChoice(Funnel Transformer model)longformer β
TFLongformerForMultipleChoice(Longformer model)mobilebert β
TFMobileBertForMultipleChoice(MobileBERT model)mpnet β
TFMPNetForMultipleChoice(MPNet model)roberta β
TFRobertaForMultipleChoice(RoBERTa model)roformer β
TFRoFormerForMultipleChoice(RoFormer model)xlm β
TFXLMForMultipleChoice(XLM model)xlm-roberta β
TFXLMRobertaForMultipleChoice(XLM-RoBERTa model)xlnet β
TFXLNetForMultipleChoice(XLNet model)
- Parameters
pretrained_model_name_or_path (
stroros.PathLike) βCan be either:
A string, the model id of a pretrained model hosted inside a model repo on huggingface.co. Valid model ids can be located at the root-level, like
bert-base-uncased, or namespaced under a user or organization name, likedbmdz/bert-base-german-cased.A path to a directory containing model weights saved using
save_pretrained(), e.g.,./my_model_directory/.A path or url to a PyTorch state_dict save file (e.g,
./pt_model/pytorch_model.bin). In this case,from_ptshould be set toTrueand a configuration object should be provided asconfigargument. This loading path is slower than converting the PyTorch model in a TensorFlow model using the provided conversion scripts and loading the TensorFlow model afterwards.
model_args (additional positional arguments, optional) β Will be passed along to the underlying model
__init__()method.config (
PretrainedConfig, optional) βConfiguration for the model to use instead of an automatically loaded configuration. Configuration can be automatically loaded when:
The model is a model provided by the library (loaded with the model id string of a pretrained model).
The model was saved using
save_pretrained()and is reloaded by supplying the save directory.The model is loaded by supplying a local directory as
pretrained_model_name_or_pathand a configuration JSON file named config.json is found in the directory.
cache_dir (
stroros.PathLike, optional) β Path to a directory in which a downloaded pretrained model configuration should be cached if the standard cache should not be used.from_pt (
bool, optional, defaults toFalse) β Load the model weights from a PyTorch checkpoint save file (see docstring ofpretrained_model_name_or_pathargument).force_download (
bool, optional, defaults toFalse) β Whether or not to force the (re-)download of the model weights and configuration files, overriding the cached versions if they exist.resume_download (
bool, optional, defaults toFalse) β Whether or not to delete incompletely received files. Will attempt to resume the download if such a file exists.proxies (
Dict[str, str], `optional) β A dictionary of proxy servers to use by protocol or endpoint, e.g.,{'http': 'foo.bar:3128', 'http://hostname': 'foo.bar:4012'}. The proxies are used on each request.output_loading_info (
bool, optional, defaults toFalse) β Whether ot not to also return a dictionary containing missing keys, unexpected keys and error messages.local_files_only (
bool, optional, defaults toFalse) β Whether or not to only look at local files (e.g., not try downloading the model).revision (
str, optional, defaults to"main") β The specific model version to use. It can be a branch name, a tag name, or a commit id, since we use a git-based system for storing models and other artifacts on huggingface.co, sorevisioncan be any identifier allowed by git.kwargs (additional keyword arguments, optional) β
Can be used to update the configuration object (after it being loaded) and initiate the model (e.g.,
output_attentions=True). Behaves differently depending on whether aconfigis provided or automatically loaded:If a configuration is provided with
config,**kwargswill be directly passed to the underlying modelβs__init__method (we assume all relevant updates to the configuration have already been done)If a configuration is not provided,
kwargswill be first passed to the configuration class initialization function (from_pretrained()). Each key ofkwargsthat corresponds to a configuration attribute will be used to override said attribute with the suppliedkwargsvalue. Remaining keys that do not correspond to any configuration attribute will be passed to the underlying modelβs__init__function.
Examples:
>>> from transformers import AutoConfig, TFAutoModelForMultipleChoice >>> # Download model and configuration from huggingface.co and cache. >>> model = TFAutoModelForMultipleChoice.from_pretrained('bert-base-cased') >>> # Update configuration during loading >>> model = TFAutoModelForMultipleChoice.from_pretrained('bert-base-cased', output_attentions=True) >>> model.config.output_attentions True >>> # Loading from a PyTorch checkpoint file instead of a TensorFlow model (slower) >>> config = AutoConfig.from_pretrained('./pt_model/bert_pt_model_config.json') >>> model = TFAutoModelForMultipleChoice.from_pretrained('./pt_model/bert_pytorch_model.bin', from_pt=True, config=config)
-
classmethod
TFAutoModelForTokenClassificationΒΆ
-
class
transformers.TFAutoModelForTokenClassification(*args, **kwargs)[source]ΒΆ This is a generic model class that will be instantiated as one of the model classes of the library (with a token classification head) when created with the
from_pretrained()class method or thefrom_config()class method.This class cannot be instantiated directly using
__init__()(throws an error).-
classmethod
from_config(config, **kwargs)ΒΆ Instantiates one of the model classes of the library (with a token classification head) from a configuration.
Note
Loading a model from its configuration file does not load the model weights. It only affects the modelβs configuration. Use
from_pretrained()to load the model weights.- Parameters
config (
PretrainedConfig) βThe model class to instantiate is selected based on the configuration class:
AlbertConfigconfiguration class:TFAlbertForTokenClassification(ALBERT model)BertConfigconfiguration class:TFBertForTokenClassification(BERT model)CamembertConfigconfiguration class:TFCamembertForTokenClassification(CamemBERT model)ConvBertConfigconfiguration class:TFConvBertForTokenClassification(ConvBERT model)DistilBertConfigconfiguration class:TFDistilBertForTokenClassification(DistilBERT model)ElectraConfigconfiguration class:TFElectraForTokenClassification(ELECTRA model)FlaubertConfigconfiguration class:TFFlaubertForTokenClassification(FlauBERT model)FunnelConfigconfiguration class:TFFunnelForTokenClassification(Funnel Transformer model)LayoutLMConfigconfiguration class:TFLayoutLMForTokenClassification(LayoutLM model)LongformerConfigconfiguration class:TFLongformerForTokenClassification(Longformer model)MPNetConfigconfiguration class:TFMPNetForTokenClassification(MPNet model)MobileBertConfigconfiguration class:TFMobileBertForTokenClassification(MobileBERT model)RoFormerConfigconfiguration class:TFRoFormerForTokenClassification(RoFormer model)RobertaConfigconfiguration class:TFRobertaForTokenClassification(RoBERTa model)XLMConfigconfiguration class:TFXLMForTokenClassification(XLM model)XLMRobertaConfigconfiguration class:TFXLMRobertaForTokenClassification(XLM-RoBERTa model)XLNetConfigconfiguration class:TFXLNetForTokenClassification(XLNet model)
Examples:
>>> from transformers import AutoConfig, TFAutoModelForTokenClassification >>> # Download configuration from huggingface.co and cache. >>> config = AutoConfig.from_pretrained('bert-base-cased') >>> model = TFAutoModelForTokenClassification.from_config(config)
-
classmethod
from_pretrained(pretrained_model_name_or_path, *model_args, **kwargs)ΒΆ Instantiate one of the model classes of the library (with a token classification head) from a pretrained model.
The model class to instantiate is selected based on the
model_typeproperty of the config object (either passed as an argument or loaded frompretrained_model_name_or_pathif possible), or when itβs missing, by falling back to using pattern matching onpretrained_model_name_or_path:albert β
TFAlbertForTokenClassification(ALBERT model)bert β
TFBertForTokenClassification(BERT model)camembert β
TFCamembertForTokenClassification(CamemBERT model)convbert β
TFConvBertForTokenClassification(ConvBERT model)distilbert β
TFDistilBertForTokenClassification(DistilBERT model)electra β
TFElectraForTokenClassification(ELECTRA model)flaubert β
TFFlaubertForTokenClassification(FlauBERT model)funnel β
TFFunnelForTokenClassification(Funnel Transformer model)layoutlm β
TFLayoutLMForTokenClassification(LayoutLM model)longformer β
TFLongformerForTokenClassification(Longformer model)mobilebert β
TFMobileBertForTokenClassification(MobileBERT model)mpnet β
TFMPNetForTokenClassification(MPNet model)roberta β
TFRobertaForTokenClassification(RoBERTa model)roformer β
TFRoFormerForTokenClassification(RoFormer model)xlm β
TFXLMForTokenClassification(XLM model)xlm-roberta β
TFXLMRobertaForTokenClassification(XLM-RoBERTa model)xlnet β
TFXLNetForTokenClassification(XLNet model)
- Parameters
pretrained_model_name_or_path (
stroros.PathLike) βCan be either:
A string, the model id of a pretrained model hosted inside a model repo on huggingface.co. Valid model ids can be located at the root-level, like
bert-base-uncased, or namespaced under a user or organization name, likedbmdz/bert-base-german-cased.A path to a directory containing model weights saved using
save_pretrained(), e.g.,./my_model_directory/.A path or url to a PyTorch state_dict save file (e.g,
./pt_model/pytorch_model.bin). In this case,from_ptshould be set toTrueand a configuration object should be provided asconfigargument. This loading path is slower than converting the PyTorch model in a TensorFlow model using the provided conversion scripts and loading the TensorFlow model afterwards.
model_args (additional positional arguments, optional) β Will be passed along to the underlying model
__init__()method.config (
PretrainedConfig, optional) βConfiguration for the model to use instead of an automatically loaded configuration. Configuration can be automatically loaded when:
The model is a model provided by the library (loaded with the model id string of a pretrained model).
The model was saved using
save_pretrained()and is reloaded by supplying the save directory.The model is loaded by supplying a local directory as
pretrained_model_name_or_pathand a configuration JSON file named config.json is found in the directory.
cache_dir (
stroros.PathLike, optional) β Path to a directory in which a downloaded pretrained model configuration should be cached if the standard cache should not be used.from_pt (
bool, optional, defaults toFalse) β Load the model weights from a PyTorch checkpoint save file (see docstring ofpretrained_model_name_or_pathargument).force_download (
bool, optional, defaults toFalse) β Whether or not to force the (re-)download of the model weights and configuration files, overriding the cached versions if they exist.resume_download (
bool, optional, defaults toFalse) β Whether or not to delete incompletely received files. Will attempt to resume the download if such a file exists.proxies (
Dict[str, str], `optional) β A dictionary of proxy servers to use by protocol or endpoint, e.g.,{'http': 'foo.bar:3128', 'http://hostname': 'foo.bar:4012'}. The proxies are used on each request.output_loading_info (
bool, optional, defaults toFalse) β Whether ot not to also return a dictionary containing missing keys, unexpected keys and error messages.local_files_only (
bool, optional, defaults toFalse) β Whether or not to only look at local files (e.g., not try downloading the model).revision (
str, optional, defaults to"main") β The specific model version to use. It can be a branch name, a tag name, or a commit id, since we use a git-based system for storing models and other artifacts on huggingface.co, sorevisioncan be any identifier allowed by git.kwargs (additional keyword arguments, optional) β
Can be used to update the configuration object (after it being loaded) and initiate the model (e.g.,
output_attentions=True). Behaves differently depending on whether aconfigis provided or automatically loaded:If a configuration is provided with
config,**kwargswill be directly passed to the underlying modelβs__init__method (we assume all relevant updates to the configuration have already been done)If a configuration is not provided,
kwargswill be first passed to the configuration class initialization function (from_pretrained()). Each key ofkwargsthat corresponds to a configuration attribute will be used to override said attribute with the suppliedkwargsvalue. Remaining keys that do not correspond to any configuration attribute will be passed to the underlying modelβs__init__function.
Examples:
>>> from transformers import AutoConfig, TFAutoModelForTokenClassification >>> # Download model and configuration from huggingface.co and cache. >>> model = TFAutoModelForTokenClassification.from_pretrained('bert-base-cased') >>> # Update configuration during loading >>> model = TFAutoModelForTokenClassification.from_pretrained('bert-base-cased', output_attentions=True) >>> model.config.output_attentions True >>> # Loading from a PyTorch checkpoint file instead of a TensorFlow model (slower) >>> config = AutoConfig.from_pretrained('./pt_model/bert_pt_model_config.json') >>> model = TFAutoModelForTokenClassification.from_pretrained('./pt_model/bert_pytorch_model.bin', from_pt=True, config=config)
-
classmethod
TFAutoModelForQuestionAnsweringΒΆ
-
class
transformers.TFAutoModelForQuestionAnswering(*args, **kwargs)[source]ΒΆ This is a generic model class that will be instantiated as one of the model classes of the library (with a question answering head) when created with the
from_pretrained()class method or thefrom_config()class method.This class cannot be instantiated directly using
__init__()(throws an error).-
classmethod
from_config(config, **kwargs)ΒΆ Instantiates one of the model classes of the library (with a question answering head) from a configuration.
Note
Loading a model from its configuration file does not load the model weights. It only affects the modelβs configuration. Use
from_pretrained()to load the model weights.- Parameters
config (
PretrainedConfig) βThe model class to instantiate is selected based on the configuration class:
AlbertConfigconfiguration class:TFAlbertForQuestionAnswering(ALBERT model)BertConfigconfiguration class:TFBertForQuestionAnswering(BERT model)CamembertConfigconfiguration class:TFCamembertForQuestionAnswering(CamemBERT model)ConvBertConfigconfiguration class:TFConvBertForQuestionAnswering(ConvBERT model)DistilBertConfigconfiguration class:TFDistilBertForQuestionAnswering(DistilBERT model)ElectraConfigconfiguration class:TFElectraForQuestionAnswering(ELECTRA model)FlaubertConfigconfiguration class:TFFlaubertForQuestionAnsweringSimple(FlauBERT model)FunnelConfigconfiguration class:TFFunnelForQuestionAnswering(Funnel Transformer model)LongformerConfigconfiguration class:TFLongformerForQuestionAnswering(Longformer model)MPNetConfigconfiguration class:TFMPNetForQuestionAnswering(MPNet model)MobileBertConfigconfiguration class:TFMobileBertForQuestionAnswering(MobileBERT model)RoFormerConfigconfiguration class:TFRoFormerForQuestionAnswering(RoFormer model)RobertaConfigconfiguration class:TFRobertaForQuestionAnswering(RoBERTa model)XLMConfigconfiguration class:TFXLMForQuestionAnsweringSimple(XLM model)XLMRobertaConfigconfiguration class:TFXLMRobertaForQuestionAnswering(XLM-RoBERTa model)XLNetConfigconfiguration class:TFXLNetForQuestionAnsweringSimple(XLNet model)
Examples:
>>> from transformers import AutoConfig, TFAutoModelForQuestionAnswering >>> # Download configuration from huggingface.co and cache. >>> config = AutoConfig.from_pretrained('bert-base-cased') >>> model = TFAutoModelForQuestionAnswering.from_config(config)
-
classmethod
from_pretrained(pretrained_model_name_or_path, *model_args, **kwargs)ΒΆ Instantiate one of the model classes of the library (with a question answering head) from a pretrained model.
The model class to instantiate is selected based on the
model_typeproperty of the config object (either passed as an argument or loaded frompretrained_model_name_or_pathif possible), or when itβs missing, by falling back to using pattern matching onpretrained_model_name_or_path:albert β
TFAlbertForQuestionAnswering(ALBERT model)bert β
TFBertForQuestionAnswering(BERT model)camembert β
TFCamembertForQuestionAnswering(CamemBERT model)convbert β
TFConvBertForQuestionAnswering(ConvBERT model)distilbert β
TFDistilBertForQuestionAnswering(DistilBERT model)electra β
TFElectraForQuestionAnswering(ELECTRA model)flaubert β
TFFlaubertForQuestionAnsweringSimple(FlauBERT model)funnel β
TFFunnelForQuestionAnswering(Funnel Transformer model)longformer β
TFLongformerForQuestionAnswering(Longformer model)mobilebert β
TFMobileBertForQuestionAnswering(MobileBERT model)mpnet β
TFMPNetForQuestionAnswering(MPNet model)roberta β
TFRobertaForQuestionAnswering(RoBERTa model)roformer β
TFRoFormerForQuestionAnswering(RoFormer model)xlm β
TFXLMForQuestionAnsweringSimple(XLM model)xlm-roberta β
TFXLMRobertaForQuestionAnswering(XLM-RoBERTa model)xlnet β
TFXLNetForQuestionAnsweringSimple(XLNet model)
- Parameters
pretrained_model_name_or_path (
stroros.PathLike) βCan be either:
A string, the model id of a pretrained model hosted inside a model repo on huggingface.co. Valid model ids can be located at the root-level, like
bert-base-uncased, or namespaced under a user or organization name, likedbmdz/bert-base-german-cased.A path to a directory containing model weights saved using
save_pretrained(), e.g.,./my_model_directory/.A path or url to a PyTorch state_dict save file (e.g,
./pt_model/pytorch_model.bin). In this case,from_ptshould be set toTrueand a configuration object should be provided asconfigargument. This loading path is slower than converting the PyTorch model in a TensorFlow model using the provided conversion scripts and loading the TensorFlow model afterwards.
model_args (additional positional arguments, optional) β Will be passed along to the underlying model
__init__()method.config (
PretrainedConfig, optional) βConfiguration for the model to use instead of an automatically loaded configuration. Configuration can be automatically loaded when:
The model is a model provided by the library (loaded with the model id string of a pretrained model).
The model was saved using
save_pretrained()and is reloaded by supplying the save directory.The model is loaded by supplying a local directory as
pretrained_model_name_or_pathand a configuration JSON file named config.json is found in the directory.
cache_dir (
stroros.PathLike, optional) β Path to a directory in which a downloaded pretrained model configuration should be cached if the standard cache should not be used.from_pt (
bool, optional, defaults toFalse) β Load the model weights from a PyTorch checkpoint save file (see docstring ofpretrained_model_name_or_pathargument).force_download (
bool, optional, defaults toFalse) β Whether or not to force the (re-)download of the model weights and configuration files, overriding the cached versions if they exist.resume_download (
bool, optional, defaults toFalse) β Whether or not to delete incompletely received files. Will attempt to resume the download if such a file exists.proxies (
Dict[str, str], `optional) β A dictionary of proxy servers to use by protocol or endpoint, e.g.,{'http': 'foo.bar:3128', 'http://hostname': 'foo.bar:4012'}. The proxies are used on each request.output_loading_info (
bool, optional, defaults toFalse) β Whether ot not to also return a dictionary containing missing keys, unexpected keys and error messages.local_files_only (
bool, optional, defaults toFalse) β Whether or not to only look at local files (e.g., not try downloading the model).revision (
str, optional, defaults to"main") β The specific model version to use. It can be a branch name, a tag name, or a commit id, since we use a git-based system for storing models and other artifacts on huggingface.co, sorevisioncan be any identifier allowed by git.kwargs (additional keyword arguments, optional) β
Can be used to update the configuration object (after it being loaded) and initiate the model (e.g.,
output_attentions=True). Behaves differently depending on whether aconfigis provided or automatically loaded:If a configuration is provided with
config,**kwargswill be directly passed to the underlying modelβs__init__method (we assume all relevant updates to the configuration have already been done)If a configuration is not provided,
kwargswill be first passed to the configuration class initialization function (from_pretrained()). Each key ofkwargsthat corresponds to a configuration attribute will be used to override said attribute with the suppliedkwargsvalue. Remaining keys that do not correspond to any configuration attribute will be passed to the underlying modelβs__init__function.
Examples:
>>> from transformers import AutoConfig, TFAutoModelForQuestionAnswering >>> # Download model and configuration from huggingface.co and cache. >>> model = TFAutoModelForQuestionAnswering.from_pretrained('bert-base-cased') >>> # Update configuration during loading >>> model = TFAutoModelForQuestionAnswering.from_pretrained('bert-base-cased', output_attentions=True) >>> model.config.output_attentions True >>> # Loading from a PyTorch checkpoint file instead of a TensorFlow model (slower) >>> config = AutoConfig.from_pretrained('./pt_model/bert_pt_model_config.json') >>> model = TFAutoModelForQuestionAnswering.from_pretrained('./pt_model/bert_pytorch_model.bin', from_pt=True, config=config)
-
classmethod
FlaxAutoModelΒΆ
-
class
transformers.FlaxAutoModel(*args, **kwargs)[source]ΒΆ This is a generic model class that will be instantiated as one of the base model classes of the library when created with the
from_pretrained()class method or thefrom_config()class method.This class cannot be instantiated directly using
__init__()(throws an error).-
classmethod
from_config(config, **kwargs)ΒΆ Instantiates one of the base model classes of the library from a configuration.
Note
Loading a model from its configuration file does not load the model weights. It only affects the modelβs configuration. Use
from_pretrained()to load the model weights.- Parameters
config (
PretrainedConfig) βThe model class to instantiate is selected based on the configuration class:
BartConfigconfiguration class:FlaxBartModel(BART model)BertConfigconfiguration class:FlaxBertModel(BERT model)BigBirdConfigconfiguration class:FlaxBigBirdModel(BigBird model)CLIPConfigconfiguration class:FlaxCLIPModel(CLIP model)ElectraConfigconfiguration class:FlaxElectraModel(ELECTRA model)GPT2Configconfiguration class:FlaxGPT2Model(OpenAI GPT-2 model)GPTNeoConfigconfiguration class:FlaxGPTNeoModel(GPT Neo model)MBartConfigconfiguration class:FlaxMBartModel(mBART model)MT5Configconfiguration class:FlaxT5Model(mT5 model)MarianConfigconfiguration class:FlaxMarianModel(Marian model)RobertaConfigconfiguration class:FlaxRobertaModel(RoBERTa model)T5Configconfiguration class:FlaxT5Model(T5 model)ViTConfigconfiguration class:FlaxViTModel(ViT model)Wav2Vec2Configconfiguration class:FlaxWav2Vec2Model(Wav2Vec2 model)
Examples:
>>> from transformers import AutoConfig, FlaxAutoModel >>> # Download configuration from huggingface.co and cache. >>> config = AutoConfig.from_pretrained('bert-base-cased') >>> model = FlaxAutoModel.from_config(config)
-
classmethod
from_pretrained(pretrained_model_name_or_path, *model_args, **kwargs)ΒΆ Instantiate one of the base model classes of the library from a pretrained model.
The model class to instantiate is selected based on the
model_typeproperty of the config object (either passed as an argument or loaded frompretrained_model_name_or_pathif possible), or when itβs missing, by falling back to using pattern matching onpretrained_model_name_or_path:bart β
FlaxBartModel(BART model)bert β
FlaxBertModel(BERT model)big_bird β
FlaxBigBirdModel(BigBird model)clip β
FlaxCLIPModel(CLIP model)electra β
FlaxElectraModel(ELECTRA model)gpt2 β
FlaxGPT2Model(OpenAI GPT-2 model)gpt_neo β
FlaxGPTNeoModel(GPT Neo model)marian β
FlaxMarianModel(Marian model)mbart β
FlaxMBartModel(mBART model)mt5 β
FlaxT5Model(mT5 model)roberta β
FlaxRobertaModel(RoBERTa model)t5 β
FlaxT5Model(T5 model)vit β
FlaxViTModel(ViT model)wav2vec2 β
FlaxWav2Vec2Model(Wav2Vec2 model)
- Parameters
pretrained_model_name_or_path (
stroros.PathLike) βCan be either:
A string, the model id of a pretrained model hosted inside a model repo on huggingface.co. Valid model ids can be located at the root-level, like
bert-base-uncased, or namespaced under a user or organization name, likedbmdz/bert-base-german-cased.A path to a directory containing model weights saved using
save_pretrained(), e.g.,./my_model_directory/.A path or url to a PyTorch state_dict save file (e.g,
./pt_model/pytorch_model.bin). In this case,from_ptshould be set toTrueand a configuration object should be provided asconfigargument. This loading path is slower than converting the PyTorch model in a TensorFlow model using the provided conversion scripts and loading the TensorFlow model afterwards.
model_args (additional positional arguments, optional) β Will be passed along to the underlying model
__init__()method.config (
PretrainedConfig, optional) βConfiguration for the model to use instead of an automatically loaded configuration. Configuration can be automatically loaded when:
The model is a model provided by the library (loaded with the model id string of a pretrained model).
The model was saved using
save_pretrained()and is reloaded by supplying the save directory.The model is loaded by supplying a local directory as
pretrained_model_name_or_pathand a configuration JSON file named config.json is found in the directory.
cache_dir (
stroros.PathLike, optional) β Path to a directory in which a downloaded pretrained model configuration should be cached if the standard cache should not be used.from_pt (
bool, optional, defaults toFalse) β Load the model weights from a PyTorch checkpoint save file (see docstring ofpretrained_model_name_or_pathargument).force_download (
bool, optional, defaults toFalse) β Whether or not to force the (re-)download of the model weights and configuration files, overriding the cached versions if they exist.resume_download (
bool, optional, defaults toFalse) β Whether or not to delete incompletely received files. Will attempt to resume the download if such a file exists.proxies (
Dict[str, str], `optional) β A dictionary of proxy servers to use by protocol or endpoint, e.g.,{'http': 'foo.bar:3128', 'http://hostname': 'foo.bar:4012'}. The proxies are used on each request.output_loading_info (
bool, optional, defaults toFalse) β Whether ot not to also return a dictionary containing missing keys, unexpected keys and error messages.local_files_only (
bool, optional, defaults toFalse) β Whether or not to only look at local files (e.g., not try downloading the model).revision (
str, optional, defaults to"main") β The specific model version to use. It can be a branch name, a tag name, or a commit id, since we use a git-based system for storing models and other artifacts on huggingface.co, sorevisioncan be any identifier allowed by git.kwargs (additional keyword arguments, optional) β
Can be used to update the configuration object (after it being loaded) and initiate the model (e.g.,
output_attentions=True). Behaves differently depending on whether aconfigis provided or automatically loaded:If a configuration is provided with
config,**kwargswill be directly passed to the underlying modelβs__init__method (we assume all relevant updates to the configuration have already been done)If a configuration is not provided,
kwargswill be first passed to the configuration class initialization function (from_pretrained()). Each key ofkwargsthat corresponds to a configuration attribute will be used to override said attribute with the suppliedkwargsvalue. Remaining keys that do not correspond to any configuration attribute will be passed to the underlying modelβs__init__function.
Examples:
>>> from transformers import AutoConfig, FlaxAutoModel >>> # Download model and configuration from huggingface.co and cache. >>> model = FlaxAutoModel.from_pretrained('bert-base-cased') >>> # Update configuration during loading >>> model = FlaxAutoModel.from_pretrained('bert-base-cased', output_attentions=True) >>> model.config.output_attentions True >>> # Loading from a PyTorch checkpoint file instead of a TensorFlow model (slower) >>> config = AutoConfig.from_pretrained('./pt_model/bert_pt_model_config.json') >>> model = FlaxAutoModel.from_pretrained('./pt_model/bert_pytorch_model.bin', from_pt=True, config=config)
-
classmethod
FlaxAutoModelForCausalLMΒΆ
-
class
transformers.FlaxAutoModelForCausalLM(*args, **kwargs)[source]ΒΆ This is a generic model class that will be instantiated as one of the model classes of the library (with a causal language modeling head) when created with the
from_pretrained()class method or thefrom_config()class method.This class cannot be instantiated directly using
__init__()(throws an error).-
classmethod
from_config(config, **kwargs)ΒΆ Instantiates one of the model classes of the library (with a causal language modeling head) from a configuration.
Note
Loading a model from its configuration file does not load the model weights. It only affects the modelβs configuration. Use
from_pretrained()to load the model weights.- Parameters
config (
PretrainedConfig) βThe model class to instantiate is selected based on the configuration class:
GPT2Configconfiguration class:FlaxGPT2LMHeadModel(OpenAI GPT-2 model)GPTNeoConfigconfiguration class:FlaxGPTNeoForCausalLM(GPT Neo model)
Examples:
>>> from transformers import AutoConfig, FlaxAutoModelForCausalLM >>> # Download configuration from huggingface.co and cache. >>> config = AutoConfig.from_pretrained('bert-base-cased') >>> model = FlaxAutoModelForCausalLM.from_config(config)
-
classmethod
from_pretrained(pretrained_model_name_or_path, *model_args, **kwargs)ΒΆ Instantiate one of the model classes of the library (with a causal language modeling head) from a pretrained model.
The model class to instantiate is selected based on the
model_typeproperty of the config object (either passed as an argument or loaded frompretrained_model_name_or_pathif possible), or when itβs missing, by falling back to using pattern matching onpretrained_model_name_or_path:gpt2 β
FlaxGPT2LMHeadModel(OpenAI GPT-2 model)gpt_neo β
FlaxGPTNeoForCausalLM(GPT Neo model)
- Parameters
pretrained_model_name_or_path (
stroros.PathLike) βCan be either:
A string, the model id of a pretrained model hosted inside a model repo on huggingface.co. Valid model ids can be located at the root-level, like
bert-base-uncased, or namespaced under a user or organization name, likedbmdz/bert-base-german-cased.A path to a directory containing model weights saved using
save_pretrained(), e.g.,./my_model_directory/.A path or url to a PyTorch state_dict save file (e.g,
./pt_model/pytorch_model.bin). In this case,from_ptshould be set toTrueand a configuration object should be provided asconfigargument. This loading path is slower than converting the PyTorch model in a TensorFlow model using the provided conversion scripts and loading the TensorFlow model afterwards.
model_args (additional positional arguments, optional) β Will be passed along to the underlying model
__init__()method.config (
PretrainedConfig, optional) βConfiguration for the model to use instead of an automatically loaded configuration. Configuration can be automatically loaded when:
The model is a model provided by the library (loaded with the model id string of a pretrained model).
The model was saved using
save_pretrained()and is reloaded by supplying the save directory.The model is loaded by supplying a local directory as
pretrained_model_name_or_pathand a configuration JSON file named config.json is found in the directory.
cache_dir (
stroros.PathLike, optional) β Path to a directory in which a downloaded pretrained model configuration should be cached if the standard cache should not be used.from_pt (
bool, optional, defaults toFalse) β Load the model weights from a PyTorch checkpoint save file (see docstring ofpretrained_model_name_or_pathargument).force_download (
bool, optional, defaults toFalse) β Whether or not to force the (re-)download of the model weights and configuration files, overriding the cached versions if they exist.resume_download (
bool, optional, defaults toFalse) β Whether or not to delete incompletely received files. Will attempt to resume the download if such a file exists.proxies (
Dict[str, str], `optional) β A dictionary of proxy servers to use by protocol or endpoint, e.g.,{'http': 'foo.bar:3128', 'http://hostname': 'foo.bar:4012'}. The proxies are used on each request.output_loading_info (
bool, optional, defaults toFalse) β Whether ot not to also return a dictionary containing missing keys, unexpected keys and error messages.local_files_only (
bool, optional, defaults toFalse) β Whether or not to only look at local files (e.g., not try downloading the model).revision (
str, optional, defaults to"main") β The specific model version to use. It can be a branch name, a tag name, or a commit id, since we use a git-based system for storing models and other artifacts on huggingface.co, sorevisioncan be any identifier allowed by git.kwargs (additional keyword arguments, optional) β
Can be used to update the configuration object (after it being loaded) and initiate the model (e.g.,
output_attentions=True). Behaves differently depending on whether aconfigis provided or automatically loaded:If a configuration is provided with
config,**kwargswill be directly passed to the underlying modelβs__init__method (we assume all relevant updates to the configuration have already been done)If a configuration is not provided,
kwargswill be first passed to the configuration class initialization function (from_pretrained()). Each key ofkwargsthat corresponds to a configuration attribute will be used to override said attribute with the suppliedkwargsvalue. Remaining keys that do not correspond to any configuration attribute will be passed to the underlying modelβs__init__function.
Examples:
>>> from transformers import AutoConfig, FlaxAutoModelForCausalLM >>> # Download model and configuration from huggingface.co and cache. >>> model = FlaxAutoModelForCausalLM.from_pretrained('bert-base-cased') >>> # Update configuration during loading >>> model = FlaxAutoModelForCausalLM.from_pretrained('bert-base-cased', output_attentions=True) >>> model.config.output_attentions True >>> # Loading from a PyTorch checkpoint file instead of a TensorFlow model (slower) >>> config = AutoConfig.from_pretrained('./pt_model/bert_pt_model_config.json') >>> model = FlaxAutoModelForCausalLM.from_pretrained('./pt_model/bert_pytorch_model.bin', from_pt=True, config=config)
-
classmethod
FlaxAutoModelForPreTrainingΒΆ
-
class
transformers.FlaxAutoModelForPreTraining(*args, **kwargs)[source]ΒΆ This is a generic model class that will be instantiated as one of the model classes of the library (with a pretraining head) when created with the
from_pretrained()class method or thefrom_config()class method.This class cannot be instantiated directly using
__init__()(throws an error).-
classmethod
from_config(config, **kwargs)ΒΆ Instantiates one of the model classes of the library (with a pretraining head) from a configuration.
Note
Loading a model from its configuration file does not load the model weights. It only affects the modelβs configuration. Use
from_pretrained()to load the model weights.- Parameters
config (
PretrainedConfig) βThe model class to instantiate is selected based on the configuration class:
BartConfigconfiguration class:FlaxBartForConditionalGeneration(BART model)BertConfigconfiguration class:FlaxBertForPreTraining(BERT model)BigBirdConfigconfiguration class:FlaxBigBirdForPreTraining(BigBird model)ElectraConfigconfiguration class:FlaxElectraForPreTraining(ELECTRA model)MBartConfigconfiguration class:FlaxMBartForConditionalGeneration(mBART model)MT5Configconfiguration class:FlaxT5ForConditionalGeneration(mT5 model)RobertaConfigconfiguration class:FlaxRobertaForMaskedLM(RoBERTa model)T5Configconfiguration class:FlaxT5ForConditionalGeneration(T5 model)Wav2Vec2Configconfiguration class:FlaxWav2Vec2ForPreTraining(Wav2Vec2 model)
Examples:
>>> from transformers import AutoConfig, FlaxAutoModelForPreTraining >>> # Download configuration from huggingface.co and cache. >>> config = AutoConfig.from_pretrained('bert-base-cased') >>> model = FlaxAutoModelForPreTraining.from_config(config)
-
classmethod
from_pretrained(pretrained_model_name_or_path, *model_args, **kwargs)ΒΆ Instantiate one of the model classes of the library (with a pretraining head) from a pretrained model.
The model class to instantiate is selected based on the
model_typeproperty of the config object (either passed as an argument or loaded frompretrained_model_name_or_pathif possible), or when itβs missing, by falling back to using pattern matching onpretrained_model_name_or_path:bart β
FlaxBartForConditionalGeneration(BART model)bert β
FlaxBertForPreTraining(BERT model)big_bird β
FlaxBigBirdForPreTraining(BigBird model)electra β
FlaxElectraForPreTraining(ELECTRA model)mbart β
FlaxMBartForConditionalGeneration(mBART model)mt5 β
FlaxT5ForConditionalGeneration(mT5 model)roberta β
FlaxRobertaForMaskedLM(RoBERTa model)t5 β
FlaxT5ForConditionalGeneration(T5 model)wav2vec2 β
FlaxWav2Vec2ForPreTraining(Wav2Vec2 model)
- Parameters
pretrained_model_name_or_path (
stroros.PathLike) βCan be either:
A string, the model id of a pretrained model hosted inside a model repo on huggingface.co. Valid model ids can be located at the root-level, like
bert-base-uncased, or namespaced under a user or organization name, likedbmdz/bert-base-german-cased.A path to a directory containing model weights saved using
save_pretrained(), e.g.,./my_model_directory/.A path or url to a PyTorch state_dict save file (e.g,
./pt_model/pytorch_model.bin). In this case,from_ptshould be set toTrueand a configuration object should be provided asconfigargument. This loading path is slower than converting the PyTorch model in a TensorFlow model using the provided conversion scripts and loading the TensorFlow model afterwards.
model_args (additional positional arguments, optional) β Will be passed along to the underlying model
__init__()method.config (
PretrainedConfig, optional) βConfiguration for the model to use instead of an automatically loaded configuration. Configuration can be automatically loaded when:
The model is a model provided by the library (loaded with the model id string of a pretrained model).
The model was saved using
save_pretrained()and is reloaded by supplying the save directory.The model is loaded by supplying a local directory as
pretrained_model_name_or_pathand a configuration JSON file named config.json is found in the directory.
cache_dir (
stroros.PathLike, optional) β Path to a directory in which a downloaded pretrained model configuration should be cached if the standard cache should not be used.from_pt (
bool, optional, defaults toFalse) β Load the model weights from a PyTorch checkpoint save file (see docstring ofpretrained_model_name_or_pathargument).force_download (
bool, optional, defaults toFalse) β Whether or not to force the (re-)download of the model weights and configuration files, overriding the cached versions if they exist.resume_download (
bool, optional, defaults toFalse) β Whether or not to delete incompletely received files. Will attempt to resume the download if such a file exists.proxies (
Dict[str, str], `optional) β A dictionary of proxy servers to use by protocol or endpoint, e.g.,{'http': 'foo.bar:3128', 'http://hostname': 'foo.bar:4012'}. The proxies are used on each request.output_loading_info (
bool, optional, defaults toFalse) β Whether ot not to also return a dictionary containing missing keys, unexpected keys and error messages.local_files_only (
bool, optional, defaults toFalse) β Whether or not to only look at local files (e.g., not try downloading the model).revision (
str, optional, defaults to"main") β The specific model version to use. It can be a branch name, a tag name, or a commit id, since we use a git-based system for storing models and other artifacts on huggingface.co, sorevisioncan be any identifier allowed by git.kwargs (additional keyword arguments, optional) β
Can be used to update the configuration object (after it being loaded) and initiate the model (e.g.,
output_attentions=True). Behaves differently depending on whether aconfigis provided or automatically loaded:If a configuration is provided with
config,**kwargswill be directly passed to the underlying modelβs__init__method (we assume all relevant updates to the configuration have already been done)If a configuration is not provided,
kwargswill be first passed to the configuration class initialization function (from_pretrained()). Each key ofkwargsthat corresponds to a configuration attribute will be used to override said attribute with the suppliedkwargsvalue. Remaining keys that do not correspond to any configuration attribute will be passed to the underlying modelβs__init__function.
Examples:
>>> from transformers import AutoConfig, FlaxAutoModelForPreTraining >>> # Download model and configuration from huggingface.co and cache. >>> model = FlaxAutoModelForPreTraining.from_pretrained('bert-base-cased') >>> # Update configuration during loading >>> model = FlaxAutoModelForPreTraining.from_pretrained('bert-base-cased', output_attentions=True) >>> model.config.output_attentions True >>> # Loading from a PyTorch checkpoint file instead of a TensorFlow model (slower) >>> config = AutoConfig.from_pretrained('./pt_model/bert_pt_model_config.json') >>> model = FlaxAutoModelForPreTraining.from_pretrained('./pt_model/bert_pytorch_model.bin', from_pt=True, config=config)
-
classmethod
FlaxAutoModelForMaskedLMΒΆ
-
class
transformers.FlaxAutoModelForMaskedLM(*args, **kwargs)[source]ΒΆ This is a generic model class that will be instantiated as one of the model classes of the library (with a masked language modeling head) when created with the
from_pretrained()class method or thefrom_config()class method.This class cannot be instantiated directly using
__init__()(throws an error).-
classmethod
from_config(config, **kwargs)ΒΆ Instantiates one of the model classes of the library (with a masked language modeling head) from a configuration.
Note
Loading a model from its configuration file does not load the model weights. It only affects the modelβs configuration. Use
from_pretrained()to load the model weights.- Parameters
config (
PretrainedConfig) βThe model class to instantiate is selected based on the configuration class:
BartConfigconfiguration class:FlaxBartForConditionalGeneration(BART model)BertConfigconfiguration class:FlaxBertForMaskedLM(BERT model)BigBirdConfigconfiguration class:FlaxBigBirdForMaskedLM(BigBird model)ElectraConfigconfiguration class:FlaxElectraForMaskedLM(ELECTRA model)MBartConfigconfiguration class:FlaxMBartForConditionalGeneration(mBART model)RobertaConfigconfiguration class:FlaxRobertaForMaskedLM(RoBERTa model)
Examples:
>>> from transformers import AutoConfig, FlaxAutoModelForMaskedLM >>> # Download configuration from huggingface.co and cache. >>> config = AutoConfig.from_pretrained('bert-base-cased') >>> model = FlaxAutoModelForMaskedLM.from_config(config)
-
classmethod
from_pretrained(pretrained_model_name_or_path, *model_args, **kwargs)ΒΆ Instantiate one of the model classes of the library (with a masked language modeling head) from a pretrained model.
The model class to instantiate is selected based on the
model_typeproperty of the config object (either passed as an argument or loaded frompretrained_model_name_or_pathif possible), or when itβs missing, by falling back to using pattern matching onpretrained_model_name_or_path:bart β
FlaxBartForConditionalGeneration(BART model)bert β
FlaxBertForMaskedLM(BERT model)big_bird β
FlaxBigBirdForMaskedLM(BigBird model)electra β
FlaxElectraForMaskedLM(ELECTRA model)mbart β
FlaxMBartForConditionalGeneration(mBART model)roberta β
FlaxRobertaForMaskedLM(RoBERTa model)
- Parameters
pretrained_model_name_or_path (
stroros.PathLike) βCan be either:
A string, the model id of a pretrained model hosted inside a model repo on huggingface.co. Valid model ids can be located at the root-level, like
bert-base-uncased, or namespaced under a user or organization name, likedbmdz/bert-base-german-cased.A path to a directory containing model weights saved using
save_pretrained(), e.g.,./my_model_directory/.A path or url to a PyTorch state_dict save file (e.g,
./pt_model/pytorch_model.bin). In this case,from_ptshould be set toTrueand a configuration object should be provided asconfigargument. This loading path is slower than converting the PyTorch model in a TensorFlow model using the provided conversion scripts and loading the TensorFlow model afterwards.
model_args (additional positional arguments, optional) β Will be passed along to the underlying model
__init__()method.config (
PretrainedConfig, optional) βConfiguration for the model to use instead of an automatically loaded configuration. Configuration can be automatically loaded when:
The model is a model provided by the library (loaded with the model id string of a pretrained model).
The model was saved using
save_pretrained()and is reloaded by supplying the save directory.The model is loaded by supplying a local directory as
pretrained_model_name_or_pathand a configuration JSON file named config.json is found in the directory.
cache_dir (
stroros.PathLike, optional) β Path to a directory in which a downloaded pretrained model configuration should be cached if the standard cache should not be used.from_pt (
bool, optional, defaults toFalse) β Load the model weights from a PyTorch checkpoint save file (see docstring ofpretrained_model_name_or_pathargument).force_download (
bool, optional, defaults toFalse) β Whether or not to force the (re-)download of the model weights and configuration files, overriding the cached versions if they exist.resume_download (
bool, optional, defaults toFalse) β Whether or not to delete incompletely received files. Will attempt to resume the download if such a file exists.proxies (
Dict[str, str], `optional) β A dictionary of proxy servers to use by protocol or endpoint, e.g.,{'http': 'foo.bar:3128', 'http://hostname': 'foo.bar:4012'}. The proxies are used on each request.output_loading_info (
bool, optional, defaults toFalse) β Whether ot not to also return a dictionary containing missing keys, unexpected keys and error messages.local_files_only (
bool, optional, defaults toFalse) β Whether or not to only look at local files (e.g., not try downloading the model).revision (
str, optional, defaults to"main") β The specific model version to use. It can be a branch name, a tag name, or a commit id, since we use a git-based system for storing models and other artifacts on huggingface.co, sorevisioncan be any identifier allowed by git.kwargs (additional keyword arguments, optional) β
Can be used to update the configuration object (after it being loaded) and initiate the model (e.g.,
output_attentions=True). Behaves differently depending on whether aconfigis provided or automatically loaded:If a configuration is provided with
config,**kwargswill be directly passed to the underlying modelβs__init__method (we assume all relevant updates to the configuration have already been done)If a configuration is not provided,
kwargswill be first passed to the configuration class initialization function (from_pretrained()). Each key ofkwargsthat corresponds to a configuration attribute will be used to override said attribute with the suppliedkwargsvalue. Remaining keys that do not correspond to any configuration attribute will be passed to the underlying modelβs__init__function.
Examples:
>>> from transformers import AutoConfig, FlaxAutoModelForMaskedLM >>> # Download model and configuration from huggingface.co and cache. >>> model = FlaxAutoModelForMaskedLM.from_pretrained('bert-base-cased') >>> # Update configuration during loading >>> model = FlaxAutoModelForMaskedLM.from_pretrained('bert-base-cased', output_attentions=True) >>> model.config.output_attentions True >>> # Loading from a PyTorch checkpoint file instead of a TensorFlow model (slower) >>> config = AutoConfig.from_pretrained('./pt_model/bert_pt_model_config.json') >>> model = FlaxAutoModelForMaskedLM.from_pretrained('./pt_model/bert_pytorch_model.bin', from_pt=True, config=config)
-
classmethod
FlaxAutoModelForSeq2SeqLMΒΆ
-
class
transformers.FlaxAutoModelForSeq2SeqLM(*args, **kwargs)[source]ΒΆ This is a generic model class that will be instantiated as one of the model classes of the library (with a sequence-to-sequence language modeling head) when created with the
from_pretrained()class method or thefrom_config()class method.This class cannot be instantiated directly using
__init__()(throws an error).-
classmethod
from_config(config, **kwargs)ΒΆ Instantiates one of the model classes of the library (with a sequence-to-sequence language modeling head) from a configuration.
Note
Loading a model from its configuration file does not load the model weights. It only affects the modelβs configuration. Use
from_pretrained()to load the model weights.- Parameters
config (
PretrainedConfig) βThe model class to instantiate is selected based on the configuration class:
BartConfigconfiguration class:FlaxBartForConditionalGeneration(BART model)MT5Configconfiguration class:FlaxT5ForConditionalGeneration(mT5 model)MarianConfigconfiguration class:FlaxMarianMTModel(Marian model)T5Configconfiguration class:FlaxT5ForConditionalGeneration(T5 model)
Examples:
>>> from transformers import AutoConfig, FlaxAutoModelForSeq2SeqLM >>> # Download configuration from huggingface.co and cache. >>> config = AutoConfig.from_pretrained('t5-base') >>> model = FlaxAutoModelForSeq2SeqLM.from_config(config)
-
classmethod
from_pretrained(pretrained_model_name_or_path, *model_args, **kwargs)ΒΆ Instantiate one of the model classes of the library (with a sequence-to-sequence language modeling head) from a pretrained model.
The model class to instantiate is selected based on the
model_typeproperty of the config object (either passed as an argument or loaded frompretrained_model_name_or_pathif possible), or when itβs missing, by falling back to using pattern matching onpretrained_model_name_or_path:bart β
FlaxBartForConditionalGeneration(BART model)marian β
FlaxMarianMTModel(Marian model)mt5 β
FlaxT5ForConditionalGeneration(mT5 model)t5 β
FlaxT5ForConditionalGeneration(T5 model)
- Parameters
pretrained_model_name_or_path (
stroros.PathLike) βCan be either:
A string, the model id of a pretrained model hosted inside a model repo on huggingface.co. Valid model ids can be located at the root-level, like
bert-base-uncased, or namespaced under a user or organization name, likedbmdz/bert-base-german-cased.A path to a directory containing model weights saved using
save_pretrained(), e.g.,./my_model_directory/.A path or url to a PyTorch state_dict save file (e.g,
./pt_model/pytorch_model.bin). In this case,from_ptshould be set toTrueand a configuration object should be provided asconfigargument. This loading path is slower than converting the PyTorch model in a TensorFlow model using the provided conversion scripts and loading the TensorFlow model afterwards.
model_args (additional positional arguments, optional) β Will be passed along to the underlying model
__init__()method.config (
PretrainedConfig, optional) βConfiguration for the model to use instead of an automatically loaded configuration. Configuration can be automatically loaded when:
The model is a model provided by the library (loaded with the model id string of a pretrained model).
The model was saved using
save_pretrained()and is reloaded by supplying the save directory.The model is loaded by supplying a local directory as
pretrained_model_name_or_pathand a configuration JSON file named config.json is found in the directory.
cache_dir (
stroros.PathLike, optional) β Path to a directory in which a downloaded pretrained model configuration should be cached if the standard cache should not be used.from_pt (
bool, optional, defaults toFalse) β Load the model weights from a PyTorch checkpoint save file (see docstring ofpretrained_model_name_or_pathargument).force_download (
bool, optional, defaults toFalse) β Whether or not to force the (re-)download of the model weights and configuration files, overriding the cached versions if they exist.resume_download (
bool, optional, defaults toFalse) β Whether or not to delete incompletely received files. Will attempt to resume the download if such a file exists.proxies (
Dict[str, str], `optional) β A dictionary of proxy servers to use by protocol or endpoint, e.g.,{'http': 'foo.bar:3128', 'http://hostname': 'foo.bar:4012'}. The proxies are used on each request.output_loading_info (
bool, optional, defaults toFalse) β Whether ot not to also return a dictionary containing missing keys, unexpected keys and error messages.local_files_only (
bool, optional, defaults toFalse) β Whether or not to only look at local files (e.g., not try downloading the model).revision (
str, optional, defaults to"main") β The specific model version to use. It can be a branch name, a tag name, or a commit id, since we use a git-based system for storing models and other artifacts on huggingface.co, sorevisioncan be any identifier allowed by git.kwargs (additional keyword arguments, optional) β
Can be used to update the configuration object (after it being loaded) and initiate the model (e.g.,
output_attentions=True). Behaves differently depending on whether aconfigis provided or automatically loaded:If a configuration is provided with
config,**kwargswill be directly passed to the underlying modelβs__init__method (we assume all relevant updates to the configuration have already been done)If a configuration is not provided,
kwargswill be first passed to the configuration class initialization function (from_pretrained()). Each key ofkwargsthat corresponds to a configuration attribute will be used to override said attribute with the suppliedkwargsvalue. Remaining keys that do not correspond to any configuration attribute will be passed to the underlying modelβs__init__function.
Examples:
>>> from transformers import AutoConfig, FlaxAutoModelForSeq2SeqLM >>> # Download model and configuration from huggingface.co and cache. >>> model = FlaxAutoModelForSeq2SeqLM.from_pretrained('t5-base') >>> # Update configuration during loading >>> model = FlaxAutoModelForSeq2SeqLM.from_pretrained('t5-base', output_attentions=True) >>> model.config.output_attentions True >>> # Loading from a PyTorch checkpoint file instead of a TensorFlow model (slower) >>> config = AutoConfig.from_pretrained('./pt_model/t5_pt_model_config.json') >>> model = FlaxAutoModelForSeq2SeqLM.from_pretrained('./pt_model/t5_pytorch_model.bin', from_pt=True, config=config)
-
classmethod
FlaxAutoModelForSequenceClassificationΒΆ
-
class
transformers.FlaxAutoModelForSequenceClassification(*args, **kwargs)[source]ΒΆ This is a generic model class that will be instantiated as one of the model classes of the library (with a sequence classification head) when created with the
from_pretrained()class method or thefrom_config()class method.This class cannot be instantiated directly using
__init__()(throws an error).-
classmethod
from_config(config, **kwargs)ΒΆ Instantiates one of the model classes of the library (with a sequence classification head) from a configuration.
Note
Loading a model from its configuration file does not load the model weights. It only affects the modelβs configuration. Use
from_pretrained()to load the model weights.- Parameters
config (
PretrainedConfig) βThe model class to instantiate is selected based on the configuration class:
BartConfigconfiguration class:FlaxBartForSequenceClassification(BART model)BertConfigconfiguration class:FlaxBertForSequenceClassification(BERT model)BigBirdConfigconfiguration class:FlaxBigBirdForSequenceClassification(BigBird model)ElectraConfigconfiguration class:FlaxElectraForSequenceClassification(ELECTRA model)MBartConfigconfiguration class:FlaxMBartForSequenceClassification(mBART model)RobertaConfigconfiguration class:FlaxRobertaForSequenceClassification(RoBERTa model)
Examples:
>>> from transformers import AutoConfig, FlaxAutoModelForSequenceClassification >>> # Download configuration from huggingface.co and cache. >>> config = AutoConfig.from_pretrained('bert-base-cased') >>> model = FlaxAutoModelForSequenceClassification.from_config(config)
-
classmethod
from_pretrained(pretrained_model_name_or_path, *model_args, **kwargs)ΒΆ Instantiate one of the model classes of the library (with a sequence classification head) from a pretrained model.
The model class to instantiate is selected based on the
model_typeproperty of the config object (either passed as an argument or loaded frompretrained_model_name_or_pathif possible), or when itβs missing, by falling back to using pattern matching onpretrained_model_name_or_path:bart β
FlaxBartForSequenceClassification(BART model)bert β
FlaxBertForSequenceClassification(BERT model)big_bird β
FlaxBigBirdForSequenceClassification(BigBird model)electra β
FlaxElectraForSequenceClassification(ELECTRA model)mbart β
FlaxMBartForSequenceClassification(mBART model)roberta β
FlaxRobertaForSequenceClassification(RoBERTa model)
- Parameters
pretrained_model_name_or_path (
stroros.PathLike) βCan be either:
A string, the model id of a pretrained model hosted inside a model repo on huggingface.co. Valid model ids can be located at the root-level, like
bert-base-uncased, or namespaced under a user or organization name, likedbmdz/bert-base-german-cased.A path to a directory containing model weights saved using
save_pretrained(), e.g.,./my_model_directory/.A path or url to a PyTorch state_dict save file (e.g,
./pt_model/pytorch_model.bin). In this case,from_ptshould be set toTrueand a configuration object should be provided asconfigargument. This loading path is slower than converting the PyTorch model in a TensorFlow model using the provided conversion scripts and loading the TensorFlow model afterwards.
model_args (additional positional arguments, optional) β Will be passed along to the underlying model
__init__()method.config (
PretrainedConfig, optional) βConfiguration for the model to use instead of an automatically loaded configuration. Configuration can be automatically loaded when:
The model is a model provided by the library (loaded with the model id string of a pretrained model).
The model was saved using
save_pretrained()and is reloaded by supplying the save directory.The model is loaded by supplying a local directory as
pretrained_model_name_or_pathand a configuration JSON file named config.json is found in the directory.
cache_dir (
stroros.PathLike, optional) β Path to a directory in which a downloaded pretrained model configuration should be cached if the standard cache should not be used.from_pt (
bool, optional, defaults toFalse) β Load the model weights from a PyTorch checkpoint save file (see docstring ofpretrained_model_name_or_pathargument).force_download (
bool, optional, defaults toFalse) β Whether or not to force the (re-)download of the model weights and configuration files, overriding the cached versions if they exist.resume_download (
bool, optional, defaults toFalse) β Whether or not to delete incompletely received files. Will attempt to resume the download if such a file exists.proxies (
Dict[str, str], `optional) β A dictionary of proxy servers to use by protocol or endpoint, e.g.,{'http': 'foo.bar:3128', 'http://hostname': 'foo.bar:4012'}. The proxies are used on each request.output_loading_info (
bool, optional, defaults toFalse) β Whether ot not to also return a dictionary containing missing keys, unexpected keys and error messages.local_files_only (
bool, optional, defaults toFalse) β Whether or not to only look at local files (e.g., not try downloading the model).revision (
str, optional, defaults to"main") β The specific model version to use. It can be a branch name, a tag name, or a commit id, since we use a git-based system for storing models and other artifacts on huggingface.co, sorevisioncan be any identifier allowed by git.kwargs (additional keyword arguments, optional) β
Can be used to update the configuration object (after it being loaded) and initiate the model (e.g.,
output_attentions=True). Behaves differently depending on whether aconfigis provided or automatically loaded:If a configuration is provided with
config,**kwargswill be directly passed to the underlying modelβs__init__method (we assume all relevant updates to the configuration have already been done)If a configuration is not provided,
kwargswill be first passed to the configuration class initialization function (from_pretrained()). Each key ofkwargsthat corresponds to a configuration attribute will be used to override said attribute with the suppliedkwargsvalue. Remaining keys that do not correspond to any configuration attribute will be passed to the underlying modelβs__init__function.
Examples:
>>> from transformers import AutoConfig, FlaxAutoModelForSequenceClassification >>> # Download model and configuration from huggingface.co and cache. >>> model = FlaxAutoModelForSequenceClassification.from_pretrained('bert-base-cased') >>> # Update configuration during loading >>> model = FlaxAutoModelForSequenceClassification.from_pretrained('bert-base-cased', output_attentions=True) >>> model.config.output_attentions True >>> # Loading from a PyTorch checkpoint file instead of a TensorFlow model (slower) >>> config = AutoConfig.from_pretrained('./pt_model/bert_pt_model_config.json') >>> model = FlaxAutoModelForSequenceClassification.from_pretrained('./pt_model/bert_pytorch_model.bin', from_pt=True, config=config)
-
classmethod
FlaxAutoModelForQuestionAnsweringΒΆ
-
class
transformers.FlaxAutoModelForQuestionAnswering(*args, **kwargs)[source]ΒΆ This is a generic model class that will be instantiated as one of the model classes of the library (with a question answering head) when created with the
from_pretrained()class method or thefrom_config()class method.This class cannot be instantiated directly using
__init__()(throws an error).-
classmethod
from_config(config, **kwargs)ΒΆ Instantiates one of the model classes of the library (with a question answering head) from a configuration.
Note
Loading a model from its configuration file does not load the model weights. It only affects the modelβs configuration. Use
from_pretrained()to load the model weights.- Parameters
config (
PretrainedConfig) βThe model class to instantiate is selected based on the configuration class:
BartConfigconfiguration class:FlaxBartForQuestionAnswering(BART model)BertConfigconfiguration class:FlaxBertForQuestionAnswering(BERT model)BigBirdConfigconfiguration class:FlaxBigBirdForQuestionAnswering(BigBird model)ElectraConfigconfiguration class:FlaxElectraForQuestionAnswering(ELECTRA model)MBartConfigconfiguration class:FlaxMBartForQuestionAnswering(mBART model)RobertaConfigconfiguration class:FlaxRobertaForQuestionAnswering(RoBERTa model)
Examples:
>>> from transformers import AutoConfig, FlaxAutoModelForQuestionAnswering >>> # Download configuration from huggingface.co and cache. >>> config = AutoConfig.from_pretrained('bert-base-cased') >>> model = FlaxAutoModelForQuestionAnswering.from_config(config)
-
classmethod
from_pretrained(pretrained_model_name_or_path, *model_args, **kwargs)ΒΆ Instantiate one of the model classes of the library (with a question answering head) from a pretrained model.
The model class to instantiate is selected based on the
model_typeproperty of the config object (either passed as an argument or loaded frompretrained_model_name_or_pathif possible), or when itβs missing, by falling back to using pattern matching onpretrained_model_name_or_path:bart β
FlaxBartForQuestionAnswering(BART model)bert β
FlaxBertForQuestionAnswering(BERT model)big_bird β
FlaxBigBirdForQuestionAnswering(BigBird model)electra β
FlaxElectraForQuestionAnswering(ELECTRA model)mbart β
FlaxMBartForQuestionAnswering(mBART model)roberta β
FlaxRobertaForQuestionAnswering(RoBERTa model)
- Parameters
pretrained_model_name_or_path (
stroros.PathLike) βCan be either:
A string, the model id of a pretrained model hosted inside a model repo on huggingface.co. Valid model ids can be located at the root-level, like
bert-base-uncased, or namespaced under a user or organization name, likedbmdz/bert-base-german-cased.A path to a directory containing model weights saved using
save_pretrained(), e.g.,./my_model_directory/.A path or url to a PyTorch state_dict save file (e.g,
./pt_model/pytorch_model.bin). In this case,from_ptshould be set toTrueand a configuration object should be provided asconfigargument. This loading path is slower than converting the PyTorch model in a TensorFlow model using the provided conversion scripts and loading the TensorFlow model afterwards.
model_args (additional positional arguments, optional) β Will be passed along to the underlying model
__init__()method.config (
PretrainedConfig, optional) βConfiguration for the model to use instead of an automatically loaded configuration. Configuration can be automatically loaded when:
The model is a model provided by the library (loaded with the model id string of a pretrained model).
The model was saved using
save_pretrained()and is reloaded by supplying the save directory.The model is loaded by supplying a local directory as
pretrained_model_name_or_pathand a configuration JSON file named config.json is found in the directory.
cache_dir (
stroros.PathLike, optional) β Path to a directory in which a downloaded pretrained model configuration should be cached if the standard cache should not be used.from_pt (
bool, optional, defaults toFalse) β Load the model weights from a PyTorch checkpoint save file (see docstring ofpretrained_model_name_or_pathargument).force_download (
bool, optional, defaults toFalse) β Whether or not to force the (re-)download of the model weights and configuration files, overriding the cached versions if they exist.resume_download (
bool, optional, defaults toFalse) β Whether or not to delete incompletely received files. Will attempt to resume the download if such a file exists.proxies (
Dict[str, str], `optional) β A dictionary of proxy servers to use by protocol or endpoint, e.g.,{'http': 'foo.bar:3128', 'http://hostname': 'foo.bar:4012'}. The proxies are used on each request.output_loading_info (
bool, optional, defaults toFalse) β Whether ot not to also return a dictionary containing missing keys, unexpected keys and error messages.local_files_only (
bool, optional, defaults toFalse) β Whether or not to only look at local files (e.g., not try downloading the model).revision (
str, optional, defaults to"main") β The specific model version to use. It can be a branch name, a tag name, or a commit id, since we use a git-based system for storing models and other artifacts on huggingface.co, sorevisioncan be any identifier allowed by git.kwargs (additional keyword arguments, optional) β
Can be used to update the configuration object (after it being loaded) and initiate the model (e.g.,
output_attentions=True). Behaves differently depending on whether aconfigis provided or automatically loaded:If a configuration is provided with
config,**kwargswill be directly passed to the underlying modelβs__init__method (we assume all relevant updates to the configuration have already been done)If a configuration is not provided,
kwargswill be first passed to the configuration class initialization function (from_pretrained()). Each key ofkwargsthat corresponds to a configuration attribute will be used to override said attribute with the suppliedkwargsvalue. Remaining keys that do not correspond to any configuration attribute will be passed to the underlying modelβs__init__function.
Examples:
>>> from transformers import AutoConfig, FlaxAutoModelForQuestionAnswering >>> # Download model and configuration from huggingface.co and cache. >>> model = FlaxAutoModelForQuestionAnswering.from_pretrained('bert-base-cased') >>> # Update configuration during loading >>> model = FlaxAutoModelForQuestionAnswering.from_pretrained('bert-base-cased', output_attentions=True) >>> model.config.output_attentions True >>> # Loading from a PyTorch checkpoint file instead of a TensorFlow model (slower) >>> config = AutoConfig.from_pretrained('./pt_model/bert_pt_model_config.json') >>> model = FlaxAutoModelForQuestionAnswering.from_pretrained('./pt_model/bert_pytorch_model.bin', from_pt=True, config=config)
-
classmethod
FlaxAutoModelForTokenClassificationΒΆ
-
class
transformers.FlaxAutoModelForTokenClassification(*args, **kwargs)[source]ΒΆ This is a generic model class that will be instantiated as one of the model classes of the library (with a token classification head) when created with the
from_pretrained()class method or thefrom_config()class method.This class cannot be instantiated directly using
__init__()(throws an error).-
classmethod
from_config(config, **kwargs)ΒΆ Instantiates one of the model classes of the library (with a token classification head) from a configuration.
Note
Loading a model from its configuration file does not load the model weights. It only affects the modelβs configuration. Use
from_pretrained()to load the model weights.- Parameters
config (
PretrainedConfig) βThe model class to instantiate is selected based on the configuration class:
BertConfigconfiguration class:FlaxBertForTokenClassification(BERT model)BigBirdConfigconfiguration class:FlaxBigBirdForTokenClassification(BigBird model)ElectraConfigconfiguration class:FlaxElectraForTokenClassification(ELECTRA model)RobertaConfigconfiguration class:FlaxRobertaForTokenClassification(RoBERTa model)
Examples:
>>> from transformers import AutoConfig, FlaxAutoModelForTokenClassification >>> # Download configuration from huggingface.co and cache. >>> config = AutoConfig.from_pretrained('bert-base-cased') >>> model = FlaxAutoModelForTokenClassification.from_config(config)
-
classmethod
from_pretrained(pretrained_model_name_or_path, *model_args, **kwargs)ΒΆ Instantiate one of the model classes of the library (with a token classification head) from a pretrained model.
The model class to instantiate is selected based on the
model_typeproperty of the config object (either passed as an argument or loaded frompretrained_model_name_or_pathif possible), or when itβs missing, by falling back to using pattern matching onpretrained_model_name_or_path:bert β
FlaxBertForTokenClassification(BERT model)big_bird β
FlaxBigBirdForTokenClassification(BigBird model)electra β
FlaxElectraForTokenClassification(ELECTRA model)roberta β
FlaxRobertaForTokenClassification(RoBERTa model)
- Parameters
pretrained_model_name_or_path (
stroros.PathLike) βCan be either:
A string, the model id of a pretrained model hosted inside a model repo on huggingface.co. Valid model ids can be located at the root-level, like
bert-base-uncased, or namespaced under a user or organization name, likedbmdz/bert-base-german-cased.A path to a directory containing model weights saved using
save_pretrained(), e.g.,./my_model_directory/.A path or url to a PyTorch state_dict save file (e.g,
./pt_model/pytorch_model.bin). In this case,from_ptshould be set toTrueand a configuration object should be provided asconfigargument. This loading path is slower than converting the PyTorch model in a TensorFlow model using the provided conversion scripts and loading the TensorFlow model afterwards.
model_args (additional positional arguments, optional) β Will be passed along to the underlying model
__init__()method.config (
PretrainedConfig, optional) βConfiguration for the model to use instead of an automatically loaded configuration. Configuration can be automatically loaded when:
The model is a model provided by the library (loaded with the model id string of a pretrained model).
The model was saved using
save_pretrained()and is reloaded by supplying the save directory.The model is loaded by supplying a local directory as
pretrained_model_name_or_pathand a configuration JSON file named config.json is found in the directory.
cache_dir (
stroros.PathLike, optional) β Path to a directory in which a downloaded pretrained model configuration should be cached if the standard cache should not be used.from_pt (
bool, optional, defaults toFalse) β Load the model weights from a PyTorch checkpoint save file (see docstring ofpretrained_model_name_or_pathargument).force_download (
bool, optional, defaults toFalse) β Whether or not to force the (re-)download of the model weights and configuration files, overriding the cached versions if they exist.resume_download (
bool, optional, defaults toFalse) β Whether or not to delete incompletely received files. Will attempt to resume the download if such a file exists.proxies (
Dict[str, str], `optional) β A dictionary of proxy servers to use by protocol or endpoint, e.g.,{'http': 'foo.bar:3128', 'http://hostname': 'foo.bar:4012'}. The proxies are used on each request.output_loading_info (
bool, optional, defaults toFalse) β Whether ot not to also return a dictionary containing missing keys, unexpected keys and error messages.local_files_only (
bool, optional, defaults toFalse) β Whether or not to only look at local files (e.g., not try downloading the model).revision (
str, optional, defaults to"main") β The specific model version to use. It can be a branch name, a tag name, or a commit id, since we use a git-based system for storing models and other artifacts on huggingface.co, sorevisioncan be any identifier allowed by git.kwargs (additional keyword arguments, optional) β
Can be used to update the configuration object (after it being loaded) and initiate the model (e.g.,
output_attentions=True). Behaves differently depending on whether aconfigis provided or automatically loaded:If a configuration is provided with
config,**kwargswill be directly passed to the underlying modelβs__init__method (we assume all relevant updates to the configuration have already been done)If a configuration is not provided,
kwargswill be first passed to the configuration class initialization function (from_pretrained()). Each key ofkwargsthat corresponds to a configuration attribute will be used to override said attribute with the suppliedkwargsvalue. Remaining keys that do not correspond to any configuration attribute will be passed to the underlying modelβs__init__function.
Examples:
>>> from transformers import AutoConfig, FlaxAutoModelForTokenClassification >>> # Download model and configuration from huggingface.co and cache. >>> model = FlaxAutoModelForTokenClassification.from_pretrained('bert-base-cased') >>> # Update configuration during loading >>> model = FlaxAutoModelForTokenClassification.from_pretrained('bert-base-cased', output_attentions=True) >>> model.config.output_attentions True >>> # Loading from a PyTorch checkpoint file instead of a TensorFlow model (slower) >>> config = AutoConfig.from_pretrained('./pt_model/bert_pt_model_config.json') >>> model = FlaxAutoModelForTokenClassification.from_pretrained('./pt_model/bert_pytorch_model.bin', from_pt=True, config=config)
-
classmethod
FlaxAutoModelForMultipleChoiceΒΆ
-
class
transformers.FlaxAutoModelForMultipleChoice(*args, **kwargs)[source]ΒΆ This is a generic model class that will be instantiated as one of the model classes of the library (with a multiple choice head) when created with the
from_pretrained()class method or thefrom_config()class method.This class cannot be instantiated directly using
__init__()(throws an error).-
classmethod
from_config(config, **kwargs)ΒΆ Instantiates one of the model classes of the library (with a multiple choice head) from a configuration.
Note
Loading a model from its configuration file does not load the model weights. It only affects the modelβs configuration. Use
from_pretrained()to load the model weights.- Parameters
config (
PretrainedConfig) βThe model class to instantiate is selected based on the configuration class:
BertConfigconfiguration class:FlaxBertForMultipleChoice(BERT model)BigBirdConfigconfiguration class:FlaxBigBirdForMultipleChoice(BigBird model)ElectraConfigconfiguration class:FlaxElectraForMultipleChoice(ELECTRA model)RobertaConfigconfiguration class:FlaxRobertaForMultipleChoice(RoBERTa model)
Examples:
>>> from transformers import AutoConfig, FlaxAutoModelForMultipleChoice >>> # Download configuration from huggingface.co and cache. >>> config = AutoConfig.from_pretrained('bert-base-cased') >>> model = FlaxAutoModelForMultipleChoice.from_config(config)
-
classmethod
from_pretrained(pretrained_model_name_or_path, *model_args, **kwargs)ΒΆ Instantiate one of the model classes of the library (with a multiple choice head) from a pretrained model.
The model class to instantiate is selected based on the
model_typeproperty of the config object (either passed as an argument or loaded frompretrained_model_name_or_pathif possible), or when itβs missing, by falling back to using pattern matching onpretrained_model_name_or_path:bert β
FlaxBertForMultipleChoice(BERT model)big_bird β
FlaxBigBirdForMultipleChoice(BigBird model)electra β
FlaxElectraForMultipleChoice(ELECTRA model)roberta β
FlaxRobertaForMultipleChoice(RoBERTa model)
- Parameters
pretrained_model_name_or_path (
stroros.PathLike) βCan be either:
A string, the model id of a pretrained model hosted inside a model repo on huggingface.co. Valid model ids can be located at the root-level, like
bert-base-uncased, or namespaced under a user or organization name, likedbmdz/bert-base-german-cased.A path to a directory containing model weights saved using
save_pretrained(), e.g.,./my_model_directory/.A path or url to a PyTorch state_dict save file (e.g,
./pt_model/pytorch_model.bin). In this case,from_ptshould be set toTrueand a configuration object should be provided asconfigargument. This loading path is slower than converting the PyTorch model in a TensorFlow model using the provided conversion scripts and loading the TensorFlow model afterwards.
model_args (additional positional arguments, optional) β Will be passed along to the underlying model
__init__()method.config (
PretrainedConfig, optional) βConfiguration for the model to use instead of an automatically loaded configuration. Configuration can be automatically loaded when:
The model is a model provided by the library (loaded with the model id string of a pretrained model).
The model was saved using
save_pretrained()and is reloaded by supplying the save directory.The model is loaded by supplying a local directory as
pretrained_model_name_or_pathand a configuration JSON file named config.json is found in the directory.
cache_dir (
stroros.PathLike, optional) β Path to a directory in which a downloaded pretrained model configuration should be cached if the standard cache should not be used.from_pt (
bool, optional, defaults toFalse) β Load the model weights from a PyTorch checkpoint save file (see docstring ofpretrained_model_name_or_pathargument).force_download (
bool, optional, defaults toFalse) β Whether or not to force the (re-)download of the model weights and configuration files, overriding the cached versions if they exist.resume_download (
bool, optional, defaults toFalse) β Whether or not to delete incompletely received files. Will attempt to resume the download if such a file exists.proxies (
Dict[str, str], `optional) β A dictionary of proxy servers to use by protocol or endpoint, e.g.,{'http': 'foo.bar:3128', 'http://hostname': 'foo.bar:4012'}. The proxies are used on each request.output_loading_info (
bool, optional, defaults toFalse) β Whether ot not to also return a dictionary containing missing keys, unexpected keys and error messages.local_files_only (
bool, optional, defaults toFalse) β Whether or not to only look at local files (e.g., not try downloading the model).revision (
str, optional, defaults to"main") β The specific model version to use. It can be a branch name, a tag name, or a commit id, since we use a git-based system for storing models and other artifacts on huggingface.co, sorevisioncan be any identifier allowed by git.kwargs (additional keyword arguments, optional) β
Can be used to update the configuration object (after it being loaded) and initiate the model (e.g.,
output_attentions=True). Behaves differently depending on whether aconfigis provided or automatically loaded:If a configuration is provided with
config,**kwargswill be directly passed to the underlying modelβs__init__method (we assume all relevant updates to the configuration have already been done)If a configuration is not provided,
kwargswill be first passed to the configuration class initialization function (from_pretrained()). Each key ofkwargsthat corresponds to a configuration attribute will be used to override said attribute with the suppliedkwargsvalue. Remaining keys that do not correspond to any configuration attribute will be passed to the underlying modelβs__init__function.
Examples:
>>> from transformers import AutoConfig, FlaxAutoModelForMultipleChoice >>> # Download model and configuration from huggingface.co and cache. >>> model = FlaxAutoModelForMultipleChoice.from_pretrained('bert-base-cased') >>> # Update configuration during loading >>> model = FlaxAutoModelForMultipleChoice.from_pretrained('bert-base-cased', output_attentions=True) >>> model.config.output_attentions True >>> # Loading from a PyTorch checkpoint file instead of a TensorFlow model (slower) >>> config = AutoConfig.from_pretrained('./pt_model/bert_pt_model_config.json') >>> model = FlaxAutoModelForMultipleChoice.from_pretrained('./pt_model/bert_pytorch_model.bin', from_pt=True, config=config)
-
classmethod
FlaxAutoModelForNextSentencePredictionΒΆ
-
class
transformers.FlaxAutoModelForNextSentencePrediction(*args, **kwargs)[source]ΒΆ This is a generic model class that will be instantiated as one of the model classes of the library (with a next sentence prediction head) when created with the
from_pretrained()class method or thefrom_config()class method.This class cannot be instantiated directly using
__init__()(throws an error).-
classmethod
from_config(config, **kwargs)ΒΆ Instantiates one of the model classes of the library (with a next sentence prediction head) from a configuration.
Note
Loading a model from its configuration file does not load the model weights. It only affects the modelβs configuration. Use
from_pretrained()to load the model weights.- Parameters
config (
PretrainedConfig) βThe model class to instantiate is selected based on the configuration class:
BertConfigconfiguration class:FlaxBertForNextSentencePrediction(BERT model)
Examples:
>>> from transformers import AutoConfig, FlaxAutoModelForNextSentencePrediction >>> # Download configuration from huggingface.co and cache. >>> config = AutoConfig.from_pretrained('bert-base-cased') >>> model = FlaxAutoModelForNextSentencePrediction.from_config(config)
-
classmethod
from_pretrained(pretrained_model_name_or_path, *model_args, **kwargs)ΒΆ Instantiate one of the model classes of the library (with a next sentence prediction head) from a pretrained model.
The model class to instantiate is selected based on the
model_typeproperty of the config object (either passed as an argument or loaded frompretrained_model_name_or_pathif possible), or when itβs missing, by falling back to using pattern matching onpretrained_model_name_or_path:bert β
FlaxBertForNextSentencePrediction(BERT model)
- Parameters
pretrained_model_name_or_path (
stroros.PathLike) βCan be either:
A string, the model id of a pretrained model hosted inside a model repo on huggingface.co. Valid model ids can be located at the root-level, like
bert-base-uncased, or namespaced under a user or organization name, likedbmdz/bert-base-german-cased.A path to a directory containing model weights saved using
save_pretrained(), e.g.,./my_model_directory/.A path or url to a PyTorch state_dict save file (e.g,
./pt_model/pytorch_model.bin). In this case,from_ptshould be set toTrueand a configuration object should be provided asconfigargument. This loading path is slower than converting the PyTorch model in a TensorFlow model using the provided conversion scripts and loading the TensorFlow model afterwards.
model_args (additional positional arguments, optional) β Will be passed along to the underlying model
__init__()method.config (
PretrainedConfig, optional) βConfiguration for the model to use instead of an automatically loaded configuration. Configuration can be automatically loaded when:
The model is a model provided by the library (loaded with the model id string of a pretrained model).
The model was saved using
save_pretrained()and is reloaded by supplying the save directory.The model is loaded by supplying a local directory as
pretrained_model_name_or_pathand a configuration JSON file named config.json is found in the directory.
cache_dir (
stroros.PathLike, optional) β Path to a directory in which a downloaded pretrained model configuration should be cached if the standard cache should not be used.from_pt (
bool, optional, defaults toFalse) β Load the model weights from a PyTorch checkpoint save file (see docstring ofpretrained_model_name_or_pathargument).force_download (
bool, optional, defaults toFalse) β Whether or not to force the (re-)download of the model weights and configuration files, overriding the cached versions if they exist.resume_download (
bool, optional, defaults toFalse) β Whether or not to delete incompletely received files. Will attempt to resume the download if such a file exists.proxies (
Dict[str, str], `optional) β A dictionary of proxy servers to use by protocol or endpoint, e.g.,{'http': 'foo.bar:3128', 'http://hostname': 'foo.bar:4012'}. The proxies are used on each request.output_loading_info (
bool, optional, defaults toFalse) β Whether ot not to also return a dictionary containing missing keys, unexpected keys and error messages.local_files_only (
bool, optional, defaults toFalse) β Whether or not to only look at local files (e.g., not try downloading the model).revision (
str, optional, defaults to"main") β The specific model version to use. It can be a branch name, a tag name, or a commit id, since we use a git-based system for storing models and other artifacts on huggingface.co, sorevisioncan be any identifier allowed by git.kwargs (additional keyword arguments, optional) β
Can be used to update the configuration object (after it being loaded) and initiate the model (e.g.,
output_attentions=True). Behaves differently depending on whether aconfigis provided or automatically loaded:If a configuration is provided with
config,**kwargswill be directly passed to the underlying modelβs__init__method (we assume all relevant updates to the configuration have already been done)If a configuration is not provided,
kwargswill be first passed to the configuration class initialization function (from_pretrained()). Each key ofkwargsthat corresponds to a configuration attribute will be used to override said attribute with the suppliedkwargsvalue. Remaining keys that do not correspond to any configuration attribute will be passed to the underlying modelβs__init__function.
Examples:
>>> from transformers import AutoConfig, FlaxAutoModelForNextSentencePrediction >>> # Download model and configuration from huggingface.co and cache. >>> model = FlaxAutoModelForNextSentencePrediction.from_pretrained('bert-base-cased') >>> # Update configuration during loading >>> model = FlaxAutoModelForNextSentencePrediction.from_pretrained('bert-base-cased', output_attentions=True) >>> model.config.output_attentions True >>> # Loading from a PyTorch checkpoint file instead of a TensorFlow model (slower) >>> config = AutoConfig.from_pretrained('./pt_model/bert_pt_model_config.json') >>> model = FlaxAutoModelForNextSentencePrediction.from_pretrained('./pt_model/bert_pytorch_model.bin', from_pt=True, config=config)
-
classmethod
FlaxAutoModelForImageClassificationΒΆ
-
class
transformers.FlaxAutoModelForImageClassification(*args, **kwargs)[source]ΒΆ This is a generic model class that will be instantiated as one of the model classes of the library (with a image classification head) when created with the
from_pretrained()class method or thefrom_config()class method.This class cannot be instantiated directly using
__init__()(throws an error).-
classmethod
from_config(config, **kwargs)ΒΆ Instantiates one of the model classes of the library (with a image classification head) from a configuration.
Note
Loading a model from its configuration file does not load the model weights. It only affects the modelβs configuration. Use
from_pretrained()to load the model weights.- Parameters
config (
PretrainedConfig) βThe model class to instantiate is selected based on the configuration class:
ViTConfigconfiguration class:FlaxViTForImageClassification(ViT model)
Examples:
>>> from transformers import AutoConfig, FlaxAutoModelForImageClassification >>> # Download configuration from huggingface.co and cache. >>> config = AutoConfig.from_pretrained('bert-base-cased') >>> model = FlaxAutoModelForImageClassification.from_config(config)
-
classmethod
from_pretrained(pretrained_model_name_or_path, *model_args, **kwargs)ΒΆ Instantiate one of the model classes of the library (with a image classification head) from a pretrained model.
The model class to instantiate is selected based on the
model_typeproperty of the config object (either passed as an argument or loaded frompretrained_model_name_or_pathif possible), or when itβs missing, by falling back to using pattern matching onpretrained_model_name_or_path:vit β
FlaxViTForImageClassification(ViT model)
- Parameters
pretrained_model_name_or_path (
stroros.PathLike) βCan be either:
A string, the model id of a pretrained model hosted inside a model repo on huggingface.co. Valid model ids can be located at the root-level, like
bert-base-uncased, or namespaced under a user or organization name, likedbmdz/bert-base-german-cased.A path to a directory containing model weights saved using
save_pretrained(), e.g.,./my_model_directory/.A path or url to a PyTorch state_dict save file (e.g,
./pt_model/pytorch_model.bin). In this case,from_ptshould be set toTrueand a configuration object should be provided asconfigargument. This loading path is slower than converting the PyTorch model in a TensorFlow model using the provided conversion scripts and loading the TensorFlow model afterwards.
model_args (additional positional arguments, optional) β Will be passed along to the underlying model
__init__()method.config (
PretrainedConfig, optional) βConfiguration for the model to use instead of an automatically loaded configuration. Configuration can be automatically loaded when:
The model is a model provided by the library (loaded with the model id string of a pretrained model).
The model was saved using
save_pretrained()and is reloaded by supplying the save directory.The model is loaded by supplying a local directory as
pretrained_model_name_or_pathand a configuration JSON file named config.json is found in the directory.
cache_dir (
stroros.PathLike, optional) β Path to a directory in which a downloaded pretrained model configuration should be cached if the standard cache should not be used.from_pt (
bool, optional, defaults toFalse) β Load the model weights from a PyTorch checkpoint save file (see docstring ofpretrained_model_name_or_pathargument).force_download (
bool, optional, defaults toFalse) β Whether or not to force the (re-)download of the model weights and configuration files, overriding the cached versions if they exist.resume_download (
bool, optional, defaults toFalse) β Whether or not to delete incompletely received files. Will attempt to resume the download if such a file exists.proxies (
Dict[str, str], `optional) β A dictionary of proxy servers to use by protocol or endpoint, e.g.,{'http': 'foo.bar:3128', 'http://hostname': 'foo.bar:4012'}. The proxies are used on each request.output_loading_info (
bool, optional, defaults toFalse) β Whether ot not to also return a dictionary containing missing keys, unexpected keys and error messages.local_files_only (
bool, optional, defaults toFalse) β Whether or not to only look at local files (e.g., not try downloading the model).revision (
str, optional, defaults to"main") β The specific model version to use. It can be a branch name, a tag name, or a commit id, since we use a git-based system for storing models and other artifacts on huggingface.co, sorevisioncan be any identifier allowed by git.kwargs (additional keyword arguments, optional) β
Can be used to update the configuration object (after it being loaded) and initiate the model (e.g.,
output_attentions=True). Behaves differently depending on whether aconfigis provided or automatically loaded:If a configuration is provided with
config,**kwargswill be directly passed to the underlying modelβs__init__method (we assume all relevant updates to the configuration have already been done)If a configuration is not provided,
kwargswill be first passed to the configuration class initialization function (from_pretrained()). Each key ofkwargsthat corresponds to a configuration attribute will be used to override said attribute with the suppliedkwargsvalue. Remaining keys that do not correspond to any configuration attribute will be passed to the underlying modelβs__init__function.
Examples:
>>> from transformers import AutoConfig, FlaxAutoModelForImageClassification >>> # Download model and configuration from huggingface.co and cache. >>> model = FlaxAutoModelForImageClassification.from_pretrained('bert-base-cased') >>> # Update configuration during loading >>> model = FlaxAutoModelForImageClassification.from_pretrained('bert-base-cased', output_attentions=True) >>> model.config.output_attentions True >>> # Loading from a PyTorch checkpoint file instead of a TensorFlow model (slower) >>> config = AutoConfig.from_pretrained('./pt_model/bert_pt_model_config.json') >>> model = FlaxAutoModelForImageClassification.from_pretrained('./pt_model/bert_pytorch_model.bin', from_pt=True, config=config)
-
classmethod