CoolFace
Apppublic

Aluode/PerceptionLabPortable

sourceHugging Faceupdated 9mo agoView on Hugging Face
0likes
configuration_vilt.py148 linesDownload Raw Back to vilt
1# coding=utf-82# Copyright 2022 The HuggingFace Inc. team. All rights reserved.3#4# Licensed under the Apache License, Version 2.0 (the "License");5# you may not use this file except in compliance with the License.6# You may obtain a copy of the License at7#8#     http://www.apache.org/licenses/LICENSE-2.09#10# Unless required by applicable law or agreed to in writing, software11# distributed under the License is distributed on an "AS IS" BASIS,12# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.13# See the License for the specific language governing permissions and14# limitations under the License.15"""VilT model configuration"""16 17from ...configuration_utils import PretrainedConfig18from ...utils import logging19 20 21logger = logging.get_logger(__name__)22 23 24class ViltConfig(PretrainedConfig):25    r"""26    This is the configuration class to store the configuration of a [`ViLTModel`]. It is used to instantiate an ViLT27    model according to the specified arguments, defining the model architecture. Instantiating a configuration with the28    defaults will yield a similar configuration to that of the ViLT29    [dandelin/vilt-b32-mlm](https://huggingface.co/dandelin/vilt-b32-mlm) architecture.30 31    Configuration objects inherit from [`PretrainedConfig`] and can be used to control the model outputs. Read the32    documentation from [`PretrainedConfig`] for more information.33 34    Args:35        vocab_size (`int`, *optional*, defaults to 30522):36            Vocabulary size of the text part of the model. Defines the number of different tokens that can be37            represented by the `inputs_ids` passed when calling [`ViltModel`].38        type_vocab_size (`int`, *optional*, defaults to 2):39            The vocabulary size of the `token_type_ids` passed when calling [`ViltModel`]. This is used when encoding40            text.41        modality_type_vocab_size (`int`, *optional*, defaults to 2):42            The vocabulary size of the modalities passed when calling [`ViltModel`]. This is used after concatenating the43            embeddings of the text and image modalities.44        max_position_embeddings (`int`, *optional*, defaults to 40):45            The maximum sequence length that this model might ever be used with.46        hidden_size (`int`, *optional*, defaults to 768):47            Dimensionality of the encoder layers and the pooler layer.48        num_hidden_layers (`int`, *optional*, defaults to 12):49            Number of hidden layers in the Transformer encoder.50        num_attention_heads (`int`, *optional*, defaults to 12):51            Number of attention heads for each attention layer in the Transformer encoder.52        intermediate_size (`int`, *optional*, defaults to 3072):53            Dimensionality of the "intermediate" (i.e., feed-forward) layer in the Transformer encoder.54        hidden_act (`str` or `function`, *optional*, defaults to `"gelu"`):55            The non-linear activation function (function or string) in the encoder and pooler. If string, `"gelu"`,56            `"relu"`, `"selu"` and `"gelu_new"` are supported.57        hidden_dropout_prob (`float`, *optional*, defaults to 0.0):58            The dropout probability for all fully connected layers in the embeddings, encoder, and pooler.59        attention_probs_dropout_prob (`float`, *optional*, defaults to 0.0):60            The dropout ratio for the attention probabilities.61        initializer_range (`float`, *optional*, defaults to 0.02):62            The standard deviation of the truncated_normal_initializer for initializing all weight matrices.63        layer_norm_eps (`float`, *optional*, defaults to 1e-12):64            The epsilon used by the layer normalization layers.65        image_size (`int`, *optional*, defaults to 384):66            The size (resolution) of each image.67        patch_size (`int`, *optional*, defaults to 32):68            The size (resolution) of each patch.69        num_channels (`int`, *optional*, defaults to 3):70            The number of input channels.71        qkv_bias (`bool`, *optional*, defaults to `True`):72            Whether to add a bias to the queries, keys and values.73        max_image_length (`int`, *optional*, defaults to -1):74            The maximum number of patches to take as input for the Transformer encoder. If set to a positive integer,75            the encoder will sample `max_image_length` patches at maximum. If set to -1, will not be taken into76            account.77        num_images (`int`, *optional*, defaults to -1):78            The number of images to use for natural language visual reasoning. If set to a positive integer, will be79            used by [`ViltForImagesAndTextClassification`] for defining the classifier head.80 81    Example:82 83    ```python84    >>> from transformers import ViLTModel, ViLTConfig85 86    >>> # Initializing a ViLT dandelin/vilt-b32-mlm style configuration87    >>> configuration = ViLTConfig()88 89    >>> # Initializing a model from the dandelin/vilt-b32-mlm style configuration90    >>> model = ViLTModel(configuration)91 92    >>> # Accessing the model configuration93    >>> configuration = model.config94    ```"""95 96    model_type = "vilt"97 98    def __init__(99        self,100        vocab_size=30522,101        type_vocab_size=2,102        modality_type_vocab_size=2,103        max_position_embeddings=40,104        hidden_size=768,105        num_hidden_layers=12,106        num_attention_heads=12,107        intermediate_size=3072,108        hidden_act="gelu",109        hidden_dropout_prob=0.0,110        attention_probs_dropout_prob=0.0,111        initializer_range=0.02,112        layer_norm_eps=1e-12,113        image_size=384,114        patch_size=32,115        num_channels=3,116        qkv_bias=True,117        max_image_length=-1,118        tie_word_embeddings=False,119        num_images=-1,120        **kwargs,121    ):122        super().__init__(tie_word_embeddings=tie_word_embeddings, **kwargs)123 124        self.vocab_size = vocab_size125        self.type_vocab_size = type_vocab_size126        self.modality_type_vocab_size = modality_type_vocab_size127        self.max_position_embeddings = max_position_embeddings128 129        self.hidden_size = hidden_size130        self.num_hidden_layers = num_hidden_layers131        self.num_attention_heads = num_attention_heads132        self.intermediate_size = intermediate_size133        self.hidden_act = hidden_act134        self.hidden_dropout_prob = hidden_dropout_prob135        self.attention_probs_dropout_prob = attention_probs_dropout_prob136        self.initializer_range = initializer_range137        self.layer_norm_eps = layer_norm_eps138 139        self.image_size = image_size140        self.patch_size = patch_size141        self.num_channels = num_channels142        self.qkv_bias = qkv_bias143        self.max_image_length = max_image_length144        self.num_images = num_images145 146 147__all__ = ["ViltConfig"]148 
Aluode/PerceptionLabPortable · CoolFace