2020 the huggingface team licensed under the apache license version 2 0 the license you may not use this file except in compliance with the license you may obtain a copy of the license at http www apache orglicenseslicense2 0 unless required by applicable law or agreed to in writing software distributed under the license is distributed on an as is basis without warranties or conditions of any kind either express or implied see the license for the specific language governing permissions and limitations under the license base class for model s outputs with potential hidden states and attentions args lasthiddenstate tf tensor of shape batchsize sequencelength hiddensize sequence of hiddenstates at the output of the last layer of the model hiddenstates tupletf floattensor optional returned when outputhiddenstatestrue is passed or when config outputhiddenstatestrue tuple of tf tensor one for the output of the embeddings one for the output of each layer of shape batchsize sequencelength hiddensize hiddenstates of the model at the output of each layer plus the initial embedding outputs attentions tupletf tensor optional returned when outputattentionstrue is passed or when config outputattentionstrue tuple of tf tensor one for each layer of shape batchsize numheads sequencelength sequencelength attentions weights after the attention softmax used to compute the weighted average in the selfattention heads base class for model s outputs with potential hidden states args lasthiddenstate tf tensor shape batchsize numchannels height width sequence of hiddenstates at the output of the last layer of the model hiddenstates tupletf tensor optional returned when outputhiddenstatestrue is passed or when config outputhiddenstatestrue tuple of tf tensor one for the output of the embeddings if the model has an embedding layer one for the output of each layer of shape batchsize numchannels height width hiddenstates of the model at the output of each layer plus the optional initial embedding outputs base class for model s outputs that also contains a pooling of the last hidden states args lasthiddenstate tf tensor of shape batchsize sequencelength hiddensize sequence of hiddenstates at the output of the last layer of the model pooleroutput tf tensor of shape batchsize hiddensize last layer hiddenstate of the first token of the sequence classification token further processed by a linear layer and a tanh activation function the linear layer weights are trained from the next sentence prediction classification objective during pretraining this output is usually not a good summary of the semantic content of the input you re often better with averaging or pooling the sequence of hiddenstates for the whole input sequence hiddenstates tupletf tensor optional returned when outputhiddenstatestrue is passed or when config outputhiddenstatestrue tuple of tf tensor one for the output of the embeddings one for the output of each layer of shape batchsize sequencelength hiddensize hiddenstates of the model at the output of each layer plus the initial embedding outputs attentions tupletf tensor optional returned when outputattentionstrue is passed or when config outputattentionstrue tuple of tf tensor one for each layer of shape batchsize numheads sequencelength sequencelength attentions weights after the attention softmax used to compute the weighted average in the selfattention heads base class for model s outputs that also contains a pooling of the last hidden states args lasthiddenstate tf tensor of shape batchsize numchannels height width sequence of hiddenstates at the output of the last layer of the model pooleroutput tf tensor of shape batchsize hiddensize last layer hiddenstate after a pooling operation on the spatial dimensions hiddenstates tupletf tensor optional returned when outputhiddenstatestrue is passed or when config outputhiddenstatestrue tuple of tf tensor one for the output of the embeddings if the model has an embedding layer one for the output of each layer of shape batchsize numchannels height width hiddenstates of the model at the output of each layer plus the optional initial embedding outputs base class for model s outputs that also contains a pooling of the last hidden states args lasthiddenstate tf tensor of shape batchsize sequencelength hiddensize sequence of hiddenstates at the output of the last layer of the model pooleroutput tf tensor of shape batchsize hiddensize last layer hiddenstate of the first token of the sequence classification token further processed by a linear layer and a tanh activation function the linear layer weights are trained from the next sentence prediction classification objective during pretraining this output is usually not a good summary of the semantic content of the input you re often better with averaging or pooling the sequence of hiddenstates for the whole input sequence pastkeyvalues listtf tensor optional returned when usecachetrue is passed or when config usecachetrue list of tf tensor of length config nlayers with each tensor of shape 2 batchsize numheads sequencelength embedsizeperhead contains precomputed hiddenstates key and values in the attention blocks that can be used see pastkeyvalues input to speed up sequential decoding hiddenstates tupletf tensor optional returned when outputhiddenstatestrue is passed or when config outputhiddenstatestrue tuple of tf tensor one for the output of the embeddings one for the output of each layer of shape batchsize sequencelength hiddensize hiddenstates of the model at the output of each layer plus the initial embedding outputs attentions tupletf tensor optional returned when outputattentionstrue is passed or when config outputattentionstrue tuple of tf tensor one for each layer of shape batchsize numheads sequencelength sequencelength attentions weights after the attention softmax used to compute the weighted average in the selfattention heads crossattentions tupletf tensor optional returned when outputattentionstrue is passed or when config outputattentionstrue tuple of tf tensor one for each layer of shape batchsize numheads sequencelength sequencelength attentions weights of the decoder s crossattention layer after the attention softmax used to compute the weighted average in the crossattention heads base class for model s outputs that may also contain a past keyvalues to speed up sequential decoding args lasthiddenstate tf tensor of shape batchsize sequencelength hiddensize sequence of hiddenstates at the output of the last layer of the model if pastkeyvalues is used only the last hiddenstate of the sequences of shape batchsize 1 hiddensize is output pastkeyvalues listtf tensor optional returned when usecachetrue is passed or when config usecachetrue list of tf tensor of length config nlayers with each tensor of shape 2 batchsize numheads sequencelength embedsizeperhead contains precomputed hiddenstates key and values in the attention blocks that can be used see pastkeyvalues input to speed up sequential decoding hiddenstates tupletf tensor optional returned when outputhiddenstatestrue is passed or when config outputhiddenstatestrue tuple of tf tensor one for the output of the embeddings one for the output of each layer of shape batchsize sequencelength hiddensize hiddenstates of the model at the output of each layer plus the initial embedding outputs attentions tupletf tensor optional returned when outputattentionstrue is passed or when config outputattentionstrue tuple of tf tensor one for each layer of shape batchsize numheads sequencelength sequencelength attentions weights after the attention softmax used to compute the weighted average in the selfattention heads base class for model s outputs with potential hidden states and attentions args lasthiddenstate tf tensor of shape batchsize sequencelength hiddensize sequence of hiddenstates at the output of the last layer of the model hiddenstates tupletf floattensor optional returned when outputhiddenstatestrue is passed or when config outputhiddenstatestrue tuple of tf tensor one for the output of the embeddings one for the output of each layer of shape batchsize sequencelength hiddensize hiddenstates of the model at the output of each layer plus the initial embedding outputs attentions tupletf tensor optional returned when outputattentionstrue is passed or when config outputattentionstrue tuple of tf tensor one for each layer of shape batchsize numheads sequencelength sequencelength attentions weights after the attention softmax used to compute the weighted average in the selfattention heads crossattentions tupletf tensor optional returned when outputattentionstrue is passed or when config outputattentionstrue tuple of tf tensor one for each layer of shape batchsize numheads sequencelength sequencelength attentions weights of the decoder s crossattention layer after the attention softmax used to compute the weighted average in the crossattention heads base class for model s outputs that may also contain a past keyvalues to speed up sequential decoding args lasthiddenstate tf tensor of shape batchsize sequencelength hiddensize sequence of hiddenstates at the output of the last layer of the model if pastkeyvalues is used only the last hiddenstate of the sequences of shape batchsize 1 hiddensize is output pastkeyvalues listtf tensor optional returned when usecachetrue is passed or when config usecachetrue list of tf tensor of length config nlayers with each tensor of shape 2 batchsize numheads sequencelength embedsizeperhead contains precomputed hiddenstates key and values in the attention blocks that can be used see pastkeyvalues input to speed up sequential decoding hiddenstates tupletf floattensor optional returned when outputhiddenstatestrue is passed or when config outputhiddenstatestrue tuple of tf tensor one for the output of the embeddings one for the output of each layer of shape batchsize sequencelength hiddensize hiddenstates of the model at the output of each layer plus the initial embedding outputs attentions tupletf tensor optional returned when outputattentionstrue is passed or when config outputattentionstrue tuple of tf tensor one for each layer of shape batchsize numheads sequencelength sequencelength attentions weights after the attention softmax used to compute the weighted average in the selfattention heads crossattentions tupletf tensor optional returned when outputattentionstrue is passed or when config outputattentionstrue tuple of tf tensor one for each layer of shape batchsize numheads sequencelength sequencelength attentions weights of the decoder s crossattention layer after the attention softmax used to compute the weighted average in the crossattention heads base class for model encoder s outputs that also contains precomputed hidden states that can speed up sequential decoding args lasthiddenstate tf tensor of shape batchsize sequencelength hiddensize sequence of hiddenstates at the output of the last layer of the decoder of the model if pastkeyvalues is used only the last hiddenstate of the sequences of shape batchsize 1 hiddensize is output pastkeyvalues listtf tensor optional returned when usecachetrue is passed or when config usecachetrue list of tf tensor of length config nlayers with each tensor of shape 2 batchsize numheads sequencelength embedsizeperhead contains precomputed hiddenstates key and values in the attention blocks of the decoder that can be used see pastkeyvalues input to speed up sequential decoding decoderhiddenstates tupletf tensor optional returned when outputhiddenstatestrue is passed or when config outputhiddenstatestrue tuple of tf tensor one for the output of the embeddings one for the output of each layer of shape batchsize sequencelength hiddensize hiddenstates of the decoder at the output of each layer plus the initial embedding outputs decoderattentions tupletf tensor optional returned when outputattentionstrue is passed or when config outputattentionstrue tuple of tf tensor one for each layer of shape batchsize numheads sequencelength sequencelength attentions weights of the decoder after the attention softmax used to compute the weighted average in the selfattention heads crossattentions tupletf tensor optional returned when outputattentionstrue is passed or when config outputattentionstrue tuple of tf tensor one for each layer of shape batchsize numheads sequencelength sequencelength attentions weights of the decoder s crossattention layer after the attention softmax used to compute the weighted average in the crossattention heads encoderlasthiddenstate tf tensor of shape batchsize sequencelength hiddensize optional sequence of hiddenstates at the output of the last layer of the encoder of the model encoderhiddenstates tupletf tensor optional returned when outputhiddenstatestrue is passed or when config outputhiddenstatestrue tuple of tf tensor one for the output of the embeddings one for the output of each layer of shape batchsize sequencelength hiddensize hiddenstates of the encoder at the output of each layer plus the initial embedding outputs encoderattentions tupletf tensor optional returned when outputattentionstrue is passed or when config outputattentionstrue tuple of tf tensor one for each layer of shape batchsize numheads sequencelength sequencelength attentions weights of the encoder after the attention softmax used to compute the weighted average in the selfattention heads base class for causal language model or autoregressive outputs args loss tf tensor of shape n optional where n is the number of nonmasked labels returned when labels is provided language modeling loss for nexttoken prediction logits tf tensor of shape batchsize sequencelength config vocabsize prediction scores of the language modeling head scores for each vocabulary token before softmax hiddenstates tupletf tensor optional returned when outputhiddenstatestrue is passed or when config outputhiddenstatestrue tuple of tf tensor one for the output of the embeddings one for the output of each layer of shape batchsize sequencelength hiddensize hiddenstates of the model at the output of each layer plus the initial embedding outputs attentions tupletf tensor optional returned when outputattentionstrue is passed or when config outputattentionstrue tuple of tf tensor one for each layer of shape batchsize numheads sequencelength sequencelength attentions weights after the attention softmax used to compute the weighted average in the selfattention heads base class for causal language model or autoregressive outputs args loss tf tensor of shape n optional where n is the number of nonmasked labels returned when labels is provided language modeling loss for nexttoken prediction logits tf tensor of shape batchsize sequencelength config vocabsize prediction scores of the language modeling head scores for each vocabulary token before softmax pastkeyvalues listtf tensor optional returned when usecachetrue is passed or when config usecachetrue list of tf tensor of length config nlayers with each tensor of shape 2 batchsize numheads sequencelength embedsizeperhead contains precomputed hiddenstates key and values in the attention blocks that can be used see pastkeyvalues input to speed up sequential decoding hiddenstates tupletf tensor optional returned when outputhiddenstatestrue is passed or when config outputhiddenstatestrue tuple of tf tensor one for the output of the embeddings one for the output of each layer of shape batchsize sequencelength hiddensize hiddenstates of the model at the output of each layer plus the initial embedding outputs attentions tupletf tensor optional returned when outputattentionstrue is passed or when config outputattentionstrue tuple of tf tensor one for each layer of shape batchsize numheads sequencelength sequencelength attentions weights after the attention softmax used to compute the weighted average in the selfattention heads base class for causal language model or autoregressive outputs args loss tf tensor of shape n optional where n is the number of nonmasked labels returned when labels is provided language modeling loss for nexttoken prediction logits tf tensor of shape batchsize sequencelength config vocabsize prediction scores of the language modeling head scores for each vocabulary token before softmax hiddenstates tupletf tensor optional returned when outputhiddenstatestrue is passed or when config outputhiddenstatestrue tuple of tf tensor one for the output of the embeddings one for the output of each layer of shape batchsize sequencelength hiddensize hiddenstates of the model at the output of each layer plus the initial embedding outputs attentions tupletf tensor optional returned when outputattentionstrue is passed or when config outputattentionstrue tuple of tf tensor one for each layer of shape batchsize numheads sequencelength sequencelength attentions weights after the attention softmax used to compute the weighted average in the selfattention heads crossattentions tupletf tensor optional returned when outputattentionstrue is passed or when config outputattentionstrue tuple of tf tensor one for each layer of shape batchsize numheads sequencelength sequencelength attentions weights of the decoder s crossattention layer after the attention softmax used to compute the weighted average in the crossattention heads pastkeyvalues listtf tensor optional returned when usecachetrue is passed or when config usecachetrue list of tf tensor of length config nlayers with each tensor of shape 2 batchsize numheads sequencelength embedsizeperhead contains precomputed hiddenstates key and values in the attention blocks that can be used see pastkeyvalues input to speed up sequential decoding base class for masked language models outputs args loss tf tensor of shape n optional where n is the number of nonmasked labels returned when labels is provided masked language modeling mlm loss logits tf tensor of shape batchsize sequencelength config vocabsize prediction scores of the language modeling head scores for each vocabulary token before softmax hiddenstates tupletf tensor optional returned when outputhiddenstatestrue is passed or when config outputhiddenstatestrue tuple of tf tensor one for the output of the embeddings one for the output of each layer of shape batchsize sequencelength hiddensize hiddenstates of the model at the output of each layer plus the initial embedding outputs attentions tupletf tensor optional returned when outputattentionstrue is passed or when config outputattentionstrue tuple of tf tensor one for each layer of shape batchsize numheads sequencelength sequencelength attentions weights after the attention softmax used to compute the weighted average in the selfattention heads base class for sequencetosequence language models outputs args loss tf tensor of shape n optional where n is the number of nonmasked labels returned when labels is provided language modeling loss logits tf tensor of shape batchsize sequencelength config vocabsize prediction scores of the language modeling head scores for each vocabulary token before softmax pastkeyvalues listtf tensor optional returned when usecachetrue is passed or when config usecachetrue list of tf tensor of length config nlayers with each tensor of shape 2 batchsize numheads sequencelength embedsizeperhead contains precomputed hiddenstates key and values in the attention blocks of the decoder that can be used see pastkeyvalues input to speed up sequential decoding decoderhiddenstates tupletf tensor optional returned when outputhiddenstatestrue is passed or when config outputhiddenstatestrue tuple of tf tensor one for the output of the embeddings one for the output of each layer of shape batchsize sequencelength hiddensize hiddenstates of the decoder at the output of each layer plus the initial embedding outputs decoderattentions tupletf tensor optional returned when outputattentionstrue is passed or when config outputattentionstrue tuple of tf tensor one for each layer of shape batchsize numheads sequencelength sequencelength attentions weights of the decoder after the attention softmax used to compute the weighted average in the selfattention heads crossattentions tupletf tensor optional returned when outputattentionstrue is passed or when config outputattentionstrue tuple of tf tensor one for each layer of shape batchsize numheads sequencelength sequencelength attentions weights of the decoder s crossattention layer after the attention softmax used to compute the weighted average in the crossattention heads encoderlasthiddenstate tf tensor of shape batchsize sequencelength hiddensize optional sequence of hiddenstates at the output of the last layer of the encoder of the model encoderhiddenstates tupletf tensor optional returned when outputhiddenstatestrue is passed or when config outputhiddenstatestrue tuple of tf tensor one for the output of the embeddings one for the output of each layer of shape batchsize sequencelength hiddensize hiddenstates of the encoder at the output of each layer plus the initial embedding outputs encoderattentions tupletf tensor optional returned when outputattentionstrue is passed or when config outputattentionstrue tuple of tf tensor one for each layer of shape batchsize numheads sequencelength sequencelength attentions weights of the encoder after the attention softmax used to compute the weighted average in the selfattention heads base class for outputs of models predicting if two sentences are consecutive or not args loss tf tensor of shape n optional where n is the number of nonmasked labels returned when nextsentencelabel is provided next sentence prediction loss logits tf tensor of shape batchsize 2 prediction scores of the next sequence prediction classification head scores of truefalse continuation before softmax hiddenstates tupletf tensor optional returned when outputhiddenstatestrue is passed or when config outputhiddenstatestrue tuple of tf tensor one for the output of the embeddings one for the output of each layer of shape batchsize sequencelength hiddensize hiddenstates of the model at the output of each layer plus the initial embedding outputs attentions tupletf tensor optional returned when outputattentionstrue is passed or when config outputattentionstrue tuple of tf tensor one for each layer of shape batchsize numheads sequencelength sequencelength attentions weights after the attention softmax used to compute the weighted average in the selfattention heads base class for outputs of sentence classification models args loss tf tensor of shape batchsize optional returned when labels is provided classification or regression if config numlabels1 loss logits tf tensor of shape batchsize config numlabels classification or regression if config numlabels1 scores before softmax hiddenstates tupletf tensor optional returned when outputhiddenstatestrue is passed or when config outputhiddenstatestrue tuple of tf tensor one for the output of the embeddings one for the output of each layer of shape batchsize sequencelength hiddensize hiddenstates of the model at the output of each layer plus the initial embedding outputs attentions tupletf tensor optional returned when outputattentionstrue is passed or when config outputattentionstrue tuple of tf tensor one for each layer of shape batchsize numheads sequencelength sequencelength attentions weights after the attention softmax used to compute the weighted average in the selfattention heads base class for outputs of sequencetosequence sentence classification models args loss tf tensor of shape 1 optional returned when label is provided classification or regression if config numlabels1 loss logits tf tensor of shape batchsize config numlabels classification or regression if config numlabels1 scores before softmax pastkeyvalues listtf tensor optional returned when usecachetrue is passed or when config usecachetrue list of tf tensor of length config nlayers with each tensor of shape 2 batchsize numheads sequencelength embedsizeperhead contains precomputed hiddenstates key and values in the attention blocks of the decoder that can be used see pastkeyvalues input to speed up sequential decoding decoderhiddenstates tupletf tensor optional returned when outputhiddenstatestrue is passed or when config outputhiddenstatestrue tuple of tf tensor one for the output of the embeddings one for the output of each layer of shape batchsize sequencelength hiddensize hiddenstates of the decoder at the output of each layer plus the initial embedding outputs decoderattentions tupletf tensor optional returned when outputattentionstrue is passed or when config outputattentionstrue tuple of tf tensor one for each layer of shape batchsize numheads sequencelength sequencelength attentions weights of the decoder after the attention softmax used to compute the weighted average in the selfattention heads crossattentions tupletf tensor optional returned when outputattentionstrue is passed or when config outputattentionstrue tuple of tf tensor one for each layer of shape batchsize numheads sequencelength sequencelength encoderlasthiddenstate tf tensor of shape batchsize sequencelength hiddensize optional sequence of hiddenstates at the output of the last layer of the encoder of the model encoderhiddenstates tupletf tensor optional returned when outputhiddenstatestrue is passed or when config outputhiddenstatestrue tuple of tf tensor one for the output of the embeddings one for the output of each layer of shape batchsize sequencelength hiddensize hiddenstates of the encoder at the output of each layer plus the initial embedding outputs encoderattentions tupletf tensor optional returned when outputattentionstrue is passed or when config outputattentionstrue tuple of tf tensor one for each layer of shape batchsize numheads sequencelength sequencelength attentions weights of the encoder after the attention softmax used to compute the weighted average in the selfattention heads base class for outputs of semantic segmentation models args loss tf tensor of shape 1 optional returned when labels is provided classification or regression if config numlabels1 loss logits tf tensor of shape batchsize config numlabels logitsheight logitswidth classification scores for each pixel tip warningtrue the logits returned do not necessarily have the same size as the pixelvalues passed as inputs this is to avoid doing two interpolations and lose some quality when a user needs to resize the logits to the original image size as postprocessing you should always check your logits shape and resize as needed tip hiddenstates tupletf tensor optional returned when outputhiddenstatestrue is passed or when config outputhiddenstatestrue tuple of tf tensor one for the output of the embeddings if the model has an embedding layer one for the output of each layer of shape batchsize patchsize hiddensize hiddenstates of the model at the output of each layer plus the optional initial embedding outputs attentions tupletf tensor optional returned when outputattentionstrue is passed or when config outputattentionstrue tuple of tf tensor one for each layer of shape batchsize numheads patchsize sequencelength attentions weights after the attention softmax used to compute the weighted average in the selfattention heads base class for outputs of semantic segmentation models that do not output attention scores args loss tf tensor of shape 1 optional returned when labels is provided classification or regression if config numlabels1 loss logits tf tensor of shape batchsize config numlabels logitsheight logitswidth classification scores for each pixel tip warningtrue the logits returned do not necessarily have the same size as the pixelvalues passed as inputs this is to avoid doing two interpolations and lose some quality when a user needs to resize the logits to the original image size as postprocessing you should always check your logits shape and resize as needed tip hiddenstates tupletf tensor optional returned when outputhiddenstatestrue is passed or when config outputhiddenstatestrue tuple of tf tensor one for the output of the embeddings if the model has an embedding layer one for the output of each layer of shape batchsize patchsize hiddensize hiddenstates of the model at the output of each layer plus the optional initial embedding outputs base class for outputs of image classification models args loss tf tensor of shape 1 optional returned when labels is provided classification or regression if config numlabels1 loss logits tf tensor of shape batchsize config numlabels classification or regression if config numlabels1 scores before softmax hiddenstates tupletf tensor optional returned when outputhiddenstatestrue is passed or when config outputhiddenstatestrue tuple of tf tensor one for the output of the embeddings if the model has an embedding layer one for the output of each stage of shape batchsize sequencelength hiddensize hiddenstates also called feature maps of the model at the output of each stage attentions tupletf tensor optional returned when outputattentionstrue is passed or when config outputattentionstrue tuple of tf tensor one for each layer of shape batchsize numheads patchsize sequencelength attentions weights after the attention softmax used to compute the weighted average in the selfattention heads base class for outputs of multiple choice models args loss tf tensor of shape batchsize optional returned when labels is provided classification loss logits tf tensor of shape batchsize numchoices numchoices is the second dimension of the input tensors see inputids above classification scores before softmax hiddenstates tupletf tensor optional returned when outputhiddenstatestrue is passed or when config outputhiddenstatestrue tuple of tf tensor one for the output of the embeddings one for the output of each layer of shape batchsize sequencelength hiddensize hiddenstates of the model at the output of each layer plus the initial embedding outputs attentions tupletf tensor optional returned when outputattentionstrue is passed or when config outputattentionstrue tuple of tf tensor one for each layer of shape batchsize numheads sequencelength sequencelength attentions weights after the attention softmax used to compute the weighted average in the selfattention heads base class for outputs of token classification models args loss tf tensor of shape n optional where n is the number of unmasked labels returned when labels is provided classification loss logits tf tensor of shape batchsize sequencelength config numlabels classification scores before softmax hiddenstates tupletf tensor optional returned when outputhiddenstatestrue is passed or when config outputhiddenstatestrue tuple of tf tensor one for the output of the embeddings one for the output of each layer of shape batchsize sequencelength hiddensize hiddenstates of the model at the output of each layer plus the initial embedding outputs attentions tupletf tensor optional returned when outputattentionstrue is passed or when config outputattentionstrue tuple of tf tensor one for each layer of shape batchsize numheads sequencelength sequencelength attentions weights after the attention softmax used to compute the weighted average in the selfattention heads base class for outputs of question answering models args loss tf tensor of shape batchsize optional returned when startpositions and endpositions are provided total span extraction loss is the sum of a crossentropy for the start and end positions startlogits tf tensor of shape batchsize sequencelength spanstart scores before softmax endlogits tf tensor of shape batchsize sequencelength spanend scores before softmax hiddenstates tupletf tensor optional returned when outputhiddenstatestrue is passed or when config outputhiddenstatestrue tuple of tf tensor one for the output of the embeddings one for the output of each layer of shape batchsize sequencelength hiddensize hiddenstates of the model at the output of each layer plus the initial embedding outputs attentions tupletf tensor optional returned when outputattentionstrue is passed or when config outputattentionstrue tuple of tf tensor one for each layer of shape batchsize numheads sequencelength sequencelength attentions weights after the attention softmax used to compute the weighted average in the selfattention heads base class for outputs of sequencetosequence question answering models args loss tf tensor of shape 1 optional returned when labels is provided total span extraction loss is the sum of a crossentropy for the start and end positions startlogits tf tensor of shape batchsize sequencelength spanstart scores before softmax endlogits tf tensor of shape batchsize sequencelength spanend scores before softmax pastkeyvalues listtf tensor optional returned when usecachetrue is passed or when config usecachetrue list of tf tensor of length config nlayers with each tensor of shape 2 batchsize numheads sequencelength embedsizeperhead contains precomputed hiddenstates key and values in the attention blocks of the decoder that can be used see pastkeyvalues input to speed up sequential decoding decoderhiddenstates tupletf tensor optional returned when outputhiddenstatestrue is passed or when config outputhiddenstatestrue tuple of tf tensor one for the output of the embeddings one for the output of each layer of shape batchsize sequencelength hiddensize hiddenstates of the decoder at the output of each layer plus the initial embedding outputs decoderattentions tupletf tensor optional returned when outputattentionstrue is passed or when config outputattentionstrue tuple of tf tensor one for each layer of shape batchsize numheads sequencelength sequencelength attentions weights of the decoder after the attention softmax used to compute the weighted average in the selfattention heads encoderlasthiddenstate tf tensor of shape batchsize sequencelength hiddensize optional sequence of hiddenstates at the output of the last layer of the encoder of the model encoderhiddenstates tupletf tensor optional returned when outputhiddenstatestrue is passed or when config outputhiddenstatestrue tuple of tf tensor one for the output of the embeddings one for the output of each layer of shape batchsize sequencelength hiddensize hiddenstates of the encoder at the output of each layer plus the initial embedding outputs encoderattentions tupletf tensor optional returned when outputattentionstrue is passed or when config outputattentionstrue tuple of tf tensor one for each layer of shape batchsize numheads sequencelength sequencelength attentions weights of the encoder after the attention softmax used to compute the weighted average in the selfattention heads base class for outputs of sentence classification models args loss tf tensor of shape batchsize optional returned when labels is provided classification or regression if config numlabels1 loss logits tf tensor of shape batchsize config numlabels classification or regression if config numlabels1 scores before softmax pastkeyvalues listtf tensor optional returned when usecachetrue is passed or when config usecachetrue list of tf tensor of length config nlayers with each tensor of shape 2 batchsize numheads sequencelength embedsizeperhead contains precomputed hiddenstates key and values in the attention blocks that can be used see pastkeyvalues input to speed up sequential decoding hiddenstates tupletf tensor optional returned when outputhiddenstatestrue is passed or when config outputhiddenstatestrue tuple of tf tensor one for the output of the embeddings one for the output of each layer of shape batchsize sequencelength hiddensize hiddenstates of the model at the output of each layer plus the initial embedding outputs attentions tupletf tensor optional returned when outputattentionstrue is passed or when config outputattentionstrue tuple of tf tensor one for each layer of shape batchsize numheads sequencelength sequencelength attentions weights after the attention softmax used to compute the weighted average in the selfattention heads base class for outputs of image classification models args loss tf tensor of shape 1 optional returned when labels is provided classification or regression if config numlabels1 loss logits tf tensor of shape batchsize config numlabels classification or regression if config numlabels1 scores before softmax hiddenstates tupletf tensor optional returned when outputhiddenstatestrue is passed or when config outputhiddenstatestrue tuple of tf tensor one for the output of the embeddings if the model has an embedding layer one for the output of each stage of shape batchsize numchannels height width hiddenstates also called feature maps of the model at the output of each stage base class for outputs of masked image completion inpainting models args loss tf tensor of shape 1 optional returned when boolmaskedpos is provided reconstruction loss reconstruction tf tensor of shape batchsize numchannels height width reconstructed completed images hiddenstates tupletf tensor optional returned when outputhiddenstatestrue is passed or when config outputhiddenstatestrue tuple of tf tensor one for the output of the embeddings if the model has an embedding layer one for the output of each stage of shape batchsize sequencelength hiddensize hiddenstates also called feature maps of the model at the output of each stage attentions tupletf tensor optional returned when outputattentionstrue is passed or when config outputattentionstrue tuple of tf tensor one for each layer of shape batchsize numheads patchsize sequencelength attentions weights after the attention softmax used to compute the weighted average in the selfattention heads 2020 the huggingface team licensed under the apache license version 2 0 the license you may not use this file except in compliance with the license you may obtain a copy of the license at http www apache org licenses license 2 0 unless required by applicable law or agreed to in writing software distributed under the license is distributed on an as is basis without warranties or conditions of any kind either express or implied see the license for the specific language governing permissions and limitations under the license base class for model s outputs with potential hidden states and attentions args last_hidden_state tf tensor of shape batch_size sequence_length hidden_size sequence of hidden states at the output of the last layer of the model hidden_states tuple tf floattensor optional returned when output_hidden_states true is passed or when config output_hidden_states true tuple of tf tensor one for the output of the embeddings one for the output of each layer of shape batch_size sequence_length hidden_size hidden states of the model at the output of each layer plus the initial embedding outputs attentions tuple tf tensor optional returned when output_attentions true is passed or when config output_attentions true tuple of tf tensor one for each layer of shape batch_size num_heads sequence_length sequence_length attentions weights after the attention softmax used to compute the weighted average in the self attention heads base class for model s outputs with potential hidden states args last_hidden_state tf tensor shape batch_size num_channels height width sequence of hidden states at the output of the last layer of the model hidden_states tuple tf tensor optional returned when output_hidden_states true is passed or when config output_hidden_states true tuple of tf tensor one for the output of the embeddings if the model has an embedding layer one for the output of each layer of shape batch_size num_channels height width hidden states of the model at the output of each layer plus the optional initial embedding outputs base class for model s outputs that also contains a pooling of the last hidden states args last_hidden_state tf tensor of shape batch_size sequence_length hidden_size sequence of hidden states at the output of the last layer of the model pooler_output tf tensor of shape batch_size hidden_size last layer hidden state of the first token of the sequence classification token further processed by a linear layer and a tanh activation function the linear layer weights are trained from the next sentence prediction classification objective during pretraining this output is usually not a good summary of the semantic content of the input you re often better with averaging or pooling the sequence of hidden states for the whole input sequence hidden_states tuple tf tensor optional returned when output_hidden_states true is passed or when config output_hidden_states true tuple of tf tensor one for the output of the embeddings one for the output of each layer of shape batch_size sequence_length hidden_size hidden states of the model at the output of each layer plus the initial embedding outputs attentions tuple tf tensor optional returned when output_attentions true is passed or when config output_attentions true tuple of tf tensor one for each layer of shape batch_size num_heads sequence_length sequence_length attentions weights after the attention softmax used to compute the weighted average in the self attention heads base class for model s outputs that also contains a pooling of the last hidden states args last_hidden_state tf tensor of shape batch_size num_channels height width sequence of hidden states at the output of the last layer of the model pooler_output tf tensor of shape batch_size hidden_size last layer hidden state after a pooling operation on the spatial dimensions hidden_states tuple tf tensor optional returned when output_hidden_states true is passed or when config output_hidden_states true tuple of tf tensor one for the output of the embeddings if the model has an embedding layer one for the output of each layer of shape batch_size num_channels height width hidden states of the model at the output of each layer plus the optional initial embedding outputs base class for model s outputs that also contains a pooling of the last hidden states args last_hidden_state tf tensor of shape batch_size sequence_length hidden_size sequence of hidden states at the output of the last layer of the model pooler_output tf tensor of shape batch_size hidden_size last layer hidden state of the first token of the sequence classification token further processed by a linear layer and a tanh activation function the linear layer weights are trained from the next sentence prediction classification objective during pretraining this output is usually not a good summary of the semantic content of the input you re often better with averaging or pooling the sequence of hidden states for the whole input sequence past_key_values list tf tensor optional returned when use_cache true is passed or when config use_cache true list of tf tensor of length config n_layers with each tensor of shape 2 batch_size num_heads sequence_length embed_size_per_head contains pre computed hidden states key and values in the attention blocks that can be used see past_key_values input to speed up sequential decoding hidden_states tuple tf tensor optional returned when output_hidden_states true is passed or when config output_hidden_states true tuple of tf tensor one for the output of the embeddings one for the output of each layer of shape batch_size sequence_length hidden_size hidden states of the model at the output of each layer plus the initial embedding outputs attentions tuple tf tensor optional returned when output_attentions true is passed or when config output_attentions true tuple of tf tensor one for each layer of shape batch_size num_heads sequence_length sequence_length attentions weights after the attention softmax used to compute the weighted average in the self attention heads cross_attentions tuple tf tensor optional returned when output_attentions true is passed or when config output_attentions true tuple of tf tensor one for each layer of shape batch_size num_heads sequence_length sequence_length attentions weights of the decoder s cross attention layer after the attention softmax used to compute the weighted average in the cross attention heads base class for model s outputs that may also contain a past key values to speed up sequential decoding args last_hidden_state tf tensor of shape batch_size sequence_length hidden_size sequence of hidden states at the output of the last layer of the model if past_key_values is used only the last hidden state of the sequences of shape batch_size 1 hidden_size is output past_key_values list tf tensor optional returned when use_cache true is passed or when config use_cache true list of tf tensor of length config n_layers with each tensor of shape 2 batch_size num_heads sequence_length embed_size_per_head contains pre computed hidden states key and values in the attention blocks that can be used see past_key_values input to speed up sequential decoding hidden_states tuple tf tensor optional returned when output_hidden_states true is passed or when config output_hidden_states true tuple of tf tensor one for the output of the embeddings one for the output of each layer of shape batch_size sequence_length hidden_size hidden states of the model at the output of each layer plus the initial embedding outputs attentions tuple tf tensor optional returned when output_attentions true is passed or when config output_attentions true tuple of tf tensor one for each layer of shape batch_size num_heads sequence_length sequence_length attentions weights after the attention softmax used to compute the weighted average in the self attention heads base class for model s outputs with potential hidden states and attentions args last_hidden_state tf tensor of shape batch_size sequence_length hidden_size sequence of hidden states at the output of the last layer of the model hidden_states tuple tf floattensor optional returned when output_hidden_states true is passed or when config output_hidden_states true tuple of tf tensor one for the output of the embeddings one for the output of each layer of shape batch_size sequence_length hidden_size hidden states of the model at the output of each layer plus the initial embedding outputs attentions tuple tf tensor optional returned when output_attentions true is passed or when config output_attentions true tuple of tf tensor one for each layer of shape batch_size num_heads sequence_length sequence_length attentions weights after the attention softmax used to compute the weighted average in the self attention heads cross_attentions tuple tf tensor optional returned when output_attentions true is passed or when config output_attentions true tuple of tf tensor one for each layer of shape batch_size num_heads sequence_length sequence_length attentions weights of the decoder s cross attention layer after the attention softmax used to compute the weighted average in the cross attention heads base class for model s outputs that may also contain a past key values to speed up sequential decoding args last_hidden_state tf tensor of shape batch_size sequence_length hidden_size sequence of hidden states at the output of the last layer of the model if past_key_values is used only the last hidden state of the sequences of shape batch_size 1 hidden_size is output past_key_values list tf tensor optional returned when use_cache true is passed or when config use_cache true list of tf tensor of length config n_layers with each tensor of shape 2 batch_size num_heads sequence_length embed_size_per_head contains pre computed hidden states key and values in the attention blocks that can be used see past_key_values input to speed up sequential decoding hidden_states tuple tf floattensor optional returned when output_hidden_states true is passed or when config output_hidden_states true tuple of tf tensor one for the output of the embeddings one for the output of each layer of shape batch_size sequence_length hidden_size hidden states of the model at the output of each layer plus the initial embedding outputs attentions tuple tf tensor optional returned when output_attentions true is passed or when config output_attentions true tuple of tf tensor one for each layer of shape batch_size num_heads sequence_length sequence_length attentions weights after the attention softmax used to compute the weighted average in the self attention heads cross_attentions tuple tf tensor optional returned when output_attentions true is passed or when config output_attentions true tuple of tf tensor one for each layer of shape batch_size num_heads sequence_length sequence_length attentions weights of the decoder s cross attention layer after the attention softmax used to compute the weighted average in the cross attention heads base class for model encoder s outputs that also contains pre computed hidden states that can speed up sequential decoding args last_hidden_state tf tensor of shape batch_size sequence_length hidden_size sequence of hidden states at the output of the last layer of the decoder of the model if past_key_values is used only the last hidden state of the sequences of shape batch_size 1 hidden_size is output past_key_values list tf tensor optional returned when use_cache true is passed or when config use_cache true list of tf tensor of length config n_layers with each tensor of shape 2 batch_size num_heads sequence_length embed_size_per_head contains pre computed hidden states key and values in the attention blocks of the decoder that can be used see past_key_values input to speed up sequential decoding decoder_hidden_states tuple tf tensor optional returned when output_hidden_states true is passed or when config output_hidden_states true tuple of tf tensor one for the output of the embeddings one for the output of each layer of shape batch_size sequence_length hidden_size hidden states of the decoder at the output of each layer plus the initial embedding outputs decoder_attentions tuple tf tensor optional returned when output_attentions true is passed or when config output_attentions true tuple of tf tensor one for each layer of shape batch_size num_heads sequence_length sequence_length attentions weights of the decoder after the attention softmax used to compute the weighted average in the self attention heads cross_attentions tuple tf tensor optional returned when output_attentions true is passed or when config output_attentions true tuple of tf tensor one for each layer of shape batch_size num_heads sequence_length sequence_length attentions weights of the decoder s cross attention layer after the attention softmax used to compute the weighted average in the cross attention heads encoder_last_hidden_state tf tensor of shape batch_size sequence_length hidden_size optional sequence of hidden states at the output of the last layer of the encoder of the model encoder_hidden_states tuple tf tensor optional returned when output_hidden_states true is passed or when config output_hidden_states true tuple of tf tensor one for the output of the embeddings one for the output of each layer of shape batch_size sequence_length hidden_size hidden states of the encoder at the output of each layer plus the initial embedding outputs encoder_attentions tuple tf tensor optional returned when output_attentions true is passed or when config output_attentions true tuple of tf tensor one for each layer of shape batch_size num_heads sequence_length sequence_length attentions weights of the encoder after the attention softmax used to compute the weighted average in the self attention heads base class for causal language model or autoregressive outputs args loss tf tensor of shape n optional where n is the number of non masked labels returned when labels is provided language modeling loss for next token prediction logits tf tensor of shape batch_size sequence_length config vocab_size prediction scores of the language modeling head scores for each vocabulary token before softmax hidden_states tuple tf tensor optional returned when output_hidden_states true is passed or when config output_hidden_states true tuple of tf tensor one for the output of the embeddings one for the output of each layer of shape batch_size sequence_length hidden_size hidden states of the model at the output of each layer plus the initial embedding outputs attentions tuple tf tensor optional returned when output_attentions true is passed or when config output_attentions true tuple of tf tensor one for each layer of shape batch_size num_heads sequence_length sequence_length attentions weights after the attention softmax used to compute the weighted average in the self attention heads base class for causal language model or autoregressive outputs args loss tf tensor of shape n optional where n is the number of non masked labels returned when labels is provided language modeling loss for next token prediction logits tf tensor of shape batch_size sequence_length config vocab_size prediction scores of the language modeling head scores for each vocabulary token before softmax past_key_values list tf tensor optional returned when use_cache true is passed or when config use_cache true list of tf tensor of length config n_layers with each tensor of shape 2 batch_size num_heads sequence_length embed_size_per_head contains pre computed hidden states key and values in the attention blocks that can be used see past_key_values input to speed up sequential decoding hidden_states tuple tf tensor optional returned when output_hidden_states true is passed or when config output_hidden_states true tuple of tf tensor one for the output of the embeddings one for the output of each layer of shape batch_size sequence_length hidden_size hidden states of the model at the output of each layer plus the initial embedding outputs attentions tuple tf tensor optional returned when output_attentions true is passed or when config output_attentions true tuple of tf tensor one for each layer of shape batch_size num_heads sequence_length sequence_length attentions weights after the attention softmax used to compute the weighted average in the self attention heads base class for causal language model or autoregressive outputs args loss tf tensor of shape n optional where n is the number of non masked labels returned when labels is provided language modeling loss for next token prediction logits tf tensor of shape batch_size sequence_length config vocab_size prediction scores of the language modeling head scores for each vocabulary token before softmax hidden_states tuple tf tensor optional returned when output_hidden_states true is passed or when config output_hidden_states true tuple of tf tensor one for the output of the embeddings one for the output of each layer of shape batch_size sequence_length hidden_size hidden states of the model at the output of each layer plus the initial embedding outputs attentions tuple tf tensor optional returned when output_attentions true is passed or when config output_attentions true tuple of tf tensor one for each layer of shape batch_size num_heads sequence_length sequence_length attentions weights after the attention softmax used to compute the weighted average in the self attention heads cross_attentions tuple tf tensor optional returned when output_attentions true is passed or when config output_attentions true tuple of tf tensor one for each layer of shape batch_size num_heads sequence_length sequence_length attentions weights of the decoder s cross attention layer after the attention softmax used to compute the weighted average in the cross attention heads past_key_values list tf tensor optional returned when use_cache true is passed or when config use_cache true list of tf tensor of length config n_layers with each tensor of shape 2 batch_size num_heads sequence_length embed_size_per_head contains pre computed hidden states key and values in the attention blocks that can be used see past_key_values input to speed up sequential decoding base class for masked language models outputs args loss tf tensor of shape n optional where n is the number of non masked labels returned when labels is provided masked language modeling mlm loss logits tf tensor of shape batch_size sequence_length config vocab_size prediction scores of the language modeling head scores for each vocabulary token before softmax hidden_states tuple tf tensor optional returned when output_hidden_states true is passed or when config output_hidden_states true tuple of tf tensor one for the output of the embeddings one for the output of each layer of shape batch_size sequence_length hidden_size hidden states of the model at the output of each layer plus the initial embedding outputs attentions tuple tf tensor optional returned when output_attentions true is passed or when config output_attentions true tuple of tf tensor one for each layer of shape batch_size num_heads sequence_length sequence_length attentions weights after the attention softmax used to compute the weighted average in the self attention heads base class for sequence to sequence language models outputs args loss tf tensor of shape n optional where n is the number of non masked labels returned when labels is provided language modeling loss logits tf tensor of shape batch_size sequence_length config vocab_size prediction scores of the language modeling head scores for each vocabulary token before softmax past_key_values list tf tensor optional returned when use_cache true is passed or when config use_cache true list of tf tensor of length config n_layers with each tensor of shape 2 batch_size num_heads sequence_length embed_size_per_head contains pre computed hidden states key and values in the attention blocks of the decoder that can be used see past_key_values input to speed up sequential decoding decoder_hidden_states tuple tf tensor optional returned when output_hidden_states true is passed or when config output_hidden_states true tuple of tf tensor one for the output of the embeddings one for the output of each layer of shape batch_size sequence_length hidden_size hidden states of the decoder at the output of each layer plus the initial embedding outputs decoder_attentions tuple tf tensor optional returned when output_attentions true is passed or when config output_attentions true tuple of tf tensor one for each layer of shape batch_size num_heads sequence_length sequence_length attentions weights of the decoder after the attention softmax used to compute the weighted average in the self attention heads cross_attentions tuple tf tensor optional returned when output_attentions true is passed or when config output_attentions true tuple of tf tensor one for each layer of shape batch_size num_heads sequence_length sequence_length attentions weights of the decoder s cross attention layer after the attention softmax used to compute the weighted average in the cross attention heads encoder_last_hidden_state tf tensor of shape batch_size sequence_length hidden_size optional sequence of hidden states at the output of the last layer of the encoder of the model encoder_hidden_states tuple tf tensor optional returned when output_hidden_states true is passed or when config output_hidden_states true tuple of tf tensor one for the output of the embeddings one for the output of each layer of shape batch_size sequence_length hidden_size hidden states of the encoder at the output of each layer plus the initial embedding outputs encoder_attentions tuple tf tensor optional returned when output_attentions true is passed or when config output_attentions true tuple of tf tensor one for each layer of shape batch_size num_heads sequence_length sequence_length attentions weights of the encoder after the attention softmax used to compute the weighted average in the self attention heads base class for outputs of models predicting if two sentences are consecutive or not args loss tf tensor of shape n optional where n is the number of non masked labels returned when next_sentence_label is provided next sentence prediction loss logits tf tensor of shape batch_size 2 prediction scores of the next sequence prediction classification head scores of true false continuation before softmax hidden_states tuple tf tensor optional returned when output_hidden_states true is passed or when config output_hidden_states true tuple of tf tensor one for the output of the embeddings one for the output of each layer of shape batch_size sequence_length hidden_size hidden states of the model at the output of each layer plus the initial embedding outputs attentions tuple tf tensor optional returned when output_attentions true is passed or when config output_attentions true tuple of tf tensor one for each layer of shape batch_size num_heads sequence_length sequence_length attentions weights after the attention softmax used to compute the weighted average in the self attention heads base class for outputs of sentence classification models args loss tf tensor of shape batch_size optional returned when labels is provided classification or regression if config num_labels 1 loss logits tf tensor of shape batch_size config num_labels classification or regression if config num_labels 1 scores before softmax hidden_states tuple tf tensor optional returned when output_hidden_states true is passed or when config output_hidden_states true tuple of tf tensor one for the output of the embeddings one for the output of each layer of shape batch_size sequence_length hidden_size hidden states of the model at the output of each layer plus the initial embedding outputs attentions tuple tf tensor optional returned when output_attentions true is passed or when config output_attentions true tuple of tf tensor one for each layer of shape batch_size num_heads sequence_length sequence_length attentions weights after the attention softmax used to compute the weighted average in the self attention heads base class for outputs of sequence to sequence sentence classification models args loss tf tensor of shape 1 optional returned when label is provided classification or regression if config num_labels 1 loss logits tf tensor of shape batch_size config num_labels classification or regression if config num_labels 1 scores before softmax past_key_values list tf tensor optional returned when use_cache true is passed or when config use_cache true list of tf tensor of length config n_layers with each tensor of shape 2 batch_size num_heads sequence_length embed_size_per_head contains pre computed hidden states key and values in the attention blocks of the decoder that can be used see past_key_values input to speed up sequential decoding decoder_hidden_states tuple tf tensor optional returned when output_hidden_states true is passed or when config output_hidden_states true tuple of tf tensor one for the output of the embeddings one for the output of each layer of shape batch_size sequence_length hidden_size hidden states of the decoder at the output of each layer plus the initial embedding outputs decoder_attentions tuple tf tensor optional returned when output_attentions true is passed or when config output_attentions true tuple of tf tensor one for each layer of shape batch_size num_heads sequence_length sequence_length attentions weights of the decoder after the attention softmax used to compute the weighted average in the self attention heads cross_attentions tuple tf tensor optional returned when output_attentions true is passed or when config output_attentions true tuple of tf tensor one for each layer of shape batch_size num_heads sequence_length sequence_length encoder_last_hidden_state tf tensor of shape batch_size sequence_length hidden_size optional sequence of hidden states at the output of the last layer of the encoder of the model encoder_hidden_states tuple tf tensor optional returned when output_hidden_states true is passed or when config output_hidden_states true tuple of tf tensor one for the output of the embeddings one for the output of each layer of shape batch_size sequence_length hidden_size hidden states of the encoder at the output of each layer plus the initial embedding outputs encoder_attentions tuple tf tensor optional returned when output_attentions true is passed or when config output_attentions true tuple of tf tensor one for each layer of shape batch_size num_heads sequence_length sequence_length attentions weights of the encoder after the attention softmax used to compute the weighted average in the self attention heads base class for outputs of semantic segmentation models args loss tf tensor of shape 1 optional returned when labels is provided classification or regression if config num_labels 1 loss logits tf tensor of shape batch_size config num_labels logits_height logits_width classification scores for each pixel tip warning true the logits returned do not necessarily have the same size as the pixel_values passed as inputs this is to avoid doing two interpolations and lose some quality when a user needs to resize the logits to the original image size as post processing you should always check your logits shape and resize as needed tip hidden_states tuple tf tensor optional returned when output_hidden_states true is passed or when config output_hidden_states true tuple of tf tensor one for the output of the embeddings if the model has an embedding layer one for the output of each layer of shape batch_size patch_size hidden_size hidden states of the model at the output of each layer plus the optional initial embedding outputs attentions tuple tf tensor optional returned when output_attentions true is passed or when config output_attentions true tuple of tf tensor one for each layer of shape batch_size num_heads patch_size sequence_length attentions weights after the attention softmax used to compute the weighted average in the self attention heads base class for outputs of semantic segmentation models that do not output attention scores args loss tf tensor of shape 1 optional returned when labels is provided classification or regression if config num_labels 1 loss logits tf tensor of shape batch_size config num_labels logits_height logits_width classification scores for each pixel tip warning true the logits returned do not necessarily have the same size as the pixel_values passed as inputs this is to avoid doing two interpolations and lose some quality when a user needs to resize the logits to the original image size as post processing you should always check your logits shape and resize as needed tip hidden_states tuple tf tensor optional returned when output_hidden_states true is passed or when config output_hidden_states true tuple of tf tensor one for the output of the embeddings if the model has an embedding layer one for the output of each layer of shape batch_size patch_size hidden_size hidden states of the model at the output of each layer plus the optional initial embedding outputs base class for outputs of image classification models args loss tf tensor of shape 1 optional returned when labels is provided classification or regression if config num_labels 1 loss logits tf tensor of shape batch_size config num_labels classification or regression if config num_labels 1 scores before softmax hidden_states tuple tf tensor optional returned when output_hidden_states true is passed or when config output_hidden_states true tuple of tf tensor one for the output of the embeddings if the model has an embedding layer one for the output of each stage of shape batch_size sequence_length hidden_size hidden states also called feature maps of the model at the output of each stage attentions tuple tf tensor optional returned when output_attentions true is passed or when config output_attentions true tuple of tf tensor one for each layer of shape batch_size num_heads patch_size sequence_length attentions weights after the attention softmax used to compute the weighted average in the self attention heads base class for outputs of multiple choice models args loss tf tensor of shape batch_size optional returned when labels is provided classification loss logits tf tensor of shape batch_size num_choices num_choices is the second dimension of the input tensors see input_ids above classification scores before softmax hidden_states tuple tf tensor optional returned when output_hidden_states true is passed or when config output_hidden_states true tuple of tf tensor one for the output of the embeddings one for the output of each layer of shape batch_size sequence_length hidden_size hidden states of the model at the output of each layer plus the initial embedding outputs attentions tuple tf tensor optional returned when output_attentions true is passed or when config output_attentions true tuple of tf tensor one for each layer of shape batch_size num_heads sequence_length sequence_length attentions weights after the attention softmax used to compute the weighted average in the self attention heads base class for outputs of token classification models args loss tf tensor of shape n optional where n is the number of unmasked labels returned when labels is provided classification loss logits tf tensor of shape batch_size sequence_length config num_labels classification scores before softmax hidden_states tuple tf tensor optional returned when output_hidden_states true is passed or when config output_hidden_states true tuple of tf tensor one for the output of the embeddings one for the output of each layer of shape batch_size sequence_length hidden_size hidden states of the model at the output of each layer plus the initial embedding outputs attentions tuple tf tensor optional returned when output_attentions true is passed or when config output_attentions true tuple of tf tensor one for each layer of shape batch_size num_heads sequence_length sequence_length attentions weights after the attention softmax used to compute the weighted average in the self attention heads base class for outputs of question answering models args loss tf tensor of shape batch_size optional returned when start_positions and end_positions are provided total span extraction loss is the sum of a cross entropy for the start and end positions start_logits tf tensor of shape batch_size sequence_length span start scores before softmax end_logits tf tensor of shape batch_size sequence_length span end scores before softmax hidden_states tuple tf tensor optional returned when output_hidden_states true is passed or when config output_hidden_states true tuple of tf tensor one for the output of the embeddings one for the output of each layer of shape batch_size sequence_length hidden_size hidden states of the model at the output of each layer plus the initial embedding outputs attentions tuple tf tensor optional returned when output_attentions true is passed or when config output_attentions true tuple of tf tensor one for each layer of shape batch_size num_heads sequence_length sequence_length attentions weights after the attention softmax used to compute the weighted average in the self attention heads base class for outputs of sequence to sequence question answering models args loss tf tensor of shape 1 optional returned when labels is provided total span extraction loss is the sum of a cross entropy for the start and end positions start_logits tf tensor of shape batch_size sequence_length span start scores before softmax end_logits tf tensor of shape batch_size sequence_length span end scores before softmax past_key_values list tf tensor optional returned when use_cache true is passed or when config use_cache true list of tf tensor of length config n_layers with each tensor of shape 2 batch_size num_heads sequence_length embed_size_per_head contains pre computed hidden states key and values in the attention blocks of the decoder that can be used see past_key_values input to speed up sequential decoding decoder_hidden_states tuple tf tensor optional returned when output_hidden_states true is passed or when config output_hidden_states true tuple of tf tensor one for the output of the embeddings one for the output of each layer of shape batch_size sequence_length hidden_size hidden states of the decoder at the output of each layer plus the initial embedding outputs decoder_attentions tuple tf tensor optional returned when output_attentions true is passed or when config output_attentions true tuple of tf tensor one for each layer of shape batch_size num_heads sequence_length sequence_length attentions weights of the decoder after the attention softmax used to compute the weighted average in the self attention heads encoder_last_hidden_state tf tensor of shape batch_size sequence_length hidden_size optional sequence of hidden states at the output of the last layer of the encoder of the model encoder_hidden_states tuple tf tensor optional returned when output_hidden_states true is passed or when config output_hidden_states true tuple of tf tensor one for the output of the embeddings one for the output of each layer of shape batch_size sequence_length hidden_size hidden states of the encoder at the output of each layer plus the initial embedding outputs encoder_attentions tuple tf tensor optional returned when output_attentions true is passed or when config output_attentions true tuple of tf tensor one for each layer of shape batch_size num_heads sequence_length sequence_length attentions weights of the encoder after the attention softmax used to compute the weighted average in the self attention heads base class for outputs of sentence classification models args loss tf tensor of shape batch_size optional returned when labels is provided classification or regression if config num_labels 1 loss logits tf tensor of shape batch_size config num_labels classification or regression if config num_labels 1 scores before softmax past_key_values list tf tensor optional returned when use_cache true is passed or when config use_cache true list of tf tensor of length config n_layers with each tensor of shape 2 batch_size num_heads sequence_length embed_size_per_head contains pre computed hidden states key and values in the attention blocks that can be used see past_key_values input to speed up sequential decoding hidden_states tuple tf tensor optional returned when output_hidden_states true is passed or when config output_hidden_states true tuple of tf tensor one for the output of the embeddings one for the output of each layer of shape batch_size sequence_length hidden_size hidden states of the model at the output of each layer plus the initial embedding outputs attentions tuple tf tensor optional returned when output_attentions true is passed or when config output_attentions true tuple of tf tensor one for each layer of shape batch_size num_heads sequence_length sequence_length attentions weights after the attention softmax used to compute the weighted average in the self attention heads base class for outputs of image classification models args loss tf tensor of shape 1 optional returned when labels is provided classification or regression if config num_labels 1 loss logits tf tensor of shape batch_size config num_labels classification or regression if config num_labels 1 scores before softmax hidden_states tuple tf tensor optional returned when output_hidden_states true is passed or when config output_hidden_states true tuple of tf tensor one for the output of the embeddings if the model has an embedding layer one for the output of each stage of shape batch_size num_channels height width hidden states also called feature maps of the model at the output of each stage base class for outputs of masked image completion in painting models args loss tf tensor of shape 1 optional returned when bool_masked_pos is provided reconstruction loss reconstruction tf tensor of shape batch_size num_channels height width reconstructed completed images hidden_states tuple tf tensor optional returned when output_hidden_states true is passed or when config output_hidden_states true tuple of tf tensor one for the output of the embeddings if the model has an embedding layer one for the output of each stage of shape batch_size sequence_length hidden_size hidden states also called feature maps of the model at the output of each stage attentions tuple tf tensor optional returned when output_attentions true is passed or when config output_attentions true tuple of tf tensor one for each layer of shape batch_size num_heads patch_size sequence_length attentions weights after the attention softmax used to compute the weighted average in the self attention heads
from __future__ import annotations

