TFAutoModelForPreTraining
TFAutoModelForPreTraining
class transformers.TFAutoModelForPreTraining
( *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).
from_config
( **kwargs )
Parameters
config (PretrainedConfig) — The model class to instantiate is selected based on the configuration class:
AlbertConfig configuration class: TFAlbertForPreTraining (ALBERT model)
BartConfig configuration class: TFBartForConditionalGeneration (BART model)
BertConfig configuration class: TFBertForPreTraining (BERT model)
CTRLConfig configuration class: TFCTRLLMHeadModel (CTRL model)
CamembertConfig configuration class: TFCamembertForMaskedLM (CamemBERT model)
DistilBertConfig configuration class: TFDistilBertForMaskedLM (DistilBERT model)
ElectraConfig configuration class: TFElectraForPreTraining (ELECTRA model)
FlaubertConfig configuration class: TFFlaubertWithLMHeadModel (FlauBERT model)
FunnelConfig configuration class: TFFunnelForPreTraining (Funnel Transformer model)
GPT2Config configuration class: TFGPT2LMHeadModel (OpenAI GPT-2 model)
LayoutLMConfig configuration class: TFLayoutLMForMaskedLM (LayoutLM model)
LxmertConfig configuration class: TFLxmertForPreTraining (LXMERT model)
MPNetConfig configuration class: TFMPNetForMaskedLM (MPNet model)
MobileBertConfig configuration class: TFMobileBertForPreTraining (MobileBERT model)
OpenAIGPTConfig configuration class: TFOpenAIGPTLMHeadModel (OpenAI GPT model)
RobertaConfig configuration class: TFRobertaForMaskedLM (RoBERTa model)
RobertaPreLayerNormConfig configuration class: TFRobertaPreLayerNormForMaskedLM (RoBERTa-PreLayerNorm model)
T5Config configuration class: TFT5ForConditionalGeneration (T5 model)
TapasConfig configuration class: TFTapasForMaskedLM (TAPAS model)
TransfoXLConfig configuration class: TFTransfoXLLMHeadModel (Transformer-XL model)
ViTMAEConfig configuration class: TFViTMAEForPreTraining (ViTMAE model)
XLMConfig configuration class: TFXLMWithLMHeadModel (XLM model)
XLMRobertaConfig configuration class: TFXLMRobertaForMaskedLM (XLM-RoBERTa model)
XLNetConfig configuration class: TFXLNetLMHeadModel (XLNet model)
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:
Copied
from_pretrained
( *model_args**kwargs )
Parameters
pretrained_model_name_or_path (
str
oros.PathLike
) — Can be either:A string, the model id of a pretrained model hosted inside a model repo on huggingface.co. Valid model ids can be located at the root-level, like
bert-base-uncased
, or namespaced under a user or organization name, likedbmdz/bert-base-german-cased
.A path to a directory containing model weights saved using save_pretrained(), e.g.,
./my_model_directory/
.A path or url to a PyTorch state_dict save file (e.g,
./pt_model/pytorch_model.bin
). In this case,from_pt
should be set toTrue
and a configuration object should be provided asconfig
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.
model_args (additional positional arguments, optional) — Will be passed along to the underlying model
__init__()
method.config (PretrainedConfig, optional) — Configuration for the model to use instead of an automatically loaded configuration. Configuration can be automatically loaded when:
The model is a model provided by the library (loaded with the model id string of a pretrained model).
The model was saved using save_pretrained() and is reloaded by supplying the save directory.
The model is loaded by supplying a local directory as
pretrained_model_name_or_path
and a configuration JSON file named config.json is found in the directory.
cache_dir (
str
oros.PathLike
, optional) — Path to a directory in which a downloaded pretrained model configuration should be cached if the standard cache should not be used.from_pt (
bool
, optional, defaults toFalse
) — Load the model weights from a PyTorch checkpoint save file (see docstring ofpretrained_model_name_or_path
argument).force_download (
bool
, optional, defaults toFalse
) — Whether or not to force the (re-)download of the model weights and configuration files, overriding the cached versions if they exist.resume_download (
bool
, optional, defaults toFalse
) — Whether or not to delete incompletely received files. Will attempt to resume the download if such a file exists.proxies (
Dict[str, str]
, optional) — A dictionary of proxy servers to use by protocol or endpoint, e.g.,{'http': 'foo.bar:3128', 'http://hostname': 'foo.bar:4012'}
. The proxies are used on each request.output_loading_info(
bool
, optional, defaults toFalse
) — Whether ot not to also return a dictionary containing missing keys, unexpected keys and error messages.local_files_only(
bool
, optional, defaults toFalse
) — Whether or not to only look at local files (e.g., not try downloading the model).revision (
str
, optional, defaults to"main"
) — The specific model version to use. It can be a branch name, a tag name, or a commit id, since we use a git-based system for storing models and other artifacts on huggingface.co, sorevision
can be any identifier allowed by git.trust_remote_code (
bool
, optional, defaults toFalse
) — Whether or not to allow for custom models defined on the Hub in their own modeling files. This option should only be set toTrue
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.code_revision (
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, sorevision
can be any identifier allowed by git.kwargs (additional keyword arguments, optional) — Can be used to update the configuration object (after it being loaded) and initiate the model (e.g.,
output_attentions=True
). Behaves differently depending on whether aconfig
is provided or automatically loaded:If a configuration is provided with
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)If a configuration is not provided,
kwargs
will be first passed to the configuration class initialization function (from_pretrained()). Each key ofkwargs
that corresponds to a configuration attribute will be used to override said attribute with the suppliedkwargs
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
:
albert — TFAlbertForPreTraining (ALBERT model)
bart — TFBartForConditionalGeneration (BART model)
bert — TFBertForPreTraining (BERT model)
camembert — TFCamembertForMaskedLM (CamemBERT model)
ctrl — TFCTRLLMHeadModel (CTRL model)
distilbert — TFDistilBertForMaskedLM (DistilBERT model)
electra — TFElectraForPreTraining (ELECTRA model)
flaubert — TFFlaubertWithLMHeadModel (FlauBERT model)
funnel — TFFunnelForPreTraining (Funnel Transformer model)
gpt-sw3 — TFGPT2LMHeadModel (GPT-Sw3 model)
gpt2 — TFGPT2LMHeadModel (OpenAI GPT-2 model)
layoutlm — TFLayoutLMForMaskedLM (LayoutLM model)
lxmert — TFLxmertForPreTraining (LXMERT model)
mobilebert — TFMobileBertForPreTraining (MobileBERT model)
mpnet — TFMPNetForMaskedLM (MPNet model)
openai-gpt — TFOpenAIGPTLMHeadModel (OpenAI GPT model)
roberta — TFRobertaForMaskedLM (RoBERTa model)
roberta-prelayernorm — TFRobertaPreLayerNormForMaskedLM (RoBERTa-PreLayerNorm model)
t5 — TFT5ForConditionalGeneration (T5 model)
tapas — TFTapasForMaskedLM (TAPAS model)
transfo-xl — TFTransfoXLLMHeadModel (Transformer-XL model)
vit_mae — TFViTMAEForPreTraining (ViTMAE model)
xlm — TFXLMWithLMHeadModel (XLM model)
xlm-roberta — TFXLMRobertaForMaskedLM (XLM-RoBERTa model)
xlnet — TFXLNetLMHeadModel (XLNet model)
Examples:
Copied
Last updated