CoolFace
Apppublic

Aluode/PerceptionLabPortable

sourceHugging Faceupdated 9mo agoView on Hugging Face
0likes
configuration_pegasus.py165 linesDownload Raw Back to pegasus
1# coding=utf-82# Copyright 2021, Google and 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"""PEGASUS model configuration"""16 17from ...configuration_utils import PretrainedConfig18from ...utils import logging19 20 21logger = logging.get_logger(__name__)22 23 24class PegasusConfig(PretrainedConfig):25    r"""26    This is the configuration class to store the configuration of a [`PegasusModel`]. It is used to instantiate an27    PEGASUS model according to the specified arguments, defining the model architecture. Instantiating a configuration28    with the defaults will yield a similar configuration to that of the PEGASUS29    [google/pegasus-large](https://huggingface.co/google/pegasus-large) 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 35    Args:36        vocab_size (`int`, *optional*, defaults to 50265):37            Vocabulary size of the PEGASUS model. Defines the number of different tokens that can be represented by the38            `inputs_ids` passed when calling [`PegasusModel`] or [`TFPegasusModel`].39        d_model (`int`, *optional*, defaults to 1024):40            Dimensionality of the layers and the pooler layer.41        encoder_layers (`int`, *optional*, defaults to 12):42            Number of encoder layers.43        decoder_layers (`int`, *optional*, defaults to 12):44            Number of decoder layers.45        encoder_attention_heads (`int`, *optional*, defaults to 16):46            Number of attention heads for each attention layer in the Transformer encoder.47        decoder_attention_heads (`int`, *optional*, defaults to 16):48            Number of attention heads for each attention layer in the Transformer decoder.49        decoder_ffn_dim (`int`, *optional*, defaults to 4096):50            Dimensionality of the "intermediate" (often named feed-forward) layer in decoder.51        encoder_ffn_dim (`int`, *optional*, defaults to 4096):52            Dimensionality of the "intermediate" (often named feed-forward) layer in decoder.53        activation_function (`str` or `function`, *optional*, defaults to `"gelu"`):54            The non-linear activation function (function or string) in the encoder and pooler. If string, `"gelu"`,55            `"relu"`, `"silu"` and `"gelu_new"` are supported.56        dropout (`float`, *optional*, defaults to 0.1):57            The dropout probability for all fully connected layers in the embeddings, encoder, and pooler.58        attention_dropout (`float`, *optional*, defaults to 0.0):59            The dropout ratio for the attention probabilities.60        activation_dropout (`float`, *optional*, defaults to 0.0):61            The dropout ratio for activations inside the fully connected layer.62        max_position_embeddings (`int`, *optional*, defaults to 1024):63            The maximum sequence length that this model might ever be used with. Typically set this to something large64            just in case (e.g., 512 or 1024 or 2048).65        init_std (`float`, *optional*, defaults to 0.02):66            The standard deviation of the truncated_normal_initializer for initializing all weight matrices.67        encoder_layerdrop (`float`, *optional*, defaults to 0.0):68            The LayerDrop probability for the encoder. See the [LayerDrop paper](see https://huggingface.co/papers/1909.11556)69            for more details.70        decoder_layerdrop (`float`, *optional*, defaults to 0.0):71            The LayerDrop probability for the decoder. See the [LayerDrop paper](see https://huggingface.co/papers/1909.11556)72            for more details.73        scale_embedding (`bool`, *optional*, defaults to `False`):74            Scale embeddings by diving by sqrt(d_model).75        use_cache (`bool`, *optional*, defaults to `True`):76            Whether or not the model should return the last key/values attentions (not used by all models)77        forced_eos_token_id (`int`, *optional*, defaults to 1):78            The id of the token to force as the last generated token when `max_length` is reached. Usually set to79            `eos_token_id`.80 81    Example:82 83    ```python84    >>> from transformers import PegasusConfig, PegasusModel85 86    >>> # Initializing a PEGASUS google/pegasus-large style configuration87    >>> configuration = PegasusConfig()88 89    >>> # Initializing a model (with random weights) from the google/pegasus-large style configuration90    >>> model = PegasusModel(configuration)91 92    >>> # Accessing the model configuration93    >>> configuration = model.config94    ```"""95 96    model_type = "pegasus"97    keys_to_ignore_at_inference = ["past_key_values"]98    attribute_map = {"num_attention_heads": "encoder_attention_heads", "hidden_size": "d_model"}99 100    def __init__(101        self,102        vocab_size=50265,103        max_position_embeddings=1024,104        encoder_layers=12,105        encoder_ffn_dim=4096,106        encoder_attention_heads=16,107        decoder_layers=12,108        decoder_ffn_dim=4096,109        decoder_attention_heads=16,110        encoder_layerdrop=0.0,111        decoder_layerdrop=0.0,112        use_cache=True,113        is_encoder_decoder=True,114        activation_function="gelu",115        d_model=1024,116        dropout=0.1,117        attention_dropout=0.0,118        activation_dropout=0.0,119        init_std=0.02,120        decoder_start_token_id=0,121        scale_embedding=False,122        pad_token_id=0,123        eos_token_id=1,124        forced_eos_token_id=1,125        **kwargs,126    ):127        self.vocab_size = vocab_size128        self.max_position_embeddings = max_position_embeddings129        self.d_model = d_model130        self.encoder_ffn_dim = encoder_ffn_dim131        self.encoder_layers = encoder_layers132        self.encoder_attention_heads = encoder_attention_heads133        self.decoder_ffn_dim = decoder_ffn_dim134        self.decoder_layers = decoder_layers135        self.decoder_attention_heads = decoder_attention_heads136        self.dropout = dropout137        self.attention_dropout = attention_dropout138        self.activation_dropout = activation_dropout139        self.activation_function = activation_function140        self.init_std = init_std141        self.encoder_layerdrop = encoder_layerdrop142        self.decoder_layerdrop = decoder_layerdrop143        self.use_cache = use_cache144        self.num_hidden_layers = encoder_layers145        self.scale_embedding = scale_embedding  # scale factor will be sqrt(d_model) if True146        super().__init__(147            pad_token_id=pad_token_id,148            eos_token_id=eos_token_id,149            is_encoder_decoder=is_encoder_decoder,150            decoder_start_token_id=decoder_start_token_id,151            forced_eos_token_id=forced_eos_token_id,152            **kwargs,153        )154 155    @property156    def num_attention_heads(self) -> int:157        return self.encoder_attention_heads158 159    @property160    def hidden_size(self) -> int:161        return self.d_model162 163 164__all__ = ["PegasusConfig"]165 
Aluode/PerceptionLabPortable · CoolFace