import warnings
from dataclasses import dataclass
from typing import List, Optional, Tuple

import tensorflow as tf

from .utils import ModelOutput


@dataclass
class TFBaseModelOutput(ModelOutput):
    

    last_hidden_state: tf.Tensor = None
    hidden_states: Tuple[tf.Tensor] | None = None
    attentions: Tuple[tf.Tensor] | None = None


@dataclass
class TFBaseModelOutputWithNoAttention(ModelOutput):
    

    last_hidden_state: tf.Tensor = None
    hidden_states: Optional[Tuple[tf.Tensor, ...]] = None


@dataclass
class TFBaseModelOutputWithPooling(ModelOutput):
    

    last_hidden_state: tf.Tensor = None
    pooler_output: tf.Tensor = None
    hidden_states: Tuple[tf.Tensor] | None = None
    attentions: Tuple[tf.Tensor] | None = None


@dataclass
class TFBaseModelOutputWithPoolingAndNoAttention(ModelOutput):
    

    last_hidden_state: tf.Tensor = None
    pooler_output: tf.Tensor = None
    hidden_states: Optional[Tuple[tf.Tensor, ...]] = None


@dataclass
class TFBaseModelOutputWithPoolingAndCrossAttentions(ModelOutput):
    

    last_hidden_state: tf.Tensor = None
    pooler_output: tf.Tensor = None
    past_key_values: List[tf.Tensor] | None = None
    hidden_states: Tuple[tf.Tensor] | None = None
    attentions: Tuple[tf.Tensor] | None = None
    cross_attentions: Tuple[tf.Tensor] | None = None


