configuration_biogpt.py 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. # coding=utf-8
  2. # Copyright 2022 The HuggingFace Team and Microsoft Research AI4Science 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 at
  7. #
  8. # http://www.apache.org/licenses/LICENSE-2.0
  9. #
  10. # Unless required by applicable law or agreed to in writing, software
  11. # 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 and
  14. # limitations under the License.
  15. """BioGPT model configuration"""
  16. from ...configuration_utils import PretrainedConfig
  17. from ...utils import logging
  18. logger = logging.get_logger(__name__)
  19. class BioGptConfig(PretrainedConfig):
  20. r"""
  21. This is the configuration class to store the configuration of a [`BioGptModel`]. It is used to instantiate an
  22. BioGPT model according to the specified arguments, defining the model architecture. Instantiating a configuration
  23. with the defaults will yield a similar configuration to that of the BioGPT
  24. [microsoft/biogpt](https://huggingface.co/microsoft/biogpt) architecture.
  25. Configuration objects inherit from [`PretrainedConfig`] and can be used to control the model outputs. Read the
  26. documentation from [`PretrainedConfig`] for more information.
  27. Args:
  28. vocab_size (`int`, *optional*, defaults to 42384):
  29. Vocabulary size of the BioGPT model. Defines the number of different tokens that can be represented by the
  30. `inputs_ids` passed when calling [`BioGptModel`].
  31. hidden_size (`int`, *optional*, defaults to 1024):
  32. Dimension of the encoder layers and the pooler layer.
  33. num_hidden_layers (`int`, *optional*, defaults to 24):
  34. Number of hidden layers in the Transformer encoder.
  35. num_attention_heads (`int`, *optional*, defaults to 16):
  36. Number of attention heads for each attention layer in the Transformer encoder.
  37. intermediate_size (`int`, *optional*, defaults to 4096):
  38. Dimension of the "intermediate" (i.e., feed-forward) layer in the Transformer encoder.
  39. hidden_act (`str` or `function`, *optional*, defaults to `"gelu"`):
  40. The non-linear activation function (function or string) in the encoder and pooler. If string, `"gelu"`,
  41. `"relu"`, `"selu"` and `"gelu_new"` are supported.
  42. hidden_dropout_prob (`float`, *optional*, defaults to 0.1):
  43. The dropout probability for all fully connected layers in the embeddings, encoder, and pooler.
  44. attention_probs_dropout_prob (`float`, *optional*, defaults to 0.1):
  45. The dropout ratio for the attention probabilities.
  46. max_position_embeddings (`int`, *optional*, defaults to 1024):
  47. The maximum sequence length that this model might ever be used with. Typically set this to something large
  48. just in case (e.g., 512 or 1024 or 2048).
  49. initializer_range (`float`, *optional*, defaults to 0.02):
  50. The standard deviation of the truncated_normal_initializer for initializing all weight matrices.
  51. layer_norm_eps (`float`, *optional*, defaults to 1e-12):
  52. The epsilon used by the layer normalization layers.
  53. scale_embedding (`bool`, *optional*, defaults to `True`):
  54. Scale embeddings by diving by sqrt(d_model).
  55. use_cache (`bool`, *optional*, defaults to `True`):
  56. Whether or not the model should return the last key/values attentions (not used by all models). Only
  57. relevant if `config.is_decoder=True`.
  58. layerdrop (`float`, *optional*, defaults to 0.0):
  59. Please refer to the paper about LayerDrop: https://huggingface.co/papers/1909.11556 for further details
  60. activation_dropout (`float`, *optional*, defaults to 0.0):
  61. The dropout ratio for activations inside the fully connected layer.
  62. pad_token_id (`int`, *optional*, defaults to 1):
  63. Padding token id.
  64. bos_token_id (`int`, *optional*, defaults to 0):
  65. Beginning of stream token id.
  66. eos_token_id (`int`, *optional*, defaults to 2):
  67. End of stream token id.
  68. Example:
  69. ```python
  70. >>> from transformers import BioGptModel, BioGptConfig
  71. >>> # Initializing a BioGPT microsoft/biogpt style configuration
  72. >>> configuration = BioGptConfig()
  73. >>> # Initializing a model from the microsoft/biogpt style configuration
  74. >>> model = BioGptModel(configuration)
  75. >>> # Accessing the model configuration
  76. >>> configuration = model.config
  77. ```"""
  78. model_type = "biogpt"
  79. def __init__(
  80. self,
  81. vocab_size=42384,
  82. hidden_size=1024,
  83. num_hidden_layers=24,
  84. num_attention_heads=16,
  85. intermediate_size=4096,
  86. hidden_act="gelu",
  87. hidden_dropout_prob=0.1,
  88. attention_probs_dropout_prob=0.1,
  89. max_position_embeddings=1024,
  90. initializer_range=0.02,
  91. layer_norm_eps=1e-12,
  92. scale_embedding=True,
  93. use_cache=True,
  94. layerdrop=0.0,
  95. activation_dropout=0.0,
  96. pad_token_id=1,
  97. bos_token_id=0,
  98. eos_token_id=2,
  99. **kwargs,
  100. ):
  101. self.vocab_size = vocab_size
  102. self.max_position_embeddings = max_position_embeddings
  103. self.hidden_size = hidden_size
  104. self.num_hidden_layers = num_hidden_layers
  105. self.num_attention_heads = num_attention_heads
  106. self.intermediate_size = intermediate_size
  107. self.hidden_act = hidden_act
  108. self.hidden_dropout_prob = hidden_dropout_prob
  109. self.attention_probs_dropout_prob = attention_probs_dropout_prob
  110. self.initializer_range = initializer_range
  111. self.layer_norm_eps = layer_norm_eps
  112. self.scale_embedding = scale_embedding
  113. self.use_cache = use_cache
  114. self.layerdrop = layerdrop
  115. self.activation_dropout = activation_dropout
  116. super().__init__(pad_token_id=pad_token_id, bos_token_id=bos_token_id, eos_token_id=eos_token_id, **kwargs)
  117. __all__ = ["BioGptConfig"]