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("google-bert/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, TensorFlow, or Flax).
Each of the auto classes has a method to be extended with your custom classes. For instance, if you have defined a custom class of model NewModel
, make sure you have a NewModelConfig
then you can add those to the auto classes like this:
from transformers import AutoConfig, AutoModel AutoConfig.register("new-model", NewModelConfig) AutoModel.register(NewModelConfig, NewModel)
You will then be able to use the auto classes like you would usually do!
If your NewModelConfig
is a subclass of PretrainedConfig, make sure its model_type
attribute is set to the same key you use when registering the config (here "new-model"
).
Likewise, if your NewModel
is a subclass of PreTrainedModel, make sure its config_class
attribute is set to the same class you use when registering the model (here NewModelConfig
).
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).
( pretrained_model_name_or_path **kwargs )
Parameters
str
or os.PathLike
) — Can be either:
./my_model_directory/
../my_model_directory/configuration.json
.str
or os.PathLike
, optional) — Path to a directory in which a downloaded pretrained model configuration should be cached if the standard cache should not be used. bool
, optional, defaults to False
) — Whether or not to force the (re-)download the model weights and configuration files and override the cached versions if they exist. 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. 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 revision
can be any identifier allowed by git. bool
, optional, defaults to False
) — If False
, then this function returns just the final configuration object.
If True
, then this functions returns a Tuple(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 of kwargs
which has not been used to update config
and is otherwise ignored.
bool
, optional, defaults to False
) — Whether or not to allow for custom models defined on the Hub in their own modeling files. This option should only be set to True
for repositories you trust and in which you have read the code, as it will execute code present on the Hub on your local machine. return_unused_kwargs
keyword parameter. 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_type
property of the config object that is loaded, or when it’s missing, by falling back to using pattern matching on pretrained_model_name_or_path
:
MaskFormerSwinConfig
(MaskFormerSwin model)VitPoseBackboneConfig
(ViTPoseBackbone model)Examples:
>>> from transformers import AutoConfig >>> >>> config = AutoConfig.from_pretrained("google-bert/bert-base-uncased") >>> >>> config = AutoConfig.from_pretrained("dbmdz/bert-base-german-cased") >>> >>> config = AutoConfig.from_pretrained("./test/bert_saved_model/") >>> >>> config = AutoConfig.from_pretrained("./test/bert_saved_model/my_configuration.json") >>> >>> config = AutoConfig.from_pretrained("google-bert/bert-base-uncased", output_attentions=True, foo=False) >>> config.output_attentions True >>> config, unused_kwargs = AutoConfig.from_pretrained( ... "google-bert/bert-base-uncased", output_attentions=True, foo=False, return_unused_kwargs=True ... ) >>> config.output_attentions True >>> unused_kwargs {'foo': False}register < source >
( model_type config exist_ok = False )
Parameters
str
) — The model type like “bert” or “gpt”. Register a new configuration for this class.
AutoTokenizerThis 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).
( pretrained_model_name_or_path *inputs **kwargs )
Parameters
str
or os.PathLike
) — Can be either:
./my_model_directory/
../my_model_directory/vocab.txt
. (Not applicable to all derived classes)__init__()
method. str
or os.PathLike
, optional) — Path to a directory in which a downloaded pretrained model configuration should be cached if the standard cache should not be used. bool
, optional, defaults to False
) — Whether or not to force the (re-)download the model weights and configuration files and override the cached versions if they exist. 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. 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 revision
can be any identifier allowed by git. 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. bool
, optional, defaults to True
) — Use a fast Rust-based tokenizer if it is supported for a given model. If a fast tokenizer is not available for a given model, a normal Python-based tokenizer is returned instead. str
, optional) — Tokenizer type to be loaded. bool
, optional, defaults to False
) — Whether or not to allow for custom models defined on the Hub in their own modeling files. This option should only be set to True
for repositories you trust and in which you have read the code, as it will execute code present on the Hub on your local machine. __init__()
method. Can be used to set special tokens like bos_token
, eos_token
, unk_token
, sep_token
, pad_token
, cls_token
, mask_token
, additional_special_tokens
. See parameters in the __init__()
for more details. 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_type
property of the config object (either passed as an argument or loaded from pretrained_model_name_or_path
if possible), or when it’s missing, by falling back to using pattern matching on pretrained_model_name_or_path
:
Examples:
>>> from transformers import AutoTokenizer >>> >>> tokenizer = AutoTokenizer.from_pretrained("google-bert/bert-base-uncased") >>> >>> tokenizer = AutoTokenizer.from_pretrained("dbmdz/bert-base-german-cased") >>> >>> >>> >>> tokenizer = AutoTokenizer.from_pretrained("FacebookAI/roberta-base", add_prefix_space=True)register < source >
( config_class slow_tokenizer_class = None fast_tokenizer_class = None exist_ok = False )
Parameters
PretrainedTokenizer
, optional) — The slow tokenizer to register. PretrainedTokenizerFast
, optional) — The fast tokenizer to register. Register a new tokenizer in this mapping.
AutoFeatureExtractorThis 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).
( pretrained_model_name_or_path **kwargs )
Parameters
str
or os.PathLike
) — This can be either:
./my_model_directory/
../my_model_directory/preprocessor_config.json
.str
or os.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. bool
, optional, defaults to False
) — Whether or not to force to (re-)download the feature extractor files and override the cached versions if they exist. 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. str
or bool, optional) — The token to use as HTTP bearer authorization for remote files. If True
, will use the token generated when running huggingface-cli login
(stored in ~/.huggingface
). 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 revision
can be any identifier allowed by git. bool
, optional, defaults to False
) — If False
, then this function returns just the final feature extractor object. If True
, then this functions returns a Tuple(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 of kwargs
which has not been used to update feature_extractor
and is otherwise ignored. bool
, optional, defaults to False
) — Whether or not to allow for custom models defined on the Hub in their own modeling files. This option should only be set to True
for repositories you trust and in which you have read the code, as it will execute code present on the Hub on your local machine. 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_kwargs
keyword parameter. Instantiate one of the feature extractor classes of the library from a pretrained model vocabulary.
The feature extractor class to instantiate is selected based on the model_type
property of the config object (either passed as an argument or loaded from pretrained_model_name_or_path
if possible), or when it’s missing, by falling back to using pattern matching on pretrained_model_name_or_path
:
OwlViTFeatureExtractor
(OWL-ViT model)Passing token=True
is required when you want to use a private model.
Examples:
>>> from transformers import AutoFeatureExtractor >>> >>> feature_extractor = AutoFeatureExtractor.from_pretrained("facebook/wav2vec2-base-960h") >>> >>>
( config_class feature_extractor_class exist_ok = False )
Parameters
FeatureExtractorMixin
) — The feature extractor to register. Register a new feature extractor for this class.
AutoImageProcessor class transformers.AutoImageProcessor < source >( )
This is a generic image processor class that will be instantiated as one of the image processor classes of the library when created with the AutoImageProcessor.from_pretrained() class method.
This class cannot be instantiated directly using __init__()
(throws an error).
( pretrained_model_name_or_path *inputs **kwargs )
Parameters
str
or os.PathLike
) — This can be either:
./my_model_directory/
../my_model_directory/preprocessor_config.json
.str
or os.PathLike
, optional) — Path to a directory in which a downloaded pretrained model image processor should be cached if the standard cache should not be used. bool
, optional, defaults to False
) — Whether or not to force to (re-)download the image processor files and override the cached versions if they exist. 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. str
or bool, optional) — The token to use as HTTP bearer authorization for remote files. If True
, will use the token generated when running huggingface-cli login
(stored in ~/.huggingface
). 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 revision
can be any identifier allowed by git. bool
, optional, defaults to False
) — Use a fast torchvision-base image processor if it is supported for a given model. If a fast image processor is not available for a given model, a normal numpy-based image processor is returned instead. bool
, optional, defaults to False
) — If False
, then this function returns just the final image processor object. If True
, then this functions returns a Tuple(image_processor, unused_kwargs)
where unused_kwargs is a dictionary consisting of the key/value pairs whose keys are not image processor attributes: i.e., the part of kwargs
which has not been used to update image_processor
and is otherwise ignored. bool
, optional, defaults to False
) — Whether or not to allow for custom models defined on the Hub in their own modeling files. This option should only be set to True
for repositories you trust and in which you have read the code, as it will execute code present on the Hub on your local machine. str
, optional, defaults to "config.json"
) — The name of the file in the model directory to use for the image processor config. Dict[str, Any]
, optional) — The values in kwargs of any keys which are image processor attributes will be used to override the loaded values. Behavior concerning key/value pairs whose keys are not image processor attributes is controlled by the return_unused_kwargs
keyword parameter. Instantiate one of the image processor classes of the library from a pretrained model vocabulary.
The image processor class to instantiate is selected based on the model_type
property of the config object (either passed as an argument or loaded from pretrained_model_name_or_path
if possible), or when it’s missing, by falling back to using pattern matching on pretrained_model_name_or_path
:
Llama4ImageProcessor
or Llama4ImageProcessorFast (Llama4 model)P
or h
(Phi4Multimodal model)Passing token=True
is required when you want to use a private model.
Examples:
>>> from transformers import AutoImageProcessor >>> >>> image_processor = AutoImageProcessor.from_pretrained("google/vit-base-patch16-224-in21k") >>> >>>register < source >
( config_class image_processor_class = None slow_image_processor_class = None fast_image_processor_class = None exist_ok = False )
Parameters
Register a new image processor for this class.
AutoProcessorThis is a generic processor class that will be instantiated as one of the processor classes of the library when created with the AutoProcessor.from_pretrained() class method.
This class cannot be instantiated directly using __init__()
(throws an error).
( pretrained_model_name_or_path **kwargs )
Parameters
str
or os.PathLike
) — This can be either:
save_pretrained()
method, e.g., ./my_model_directory/
.str
or os.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. bool
, optional, defaults to False
) — Whether or not to force to (re-)download the feature extractor files and override the cached versions if they exist. 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. str
or bool, optional) — The token to use as HTTP bearer authorization for remote files. If True
, will use the token generated when running huggingface-cli login
(stored in ~/.huggingface
). 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 revision
can be any identifier allowed by git. bool
, optional, defaults to False
) — If False
, then this function returns just the final feature extractor object. If True
, then this functions returns a Tuple(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 of kwargs
which has not been used to update feature_extractor
and is otherwise ignored. bool
, optional, defaults to False
) — Whether or not to allow for custom models defined on the Hub in their own modeling files. This option should only be set to True
for repositories you trust and in which you have read the code, as it will execute code present on the Hub on your local machine. 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_kwargs
keyword parameter. Instantiate one of the processor classes of the library from a pretrained model vocabulary.
The processor class to instantiate is selected based on the model_type
property of the config object (either passed as an argument or loaded from pretrained_model_name_or_path
if possible):
Passing token=True
is required when you want to use a private model.
Examples:
>>> from transformers import AutoProcessor >>> >>> processor = AutoProcessor.from_pretrained("facebook/wav2vec2-base-960h") >>> >>>register < source >
( config_class processor_class exist_ok = False )
Parameters
Register a new processor for this class.
Generic model classesThe following auto classes are available for instantiating a base model class without a specific head.
AutoModel class transformers.AutoModel < source >( *args **kwargs )
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 the from_config() class method.
This class cannot be instantiated directly using __init__()
(throws an error).
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.
Examples:
>>> from transformers import AutoConfig, AutoModel >>> >>> config = AutoConfig.from_pretrained("google-bert/bert-base-cased") >>> model = AutoModel.from_config(config)from_pretrained < source >
( *model_args **kwargs )
Parameters
str
or os.PathLike
) — Can be either:
./my_model_directory/
../tf_model/model.ckpt.index
). In this case, from_tf
should be set to True
and a configuration object should be provided as config
argument. 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.__init__()
method. pretrained_model_name_or_path
and a configuration JSON file named config.json is found in the directory.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() and from_pretrained() is not a simpler option.
str
or os.PathLike
, optional) — Path to a directory in which a downloaded pretrained model configuration should be cached if the standard cache should not be used. bool
, optional, defaults to False
) — Load the model weights from a TensorFlow checkpoint save file (see docstring of pretrained_model_name_or_path
argument). bool
, optional, defaults to False
) — Whether or not to force the (re-)download of the model weights and configuration files, overriding the cached versions if they exist. 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. bool
, optional, defaults to False
) — Whether ot not to also return a dictionary containing missing keys, unexpected keys and error messages. bool
, optional, defaults to False
) — Whether or not to only look at local files (e.g., not try downloading the model). 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 revision
can be any identifier allowed by git. bool
, optional, defaults to False
) — Whether or not to allow for custom models defined on the Hub in their own modeling files. This option should only be set to True
for repositories you trust and in which you have read the code, as it will execute code present on the Hub on your local machine. str
, optional, defaults to "main"
) — The specific revision to use for the code on the Hub, if the code leaves in a different repository than the rest of the model. 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 revision
can be any identifier allowed by git. output_attentions=True
). Behaves differently depending on whether a config
is provided or automatically loaded:
config
, **kwargs
will be directly passed to the underlying model’s __init__
method (we assume all relevant updates to the configuration have already been done)kwargs
will be first passed to the configuration class initialization function (from_pretrained()). Each key of kwargs
that corresponds to a configuration attribute will be used to override said attribute with the supplied kwargs
value. Remaining keys that do not correspond to any configuration attribute will be passed to the underlying model’s __init__
function.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_type
property of the config object (either passed as an argument or loaded from pretrained_model_name_or_path
if possible), or when it’s missing, by falling back to using pattern matching on pretrained_model_name_or_path
:
MaskFormerSwinModel
(MaskFormerSwin 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 with model.train()
Examples:
>>> from transformers import AutoConfig, AutoModel >>> >>> model = AutoModel.from_pretrained("google-bert/bert-base-cased") >>> >>> model = AutoModel.from_pretrained("google-bert/bert-base-cased", output_attentions=True) >>> model.config.output_attentions True >>> >>> 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 ... )TFAutoModel class transformers.TFAutoModel < source >
( *args **kwargs )
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 the from_config() class method.
This class cannot be instantiated directly using __init__()
(throws an error).
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.
Examples:
>>> from transformers import AutoConfig, TFAutoModel >>> >>> config = AutoConfig.from_pretrained("google-bert/bert-base-cased") >>> model = TFAutoModel.from_config(config)from_pretrained < source >
( *model_args **kwargs )
Parameters
str
or os.PathLike
) — Can be either:
./my_model_directory/
../pt_model/pytorch_model.bin
). In this case, from_pt
should be set to True
and a configuration object should be provided as config
argument. 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.__init__()
method. pretrained_model_name_or_path
and a configuration JSON file named config.json is found in the directory.str
or os.PathLike
, optional) — Path to a directory in which a downloaded pretrained model configuration should be cached if the standard cache should not be used. bool
, optional, defaults to False
) — Load the model weights from a PyTorch checkpoint save file (see docstring of pretrained_model_name_or_path
argument). bool
, optional, defaults to False
) — Whether or not to force the (re-)download of the model weights and configuration files, overriding the cached versions if they exist. 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. bool
, optional, defaults to False
) — Whether ot not to also return a dictionary containing missing keys, unexpected keys and error messages. bool
, optional, defaults to False
) — Whether or not to only look at local files (e.g., not try downloading the model). 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 revision
can be any identifier allowed by git. bool
, optional, defaults to False
) — Whether or not to allow for custom models defined on the Hub in their own modeling files. This option should only be set to True
for repositories you trust and in which you have read the code, as it will execute code present on the Hub on your local machine. str
, optional, defaults to "main"
) — The specific revision to use for the code on the Hub, if the code leaves in a different repository than the rest of the model. 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 revision
can be any identifier allowed by git. output_attentions=True
). Behaves differently depending on whether a config
is provided or automatically loaded:
config
, **kwargs
will be directly passed to the underlying model’s __init__
method (we assume all relevant updates to the configuration have already been done)kwargs
will be first passed to the configuration class initialization function (from_pretrained()). Each key of kwargs
that corresponds to a configuration attribute will be used to override said attribute with the supplied kwargs
value. Remaining keys that do not correspond to any configuration attribute will be passed to the underlying model’s __init__
function.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_type
property of the config object (either passed as an argument or loaded from pretrained_model_name_or_path
if possible), or when it’s missing, by falling back to using pattern matching on pretrained_model_name_or_path
:
Examples:
>>> from transformers import AutoConfig, TFAutoModel >>> >>> model = TFAutoModel.from_pretrained("google-bert/bert-base-cased") >>> >>> model = TFAutoModel.from_pretrained("google-bert/bert-base-cased", output_attentions=True) >>> model.config.output_attentions True >>> >>> 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 ... )FlaxAutoModel class transformers.FlaxAutoModel < source >
( *args **kwargs )
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 the from_config() class method.
This class cannot be instantiated directly using __init__()
(throws an error).
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.
Examples:
>>> from transformers import AutoConfig, FlaxAutoModel >>> >>> config = AutoConfig.from_pretrained("google-bert/bert-base-cased") >>> model = FlaxAutoModel.from_config(config)from_pretrained < source >
( *model_args **kwargs )
Parameters
str
or os.PathLike
) — Can be either:
./my_model_directory/
../pt_model/pytorch_model.bin
). In this case, from_pt
should be set to True
and a configuration object should be provided as config
argument. 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.__init__()
method. pretrained_model_name_or_path
and a configuration JSON file named config.json is found in the directory.str
or os.PathLike
, optional) — Path to a directory in which a downloaded pretrained model configuration should be cached if the standard cache should not be used. bool
, optional, defaults to False
) — Load the model weights from a PyTorch checkpoint save file (see docstring of pretrained_model_name_or_path
argument). bool
, optional, defaults to False
) — Whether or not to force the (re-)download of the model weights and configuration files, overriding the cached versions if they exist. 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. bool
, optional, defaults to False
) — Whether ot not to also return a dictionary containing missing keys, unexpected keys and error messages. bool
, optional, defaults to False
) — Whether or not to only look at local files (e.g., not try downloading the model). 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 revision
can be any identifier allowed by git. bool
, optional, defaults to False
) — Whether or not to allow for custom models defined on the Hub in their own modeling files. This option should only be set to True
for repositories you trust and in which you have read the code, as it will execute code present on the Hub on your local machine. str
, optional, defaults to "main"
) — The specific revision to use for the code on the Hub, if the code leaves in a different repository than the rest of the model. 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 revision
can be any identifier allowed by git. output_attentions=True
). Behaves differently depending on whether a config
is provided or automatically loaded:
config
, **kwargs
will be directly passed to the underlying model’s __init__
method (we assume all relevant updates to the configuration have already been done)kwargs
will be first passed to the configuration class initialization function (from_pretrained()). Each key of kwargs
that corresponds to a configuration attribute will be used to override said attribute with the supplied kwargs
value. Remaining keys that do not correspond to any configuration attribute will be passed to the underlying model’s __init__
function.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_type
property of the config object (either passed as an argument or loaded from pretrained_model_name_or_path
if possible), or when it’s missing, by falling back to using pattern matching on pretrained_model_name_or_path
:
Examples:
>>> from transformers import AutoConfig, FlaxAutoModel >>> >>> model = FlaxAutoModel.from_pretrained("google-bert/bert-base-cased") >>> >>> model = FlaxAutoModel.from_pretrained("google-bert/bert-base-cased", output_attentions=True) >>> model.config.output_attentions True >>> >>> 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 ... )Generic pretraining classes
The following auto classes are available for instantiating a model with a pretraining head.
AutoModelForPreTraining class transformers.AutoModelForPreTraining < source >( *args **kwargs )
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 the from_config() class method.
This class cannot be instantiated directly using __init__()
(throws an error).
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.
Examples:
>>> from transformers import AutoConfig, AutoModelForPreTraining >>> >>> config = AutoConfig.from_pretrained("google-bert/bert-base-cased") >>> model = AutoModelForPreTraining.from_config(config)from_pretrained < source >
( *model_args **kwargs )
Parameters
str
or os.PathLike
) — Can be either:
./my_model_directory/
../tf_model/model.ckpt.index
). In this case, from_tf
should be set to True
and a configuration object should be provided as config
argument. 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.__init__()
method. pretrained_model_name_or_path
and a configuration JSON file named config.json is found in the directory.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() and from_pretrained() is not a simpler option.
str
or os.PathLike
, optional) — Path to a directory in which a downloaded pretrained model configuration should be cached if the standard cache should not be used. bool
, optional, defaults to False
) — Load the model weights from a TensorFlow checkpoint save file (see docstring of pretrained_model_name_or_path
argument). bool
, optional, defaults to False
) — Whether or not to force the (re-)download of the model weights and configuration files, overriding the cached versions if they exist. 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. bool
, optional, defaults to False
) — Whether ot not to also return a dictionary containing missing keys, unexpected keys and error messages. bool
, optional, defaults to False
) — Whether or not to only look at local files (e.g., not try downloading the model). 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 revision
can be any identifier allowed by git. bool
, optional, defaults to False
) — Whether or not to allow for custom models defined on the Hub in their own modeling files. This option should only be set to True
for repositories you trust and in which you have read the code, as it will execute code present on the Hub on your local machine. str
, optional, defaults to "main"
) — The specific revision to use for the code on the Hub, if the code leaves in a different repository than the rest of the model. 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 revision
can be any identifier allowed by git. output_attentions=True
). Behaves differently depending on whether a config
is provided or automatically loaded:
config
, **kwargs
will be directly passed to the underlying model’s __init__
method (we assume all relevant updates to the configuration have already been done)kwargs
will be first passed to the configuration class initialization function (from_pretrained()). Each key of kwargs
that corresponds to a configuration attribute will be used to override said attribute with the supplied kwargs
value. Remaining keys that do not correspond to any configuration attribute will be passed to the underlying model’s __init__
function.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_type
property of the config object (either passed as an argument or loaded from pretrained_model_name_or_path
if possible), or when it’s missing, by falling back to using pattern matching on pretrained_model_name_or_path
:
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 with model.train()
Examples:
>>> from transformers import AutoConfig, AutoModelForPreTraining >>> >>> model = AutoModelForPreTraining.from_pretrained("google-bert/bert-base-cased") >>> >>> model = AutoModelForPreTraining.from_pretrained("google-bert/bert-base-cased", output_attentions=True) >>> model.config.output_attentions True >>> >>> 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 ... )TFAutoModelForPreTraining class transformers.TFAutoModelForPreTraining < source >
( *args **kwargs )
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 the from_config() class method.
This class cannot be instantiated directly using __init__()
(throws an error).
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.
Examples:
>>> from transformers import AutoConfig, TFAutoModelForPreTraining >>> >>> config = AutoConfig.from_pretrained("google-bert/bert-base-cased") >>> model = TFAutoModelForPreTraining.from_config(config)from_pretrained < source >
( *model_args **kwargs )
Parameters
str
or os.PathLike
) — Can be either:
./my_model_directory/
../pt_model/pytorch_model.bin
). In this case, from_pt
should be set to True
and a configuration object should be provided as config
argument. 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.__init__()
method. pretrained_model_name_or_path
and a configuration JSON file named config.json is found in the directory.str
or os.PathLike
, optional) — Path to a directory in which a downloaded pretrained model configuration should be cached if the standard cache should not be used. bool
, optional, defaults to False
) — Load the model weights from a PyTorch checkpoint save file (see docstring of pretrained_model_name_or_path
argument). bool
, optional, defaults to False
) — Whether or not to force the (re-)download of the model weights and configuration files, overriding the cached versions if they exist. 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. bool
, optional, defaults to False
) — Whether ot not to also return a dictionary containing missing keys, unexpected keys and error messages. bool
, optional, defaults to False
) — Whether or not to only look at local files (e.g., not try downloading the model). 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 revision
can be any identifier allowed by git. bool
, optional, defaults to False
) — Whether or not to allow for custom models defined on the Hub in their own modeling files. This option should only be set to True
for repositories you trust and in which you have read the code, as it will execute code present on the Hub on your local machine. str
, optional, defaults to "main"
) — The specific revision to use for the code on the Hub, if the code leaves in a different repository than the rest of the model. 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 revision
can be any identifier allowed by git. output_attentions=True
). Behaves differently depending on whether a config
is provided or automatically loaded:
config
, **kwargs
will be directly passed to the underlying model’s __init__
method (we assume all relevant updates to the configuration have already been done)kwargs
will be first passed to the configuration class initialization function (from_pretrained()). Each key of kwargs
that corresponds to a configuration attribute will be used to override said attribute with the supplied kwargs
value. Remaining keys that do not correspond to any configuration attribute will be passed to the underlying model’s __init__
function.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_type
property of the config object (either passed as an argument or loaded from pretrained_model_name_or_path
if possible), or when it’s missing, by falling back to using pattern matching on pretrained_model_name_or_path
:
Examples:
>>> from transformers import AutoConfig, TFAutoModelForPreTraining >>> >>> model = TFAutoModelForPreTraining.from_pretrained("google-bert/bert-base-cased") >>> >>> model = TFAutoModelForPreTraining.from_pretrained("google-bert/bert-base-cased", output_attentions=True) >>> model.config.output_attentions True >>> >>> 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 ... )FlaxAutoModelForPreTraining class transformers.FlaxAutoModelForPreTraining < source >
( *args **kwargs )
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 the from_config() class method.
This class cannot be instantiated directly using __init__()
(throws an error).
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.
Examples:
>>> from transformers import AutoConfig, FlaxAutoModelForPreTraining >>> >>> config = AutoConfig.from_pretrained("google-bert/bert-base-cased") >>> model = FlaxAutoModelForPreTraining.from_config(config)from_pretrained < source >
( *model_args **kwargs )
Parameters
str
or os.PathLike
) — Can be either:
./my_model_directory/
../pt_model/pytorch_model.bin
). In this case, from_pt
should be set to True
and a configuration object should be provided as config
argument. 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.__init__()
method. pretrained_model_name_or_path
and a configuration JSON file named config.json is found in the directory.str
or os.PathLike
, optional) — Path to a directory in which a downloaded pretrained model configuration should be cached if the standard cache should not be used. bool
, optional, defaults to False
) — Load the model weights from a PyTorch checkpoint save file (see docstring of pretrained_model_name_or_path
argument). bool
, optional, defaults to False
) — Whether or not to force the (re-)download of the model weights and configuration files, overriding the cached versions if they exist. 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. bool
, optional, defaults to False
) — Whether ot not to also return a dictionary containing missing keys, unexpected keys and error messages. bool
, optional, defaults to False
) — Whether or not to only look at local files (e.g., not try downloading the model). 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 revision
can be any identifier allowed by git. bool
, optional, defaults to False
) — Whether or not to allow for custom models defined on the Hub in their own modeling files. This option should only be set to True
for repositories you trust and in which you have read the code, as it will execute code present on the Hub on your local machine. str
, optional, defaults to "main"
) — The specific revision to use for the code on the Hub, if the code leaves in a different repository than the rest of the model. 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 revision
can be any identifier allowed by git. output_attentions=True
). Behaves differently depending on whether a config
is provided or automatically loaded:
config
, **kwargs
will be directly passed to the underlying model’s __init__
method (we assume all relevant updates to the configuration have already been done)kwargs
will be first passed to the configuration class initialization function (from_pretrained()). Each key of kwargs
that corresponds to a configuration attribute will be used to override said attribute with the supplied kwargs
value. Remaining keys that do not correspond to any configuration attribute will be passed to the underlying model’s __init__
function.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_type
property of the config object (either passed as an argument or loaded from pretrained_model_name_or_path
if possible), or when it’s missing, by falling back to using pattern matching on pretrained_model_name_or_path
:
Examples:
>>> from transformers import AutoConfig, FlaxAutoModelForPreTraining >>> >>> model = FlaxAutoModelForPreTraining.from_pretrained("google-bert/bert-base-cased") >>> >>> model = FlaxAutoModelForPreTraining.from_pretrained("google-bert/bert-base-cased", output_attentions=True) >>> model.config.output_attentions True >>> >>> 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 ... )Natural Language Processing
The following auto classes are available for the following natural language processing tasks.
AutoModelForCausalLM class transformers.AutoModelForCausalLM < source >( *args **kwargs )
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 the from_config() class method.
This class cannot be instantiated directly using __init__()
(throws an error).
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.
Examples:
>>> from transformers import AutoConfig, AutoModelForCausalLM >>> >>> config = AutoConfig.from_pretrained("google-bert/bert-base-cased") >>> model = AutoModelForCausalLM.from_config(config)from_pretrained < source >
( *model_args **kwargs )
Parameters
str
or os.PathLike
) — Can be either:
./my_model_directory/
../tf_model/model.ckpt.index
). In this case, from_tf
should be set to True
and a configuration object should be provided as config
argument. 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.__init__()
method. pretrained_model_name_or_path
and a configuration JSON file named config.json is found in the directory.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() and from_pretrained() is not a simpler option.
str
or os.PathLike
, optional) — Path to a directory in which a downloaded pretrained model configuration should be cached if the standard cache should not be used. bool
, optional, defaults to False
) — Load the model weights from a TensorFlow checkpoint save file (see docstring of pretrained_model_name_or_path
argument). bool
, optional, defaults to False
) — Whether or not to force the (re-)download of the model weights and configuration files, overriding the cached versions if they exist. 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. bool
, optional, defaults to False
) — Whether ot not to also return a dictionary containing missing keys, unexpected keys and error messages. bool
, optional, defaults to False
) — Whether or not to only look at local files (e.g., not try downloading the model). 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 revision
can be any identifier allowed by git. bool
, optional, defaults to False
) — Whether or not to allow for custom models defined on the Hub in their own modeling files. This option should only be set to True
for repositories you trust and in which you have read the code, as it will execute code present on the Hub on your local machine. str
, optional, defaults to "main"
) — The specific revision to use for the code on the Hub, if the code leaves in a different repository than the rest of the model. 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 revision
can be any identifier allowed by git. output_attentions=True
). Behaves differently depending on whether a config
is provided or automatically loaded:
config
, **kwargs
will be directly passed to the underlying model’s __init__
method (we assume all relevant updates to the configuration have already been done)kwargs
will be first passed to the configuration class initialization function (from_pretrained()). Each key of kwargs
that corresponds to a configuration attribute will be used to override said attribute with the supplied kwargs
value. Remaining keys that do not correspond to any configuration attribute will be passed to the underlying model’s __init__
function.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_type
property of the config object (either passed as an argument or loaded from pretrained_model_name_or_path
if possible), or when it’s missing, by falling back to using pattern matching on pretrained_model_name_or_path
:
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 with model.train()
Examples:
>>> from transformers import AutoConfig, AutoModelForCausalLM >>> >>> model = AutoModelForCausalLM.from_pretrained("google-bert/bert-base-cased") >>> >>> model = AutoModelForCausalLM.from_pretrained("google-bert/bert-base-cased", output_attentions=True) >>> model.config.output_attentions True >>> >>> 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 ... )TFAutoModelForCausalLM class transformers.TFAutoModelForCausalLM < source >
( *args **kwargs )
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 the from_config() class method.
This class cannot be instantiated directly using __init__()
(throws an error).
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.
Examples:
>>> from transformers import AutoConfig, TFAutoModelForCausalLM >>> >>> config = AutoConfig.from_pretrained("google-bert/bert-base-cased") >>> model = TFAutoModelForCausalLM.from_config(config)from_pretrained < source >
( *model_args **kwargs )
Parameters
str
or os.PathLike
) — Can be either:
./my_model_directory/
../pt_model/pytorch_model.bin
). In this case, from_pt
should be set to True
and a configuration object should be provided as config
argument. 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.__init__()
method. pretrained_model_name_or_path
and a configuration JSON file named config.json is found in the directory.str
or os.PathLike
, optional) — Path to a directory in which a downloaded pretrained model configuration should be cached if the standard cache should not be used. bool
, optional, defaults to False
) — Load the model weights from a PyTorch checkpoint save file (see docstring of pretrained_model_name_or_path
argument). bool
, optional, defaults to False
) — Whether or not to force the (re-)download of the model weights and configuration files, overriding the cached versions if they exist. 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. bool
, optional, defaults to False
) — Whether ot not to also return a dictionary containing missing keys, unexpected keys and error messages. bool
, optional, defaults to False
) — Whether or not to only look at local files (e.g., not try downloading the model). 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 revision
can be any identifier allowed by git. bool
, optional, defaults to False
) — Whether or not to allow for custom models defined on the Hub in their own modeling files. This option should only be set to True
for repositories you trust and in which you have read the code, as it will execute code present on the Hub on your local machine. str
, optional, defaults to "main"
) — The specific revision to use for the code on the Hub, if the code leaves in a different repository than the rest of the model. 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 revision
can be any identifier allowed by git. output_attentions=True
). Behaves differently depending on whether a config
is provided or automatically loaded:
config
, **kwargs
will be directly passed to the underlying model’s __init__
method (we assume all relevant updates to the configuration have already been done)kwargs
will be first passed to the configuration class initialization function (from_pretrained()). Each key of kwargs
that corresponds to a configuration attribute will be used to override said attribute with the supplied kwargs
value. Remaining keys that do not correspond to any configuration attribute will be passed to the underlying model’s __init__
function.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_type
property of the config object (either passed as an argument or loaded from pretrained_model_name_or_path
if possible), or when it’s missing, by falling back to using pattern matching on pretrained_model_name_or_path
:
Examples:
>>> from transformers import AutoConfig, TFAutoModelForCausalLM >>> >>> model = TFAutoModelForCausalLM.from_pretrained("google-bert/bert-base-cased") >>> >>> model = TFAutoModelForCausalLM.from_pretrained("google-bert/bert-base-cased", output_attentions=True) >>> model.config.output_attentions True >>> >>> 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 ... )FlaxAutoModelForCausalLM class transformers.FlaxAutoModelForCausalLM < source >
( *args **kwargs )
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 the from_config() class method.
This class cannot be instantiated directly using __init__()
(throws an error).
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.
Examples:
>>> from transformers import AutoConfig, FlaxAutoModelForCausalLM >>> >>> config = AutoConfig.from_pretrained("google-bert/bert-base-cased") >>> model = FlaxAutoModelForCausalLM.from_config(config)from_pretrained < source >
( *model_args **kwargs )
Parameters
str
or os.PathLike
) — Can be either:
./my_model_directory/
../pt_model/pytorch_model.bin
). In this case, from_pt
should be set to True
and a configuration object should be provided as config
argument. 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.__init__()
method. pretrained_model_name_or_path
and a configuration JSON file named config.json is found in the directory.str
or os.PathLike
, optional) — Path to a directory in which a downloaded pretrained model configuration should be cached if the standard cache should not be used. bool
, optional, defaults to False
) — Load the model weights from a PyTorch checkpoint save file (see docstring of pretrained_model_name_or_path
argument). bool
, optional, defaults to False
) — Whether or not to force the (re-)download of the model weights and configuration files, overriding the cached versions if they exist. 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. bool
, optional, defaults to False
) — Whether ot not to also return a dictionary containing missing keys, unexpected keys and error messages. bool
, optional, defaults to False
) — Whether or not to only look at local files (e.g., not try downloading the model). 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 revision
can be any identifier allowed by git. bool
, optional, defaults to False
) — Whether or not to allow for custom models defined on the Hub in their own modeling files. This option should only be set to True
for repositories you trust and in which you have read the code, as it will execute code present on the Hub on your local machine. str
, optional, defaults to "main"
) — The specific revision to use for the code on the Hub, if the code leaves in a different repository than the rest of the model. 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 revision
can be any identifier allowed by git. output_attentions=True
). Behaves differently depending on whether a config
is provided or automatically loaded:
config
, **kwargs
will be directly passed to the underlying model’s __init__
method (we assume all relevant updates to the configuration have already been done)kwargs
will be first passed to the configuration class initialization function (from_pretrained()). Each key of kwargs
that corresponds to a configuration attribute will be used to override said attribute with the supplied kwargs
value. Remaining keys that do not correspond to any configuration attribute will be passed to the underlying model’s __init__
function.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_type
property of the config object (either passed as an argument or loaded from pretrained_model_name_or_path
if possible), or when it’s missing, by falling back to using pattern matching on pretrained_model_name_or_path
:
Examples:
>>> from transformers import AutoConfig, FlaxAutoModelForCausalLM >>> >>> model = FlaxAutoModelForCausalLM.from_pretrained("google-bert/bert-base-cased") >>> >>> model = FlaxAutoModelForCausalLM.from_pretrained("google-bert/bert-base-cased", output_attentions=True) >>> model.config.output_attentions True >>> >>> 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 ... )AutoModelForMaskedLM class transformers.AutoModelForMaskedLM < source >
( *args **kwargs )
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 the from_config() class method.
This class cannot be instantiated directly using __init__()
(throws an error).
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.
Examples:
>>> from transformers import AutoConfig, AutoModelForMaskedLM >>> >>> config = AutoConfig.from_pretrained("google-bert/bert-base-cased") >>> model = AutoModelForMaskedLM.from_config(config)from_pretrained < source >
( *model_args **kwargs )
Parameters
str
or os.PathLike
) — Can be either:
./my_model_directory/
../tf_model/model.ckpt.index
). In this case, from_tf
should be set to True
and a configuration object should be provided as config
argument. 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.__init__()
method. pretrained_model_name_or_path
and a configuration JSON file named config.json is found in the directory.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() and from_pretrained() is not a simpler option.
str
or os.PathLike
, optional) — Path to a directory in which a downloaded pretrained model configuration should be cached if the standard cache should not be used. bool
, optional, defaults to False
) — Load the model weights from a TensorFlow checkpoint save file (see docstring of pretrained_model_name_or_path
argument). bool
, optional, defaults to False
) — Whether or not to force the (re-)download of the model weights and configuration files, overriding the cached versions if they exist. 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. bool
, optional, defaults to False
) — Whether ot not to also return a dictionary containing missing keys, unexpected keys and error messages. bool
, optional, defaults to False
) — Whether or not to only look at local files (e.g., not try downloading the model). 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 revision
can be any identifier allowed by git. bool
, optional, defaults to False
) — Whether or not to allow for custom models defined on the Hub in their own modeling files. This option should only be set to True
for repositories you trust and in which you have read the code, as it will execute code present on the Hub on your local machine. str
, optional, defaults to "main"
) — The specific revision to use for the code on the Hub, if the code leaves in a different repository than the rest of the model. 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 revision
can be any identifier allowed by git. output_attentions=True
). Behaves differently depending on whether a config
is provided or automatically loaded:
config
, **kwargs
will be directly passed to the underlying model’s __init__
method (we assume all relevant updates to the configuration have already been done)kwargs
will be first passed to the configuration class initialization function (from_pretrained()). Each key of kwargs
that corresponds to a configuration attribute will be used to override said attribute with the supplied kwargs
value. Remaining keys that do not correspond to any configuration attribute will be passed to the underlying model’s __init__
function.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_type
property of the config object (either passed as an argument or loaded from pretrained_model_name_or_path
if possible), or when it’s missing, by falling back to using pattern matching on pretrained_model_name_or_path
:
Wav2Vec2ForMaskedLM
(Wav2Vec2 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 with model.train()
Examples:
>>> from transformers import AutoConfig, AutoModelForMaskedLM >>> >>> model = AutoModelForMaskedLM.from_pretrained("google-bert/bert-base-cased") >>> >>> model = AutoModelForMaskedLM.from_pretrained("google-bert/bert-base-cased", output_attentions=True) >>> model.config.output_attentions True >>> >>> 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 ... )TFAutoModelForMaskedLM class transformers.TFAutoModelForMaskedLM < source >
( *args **kwargs )
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 the from_config() class method.
This class cannot be instantiated directly using __init__()
(throws an error).
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.
Examples:
>>> from transformers import AutoConfig, TFAutoModelForMaskedLM >>> >>> config = AutoConfig.from_pretrained("google-bert/bert-base-cased") >>> model = TFAutoModelForMaskedLM.from_config(config)from_pretrained < source >
( *model_args **kwargs )
Parameters
str
or os.PathLike
) — Can be either:
./my_model_directory/
../pt_model/pytorch_model.bin
). In this case, from_pt
should be set to True
and a configuration object should be provided as config
argument. 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.__init__()
method. pretrained_model_name_or_path
and a configuration JSON file named config.json is found in the directory.str
or os.PathLike
, optional) — Path to a directory in which a downloaded pretrained model configuration should be cached if the standard cache should not be used. bool
, optional, defaults to False
) — Load the model weights from a PyTorch checkpoint save file (see docstring of pretrained_model_name_or_path
argument). bool
, optional, defaults to False
) — Whether or not to force the (re-)download of the model weights and configuration files, overriding the cached versions if they exist. 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. bool
, optional, defaults to False
) — Whether ot not to also return a dictionary containing missing keys, unexpected keys and error messages. bool
, optional, defaults to False
) — Whether or not to only look at local files (e.g., not try downloading the model). 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 revision
can be any identifier allowed by git. bool
, optional, defaults to False
) — Whether or not to allow for custom models defined on the Hub in their own modeling files. This option should only be set to True
for repositories you trust and in which you have read the code, as it will execute code present on the Hub on your local machine. str
, optional, defaults to "main"
) — The specific revision to use for the code on the Hub, if the code leaves in a different repository than the rest of the model. 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 revision
can be any identifier allowed by git. output_attentions=True
). Behaves differently depending on whether a config
is provided or automatically loaded:
config
, **kwargs
will be directly passed to the underlying model’s __init__
method (we assume all relevant updates to the configuration have already been done)kwargs
will be first passed to the configuration class initialization function (from_pretrained()). Each key of kwargs
that corresponds to a configuration attribute will be used to override said attribute with the supplied kwargs
value. Remaining keys that do not correspond to any configuration attribute will be passed to the underlying model’s __init__
function.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_type
property of the config object (either passed as an argument or loaded from pretrained_model_name_or_path
if possible), or when it’s missing, by falling back to using pattern matching on pretrained_model_name_or_path
:
Examples:
>>> from transformers import AutoConfig, TFAutoModelForMaskedLM >>> >>> model = TFAutoModelForMaskedLM.from_pretrained("google-bert/bert-base-cased") >>> >>> model = TFAutoModelForMaskedLM.from_pretrained("google-bert/bert-base-cased", output_attentions=True) >>> model.config.output_attentions True >>> >>> 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 ... )FlaxAutoModelForMaskedLM class transformers.FlaxAutoModelForMaskedLM < source >
( *args **kwargs )
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 the from_config() class method.
This class cannot be instantiated directly using __init__()
(throws an error).
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.
Examples:
>>> from transformers import AutoConfig, FlaxAutoModelForMaskedLM >>> >>> config = AutoConfig.from_pretrained("google-bert/bert-base-cased") >>> model = FlaxAutoModelForMaskedLM.from_config(config)from_pretrained < source >
( *model_args **kwargs )
Parameters
str
or os.PathLike
) — Can be either:
./my_model_directory/
../pt_model/pytorch_model.bin
). In this case, from_pt
should be set to True
and a configuration object should be provided as config
argument. 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.__init__()
method. pretrained_model_name_or_path
and a configuration JSON file named config.json is found in the directory.str
or os.PathLike
, optional) — Path to a directory in which a downloaded pretrained model configuration should be cached if the standard cache should not be used. bool
, optional, defaults to False
) — Load the model weights from a PyTorch checkpoint save file (see docstring of pretrained_model_name_or_path
argument). bool
, optional, defaults to False
) — Whether or not to force the (re-)download of the model weights and configuration files, overriding the cached versions if they exist. 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. bool
, optional, defaults to False
) — Whether ot not to also return a dictionary containing missing keys, unexpected keys and error messages. bool
, optional, defaults to False
) — Whether or not to only look at local files (e.g., not try downloading the model). 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 revision
can be any identifier allowed by git. bool
, optional, defaults to False
) — Whether or not to allow for custom models defined on the Hub in their own modeling files. This option should only be set to True
for repositories you trust and in which you have read the code, as it will execute code present on the Hub on your local machine. str
, optional, defaults to "main"
) — The specific revision to use for the code on the Hub, if the code leaves in a different repository than the rest of the model. 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 revision
can be any identifier allowed by git. output_attentions=True
). Behaves differently depending on whether a config
is provided or automatically loaded:
config
, **kwargs
will be directly passed to the underlying model’s __init__
method (we assume all relevant updates to the configuration have already been done)kwargs
will be first passed to the configuration class initialization function (from_pretrained()). Each key of kwargs
that corresponds to a configuration attribute will be used to override said attribute with the supplied kwargs
value. Remaining keys that do not correspond to any configuration attribute will be passed to the underlying model’s __init__
function.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_type
property of the config object (either passed as an argument or loaded from pretrained_model_name_or_path
if possible), or when it’s missing, by falling back to using pattern matching on pretrained_model_name_or_path
:
Examples:
>>> from transformers import AutoConfig, FlaxAutoModelForMaskedLM >>> >>> model = FlaxAutoModelForMaskedLM.from_pretrained("google-bert/bert-base-cased") >>> >>> model = FlaxAutoModelForMaskedLM.from_pretrained("google-bert/bert-base-cased", output_attentions=True) >>> model.config.output_attentions True >>> >>> 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 ... )AutoModelForMaskGeneration class transformers.AutoModelForMaskGeneration < source >
( *args **kwargs )
TFAutoModelForMaskGeneration class transformers.TFAutoModelForMaskGeneration < source >( *args **kwargs )
AutoModelForSeq2SeqLM class transformers.AutoModelForSeq2SeqLM < source >( *args **kwargs )
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 the from_config() class method.
This class cannot be instantiated directly using __init__()
(throws an error).
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.
Examples:
>>> from transformers import AutoConfig, AutoModelForSeq2SeqLM >>> >>> config = AutoConfig.from_pretrained("google-t5/t5-base") >>> model = AutoModelForSeq2SeqLM.from_config(config)from_pretrained < source >
( *model_args **kwargs )
Parameters
str
or os.PathLike
) — Can be either:
./my_model_directory/
../tf_model/model.ckpt.index
). In this case, from_tf
should be set to True
and a configuration object should be provided as config
argument. 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.__init__()
method. pretrained_model_name_or_path
and a configuration JSON file named config.json is found in the directory.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() and from_pretrained() is not a simpler option.
str
or os.PathLike
, optional) — Path to a directory in which a downloaded pretrained model configuration should be cached if the standard cache should not be used. bool
, optional, defaults to False
) — Load the model weights from a TensorFlow checkpoint save file (see docstring of pretrained_model_name_or_path
argument). bool
, optional, defaults to False
) — Whether or not to force the (re-)download of the model weights and configuration files, overriding the cached versions if they exist. 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. bool
, optional, defaults to False
) — Whether ot not to also return a dictionary containing missing keys, unexpected keys and error messages. bool
, optional, defaults to False
) — Whether or not to only look at local files (e.g., not try downloading the model). 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 revision
can be any identifier allowed by git. bool
, optional, defaults to False
) — Whether or not to allow for custom models defined on the Hub in their own modeling files. This option should only be set to True
for repositories you trust and in which you have read the code, as it will execute code present on the Hub on your local machine. str
, optional, defaults to "main"
) — The specific revision to use for the code on the Hub, if the code leaves in a different repository than the rest of the model. 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 revision
can be any identifier allowed by git. output_attentions=True
). Behaves differently depending on whether a config
is provided or automatically loaded:
config
, **kwargs
will be directly passed to the underlying model’s __init__
method (we assume all relevant updates to the configuration have already been done)kwargs
will be first passed to the configuration class initialization function (from_pretrained()). Each key of kwargs
that corresponds to a configuration attribute will be used to override said attribute with the supplied kwargs
value. Remaining keys that do not correspond to any configuration attribute will be passed to the underlying model’s __init__
function.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_type
property of the config object (either passed as an argument or loaded from pretrained_model_name_or_path
if possible), or when it’s missing, by falling back to using pattern matching on pretrained_model_name_or_path
:
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 with model.train()
Examples:
>>> from transformers import AutoConfig, AutoModelForSeq2SeqLM >>> >>> model = AutoModelForSeq2SeqLM.from_pretrained("google-t5/t5-base") >>> >>> model = AutoModelForSeq2SeqLM.from_pretrained("google-t5/t5-base", output_attentions=True) >>> model.config.output_attentions True >>> >>> 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 ... )TFAutoModelForSeq2SeqLM class transformers.TFAutoModelForSeq2SeqLM < source >
( *args **kwargs )
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 the from_config() class method.
This class cannot be instantiated directly using __init__()
(throws an error).
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.
Examples:
>>> from transformers import AutoConfig, TFAutoModelForSeq2SeqLM >>> >>> config = AutoConfig.from_pretrained("google-t5/t5-base") >>> model = TFAutoModelForSeq2SeqLM.from_config(config)from_pretrained < source >
( *model_args **kwargs )
Parameters
str
or os.PathLike
) — Can be either:
./my_model_directory/
../pt_model/pytorch_model.bin
). In this case, from_pt
should be set to True
and a configuration object should be provided as config
argument. 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.__init__()
method. pretrained_model_name_or_path
and a configuration JSON file named config.json is found in the directory.str
or os.PathLike
, optional) — Path to a directory in which a downloaded pretrained model configuration should be cached if the standard cache should not be used. bool
, optional, defaults to False
) — Load the model weights from a PyTorch checkpoint save file (see docstring of pretrained_model_name_or_path
argument). bool
, optional, defaults to False
) — Whether or not to force the (re-)download of the model weights and configuration files, overriding the cached versions if they exist. 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. bool
, optional, defaults to False
) — Whether ot not to also return a dictionary containing missing keys, unexpected keys and error messages. bool
, optional, defaults to False
) — Whether or not to only look at local files (e.g., not try downloading the model). 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 revision
can be any identifier allowed by git. bool
, optional, defaults to False
) — Whether or not to allow for custom models defined on the Hub in their own modeling files. This option should only be set to True
for repositories you trust and in which you have read the code, as it will execute code present on the Hub on your local machine. str
, optional, defaults to "main"
) — The specific revision to use for the code on the Hub, if the code leaves in a different repository than the rest of the model. 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 revision
can be any identifier allowed by git. output_attentions=True
). Behaves differently depending on whether a config
is provided or automatically loaded:
config
, **kwargs
will be directly passed to the underlying model’s __init__
method (we assume all relevant updates to the configuration have already been done)kwargs
will be first passed to the configuration class initialization function (from_pretrained()). Each key of kwargs
that corresponds to a configuration attribute will be used to override said attribute with the supplied kwargs
value. Remaining keys that do not correspond to any configuration attribute will be passed to the underlying model’s __init__
function.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_type
property of the config object (either passed as an argument or loaded from pretrained_model_name_or_path
if possible), or when it’s missing, by falling back to using pattern matching on pretrained_model_name_or_path
:
Examples:
>>> from transformers import AutoConfig, TFAutoModelForSeq2SeqLM >>> >>> model = TFAutoModelForSeq2SeqLM.from_pretrained("google-t5/t5-base") >>> >>> model = TFAutoModelForSeq2SeqLM.from_pretrained("google-t5/t5-base", output_attentions=True) >>> model.config.output_attentions True >>> >>> 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 ... )FlaxAutoModelForSeq2SeqLM class transformers.FlaxAutoModelForSeq2SeqLM < source >
( *args **kwargs )
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 the from_config() class method.
This class cannot be instantiated directly using __init__()
(throws an error).
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.
Examples:
>>> from transformers import AutoConfig, FlaxAutoModelForSeq2SeqLM >>> >>> config = AutoConfig.from_pretrained("google-t5/t5-base") >>> model = FlaxAutoModelForSeq2SeqLM.from_config(config)from_pretrained < source >
( *model_args **kwargs )
Parameters
str
or os.PathLike
) — Can be either:
./my_model_directory/
../pt_model/pytorch_model.bin
). In this case, from_pt
should be set to True
and a configuration object should be provided as config
argument. 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.__init__()
method. pretrained_model_name_or_path
and a configuration JSON file named config.json is found in the directory.str
or os.PathLike
, optional) — Path to a directory in which a downloaded pretrained model configuration should be cached if the standard cache should not be used. bool
, optional, defaults to False
) — Load the model weights from a PyTorch checkpoint save file (see docstring of pretrained_model_name_or_path
argument). bool
, optional, defaults to False
) — Whether or not to force the (re-)download of the model weights and configuration files, overriding the cached versions if they exist. 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. bool
, optional, defaults to False
) — Whether ot not to also return a dictionary containing missing keys, unexpected keys and error messages. bool
, optional, defaults to False
) — Whether or not to only look at local files (e.g., not try downloading the model). 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 revision
can be any identifier allowed by git. bool
, optional, defaults to False
) — Whether or not to allow for custom models defined on the Hub in their own modeling files. This option should only be set to True
for repositories you trust and in which you have read the code, as it will execute code present on the Hub on your local machine. str
, optional, defaults to "main"
) — The specific revision to use for the code on the Hub, if the code leaves in a different repository than the rest of the model. 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 revision
can be any identifier allowed by git. output_attentions=True
). Behaves differently depending on whether a config
is provided or automatically loaded:
config
, **kwargs
will be directly passed to the underlying model’s __init__
method (we assume all relevant updates to the configuration have already been done)kwargs
will be first passed to the configuration class initialization function (from_pretrained()). Each key of kwargs
that corresponds to a configuration attribute will be used to override said attribute with the supplied kwargs
value. Remaining keys that do not correspond to any configuration attribute will be passed to the underlying model’s __init__
function.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_type
property of the config object (either passed as an argument or loaded from pretrained_model_name_or_path
if possible), or when it’s missing, by falling back to using pattern matching on pretrained_model_name_or_path
:
Examples:
>>> from transformers import AutoConfig, FlaxAutoModelForSeq2SeqLM >>> >>> model = FlaxAutoModelForSeq2SeqLM.from_pretrained("google-t5/t5-base") >>> >>> model = FlaxAutoModelForSeq2SeqLM.from_pretrained("google-t5/t5-base", output_attentions=True) >>> model.config.output_attentions True >>> >>> 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 ... )AutoModelForSequenceClassification class transformers.AutoModelForSequenceClassification < source >
( *args **kwargs )
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 the from_config() class method.
This class cannot be instantiated directly using __init__()
(throws an error).
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.
Examples:
>>> from transformers import AutoConfig, AutoModelForSequenceClassification >>> >>> config = AutoConfig.from_pretrained("google-bert/bert-base-cased") >>> model = AutoModelForSequenceClassification.from_config(config)from_pretrained < source >
( *model_args **kwargs )
Parameters
str
or os.PathLike
) — Can be either:
./my_model_directory/
../tf_model/model.ckpt.index
). In this case, from_tf
should be set to True
and a configuration object should be provided as config
argument. 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.__init__()
method. pretrained_model_name_or_path
and a configuration JSON file named config.json is found in the directory.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() and from_pretrained() is not a simpler option.
str
or os.PathLike
, optional) — Path to a directory in which a downloaded pretrained model configuration should be cached if the standard cache should not be used. bool
, optional, defaults to False
) — Load the model weights from a TensorFlow checkpoint save file (see docstring of pretrained_model_name_or_path
argument). bool
, optional, defaults to False
) — Whether or not to force the (re-)download of the model weights and configuration files, overriding the cached versions if they exist. 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. bool
, optional, defaults to False
) — Whether ot not to also return a dictionary containing missing keys, unexpected keys and error messages. bool
, optional, defaults to False
) — Whether or not to only look at local files (e.g., not try downloading the model). 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 revision
can be any identifier allowed by git. bool
, optional, defaults to False
) — Whether or not to allow for custom models defined on the Hub in their own modeling files. This option should only be set to True
for repositories you trust and in which you have read the code, as it will execute code present on the Hub on your local machine. str
, optional, defaults to "main"
) — The specific revision to use for the code on the Hub, if the code leaves in a different repository than the rest of the model. 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 revision
can be any identifier allowed by git. output_attentions=True
). Behaves differently depending on whether a config
is provided or automatically loaded:
config
, **kwargs
will be directly passed to the underlying model’s __init__
method (we assume all relevant updates to the configuration have already been done)kwargs
will be first passed to the configuration class initialization function (from_pretrained()). Each key of kwargs
that corresponds to a configuration attribute will be used to override said attribute with the supplied kwargs
value. Remaining keys that do not correspond to any configuration attribute will be passed to the underlying model’s __init__
function.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_type
property of the config object (either passed as an argument or loaded from pretrained_model_name_or_path
if possible), or when it’s missing, by falling back to using pattern matching on pretrained_model_name_or_path
:
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 with model.train()
Examples:
>>> from transformers import AutoConfig, AutoModelForSequenceClassification >>> >>> model = AutoModelForSequenceClassification.from_pretrained("google-bert/bert-base-cased") >>> >>> model = AutoModelForSequenceClassification.from_pretrained("google-bert/bert-base-cased", output_attentions=True) >>> model.config.output_attentions True >>> >>> 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 ... )TFAutoModelForSequenceClassification class transformers.TFAutoModelForSequenceClassification < source >
( *args **kwargs )
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 the from_config() class method.
This class cannot be instantiated directly using __init__()
(throws an error).
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.
Examples:
>>> from transformers import AutoConfig, TFAutoModelForSequenceClassification >>> >>> config = AutoConfig.from_pretrained("google-bert/bert-base-cased") >>> model = TFAutoModelForSequenceClassification.from_config(config)from_pretrained < source >
( *model_args **kwargs )
Parameters
str
or os.PathLike
) — Can be either:
./my_model_directory/
../pt_model/pytorch_model.bin
). In this case, from_pt
should be set to True
and a configuration object should be provided as config
argument. 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.__init__()
method. pretrained_model_name_or_path
and a configuration JSON file named config.json is found in the directory.str
or os.PathLike
, optional) — Path to a directory in which a downloaded pretrained model configuration should be cached if the standard cache should not be used. bool
, optional, defaults to False
) — Load the model weights from a PyTorch checkpoint save file (see docstring of pretrained_model_name_or_path
argument). bool
, optional, defaults to False
) — Whether or not to force the (re-)download of the model weights and configuration files, overriding the cached versions if they exist. 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. bool
, optional, defaults to False
) — Whether ot not to also return a dictionary containing missing keys, unexpected keys and error messages. bool
, optional, defaults to False
) — Whether or not to only look at local files (e.g., not try downloading the model). 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 revision
can be any identifier allowed by git. bool
, optional, defaults to False
) — Whether or not to allow for custom models defined on the Hub in their own modeling files. This option should only be set to True
for repositories you trust and in which you have read the code, as it will execute code present on the Hub on your local machine. str
, optional, defaults to "main"
) — The specific revision to use for the code on the Hub, if the code leaves in a different repository than the rest of the model. 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 revision
can be any identifier allowed by git. output_attentions=True
). Behaves differently depending on whether a config
is provided or automatically loaded:
config
, **kwargs
will be directly passed to the underlying model’s __init__
method (we assume all relevant updates to the configuration have already been done)kwargs
will be first passed to the configuration class initialization function (from_pretrained()). Each key of kwargs
that corresponds to a configuration attribute will be used to override said attribute with the supplied kwargs
value. Remaining keys that do not correspond to any configuration attribute will be passed to the underlying model’s __init__
function.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_type
property of the config object (either passed as an argument or loaded from pretrained_model_name_or_path
if possible), or when it’s missing, by falling back to using pattern matching on pretrained_model_name_or_path
:
Examples:
>>> from transformers import AutoConfig, TFAutoModelForSequenceClassification >>> >>> model = TFAutoModelForSequenceClassification.from_pretrained("google-bert/bert-base-cased") >>> >>> model = TFAutoModelForSequenceClassification.from_pretrained("google-bert/bert-base-cased", output_attentions=True) >>> model.config.output_attentions True >>> >>> 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 ... )FlaxAutoModelForSequenceClassification class transformers.FlaxAutoModelForSequenceClassification < source >
( *args **kwargs )
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 the from_config() class method.
This class cannot be instantiated directly using __init__()
(throws an error).
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.
Examples:
>>> from transformers import AutoConfig, FlaxAutoModelForSequenceClassification >>> >>> config = AutoConfig.from_pretrained("google-bert/bert-base-cased") >>> model = FlaxAutoModelForSequenceClassification.from_config(config)from_pretrained < source >
( *model_args **kwargs )
Parameters
str
or os.PathLike
) — Can be either:
./my_model_directory/
../pt_model/pytorch_model.bin
). In this case, from_pt
should be set to True
and a configuration object should be provided as config
argument. 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.__init__()
method. pretrained_model_name_or_path
and a configuration JSON file named config.json is found in the directory.str
or os.PathLike
, optional) — Path to a directory in which a downloaded pretrained model configuration should be cached if the standard cache should not be used. bool
, optional, defaults to False
) — Load the model weights from a PyTorch checkpoint save file (see docstring of pretrained_model_name_or_path
argument). bool
, optional, defaults to False
) — Whether or not to force the (re-)download of the model weights and configuration files, overriding the cached versions if they exist. 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. bool
, optional, defaults to False
) — Whether ot not to also return a dictionary containing missing keys, unexpected keys and error messages. bool
, optional, defaults to False
) — Whether or not to only look at local files (e.g., not try downloading the model). 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 revision
can be any identifier allowed by git. bool
, optional, defaults to False
) — Whether or not to allow for custom models defined on the Hub in their own modeling files. This option should only be set to True
for repositories you trust and in which you have read the code, as it will execute code present on the Hub on your local machine. str
, optional, defaults to "main"
) — The specific revision to use for the code on the Hub, if the code leaves in a different repository than the rest of the model. 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 revision
can be any identifier allowed by git. output_attentions=True
). Behaves differently depending on whether a config
is provided or automatically loaded:
config
, **kwargs
will be directly passed to the underlying model’s __init__
method (we assume all relevant updates to the configuration have already been done)kwargs
will be first passed to the configuration class initialization function (from_pretrained()). Each key of kwargs
that corresponds to a configuration attribute will be used to override said attribute with the supplied kwargs
value. Remaining keys that do not correspond to any configuration attribute will be passed to the underlying model’s __init__
function.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_type
property of the config object (either passed as an argument or loaded from pretrained_model_name_or_path
if possible), or when it’s missing, by falling back to using pattern matching on pretrained_model_name_or_path
:
Examples:
>>> from transformers import AutoConfig, FlaxAutoModelForSequenceClassification >>> >>> model = FlaxAutoModelForSequenceClassification.from_pretrained("google-bert/bert-base-cased") >>> >>> model = FlaxAutoModelForSequenceClassification.from_pretrained("google-bert/bert-base-cased", output_attentions=True) >>> model.config.output_attentions True >>> >>> 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 ... )AutoModelForMultipleChoice class transformers.AutoModelForMultipleChoice < source >
( *args **kwargs )
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 the from_config() class method.
This class cannot be instantiated directly using __init__()
(throws an error).
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.
Examples:
>>> from transformers import AutoConfig, AutoModelForMultipleChoice >>> >>> config = AutoConfig.from_pretrained("google-bert/bert-base-cased") >>> model = AutoModelForMultipleChoice.from_config(config)from_pretrained < source >
( *model_args **kwargs )
Parameters
str
or os.PathLike
) — Can be either:
./my_model_directory/
../tf_model/model.ckpt.index
). In this case, from_tf
should be set to True
and a configuration object should be provided as config
argument. 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.__init__()
method. pretrained_model_name_or_path
and a configuration JSON file named config.json is found in the directory.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() and from_pretrained() is not a simpler option.
str
or os.PathLike
, optional) — Path to a directory in which a downloaded pretrained model configuration should be cached if the standard cache should not be used. bool
, optional, defaults to False
) — Load the model weights from a TensorFlow checkpoint save file (see docstring of pretrained_model_name_or_path
argument). bool
, optional, defaults to False
) — Whether or not to force the (re-)download of the model weights and configuration files, overriding the cached versions if they exist. 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. bool
, optional, defaults to False
) — Whether ot not to also return a dictionary containing missing keys, unexpected keys and error messages. bool
, optional, defaults to False
) — Whether or not to only look at local files (e.g., not try downloading the model). 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 revision
can be any identifier allowed by git. bool
, optional, defaults to False
) — Whether or not to allow for custom models defined on the Hub in their own modeling files. This option should only be set to True
for repositories you trust and in which you have read the code, as it will execute code present on the Hub on your local machine. str
, optional, defaults to "main"
) — The specific revision to use for the code on the Hub, if the code leaves in a different repository than the rest of the model. 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 revision
can be any identifier allowed by git. output_attentions=True
). Behaves differently depending on whether a config
is provided or automatically loaded:
config
, **kwargs
will be directly passed to the underlying model’s __init__
method (we assume all relevant updates to the configuration have already been done)kwargs
will be first passed to the configuration class initialization function (from_pretrained()). Each key of kwargs
that corresponds to a configuration attribute will be used to override said attribute with the supplied kwargs
value. Remaining keys that do not correspond to any configuration attribute will be passed to the underlying model’s __init__
function.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_type
property of the config object (either passed as an argument or loaded from pretrained_model_name_or_path
if possible), or when it’s missing, by falling back to using pattern matching on pretrained_model_name_or_path
:
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 with model.train()
Examples:
>>> from transformers import AutoConfig, AutoModelForMultipleChoice >>> >>> model = AutoModelForMultipleChoice.from_pretrained("google-bert/bert-base-cased") >>> >>> model = AutoModelForMultipleChoice.from_pretrained("google-bert/bert-base-cased", output_attentions=True) >>> model.config.output_attentions True >>> >>> 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 ... )TFAutoModelForMultipleChoice class transformers.TFAutoModelForMultipleChoice < source >
( *args **kwargs )
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 the from_config() class method.
This class cannot be instantiated directly using __init__()
(throws an error).
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.
Examples:
>>> from transformers import AutoConfig, TFAutoModelForMultipleChoice >>> >>> config = AutoConfig.from_pretrained("google-bert/bert-base-cased") >>> model = TFAutoModelForMultipleChoice.from_config(config)from_pretrained < source >
( *model_args **kwargs )
Parameters
str
or os.PathLike
) — Can be either:
./my_model_directory/
../pt_model/pytorch_model.bin
). In this case, from_pt
should be set to True
and a configuration object should be provided as config
argument. 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.__init__()
method. pretrained_model_name_or_path
and a configuration JSON file named config.json is found in the directory.str
or os.PathLike
, optional) — Path to a directory in which a downloaded pretrained model configuration should be cached if the standard cache should not be used. bool
, optional, defaults to False
) — Load the model weights from a PyTorch checkpoint save file (see docstring of pretrained_model_name_or_path
argument). bool
, optional, defaults to False
) — Whether or not to force the (re-)download of the model weights and configuration files, overriding the cached versions if they exist. 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. bool
, optional, defaults to False
) — Whether ot not to also return a dictionary containing missing keys, unexpected keys and error messages. bool
, optional, defaults to False
) — Whether or not to only look at local files (e.g., not try downloading the model). 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 revision
can be any identifier allowed by git. bool
, optional, defaults to False
) — Whether or not to allow for custom models defined on the Hub in their own modeling files. This option should only be set to True
for repositories you trust and in which you have read the code, as it will execute code present on the Hub on your local machine. str
, optional, defaults to "main"
) — The specific revision to use for the code on the Hub, if the code leaves in a different repository than the rest of the model. 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 revision
can be any identifier allowed by git. output_attentions=True
). Behaves differently depending on whether a config
is provided or automatically loaded:
config
, **kwargs
will be directly passed to the underlying model’s __init__
method (we assume all relevant updates to the configuration have already been done)kwargs
will be first passed to the configuration class initialization function (from_pretrained()). Each key of kwargs
that corresponds to a configuration attribute will be used to override said attribute with the supplied kwargs
value. Remaining keys that do not correspond to any configuration attribute will be passed to the underlying model’s __init__
function.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_type
property of the config object (either passed as an argument or loaded from pretrained_model_name_or_path
if possible), or when it’s missing, by falling back to using pattern matching on pretrained_model_name_or_path
:
Examples:
>>> from transformers import AutoConfig, TFAutoModelForMultipleChoice >>> >>> model = TFAutoModelForMultipleChoice.from_pretrained("google-bert/bert-base-cased") >>> >>> model = TFAutoModelForMultipleChoice.from_pretrained("google-bert/bert-base-cased", output_attentions=True) >>> model.config.output_attentions True >>> >>> 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 ... )FlaxAutoModelForMultipleChoice class transformers.FlaxAutoModelForMultipleChoice < source >
( *args **kwargs )
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 the from_config() class method.
This class cannot be instantiated directly using __init__()
(throws an error).
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.
Examples:
>>> from transformers import AutoConfig, FlaxAutoModelForMultipleChoice >>> >>> config = AutoConfig.from_pretrained("google-bert/bert-base-cased") >>> model = FlaxAutoModelForMultipleChoice.from_config(config)from_pretrained < source >
( *model_args **kwargs )
Parameters
str
or os.PathLike
) — Can be either:
./my_model_directory/
../pt_model/pytorch_model.bin
). In this case, from_pt
should be set to True
and a configuration object should be provided as config
argument. 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.__init__()
method. pretrained_model_name_or_path
and a configuration JSON file named config.json is found in the directory.str
or os.PathLike
, optional) — Path to a directory in which a downloaded pretrained model configuration should be cached if the standard cache should not be used. bool
, optional, defaults to False
) — Load the model weights from a PyTorch checkpoint save file (see docstring of pretrained_model_name_or_path
argument). bool
, optional, defaults to False
) — Whether or not to force the (re-)download of the model weights and configuration files, overriding the cached versions if they exist. 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. bool
, optional, defaults to False
) — Whether ot not to also return a dictionary containing missing keys, unexpected keys and error messages. bool
, optional, defaults to False
) — Whether or not to only look at local files (e.g., not try downloading the model). 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 revision
can be any identifier allowed by git. bool
, optional, defaults to False
) — Whether or not to allow for custom models defined on the Hub in their own modeling files. This option should only be set to True
for repositories you trust and in which you have read the code, as it will execute code present on the Hub on your local machine. str
, optional, defaults to "main"
) — The specific revision to use for the code on the Hub, if the code leaves in a different repository than the rest of the model. 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 revision
can be any identifier allowed by git. output_attentions=True
). Behaves differently depending on whether a config
is provided or automatically loaded:
config
, **kwargs
will be directly passed to the underlying model’s __init__
method (we assume all relevant updates to the configuration have already been done)kwargs
will be first passed to the configuration class initialization function (from_pretrained()). Each key of kwargs
that corresponds to a configuration attribute will be used to override said attribute with the supplied kwargs
value. Remaining keys that do not correspond to any configuration attribute will be passed to the underlying model’s __init__
function.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_type
property of the config object (either passed as an argument or loaded from pretrained_model_name_or_path
if possible), or when it’s missing, by falling back to using pattern matching on pretrained_model_name_or_path
:
Examples:
>>> from transformers import AutoConfig, FlaxAutoModelForMultipleChoice >>> >>> model = FlaxAutoModelForMultipleChoice.from_pretrained("google-bert/bert-base-cased") >>> >>> model = FlaxAutoModelForMultipleChoice.from_pretrained("google-bert/bert-base-cased", output_attentions=True) >>> model.config.output_attentions True >>> >>> 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 ... )AutoModelForNextSentencePrediction class transformers.AutoModelForNextSentencePrediction < source >
( *args **kwargs )
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 the from_config() class method.
This class cannot be instantiated directly using __init__()
(throws an error).
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.
Examples:
>>> from transformers import AutoConfig, AutoModelForNextSentencePrediction >>> >>> config = AutoConfig.from_pretrained("google-bert/bert-base-cased") >>> model = AutoModelForNextSentencePrediction.from_config(config)from_pretrained < source >
( *model_args **kwargs )
Parameters
str
or os.PathLike
) — Can be either:
./my_model_directory/
../tf_model/model.ckpt.index
). In this case, from_tf
should be set to True
and a configuration object should be provided as config
argument. 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.__init__()
method. pretrained_model_name_or_path
and a configuration JSON file named config.json is found in the directory.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() and from_pretrained() is not a simpler option.
str
or os.PathLike
, optional) — Path to a directory in which a downloaded pretrained model configuration should be cached if the standard cache should not be used. bool
, optional, defaults to False
) — Load the model weights from a TensorFlow checkpoint save file (see docstring of pretrained_model_name_or_path
argument). bool
, optional, defaults to False
) — Whether or not to force the (re-)download of the model weights and configuration files, overriding the cached versions if they exist. 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. bool
, optional, defaults to False
) — Whether ot not to also return a dictionary containing missing keys, unexpected keys and error messages. bool
, optional, defaults to False
) — Whether or not to only look at local files (e.g., not try downloading the model). 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 revision
can be any identifier allowed by git. bool
, optional, defaults to False
) — Whether or not to allow for custom models defined on the Hub in their own modeling files. This option should only be set to True
for repositories you trust and in which you have read the code, as it will execute code present on the Hub on your local machine. str
, optional, defaults to "main"
) — The specific revision to use for the code on the Hub, if the code leaves in a different repository than the rest of the model. 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 revision
can be any identifier allowed by git. output_attentions=True
). Behaves differently depending on whether a config
is provided or automatically loaded:
config
, **kwargs
will be directly passed to the underlying model’s __init__
method (we assume all relevant updates to the configuration have already been done)kwargs
will be first passed to the configuration class initialization function (from_pretrained()). Each key of kwargs
that corresponds to a configuration attribute will be used to override said attribute with the supplied kwargs
value. Remaining keys that do not correspond to any configuration attribute will be passed to the underlying model’s __init__
function.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_type
property of the config object (either passed as an argument or loaded from pretrained_model_name_or_path
if possible), or when it’s missing, by falling back to using pattern matching on pretrained_model_name_or_path
:
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 with model.train()
Examples:
>>> from transformers import AutoConfig, AutoModelForNextSentencePrediction >>> >>> model = AutoModelForNextSentencePrediction.from_pretrained("google-bert/bert-base-cased") >>> >>> model = AutoModelForNextSentencePrediction.from_pretrained("google-bert/bert-base-cased", output_attentions=True) >>> model.config.output_attentions True >>> >>> 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 ... )TFAutoModelForNextSentencePrediction class transformers.TFAutoModelForNextSentencePrediction < source >
( *args **kwargs )
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 the from_config() class method.
This class cannot be instantiated directly using __init__()
(throws an error).
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.
Examples:
>>> from transformers import AutoConfig, TFAutoModelForNextSentencePrediction >>> >>> config = AutoConfig.from_pretrained("google-bert/bert-base-cased") >>> model = TFAutoModelForNextSentencePrediction.from_config(config)from_pretrained < source >
( *model_args **kwargs )
Parameters
str
or os.PathLike
) — Can be either:
./my_model_directory/
../pt_model/pytorch_model.bin
). In this case, from_pt
should be set to True
and a configuration object should be provided as config
argument. 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.__init__()
method. pretrained_model_name_or_path
and a configuration JSON file named config.json is found in the directory.str
or os.PathLike
, optional) — Path to a directory in which a downloaded pretrained model configuration should be cached if the standard cache should not be used. bool
, optional, defaults to False
) — Load the model weights from a PyTorch checkpoint save file (see docstring of pretrained_model_name_or_path
argument). bool
, optional, defaults to False
) — Whether or not to force the (re-)download of the model weights and configuration files, overriding the cached versions if they exist. 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. bool
, optional, defaults to False
) — Whether ot not to also return a dictionary containing missing keys, unexpected keys and error messages. bool
, optional, defaults to False
) — Whether or not to only look at local files (e.g., not try downloading the model). 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 revision
can be any identifier allowed by git. bool
, optional, defaults to False
) — Whether or not to allow for custom models defined on the Hub in their own modeling files. This option should only be set to True
for repositories you trust and in which you have read the code, as it will execute code present on the Hub on your local machine. str
, optional, defaults to "main"
) — The specific revision to use for the code on the Hub, if the code leaves in a different repository than the rest of the model. 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 revision
can be any identifier allowed by git. output_attentions=True
). Behaves differently depending on whether a config
is provided or automatically loaded:
config
, **kwargs
will be directly passed to the underlying model’s __init__
method (we assume all relevant updates to the configuration have already been done)kwargs
will be first passed to the configuration class initialization function (from_pretrained()). Each key of kwargs
that corresponds to a configuration attribute will be used to override said attribute with the supplied kwargs
value. Remaining keys that do not correspond to any configuration attribute will be passed to the underlying model’s __init__
function.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_type
property of the config object (either passed as an argument or loaded from pretrained_model_name_or_path
if possible), or when it’s missing, by falling back to using pattern matching on pretrained_model_name_or_path
:
Examples:
>>> from transformers import AutoConfig, TFAutoModelForNextSentencePrediction >>> >>> model = TFAutoModelForNextSentencePrediction.from_pretrained("google-bert/bert-base-cased") >>> >>> model = TFAutoModelForNextSentencePrediction.from_pretrained("google-bert/bert-base-cased", output_attentions=True) >>> model.config.output_attentions True >>> >>> config = AutoConfig.from_pretrained("./pt_model/bert_pt_model_config.json") >>> model = TFAutoModelForNextSentencePrediction.from_pretrained( ... "./pt_model/bert_pytorch_model.bin", from_pt=True, config=config ... )FlaxAutoModelForNextSentencePrediction class transformers.FlaxAutoModelForNextSentencePrediction < source >
( *args **kwargs )
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 the from_config() class method.
This class cannot be instantiated directly using __init__()
(throws an error).
( **kwargs )
Parameters
str
, optional) — The attention implementation to use in the model (if relevant). Can be any of "eager"
(manual implementation of the attention), "sdpa"
(using F.scaled_dot_product_attention
), or "flash_attention_2"
(using Dao-AILab/flash-attention). By default, if available, SDPA will be used for torch>=2.1.1. The default is otherwise the manual "eager"
implementation. 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.
Examples:
>>> from transformers import AutoConfig, FlaxAutoModelForNextSentencePrediction >>> >>> config = AutoConfig.from_pretrained("google-bert/bert-base-cased") >>> model = FlaxAutoModelForNextSentencePrediction.from_config(config)from_pretrained < source >
( *model_args **kwargs )
Parameters
str
or os.PathLike
) — Can be either:
./my_model_directory/
../pt_model/pytorch_model.bin
). In this case, from_pt
should be set to True
and a configuration object should be provided as config
argument. 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.__init__()
method. pretrained_model_name_or_path
and a configuration JSON file named config.json is found in the directory.str
or os.PathLike
, optional) — Path to a directory in which a downloaded pretrained model configuration should be cached if the standard cache should not be used. bool
, optional, defaults to False
) — Load the model weights from a PyTorch checkpoint save file (see docstring of pretrained_model_name_or_path
argument). bool
, optional, defaults to False
) — Whether or not to force the (re-)download of the model weights and configuration files, overriding the cached versions if they exist. 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. bool
, optional, defaults to False
) — Whether ot not to also return a dictionary containing missing keys, unexpected keys and error messages. bool
, optional, defaults to False
) — Whether or not to only look at local files (e.g., not try downloading the model). 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 revision
can be any identifier allowed by git. bool
, optional, defaults to False
) — Whether or not to allow for custom models defined on the Hub in their own modeling files. This option should only be set to True
for repositories you trust and in which you have read the code, as it will execute code present on the Hub on your local machine. str
, optional, defaults to "main"
) — The specific revision to use for the code on the Hub, if the code leaves in a different repository than the rest of the model. 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 revision
can be any identifier allowed by git. output_attentions=True
). Behaves differently depending on whether a config
is provided or automatically loaded:
config
, **kwargs
will be directly passed to the underlying model’s __init__
method (we assume all relevant updates to the configuration have already been done)kwargs
will be first passed to the configuration class initialization function (from_pretrained()). Each key of kwargs
that corresponds to a configuration attribute will be used to override said attribute with the supplied kwargs
value. Remaining keys that do not correspond to any configuration attribute will be passed to the underlying model’s __init__
function.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_type
property of the config object (either passed as an argument or loaded from pretrained_model_name_or_path
if possible), or when it’s missing, by falling back to using pattern matching on pretrained_model_name_or_path
:
Examples:
>>> from transformers import AutoConfig, FlaxAutoModelForNextSentencePrediction >>> >>> model = FlaxAutoModelForNextSentencePrediction.from_pretrained("google-bert/bert-base-cased") >>> >>> model = FlaxAutoModelForNextSentencePrediction.from_pretrained("google-bert/bert-base-cased", output_attentions=True) >>> model.config.output_attentions True >>> >>> 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 ... )AutoModelForTokenClassification class transformers.AutoModelForTokenClassification < source >
( *args **kwargs )
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 the from_config() class method.
This class cannot be instantiated directly using __init__()
(throws an error).
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.
Examples:
>>> from transformers import AutoConfig, AutoModelForTokenClassification >>> >>> config = AutoConfig.from_pretrained("google-bert/bert-base-cased") >>> model = AutoModelForTokenClassification.from_config(config)from_pretrained < source >
( *model_args **kwargs )
Parameters
str
or os.PathLike
) — Can be either:
./my_model_directory/
../tf_model/model.ckpt.index
). In this case, from_tf
should be set to True
and a configuration object should be provided as config
argument. 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.__init__()
method. pretrained_model_name_or_path
and a configuration JSON file named config.json is found in the directory.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() and from_pretrained() is not a simpler option.
str
or os.PathLike
, optional) — Path to a directory in which a downloaded pretrained model configuration should be cached if the standard cache should not be used. bool
, optional, defaults to False
) — Load the model weights from a TensorFlow checkpoint save file (see docstring of pretrained_model_name_or_path
argument). bool
, optional, defaults to False
) — Whether or not to force the (re-)download of the model weights and configuration files, overriding the cached versions if they exist. 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. bool
, optional, defaults to False
) — Whether ot not to also return a dictionary containing missing keys, unexpected keys and error messages. bool
, optional, defaults to False
) — Whether or not to only look at local files (e.g., not try downloading the model). 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 revision
can be any identifier allowed by git. bool
, optional, defaults to False
) — Whether or not to allow for custom models defined on the Hub in their own modeling files. This option should only be set to True
for repositories you trust and in which you have read the code, as it will execute code present on the Hub on your local machine. str
, optional, defaults to "main"
) — The specific revision to use for the code on the Hub, if the code leaves in a different repository than the rest of the model. 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 revision
can be any identifier allowed by git. output_attentions=True
). Behaves differently depending on whether a config
is provided or automatically loaded:
config
, **kwargs
will be directly passed to the underlying model’s __init__
method (we assume all relevant updates to the configuration have already been done)kwargs
will be first passed to the configuration class initialization function (from_pretrained()). Each key of kwargs
that corresponds to a configuration attribute will be used to override said attribute with the supplied kwargs
value. Remaining keys that do not correspond to any configuration attribute will be passed to the underlying model’s __init__
function.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_type
property of the config object (either passed as an argument or loaded from pretrained_model_name_or_path
if possible), or when it’s missing, by falling back to using pattern matching on pretrained_model_name_or_path
:
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 with model.train()
Examples:
>>> from transformers import AutoConfig, AutoModelForTokenClassification >>> >>> model = AutoModelForTokenClassification.from_pretrained("google-bert/bert-base-cased") >>> >>> model = AutoModelForTokenClassification.from_pretrained("google-bert/bert-base-cased", output_attentions=True) >>> model.config.output_attentions True >>> >>> 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 ... )TFAutoModelForTokenClassification class transformers.TFAutoModelForTokenClassification < source >
( *args **kwargs )
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 the from_config() class method.
This class cannot be instantiated directly using __init__()
(throws an error).
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.
Examples:
>>> from transformers import AutoConfig, TFAutoModelForTokenClassification >>> >>> config = AutoConfig.from_pretrained("google-bert/bert-base-cased") >>> model = TFAutoModelForTokenClassification.from_config(config)from_pretrained < source >
( *model_args **kwargs )
Parameters
str
or os.PathLike
) — Can be either:
./my_model_directory/
../pt_model/pytorch_model.bin
). In this case, from_pt
should be set to True
and a configuration object should be provided as config
argument. 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.__init__()
method. pretrained_model_name_or_path
and a configuration JSON file named config.json is found in the directory.str
or os.PathLike
, optional) — Path to a directory in which a downloaded pretrained model configuration should be cached if the standard cache should not be used. bool
, optional, defaults to False
) — Load the model weights from a PyTorch checkpoint save file (see docstring of pretrained_model_name_or_path
argument). bool
, optional, defaults to False
) — Whether or not to force the (re-)download of the model weights and configuration files, overriding the cached versions if they exist. 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. bool
, optional, defaults to False
) — Whether ot not to also return a dictionary containing missing keys, unexpected keys and error messages. bool
, optional, defaults to False
) — Whether or not to only look at local files (e.g., not try downloading the model). 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 revision
can be any identifier allowed by git. bool
, optional, defaults to False
) — Whether or not to allow for custom models defined on the Hub in their own modeling files. This option should only be set to True
for repositories you trust and in which you have read the code, as it will execute code present on the Hub on your local machine. str
, optional, defaults to "main"
) — The specific revision to use for the code on the Hub, if the code leaves in a different repository than the rest of the model. 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 revision
can be any identifier allowed by git. output_attentions=True
). Behaves differently depending on whether a config
is provided or automatically loaded:
config
, **kwargs
will be directly passed to the underlying model’s __init__
method (we assume all relevant updates to the configuration have already been done)kwargs
will be first passed to the configuration class initialization function (from_pretrained()). Each key of kwargs
that corresponds to a configuration attribute will be used to override said attribute with the supplied kwargs
value. Remaining keys that do not correspond to any configuration attribute will be passed to the underlying model’s __init__
function.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_type
property of the config object (either passed as an argument or loaded from pretrained_model_name_or_path
if possible), or when it’s missing, by falling back to using pattern matching on pretrained_model_name_or_path
:
Examples:
>>> from transformers import AutoConfig, TFAutoModelForTokenClassification >>> >>> model = TFAutoModelForTokenClassification.from_pretrained("google-bert/bert-base-cased") >>> >>> model = TFAutoModelForTokenClassification.from_pretrained("google-bert/bert-base-cased", output_attentions=True) >>> model.config.output_attentions True >>> >>> 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 ... )FlaxAutoModelForTokenClassification class transformers.FlaxAutoModelForTokenClassification < source >
( *args **kwargs )
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 the from_config() class method.
This class cannot be instantiated directly using __init__()
(throws an error).
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.
Examples:
>>> from transformers import AutoConfig, FlaxAutoModelForTokenClassification >>> >>> config = AutoConfig.from_pretrained("google-bert/bert-base-cased") >>> model = FlaxAutoModelForTokenClassification.from_config(config)from_pretrained < source >
( *model_args **kwargs )
Parameters
str
or os.PathLike
) — Can be either:
./my_model_directory/
../pt_model/pytorch_model.bin
). In this case, from_pt
should be set to True
and a configuration object should be provided as config
argument. 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.__init__()
method. pretrained_model_name_or_path
and a configuration JSON file named config.json is found in the directory.str
or os.PathLike
, optional) — Path to a directory in which a downloaded pretrained model configuration should be cached if the standard cache should not be used. bool
, optional, defaults to False
) — Load the model weights from a PyTorch checkpoint save file (see docstring of pretrained_model_name_or_path
argument). bool
, optional, defaults to False
) — Whether or not to force the (re-)download of the model weights and configuration files, overriding the cached versions if they exist. 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. bool
, optional, defaults to False
) — Whether ot not to also return a dictionary containing missing keys, unexpected keys and error messages. bool
, optional, defaults to False
) — Whether or not to only look at local files (e.g., not try downloading the model). 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 revision
can be any identifier allowed by git. bool
, optional, defaults to False
) — Whether or not to allow for custom models defined on the Hub in their own modeling files. This option should only be set to True
for repositories you trust and in which you have read the code, as it will execute code present on the Hub on your local machine. str
, optional, defaults to "main"
) — The specific revision to use for the code on the Hub, if the code leaves in a different repository than the rest of the model. 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 revision
can be any identifier allowed by git. output_attentions=True
). Behaves differently depending on whether a config
is provided or automatically loaded:
config
, **kwargs
will be directly passed to the underlying model’s __init__
method (we assume all relevant updates to the configuration have already been done)kwargs
will be first passed to the configuration class initialization function (from_pretrained()). Each key of kwargs
that corresponds to a configuration attribute will be used to override said attribute with the supplied kwargs
value. Remaining keys that do not correspond to any configuration attribute will be passed to the underlying model’s __init__
function.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_type
property of the config object (either passed as an argument or loaded from pretrained_model_name_or_path
if possible), or when it’s missing, by falling back to using pattern matching on pretrained_model_name_or_path
:
Examples:
>>> from transformers import AutoConfig, FlaxAutoModelForTokenClassification >>> >>> model = FlaxAutoModelForTokenClassification.from_pretrained("google-bert/bert-base-cased") >>> >>> model = FlaxAutoModelForTokenClassification.from_pretrained("google-bert/bert-base-cased", output_attentions=True) >>> model.config.output_attentions True >>> >>> 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 ... )AutoModelForQuestionAnswering class transformers.AutoModelForQuestionAnswering < source >
( *args **kwargs )
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 the from_config() class method.
This class cannot be instantiated directly using __init__()
(throws an error).
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.
Examples:
>>> from transformers import AutoConfig, AutoModelForQuestionAnswering >>> >>> config = AutoConfig.from_pretrained("google-bert/bert-base-cased") >>> model = AutoModelForQuestionAnswering.from_config(config)from_pretrained < source >
( *model_args **kwargs )
Parameters
str
or os.PathLike
) — Can be either:
./my_model_directory/
../tf_model/model.ckpt.index
). In this case, from_tf
should be set to True
and a configuration object should be provided as config
argument. 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.__init__()
method. pretrained_model_name_or_path
and a configuration JSON file named config.json is found in the directory.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() and from_pretrained() is not a simpler option.
str
or os.PathLike
, optional) — Path to a directory in which a downloaded pretrained model configuration should be cached if the standard cache should not be used. bool
, optional, defaults to False
) — Load the model weights from a TensorFlow checkpoint save file (see docstring of pretrained_model_name_or_path
argument). bool
, optional, defaults to False
) — Whether or not to force the (re-)download of the model weights and configuration files, overriding the cached versions if they exist. 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. bool
, optional, defaults to False
) — Whether ot not to also return a dictionary containing missing keys, unexpected keys and error messages. bool
, optional, defaults to False
) — Whether or not to only look at local files (e.g., not try downloading the model). 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 revision
can be any identifier allowed by git. bool
, optional, defaults to False
) — Whether or not to allow for custom models defined on the Hub in their own modeling files. This option should only be set to True
for repositories you trust and in which you have read the code, as it will execute code present on the Hub on your local machine. str
, optional, defaults to "main"
) — The specific revision to use for the code on the Hub, if the code leaves in a different repository than the rest of the model. 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 revision
can be any identifier allowed by git. output_attentions=True
). Behaves differently depending on whether a config
is provided or automatically loaded:
config
, **kwargs
will be directly passed to the underlying model’s __init__
method (we assume all relevant updates to the configuration have already been done)kwargs
will be first passed to the configuration class initialization function (from_pretrained()). Each key of kwargs
that corresponds to a configuration attribute will be used to override said attribute with the supplied kwargs
value. Remaining keys that do not correspond to any configuration attribute will be passed to the underlying model’s __init__
function.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_type
property of the config object (either passed as an argument or loaded from pretrained_model_name_or_path
if possible), or when it’s missing, by falling back to using pattern matching on pretrained_model_name_or_path
:
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 with model.train()
Examples:
>>> from transformers import AutoConfig, AutoModelForQuestionAnswering >>> >>> model = AutoModelForQuestionAnswering.from_pretrained("google-bert/bert-base-cased") >>> >>> model = AutoModelForQuestionAnswering.from_pretrained("google-bert/bert-base-cased", output_attentions=True) >>> model.config.output_attentions True >>> >>> 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 ... )TFAutoModelForQuestionAnswering class transformers.TFAutoModelForQuestionAnswering < source >
( *args **kwargs )
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 the from_config() class method.
This class cannot be instantiated directly using __init__()
(throws an error).
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.
Examples:
>>> from transformers import AutoConfig, TFAutoModelForQuestionAnswering >>> >>> config = AutoConfig.from_pretrained("google-bert/bert-base-cased") >>> model = TFAutoModelForQuestionAnswering.from_config(config)from_pretrained < source >
( *model_args **kwargs )
Parameters
str
or os.PathLike
) — Can be either:
./my_model_directory/
../pt_model/pytorch_model.bin
). In this case, from_pt
should be set to True
and a configuration object should be provided as config
argument. 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.__init__()
method. pretrained_model_name_or_path
and a configuration JSON file named config.json is found in the directory.str
or os.PathLike
, optional) — Path to a directory in which a downloaded pretrained model configuration should be cached if the standard cache should not be used. bool
, optional, defaults to False
) — Load the model weights from a PyTorch checkpoint save file (see docstring of pretrained_model_name_or_path
argument). bool
, optional, defaults to False
) — Whether or not to force the (re-)download of the model weights and configuration files, overriding the cached versions if they exist. 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. bool
, optional, defaults to False
) — Whether ot not to also return a dictionary containing missing keys, unexpected keys and error messages. bool
, optional, defaults to False
) — Whether or not to only look at local files (e.g., not try downloading the model). 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 revision
can be any identifier allowed by git. bool
, optional, defaults to False
) — Whether or not to allow for custom models defined on the Hub in their own modeling files. This option should only be set to True
for repositories you trust and in which you have read the code, as it will execute code present on the Hub on your local machine. str
, optional, defaults to "main"
) — The specific revision to use for the code on the Hub, if the code leaves in a different repository than the rest of the model. 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 revision
can be any identifier allowed by git. output_attentions=True
). Behaves differently depending on whether a config
is provided or automatically loaded:
config
, **kwargs
will be directly passed to the underlying model’s __init__
method (we assume all relevant updates to the configuration have already been done)kwargs
will be first passed to the configuration class initialization function (from_pretrained()). Each key of kwargs
that corresponds to a configuration attribute will be used to override said attribute with the supplied kwargs
value. Remaining keys that do not correspond to any configuration attribute will be passed to the underlying model’s __init__
function.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_type
property of the config object (either passed as an argument or loaded from pretrained_model_name_or_path
if possible), or when it’s missing, by falling back to using pattern matching on pretrained_model_name_or_path
:
Examples:
>>> from transformers import AutoConfig, TFAutoModelForQuestionAnswering >>> >>> model = TFAutoModelForQuestionAnswering.from_pretrained("google-bert/bert-base-cased") >>> >>> model = TFAutoModelForQuestionAnswering.from_pretrained("google-bert/bert-base-cased", output_attentions=True) >>> model.config.output_attentions True >>> >>> 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 ... )FlaxAutoModelForQuestionAnswering class transformers.FlaxAutoModelForQuestionAnswering < source >
( *args **kwargs )
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 the from_config() class method.
This class cannot be instantiated directly using __init__()
(throws an error).
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.
Examples:
>>> from transformers import AutoConfig, FlaxAutoModelForQuestionAnswering >>> >>> config = AutoConfig.from_pretrained("google-bert/bert-base-cased") >>> model = FlaxAutoModelForQuestionAnswering.from_config(config)from_pretrained < source >
( *model_args **kwargs )
Parameters
str
or os.PathLike
) — Can be either:
./my_model_directory/
../pt_model/pytorch_model.bin
). In this case, from_pt
should be set to True
and a configuration object should be provided as config
argument. 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.__init__()
method. pretrained_model_name_or_path
and a configuration JSON file named config.json is found in the directory.str
or os.PathLike
, optional) — Path to a directory in which a downloaded pretrained model configuration should be cached if the standard cache should not be used. bool
, optional, defaults to False
) — Load the model weights from a PyTorch checkpoint save file (see docstring of pretrained_model_name_or_path
argument). bool
, optional, defaults to False
) — Whether or not to force the (re-)download of the model weights and configuration files, overriding the cached versions if they exist. 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. bool
, optional, defaults to False
) — Whether ot not to also return a dictionary containing missing keys, unexpected keys and error messages. bool
, optional, defaults to False
) — Whether or not to only look at local files (e.g., not try downloading the model). 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 revision
can be any identifier allowed by git. bool
, optional, defaults to False
) — Whether or not to allow for custom models defined on the Hub in their own modeling files. This option should only be set to True
for repositories you trust and in which you have read the code, as it will execute code present on the Hub on your local machine. str
, optional, defaults to "main"
) — The specific revision to use for the code on the Hub, if the code leaves in a different repository than the rest of the model. 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 revision
can be any identifier allowed by git. output_attentions=True
). Behaves differently depending on whether a config
is provided or automatically loaded:
config
, **kwargs
will be directly passed to the underlying model’s __init__
method (we assume all relevant updates to the configuration have already been done)kwargs
will be first passed to the configuration class initialization function (from_pretrained()). Each key of kwargs
that corresponds to a configuration attribute will be used to override said attribute with the supplied kwargs
value. Remaining keys that do not correspond to any configuration attribute will be passed to the underlying model’s __init__
function.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_type
property of the config object (either passed as an argument or loaded from pretrained_model_name_or_path
if possible), or when it’s missing, by falling back to using pattern matching on pretrained_model_name_or_path
:
Examples:
>>> from transformers import AutoConfig, FlaxAutoModelForQuestionAnswering >>> >>> model = FlaxAutoModelForQuestionAnswering.from_pretrained("google-bert/bert-base-cased") >>> >>> model = FlaxAutoModelForQuestionAnswering.from_pretrained("google-bert/bert-base-cased", output_attentions=True) >>> model.config.output_attentions True >>> >>> 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 ... )AutoModelForTextEncoding class transformers.AutoModelForTextEncoding < source >
( *args **kwargs )
TFAutoModelForTextEncoding class transformers.TFAutoModelForTextEncoding < source >( *args **kwargs )
Computer visionThe following auto classes are available for the following computer vision tasks.
AutoModelForDepthEstimation class transformers.AutoModelForDepthEstimation < source >( *args **kwargs )
This is a generic model class that will be instantiated as one of the model classes of the library (with a depth estimation head) when created with the from_pretrained() class method or the from_config() class method.
This class cannot be instantiated directly using __init__()
(throws an error).
Instantiates one of the model classes of the library (with a depth estimation 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.
Examples:
>>> from transformers import AutoConfig, AutoModelForDepthEstimation >>> >>> config = AutoConfig.from_pretrained("google-bert/bert-base-cased") >>> model = AutoModelForDepthEstimation.from_config(config)from_pretrained < source >
( *model_args **kwargs )
Parameters
str
or os.PathLike
) — Can be either:
./my_model_directory/
../tf_model/model.ckpt.index
). In this case, from_tf
should be set to True
and a configuration object should be provided as config
argument. 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.__init__()
method. pretrained_model_name_or_path
and a configuration JSON file named config.json is found in the directory.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() and from_pretrained() is not a simpler option.
str
or os.PathLike
, optional) — Path to a directory in which a downloaded pretrained model configuration should be cached if the standard cache should not be used. bool
, optional, defaults to False
) — Load the model weights from a TensorFlow checkpoint save file (see docstring of pretrained_model_name_or_path
argument). bool
, optional, defaults to False
) — Whether or not to force the (re-)download of the model weights and configuration files, overriding the cached versions if they exist. 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. bool
, optional, defaults to False
) — Whether ot not to also return a dictionary containing missing keys, unexpected keys and error messages. bool
, optional, defaults to False
) — Whether or not to only look at local files (e.g., not try downloading the model). 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 revision
can be any identifier allowed by git. bool
, optional, defaults to False
) — Whether or not to allow for custom models defined on the Hub in their own modeling files. This option should only be set to True
for repositories you trust and in which you have read the code, as it will execute code present on the Hub on your local machine. str
, optional, defaults to "main"
) — The specific revision to use for the code on the Hub, if the code leaves in a different repository than the rest of the model. 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 revision
can be any identifier allowed by git. output_attentions=True
). Behaves differently depending on whether a config
is provided or automatically loaded:
config
, **kwargs
will be directly passed to the underlying model’s __init__
method (we assume all relevant updates to the configuration have already been done)kwargs
will be first passed to the configuration class initialization function (from_pretrained()). Each key of kwargs
that corresponds to a configuration attribute will be used to override said attribute with the supplied kwargs
value. Remaining keys that do not correspond to any configuration attribute will be passed to the underlying model’s __init__
function.Instantiate one of the model classes of the library (with a depth estimation head) from a pretrained model.
The model class to instantiate is selected based on the model_type
property of the config object (either passed as an argument or loaded from pretrained_model_name_or_path
if possible), or when it’s missing, by falling back to using pattern matching on pretrained_model_name_or_path
:
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 with model.train()
Examples:
>>> from transformers import AutoConfig, AutoModelForDepthEstimation >>> >>> model = AutoModelForDepthEstimation.from_pretrained("google-bert/bert-base-cased") >>> >>> model = AutoModelForDepthEstimation.from_pretrained("google-bert/bert-base-cased", output_attentions=True) >>> model.config.output_attentions True >>> >>> config = AutoConfig.from_pretrained("./tf_model/bert_tf_model_config.json") >>> model = AutoModelForDepthEstimation.from_pretrained( ... "./tf_model/bert_tf_checkpoint.ckpt.index", from_tf=True, config=config ... )AutoModelForImageClassification class transformers.AutoModelForImageClassification < source >
( *args **kwargs )
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 the from_config() class method.
This class cannot be instantiated directly using __init__()
(throws an error).
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.
Examples:
>>> from transformers import AutoConfig, AutoModelForImageClassification >>> >>> config = AutoConfig.from_pretrained("google-bert/bert-base-cased") >>> model = AutoModelForImageClassification.from_config(config)from_pretrained < source >
( *model_args **kwargs )
Parameters
str
or os.PathLike
) — Can be either:
./my_model_directory/
../tf_model/model.ckpt.index
). In this case, from_tf
should be set to True
and a configuration object should be provided as config
argument. 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.__init__()
method. pretrained_model_name_or_path
and a configuration JSON file named config.json is found in the directory.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() and from_pretrained() is not a simpler option.
str
or os.PathLike
, optional) — Path to a directory in which a downloaded pretrained model configuration should be cached if the standard cache should not be used. bool
, optional, defaults to False
) — Load the model weights from a TensorFlow checkpoint save file (see docstring of pretrained_model_name_or_path
argument). bool
, optional, defaults to False
) — Whether or not to force the (re-)download of the model weights and configuration files, overriding the cached versions if they exist. 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. bool
, optional, defaults to False
) — Whether ot not to also return a dictionary containing missing keys, unexpected keys and error messages. bool
, optional, defaults to False
) — Whether or not to only look at local files (e.g., not try downloading the model). 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 revision
can be any identifier allowed by git. bool
, optional, defaults to False
) — Whether or not to allow for custom models defined on the Hub in their own modeling files. This option should only be set to True
for repositories you trust and in which you have read the code, as it will execute code present on the Hub on your local machine. str
, optional, defaults to "main"
) — The specific revision to use for the code on the Hub, if the code leaves in a different repository than the rest of the model. 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 revision
can be any identifier allowed by git. output_attentions=True
). Behaves differently depending on whether a config
is provided or automatically loaded:
config
, **kwargs
will be directly passed to the underlying model’s __init__
method (we assume all relevant updates to the configuration have already been done)kwargs
will be first passed to the configuration class initialization function (from_pretrained()). Each key of kwargs
that corresponds to a configuration attribute will be used to override said attribute with the supplied kwargs
value. Remaining keys that do not correspond to any configuration attribute will be passed to the underlying model’s __init__
function.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_type
property of the config object (either passed as an argument or loaded from pretrained_model_name_or_path
if possible), or when it’s missing, by falling back to using pattern matching on pretrained_model_name_or_path
:
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 with model.train()
Examples:
>>> from transformers import AutoConfig, AutoModelForImageClassification >>> >>> model = AutoModelForImageClassification.from_pretrained("google-bert/bert-base-cased") >>> >>> model = AutoModelForImageClassification.from_pretrained("google-bert/bert-base-cased", output_attentions=True) >>> model.config.output_attentions True >>> >>> 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 ... )TFAutoModelForImageClassification class transformers.TFAutoModelForImageClassification < source >
( *args **kwargs )
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 the from_config() class method.
This class cannot be instantiated directly using __init__()
(throws an error).
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.
Examples:
>>> from transformers import AutoConfig, TFAutoModelForImageClassification >>> >>> config = AutoConfig.from_pretrained("google-bert/bert-base-cased") >>> model = TFAutoModelForImageClassification.from_config(config)from_pretrained < source >
( *model_args **kwargs )
Parameters
str
or os.PathLike
) — Can be either:
./my_model_directory/
../pt_model/pytorch_model.bin
). In this case, from_pt
should be set to True
and a configuration object should be provided as config
argument. 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.__init__()
method. pretrained_model_name_or_path
and a configuration JSON file named config.json is found in the directory.str
or os.PathLike
, optional) — Path to a directory in which a downloaded pretrained model configuration should be cached if the standard cache should not be used. bool
, optional, defaults to False
) — Load the model weights from a PyTorch checkpoint save file (see docstring of pretrained_model_name_or_path
argument). bool
, optional, defaults to False
) — Whether or not to force the (re-)download of the model weights and configuration files, overriding the cached versions if they exist. 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. bool
, optional, defaults to False
) — Whether ot not to also return a dictionary containing missing keys, unexpected keys and error messages. bool
, optional, defaults to False
) — Whether or not to only look at local files (e.g., not try downloading the model). 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 revision
can be any identifier allowed by git. bool
, optional, defaults to False
) — Whether or not to allow for custom models defined on the Hub in their own modeling files. This option should only be set to True
for repositories you trust and in which you have read the code, as it will execute code present on the Hub on your local machine. str
, optional, defaults to "main"
) — The specific revision to use for the code on the Hub, if the code leaves in a different repository than the rest of the model. 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 revision
can be any identifier allowed by git. output_attentions=True
). Behaves differently depending on whether a config
is provided or automatically loaded:
config
, **kwargs
will be directly passed to the underlying model’s __init__
method (we assume all relevant updates to the configuration have already been done)kwargs
will be first passed to the configuration class initialization function (from_pretrained()). Each key of kwargs
that corresponds to a configuration attribute will be used to override said attribute with the supplied kwargs
value. Remaining keys that do not correspond to any configuration attribute will be passed to the underlying model’s __init__
function.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_type
property of the config object (either passed as an argument or loaded from pretrained_model_name_or_path
if possible), or when it’s missing, by falling back to using pattern matching on pretrained_model_name_or_path
:
Examples:
>>> from transformers import AutoConfig, TFAutoModelForImageClassification >>> >>> model = TFAutoModelForImageClassification.from_pretrained("google-bert/bert-base-cased") >>> >>> model = TFAutoModelForImageClassification.from_pretrained("google-bert/bert-base-cased", output_attentions=True) >>> model.config.output_attentions True >>> >>> config = AutoConfig.from_pretrained("./pt_model/bert_pt_model_config.json") >>> model = TFAutoModelForImageClassification.from_pretrained( ... "./pt_model/bert_pytorch_model.bin", from_pt=True, config=config ... )FlaxAutoModelForImageClassification class transformers.FlaxAutoModelForImageClassification < source >
( *args **kwargs )
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 the from_config() class method.
This class cannot be instantiated directly using __init__()
(throws an error).
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.
Examples:
>>> from transformers import AutoConfig, FlaxAutoModelForImageClassification >>> >>> config = AutoConfig.from_pretrained("google-bert/bert-base-cased") >>> model = FlaxAutoModelForImageClassification.from_config(config)from_pretrained < source >
( *model_args **kwargs )
Parameters
str
or os.PathLike
) — Can be either:
./my_model_directory/
../pt_model/pytorch_model.bin
). In this case, from_pt
should be set to True
and a configuration object should be provided as config
argument. 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.__init__()
method. pretrained_model_name_or_path
and a configuration JSON file named config.json is found in the directory.str
or os.PathLike
, optional) — Path to a directory in which a downloaded pretrained model configuration should be cached if the standard cache should not be used. bool
, optional, defaults to False
) — Load the model weights from a PyTorch checkpoint save file (see docstring of pretrained_model_name_or_path
argument). bool
, optional, defaults to False
) — Whether or not to force the (re-)download of the model weights and configuration files, overriding the cached versions if they exist. 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. bool
, optional, defaults to False
) — Whether ot not to also return a dictionary containing missing keys, unexpected keys and error messages. bool
, optional, defaults to False
) — Whether or not to only look at local files (e.g., not try downloading the model). 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 revision
can be any identifier allowed by git. bool
, optional, defaults to False
) — Whether or not to allow for custom models defined on the Hub in their own modeling files. This option should only be set to True
for repositories you trust and in which you have read the code, as it will execute code present on the Hub on your local machine. str
, optional, defaults to "main"
) — The specific revision to use for the code on the Hub, if the code leaves in a different repository than the rest of the model. 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 revision
can be any identifier allowed by git. output_attentions=True
). Behaves differently depending on whether a config
is provided or automatically loaded:
config
, **kwargs
will be directly passed to the underlying model’s __init__
method (we assume all relevant updates to the configuration have already been done)kwargs
will be first passed to the configuration class initialization function (from_pretrained()). Each key of kwargs
that corresponds to a configuration attribute will be used to override said attribute with the supplied kwargs
value. Remaining keys that do not correspond to any configuration attribute will be passed to the underlying model’s __init__
function.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_type
property of the config object (either passed as an argument or loaded from pretrained_model_name_or_path
if possible), or when it’s missing, by falling back to using pattern matching on pretrained_model_name_or_path
:
Examples:
>>> from transformers import AutoConfig, FlaxAutoModelForImageClassification >>> >>> model = FlaxAutoModelForImageClassification.from_pretrained("google-bert/bert-base-cased") >>> >>> model = FlaxAutoModelForImageClassification.from_pretrained("google-bert/bert-base-cased", output_attentions=True) >>> model.config.output_attentions True >>> >>> 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 ... )AutoModelForVideoClassification class transformers.AutoModelForVideoClassification < source >
( *args **kwargs )
This is a generic model class that will be instantiated as one of the model classes of the library (with a video classification head) when created with the from_pretrained() class method or the from_config() class method.
This class cannot be instantiated directly using __init__()
(throws an error).
Instantiates one of the model classes of the library (with a video 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.
Examples:
>>> from transformers import AutoConfig, AutoModelForVideoClassification >>> >>> config = AutoConfig.from_pretrained("google-bert/bert-base-cased") >>> model = AutoModelForVideoClassification.from_config(config)from_pretrained < source >
( *model_args **kwargs )
Parameters
str
or os.PathLike
) — Can be either:
./my_model_directory/
../tf_model/model.ckpt.index
). In this case, from_tf
should be set to True
and a configuration object should be provided as config
argument. 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.__init__()
method. pretrained_model_name_or_path
and a configuration JSON file named config.json is found in the directory.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() and from_pretrained() is not a simpler option.
str
or os.PathLike
, optional) — Path to a directory in which a downloaded pretrained model configuration should be cached if the standard cache should not be used. bool
, optional, defaults to False
) — Load the model weights from a TensorFlow checkpoint save file (see docstring of pretrained_model_name_or_path
argument). bool
, optional, defaults to False
) — Whether or not to force the (re-)download of the model weights and configuration files, overriding the cached versions if they exist. 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. bool
, optional, defaults to False
) — Whether ot not to also return a dictionary containing missing keys, unexpected keys and error messages. bool
, optional, defaults to False
) — Whether or not to only look at local files (e.g., not try downloading the model). 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 revision
can be any identifier allowed by git. bool
, optional, defaults to False
) — Whether or not to allow for custom models defined on the Hub in their own modeling files. This option should only be set to True
for repositories you trust and in which you have read the code, as it will execute code present on the Hub on your local machine. str
, optional, defaults to "main"
) — The specific revision to use for the code on the Hub, if the code leaves in a different repository than the rest of the model. 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 revision
can be any identifier allowed by git. output_attentions=True
). Behaves differently depending on whether a config
is provided or automatically loaded:
config
, **kwargs
will be directly passed to the underlying model’s __init__
method (we assume all relevant updates to the configuration have already been done)kwargs
will be first passed to the configuration class initialization function (from_pretrained()). Each key of kwargs
that corresponds to a configuration attribute will be used to override said attribute with the supplied kwargs
value. Remaining keys that do not correspond to any configuration attribute will be passed to the underlying model’s __init__
function.Instantiate one of the model classes of the library (with a video classification head) from a pretrained model.
The model class to instantiate is selected based on the model_type
property of the config object (either passed as an argument or loaded from pretrained_model_name_or_path
if possible), or when it’s missing, by falling back to using pattern matching on pretrained_model_name_or_path
:
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 with model.train()
Examples:
>>> from transformers import AutoConfig, AutoModelForVideoClassification >>> >>> model = AutoModelForVideoClassification.from_pretrained("google-bert/bert-base-cased") >>> >>> model = AutoModelForVideoClassification.from_pretrained("google-bert/bert-base-cased", output_attentions=True) >>> model.config.output_attentions True >>> >>> config = AutoConfig.from_pretrained("./tf_model/bert_tf_model_config.json") >>> model = AutoModelForVideoClassification.from_pretrained( ... "./tf_model/bert_tf_checkpoint.ckpt.index", from_tf=True, config=config ... )AutoModelForKeypointDetection class transformers.AutoModelForKeypointDetection < source >
( *args **kwargs )
AutoModelForMaskedImageModeling class transformers.AutoModelForMaskedImageModeling < source >( *args **kwargs )
This is a generic model class that will be instantiated as one of the model classes of the library (with a masked image modeling head) when created with the from_pretrained() class method or the from_config() class method.
This class cannot be instantiated directly using __init__()
(throws an error).
Instantiates one of the model classes of the library (with a masked image 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.
Examples:
>>> from transformers import AutoConfig, AutoModelForMaskedImageModeling >>> >>> config = AutoConfig.from_pretrained("google-bert/bert-base-cased") >>> model = AutoModelForMaskedImageModeling.from_config(config)from_pretrained < source >
( *model_args **kwargs )
Parameters
str
or os.PathLike
) — Can be either:
./my_model_directory/
../tf_model/model.ckpt.index
). In this case, from_tf
should be set to True
and a configuration object should be provided as config
argument. 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.__init__()
method. pretrained_model_name_or_path
and a configuration JSON file named config.json is found in the directory.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() and from_pretrained() is not a simpler option.
str
or os.PathLike
, optional) — Path to a directory in which a downloaded pretrained model configuration should be cached if the standard cache should not be used. bool
, optional, defaults to False
) — Load the model weights from a TensorFlow checkpoint save file (see docstring of pretrained_model_name_or_path
argument). bool
, optional, defaults to False
) — Whether or not to force the (re-)download of the model weights and configuration files, overriding the cached versions if they exist. 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. bool
, optional, defaults to False
) — Whether ot not to also return a dictionary containing missing keys, unexpected keys and error messages. bool
, optional, defaults to False
) — Whether or not to only look at local files (e.g., not try downloading the model). 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 revision
can be any identifier allowed by git. bool
, optional, defaults to False
) — Whether or not to allow for custom models defined on the Hub in their own modeling files. This option should only be set to True
for repositories you trust and in which you have read the code, as it will execute code present on the Hub on your local machine. str
, optional, defaults to "main"
) — The specific revision to use for the code on the Hub, if the code leaves in a different repository than the rest of the model. 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 revision
can be any identifier allowed by git. output_attentions=True
). Behaves differently depending on whether a config
is provided or automatically loaded:
config
, **kwargs
will be directly passed to the underlying model’s __init__
method (we assume all relevant updates to the configuration have already been done)kwargs
will be first passed to the configuration class initialization function (from_pretrained()). Each key of kwargs
that corresponds to a configuration attribute will be used to override said attribute with the supplied kwargs
value. Remaining keys that do not correspond to any configuration attribute will be passed to the underlying model’s __init__
function.Instantiate one of the model classes of the library (with a masked image modeling head) from a pretrained model.
The model class to instantiate is selected based on the model_type
property of the config object (either passed as an argument or loaded from pretrained_model_name_or_path
if possible), or when it’s missing, by falling back to using pattern matching on pretrained_model_name_or_path
:
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 with model.train()
Examples:
>>> from transformers import AutoConfig, AutoModelForMaskedImageModeling >>> >>> model = AutoModelForMaskedImageModeling.from_pretrained("google-bert/bert-base-cased") >>> >>> model = AutoModelForMaskedImageModeling.from_pretrained("google-bert/bert-base-cased", output_attentions=True) >>> model.config.output_attentions True >>> >>> config = AutoConfig.from_pretrained("./tf_model/bert_tf_model_config.json") >>> model = AutoModelForMaskedImageModeling.from_pretrained( ... "./tf_model/bert_tf_checkpoint.ckpt.index", from_tf=True, config=config ... )TFAutoModelForMaskedImageModeling class transformers.TFAutoModelForMaskedImageModeling < source >
( *args **kwargs )
This is a generic model class that will be instantiated as one of the model classes of the library (with a masked image modeling head) when created with the from_pretrained() class method or the from_config() class method.
This class cannot be instantiated directly using __init__()
(throws an error).
Instantiates one of the model classes of the library (with a masked image 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.
Examples:
>>> from transformers import AutoConfig, TFAutoModelForMaskedImageModeling >>> >>> config = AutoConfig.from_pretrained("google-bert/bert-base-cased") >>> model = TFAutoModelForMaskedImageModeling.from_config(config)from_pretrained < source >
( *model_args **kwargs )
Parameters
str
or os.PathLike
) — Can be either:
./my_model_directory/
../pt_model/pytorch_model.bin
). In this case, from_pt
should be set to True
and a configuration object should be provided as config
argument. 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.__init__()
method. pretrained_model_name_or_path
and a configuration JSON file named config.json is found in the directory.str
or os.PathLike
, optional) — Path to a directory in which a downloaded pretrained model configuration should be cached if the standard cache should not be used. bool
, optional, defaults to False
) — Load the model weights from a PyTorch checkpoint save file (see docstring of pretrained_model_name_or_path
argument). bool
, optional, defaults to False
) — Whether or not to force the (re-)download of the model weights and configuration files, overriding the cached versions if they exist. 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. bool
, optional, defaults to False
) — Whether ot not to also return a dictionary containing missing keys, unexpected keys and error messages. bool
, optional, defaults to False
) — Whether or not to only look at local files (e.g., not try downloading the model). 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 revision
can be any identifier allowed by git. bool
, optional, defaults to False
) — Whether or not to allow for custom models defined on the Hub in their own modeling files. This option should only be set to True
for repositories you trust and in which you have read the code, as it will execute code present on the Hub on your local machine. str
, optional, defaults to "main"
) — The specific revision to use for the code on the Hub, if the code leaves in a different repository than the rest of the model. 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 revision
can be any identifier allowed by git. output_attentions=True
). Behaves differently depending on whether a config
is provided or automatically loaded:
config
, **kwargs
will be directly passed to the underlying model’s __init__
method (we assume all relevant updates to the configuration have already been done)kwargs
will be first passed to the configuration class initialization function (from_pretrained()). Each key of kwargs
that corresponds to a configuration attribute will be used to override said attribute with the supplied kwargs
value. Remaining keys that do not correspond to any configuration attribute will be passed to the underlying model’s __init__
function.Instantiate one of the model classes of the library (with a masked image modeling head) from a pretrained model.
The model class to instantiate is selected based on the model_type
property of the config object (either passed as an argument or loaded from pretrained_model_name_or_path
if possible), or when it’s missing, by falling back to using pattern matching on pretrained_model_name_or_path
:
Examples:
>>> from transformers import AutoConfig, TFAutoModelForMaskedImageModeling >>> >>> model = TFAutoModelForMaskedImageModeling.from_pretrained("google-bert/bert-base-cased") >>> >>> model = TFAutoModelForMaskedImageModeling.from_pretrained("google-bert/bert-base-cased", output_attentions=True) >>> model.config.output_attentions True >>> >>> config = AutoConfig.from_pretrained("./pt_model/bert_pt_model_config.json") >>> model = TFAutoModelForMaskedImageModeling.from_pretrained( ... "./pt_model/bert_pytorch_model.bin", from_pt=True, config=config ... )AutoModelForObjectDetection class transformers.AutoModelForObjectDetection < source >
( *args **kwargs )
This is a generic model class that will be instantiated as one of the model classes of the library (with a object detection head) when created with the from_pretrained() class method or the from_config() class method.
This class cannot be instantiated directly using __init__()
(throws an error).
Instantiates one of the model classes of the library (with a object detection 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.
Examples:
>>> from transformers import AutoConfig, AutoModelForObjectDetection >>> >>> config = AutoConfig.from_pretrained("google-bert/bert-base-cased") >>> model = AutoModelForObjectDetection.from_config(config)from_pretrained < source >
( *model_args **kwargs )
Parameters
str
or os.PathLike
) — Can be either:
./my_model_directory/
../tf_model/model.ckpt.index
). In this case, from_tf
should be set to True
and a configuration object should be provided as config
argument. 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.__init__()
method. pretrained_model_name_or_path
and a configuration JSON file named config.json is found in the directory.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() and from_pretrained() is not a simpler option.
str
or os.PathLike
, optional) — Path to a directory in which a downloaded pretrained model configuration should be cached if the standard cache should not be used. bool
, optional, defaults to False
) — Load the model weights from a TensorFlow checkpoint save file (see docstring of pretrained_model_name_or_path
argument). bool
, optional, defaults to False
) — Whether or not to force the (re-)download of the model weights and configuration files, overriding the cached versions if they exist. 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. bool
, optional, defaults to False
) — Whether ot not to also return a dictionary containing missing keys, unexpected keys and error messages. bool
, optional, defaults to False
) — Whether or not to only look at local files (e.g., not try downloading the model). 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 revision
can be any identifier allowed by git. bool
, optional, defaults to False
) — Whether or not to allow for custom models defined on the Hub in their own modeling files. This option should only be set to True
for repositories you trust and in which you have read the code, as it will execute code present on the Hub on your local machine. str
, optional, defaults to "main"
) — The specific revision to use for the code on the Hub, if the code leaves in a different repository than the rest of the model. 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 revision
can be any identifier allowed by git. output_attentions=True
). Behaves differently depending on whether a config
is provided or automatically loaded:
config
, **kwargs
will be directly passed to the underlying model’s __init__
method (we assume all relevant updates to the configuration have already been done)kwargs
will be first passed to the configuration class initialization function (from_pretrained()). Each key of kwargs
that corresponds to a configuration attribute will be used to override said attribute with the supplied kwargs
value. Remaining keys that do not correspond to any configuration attribute will be passed to the underlying model’s __init__
function.Instantiate one of the model classes of the library (with a object detection head) from a pretrained model.
The model class to instantiate is selected based on the model_type
property of the config object (either passed as an argument or loaded from pretrained_model_name_or_path
if possible), or when it’s missing, by falling back to using pattern matching on pretrained_model_name_or_path
:
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 with model.train()
Examples:
>>> from transformers import AutoConfig, AutoModelForObjectDetection >>> >>> model = AutoModelForObjectDetection.from_pretrained("google-bert/bert-base-cased") >>> >>> model = AutoModelForObjectDetection.from_pretrained("google-bert/bert-base-cased", output_attentions=True) >>> model.config.output_attentions True >>> >>> config = AutoConfig.from_pretrained("./tf_model/bert_tf_model_config.json") >>> model = AutoModelForObjectDetection.from_pretrained( ... "./tf_model/bert_tf_checkpoint.ckpt.index", from_tf=True, config=config ... )AutoModelForImageSegmentation class transformers.AutoModelForImageSegmentation < source >
( *args **kwargs )
This is a generic model class that will be instantiated as one of the model classes of the library (with a image segmentation head) when created with the from_pretrained() class method or the from_config() class method.
This class cannot be instantiated directly using __init__()
(throws an error).
( **kwargs )
Parameters
str
, optional) — The attention implementation to use in the model (if relevant). Can be any of "eager"
(manual implementation of the attention), "sdpa"
(using F.scaled_dot_product_attention
), or "flash_attention_2"
(using Dao-AILab/flash-attention). By default, if available, SDPA will be used for torch>=2.1.1. The default is otherwise the manual "eager"
implementation. Instantiates one of the model classes of the library (with a image segmentation 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.
Examples:
>>> from transformers import AutoConfig, AutoModelForImageSegmentation >>> >>> config = AutoConfig.from_pretrained("google-bert/bert-base-cased") >>> model = AutoModelForImageSegmentation.from_config(config)from_pretrained < source >
( *model_args **kwargs )
Parameters
str
or os.PathLike
) — Can be either:
./my_model_directory/
../tf_model/model.ckpt.index
). In this case, from_tf
should be set to True
and a configuration object should be provided as config
argument. 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.__init__()
method. pretrained_model_name_or_path
and a configuration JSON file named config.json is found in the directory.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() and from_pretrained() is not a simpler option.
str
or os.PathLike
, optional) — Path to a directory in which a downloaded pretrained model configuration should be cached if the standard cache should not be used. bool
, optional, defaults to False
) — Load the model weights from a TensorFlow checkpoint save file (see docstring of pretrained_model_name_or_path
argument). bool
, optional, defaults to False
) — Whether or not to force the (re-)download of the model weights and configuration files, overriding the cached versions if they exist. 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. bool
, optional, defaults to False
) — Whether ot not to also return a dictionary containing missing keys, unexpected keys and error messages. bool
, optional, defaults to False
) — Whether or not to only look at local files (e.g., not try downloading the model). 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 revision
can be any identifier allowed by git. bool
, optional, defaults to False
) — Whether or not to allow for custom models defined on the Hub in their own modeling files. This option should only be set to True
for repositories you trust and in which you have read the code, as it will execute code present on the Hub on your local machine. str
, optional, defaults to "main"
) — The specific revision to use for the code on the Hub, if the code leaves in a different repository than the rest of the model. 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 revision
can be any identifier allowed by git. output_attentions=True
). Behaves differently depending on whether a config
is provided or automatically loaded:
config
, **kwargs
will be directly passed to the underlying model’s __init__
method (we assume all relevant updates to the configuration have already been done)kwargs
will be first passed to the configuration class initialization function (from_pretrained()). Each key of kwargs
that corresponds to a configuration attribute will be used to override said attribute with the supplied kwargs
value. Remaining keys that do not correspond to any configuration attribute will be passed to the underlying model’s __init__
function.Instantiate one of the model classes of the library (with a image segmentation head) from a pretrained model.
The model class to instantiate is selected based on the model_type
property of the config object (either passed as an argument or loaded from pretrained_model_name_or_path
if possible), or when it’s missing, by falling back to using pattern matching on pretrained_model_name_or_path
:
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 with model.train()
Examples:
>>> from transformers import AutoConfig, AutoModelForImageSegmentation >>> >>> model = AutoModelForImageSegmentation.from_pretrained("google-bert/bert-base-cased") >>> >>> model = AutoModelForImageSegmentation.from_pretrained("google-bert/bert-base-cased", output_attentions=True) >>> model.config.output_attentions True >>> >>> config = AutoConfig.from_pretrained("./tf_model/bert_tf_model_config.json") >>> model = AutoModelForImageSegmentation.from_pretrained( ... "./tf_model/bert_tf_checkpoint.ckpt.index", from_tf=True, config=config ... )AutoModelForImageToImage class transformers.AutoModelForImageToImage < source >
( *args **kwargs )
AutoModelForSemanticSegmentation class transformers.AutoModelForSemanticSegmentation < source >( *args **kwargs )
This is a generic model class that will be instantiated as one of the model classes of the library (with a semantic segmentation head) when created with the from_pretrained() class method or the from_config() class method.
This class cannot be instantiated directly using __init__()
(throws an error).
Instantiates one of the model classes of the library (with a semantic segmentation 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.
Examples:
>>> from transformers import AutoConfig, AutoModelForSemanticSegmentation >>> >>> config = AutoConfig.from_pretrained("google-bert/bert-base-cased") >>> model = AutoModelForSemanticSegmentation.from_config(config)from_pretrained < source >
( *model_args **kwargs )
Parameters
str
or os.PathLike
) — Can be either:
./my_model_directory/
../tf_model/model.ckpt.index
). In this case, from_tf
should be set to True
and a configuration object should be provided as config
argument. 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.__init__()
method. pretrained_model_name_or_path
and a configuration JSON file named config.json is found in the directory.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() and from_pretrained() is not a simpler option.
str
or os.PathLike
, optional) — Path to a directory in which a downloaded pretrained model configuration should be cached if the standard cache should not be used. bool
, optional, defaults to False
) — Load the model weights from a TensorFlow checkpoint save file (see docstring of pretrained_model_name_or_path
argument). bool
, optional, defaults to False
) — Whether or not to force the (re-)download of the model weights and configuration files, overriding the cached versions if they exist. 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. bool
, optional, defaults to False
) — Whether ot not to also return a dictionary containing missing keys, unexpected keys and error messages. bool
, optional, defaults to False
) — Whether or not to only look at local files (e.g., not try downloading the model). 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 revision
can be any identifier allowed by git. bool
, optional, defaults to False
) — Whether or not to allow for custom models defined on the Hub in their own modeling files. This option should only be set to True
for repositories you trust and in which you have read the code, as it will execute code present on the Hub on your local machine. str
, optional, defaults to "main"
) — The specific revision to use for the code on the Hub, if the code leaves in a different repository than the rest of the model. 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 revision
can be any identifier allowed by git. output_attentions=True
). Behaves differently depending on whether a config
is provided or automatically loaded:
config
, **kwargs
will be directly passed to the underlying model’s __init__
method (we assume all relevant updates to the configuration have already been done)kwargs
will be first passed to the configuration class initialization function (from_pretrained()). Each key of kwargs
that corresponds to a configuration attribute will be used to override said attribute with the supplied kwargs
value. Remaining keys that do not correspond to any configuration attribute will be passed to the underlying model’s __init__
function.Instantiate one of the model classes of the library (with a semantic segmentation head) from a pretrained model.
The model class to instantiate is selected based on the model_type
property of the config object (either passed as an argument or loaded from pretrained_model_name_or_path
if possible), or when it’s missing, by falling back to using pattern matching on pretrained_model_name_or_path
:
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 with model.train()
Examples:
>>> from transformers import AutoConfig, AutoModelForSemanticSegmentation >>> >>> model = AutoModelForSemanticSegmentation.from_pretrained("google-bert/bert-base-cased") >>> >>> model = AutoModelForSemanticSegmentation.from_pretrained("google-bert/bert-base-cased", output_attentions=True) >>> model.config.output_attentions True >>> >>> config = AutoConfig.from_pretrained("./tf_model/bert_tf_model_config.json") >>> model = AutoModelForSemanticSegmentation.from_pretrained( ... "./tf_model/bert_tf_checkpoint.ckpt.index", from_tf=True, config=config ... )TFAutoModelForSemanticSegmentation class transformers.TFAutoModelForSemanticSegmentation < source >
( *args **kwargs )
This is a generic model class that will be instantiated as one of the model classes of the library (with a semantic segmentation head) when created with the from_pretrained() class method or the from_config() class method.
This class cannot be instantiated directly using __init__()
(throws an error).
Instantiates one of the model classes of the library (with a semantic segmentation 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.
Examples:
>>> from transformers import AutoConfig, TFAutoModelForSemanticSegmentation >>> >>> config = AutoConfig.from_pretrained("google-bert/bert-base-cased") >>> model = TFAutoModelForSemanticSegmentation.from_config(config)from_pretrained < source >
( *model_args **kwargs )
Parameters
str
or os.PathLike
) — Can be either:
./my_model_directory/
../pt_model/pytorch_model.bin
). In this case, from_pt
should be set to True
and a configuration object should be provided as config
argument. 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.__init__()
method. pretrained_model_name_or_path
and a configuration JSON file named config.json is found in the directory.str
or os.PathLike
, optional) — Path to a directory in which a downloaded pretrained model configuration should be cached if the standard cache should not be used. bool
, optional, defaults to False
) — Load the model weights from a PyTorch checkpoint save file (see docstring of pretrained_model_name_or_path
argument). bool
, optional, defaults to False
) — Whether or not to force the (re-)download of the model weights and configuration files, overriding the cached versions if they exist. 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. bool
, optional, defaults to False
) — Whether ot not to also return a dictionary containing missing keys, unexpected keys and error messages. bool
, optional, defaults to False
) — Whether or not to only look at local files (e.g., not try downloading the model). 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 revision
can be any identifier allowed by git. bool
, optional, defaults to False
) — Whether or not to allow for custom models defined on the Hub in their own modeling files. This option should only be set to True
for repositories you trust and in which you have read the code, as it will execute code present on the Hub on your local machine. str
, optional, defaults to "main"
) — The specific revision to use for the code on the Hub, if the code leaves in a different repository than the rest of the model. 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 revision
can be any identifier allowed by git. output_attentions=True
). Behaves differently depending on whether a config
is provided or automatically loaded:
config
, **kwargs
will be directly passed to the underlying model’s __init__
method (we assume all relevant updates to the configuration have already been done)kwargs
will be first passed to the configuration class initialization function (from_pretrained()). Each key of kwargs
that corresponds to a configuration attribute will be used to override said attribute with the supplied kwargs
value. Remaining keys that do not correspond to any configuration attribute will be passed to the underlying model’s __init__
function.Instantiate one of the model classes of the library (with a semantic segmentation head) from a pretrained model.
The model class to instantiate is selected based on the model_type
property of the config object (either passed as an argument or loaded from pretrained_model_name_or_path
if possible), or when it’s missing, by falling back to using pattern matching on pretrained_model_name_or_path
:
Examples:
>>> from transformers import AutoConfig, TFAutoModelForSemanticSegmentation >>> >>> model = TFAutoModelForSemanticSegmentation.from_pretrained("google-bert/bert-base-cased") >>> >>> model = TFAutoModelForSemanticSegmentation.from_pretrained("google-bert/bert-base-cased", output_attentions=True) >>> model.config.output_attentions True >>> >>> config = AutoConfig.from_pretrained("./pt_model/bert_pt_model_config.json") >>> model = TFAutoModelForSemanticSegmentation.from_pretrained( ... "./pt_model/bert_pytorch_model.bin", from_pt=True, config=config ... )AutoModelForInstanceSegmentation class transformers.AutoModelForInstanceSegmentation < source >
( *args **kwargs )
This is a generic model class that will be instantiated as one of the model classes of the library (with a instance segmentation head) when created with the from_pretrained() class method or the from_config() class method.
This class cannot be instantiated directly using __init__()
(throws an error).
Instantiates one of the model classes of the library (with a instance segmentation 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.
Examples:
>>> from transformers import AutoConfig, AutoModelForInstanceSegmentation >>> >>> config = AutoConfig.from_pretrained("google-bert/bert-base-cased") >>> model = AutoModelForInstanceSegmentation.from_config(config)from_pretrained < source >
( *model_args **kwargs )
Parameters
str
or os.PathLike
) — Can be either:
./my_model_directory/
../tf_model/model.ckpt.index
). In this case, from_tf
should be set to True
and a configuration object should be provided as config
argument. 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.__init__()
method. pretrained_model_name_or_path
and a configuration JSON file named config.json is found in the directory.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() and from_pretrained() is not a simpler option.
str
or os.PathLike
, optional) — Path to a directory in which a downloaded pretrained model configuration should be cached if the standard cache should not be used. bool
, optional, defaults to False
) — Load the model weights from a TensorFlow checkpoint save file (see docstring of pretrained_model_name_or_path
argument). bool
, optional, defaults to False
) — Whether or not to force the (re-)download of the model weights and configuration files, overriding the cached versions if they exist. 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. bool
, optional, defaults to False
) — Whether ot not to also return a dictionary containing missing keys, unexpected keys and error messages. bool
, optional, defaults to False
) — Whether or not to only look at local files (e.g., not try downloading the model). 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 revision
can be any identifier allowed by git. bool
, optional, defaults to False
) — Whether or not to allow for custom models defined on the Hub in their own modeling files. This option should only be set to True
for repositories you trust and in which you have read the code, as it will execute code present on the Hub on your local machine. str
, optional, defaults to "main"
) — The specific revision to use for the code on the Hub, if the code leaves in a different repository than the rest of the model. 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 revision
can be any identifier allowed by git. output_attentions=True
). Behaves differently depending on whether a config
is provided or automatically loaded:
config
, **kwargs
will be directly passed to the underlying model’s __init__
method (we assume all relevant updates to the configuration have already been done)kwargs
will be first passed to the configuration class initialization function (from_pretrained()). Each key of kwargs
that corresponds to a configuration attribute will be used to override said attribute with the supplied kwargs
value. Remaining keys that do not correspond to any configuration attribute will be passed to the underlying model’s __init__
function.Instantiate one of the model classes of the library (with a instance segmentation head) from a pretrained model.
The model class to instantiate is selected based on the model_type
property of the config object (either passed as an argument or loaded from pretrained_model_name_or_path
if possible), or when it’s missing, by falling back to using pattern matching on pretrained_model_name_or_path
:
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 with model.train()
Examples:
>>> from transformers import AutoConfig, AutoModelForInstanceSegmentation >>> >>> model = AutoModelForInstanceSegmentation.from_pretrained("google-bert/bert-base-cased") >>> >>> model = AutoModelForInstanceSegmentation.from_pretrained("google-bert/bert-base-cased", output_attentions=True) >>> model.config.output_attentions True >>> >>> config = AutoConfig.from_pretrained("./tf_model/bert_tf_model_config.json") >>> model = AutoModelForInstanceSegmentation.from_pretrained( ... "./tf_model/bert_tf_checkpoint.ckpt.index", from_tf=True, config=config ... )AutoModelForUniversalSegmentation class transformers.AutoModelForUniversalSegmentation < source >
( *args **kwargs )
This is a generic model class that will be instantiated as one of the model classes of the library (with a universal image segmentation head) when created with the from_pretrained() class method or the from_config() class method.
This class cannot be instantiated directly using __init__()
(throws an error).
Instantiates one of the model classes of the library (with a universal image segmentation 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.
Examples:
>>> from transformers import AutoConfig, AutoModelForUniversalSegmentation >>> >>> config = AutoConfig.from_pretrained("google-bert/bert-base-cased") >>> model = AutoModelForUniversalSegmentation.from_config(config)from_pretrained < source >
( *model_args **kwargs )
Parameters
str
or os.PathLike
) — Can be either:
./my_model_directory/
../tf_model/model.ckpt.index
). In this case, from_tf
should be set to True
and a configuration object should be provided as config
argument. 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.__init__()
method. pretrained_model_name_or_path
and a configuration JSON file named config.json is found in the directory.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() and from_pretrained() is not a simpler option.
str
or os.PathLike
, optional) — Path to a directory in which a downloaded pretrained model configuration should be cached if the standard cache should not be used. bool
, optional, defaults to False
) — Load the model weights from a TensorFlow checkpoint save file (see docstring of pretrained_model_name_or_path
argument). bool
, optional, defaults to False
) — Whether or not to force the (re-)download of the model weights and configuration files, overriding the cached versions if they exist. 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. bool
, optional, defaults to False
) — Whether ot not to also return a dictionary containing missing keys, unexpected keys and error messages. bool
, optional, defaults to False
) — Whether or not to only look at local files (e.g., not try downloading the model). 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 revision
can be any identifier allowed by git. bool
, optional, defaults to False
) — Whether or not to allow for custom models defined on the Hub in their own modeling files. This option should only be set to True
for repositories you trust and in which you have read the code, as it will execute code present on the Hub on your local machine. str
, optional, defaults to "main"
) — The specific revision to use for the code on the Hub, if the code leaves in a different repository than the rest of the model. 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 revision
can be any identifier allowed by git. output_attentions=True
). Behaves differently depending on whether a config
is provided or automatically loaded:
config
, **kwargs
will be directly passed to the underlying model’s __init__
method (we assume all relevant updates to the configuration have already been done)kwargs
will be first passed to the configuration class initialization function (from_pretrained()). Each key of kwargs
that corresponds to a configuration attribute will be used to override said attribute with the supplied kwargs
value. Remaining keys that do not correspond to any configuration attribute will be passed to the underlying model’s __init__
function.Instantiate one of the model classes of the library (with a universal image segmentation head) from a pretrained model.
The model class to instantiate is selected based on the model_type
property of the config object (either passed as an argument or loaded from pretrained_model_name_or_path
if possible), or when it’s missing, by falling back to using pattern matching on pretrained_model_name_or_path
:
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 with model.train()
Examples:
>>> from transformers import AutoConfig, AutoModelForUniversalSegmentation >>> >>> model = AutoModelForUniversalSegmentation.from_pretrained("google-bert/bert-base-cased") >>> >>> model = AutoModelForUniversalSegmentation.from_pretrained("google-bert/bert-base-cased", output_attentions=True) >>> model.config.output_attentions True >>> >>> config = AutoConfig.from_pretrained("./tf_model/bert_tf_model_config.json") >>> model = AutoModelForUniversalSegmentation.from_pretrained( ... "./tf_model/bert_tf_checkpoint.ckpt.index", from_tf=True, config=config ... )AutoModelForZeroShotImageClassification class transformers.AutoModelForZeroShotImageClassification < source >
( *args **kwargs )
This is a generic model class that will be instantiated as one of the model classes of the library (with a zero-shot image classification head) when created with the from_pretrained() class method or the from_config() class method.
This class cannot be instantiated directly using __init__()
(throws an error).
Instantiates one of the model classes of the library (with a zero-shot 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.
Examples:
>>> from transformers import AutoConfig, AutoModelForZeroShotImageClassification >>> >>> config = AutoConfig.from_pretrained("google-bert/bert-base-cased") >>> model = AutoModelForZeroShotImageClassification.from_config(config)from_pretrained < source >
( *model_args **kwargs )
Parameters
str
or os.PathLike
) — Can be either:
./my_model_directory/
../tf_model/model.ckpt.index
). In this case, from_tf
should be set to True
and a configuration object should be provided as config
argument. 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.__init__()
method. pretrained_model_name_or_path
and a configuration JSON file named config.json is found in the directory.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() and from_pretrained() is not a simpler option.
str
or os.PathLike
, optional) — Path to a directory in which a downloaded pretrained model configuration should be cached if the standard cache should not be used. bool
, optional, defaults to False
) — Load the model weights from a TensorFlow checkpoint save file (see docstring of pretrained_model_name_or_path
argument). bool
, optional, defaults to False
) — Whether or not to force the (re-)download of the model weights and configuration files, overriding the cached versions if they exist. 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. bool
, optional, defaults to False
) — Whether ot not to also return a dictionary containing missing keys, unexpected keys and error messages. bool
, optional, defaults to False
) — Whether or not to only look at local files (e.g., not try downloading the model). 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 revision
can be any identifier allowed by git. bool
, optional, defaults to False
) — Whether or not to allow for custom models defined on the Hub in their own modeling files. This option should only be set to True
for repositories you trust and in which you have read the code, as it will execute code present on the Hub on your local machine. str
, optional, defaults to "main"
) — The specific revision to use for the code on the Hub, if the code leaves in a different repository than the rest of the model. 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 revision
can be any identifier allowed by git. output_attentions=True
). Behaves differently depending on whether a config
is provided or automatically loaded:
config
, **kwargs
will be directly passed to the underlying model’s __init__
method (we assume all relevant updates to the configuration have already been done)kwargs
will be first passed to the configuration class initialization function (from_pretrained()). Each key of kwargs
that corresponds to a configuration attribute will be used to override said attribute with the supplied kwargs
value. Remaining keys that do not correspond to any configuration attribute will be passed to the underlying model’s __init__
function.Instantiate one of the model classes of the library (with a zero-shot image classification head) from a pretrained model.
The model class to instantiate is selected based on the model_type
property of the config object (either passed as an argument or loaded from pretrained_model_name_or_path
if possible), or when it’s missing, by falling back to using pattern matching on pretrained_model_name_or_path
:
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 with model.train()
Examples:
>>> from transformers import AutoConfig, AutoModelForZeroShotImageClassification >>> >>> model = AutoModelForZeroShotImageClassification.from_pretrained("google-bert/bert-base-cased") >>> >>> model = AutoModelForZeroShotImageClassification.from_pretrained("google-bert/bert-base-cased", output_attentions=True) >>> model.config.output_attentions True >>> >>> config = AutoConfig.from_pretrained("./tf_model/bert_tf_model_config.json") >>> model = AutoModelForZeroShotImageClassification.from_pretrained( ... "./tf_model/bert_tf_checkpoint.ckpt.index", from_tf=True, config=config ... )TFAutoModelForZeroShotImageClassification class transformers.TFAutoModelForZeroShotImageClassification < source >
( *args **kwargs )
This is a generic model class that will be instantiated as one of the model classes of the library (with a zero-shot image classification head) when created with the from_pretrained() class method or the from_config() class method.
This class cannot be instantiated directly using __init__()
(throws an error).
( **kwargs )
Parameters
str
, optional) — The attention implementation to use in the model (if relevant). Can be any of "eager"
(manual implementation of the attention), "sdpa"
(using F.scaled_dot_product_attention
), or "flash_attention_2"
(using Dao-AILab/flash-attention). By default, if available, SDPA will be used for torch>=2.1.1. The default is otherwise the manual "eager"
implementation. Instantiates one of the model classes of the library (with a zero-shot 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.
Examples:
>>> from transformers import AutoConfig, TFAutoModelForZeroShotImageClassification >>> >>> config = AutoConfig.from_pretrained("google-bert/bert-base-cased") >>> model = TFAutoModelForZeroShotImageClassification.from_config(config)from_pretrained < source >
( *model_args **kwargs )
Parameters
str
or os.PathLike
) — Can be either:
./my_model_directory/
../pt_model/pytorch_model.bin
). In this case, from_pt
should be set to True
and a configuration object should be provided as config
argument. 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.__init__()
method. pretrained_model_name_or_path
and a configuration JSON file named config.json is found in the directory.str
or os.PathLike
, optional) — Path to a directory in which a downloaded pretrained model configuration should be cached if the standard cache should not be used. bool
, optional, defaults to False
) — Load the model weights from a PyTorch checkpoint save file (see docstring of pretrained_model_name_or_path
argument). bool
, optional, defaults to False
) — Whether or not to force the (re-)download of the model weights and configuration files, overriding the cached versions if they exist. 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. bool
, optional, defaults to False
) — Whether ot not to also return a dictionary containing missing keys, unexpected keys and error messages. bool
, optional, defaults to False
) — Whether or not to only look at local files (e.g., not try downloading the model). 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 revision
can be any identifier allowed by git. bool
, optional, defaults to False
) — Whether or not to allow for custom models defined on the Hub in their own modeling files. This option should only be set to True
for repositories you trust and in which you have read the code, as it will execute code present on the Hub on your local machine. str
, optional, defaults to "main"
) — The specific revision to use for the code on the Hub, if the code leaves in a different repository than the rest of the model. 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 revision
can be any identifier allowed by git. output_attentions=True
). Behaves differently depending on whether a config
is provided or automatically loaded:
config
, **kwargs
will be directly passed to the underlying model’s __init__
method (we assume all relevant updates to the configuration have already been done)kwargs
will be first passed to the configuration class initialization function (from_pretrained()). Each key of kwargs
that corresponds to a configuration attribute will be used to override said attribute with the supplied kwargs
value. Remaining keys that do not correspond to any configuration attribute will be passed to the underlying model’s __init__
function.Instantiate one of the model classes of the library (with a zero-shot image classification head) from a pretrained model.
The model class to instantiate is selected based on the model_type
property of the config object (either passed as an argument or loaded from pretrained_model_name_or_path
if possible), or when it’s missing, by falling back to using pattern matching on pretrained_model_name_or_path
:
Examples:
>>> from transformers import AutoConfig, TFAutoModelForZeroShotImageClassification >>> >>> model = TFAutoModelForZeroShotImageClassification.from_pretrained("google-bert/bert-base-cased") >>> >>> model = TFAutoModelForZeroShotImageClassification.from_pretrained("google-bert/bert-base-cased", output_attentions=True) >>> model.config.output_attentions True >>> >>> config = AutoConfig.from_pretrained("./pt_model/bert_pt_model_config.json") >>> model = TFAutoModelForZeroShotImageClassification.from_pretrained( ... "./pt_model/bert_pytorch_model.bin", from_pt=True, config=config ... )AutoModelForZeroShotObjectDetection class transformers.AutoModelForZeroShotObjectDetection < source >
( *args **kwargs )
This is a generic model class that will be instantiated as one of the model classes of the library (with a zero-shot object detection head) when created with the from_pretrained() class method or the from_config() class method.
This class cannot be instantiated directly using __init__()
(throws an error).
Instantiates one of the model classes of the library (with a zero-shot object detection 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.
Examples:
>>> from transformers import AutoConfig, AutoModelForZeroShotObjectDetection >>> >>> config = AutoConfig.from_pretrained("google-bert/bert-base-cased") >>> model = AutoModelForZeroShotObjectDetection.from_config(config)from_pretrained < source >
( *model_args **kwargs )
Parameters
str
or os.PathLike
) — Can be either:
./my_model_directory/
../tf_model/model.ckpt.index
). In this case, from_tf
should be set to True
and a configuration object should be provided as config
argument. 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.__init__()
method. pretrained_model_name_or_path
and a configuration JSON file named config.json is found in the directory.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() and from_pretrained() is not a simpler option.
str
or os.PathLike
, optional) — Path to a directory in which a downloaded pretrained model configuration should be cached if the standard cache should not be used. bool
, optional, defaults to False
) — Load the model weights from a TensorFlow checkpoint save file (see docstring of pretrained_model_name_or_path
argument). bool
, optional, defaults to False
) — Whether or not to force the (re-)download of the model weights and configuration files, overriding the cached versions if they exist. 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. bool
, optional, defaults to False
) — Whether ot not to also return a dictionary containing missing keys, unexpected keys and error messages. bool
, optional, defaults to False
) — Whether or not to only look at local files (e.g., not try downloading the model). 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 revision
can be any identifier allowed by git. bool
, optional, defaults to False
) — Whether or not to allow for custom models defined on the Hub in their own modeling files. This option should only be set to True
for repositories you trust and in which you have read the code, as it will execute code present on the Hub on your local machine. str
, optional, defaults to "main"
) — The specific revision to use for the code on the Hub, if the code leaves in a different repository than the rest of the model. 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 revision
can be any identifier allowed by git. output_attentions=True
). Behaves differently depending on whether a config
is provided or automatically loaded:
config
, **kwargs
will be directly passed to the underlying model’s __init__
method (we assume all relevant updates to the configuration have already been done)kwargs
will be first passed to the configuration class initialization function (from_pretrained()). Each key of kwargs
that corresponds to a configuration attribute will be used to override said attribute with the supplied kwargs
value. Remaining keys that do not correspond to any configuration attribute will be passed to the underlying model’s __init__
function.Instantiate one of the model classes of the library (with a zero-shot object detection head) from a pretrained model.
The model class to instantiate is selected based on the model_type
property of the config object (either passed as an argument or loaded from pretrained_model_name_or_path
if possible), or when it’s missing, by falling back to using pattern matching on pretrained_model_name_or_path
:
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 with model.train()
Examples:
>>> from transformers import AutoConfig, AutoModelForZeroShotObjectDetection >>> >>> model = AutoModelForZeroShotObjectDetection.from_pretrained("google-bert/bert-base-cased") >>> >>> model = AutoModelForZeroShotObjectDetection.from_pretrained("google-bert/bert-base-cased", output_attentions=True) >>> model.config.output_attentions True >>> >>> config = AutoConfig.from_pretrained("./tf_model/bert_tf_model_config.json") >>> model = AutoModelForZeroShotObjectDetection.from_pretrained( ... "./tf_model/bert_tf_checkpoint.ckpt.index", from_tf=True, config=config ... )Audio
The following auto classes are available for the following audio tasks.
AutoModelForAudioClassification class transformers.AutoModelForAudioClassification < source >( *args **kwargs )
This is a generic model class that will be instantiated as one of the model classes of the library (with a audio classification head) when created with the from_pretrained() class method or the from_config() class method.
This class cannot be instantiated directly using __init__()
(throws an error).
Instantiates one of the model classes of the library (with a audio 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.
Examples:
>>> from transformers import AutoConfig, AutoModelForAudioClassification >>> >>> config = AutoConfig.from_pretrained("google-bert/bert-base-cased") >>> model = AutoModelForAudioClassification.from_config(config)from_pretrained < source >
( *model_args **kwargs )
Parameters
str
or os.PathLike
) — Can be either:
./my_model_directory/
../tf_model/model.ckpt.index
). In this case, from_tf
should be set to True
and a configuration object should be provided as config
argument. 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.__init__()
method. pretrained_model_name_or_path
and a configuration JSON file named config.json is found in the directory.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() and from_pretrained() is not a simpler option.
str
or os.PathLike
, optional) — Path to a directory in which a downloaded pretrained model configuration should be cached if the standard cache should not be used. bool
, optional, defaults to False
) — Load the model weights from a TensorFlow checkpoint save file (see docstring of pretrained_model_name_or_path
argument). bool
, optional, defaults to False
) — Whether or not to force the (re-)download of the model weights and configuration files, overriding the cached versions if they exist. 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. bool
, optional, defaults to False
) — Whether ot not to also return a dictionary containing missing keys, unexpected keys and error messages. bool
, optional, defaults to False
) — Whether or not to only look at local files (e.g., not try downloading the model). 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 revision
can be any identifier allowed by git. bool
, optional, defaults to False
) — Whether or not to allow for custom models defined on the Hub in their own modeling files. This option should only be set to True
for repositories you trust and in which you have read the code, as it will execute code present on the Hub on your local machine. str
, optional, defaults to "main"
) — The specific revision to use for the code on the Hub, if the code leaves in a different repository than the rest of the model. 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 revision
can be any identifier allowed by git. output_attentions=True
). Behaves differently depending on whether a config
is provided or automatically loaded:
config
, **kwargs
will be directly passed to the underlying model’s __init__
method (we assume all relevant updates to the configuration have already been done)kwargs
will be first passed to the configuration class initialization function (from_pretrained()). Each key of kwargs
that corresponds to a configuration attribute will be used to override said attribute with the supplied kwargs
value. Remaining keys that do not correspond to any configuration attribute will be passed to the underlying model’s __init__
function.Instantiate one of the model classes of the library (with a audio classification head) from a pretrained model.
The model class to instantiate is selected based on the model_type
property of the config object (either passed as an argument or loaded from pretrained_model_name_or_path
if possible), or when it’s missing, by falling back to using pattern matching on pretrained_model_name_or_path
:
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 with model.train()
Examples:
>>> from transformers import AutoConfig, AutoModelForAudioClassification >>> >>> model = AutoModelForAudioClassification.from_pretrained("google-bert/bert-base-cased") >>> >>> model = AutoModelForAudioClassification.from_pretrained("google-bert/bert-base-cased", output_attentions=True) >>> model.config.output_attentions True >>> >>> config = AutoConfig.from_pretrained("./tf_model/bert_tf_model_config.json") >>> model = AutoModelForAudioClassification.from_pretrained( ... "./tf_model/bert_tf_checkpoint.ckpt.index", from_tf=True, config=config ... )AutoModelForAudioFrameClassification class transformers.TFAutoModelForAudioClassification < source >
( *args **kwargs )
This is a generic model class that will be instantiated as one of the model classes of the library (with a audio classification head) when created with the from_pretrained() class method or the from_config() class method.
This class cannot be instantiated directly using __init__()
(throws an error).
Instantiates one of the model classes of the library (with a audio 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.
Examples:
>>> from transformers import AutoConfig, TFAutoModelForAudioClassification >>> >>> config = AutoConfig.from_pretrained("google-bert/bert-base-cased") >>> model = TFAutoModelForAudioClassification.from_config(config)from_pretrained < source >
( *model_args **kwargs )
Parameters
str
or os.PathLike
) — Can be either:
./my_model_directory/
../pt_model/pytorch_model.bin
). In this case, from_pt
should be set to True
and a configuration object should be provided as config
argument. 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.__init__()
method. pretrained_model_name_or_path
and a configuration JSON file named config.json is found in the directory.str
or os.PathLike
, optional) — Path to a directory in which a downloaded pretrained model configuration should be cached if the standard cache should not be used. bool
, optional, defaults to False
) — Load the model weights from a PyTorch checkpoint save file (see docstring of pretrained_model_name_or_path
argument). bool
, optional, defaults to False
) — Whether or not to force the (re-)download of the model weights and configuration files, overriding the cached versions if they exist. 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. bool
, optional, defaults to False
) — Whether ot not to also return a dictionary containing missing keys, unexpected keys and error messages. bool
, optional, defaults to False
) — Whether or not to only look at local files (e.g., not try downloading the model). 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 revision
can be any identifier allowed by git. bool
, optional, defaults to False
) — Whether or not to allow for custom models defined on the Hub in their own modeling files. This option should only be set to True
for repositories you trust and in which you have read the code, as it will execute code present on the Hub on your local machine. str
, optional, defaults to "main"
) — The specific revision to use for the code on the Hub, if the code leaves in a different repository than the rest of the model. 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 revision
can be any identifier allowed by git. output_attentions=True
). Behaves differently depending on whether a config
is provided or automatically loaded:
config
, **kwargs
will be directly passed to the underlying model’s __init__
method (we assume all relevant updates to the configuration have already been done)kwargs
will be first passed to the configuration class initialization function (from_pretrained()). Each key of kwargs
that corresponds to a configuration attribute will be used to override said attribute with the supplied kwargs
value. Remaining keys that do not correspond to any configuration attribute will be passed to the underlying model’s __init__
function.Instantiate one of the model classes of the library (with a audio classification head) from a pretrained model.
The model class to instantiate is selected based on the model_type
property of the config object (either passed as an argument or loaded from pretrained_model_name_or_path
if possible), or when it’s missing, by falling back to using pattern matching on pretrained_model_name_or_path
:
Examples:
>>> from transformers import AutoConfig, TFAutoModelForAudioClassification >>> >>> model = TFAutoModelForAudioClassification.from_pretrained("google-bert/bert-base-cased") >>> >>> model = TFAutoModelForAudioClassification.from_pretrained("google-bert/bert-base-cased", output_attentions=True) >>> model.config.output_attentions True >>> >>> config = AutoConfig.from_pretrained("./pt_model/bert_pt_model_config.json") >>> model = TFAutoModelForAudioClassification.from_pretrained( ... "./pt_model/bert_pytorch_model.bin", from_pt=True, config=config ... )TFAutoModelForAudioFrameClassification class transformers.AutoModelForAudioFrameClassification < source >
( *args **kwargs )
This is a generic model class that will be instantiated as one of the model classes of the library (with a audio frame (token) classification head) when created with the from_pretrained() class method or the from_config() class method.
This class cannot be instantiated directly using __init__()
(throws an error).
Instantiates one of the model classes of the library (with a audio frame (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.
Examples:
>>> from transformers import AutoConfig, AutoModelForAudioFrameClassification >>> >>> config = AutoConfig.from_pretrained("google-bert/bert-base-cased") >>> model = AutoModelForAudioFrameClassification.from_config(config)from_pretrained < source >
( *model_args **kwargs )
Parameters
str
or os.PathLike
) — Can be either:
./my_model_directory/
../tf_model/model.ckpt.index
). In this case, from_tf
should be set to True
and a configuration object should be provided as config
argument. 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.__init__()
method. pretrained_model_name_or_path
and a configuration JSON file named config.json is found in the directory.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() and from_pretrained() is not a simpler option.
str
or os.PathLike
, optional) — Path to a directory in which a downloaded pretrained model configuration should be cached if the standard cache should not be used. bool
, optional, defaults to False
) — Load the model weights from a TensorFlow checkpoint save file (see docstring of pretrained_model_name_or_path
argument). bool
, optional, defaults to False
) — Whether or not to force the (re-)download of the model weights and configuration files, overriding the cached versions if they exist. 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. bool
, optional, defaults to False
) — Whether ot not to also return a dictionary containing missing keys, unexpected keys and error messages. bool
, optional, defaults to False
) — Whether or not to only look at local files (e.g., not try downloading the model). 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 revision
can be any identifier allowed by git. bool
, optional, defaults to False
) — Whether or not to allow for custom models defined on the Hub in their own modeling files. This option should only be set to True
for repositories you trust and in which you have read the code, as it will execute code present on the Hub on your local machine. str
, optional, defaults to "main"
) — The specific revision to use for the code on the Hub, if the code leaves in a different repository than the rest of the model. 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 revision
can be any identifier allowed by git. output_attentions=True
). Behaves differently depending on whether a config
is provided or automatically loaded:
config
, **kwargs
will be directly passed to the underlying model’s __init__
method (we assume all relevant updates to the configuration have already been done)kwargs
will be first passed to the configuration class initialization function (from_pretrained()). Each key of kwargs
that corresponds to a configuration attribute will be used to override said attribute with the supplied kwargs
value. Remaining keys that do not correspond to any configuration attribute will be passed to the underlying model’s __init__
function.Instantiate one of the model classes of the library (with a audio frame (token) classification head) from a pretrained model.
The model class to instantiate is selected based on the model_type
property of the config object (either passed as an argument or loaded from pretrained_model_name_or_path
if possible), or when it’s missing, by falling back to using pattern matching on pretrained_model_name_or_path
:
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 with model.train()
Examples:
>>> from transformers import AutoConfig, AutoModelForAudioFrameClassification >>> >>> model = AutoModelForAudioFrameClassification.from_pretrained("google-bert/bert-base-cased") >>> >>> model = AutoModelForAudioFrameClassification.from_pretrained("google-bert/bert-base-cased", output_attentions=True) >>> model.config.output_attentions True >>> >>> config = AutoConfig.from_pretrained("./tf_model/bert_tf_model_config.json") >>> model = AutoModelForAudioFrameClassification.from_pretrained( ... "./tf_model/bert_tf_checkpoint.ckpt.index", from_tf=True, config=config ... )AutoModelForCTC class transformers.AutoModelForCTC < source >
( *args **kwargs )
This is a generic model class that will be instantiated as one of the model classes of the library (with a connectionist temporal classification head) when created with the from_pretrained() class method or the from_config() class method.
This class cannot be instantiated directly using __init__()
(throws an error).
Instantiates one of the model classes of the library (with a connectionist temporal 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.
Examples:
>>> from transformers import AutoConfig, AutoModelForCTC >>> >>> config = AutoConfig.from_pretrained("google-bert/bert-base-cased") >>> model = AutoModelForCTC.from_config(config)from_pretrained < source >
( *model_args **kwargs )
Parameters
str
or os.PathLike
) — Can be either:
./my_model_directory/
../tf_model/model.ckpt.index
). In this case, from_tf
should be set to True
and a configuration object should be provided as config
argument. 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.__init__()
method. pretrained_model_name_or_path
and a configuration JSON file named config.json is found in the directory.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() and from_pretrained() is not a simpler option.
str
or os.PathLike
, optional) — Path to a directory in which a downloaded pretrained model configuration should be cached if the standard cache should not be used. bool
, optional, defaults to False
) — Load the model weights from a TensorFlow checkpoint save file (see docstring of pretrained_model_name_or_path
argument). bool
, optional, defaults to False
) — Whether or not to force the (re-)download of the model weights and configuration files, overriding the cached versions if they exist. 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. bool
, optional, defaults to False
) — Whether ot not to also return a dictionary containing missing keys, unexpected keys and error messages. bool
, optional, defaults to False
) — Whether or not to only look at local files (e.g., not try downloading the model). 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 revision
can be any identifier allowed by git. bool
, optional, defaults to False
) — Whether or not to allow for custom models defined on the Hub in their own modeling files. This option should only be set to True
for repositories you trust and in which you have read the code, as it will execute code present on the Hub on your local machine. str
, optional, defaults to "main"
) — The specific revision to use for the code on the Hub, if the code leaves in a different repository than the rest of the model. 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 revision
can be any identifier allowed by git. output_attentions=True
). Behaves differently depending on whether a config
is provided or automatically loaded:
config
, **kwargs
will be directly passed to the underlying model’s __init__
method (we assume all relevant updates to the configuration have already been done)kwargs
will be first passed to the configuration class initialization function (from_pretrained()). Each key of kwargs
that corresponds to a configuration attribute will be used to override said attribute with the supplied kwargs
value. Remaining keys that do not correspond to any configuration attribute will be passed to the underlying model’s __init__
function.Instantiate one of the model classes of the library (with a connectionist temporal classification head) from a pretrained model.
The model class to instantiate is selected based on the model_type
property of the config object (either passed as an argument or loaded from pretrained_model_name_or_path
if possible), or when it’s missing, by falling back to using pattern matching on pretrained_model_name_or_path
:
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 with model.train()
Examples:
>>> from transformers import AutoConfig, AutoModelForCTC >>> >>> model = AutoModelForCTC.from_pretrained("google-bert/bert-base-cased") >>> >>> model = AutoModelForCTC.from_pretrained("google-bert/bert-base-cased", output_attentions=True) >>> model.config.output_attentions True >>> >>> config = AutoConfig.from_pretrained("./tf_model/bert_tf_model_config.json") >>> model = AutoModelForCTC.from_pretrained( ... "./tf_model/bert_tf_checkpoint.ckpt.index", from_tf=True, config=config ... )AutoModelForSpeechSeq2Seq class transformers.AutoModelForSpeechSeq2Seq < source >
( *args **kwargs )
This is a generic model class that will be instantiated as one of the model classes of the library (with a sequence-to-sequence speech-to-text modeling head) when created with the from_pretrained() class method or the from_config() class method.
This class cannot be instantiated directly using __init__()
(throws an error).
Instantiates one of the model classes of the library (with a sequence-to-sequence speech-to-text 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.
Examples:
>>> from transformers import AutoConfig, AutoModelForSpeechSeq2Seq >>> >>> config = AutoConfig.from_pretrained("google-bert/bert-base-cased") >>> model = AutoModelForSpeechSeq2Seq.from_config(config)from_pretrained < source >
( *model_args **kwargs )
Parameters
str
or os.PathLike
) — Can be either:
./my_model_directory/
../tf_model/model.ckpt.index
). In this case, from_tf
should be set to True
and a configuration object should be provided as config
argument. 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.__init__()
method. pretrained_model_name_or_path
and a configuration JSON file named config.json is found in the directory.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() and from_pretrained() is not a simpler option.
str
or os.PathLike
, optional) — Path to a directory in which a downloaded pretrained model configuration should be cached if the standard cache should not be used. bool
, optional, defaults to False
) — Load the model weights from a TensorFlow checkpoint save file (see docstring of pretrained_model_name_or_path
argument). bool
, optional, defaults to False
) — Whether or not to force the (re-)download of the model weights and configuration files, overriding the cached versions if they exist. 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. bool
, optional, defaults to False
) — Whether ot not to also return a dictionary containing missing keys, unexpected keys and error messages. bool
, optional, defaults to False
) — Whether or not to only look at local files (e.g., not try downloading the model). 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 revision
can be any identifier allowed by git. bool
, optional, defaults to False
) — Whether or not to allow for custom models defined on the Hub in their own modeling files. This option should only be set to True
for repositories you trust and in which you have read the code, as it will execute code present on the Hub on your local machine. str
, optional, defaults to "main"
) — The specific revision to use for the code on the Hub, if the code leaves in a different repository than the rest of the model. 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 revision
can be any identifier allowed by git. output_attentions=True
). Behaves differently depending on whether a config
is provided or automatically loaded:
config
, **kwargs
will be directly passed to the underlying model’s __init__
method (we assume all relevant updates to the configuration have already been done)kwargs
will be first passed to the configuration class initialization function (from_pretrained()). Each key of kwargs
that corresponds to a configuration attribute will be used to override said attribute with the supplied kwargs
value. Remaining keys that do not correspond to any configuration attribute will be passed to the underlying model’s __init__
function.Instantiate one of the model classes of the library (with a sequence-to-sequence speech-to-text modeling head) from a pretrained model.
The model class to instantiate is selected based on the model_type
property of the config object (either passed as an argument or loaded from pretrained_model_name_or_path
if possible), or when it’s missing, by falling back to using pattern matching on pretrained_model_name_or_path
:
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 with model.train()
Examples:
>>> from transformers import AutoConfig, AutoModelForSpeechSeq2Seq >>> >>> model = AutoModelForSpeechSeq2Seq.from_pretrained("google-bert/bert-base-cased") >>> >>> model = AutoModelForSpeechSeq2Seq.from_pretrained("google-bert/bert-base-cased", output_attentions=True) >>> model.config.output_attentions True >>> >>> config = AutoConfig.from_pretrained("./tf_model/bert_tf_model_config.json") >>> model = AutoModelForSpeechSeq2Seq.from_pretrained( ... "./tf_model/bert_tf_checkpoint.ckpt.index", from_tf=True, config=config ... )TFAutoModelForSpeechSeq2Seq class transformers.TFAutoModelForSpeechSeq2Seq < source >
( *args **kwargs )
This is a generic model class that will be instantiated as one of the model classes of the library (with a sequence-to-sequence speech-to-text modeling head) when created with the from_pretrained() class method or the from_config() class method.
This class cannot be instantiated directly using __init__()
(throws an error).
Instantiates one of the model classes of the library (with a sequence-to-sequence speech-to-text 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.
Examples:
>>> from transformers import AutoConfig, TFAutoModelForSpeechSeq2Seq >>> >>> config = AutoConfig.from_pretrained("google-bert/bert-base-cased") >>> model = TFAutoModelForSpeechSeq2Seq.from_config(config)from_pretrained < source >
( *model_args **kwargs )
Parameters
str
or os.PathLike
) — Can be either:
./my_model_directory/
../pt_model/pytorch_model.bin
). In this case, from_pt
should be set to True
and a configuration object should be provided as config
argument. 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.__init__()
method. pretrained_model_name_or_path
and a configuration JSON file named config.json is found in the directory.str
or os.PathLike
, optional) — Path to a directory in which a downloaded pretrained model configuration should be cached if the standard cache should not be used. bool
, optional, defaults to False
) — Load the model weights from a PyTorch checkpoint save file (see docstring of pretrained_model_name_or_path
argument). bool
, optional, defaults to False
) — Whether or not to force the (re-)download of the model weights and configuration files, overriding the cached versions if they exist. 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. bool
, optional, defaults to False
) — Whether ot not to also return a dictionary containing missing keys, unexpected keys and error messages. bool
, optional, defaults to False
) — Whether or not to only look at local files (e.g., not try downloading the model). 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 revision
can be any identifier allowed by git. bool
, optional, defaults to False
) — Whether or not to allow for custom models defined on the Hub in their own modeling files. This option should only be set to True
for repositories you trust and in which you have read the code, as it will execute code present on the Hub on your local machine. str
, optional, defaults to "main"
) — The specific revision to use for the code on the Hub, if the code leaves in a different repository than the rest of the model. 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 revision
can be any identifier allowed by git. output_attentions=True
). Behaves differently depending on whether a config
is provided or automatically loaded:
config
, **kwargs
will be directly passed to the underlying model’s __init__
method (we assume all relevant updates to the configuration have already been done)kwargs
will be first passed to the configuration class initialization function (from_pretrained()). Each key of kwargs
that corresponds to a configuration attribute will be used to override said attribute with the supplied kwargs
value. Remaining keys that do not correspond to any configuration attribute will be passed to the underlying model’s __init__
function.Instantiate one of the model classes of the library (with a sequence-to-sequence speech-to-text modeling head) from a pretrained model.
The model class to instantiate is selected based on the model_type
property of the config object (either passed as an argument or loaded from pretrained_model_name_or_path
if possible), or when it’s missing, by falling back to using pattern matching on pretrained_model_name_or_path
:
Examples:
>>> from transformers import AutoConfig, TFAutoModelForSpeechSeq2Seq >>> >>> model = TFAutoModelForSpeechSeq2Seq.from_pretrained("google-bert/bert-base-cased") >>> >>> model = TFAutoModelForSpeechSeq2Seq.from_pretrained("google-bert/bert-base-cased", output_attentions=True) >>> model.config.output_attentions True >>> >>> config = AutoConfig.from_pretrained("./pt_model/bert_pt_model_config.json") >>> model = TFAutoModelForSpeechSeq2Seq.from_pretrained( ... "./pt_model/bert_pytorch_model.bin", from_pt=True, config=config ... )FlaxAutoModelForSpeechSeq2Seq class transformers.FlaxAutoModelForSpeechSeq2Seq < source >
( *args **kwargs )
This is a generic model class that will be instantiated as one of the model classes of the library (with a sequence-to-sequence speech-to-text modeling head) when created with the from_pretrained() class method or the from_config() class method.
This class cannot be instantiated directly using __init__()
(throws an error).
Instantiates one of the model classes of the library (with a sequence-to-sequence speech-to-text 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.
Examples:
>>> from transformers import AutoConfig, FlaxAutoModelForSpeechSeq2Seq >>> >>> config = AutoConfig.from_pretrained("google-bert/bert-base-cased") >>> model = FlaxAutoModelForSpeechSeq2Seq.from_config(config)from_pretrained < source >
( *model_args **kwargs )
Parameters
str
or os.PathLike
) — Can be either:
./my_model_directory/
../pt_model/pytorch_model.bin
). In this case, from_pt
should be set to True
and a configuration object should be provided as config
argument. 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.__init__()
method. pretrained_model_name_or_path
and a configuration JSON file named config.json is found in the directory.str
or os.PathLike
, optional) — Path to a directory in which a downloaded pretrained model configuration should be cached if the standard cache should not be used. bool
, optional, defaults to False
) — Load the model weights from a PyTorch checkpoint save file (see docstring of pretrained_model_name_or_path
argument). bool
, optional, defaults to False
) — Whether or not to force the (re-)download of the model weights and configuration files, overriding the cached versions if they exist. 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. bool
, optional, defaults to False
) — Whether ot not to also return a dictionary containing missing keys, unexpected keys and error messages. bool
, optional, defaults to False
) — Whether or not to only look at local files (e.g., not try downloading the model). 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 revision
can be any identifier allowed by git. bool
, optional, defaults to False
) — Whether or not to allow for custom models defined on the Hub in their own modeling files. This option should only be set to True
for repositories you trust and in which you have read the code, as it will execute code present on the Hub on your local machine. str
, optional, defaults to "main"
) — The specific revision to use for the code on the Hub, if the code leaves in a different repository than the rest of the model. 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 revision
can be any identifier allowed by git. output_attentions=True
). Behaves differently depending on whether a config
is provided or automatically loaded:
config
, **kwargs
will be directly passed to the underlying model’s __init__
method (we assume all relevant updates to the configuration have already been done)kwargs
will be first passed to the configuration class initialization function (from_pretrained()). Each key of kwargs
that corresponds to a configuration attribute will be used to override said attribute with the supplied kwargs
value. Remaining keys that do not correspond to any configuration attribute will be passed to the underlying model’s __init__
function.Instantiate one of the model classes of the library (with a sequence-to-sequence speech-to-text modeling head) from a pretrained model.
The model class to instantiate is selected based on the model_type
property of the config object (either passed as an argument or loaded from pretrained_model_name_or_path
if possible), or when it’s missing, by falling back to using pattern matching on pretrained_model_name_or_path
:
Examples:
>>> from transformers import AutoConfig, FlaxAutoModelForSpeechSeq2Seq >>> >>> model = FlaxAutoModelForSpeechSeq2Seq.from_pretrained("google-bert/bert-base-cased") >>> >>> model = FlaxAutoModelForSpeechSeq2Seq.from_pretrained("google-bert/bert-base-cased", output_attentions=True) >>> model.config.output_attentions True >>> >>> config = AutoConfig.from_pretrained("./pt_model/bert_pt_model_config.json") >>> model = FlaxAutoModelForSpeechSeq2Seq.from_pretrained( ... "./pt_model/bert_pytorch_model.bin", from_pt=True, config=config ... )AutoModelForAudioXVector class transformers.AutoModelForAudioXVector < source >
( *args **kwargs )
This is a generic model class that will be instantiated as one of the model classes of the library (with a audio retrieval via x-vector head) when created with the from_pretrained() class method or the from_config() class method.
This class cannot be instantiated directly using __init__()
(throws an error).
Instantiates one of the model classes of the library (with a audio retrieval via x-vector 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.
Examples:
>>> from transformers import AutoConfig, AutoModelForAudioXVector >>> >>> config = AutoConfig.from_pretrained("google-bert/bert-base-cased") >>> model = AutoModelForAudioXVector.from_config(config)from_pretrained < source >
( *model_args **kwargs )
Parameters
str
or os.PathLike
) — Can be either:
./my_model_directory/
../tf_model/model.ckpt.index
). In this case, from_tf
should be set to True
and a configuration object should be provided as config
argument. 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.__init__()
method. pretrained_model_name_or_path
and a configuration JSON file named config.json is found in the directory.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() and from_pretrained() is not a simpler option.
str
or os.PathLike
, optional) — Path to a directory in which a downloaded pretrained model configuration should be cached if the standard cache should not be used. bool
, optional, defaults to False
) — Load the model weights from a TensorFlow checkpoint save file (see docstring of pretrained_model_name_or_path
argument). bool
, optional, defaults to False
) — Whether or not to force the (re-)download of the model weights and configuration files, overriding the cached versions if they exist. 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. bool
, optional, defaults to False
) — Whether ot not to also return a dictionary containing missing keys, unexpected keys and error messages. bool
, optional, defaults to False
) — Whether or not to only look at local files (e.g., not try downloading the model). 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 revision
can be any identifier allowed by git. bool
, optional, defaults to False
) — Whether or not to allow for custom models defined on the Hub in their own modeling files. This option should only be set to True
for repositories you trust and in which you have read the code, as it will execute code present on the Hub on your local machine. str
, optional, defaults to "main"
) — The specific revision to use for the code on the Hub, if the code leaves in a different repository than the rest of the model. 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 revision
can be any identifier allowed by git. output_attentions=True
). Behaves differently depending on whether a config
is provided or automatically loaded:
config
, **kwargs
will be directly passed to the underlying model’s __init__
method (we assume all relevant updates to the configuration have already been done)kwargs
will be first passed to the configuration class initialization function (from_pretrained()). Each key of kwargs
that corresponds to a configuration attribute will be used to override said attribute with the supplied kwargs
value. Remaining keys that do not correspond to any configuration attribute will be passed to the underlying model’s __init__
function.Instantiate one of the model classes of the library (with a audio retrieval via x-vector head) from a pretrained model.
The model class to instantiate is selected based on the model_type
property of the config object (either passed as an argument or loaded from pretrained_model_name_or_path
if possible), or when it’s missing, by falling back to using pattern matching on pretrained_model_name_or_path
:
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 with model.train()
Examples:
>>> from transformers import AutoConfig, AutoModelForAudioXVector >>> >>> model = AutoModelForAudioXVector.from_pretrained("google-bert/bert-base-cased") >>> >>> model = AutoModelForAudioXVector.from_pretrained("google-bert/bert-base-cased", output_attentions=True) >>> model.config.output_attentions True >>> >>> config = AutoConfig.from_pretrained("./tf_model/bert_tf_model_config.json") >>> model = AutoModelForAudioXVector.from_pretrained( ... "./tf_model/bert_tf_checkpoint.ckpt.index", from_tf=True, config=config ... )AutoModelForTextToSpectrogram class transformers.AutoModelForTextToSpectrogram < source >
( *args **kwargs )
AutoModelForTextToWaveform class transformers.AutoModelForTextToWaveform < source >( *args **kwargs )
MultimodalThe following auto classes are available for the following multimodal tasks.
AutoModelForTableQuestionAnswering class transformers.AutoModelForTableQuestionAnswering < source >( *args **kwargs )
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 the from_config() class method.
This class cannot be instantiated directly using __init__()
(throws an error).
( **kwargs )
Parameters
str
, optional) — The attention implementation to use in the model (if relevant). Can be any of "eager"
(manual implementation of the attention), "sdpa"
(using F.scaled_dot_product_attention
), or "flash_attention_2"
(using Dao-AILab/flash-attention). By default, if available, SDPA will be used for torch>=2.1.1. The default is otherwise the manual "eager"
implementation. 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.
Examples:
>>> from transformers import AutoConfig, AutoModelForTableQuestionAnswering >>> >>> config = AutoConfig.from_pretrained("google/tapas-base-finetuned-wtq") >>> model = AutoModelForTableQuestionAnswering.from_config(config)from_pretrained < source >
( *model_args **kwargs )
Parameters
str
or os.PathLike
) — Can be either:
./my_model_directory/
../tf_model/model.ckpt.index
). In this case, from_tf
should be set to True
and a configuration object should be provided as config
argument. 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.__init__()
method. pretrained_model_name_or_path
and a configuration JSON file named config.json is found in the directory.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() and from_pretrained() is not a simpler option.
str
or os.PathLike
, optional) — Path to a directory in which a downloaded pretrained model configuration should be cached if the standard cache should not be used. bool
, optional, defaults to False
) — Load the model weights from a TensorFlow checkpoint save file (see docstring of pretrained_model_name_or_path
argument). bool
, optional, defaults to False
) — Whether or not to force the (re-)download of the model weights and configuration files, overriding the cached versions if they exist. 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. bool
, optional, defaults to False
) — Whether ot not to also return a dictionary containing missing keys, unexpected keys and error messages. bool
, optional, defaults to False
) — Whether or not to only look at local files (e.g., not try downloading the model). 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 revision
can be any identifier allowed by git. bool
, optional, defaults to False
) — Whether or not to allow for custom models defined on the Hub in their own modeling files. This option should only be set to True
for repositories you trust and in which you have read the code, as it will execute code present on the Hub on your local machine. str
, optional, defaults to "main"
) — The specific revision to use for the code on the Hub, if the code leaves in a different repository than the rest of the model. 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 revision
can be any identifier allowed by git. output_attentions=True
). Behaves differently depending on whether a config
is provided or automatically loaded:
config
, **kwargs
will be directly passed to the underlying model’s __init__
method (we assume all relevant updates to the configuration have already been done)kwargs
will be first passed to the configuration class initialization function (from_pretrained()). Each key of kwargs
that corresponds to a configuration attribute will be used to override said attribute with the supplied kwargs
value. Remaining keys that do not correspond to any configuration attribute will be passed to the underlying model’s __init__
function.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_type
property of the config object (either passed as an argument or loaded from pretrained_model_name_or_path
if possible), or when it’s missing, by falling back to using pattern matching on pretrained_model_name_or_path
:
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 with model.train()
Examples:
>>> from transformers import AutoConfig, AutoModelForTableQuestionAnswering >>> >>> model = AutoModelForTableQuestionAnswering.from_pretrained("google/tapas-base-finetuned-wtq") >>> >>> model = AutoModelForTableQuestionAnswering.from_pretrained("google/tapas-base-finetuned-wtq", output_attentions=True) >>> model.config.output_attentions True >>> >>> 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 ... )TFAutoModelForTableQuestionAnswering class transformers.TFAutoModelForTableQuestionAnswering < source >
( *args **kwargs )
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 the from_config() class method.
This class cannot be instantiated directly using __init__()
(throws an error).
( **kwargs )
Parameters
str
, optional) — The attention implementation to use in the model (if relevant). Can be any of "eager"
(manual implementation of the attention), "sdpa"
(using F.scaled_dot_product_attention
), or "flash_attention_2"
(using Dao-AILab/flash-attention). By default, if available, SDPA will be used for torch>=2.1.1. The default is otherwise the manual "eager"
implementation. 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.
Examples:
>>> from transformers import AutoConfig, TFAutoModelForTableQuestionAnswering >>> >>> config = AutoConfig.from_pretrained("google/tapas-base-finetuned-wtq") >>> model = TFAutoModelForTableQuestionAnswering.from_config(config)from_pretrained < source >
( *model_args **kwargs )
Parameters
str
or os.PathLike
) — Can be either:
./my_model_directory/
../pt_model/pytorch_model.bin
). In this case, from_pt
should be set to True
and a configuration object should be provided as config
argument. 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.__init__()
method. pretrained_model_name_or_path
and a configuration JSON file named config.json is found in the directory.str
or os.PathLike
, optional) — Path to a directory in which a downloaded pretrained model configuration should be cached if the standard cache should not be used. bool
, optional, defaults to False
) — Load the model weights from a PyTorch checkpoint save file (see docstring of pretrained_model_name_or_path
argument). bool
, optional, defaults to False
) — Whether or not to force the (re-)download of the model weights and configuration files, overriding the cached versions if they exist. 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. bool
, optional, defaults to False
) — Whether ot not to also return a dictionary containing missing keys, unexpected keys and error messages. bool
, optional, defaults to False
) — Whether or not to only look at local files (e.g., not try downloading the model). 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 revision
can be any identifier allowed by git. bool
, optional, defaults to False
) — Whether or not to allow for custom models defined on the Hub in their own modeling files. This option should only be set to True
for repositories you trust and in which you have read the code, as it will execute code present on the Hub on your local machine. str
, optional, defaults to "main"
) — The specific revision to use for the code on the Hub, if the code leaves in a different repository than the rest of the model. 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 revision
can be any identifier allowed by git. output_attentions=True
). Behaves differently depending on whether a config
is provided or automatically loaded:
config
, **kwargs
will be directly passed to the underlying model’s __init__
method (we assume all relevant updates to the configuration have already been done)kwargs
will be first passed to the configuration class initialization function (from_pretrained()). Each key of kwargs
that corresponds to a configuration attribute will be used to override said attribute with the supplied kwargs
value. Remaining keys that do not correspond to any configuration attribute will be passed to the underlying model’s __init__
function.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_type
property of the config object (either passed as an argument or loaded from pretrained_model_name_or_path
if possible), or when it’s missing, by falling back to using pattern matching on pretrained_model_name_or_path
:
Examples:
>>> from transformers import AutoConfig, TFAutoModelForTableQuestionAnswering >>> >>> model = TFAutoModelForTableQuestionAnswering.from_pretrained("google/tapas-base-finetuned-wtq") >>> >>> model = TFAutoModelForTableQuestionAnswering.from_pretrained("google/tapas-base-finetuned-wtq", output_attentions=True) >>> model.config.output_attentions True >>> >>> config = AutoConfig.from_pretrained("./pt_model/tapas_pt_model_config.json") >>> model = TFAutoModelForTableQuestionAnswering.from_pretrained( ... "./pt_model/tapas_pytorch_model.bin", from_pt=True, config=config ... )AutoModelForDocumentQuestionAnswering class transformers.AutoModelForDocumentQuestionAnswering < source >
( *args **kwargs )
This is a generic model class that will be instantiated as one of the model classes of the library (with a document question answering head) when created with the from_pretrained() class method or the from_config() class method.
This class cannot be instantiated directly using __init__()
(throws an error).
Instantiates one of the model classes of the library (with a document 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.
Examples:
>>> from transformers import AutoConfig, AutoModelForDocumentQuestionAnswering >>> >>> config = AutoConfig.from_pretrained("impira/layoutlm-document-qa", revision="52e01b3") >>> model = AutoModelForDocumentQuestionAnswering.from_config(config)from_pretrained < source >
( *model_args **kwargs )
Parameters
str
or os.PathLike
) — Can be either:
./my_model_directory/
../tf_model/model.ckpt.index
). In this case, from_tf
should be set to True
and a configuration object should be provided as config
argument. 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.__init__()
method. pretrained_model_name_or_path
and a configuration JSON file named config.json is found in the directory.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() and from_pretrained() is not a simpler option.
str
or os.PathLike
, optional) — Path to a directory in which a downloaded pretrained model configuration should be cached if the standard cache should not be used. bool
, optional, defaults to False
) — Load the model weights from a TensorFlow checkpoint save file (see docstring of pretrained_model_name_or_path
argument). bool
, optional, defaults to False
) — Whether or not to force the (re-)download of the model weights and configuration files, overriding the cached versions if they exist. 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. bool
, optional, defaults to False
) — Whether ot not to also return a dictionary containing missing keys, unexpected keys and error messages. bool
, optional, defaults to False
) — Whether or not to only look at local files (e.g., not try downloading the model). 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 revision
can be any identifier allowed by git. bool
, optional, defaults to False
) — Whether or not to allow for custom models defined on the Hub in their own modeling files. This option should only be set to True
for repositories you trust and in which you have read the code, as it will execute code present on the Hub on your local machine. str
, optional, defaults to "main"
) — The specific revision to use for the code on the Hub, if the code leaves in a different repository than the rest of the model. 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 revision
can be any identifier allowed by git. output_attentions=True
). Behaves differently depending on whether a config
is provided or automatically loaded:
config
, **kwargs
will be directly passed to the underlying model’s __init__
method (we assume all relevant updates to the configuration have already been done)kwargs
will be first passed to the configuration class initialization function (from_pretrained()). Each key of kwargs
that corresponds to a configuration attribute will be used to override said attribute with the supplied kwargs
value. Remaining keys that do not correspond to any configuration attribute will be passed to the underlying model’s __init__
function.Instantiate one of the model classes of the library (with a document question answering head) from a pretrained model.
The model class to instantiate is selected based on the model_type
property of the config object (either passed as an argument or loaded from pretrained_model_name_or_path
if possible), or when it’s missing, by falling back to using pattern matching on pretrained_model_name_or_path
:
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 with model.train()
Examples:
>>> from transformers import AutoConfig, AutoModelForDocumentQuestionAnswering >>> >>> model = AutoModelForDocumentQuestionAnswering.from_pretrained("impira/layoutlm-document-qa", revision="52e01b3") >>> >>> model = AutoModelForDocumentQuestionAnswering.from_pretrained("impira/layoutlm-document-qa", revision="52e01b3", output_attentions=True) >>> model.config.output_attentions True >>> >>> config = AutoConfig.from_pretrained("./tf_model/layoutlm_tf_model_config.json") >>> model = AutoModelForDocumentQuestionAnswering.from_pretrained( ... "./tf_model/layoutlm_tf_checkpoint.ckpt.index", from_tf=True, config=config ... )TFAutoModelForDocumentQuestionAnswering class transformers.TFAutoModelForDocumentQuestionAnswering < source >
( *args **kwargs )
This is a generic model class that will be instantiated as one of the model classes of the library (with a document question answering head) when created with the from_pretrained() class method or the from_config() class method.
This class cannot be instantiated directly using __init__()
(throws an error).
Instantiates one of the model classes of the library (with a document 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.
Examples:
>>> from transformers import AutoConfig, TFAutoModelForDocumentQuestionAnswering >>> >>> config = AutoConfig.from_pretrained("impira/layoutlm-document-qa", revision="52e01b3") >>> model = TFAutoModelForDocumentQuestionAnswering.from_config(config)from_pretrained < source >
( *model_args **kwargs )
Parameters
str
or os.PathLike
) — Can be either:
./my_model_directory/
../pt_model/pytorch_model.bin
). In this case, from_pt
should be set to True
and a configuration object should be provided as config
argument. 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.__init__()
method. pretrained_model_name_or_path
and a configuration JSON file named config.json is found in the directory.str
or os.PathLike
, optional) — Path to a directory in which a downloaded pretrained model configuration should be cached if the standard cache should not be used. bool
, optional, defaults to False
) — Load the model weights from a PyTorch checkpoint save file (see docstring of pretrained_model_name_or_path
argument). bool
, optional, defaults to False
) — Whether or not to force the (re-)download of the model weights and configuration files, overriding the cached versions if they exist. 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. bool
, optional, defaults to False
) — Whether ot not to also return a dictionary containing missing keys, unexpected keys and error messages. bool
, optional, defaults to False
) — Whether or not to only look at local files (e.g., not try downloading the model). 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 revision
can be any identifier allowed by git. bool
, optional, defaults to False
) — Whether or not to allow for custom models defined on the Hub in their own modeling files. This option should only be set to True
for repositories you trust and in which you have read the code, as it will execute code present on the Hub on your local machine. str
, optional, defaults to "main"
) — The specific revision to use for the code on the Hub, if the code leaves in a different repository than the rest of the model. 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 revision
can be any identifier allowed by git. output_attentions=True
). Behaves differently depending on whether a config
is provided or automatically loaded:
config
, **kwargs
will be directly passed to the underlying model’s __init__
method (we assume all relevant updates to the configuration have already been done)kwargs
will be first passed to the configuration class initialization function (from_pretrained()). Each key of kwargs
that corresponds to a configuration attribute will be used to override said attribute with the supplied kwargs
value. Remaining keys that do not correspond to any configuration attribute will be passed to the underlying model’s __init__
function.Instantiate one of the model classes of the library (with a document question answering head) from a pretrained model.
The model class to instantiate is selected based on the model_type
property of the config object (either passed as an argument or loaded from pretrained_model_name_or_path
if possible), or when it’s missing, by falling back to using pattern matching on pretrained_model_name_or_path
:
Examples:
>>> from transformers import AutoConfig, TFAutoModelForDocumentQuestionAnswering >>> >>> model = TFAutoModelForDocumentQuestionAnswering.from_pretrained("impira/layoutlm-document-qa", revision="52e01b3") >>> >>> model = TFAutoModelForDocumentQuestionAnswering.from_pretrained("impira/layoutlm-document-qa", revision="52e01b3", output_attentions=True) >>> model.config.output_attentions True >>> >>> config = AutoConfig.from_pretrained("./pt_model/layoutlm_pt_model_config.json") >>> model = TFAutoModelForDocumentQuestionAnswering.from_pretrained( ... "./pt_model/layoutlm_pytorch_model.bin", from_pt=True, config=config ... )AutoModelForVisualQuestionAnswering class transformers.AutoModelForVisualQuestionAnswering < source >
( *args **kwargs )
This is a generic model class that will be instantiated as one of the model classes of the library (with a visual question answering head) when created with the from_pretrained() class method or the from_config() class method.
This class cannot be instantiated directly using __init__()
(throws an error).
Instantiates one of the model classes of the library (with a visual 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.
Examples:
>>> from transformers import AutoConfig, AutoModelForVisualQuestionAnswering >>> >>> config = AutoConfig.from_pretrained("dandelin/vilt-b32-finetuned-vqa") >>> model = AutoModelForVisualQuestionAnswering.from_config(config)from_pretrained < source >
( *model_args **kwargs )
Parameters
str
or os.PathLike
) — Can be either:
./my_model_directory/
../tf_model/model.ckpt.index
). In this case, from_tf
should be set to True
and a configuration object should be provided as config
argument. 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.__init__()
method. pretrained_model_name_or_path
and a configuration JSON file named config.json is found in the directory.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() and from_pretrained() is not a simpler option.
str
or os.PathLike
, optional) — Path to a directory in which a downloaded pretrained model configuration should be cached if the standard cache should not be used. bool
, optional, defaults to False
) — Load the model weights from a TensorFlow checkpoint save file (see docstring of pretrained_model_name_or_path
argument). bool
, optional, defaults to False
) — Whether or not to force the (re-)download of the model weights and configuration files, overriding the cached versions if they exist. 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. bool
, optional, defaults to False
) — Whether ot not to also return a dictionary containing missing keys, unexpected keys and error messages. bool
, optional, defaults to False
) — Whether or not to only look at local files (e.g., not try downloading the model). 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 revision
can be any identifier allowed by git. bool
, optional, defaults to False
) — Whether or not to allow for custom models defined on the Hub in their own modeling files. This option should only be set to True
for repositories you trust and in which you have read the code, as it will execute code present on the Hub on your local machine. str
, optional, defaults to "main"
) — The specific revision to use for the code on the Hub, if the code leaves in a different repository than the rest of the model. 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 revision
can be any identifier allowed by git. output_attentions=True
). Behaves differently depending on whether a config
is provided or automatically loaded:
config
, **kwargs
will be directly passed to the underlying model’s __init__
method (we assume all relevant updates to the configuration have already been done)kwargs
will be first passed to the configuration class initialization function (from_pretrained()). Each key of kwargs
that corresponds to a configuration attribute will be used to override said attribute with the supplied kwargs
value. Remaining keys that do not correspond to any configuration attribute will be passed to the underlying model’s __init__
function.Instantiate one of the model classes of the library (with a visual question answering head) from a pretrained model.
The model class to instantiate is selected based on the model_type
property of the config object (either passed as an argument or loaded from pretrained_model_name_or_path
if possible), or when it’s missing, by falling back to using pattern matching on pretrained_model_name_or_path
:
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 with model.train()
Examples:
>>> from transformers import AutoConfig, AutoModelForVisualQuestionAnswering >>> >>> model = AutoModelForVisualQuestionAnswering.from_pretrained("dandelin/vilt-b32-finetuned-vqa") >>> >>> model = AutoModelForVisualQuestionAnswering.from_pretrained("dandelin/vilt-b32-finetuned-vqa", output_attentions=True) >>> model.config.output_attentions True >>> >>> config = AutoConfig.from_pretrained("./tf_model/vilt_tf_model_config.json") >>> model = AutoModelForVisualQuestionAnswering.from_pretrained( ... "./tf_model/vilt_tf_checkpoint.ckpt.index", from_tf=True, config=config ... )AutoModelForVision2Seq class transformers.AutoModelForVision2Seq < source >
( *args **kwargs )
This is a generic model class that will be instantiated as one of the model classes of the library (with a vision-to-text modeling head) when created with the from_pretrained() class method or the from_config() class method.
This class cannot be instantiated directly using __init__()
(throws an error).
Instantiates one of the model classes of the library (with a vision-to-text 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.
Examples:
>>> from transformers import AutoConfig, AutoModelForVision2Seq >>> >>> config = AutoConfig.from_pretrained("google-bert/bert-base-cased") >>> model = AutoModelForVision2Seq.from_config(config)from_pretrained < source >
( *model_args **kwargs )
Parameters
str
or os.PathLike
) — Can be either:
./my_model_directory/
../tf_model/model.ckpt.index
). In this case, from_tf
should be set to True
and a configuration object should be provided as config
argument. 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.__init__()
method. pretrained_model_name_or_path
and a configuration JSON file named config.json is found in the directory.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() and from_pretrained() is not a simpler option.
str
or os.PathLike
, optional) — Path to a directory in which a downloaded pretrained model configuration should be cached if the standard cache should not be used. bool
, optional, defaults to False
) — Load the model weights from a TensorFlow checkpoint save file (see docstring of pretrained_model_name_or_path
argument). bool
, optional, defaults to False
) — Whether or not to force the (re-)download of the model weights and configuration files, overriding the cached versions if they exist. 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. bool
, optional, defaults to False
) — Whether ot not to also return a dictionary containing missing keys, unexpected keys and error messages. bool
, optional, defaults to False
) — Whether or not to only look at local files (e.g., not try downloading the model). 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 revision
can be any identifier allowed by git. bool
, optional, defaults to False
) — Whether or not to allow for custom models defined on the Hub in their own modeling files. This option should only be set to True
for repositories you trust and in which you have read the code, as it will execute code present on the Hub on your local machine. str
, optional, defaults to "main"
) — The specific revision to use for the code on the Hub, if the code leaves in a different repository than the rest of the model. 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 revision
can be any identifier allowed by git. output_attentions=True
). Behaves differently depending on whether a config
is provided or automatically loaded:
config
, **kwargs
will be directly passed to the underlying model’s __init__
method (we assume all relevant updates to the configuration have already been done)kwargs
will be first passed to the configuration class initialization function (from_pretrained()). Each key of kwargs
that corresponds to a configuration attribute will be used to override said attribute with the supplied kwargs
value. Remaining keys that do not correspond to any configuration attribute will be passed to the underlying model’s __init__
function.Instantiate one of the model classes of the library (with a vision-to-text modeling head) from a pretrained model.
The model class to instantiate is selected based on the model_type
property of the config object (either passed as an argument or loaded from pretrained_model_name_or_path
if possible), or when it’s missing, by falling back to using pattern matching on pretrained_model_name_or_path
:
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 with model.train()
Examples:
>>> from transformers import AutoConfig, AutoModelForVision2Seq >>> >>> model = AutoModelForVision2Seq.from_pretrained("google-bert/bert-base-cased") >>> >>> model = AutoModelForVision2Seq.from_pretrained("google-bert/bert-base-cased", output_attentions=True) >>> model.config.output_attentions True >>> >>> config = AutoConfig.from_pretrained("./tf_model/bert_tf_model_config.json") >>> model = AutoModelForVision2Seq.from_pretrained( ... "./tf_model/bert_tf_checkpoint.ckpt.index", from_tf=True, config=config ... )TFAutoModelForVision2Seq class transformers.TFAutoModelForVision2Seq < source >
( *args **kwargs )
This is a generic model class that will be instantiated as one of the model classes of the library (with a vision-to-text modeling head) when created with the from_pretrained() class method or the from_config() class method.
This class cannot be instantiated directly using __init__()
(throws an error).
Instantiates one of the model classes of the library (with a vision-to-text 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.
Examples:
>>> from transformers import AutoConfig, TFAutoModelForVision2Seq >>> >>> config = AutoConfig.from_pretrained("google-bert/bert-base-cased") >>> model = TFAutoModelForVision2Seq.from_config(config)from_pretrained < source >
( *model_args **kwargs )
Parameters
str
or os.PathLike
) — Can be either:
./my_model_directory/
../pt_model/pytorch_model.bin
). In this case, from_pt
should be set to True
and a configuration object should be provided as config
argument. 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.__init__()
method. pretrained_model_name_or_path
and a configuration JSON file named config.json is found in the directory.str
or os.PathLike
, optional) — Path to a directory in which a downloaded pretrained model configuration should be cached if the standard cache should not be used. bool
, optional, defaults to False
) — Load the model weights from a PyTorch checkpoint save file (see docstring of pretrained_model_name_or_path
argument). bool
, optional, defaults to False
) — Whether or not to force the (re-)download of the model weights and configuration files, overriding the cached versions if they exist. 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. bool
, optional, defaults to False
) — Whether ot not to also return a dictionary containing missing keys, unexpected keys and error messages. bool
, optional, defaults to False
) — Whether or not to only look at local files (e.g., not try downloading the model). 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 revision
can be any identifier allowed by git. bool
, optional, defaults to False
) — Whether or not to allow for custom models defined on the Hub in their own modeling files. This option should only be set to True
for repositories you trust and in which you have read the code, as it will execute code present on the Hub on your local machine. str
, optional, defaults to "main"
) — The specific revision to use for the code on the Hub, if the code leaves in a different repository than the rest of the model. 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 revision
can be any identifier allowed by git. output_attentions=True
). Behaves differently depending on whether a config
is provided or automatically loaded:
config
, **kwargs
will be directly passed to the underlying model’s __init__
method (we assume all relevant updates to the configuration have already been done)kwargs
will be first passed to the configuration class initialization function (from_pretrained()). Each key of kwargs
that corresponds to a configuration attribute will be used to override said attribute with the supplied kwargs
value. Remaining keys that do not correspond to any configuration attribute will be passed to the underlying model’s __init__
function.Instantiate one of the model classes of the library (with a vision-to-text modeling head) from a pretrained model.
The model class to instantiate is selected based on the model_type
property of the config object (either passed as an argument or loaded from pretrained_model_name_or_path
if possible), or when it’s missing, by falling back to using pattern matching on pretrained_model_name_or_path
:
Examples:
>>> from transformers import AutoConfig, TFAutoModelForVision2Seq >>> >>> model = TFAutoModelForVision2Seq.from_pretrained("google-bert/bert-base-cased") >>> >>> model = TFAutoModelForVision2Seq.from_pretrained("google-bert/bert-base-cased", output_attentions=True) >>> model.config.output_attentions True >>> >>> config = AutoConfig.from_pretrained("./pt_model/bert_pt_model_config.json") >>> model = TFAutoModelForVision2Seq.from_pretrained( ... "./pt_model/bert_pytorch_model.bin", from_pt=True, config=config ... )FlaxAutoModelForVision2Seq class transformers.FlaxAutoModelForVision2Seq < source >
( *args **kwargs )
This is a generic model class that will be instantiated as one of the model classes of the library (with a vision-to-text modeling head) when created with the from_pretrained() class method or the from_config() class method.
This class cannot be instantiated directly using __init__()
(throws an error).
Instantiates one of the model classes of the library (with a vision-to-text 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.
Examples:
>>> from transformers import AutoConfig, FlaxAutoModelForVision2Seq >>> >>> config = AutoConfig.from_pretrained("google-bert/bert-base-cased") >>> model = FlaxAutoModelForVision2Seq.from_config(config)from_pretrained < source >
( *model_args **kwargs )
Parameters
str
or os.PathLike
) — Can be either:
./my_model_directory/
../pt_model/pytorch_model.bin
). In this case, from_pt
should be set to True
and a configuration object should be provided as config
argument. 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.__init__()
method. pretrained_model_name_or_path
and a configuration JSON file named config.json is found in the directory.str
or os.PathLike
, optional) — Path to a directory in which a downloaded pretrained model configuration should be cached if the standard cache should not be used. bool
, optional, defaults to False
) — Load the model weights from a PyTorch checkpoint save file (see docstring of pretrained_model_name_or_path
argument). bool
, optional, defaults to False
) — Whether or not to force the (re-)download of the model weights and configuration files, overriding the cached versions if they exist. 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. bool
, optional, defaults to False
) — Whether ot not to also return a dictionary containing missing keys, unexpected keys and error messages. bool
, optional, defaults to False
) — Whether or not to only look at local files (e.g., not try downloading the model). 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 revision
can be any identifier allowed by git. bool
, optional, defaults to False
) — Whether or not to allow for custom models defined on the Hub in their own modeling files. This option should only be set to True
for repositories you trust and in which you have read the code, as it will execute code present on the Hub on your local machine. str
, optional, defaults to "main"
) — The specific revision to use for the code on the Hub, if the code leaves in a different repository than the rest of the model. 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 revision
can be any identifier allowed by git. output_attentions=True
). Behaves differently depending on whether a config
is provided or automatically loaded:
config
, **kwargs
will be directly passed to the underlying model’s __init__
method (we assume all relevant updates to the configuration have already been done)kwargs
will be first passed to the configuration class initialization function (from_pretrained()). Each key of kwargs
that corresponds to a configuration attribute will be used to override said attribute with the supplied kwargs
value. Remaining keys that do not correspond to any configuration attribute will be passed to the underlying model’s __init__
function.Instantiate one of the model classes of the library (with a vision-to-text modeling head) from a pretrained model.
The model class to instantiate is selected based on the model_type
property of the config object (either passed as an argument or loaded from pretrained_model_name_or_path
if possible), or when it’s missing, by falling back to using pattern matching on pretrained_model_name_or_path
:
Examples:
>>> from transformers import AutoConfig, FlaxAutoModelForVision2Seq >>> >>> model = FlaxAutoModelForVision2Seq.from_pretrained("google-bert/bert-base-cased") >>> >>> model = FlaxAutoModelForVision2Seq.from_pretrained("google-bert/bert-base-cased", output_attentions=True) >>> model.config.output_attentions True >>> >>> config = AutoConfig.from_pretrained("./pt_model/bert_pt_model_config.json") >>> model = FlaxAutoModelForVision2Seq.from_pretrained( ... "./pt_model/bert_pytorch_model.bin", from_pt=True, config=config ... )AutoModelForImageTextToText class transformers.AutoModelForImageTextToText < source >
( *args **kwargs )
This is a generic model class that will be instantiated as one of the model classes of the library (with a image-text-to-text modeling head) when created with the from_pretrained() class method or the from_config() class method.
This class cannot be instantiated directly using __init__()
(throws an error).
Instantiates one of the model classes of the library (with a image-text-to-text 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.
Examples:
>>> from transformers import AutoConfig, AutoModelForImageTextToText >>> >>> config = AutoConfig.from_pretrained("google-bert/bert-base-cased") >>> model = AutoModelForImageTextToText.from_config(config)from_pretrained < source >
( *model_args **kwargs )
Parameters
str
or os.PathLike
) — Can be either:
./my_model_directory/
../tf_model/model.ckpt.index
). In this case, from_tf
should be set to True
and a configuration object should be provided as config
argument. 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.__init__()
method. pretrained_model_name_or_path
and a configuration JSON file named config.json is found in the directory.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() and from_pretrained() is not a simpler option.
str
or os.PathLike
, optional) — Path to a directory in which a downloaded pretrained model configuration should be cached if the standard cache should not be used. bool
, optional, defaults to False
) — Load the model weights from a TensorFlow checkpoint save file (see docstring of pretrained_model_name_or_path
argument). bool
, optional, defaults to False
) — Whether or not to force the (re-)download of the model weights and configuration files, overriding the cached versions if they exist. 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. bool
, optional, defaults to False
) — Whether ot not to also return a dictionary containing missing keys, unexpected keys and error messages. bool
, optional, defaults to False
) — Whether or not to only look at local files (e.g., not try downloading the model). 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 revision
can be any identifier allowed by git. bool
, optional, defaults to False
) — Whether or not to allow for custom models defined on the Hub in their own modeling files. This option should only be set to True
for repositories you trust and in which you have read the code, as it will execute code present on the Hub on your local machine. str
, optional, defaults to "main"
) — The specific revision to use for the code on the Hub, if the code leaves in a different repository than the rest of the model. 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 revision
can be any identifier allowed by git. output_attentions=True
). Behaves differently depending on whether a config
is provided or automatically loaded:
config
, **kwargs
will be directly passed to the underlying model’s __init__
method (we assume all relevant updates to the configuration have already been done)kwargs
will be first passed to the configuration class initialization function (from_pretrained()). Each key of kwargs
that corresponds to a configuration attribute will be used to override said attribute with the supplied kwargs
value. Remaining keys that do not correspond to any configuration attribute will be passed to the underlying model’s __init__
function.Instantiate one of the model classes of the library (with a image-text-to-text modeling head) from a pretrained model.
The model class to instantiate is selected based on the model_type
property of the config object (either passed as an argument or loaded from pretrained_model_name_or_path
if possible), or when it’s missing, by falling back to using pattern matching on pretrained_model_name_or_path
:
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 with model.train()
Examples:
>>> from transformers import AutoConfig, AutoModelForImageTextToText >>> >>> model = AutoModelForImageTextToText.from_pretrained("google-bert/bert-base-cased") >>> >>> model = AutoModelForImageTextToText.from_pretrained("google-bert/bert-base-cased", output_attentions=True) >>> model.config.output_attentions True >>> >>> config = AutoConfig.from_pretrained("./tf_model/bert_tf_model_config.json") >>> model = AutoModelForImageTextToText.from_pretrained( ... "./tf_model/bert_tf_checkpoint.ckpt.index", from_tf=True, config=config ... )< > Update on GitHub
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.3