@dataclass
class TFBaseModelOutputWithPast(ModelOutput):
    

    last_hidden_state: tf.Tensor = None
    past_key_values: List[tf.Tensor] | None = None
    hidden_states: Tuple[tf.Tensor] | None = None
    attentions: Tuple[tf.Tensor] | None = None


@dataclass
class TFBaseModelOutputWithCrossAttentions(ModelOutput):
    

    last_hidden_state: tf.Tensor = None
    hidden_states: Tuple[tf.Tensor] | None = None
    attentions: Tuple[tf.Tensor] | None = None
    cross_attentions: Tuple[tf.Tensor] | None = None


@dataclass
class TFBaseModelOutputWithPastAndCrossAttentions(ModelOutput):
    

    last_hidden_state: tf.Tensor = None
    past_key_values: List[tf.Tensor] | None = None
    hidden_states: Tuple[tf.Tensor] | None = None
    attentions: Tuple[tf.Tensor] | None = None
    cross_attentions: Tuple[tf.Tensor] | None = None


@dataclass
class TFSeq2SeqModelOutput(ModelOutput):
    

    last_hidden_state: tf.Tensor = None
    past_key_values: List[tf.Tensor] | None = None
    decoder_hidden_states: Tuple[tf.Tensor] | None = None
    decoder_attentions: Tuple[tf.Tensor] | None = None
    cross_attentions: Tuple[tf.Tensor] | None = None
    encoder_last_hidden_state: tf.Tensor | None = None
    encoder_hidden_states: Tuple[tf.Tensor] | None = None
    encoder_attentions: Tuple[tf.Tensor] | None = None


