configuration_electra.py 3.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  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. """ELECTRA 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/electra-small-discriminator")
  20. @strict
  21. class ElectraConfig(PreTrainedConfig):
  22. r"""
  23. summary_type (`str`, *optional*, defaults to `"first"`):
  24. Argument used when doing sequence summary. Used in the sequence classification and multiple choice models.
  25. Has to be one of the following options:
  26. - `"last"`: Take the last token hidden state (like XLNet).
  27. - `"first"`: Take the first token hidden state (like BERT).
  28. - `"mean"`: Take the mean of all tokens hidden states.
  29. - `"cls_index"`: Supply a Tensor of classification token position (like GPT/GPT-2).
  30. - `"attn"`: Not implemented now, use multi-head attention.
  31. summary_use_proj (`bool`, *optional*, defaults to `True`):
  32. Argument used when doing sequence summary. Used in the sequence classification and multiple choice models.
  33. Whether or not to add a projection after the vector extraction.
  34. summary_activation (`str`, *optional*):
  35. Argument used when doing sequence summary. Used in the sequence classification and multiple choice models.
  36. Pass `"gelu"` for a gelu activation to the output, any other value will result in no activation.
  37. summary_last_dropout (`float`, *optional*, defaults to 0.0):
  38. Argument used when doing sequence summary. Used in the sequence classification and multiple choice models.
  39. The dropout ratio to be used after the projection and activation.
  40. Examples:
  41. ```python
  42. >>> from transformers import ElectraConfig, ElectraModel
  43. >>> # Initializing a ELECTRA electra-base-uncased style configuration
  44. >>> configuration = ElectraConfig()
  45. >>> # Initializing a model (with random weights) from the electra-base-uncased style configuration
  46. >>> model = ElectraModel(configuration)
  47. >>> # Accessing the model configuration
  48. >>> configuration = model.config
  49. ```"""
  50. model_type = "electra"
  51. vocab_size: int = 30522
  52. embedding_size: int = 128
  53. hidden_size: int = 256
  54. num_hidden_layers: int = 12
  55. num_attention_heads: int = 4
  56. intermediate_size: int = 1024
  57. hidden_act: str = "gelu"
  58. hidden_dropout_prob: float | int = 0.1
  59. attention_probs_dropout_prob: float | int = 0.1
  60. max_position_embeddings: int = 512
  61. type_vocab_size: int = 2
  62. initializer_range: float = 0.02
  63. layer_norm_eps: float = 1e-12
  64. summary_type: str = "first"
  65. summary_use_proj: bool = True
  66. summary_activation: str = "gelu"
  67. summary_last_dropout: float | int = 0.1
  68. pad_token_id: int | None = 0
  69. use_cache: bool = True
  70. classifier_dropout: float | int | None = None
  71. is_decoder: bool = False
  72. add_cross_attention: bool = False
  73. bos_token_id: int | None = None
  74. eos_token_id: int | list[int] | None = None
  75. tie_word_embeddings: bool = True
  76. __all__ = ["ElectraConfig"]