text stringlengths 31 243k | type stringclasses 1
value | start int64 36 275k | end int64 286 280k | depth int64 0 1 | filepath stringlengths 85 188 | parent_class stringclasses 3
values | class_index int64 0 10.8k |
|---|---|---|---|---|---|---|---|
class Kosmos2TextModel(Kosmos2PreTrainedModel):
config_class = Kosmos2TextConfig
def __init__(self, config: Kosmos2TextConfig):
super().__init__(config)
self.model = Kosmos2TextTransformer(config)
# Initialize weights and apply final processing
self.post_init()
def get_inpu... | class_definition | 72,745 | 75,099 | 0 | /Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/models/kosmos2/modeling_kosmos2.py | null | 6,100 |
class Kosmos2TextForCausalLM(Kosmos2PreTrainedModel, GenerationMixin):
config_class = Kosmos2TextConfig
_tied_weights_keys = ["lm_head.weight"]
def __init__(self, config: Kosmos2TextConfig):
super().__init__(config)
self.model = Kosmos2TextTransformer(config)
self.lm_head = nn.Line... | class_definition | 75,305 | 82,396 | 0 | /Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/models/kosmos2/modeling_kosmos2.py | null | 6,101 |
class Kosmos2ImageToTextProjection(nn.Module):
"""The layer that transforms the image model's output to part of the text model's input (namely, image features)"""
def __init__(self, config: Kosmos2Config):
super().__init__()
self.dense = nn.Linear(config.vision_config.hidden_size, config.text_c... | class_definition | 82,399 | 83,753 | 0 | /Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/models/kosmos2/modeling_kosmos2.py | null | 6,102 |
class Kosmos2Model(Kosmos2PreTrainedModel):
config_class = Kosmos2Config
main_input_name = "pixel_values"
def __init__(self, config: Kosmos2Config):
super().__init__(config)
self.text_model = Kosmos2TextModel(config.text_config)
self.vision_model = Kosmos2VisionModel(config.vision_... | class_definition | 83,947 | 89,393 | 0 | /Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/models/kosmos2/modeling_kosmos2.py | null | 6,103 |
class Kosmos2ForConditionalGeneration(Kosmos2PreTrainedModel, GenerationMixin):
config_class = Kosmos2Config
main_input_name = "pixel_values"
_tied_weights_keys = ["text_model.lm_head.weight"]
def __init__(self, config: Kosmos2Config):
super().__init__(config)
self.text_model = Kosmos2... | class_definition | 89,606 | 98,036 | 0 | /Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/models/kosmos2/modeling_kosmos2.py | null | 6,104 |
class Kosmos2TextConfig(PretrainedConfig):
r"""
This is the configuration class to store the configuration of a [`Kosmos2TextModel`]. It is used to instantiate a
KOSMOS-2 text decoder according to the specified arguments, defining the model architecture. Instantiating a
configuration with the defaults w... | class_definition | 808 | 5,981 | 0 | /Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/models/kosmos2/configuration_kosmos2.py | null | 6,105 |
class Kosmos2VisionConfig(PretrainedConfig):
r"""
This is the configuration class to store the configuration of a [`Kosmos2VisionModel`]. It is used to instantiate a
KOSMOS-2 vision encoder according to the specified arguments, defining the model architecture. Instantiating a
configuration with the defa... | class_definition | 5,984 | 9,575 | 0 | /Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/models/kosmos2/configuration_kosmos2.py | null | 6,106 |
class Kosmos2Config(PretrainedConfig):
r"""
This is the configuration class to store the configuration of a [`Kosmos2Model`]. It is used to instantiate a
KOSMOS-2 model according to the specified arguments, defining the model architecture. Instantiating a configuration
with the defaults will yield a sim... | class_definition | 9,578 | 11,849 | 0 | /Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/models/kosmos2/configuration_kosmos2.py | null | 6,107 |
class TFBlipTextEmbeddings(keras.layers.Layer):
"""Construct the embeddings from word and position embeddings."""
def __init__(self, config, **kwargs):
super().__init__(**kwargs)
self.word_embeddings = keras.layers.Embedding(
config.vocab_size,
config.hidden_size,
... | class_definition | 3,100 | 6,120 | 0 | /Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/models/blip/modeling_tf_blip_text.py | null | 6,108 |
class TFBlipTextSelfAttention(keras.layers.Layer):
def __init__(self, config, is_cross_attention, **kwargs):
super().__init__(**kwargs)
self.config = config
if config.hidden_size % config.num_attention_heads != 0 and not hasattr(config, "embedding_size"):
raise ValueError(
... | class_definition | 6,201 | 13,642 | 0 | /Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/models/blip/modeling_tf_blip_text.py | null | 6,109 |
class TFBlipTextSelfOutput(keras.layers.Layer):
def __init__(self, config: BlipTextConfig, **kwargs):
super().__init__(**kwargs)
self.dense = keras.layers.Dense(
units=config.hidden_size, kernel_initializer=get_initializer(config.initializer_range), name="dense"
)
self.L... | class_definition | 13,645 | 14,989 | 0 | /Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/models/blip/modeling_tf_blip_text.py | null | 6,110 |
class TFBlipTextAttention(keras.layers.Layer):
def __init__(self, config, is_cross_attention=False, **kwargs):
super().__init__(**kwargs)
self.self = TFBlipTextSelfAttention(config, is_cross_attention, name="self")
# "output" is a protected attribute on TF models
self.self_output = T... | class_definition | 15,070 | 16,762 | 0 | /Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/models/blip/modeling_tf_blip_text.py | null | 6,111 |
class TFBlipTextIntermediate(keras.layers.Layer):
def __init__(self, config: BlipTextConfig, **kwargs):
super().__init__(**kwargs)
self.dense = keras.layers.Dense(
units=config.intermediate_size, kernel_initializer=get_initializer(config.initializer_range), name="dense"
)
... | class_definition | 16,860 | 17,890 | 0 | /Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/models/blip/modeling_tf_blip_text.py | null | 6,112 |
class TFBlipTextOutput(keras.layers.Layer):
def __init__(self, config: BlipTextConfig, **kwargs):
super().__init__(**kwargs)
self.dense = keras.layers.Dense(
units=config.hidden_size, kernel_initializer=get_initializer(config.initializer_range), name="dense"
)
self.Layer... | class_definition | 17,893 | 19,230 | 0 | /Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/models/blip/modeling_tf_blip_text.py | null | 6,113 |
class TFBlipTextLayer(keras.layers.Layer):
def __init__(self, config, **kwargs):
super().__init__(**kwargs)
self.config = config
self.attention = TFBlipTextAttention(config, name="attention")
if self.config.is_decoder:
self.crossattention = TFBlipTextAttention(
... | class_definition | 19,233 | 22,262 | 0 | /Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/models/blip/modeling_tf_blip_text.py | null | 6,114 |
class TFBlipTextEncoder(keras.layers.Layer):
config_class = BlipTextConfig
def __init__(self, config, name=None, **kwargs):
super().__init__(name=name, **kwargs)
self.config = config
self.layer = [TFBlipTextLayer(config, name=f"layer_._{i}") for i in range(config.num_hidden_layers)]
... | class_definition | 22,364 | 25,421 | 0 | /Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/models/blip/modeling_tf_blip_text.py | null | 6,115 |
class TFBlipTextPooler(keras.layers.Layer):
def __init__(self, config: BlipTextConfig, **kwargs):
super().__init__(**kwargs)
self.dense = keras.layers.Dense(
units=config.hidden_size,
kernel_initializer=get_initializer(config.initializer_range),
activation="tanh"... | class_definition | 25,513 | 26,490 | 0 | /Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/models/blip/modeling_tf_blip_text.py | null | 6,116 |
class TFBlipTextPredictionHeadTransform(keras.layers.Layer):
def __init__(self, config: BlipTextConfig, **kwargs):
super().__init__(**kwargs)
self.dense = keras.layers.Dense(
units=config.hidden_size,
kernel_initializer=get_initializer(config.initializer_range),
... | class_definition | 26,599 | 28,004 | 0 | /Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/models/blip/modeling_tf_blip_text.py | null | 6,117 |
class TFBlipTextLMPredictionHead(keras.layers.Layer):
def __init__(self, config, **kwargs):
super().__init__(**kwargs)
self.transform = TFBlipTextPredictionHeadTransform(config, name="transform")
# The output weights are the same as the input embeddings, but there is
# an output-onl... | class_definition | 28,007 | 29,336 | 0 | /Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/models/blip/modeling_tf_blip_text.py | null | 6,118 |
class TFBlipTextOnlyMLMHead(keras.layers.Layer):
def __init__(self, config, **kwargs):
super().__init__(**kwargs)
self.predictions = TFBlipTextLMPredictionHead(config, name="predictions")
def call(self, sequence_output: tf.Tensor) -> tf.Tensor:
prediction_scores = self.predictions(seque... | class_definition | 29,339 | 29,970 | 0 | /Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/models/blip/modeling_tf_blip_text.py | null | 6,119 |
class TFBlipTextPreTrainedModel(TFPreTrainedModel):
"""
An abstract class to handle weights initialization and a simple interface for downloading and loading pretrained
models.
"""
config_class = BlipTextConfig
base_model_prefix = "bert"
_keys_to_ignore_on_load_missing = [r"position_ids"] | class_definition | 30,052 | 30,370 | 0 | /Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/models/blip/modeling_tf_blip_text.py | null | 6,120 |
class TFBlipTextModel(TFBlipTextPreTrainedModel):
"""
The model can behave as an encoder (with only self-attention) as well as a decoder, in which case a layer of
cross-attention is added between the self-attention layers, following the architecture described in [Attention is
all you need](https://arxiv... | class_definition | 30,488 | 42,796 | 0 | /Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/models/blip/modeling_tf_blip_text.py | null | 6,121 |
class TFBlipTextLMHeadModel(TFBlipTextPreTrainedModel):
_keys_to_ignore_on_load_unexpected = [r"pooler"]
_keys_to_ignore_on_load_missing = [r"position_ids", r"predictions.decoder.bias"]
def __init__(self, config, **kwargs):
super().__init__(config, **kwargs)
self.bert = TFBlipTextModel(con... | class_definition | 42,878 | 49,971 | 0 | /Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/models/blip/modeling_tf_blip_text.py | null | 6,122 |
class BlipProcessorKwargs(ProcessingKwargs, total=False):
_defaults = {
"text_kwargs": {
"add_special_tokens": True,
"padding": False,
"stride": 0,
"return_overflowing_tokens": False,
"return_special_tokens_mask": False,
"return_offsets... | class_definition | 878 | 1,370 | 0 | /Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/models/blip/processing_blip.py | null | 6,123 |
class BlipProcessor(ProcessorMixin):
r"""
Constructs a BLIP processor which wraps a BERT tokenizer and BLIP image processor into a single processor.
[`BlipProcessor`] offers all the functionalities of [`BlipImageProcessor`] and [`BertTokenizerFast`]. See the
docstring of [`~BlipProcessor.__call__`] and... | class_definition | 1,373 | 5,866 | 0 | /Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/models/blip/processing_blip.py | null | 6,124 |
class BlipImageProcessor(BaseImageProcessor):
r"""
Constructs a BLIP image processor.
Args:
do_resize (`bool`, *optional*, defaults to `True`):
Whether to resize the image's (height, width) dimensions to the specified `size`. Can be overridden by the
`do_resize` parameter in... | class_definition | 1,374 | 15,224 | 0 | /Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/models/blip/image_processing_blip.py | null | 6,125 |
class BlipTextConfig(PretrainedConfig):
r"""
This is the configuration class to store the configuration of a [`BlipTextModel`]. It is used to instantiate a BLIP
text model according to the specified arguments, defining the model architecture. Instantiating a configuration
with the defaults will yield a ... | class_definition | 781 | 6,816 | 0 | /Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/models/blip/configuration_blip.py | null | 6,126 |
class BlipVisionConfig(PretrainedConfig):
r"""
This is the configuration class to store the configuration of a [`BlipVisionModel`]. It is used to instantiate a
BLIP vision model according to the specified arguments, defining the model architecture. Instantiating a
configuration defaults will yield a sim... | class_definition | 6,819 | 10,433 | 0 | /Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/models/blip/configuration_blip.py | null | 6,127 |
class BlipConfig(PretrainedConfig):
r"""
[`BlipConfig`] is the configuration class to store the configuration of a [`BlipModel`]. It is used to instantiate
a BLIP model according to the specified arguments, defining the text model and vision model configs. Instantiating
a configuration with the defaults... | class_definition | 10,436 | 14,828 | 0 | /Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/models/blip/configuration_blip.py | null | 6,128 |
class TFBlipForConditionalGenerationModelOutput(ModelOutput):
"""
Adapted from the base class for vision model's outputs that also contains image embeddings of the pooling of the
last hidden states. This class also adds the loss term from the text decoder.
Args:
loss (`tf.Tensor`, *optional*, r... | class_definition | 2,211 | 4,632 | 0 | /Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/models/blip/modeling_tf_blip.py | null | 6,129 |
class TFBlipTextVisionModelOutput(ModelOutput):
"""
Adapted from the base class for vision model's outputs that also contains image embeddings of the pooling of the
last hidden states. This class also adds the loss term from the text decoder.
Args:
loss (`tf.Tensor` of shape `(1,)`, *optional*,... | class_definition | 4,646 | 6,609 | 0 | /Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/models/blip/modeling_tf_blip.py | null | 6,130 |
class TFBlipImageTextMatchingModelOutput(ModelOutput):
"""
Adapted from the base class for vision model's outputs that also contains image embeddings of the pooling of the
last hidden states. This class also adds the loss term from the text decoder as well as the image-text similarity
scores.
Args:... | class_definition | 6,623 | 9,158 | 0 | /Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/models/blip/modeling_tf_blip.py | null | 6,131 |
class TFBlipOutput(ModelOutput):
"""
Args:
loss (`tf.Tensor` of shape `(1,)`, *optional*, returned when `return_loss` is `True`):
Contrastive loss for image-text similarity.
logits_per_image:(`tf.Tensor` of shape `(image_batch_size, text_batch_size)`):
The scaled dot prod... | class_definition | 9,172 | 10,953 | 0 | /Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/models/blip/modeling_tf_blip.py | null | 6,132 |
class TFBlipVisionEmbeddings(keras.layers.Layer):
def __init__(self, config: BlipVisionConfig, **kwargs):
super().__init__(**kwargs)
self.config = config
self.embed_dim = config.hidden_size
self.image_size = config.image_size
self.patch_size = config.patch_size
self.... | class_definition | 10,956 | 13,242 | 0 | /Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/models/blip/modeling_tf_blip.py | null | 6,133 |
class TFBlipTextEmbeddings(keras.layers.Layer):
def __init__(self, config: BlipTextConfig, **kwargs):
super().__init__(**kwargs)
self.embed_dim = config.hidden_size
self.config = config
def build(self, input_shape: tf.TensorShape = None):
with tf.name_scope("token_embedding"):... | class_definition | 13,338 | 15,474 | 0 | /Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/models/blip/modeling_tf_blip.py | null | 6,134 |
class TFBlipAttention(keras.layers.Layer):
"""Multi-headed attention from 'Attention Is All You Need' paper"""
def __init__(self, config, **kwargs):
super().__init__(**kwargs)
self.config = config
self.embed_dim = config.hidden_size
self.num_heads = config.num_attention_heads
... | class_definition | 15,477 | 18,952 | 0 | /Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/models/blip/modeling_tf_blip.py | null | 6,135 |
class TFBlipMLP(keras.layers.Layer):
def __init__(self, config: BlipConfig, **kwargs):
super().__init__(**kwargs)
self.activation_fn = get_tf_activation(config.hidden_act)
in_proj_std = (config.hidden_size**-0.5) * ((2 * config.num_hidden_layers) ** -0.5)
fc_std = (2 * config.hidde... | class_definition | 18,955 | 20,322 | 0 | /Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/models/blip/modeling_tf_blip.py | null | 6,136 |
class TFBlipEncoderLayer(keras.layers.Layer):
def __init__(self, config: BlipConfig, **kwargs):
super().__init__(**kwargs)
self.embed_dim = config.hidden_size
self.self_attn = TFBlipAttention(config, name="self_attn")
self.layer_norm1 = keras.layers.LayerNormalization(epsilon=config.... | class_definition | 20,325 | 23,081 | 0 | /Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/models/blip/modeling_tf_blip.py | null | 6,137 |
class TFBlipPreTrainedModel(TFPreTrainedModel):
"""
An abstract class to handle weights initialization and a simple interface for downloading and loading pretrained
models.
"""
config_class = BlipConfig
base_model_prefix = "blip"
_keys_to_ignore_on_load_missing = [r"position_ids"] | class_definition | 23,084 | 23,394 | 0 | /Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/models/blip/modeling_tf_blip.py | null | 6,138 |
class TFBlipEncoder(keras.layers.Layer):
config_class = BlipConfig
"""
Transformer encoder consisting of `config.num_hidden_layers` self attention layers. Each layer is a
[`BlipEncoderLayer`].
Args:
config (`BlipConfig`):
The corresponding vision configuration for the `BlipEncod... | class_definition | 27,169 | 30,950 | 0 | /Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/models/blip/modeling_tf_blip.py | null | 6,139 |
class TFBlipVisionModel(TFBlipPreTrainedModel):
main_input_name = "pixel_values"
config_class = BlipVisionConfig
def __init__(self, config: BlipVisionConfig, *args, **kwargs):
super().__init__(config, *args, **kwargs)
self.config = config
self.embeddings = TFBlipVisionEmbeddings(co... | class_definition | 30,953 | 34,812 | 0 | /Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/models/blip/modeling_tf_blip.py | null | 6,140 |
class TFBlipMainLayer(keras.layers.Layer):
config_class = BlipConfig
def __init__(self, config: BlipConfig, *args, **kwargs):
super().__init__(*args, **kwargs)
if not isinstance(config.text_config, BlipTextConfig):
raise TypeError(
"config.text_config is expected to... | class_definition | 34,815 | 40,356 | 0 | /Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/models/blip/modeling_tf_blip.py | null | 6,141 |
class TFBlipModel(TFBlipPreTrainedModel):
config_class = BlipConfig
_keys_to_ignore_on_load_missing = [r"text_decoder.cls.predictions.decoder.bias"]
main_input_name = "input_ids"
def __init__(self, config: BlipConfig, *inputs, **kwargs):
super().__init__(config, *inputs, **kwargs)
self... | class_definition | 40,359 | 46,208 | 0 | /Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/models/blip/modeling_tf_blip.py | null | 6,142 |
class TFBlipForConditionalGeneration(TFBlipPreTrainedModel):
config_class = BlipConfig
_keys_to_ignore_on_load_missing = [r"text_decoder.cls.predictions.decoder.bias"]
main_input_name = "pixel_values"
def __init__(self, config: BlipConfig, *args, **kwargs):
super().__init__(config, *args, **kwa... | class_definition | 46,740 | 53,749 | 0 | /Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/models/blip/modeling_tf_blip.py | null | 6,143 |
class TFBlipForQuestionAnswering(TFBlipPreTrainedModel):
config_class = BlipConfig
_keys_to_ignore_on_load_missing = [r"text_decoder.cls.predictions.decoder.bias"]
def __init__(self, config: BlipConfig, *args, **kwargs):
super().__init__(config, *args, **kwargs)
self.vision_model = TFBlipV... | class_definition | 54,154 | 64,270 | 0 | /Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/models/blip/modeling_tf_blip.py | null | 6,144 |
class TFBlipForImageTextRetrieval(TFBlipPreTrainedModel):
config_class = BlipConfig
def __init__(self, config: BlipConfig, *args, **kwargs):
super().__init__(config, *args, **kwargs)
self.vision_model = TFBlipVisionModel(config.vision_config, name="vision_model")
self.text_encoder = T... | class_definition | 64,592 | 71,311 | 0 | /Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/models/blip/modeling_tf_blip.py | null | 6,145 |
class BlipTextEmbeddings(nn.Module):
"""Construct the embeddings from word and position embeddings."""
def __init__(self, config):
super().__init__()
self.word_embeddings = nn.Embedding(config.vocab_size, config.hidden_size, padding_idx=config.pad_token_id)
self.position_embeddings = nn... | class_definition | 1,422 | 3,488 | 0 | /Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/models/blip/modeling_blip_text.py | null | 6,146 |
class BlipTextSelfAttention(nn.Module):
def __init__(self, config, is_cross_attention):
super().__init__()
self.config = config
if config.hidden_size % config.num_attention_heads != 0 and not hasattr(config, "embedding_size"):
raise ValueError(
"The hidden size (%... | class_definition | 3,569 | 10,159 | 0 | /Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/models/blip/modeling_blip_text.py | null | 6,147 |
class BlipTextSelfOutput(nn.Module):
def __init__(self, config):
super().__init__()
self.dense = nn.Linear(config.hidden_size, config.hidden_size)
self.LayerNorm = nn.LayerNorm(config.hidden_size, eps=config.layer_norm_eps)
self.dropout = nn.Dropout(config.hidden_dropout_prob)
d... | class_definition | 10,252 | 10,862 | 0 | /Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/models/blip/modeling_blip_text.py | null | 6,148 |
class BlipTextAttention(nn.Module):
def __init__(self, config, is_cross_attention=False):
super().__init__()
self.self = BlipTextSelfAttention(config, is_cross_attention)
self.output = BlipTextSelfOutput(config)
self.pruned_heads = set()
def prune_heads(self, heads):
if ... | class_definition | 10,943 | 12,983 | 0 | /Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/models/blip/modeling_blip_text.py | null | 6,149 |
class BlipTextIntermediate(nn.Module):
def __init__(self, config):
super().__init__()
self.dense = nn.Linear(config.hidden_size, config.intermediate_size)
if isinstance(config.hidden_act, str):
self.intermediate_act_fn = ACT2FN[config.hidden_act]
else:
self.in... | class_definition | 13,078 | 13,647 | 0 | /Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/models/blip/modeling_blip_text.py | null | 6,150 |
class BlipTextOutput(nn.Module):
def __init__(self, config):
super().__init__()
self.dense = nn.Linear(config.intermediate_size, config.hidden_size)
self.LayerNorm = nn.LayerNorm(config.hidden_size, eps=config.layer_norm_eps)
self.dropout = nn.Dropout(config.hidden_dropout_prob)
... | class_definition | 13,736 | 14,348 | 0 | /Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/models/blip/modeling_blip_text.py | null | 6,151 |
class BlipTextLayer(nn.Module):
def __init__(self, config, layer_num):
super().__init__()
self.config = config
self.chunk_size_feed_forward = config.chunk_size_feed_forward
self.seq_len_dim = 1
self.attention = BlipTextAttention(config)
self.layer_num = layer_num
... | class_definition | 14,351 | 16,983 | 0 | /Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/models/blip/modeling_blip_text.py | null | 6,152 |
class BlipTextEncoder(nn.Module):
def __init__(self, config):
super().__init__()
self.config = config
self.layer = nn.ModuleList([BlipTextLayer(config, i) for i in range(config.num_hidden_layers)])
self.gradient_checkpointing = False
def forward(
self,
hidden_sta... | class_definition | 17,065 | 20,838 | 0 | /Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/models/blip/modeling_blip_text.py | null | 6,153 |
class BlipTextPooler(nn.Module):
def __init__(self, config):
super().__init__()
self.dense = nn.Linear(config.hidden_size, config.hidden_size)
self.activation = nn.Tanh()
def forward(self, hidden_states: torch.Tensor) -> torch.Tensor:
# We "pool" the model by simply taking the h... | class_definition | 20,925 | 21,488 | 0 | /Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/models/blip/modeling_blip_text.py | null | 6,154 |
class BlipTextPredictionHeadTransform(nn.Module):
def __init__(self, config):
super().__init__()
self.dense = nn.Linear(config.hidden_size, config.hidden_size)
if isinstance(config.hidden_act, str):
self.transform_act_fn = ACT2FN[config.hidden_act]
else:
self.... | class_definition | 21,592 | 22,296 | 0 | /Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/models/blip/modeling_blip_text.py | null | 6,155 |
class BlipTextLMPredictionHead(nn.Module):
def __init__(self, config):
super().__init__()
self.transform = BlipTextPredictionHeadTransform(config)
# The output weights are the same as the input embeddings, but there is
# an output-only bias for each token.
self.decoder = nn.... | class_definition | 22,393 | 23,233 | 0 | /Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/models/blip/modeling_blip_text.py | null | 6,156 |
class BlipTextOnlyMLMHead(nn.Module):
def __init__(self, config):
super().__init__()
self.predictions = BlipTextLMPredictionHead(config)
def forward(self, sequence_output: torch.Tensor) -> torch.Tensor:
prediction_scores = self.predictions(sequence_output)
return prediction_scor... | class_definition | 23,325 | 23,647 | 0 | /Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/models/blip/modeling_blip_text.py | null | 6,157 |
class BlipTextPreTrainedModel(PreTrainedModel):
"""
An abstract class to handle weights initialization and a simple interface for downloading and loading pretrained
models.
"""
config_class = BlipTextConfig
base_model_prefix = "bert"
_no_split_modules = []
def _init_weights(self, modul... | class_definition | 23,729 | 24,626 | 0 | /Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/models/blip/modeling_blip_text.py | null | 6,158 |
class BlipTextModel(BlipTextPreTrainedModel):
"""
The model can behave as an encoder (with only self-attention) as well as a decoder, in which case a layer of
cross-attention is added between the self-attention layers, following the architecture described in [Attention is
all you need](https://arxiv.org... | class_definition | 24,744 | 36,998 | 0 | /Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/models/blip/modeling_blip_text.py | null | 6,159 |
class BlipTextLMHeadModel(BlipTextPreTrainedModel, GenerationMixin):
def __init__(self, config):
super().__init__(config)
self.bert = BlipTextModel(config, add_pooling_layer=False)
self.cls = BlipTextOnlyMLMHead(config)
self.label_smoothing = config.label_smoothing
def get_inpu... | class_definition | 37,080 | 44,174 | 0 | /Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/models/blip/modeling_blip_text.py | null | 6,160 |
class BlipForConditionalGenerationModelOutput(ModelOutput):
"""
Adapted from the base class for vision model's outputs that also contains image embeddings of the pooling of the
last hidden states. This class also adds the loss term from the text decoder.
Args:
loss (`torch.FloatTensor`, *option... | class_definition | 2,009 | 4,562 | 0 | /Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/models/blip/modeling_blip.py | null | 6,161 |
class BlipTextVisionModelOutput(ModelOutput):
"""
Adapted from the base class for vision model's outputs that also contains image embeddings of the pooling of the
last hidden states. This class also adds the loss term from the text decoder.
Args:
loss (`torch.FloatTensor` of shape `(1,)`, *opti... | class_definition | 4,576 | 6,645 | 0 | /Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/models/blip/modeling_blip.py | null | 6,162 |
class BlipImageTextMatchingModelOutput(ModelOutput):
"""
Adapted from the base class for vision model's outputs that also contains image embeddings of the pooling of the
last hidden states. This class also adds the loss term from the text decoder as well as the image-text similarity
scores.
Args:
... | class_definition | 6,659 | 9,357 | 0 | /Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/models/blip/modeling_blip.py | null | 6,163 |
class BlipOutput(ModelOutput):
"""
Args:
loss (`torch.FloatTensor` of shape `(1,)`, *optional*, returned when `return_loss` is `True`):
Contrastive loss for image-text similarity.
logits_per_image:(`torch.FloatTensor` of shape `(image_batch_size, text_batch_size)`):
The s... | class_definition | 9,371 | 11,229 | 0 | /Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/models/blip/modeling_blip.py | null | 6,164 |
class BlipVisionEmbeddings(nn.Module):
def __init__(self, config: BlipVisionConfig):
super().__init__()
self.config = config
self.embed_dim = config.hidden_size
self.image_size = config.image_size
self.patch_size = config.patch_size
self.class_embedding = nn.Paramete... | class_definition | 11,232 | 14,642 | 0 | /Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/models/blip/modeling_blip.py | null | 6,165 |
class BlipTextEmbeddings(nn.Module):
def __init__(self, config: BlipTextConfig):
super().__init__()
embed_dim = config.hidden_size
self.token_embedding = nn.Embedding(config.vocab_size, embed_dim)
self.position_embedding = nn.Embedding(config.max_position_embeddings, embed_dim)
... | class_definition | 14,733 | 16,311 | 0 | /Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/models/blip/modeling_blip.py | null | 6,166 |
class BlipAttention(nn.Module):
"""Multi-headed attention from 'Attention Is All You Need' paper"""
def __init__(self, config):
super().__init__()
self.config = config
self.embed_dim = config.hidden_size
self.num_heads = config.num_attention_heads
self.head_dim = self.em... | class_definition | 16,314 | 19,072 | 0 | /Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/models/blip/modeling_blip.py | null | 6,167 |
class BlipMLP(nn.Module):
def __init__(self, config):
super().__init__()
self.config = config
self.activation_fn = ACT2FN[config.hidden_act]
self.fc1 = nn.Linear(config.hidden_size, config.intermediate_size)
self.fc2 = nn.Linear(config.intermediate_size, config.hidden_size)
... | class_definition | 19,152 | 19,722 | 0 | /Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/models/blip/modeling_blip.py | null | 6,168 |
class BlipEncoderLayer(nn.Module):
def __init__(self, config: BlipConfig):
super().__init__()
self.embed_dim = config.hidden_size
self.self_attn = BlipAttention(config)
self.layer_norm1 = nn.LayerNorm(self.embed_dim, eps=config.layer_norm_eps)
self.mlp = BlipMLP(config)
... | class_definition | 19,725 | 21,563 | 0 | /Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/models/blip/modeling_blip.py | null | 6,169 |
class BlipPreTrainedModel(PreTrainedModel):
"""
An abstract class to handle weights initialization and a simple interface for downloading and loading pretrained
models.
"""
config_class = BlipConfig
base_model_prefix = "blip"
supports_gradient_checkpointing = True
_no_split_modules = ["... | class_definition | 21,566 | 23,085 | 0 | /Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/models/blip/modeling_blip.py | null | 6,170 |
class BlipEncoder(nn.Module):
"""
Transformer encoder consisting of `config.num_hidden_layers` self attention layers. Each layer is a
[`BlipEncoderLayer`].
Args:
config (`BlipConfig`):
The corresponding vision configuration for the `BlipEncoder`.
"""
def __init__(self, conf... | class_definition | 28,822 | 32,553 | 0 | /Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/models/blip/modeling_blip.py | null | 6,171 |
class BlipVisionModel(BlipPreTrainedModel):
main_input_name = "pixel_values"
config_class = BlipVisionConfig
def __init__(self, config: BlipVisionConfig):
super().__init__(config)
self.config = config
embed_dim = config.hidden_size
self.embeddings = BlipVisionEmbeddings(con... | class_definition | 32,556 | 35,031 | 0 | /Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/models/blip/modeling_blip.py | null | 6,172 |
class BlipModel(BlipPreTrainedModel):
config_class = BlipConfig
def __init__(self, config: BlipConfig):
super().__init__(config)
if not isinstance(config.text_config, BlipTextConfig):
raise TypeError(
"config.text_config is expected to be of type BlipTextConfig but ... | class_definition | 35,291 | 46,505 | 0 | /Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/models/blip/modeling_blip.py | null | 6,173 |
class BlipForConditionalGeneration(BlipPreTrainedModel, GenerationMixin):
config_class = BlipConfig
_tied_weights_keys = ["text_decoder.cls.predictions.decoder.bias"]
main_input_name = "pixel_values"
def __init__(self, config: BlipConfig):
super().__init__(config)
self.vision_model = B... | class_definition | 47,037 | 53,875 | 0 | /Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/models/blip/modeling_blip.py | null | 6,174 |
class BlipForQuestionAnswering(BlipPreTrainedModel):
config_class = BlipConfig
_tied_weights_keys = ["text_decoder.cls.predictions.decoder.bias"]
def __init__(self, config: BlipConfig):
super().__init__(config)
self.vision_model = BlipVisionModel(config.vision_config)
self.text_en... | class_definition | 54,280 | 63,323 | 0 | /Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/models/blip/modeling_blip.py | null | 6,175 |
class BlipForImageTextRetrieval(BlipPreTrainedModel):
config_class = BlipConfig
def __init__(self, config: BlipConfig):
super().__init__(config)
self.vision_model = BlipVisionModel(config.vision_config)
self.text_encoder = BlipTextModel(config.text_config, add_pooling_layer=False)
... | class_definition | 63,645 | 68,642 | 0 | /Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/models/blip/modeling_blip.py | null | 6,176 |
class RetrievAugLMMarginOutput(ModelOutput):
"""
Base class for retriever augmented marginalized models outputs.
Args:
loss (`torch.FloatTensor` of shape `(1,)`, *optional*, returned when `labels` is provided):
Language modeling loss.
logits (`torch.FloatTensor` of shape `(batch... | class_definition | 1,305 | 8,630 | 0 | /Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/models/rag/modeling_rag.py | null | 6,177 |
class RetrievAugLMOutput(ModelOutput):
"""
Args:
logits (`torch.FloatTensor` of shape `(batch_size, sequence_length, config.vocab_size)`):
Prediction scores of the language modeling head. The score is possibly marginalized over all documents for
each vocabulary token.
doc... | class_definition | 8,644 | 15,713 | 0 | /Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/models/rag/modeling_rag.py | null | 6,178 |
class RagPreTrainedModel(PreTrainedModel):
r"""
RAG models were released with the paper [Retrieval-Augmented Generation for Knowledge-Intensive NLP
Tasks](https://arxiv.org/abs/2005.11401) by Patrick Lewis, Ethan Perez, Aleksandra Piktus et al.
RAG is a retriever augmented model and encapsulate three c... | class_definition | 15,716 | 23,889 | 0 | /Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/models/rag/modeling_rag.py | null | 6,179 |
class RagModel(RagPreTrainedModel):
def __init__(
self,
config: Optional[PretrainedConfig] = None,
question_encoder: Optional[PreTrainedModel] = None,
generator: Optional[PreTrainedModel] = None,
retriever: Optional[RagRetriever] = None, # or maybe just use a `set_retriever(... | class_definition | 31,012 | 42,438 | 0 | /Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/models/rag/modeling_rag.py | null | 6,180 |
class RagSequenceForGeneration(RagPreTrainedModel):
def __init__(
self,
config: Optional[PretrainedConfig] = None,
question_encoder: Optional[PreTrainedModel] = None,
generator: Optional[PreTrainedModel] = None,
retriever: Optional[RagRetriever] = None,
**kwargs,
... | class_definition | 42,637 | 61,568 | 0 | /Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/models/rag/modeling_rag.py | null | 6,181 |
class RagTokenForGeneration(RagPreTrainedModel):
def __init__(
self,
config: Optional[PretrainedConfig] = None,
question_encoder: Optional[PreTrainedModel] = None,
generator: Optional[PreTrainedModel] = None,
retriever: Optional[RagRetriever] = None,
**kwargs,
):
... | class_definition | 61,761 | 86,275 | 0 | /Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/models/rag/modeling_rag.py | null | 6,182 |
class RagConfig(PretrainedConfig):
model_type = "rag"
is_composition = True
def __init__(
self,
vocab_size=None,
is_encoder_decoder=True,
prefix=None,
bos_token_id=None,
pad_token_id=None,
eos_token_id=None,
decoder_start_token_id=None,
... | class_definition | 4,699 | 8,486 | 0 | /Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/models/rag/configuration_rag.py | null | 6,183 |
class TFRetrievAugLMMarginOutput(ModelOutput):
"""
Base class for retriever augmented marginalized models outputs.
Args:
loss (`tf.Tensor` of shape `(1,)`, *optional*, returned when `labels` is provided):
Language modeling loss.
logits (`tf.Tensor` of shape `(batch_size, sequenc... | class_definition | 1,372 | 7,819 | 0 | /Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/models/rag/modeling_tf_rag.py | null | 6,184 |
class TFRetrievAugLMOutput(ModelOutput):
"""
Args:
logits (`tf.Tensor` of shape `(batch_size, sequence_length, config.vocab_size)`):
Prediction scores of the language modeling head. The score is possibly marginalized over all documents for
each vocabulary token.
past_key_... | class_definition | 7,833 | 14,020 | 0 | /Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/models/rag/modeling_tf_rag.py | null | 6,185 |
class TFRagPreTrainedModel(TFPreTrainedModel):
r"""
RAG models were released with the paper [Retrieval-Augmented Generation for Knowledge-Intensive NLP
Tasks](https://arxiv.org/abs/2005.11401) by Patrick Lewis, Ethan Perez, Aleksandra Piktus et al.
RAG is a retriever augmented model and encapsulate thr... | class_definition | 14,023 | 22,226 | 0 | /Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/models/rag/modeling_tf_rag.py | null | 6,186 |
class TFRagModel(TFRagPreTrainedModel):
load_weight_prefix = "tf_rag_model_1"
def __init__(
self,
config: Optional[PretrainedConfig] = None,
question_encoder: Optional[TFPreTrainedModel] = None,
generator: Optional[TFPreTrainedModel] = None,
retriever: Optional[RagRetrie... | class_definition | 29,544 | 39,958 | 0 | /Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/models/rag/modeling_tf_rag.py | null | 6,187 |
class TFRagTokenForGeneration(TFRagPreTrainedModel, TFCausalLanguageModelingLoss):
load_weight_prefix = "tf_rag_token_for_generation_1/rag"
def __init__(
self,
config: Optional[PretrainedConfig] = None,
question_encoder: Optional[TFPreTrainedModel] = None,
generator: Optional[TF... | class_definition | 40,154 | 66,857 | 0 | /Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/models/rag/modeling_tf_rag.py | null | 6,188 |
class TFRagSequenceForGeneration(TFRagPreTrainedModel, TFCausalLanguageModelingLoss):
load_weight_prefix = "tf_rag_sequence_for_generation_1/rag"
def __init__(
self,
config: Optional[PretrainedConfig] = None,
question_encoder: Optional[TFPreTrainedModel] = None,
generator: Optio... | class_definition | 67,059 | 88,808 | 0 | /Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/models/rag/modeling_tf_rag.py | null | 6,189 |
class Index:
"""
A base class for the Indices encapsulated by the [`RagRetriever`].
"""
def get_doc_dicts(self, doc_ids: np.ndarray) -> List[dict]:
"""
Returns a list of dictionaries, containing titles and text of the retrieved documents.
Args:
doc_ids (`np.ndarray`... | class_definition | 1,351 | 2,989 | 0 | /Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/models/rag/retrieval_rag.py | null | 6,190 |
class LegacyIndex(Index):
"""
An index which can be deserialized from the files built using https://github.com/facebookresearch/DPR. We use
default faiss index parameters as specified in that repository.
Args:
vector_size (`int`):
The dimension of indexed vectors.
index_path... | class_definition | 2,992 | 8,230 | 0 | /Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/models/rag/retrieval_rag.py | null | 6,191 |
class HFIndexBase(Index):
def __init__(self, vector_size, dataset, index_initialized=False):
self.vector_size = vector_size
self.dataset = dataset
self._index_initialized = index_initialized
self._check_dataset_format(with_index=index_initialized)
dataset.set_format("numpy", ... | class_definition | 8,233 | 10,410 | 0 | /Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/models/rag/retrieval_rag.py | null | 6,192 |
class CanonicalHFIndex(HFIndexBase):
"""
A wrapper around an instance of [`~datasets.Datasets`]. If `index_path` is set to `None`, we load the pre-computed
index available with the [`~datasets.arrow_dataset.Dataset`], otherwise, we load the index from the indicated path
on disk.
Args:
vecto... | class_definition | 10,413 | 13,474 | 0 | /Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/models/rag/retrieval_rag.py | null | 6,193 |
class CustomHFIndex(HFIndexBase):
"""
A wrapper around an instance of [`~datasets.Datasets`]. The dataset and the index are both loaded from the
indicated paths on disk.
Args:
vector_size (`int`): the dimension of the passages embeddings used by the index
dataset_path (`str`):
... | class_definition | 13,477 | 15,068 | 0 | /Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/models/rag/retrieval_rag.py | null | 6,194 |
class RagRetriever:
"""
Retriever used to get documents from vector queries. It retrieves the documents embeddings as well as the documents
contents, and it formats them to be used with a RagModel.
Args:
config ([`RagConfig`]):
The configuration of the RAG model this Retriever is us... | class_definition | 15,071 | 29,921 | 0 | /Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/models/rag/retrieval_rag.py | null | 6,195 |
class RagTokenizer:
def __init__(self, question_encoder, generator):
self.question_encoder = question_encoder
self.generator = generator
self.current_tokenizer = self.question_encoder
def save_pretrained(self, save_directory):
if os.path.isfile(save_directory):
raise... | class_definition | 889 | 4,576 | 0 | /Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/models/rag/tokenization_rag.py | null | 6,196 |
class MobileViTV2Config(PretrainedConfig):
r"""
This is the configuration class to store the configuration of a [`MobileViTV2Model`]. It is used to instantiate a
MobileViTV2 model according to the specified arguments, defining the model architecture. Instantiating a
configuration with the defaults will ... | class_definition | 914 | 6,439 | 0 | /Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/models/mobilevitv2/configuration_mobilevitv2.py | null | 6,197 |
class MobileViTV2OnnxConfig(OnnxConfig):
torch_onnx_minimum_version = version.parse("1.11")
@property
def inputs(self) -> Mapping[str, Mapping[int, str]]:
return OrderedDict([("pixel_values", {0: "batch", 1: "num_channels", 2: "height", 3: "width"})])
@property
def outputs(self) -> Mapping... | class_definition | 6,442 | 7,090 | 0 | /Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/models/mobilevitv2/configuration_mobilevitv2.py | null | 6,198 |
class MobileViTV2ConvLayer(nn.Module):
def __init__(
self,
config: MobileViTV2Config,
in_channels: int,
out_channels: int,
kernel_size: int,
stride: int = 1,
groups: int = 1,
bias: bool = False,
dilation: int = 1,
use_normalization: boo... | class_definition | 2,773 | 4,865 | 0 | /Users/nielsrogge/Documents/python_projecten/transformers/src/transformers/models/mobilevitv2/modeling_mobilevitv2.py | null | 6,199 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.