@dataclass
class TFCausalLMOutput(ModelOutput):
    

    loss: tf.Tensor | None = None
    logits: tf.Tensor = None
    hidden_states: Tuple[tf.Tensor] | None = None
    attentions: Tuple[tf.Tensor] | None = None


@dataclass
class TFCausalLMOutputWithPast(ModelOutput):
    

    loss: tf.Tensor | None = None
    logits: tf.Tensor = None
    past_key_values: List[tf.Tensor] | None = None
    hidden_states: Tuple[tf.Tensor] | None = None
    attentions: Tuple[tf.Tensor] | None = None


@dataclass
class TFCausalLMOutputWithCrossAttentions(ModelOutput):
    

    loss: tf.Tensor | None = None
    logits: tf.Tensor = None
    past_key_values: List[tf.Tensor] | None = None
    hidden_states: Tuple[tf.Tensor] | None = None
    attentions: Tuple[tf.Tensor] | None = None
    cross_attentions: Tuple[tf.Tensor] | None = None


@dataclass
class TFMaskedLMOutput(ModelOutput):
    

    loss: tf.Tensor | None = None
    logits: tf.Tensor = None
    hidden_states: Tuple[tf.Tensor] | None = None
    attentions: Tuple[tf.Tensor] | None = None


@dataclass
class TFSeq2SeqLMOutput(ModelOutput):
    

    loss: tf.Tensor | None = None
    logits: tf.Tensor = None
    past_key_values: List[tf.Tensor] | None = None
    decoder_hidden_states: Tuple[tf.Tensor] | None = None
    decoder_attentions: Tuple[tf.Tensor] | None = None
    cross_attentions: Tuple[tf.Tensor] | None = None
    encoder_last_hidden_state: tf.Tensor | None = None
    encoder_hidden_states: Tuple[tf.Tensor] | None = None
    encoder_attentions: Tuple[tf.Tensor] | None = None


