Aluode/PerceptionLabPortable
0
1# coding=utf-82# Copyright 2018 The Google AI Language Team Authors and The HuggingFace Inc. team.3# Copyright (c) 2018, NVIDIA CORPORATION. All rights reserved.4#5# Licensed under the Apache License, Version 2.0 (the "License");6# you may not use this file except in compliance with the License.7# You may obtain a copy of the License at8#9# http://www.apache.org/licenses/LICENSE-2.010#11# Unless required by applicable law or agreed to in writing, software12# distributed under the License is distributed on an "AS IS" BASIS,13# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.14# See the License for the specific language governing permissions and15# limitations under the License.16"""XLM-RoBERTa configuration"""17 18from collections import OrderedDict19from collections.abc import Mapping20 21from ...configuration_utils import PretrainedConfig22from ...onnx import OnnxConfig23from ...utils import logging24 25 26logger = logging.get_logger(__name__)27 28 29class XLMRobertaConfig(PretrainedConfig):30 r"""31 This is the configuration class to store the configuration of a [`XLMRobertaModel`] or a [`TFXLMRobertaModel`]. It32 is used to instantiate a XLM-RoBERTa model according to the specified arguments, defining the model architecture.33 Instantiating a configuration with the defaults will yield a similar configuration to that of the XLMRoBERTa34 [FacebookAI/xlm-roberta-base](https://huggingface.co/FacebookAI/xlm-roberta-base) architecture.35 36 Configuration objects inherit from [`PretrainedConfig`] and can be used to control the model outputs. Read the37 documentation from [`PretrainedConfig`] for more information.38 39 40 Args:41 vocab_size (`int`, *optional*, defaults to 30522):42 Vocabulary size of the XLM-RoBERTa model. Defines the number of different tokens that can be represented by43 the `inputs_ids` passed when calling [`XLMRobertaModel`] or [`TFXLMRobertaModel`].44 hidden_size (`int`, *optional*, defaults to 768):45 Dimensionality of the encoder layers and the pooler layer.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 [`XLMRobertaModel`] or64 [`TFXLMRobertaModel`].65 initializer_range (`float`, *optional*, defaults to 0.02):66 The standard deviation of the truncated_normal_initializer for initializing all weight matrices.67 layer_norm_eps (`float`, *optional*, defaults to 1e-12):68 The epsilon used by the layer normalization layers.69 position_embedding_type (`str`, *optional*, defaults to `"absolute"`):70 Type of position embedding. Choose one of `"absolute"`, `"relative_key"`, `"relative_key_query"`. For71 positional embeddings use `"absolute"`. For more information on `"relative_key"`, please refer to72 [Self-Attention with Relative Position Representations (Shaw et al.)](https://huggingface.co/papers/1803.02155).73 For more information on `"relative_key_query"`, please refer to *Method 4* in [Improve Transformer Models74 with Better Relative Position Embeddings (Huang et al.)](https://huggingface.co/papers/2009.13658).75 is_decoder (`bool`, *optional*, defaults to `False`):76 Whether the model is used as a decoder or not. If `False`, the model is used as an encoder.77 use_cache (`bool`, *optional*, defaults to `True`):78 Whether or not the model should return the last key/values attentions (not used by all models). Only79 relevant if `config.is_decoder=True`.80 classifier_dropout (`float`, *optional*):81 The dropout ratio for the classification head.82 83 Examples:84 85 ```python86 >>> from transformers import XLMRobertaConfig, XLMRobertaModel87 88 >>> # Initializing a XLM-RoBERTa FacebookAI/xlm-roberta-base style configuration89 >>> configuration = XLMRobertaConfig()90 91 >>> # Initializing a model (with random weights) from the FacebookAI/xlm-roberta-base style configuration92 >>> model = XLMRobertaModel(configuration)93 94 >>> # Accessing the model configuration95 >>> configuration = model.config96 ```"""97 98 model_type = "xlm-roberta"99 100 def __init__(101 self,102 vocab_size=30522,103 hidden_size=768,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 pad_token_id=1,115 bos_token_id=0,116 eos_token_id=2,117 position_embedding_type="absolute",118 use_cache=True,119 classifier_dropout=None,120 **kwargs,121 ):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.hidden_size = hidden_size126 self.num_hidden_layers = num_hidden_layers127 self.num_attention_heads = num_attention_heads128 self.hidden_act = hidden_act129 self.intermediate_size = intermediate_size130 self.hidden_dropout_prob = hidden_dropout_prob131 self.attention_probs_dropout_prob = attention_probs_dropout_prob132 self.max_position_embeddings = max_position_embeddings133 self.type_vocab_size = type_vocab_size134 self.initializer_range = initializer_range135 self.layer_norm_eps = layer_norm_eps136 self.position_embedding_type = position_embedding_type137 self.use_cache = use_cache138 self.classifier_dropout = classifier_dropout139 140 141# Copied from transformers.models.roberta.configuration_roberta.RobertaOnnxConfig with Roberta->XLMRoberta142class XLMRobertaOnnxConfig(OnnxConfig):143 @property144 def inputs(self) -> Mapping[str, Mapping[int, str]]:145 if self.task == "multiple-choice":146 dynamic_axis = {0: "batch", 1: "choice", 2: "sequence"}147 else:148 dynamic_axis = {0: "batch", 1: "sequence"}149 return OrderedDict(150 [151 ("input_ids", dynamic_axis),152 ("attention_mask", dynamic_axis),153 ]154 )155 156 157__all__ = ["XLMRobertaConfig", "XLMRobertaOnnxConfig"]158 