configuration_deberta.py 3.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. # Copyright 2020, Microsoft and the HuggingFace Inc. team.
  2. #
  3. # Licensed under the Apache License, Version 2.0 (the "License");
  4. # you may not use this file except in compliance with the License.
  5. # You may obtain a copy of the License at
  6. #
  7. # http://www.apache.org/licenses/LICENSE-2.0
  8. #
  9. # Unless required by applicable law or agreed to in writing, software
  10. # distributed under the License is distributed on an "AS IS" BASIS,
  11. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. # See the License for the specific language governing permissions and
  13. # limitations under the License.
  14. """DeBERTa model configuration"""
  15. from huggingface_hub.dataclasses import strict
  16. from ...configuration_utils import PreTrainedConfig
  17. from ...utils import auto_docstring
  18. @auto_docstring(checkpoint="microsoft/deberta-base")
  19. @strict
  20. class DebertaConfig(PreTrainedConfig):
  21. r"""
  22. relative_attention (`bool`, *optional*, defaults to `False`):
  23. Whether use relative position encoding.
  24. max_relative_positions (`int`, *optional*, defaults to -1):
  25. The range of relative positions `[-max_position_embeddings, max_position_embeddings]`. Use the same value
  26. as `max_position_embeddings`.
  27. position_biased_input (`bool`, *optional*, defaults to `True`):
  28. Whether add absolute position embedding to content embedding.
  29. pos_att_type (`list[str]`, *optional*):
  30. The type of relative position attention, it can be a combination of `["p2c", "c2p"]`, e.g. `["p2c"]`,
  31. `["p2c", "c2p"]`.
  32. pooler_dropout (`float`, *optional*, defaults to `0`):
  33. Dropout rate in the pooler module.
  34. pooler_hidden_act (`str`, *optional*, defaults to `"gelu"`):
  35. Activation function used in the dropout module.
  36. legacy (`bool`, *optional*, defaults to `True`):
  37. Whether or not the model should use the legacy `LegacyDebertaOnlyMLMHead`, which does not work properly
  38. for mask infilling tasks.
  39. Example:
  40. ```python
  41. >>> from transformers import DebertaConfig, DebertaModel
  42. >>> # Initializing a DeBERTa microsoft/deberta-base style configuration
  43. >>> configuration = DebertaConfig()
  44. >>> # Initializing a model (with random weights) from the microsoft/deberta-base style configuration
  45. >>> model = DebertaModel(configuration)
  46. >>> # Accessing the model configuration
  47. >>> configuration = model.config
  48. ```"""
  49. model_type = "deberta"
  50. vocab_size: int = 50265
  51. hidden_size: int = 768
  52. num_hidden_layers: int = 12
  53. num_attention_heads: int = 12
  54. intermediate_size: int = 3072
  55. hidden_act: str = "gelu"
  56. hidden_dropout_prob: float | int = 0.1
  57. attention_probs_dropout_prob: float | int = 0.1
  58. max_position_embeddings: int = 512
  59. type_vocab_size: int = 0
  60. initializer_range: float = 0.02
  61. layer_norm_eps: float = 1e-7
  62. relative_attention: bool = False
  63. max_relative_positions: int = -1
  64. pad_token_id: int | None = 0
  65. bos_token_id: int | None = None
  66. eos_token_id: int | list[int] | None = None
  67. position_biased_input: bool = True
  68. pos_att_type: str | list[str] | None = None
  69. pooler_dropout: float | int = 0.0
  70. pooler_hidden_act: str = "gelu"
  71. legacy: bool = True
  72. tie_word_embeddings: bool = True
  73. def __post_init__(self, **kwargs):
  74. # Backwards compatibility
  75. if isinstance(self.pos_att_type, str):
  76. self.pos_att_type = [x.strip() for x in self.pos_att_type.lower().split("|")]
  77. self.pooler_hidden_size = kwargs.get("pooler_hidden_size", self.hidden_size)
  78. super().__post_init__(**kwargs)
  79. __all__ = ["DebertaConfig"]