@dataclass
class TFNextSentencePredictorOutput(ModelOutput):
    

    loss: tf.Tensor | None = None
    logits: tf.Tensor = None
    hidden_states: Tuple[tf.Tensor] | None = None
    attentions: Tuple[tf.Tensor] | None = None


@dataclass
class TFSequenceClassifierOutput(ModelOutput):
    

    loss: tf.Tensor | None = None
    logits: tf.Tensor = None
    hidden_states: Tuple[tf.Tensor] | None = None
    attentions: Tuple[tf.Tensor] | None = None


@dataclass
class TFSeq2SeqSequenceClassifierOutput(ModelOutput):
    

    loss: tf.Tensor | None = None
    logits: tf.Tensor = None
    past_key_values: List[tf.Tensor] | None = None
    decoder_hidden_states: Tuple[tf.Tensor] | None = None
    decoder_attentions: Tuple[tf.Tensor] | None = None
    cross_attentions: Tuple[tf.Tensor] | None = None
    encoder_last_hidden_state: tf.Tensor | None = None
    encoder_hidden_states: Tuple[tf.Tensor] | None = None
    encoder_attentions: Tuple[tf.Tensor] | None = None


@dataclass
class TFSemanticSegmenterOutput(ModelOutput):
    

    loss: tf.Tensor | None = None
    logits: tf.Tensor = None
    hidden_states: Tuple[tf.Tensor] | None = None
    attentions: Tuple[tf.Tensor] | None = None


