configuration_mpnet.py 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. # coding=utf-8
  2. # Copyright 2018 The HuggingFace Inc. team, Microsoft Corporation.
  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 at
  8. #
  9. # http://www.apache.org/licenses/LICENSE-2.0
  10. #
  11. # Unless required by applicable law or agreed to in writing, software
  12. # 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 and
  15. # limitations under the License.
  16. """MPNet model configuration"""
  17. from ...configuration_utils import PretrainedConfig
  18. from ...utils import logging
  19. logger = logging.get_logger(__name__)
  20. class MPNetConfig(PretrainedConfig):
  21. r"""
  22. This is the configuration class to store the configuration of a [`MPNetModel`] or a [`TFMPNetModel`]. It is used to
  23. instantiate a MPNet model according to the specified arguments, defining the model architecture. Instantiating a
  24. configuration with the defaults will yield a similar configuration to that of the MPNet
  25. [microsoft/mpnet-base](https://huggingface.co/microsoft/mpnet-base) architecture.
  26. Configuration objects inherit from [`PretrainedConfig`] and can be used to control the model outputs. Read the
  27. documentation from [`PretrainedConfig`] for more information.
  28. Args:
  29. vocab_size (`int`, *optional*, defaults to 30527):
  30. Vocabulary size of the MPNet model. Defines the number of different tokens that can be represented by the
  31. `inputs_ids` passed when calling [`MPNetModel`] or [`TFMPNetModel`].
  32. hidden_size (`int`, *optional*, defaults to 768):
  33. Dimensionality of the encoder layers and the pooler layer.
  34. num_hidden_layers (`int`, *optional*, defaults to 12):
  35. Number of hidden layers in the Transformer encoder.
  36. num_attention_heads (`int`, *optional*, defaults to 12):
  37. Number of attention heads for each attention layer in the Transformer encoder.
  38. intermediate_size (`int`, *optional*, defaults to 3072):
  39. Dimensionality of the "intermediate" (often named feed-forward) layer in the Transformer encoder.
  40. hidden_act (`str` or `Callable`, *optional*, defaults to `"gelu"`):
  41. The non-linear activation function (function or string) in the encoder and pooler. If string, `"gelu"`,
  42. `"relu"`, `"silu"` and `"gelu_new"` are supported.
  43. hidden_dropout_prob (`float`, *optional*, defaults to 0.1):
  44. The dropout probability for all fully connected layers in the embeddings, encoder, and pooler.
  45. attention_probs_dropout_prob (`float`, *optional*, defaults to 0.1):
  46. The dropout ratio for the attention probabilities.
  47. max_position_embeddings (`int`, *optional*, defaults to 512):
  48. The maximum sequence length that this model might ever be used with. Typically set this to something large
  49. just in case (e.g., 512 or 1024 or 2048).
  50. initializer_range (`float`, *optional*, defaults to 0.02):
  51. The standard deviation of the truncated_normal_initializer for initializing all weight matrices.
  52. layer_norm_eps (`float`, *optional*, defaults to 1e-12):
  53. The epsilon used by the layer normalization layers.
  54. relative_attention_num_buckets (`int`, *optional*, defaults to 32):
  55. The number of buckets to use for each attention layer.
  56. Examples:
  57. ```python
  58. >>> from transformers import MPNetModel, MPNetConfig
  59. >>> # Initializing a MPNet mpnet-base style configuration
  60. >>> configuration = MPNetConfig()
  61. >>> # Initializing a model from the mpnet-base style configuration
  62. >>> model = MPNetModel(configuration)
  63. >>> # Accessing the model configuration
  64. >>> configuration = model.config
  65. ```"""
  66. model_type = "mpnet"
  67. def __init__(
  68. self,
  69. vocab_size=30527,
  70. hidden_size=768,
  71. num_hidden_layers=12,
  72. num_attention_heads=12,
  73. intermediate_size=3072,
  74. hidden_act="gelu",
  75. hidden_dropout_prob=0.1,
  76. attention_probs_dropout_prob=0.1,
  77. max_position_embeddings=512,
  78. initializer_range=0.02,
  79. layer_norm_eps=1e-12,
  80. relative_attention_num_buckets=32,
  81. pad_token_id=1,
  82. bos_token_id=0,
  83. eos_token_id=2,
  84. **kwargs,
  85. ):
  86. super().__init__(pad_token_id=pad_token_id, bos_token_id=bos_token_id, eos_token_id=eos_token_id, **kwargs)
  87. self.vocab_size = vocab_size
  88. self.hidden_size = hidden_size
  89. self.num_hidden_layers = num_hidden_layers
  90. self.num_attention_heads = num_attention_heads
  91. self.hidden_act = hidden_act
  92. self.intermediate_size = intermediate_size
  93. self.hidden_dropout_prob = hidden_dropout_prob
  94. self.attention_probs_dropout_prob = attention_probs_dropout_prob
  95. self.max_position_embeddings = max_position_embeddings
  96. self.initializer_range = initializer_range
  97. self.layer_norm_eps = layer_norm_eps
  98. self.relative_attention_num_buckets = relative_attention_num_buckets
  99. __all__ = ["MPNetConfig"]