CoolFace
Apppublic

Aluode/PerceptionLabPortable

sourceHugging Faceupdated 9mo agoView on Hugging Face
0likes
configuration_luke.py143 linesDownload Raw Back to luke
1# coding=utf-82# Copyright Studio Ousia and The HuggingFace Inc. team.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"""LUKE configuration"""16 17from ...configuration_utils import PretrainedConfig18from ...utils import logging19 20 21logger = logging.get_logger(__name__)22 23 24class LukeConfig(PretrainedConfig):25    r"""26    This is the configuration class to store the configuration of a [`LukeModel`]. It is used to instantiate a LUKE27    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 LUKE29    [studio-ousia/luke-base](https://huggingface.co/studio-ousia/luke-base) 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 50267):37            Vocabulary size of the LUKE model. Defines the number of different tokens that can be represented by the38            `inputs_ids` passed when calling [`LukeModel`].39        entity_vocab_size (`int`, *optional*, defaults to 500000):40            Entity vocabulary size of the LUKE model. Defines the number of different entities that can be represented41            by the `entity_ids` passed when calling [`LukeModel`].42        hidden_size (`int`, *optional*, defaults to 768):43            Dimensionality of the encoder layers and the pooler layer.44        entity_emb_size (`int`, *optional*, defaults to 256):45            The number of dimensions of the entity embedding.46        num_hidden_layers (`int`, *optional*, defaults to 12):47            Number of hidden layers in the Transformer encoder.48        num_attention_heads (`int`, *optional*, defaults to 12):49            Number of attention heads for each attention layer in the Transformer encoder.50        intermediate_size (`int`, *optional*, defaults to 3072):51            Dimensionality of the "intermediate" (often named feed-forward) layer in the Transformer encoder.52        hidden_act (`str` or `Callable`, *optional*, defaults to `"gelu"`):53            The non-linear activation function (function or string) in the encoder and pooler. If string, `"gelu"`,54            `"relu"`, `"silu"` and `"gelu_new"` are supported.55        hidden_dropout_prob (`float`, *optional*, defaults to 0.1):56            The dropout probability for all fully connected layers in the embeddings, encoder, and pooler.57        attention_probs_dropout_prob (`float`, *optional*, defaults to 0.1):58            The dropout ratio for the attention probabilities.59        max_position_embeddings (`int`, *optional*, defaults to 512):60            The maximum sequence length that this model might ever be used with. Typically set this to something large61            just in case (e.g., 512 or 1024 or 2048).62        type_vocab_size (`int`, *optional*, defaults to 2):63            The vocabulary size of the `token_type_ids` passed when calling [`LukeModel`].64        initializer_range (`float`, *optional*, defaults to 0.02):65            The standard deviation of the truncated_normal_initializer for initializing all weight matrices.66        layer_norm_eps (`float`, *optional*, defaults to 1e-12):67            The epsilon used by the layer normalization layers.68        use_entity_aware_attention (`bool`, *optional*, defaults to `True`):69            Whether or not the model should use the entity-aware self-attention mechanism proposed in [LUKE: Deep70            Contextualized Entity Representations with Entity-aware Self-attention (Yamada et71            al.)](https://huggingface.co/papers/2010.01057).72        classifier_dropout (`float`, *optional*):73            The dropout ratio for the classification head.74        pad_token_id (`int`, *optional*, defaults to 1):75            Padding token id.76        bos_token_id (`int`, *optional*, defaults to 0):77            Beginning of stream token id.78        eos_token_id (`int`, *optional*, defaults to 2):79            End of stream token id.80 81    Examples:82 83    ```python84    >>> from transformers import LukeConfig, LukeModel85 86    >>> # Initializing a LUKE configuration87    >>> configuration = LukeConfig()88 89    >>> # Initializing a model from the configuration90    >>> model = LukeModel(configuration)91 92    >>> # Accessing the model configuration93    >>> configuration = model.config94    ```"""95 96    model_type = "luke"97 98    def __init__(99        self,100        vocab_size=50267,101        entity_vocab_size=500000,102        hidden_size=768,103        entity_emb_size=256,104        num_hidden_layers=12,105        num_attention_heads=12,106        intermediate_size=3072,107        hidden_act="gelu",108        hidden_dropout_prob=0.1,109        attention_probs_dropout_prob=0.1,110        max_position_embeddings=512,111        type_vocab_size=2,112        initializer_range=0.02,113        layer_norm_eps=1e-12,114        use_entity_aware_attention=True,115        classifier_dropout=None,116        pad_token_id=1,117        bos_token_id=0,118        eos_token_id=2,119        **kwargs,120    ):121        """Constructs LukeConfig."""122        super().__init__(pad_token_id=pad_token_id, bos_token_id=bos_token_id, eos_token_id=eos_token_id, **kwargs)123 124        self.vocab_size = vocab_size125        self.entity_vocab_size = entity_vocab_size126        self.hidden_size = hidden_size127        self.entity_emb_size = entity_emb_size128        self.num_hidden_layers = num_hidden_layers129        self.num_attention_heads = num_attention_heads130        self.hidden_act = hidden_act131        self.intermediate_size = intermediate_size132        self.hidden_dropout_prob = hidden_dropout_prob133        self.attention_probs_dropout_prob = attention_probs_dropout_prob134        self.max_position_embeddings = max_position_embeddings135        self.type_vocab_size = type_vocab_size136        self.initializer_range = initializer_range137        self.layer_norm_eps = layer_norm_eps138        self.use_entity_aware_attention = use_entity_aware_attention139        self.classifier_dropout = classifier_dropout140 141 142__all__ = ["LukeConfig"]143