AutoModelForQuestionAnswering
AutoModelForQuestionAnswering
class transformers.AutoModelForQuestionAnswering
( *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).
from_config
( **kwargs )
Parameters
config (PretrainedConfig) — The model class to instantiate is selected based on the configuration class:
AlbertConfig configuration class: AlbertForQuestionAnswering (ALBERT model)
BartConfig configuration class: BartForQuestionAnswering (BART model)
BertConfig configuration class: BertForQuestionAnswering (BERT model)
BigBirdConfig configuration class: BigBirdForQuestionAnswering (BigBird model)
BigBirdPegasusConfig configuration class: BigBirdPegasusForQuestionAnswering (BigBird-Pegasus model)
BloomConfig configuration class: BloomForQuestionAnswering (BLOOM model)
CamembertConfig configuration class: CamembertForQuestionAnswering (CamemBERT model)
CanineConfig configuration class: CanineForQuestionAnswering (CANINE model)
ConvBertConfig configuration class: ConvBertForQuestionAnswering (ConvBERT model)
Data2VecTextConfig configuration class: Data2VecTextForQuestionAnswering (Data2VecText model)
DebertaConfig configuration class: DebertaForQuestionAnswering (DeBERTa model)
DebertaV2Config configuration class: DebertaV2ForQuestionAnswering (DeBERTa-v2 model)
DistilBertConfig configuration class: DistilBertForQuestionAnswering (DistilBERT model)
ElectraConfig configuration class: ElectraForQuestionAnswering (ELECTRA model)
ErnieConfig configuration class: ErnieForQuestionAnswering (ERNIE model)
ErnieMConfig configuration class: ErnieMForQuestionAnswering (ErnieM model)
FNetConfig configuration class: FNetForQuestionAnswering (FNet model)
FalconConfig configuration class: FalconForQuestionAnswering (Falcon model)
FlaubertConfig configuration class: FlaubertForQuestionAnsweringSimple (FlauBERT model)
FunnelConfig configuration class: FunnelForQuestionAnswering (Funnel Transformer model)
GPT2Config configuration class: GPT2ForQuestionAnswering (OpenAI GPT-2 model)
GPTJConfig configuration class: GPTJForQuestionAnswering (GPT-J model)
GPTNeoConfig configuration class: GPTNeoForQuestionAnswering (GPT Neo model)
GPTNeoXConfig configuration class: GPTNeoXForQuestionAnswering (GPT NeoX model)
IBertConfig configuration class: IBertForQuestionAnswering (I-BERT model)
LEDConfig configuration class: LEDForQuestionAnswering (LED model)
LayoutLMv2Config configuration class: LayoutLMv2ForQuestionAnswering (LayoutLMv2 model)
LayoutLMv3Config configuration class: LayoutLMv3ForQuestionAnswering (LayoutLMv3 model)
LiltConfig configuration class: LiltForQuestionAnswering (LiLT model)
LongformerConfig configuration class: LongformerForQuestionAnswering (Longformer model)
LukeConfig configuration class: LukeForQuestionAnswering (LUKE model)
LxmertConfig configuration class: LxmertForQuestionAnswering (LXMERT model)
MBartConfig configuration class: MBartForQuestionAnswering (mBART model)
MPNetConfig configuration class: MPNetForQuestionAnswering (MPNet model)
MT5Config configuration class: MT5ForQuestionAnswering (MT5 model)
MarkupLMConfig configuration class: MarkupLMForQuestionAnswering (MarkupLM model)
MegaConfig configuration class: MegaForQuestionAnswering (MEGA model)
MegatronBertConfig configuration class: MegatronBertForQuestionAnswering (Megatron-BERT model)
MobileBertConfig configuration class: MobileBertForQuestionAnswering (MobileBERT model)
MptConfig configuration class: MptForQuestionAnswering (MPT model)
MraConfig configuration class: MraForQuestionAnswering (MRA model)
MvpConfig configuration class: MvpForQuestionAnswering (MVP model)
NezhaConfig configuration class: NezhaForQuestionAnswering (Nezha model)
NystromformerConfig configuration class: NystromformerForQuestionAnswering (Nyströmformer model)
OPTConfig configuration class: OPTForQuestionAnswering (OPT model)
QDQBertConfig configuration class: QDQBertForQuestionAnswering (QDQBert model)
ReformerConfig configuration class: ReformerForQuestionAnswering (Reformer model)
RemBertConfig configuration class: RemBertForQuestionAnswering (RemBERT model)
RoCBertConfig configuration class: RoCBertForQuestionAnswering (RoCBert model)
RoFormerConfig configuration class: RoFormerForQuestionAnswering (RoFormer model)
RobertaConfig configuration class: RobertaForQuestionAnswering (RoBERTa model)
RobertaPreLayerNormConfig configuration class: RobertaPreLayerNormForQuestionAnswering (RoBERTa-PreLayerNorm model)
SplinterConfig configuration class: SplinterForQuestionAnswering (Splinter model)
SqueezeBertConfig configuration class: SqueezeBertForQuestionAnswering (SqueezeBERT model)
T5Config configuration class: T5ForQuestionAnswering (T5 model)
UMT5Config configuration class: UMT5ForQuestionAnswering (UMT5 model)
XLMConfig configuration class: XLMForQuestionAnsweringSimple (XLM model)
XLMRobertaConfig configuration class: XLMRobertaForQuestionAnswering (XLM-RoBERTa model)
XLMRobertaXLConfig configuration class: XLMRobertaXLForQuestionAnswering (XLM-RoBERTa-XL model)
XLNetConfig configuration class: XLNetForQuestionAnsweringSimple (XLNet model)
XmodConfig configuration class: XmodForQuestionAnswering (X-MOD model)
YosoConfig configuration class: YosoForQuestionAnswering (YOSO model)
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:
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 tensorflow index checkpoint file (e.g,
./tf_model/model.ckpt.index
). In this case,from_tf
should be set toTrue
and a configuration object should be provided asconfig
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.
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.
state_dict (Dict[str, torch.Tensor], optional) — A state dictionary to use instead of a state dictionary loaded from saved weights file.
This option can be used if you want to create a model from a pretrained configuration but load your own weights. In this case though, you should check if using save_pretrained() and from_pretrained() is not a simpler option.
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_tf (
bool
, optional, defaults toFalse
) — Load the model weights from a TensorFlow 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 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
:
albert — AlbertForQuestionAnswering (ALBERT model)
bart — BartForQuestionAnswering (BART model)
bert — BertForQuestionAnswering (BERT model)
big_bird — BigBirdForQuestionAnswering (BigBird model)
bigbird_pegasus — BigBirdPegasusForQuestionAnswering (BigBird-Pegasus model)
bloom — BloomForQuestionAnswering (BLOOM model)
camembert — CamembertForQuestionAnswering (CamemBERT model)
canine — CanineForQuestionAnswering (CANINE model)
convbert — ConvBertForQuestionAnswering (ConvBERT model)
data2vec-text — Data2VecTextForQuestionAnswering (Data2VecText model)
deberta — DebertaForQuestionAnswering (DeBERTa model)
deberta-v2 — DebertaV2ForQuestionAnswering (DeBERTa-v2 model)
distilbert — DistilBertForQuestionAnswering (DistilBERT model)
electra — ElectraForQuestionAnswering (ELECTRA model)
ernie — ErnieForQuestionAnswering (ERNIE model)
ernie_m — ErnieMForQuestionAnswering (ErnieM model)
falcon — FalconForQuestionAnswering (Falcon model)
flaubert — FlaubertForQuestionAnsweringSimple (FlauBERT model)
fnet — FNetForQuestionAnswering (FNet model)
funnel — FunnelForQuestionAnswering (Funnel Transformer model)
gpt2 — GPT2ForQuestionAnswering (OpenAI GPT-2 model)
gpt_neo — GPTNeoForQuestionAnswering (GPT Neo model)
gpt_neox — GPTNeoXForQuestionAnswering (GPT NeoX model)
gptj — GPTJForQuestionAnswering (GPT-J model)
ibert — IBertForQuestionAnswering (I-BERT model)
layoutlmv2 — LayoutLMv2ForQuestionAnswering (LayoutLMv2 model)
layoutlmv3 — LayoutLMv3ForQuestionAnswering (LayoutLMv3 model)
led — LEDForQuestionAnswering (LED model)
lilt — LiltForQuestionAnswering (LiLT model)
longformer — LongformerForQuestionAnswering (Longformer model)
luke — LukeForQuestionAnswering (LUKE model)
lxmert — LxmertForQuestionAnswering (LXMERT model)
markuplm — MarkupLMForQuestionAnswering (MarkupLM model)
mbart — MBartForQuestionAnswering (mBART model)
mega — MegaForQuestionAnswering (MEGA model)
megatron-bert — MegatronBertForQuestionAnswering (Megatron-BERT model)
mobilebert — MobileBertForQuestionAnswering (MobileBERT model)
mpnet — MPNetForQuestionAnswering (MPNet model)
mpt — MptForQuestionAnswering (MPT model)
mra — MraForQuestionAnswering (MRA model)
mt5 — MT5ForQuestionAnswering (MT5 model)
mvp — MvpForQuestionAnswering (MVP model)
nezha — NezhaForQuestionAnswering (Nezha model)
nystromformer — NystromformerForQuestionAnswering (Nyströmformer model)
opt — OPTForQuestionAnswering (OPT model)
qdqbert — QDQBertForQuestionAnswering (QDQBert model)
reformer — ReformerForQuestionAnswering (Reformer model)
rembert — RemBertForQuestionAnswering (RemBERT model)
roberta — RobertaForQuestionAnswering (RoBERTa model)
roberta-prelayernorm — RobertaPreLayerNormForQuestionAnswering (RoBERTa-PreLayerNorm model)
roc_bert — RoCBertForQuestionAnswering (RoCBert model)
roformer — RoFormerForQuestionAnswering (RoFormer model)
splinter — SplinterForQuestionAnswering (Splinter model)
squeezebert — SqueezeBertForQuestionAnswering (SqueezeBERT model)
t5 — T5ForQuestionAnswering (T5 model)
umt5 — UMT5ForQuestionAnswering (UMT5 model)
xlm — XLMForQuestionAnsweringSimple (XLM model)
xlm-roberta — XLMRobertaForQuestionAnswering (XLM-RoBERTa model)
xlm-roberta-xl — XLMRobertaXLForQuestionAnswering (XLM-RoBERTa-XL model)
xlnet — XLNetForQuestionAnsweringSimple (XLNet model)
xmod — XmodForQuestionAnswering (X-MOD model)
yoso — YosoForQuestionAnswering (YOSO 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:
Copied
Last updated