configuration_splinter.py 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. # coding=utf-8
  2. # Copyright 2021 Tel AViv University, AllenAI 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 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. """Splinter model configuration"""
  16. from ...configuration_utils import PretrainedConfig
  17. from ...utils import logging
  18. logger = logging.get_logger(__name__)
  19. class SplinterConfig(PretrainedConfig):
  20. r"""
  21. This is the configuration class to store the configuration of a [`SplinterModel`]. It is used to instantiate an
  22. Splinter 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 Splinter
  24. [tau/splinter-base](https://huggingface.co/tau/splinter-base) 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 30522):
  29. Vocabulary size of the Splinter model. Defines the number of different tokens that can be represented by
  30. the `inputs_ids` passed when calling [`SplinterModel`].
  31. hidden_size (`int`, *optional*, defaults to 768):
  32. Dimension of the encoder layers and the pooler layer.
  33. num_hidden_layers (`int`, *optional*, defaults to 12):
  34. Number of hidden layers in the Transformer encoder.
  35. num_attention_heads (`int`, *optional*, defaults to 12):
  36. Number of attention heads for each attention layer in the Transformer encoder.
  37. intermediate_size (`int`, *optional*, defaults to 3072):
  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 512):
  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. type_vocab_size (`int`, *optional*, defaults to 2):
  50. The vocabulary size of the `token_type_ids` passed when calling [`SplinterModel`].
  51. initializer_range (`float`, *optional*, defaults to 0.02):
  52. The standard deviation of the truncated_normal_initializer for initializing all weight matrices.
  53. layer_norm_eps (`float`, *optional*, defaults to 1e-12):
  54. The epsilon used by the layer normalization layers.
  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. question_token_id (`int`, *optional*, defaults to 104):
  59. The id of the `[QUESTION]` token.
  60. Example:
  61. ```python
  62. >>> from transformers import SplinterModel, SplinterConfig
  63. >>> # Initializing a Splinter tau/splinter-base style configuration
  64. >>> configuration = SplinterConfig()
  65. >>> # Initializing a model from the tau/splinter-base style configuration
  66. >>> model = SplinterModel(configuration)
  67. >>> # Accessing the model configuration
  68. >>> configuration = model.config
  69. ```"""
  70. model_type = "splinter"
  71. def __init__(
  72. self,
  73. vocab_size=30522,
  74. hidden_size=768,
  75. num_hidden_layers=12,
  76. num_attention_heads=12,
  77. intermediate_size=3072,
  78. hidden_act="gelu",
  79. hidden_dropout_prob=0.1,
  80. attention_probs_dropout_prob=0.1,
  81. max_position_embeddings=512,
  82. type_vocab_size=2,
  83. initializer_range=0.02,
  84. layer_norm_eps=1e-12,
  85. use_cache=True,
  86. pad_token_id=0,
  87. question_token_id=104,
  88. **kwargs,
  89. ):
  90. super().__init__(pad_token_id=pad_token_id, **kwargs)
  91. self.vocab_size = vocab_size
  92. self.max_position_embeddings = max_position_embeddings
  93. self.hidden_size = hidden_size
  94. self.num_hidden_layers = num_hidden_layers
  95. self.num_attention_heads = num_attention_heads
  96. self.intermediate_size = intermediate_size
  97. self.hidden_act = hidden_act
  98. self.hidden_dropout_prob = hidden_dropout_prob
  99. self.attention_probs_dropout_prob = attention_probs_dropout_prob
  100. self.initializer_range = initializer_range
  101. self.type_vocab_size = type_vocab_size
  102. self.layer_norm_eps = layer_norm_eps
  103. self.use_cache = use_cache
  104. self.question_token_id = question_token_id