configuration_distilbert.py 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. # Copyright 2019-present, the HuggingFace Inc. team, The Google AI Language Team and Facebook, Inc.
  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. """DistilBERT 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="google/distilbert-base-uncased")
  19. @strict
  20. class DistilBertConfig(PreTrainedConfig):
  21. r"""
  22. sinusoidal_pos_embds (`boolean`, *optional*, defaults to `False`):
  23. Whether to use sinusoidal positional embeddings.
  24. dim (`int`, *optional*, defaults to 768):
  25. Dimensionality of the encoder layers and the pooler layer.
  26. qa_dropout (`float`, *optional*, defaults to 0.1):
  27. The dropout probabilities used in the question answering model [`DistilBertForQuestionAnswering`].
  28. seq_classif_dropout (`float`, *optional*, defaults to 0.2):
  29. The dropout probabilities used in the sequence classification and the multiple choice model
  30. [`DistilBertForSequenceClassification`].
  31. Examples:
  32. ```python
  33. >>> from transformers import DistilBertConfig, DistilBertModel
  34. >>> # Initializing a DistilBERT configuration
  35. >>> configuration = DistilBertConfig()
  36. >>> # Initializing a model (with random weights) from the configuration
  37. >>> model = DistilBertModel(configuration)
  38. >>> # Accessing the model configuration
  39. >>> configuration = model.config
  40. ```"""
  41. model_type = "distilbert"
  42. attribute_map = {
  43. "hidden_size": "dim",
  44. "num_attention_heads": "n_heads",
  45. "num_hidden_layers": "n_layers",
  46. }
  47. vocab_size: int = 30522
  48. max_position_embeddings: int = 512
  49. sinusoidal_pos_embds: bool = False
  50. n_layers: int = 6
  51. n_heads: int = 12
  52. dim: int = 768
  53. hidden_dim: int = 4 * 768
  54. dropout: float | int = 0.1
  55. attention_dropout: float | int = 0.1
  56. activation: str = "gelu"
  57. initializer_range: float = 0.02
  58. qa_dropout: float | int = 0.1
  59. seq_classif_dropout: float | int = 0.2
  60. pad_token_id: int | None = 0
  61. eos_token_id: int | list[int] | None = None
  62. bos_token_id: int | None = None
  63. tie_word_embeddings: bool = True
  64. __all__ = ["DistilBertConfig"]