configuration_bert.py 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. # Copyright 2018 The Google AI Language Team Authors and The HuggingFace Inc. team.
  2. # Copyright (c) 2018, NVIDIA CORPORATION. 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. """BERT model configuration"""
  16. from huggingface_hub.dataclasses import strict
  17. from ...configuration_utils import PreTrainedConfig
  18. from ...utils import auto_docstring
  19. @auto_docstring(checkpoint="google-bert/bert-base-uncased")
  20. @strict
  21. class BertConfig(PreTrainedConfig):
  22. r"""
  23. Examples:
  24. ```python
  25. >>> from transformers import BertConfig, BertModel
  26. >>> # Initializing a BERT google-bert/bert-base-uncased style configuration
  27. >>> configuration = BertConfig()
  28. >>> # Initializing a model (with random weights) from the google-bert/bert-base-uncased style configuration
  29. >>> model = BertModel(configuration)
  30. >>> # Accessing the model configuration
  31. >>> configuration = model.config
  32. ```"""
  33. model_type = "bert"
  34. vocab_size: int = 30522
  35. hidden_size: int = 768
  36. num_hidden_layers: int = 12
  37. num_attention_heads: int = 12
  38. intermediate_size: int = 3072
  39. hidden_act: str = "gelu"
  40. hidden_dropout_prob: float | int = 0.1
  41. attention_probs_dropout_prob: float | int = 0.1
  42. max_position_embeddings: int = 512
  43. type_vocab_size: int = 2
  44. initializer_range: float = 0.02
  45. layer_norm_eps: float = 1e-12
  46. pad_token_id: int | None = 0
  47. use_cache: bool = True
  48. classifier_dropout: float | int | None = None
  49. is_decoder: bool = False
  50. add_cross_attention: bool = False
  51. bos_token_id: int | None = None
  52. eos_token_id: int | list[int] | None = None
  53. tie_word_embeddings: bool = True
  54. __all__ = ["BertConfig"]