@dataclass
class TFSemanticSegmenterOutputWithNoAttention(ModelOutput):
    

    loss: tf.Tensor | None = None
    logits: tf.Tensor = None
    hidden_states: Tuple[tf.Tensor] | None = None


@dataclass
class TFImageClassifierOutput(ModelOutput):
    

    loss: tf.Tensor | None = None
    logits: tf.Tensor = None
    hidden_states: Tuple[tf.Tensor] | None = None
    attentions: Tuple[tf.Tensor] | None = None


@dataclass
class TFMultipleChoiceModelOutput(ModelOutput):
    

    loss: tf.Tensor | None = None
    logits: tf.Tensor = None
    hidden_states: Tuple[tf.Tensor] | None = None
    attentions: Tuple[tf.Tensor] | None = None


@dataclass
class TFTokenClassifierOutput(ModelOutput):
    

    loss: tf.Tensor | None = None
    logits: tf.Tensor = None
    hidden_states: Tuple[tf.Tensor] | None = None
    attentions: Tuple[tf.Tensor] | None = None


@dataclass
class TFQuestionAnsweringModelOutput(ModelOutput):
    

    loss: tf.Tensor | None = None
    start_logits: tf.Tensor = None
    end_logits: tf.Tensor = None
    hidden_states: Tuple[tf.Tensor] | None = None
    attentions: Tuple[tf.Tensor] | None = None


@dataclass
class TFSeq2SeqQuestionAnsweringModelOutput(ModelOutput):
    

    loss: tf.Tensor | None = None
    start_logits: tf.Tensor = None
    end_logits: tf.Tensor = None
    past_key_values: List[tf.Tensor] | None = None
    decoder_hidden_states: Tuple[tf.Tensor] | None = None
    decoder_attentions: Tuple[tf.Tensor] | None = None
    encoder_last_hidden_state: tf.Tensor | None = None
    encoder_hidden_states: Tuple[tf.Tensor] | None = None
    encoder_attentions: Tuple[tf.Tensor] | None = None


@dataclass
class TFSequenceClassifierOutputWithPast(ModelOutput):
    

    loss: tf.Tensor | None = None
    logits: tf.Tensor = None
    past_key_values: List[tf.Tensor] | None = None
    hidden_states: Tuple[tf.Tensor] | None = None
    attentions: Tuple[tf.Tensor] | None = None


@dataclass
class TFImageClassifierOutputWithNoAttention(ModelOutput):
    

    loss: tf.Tensor | None = None
    logits: tf.Tensor = None
    hidden_states: Optional[Tuple[tf.Tensor, ...]] = None


@dataclass
class TFMaskedImageModelingOutput(ModelOutput):
    

    loss: tf.Tensor | None = None
    reconstruction: tf.Tensor = None
    hidden_states: Tuple[tf.Tensor] | None = None
    attentions: Tuple[tf.Tensor] | None = None

    @property
    def logits(self):
        warnings.warn(
            "logits attribute is deprecated and will be removed in version 5 of Transformers."
            " Please use the reconstruction attribute to retrieve the final output instead.",
            FutureWarning,
        )
        return self.reconstruction