configuration_openai.py 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. # Copyright 2018 The OpenAI Team Authors and 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. """OpenAI GPT configuration"""
  16. from huggingface_hub.dataclasses import strict
  17. from ...configuration_utils import PreTrainedConfig
  18. from ...utils import auto_docstring
  19. @auto_docstring(checkpoint="openai-community/openai-gpt")
  20. @strict
  21. class OpenAIGPTConfig(PreTrainedConfig):
  22. r"""
  23. afn (`str` or `Callable`, *optional*, defaults to `"gelu"`):
  24. The non-linear activation function (function or string) in the encoder and pooler. If string, `"gelu"`,
  25. `"relu"`, `"silu"` and `"gelu_new"` are supported.
  26. layer_norm_epsilon (`float`, *optional*, defaults to 1e-05):
  27. The epsilon to use in the layer normalization layers
  28. summary_type (`str`, *optional*, defaults to `"cls_index"`):
  29. Argument used when doing sequence summary, used in the models [`OpenAIGPTDoubleHeadsModel`] and
  30. [`OpenAIGPTDoubleHeadsModel`].
  31. Has to be one of the following options:
  32. - `"last"`: Take the last token hidden state (like XLNet).
  33. - `"first"`: Take the first token hidden state (like BERT).
  34. - `"mean"`: Take the mean of all tokens hidden states.
  35. - `"cls_index"`: Supply a Tensor of classification token position (like GPT/GPT-2).
  36. - `"attn"`: Not implemented now, use multi-head attention.
  37. summary_use_proj (`bool`, *optional*, defaults to `True`):
  38. Argument used when doing sequence summary, used in the models [`OpenAIGPTDoubleHeadsModel`] and
  39. [`OpenAIGPTDoubleHeadsModel`].
  40. Whether or not to add a projection after the vector extraction.
  41. summary_activation (`str`, *optional*):
  42. Argument used when doing sequence summary, used in the models [`OpenAIGPTDoubleHeadsModel`] and
  43. [`OpenAIGPTDoubleHeadsModel`].
  44. Pass `"tanh"` for a tanh activation to the output, any other value will result in no activation.
  45. summary_proj_to_labels (`bool`, *optional*, defaults to `True`):
  46. Argument used when doing sequence summary, used in the models [`OpenAIGPTDoubleHeadsModel`] and
  47. [`OpenAIGPTDoubleHeadsModel`].
  48. Whether the projection outputs should have `config.num_labels` or `config.hidden_size` classes.
  49. summary_first_dropout (`float`, *optional*, defaults to 0.1):
  50. Argument used when doing sequence summary, used in the models [`OpenAIGPTDoubleHeadsModel`] and
  51. [`OpenAIGPTDoubleHeadsModel`].
  52. The dropout ratio to be used after the projection and activation.
  53. Examples:
  54. ```python
  55. >>> from transformers import OpenAIGPTConfig, OpenAIGPTModel
  56. >>> # Initializing a GPT configuration
  57. >>> configuration = OpenAIGPTConfig()
  58. >>> # Initializing a model (with random weights) from the configuration
  59. >>> model = OpenAIGPTModel(configuration)
  60. >>> # Accessing the model configuration
  61. >>> configuration = model.config
  62. ```"""
  63. model_type = "openai-gpt"
  64. attribute_map = {
  65. "max_position_embeddings": "n_positions",
  66. "hidden_size": "n_embd",
  67. "num_attention_heads": "n_head",
  68. "num_hidden_layers": "n_layer",
  69. }
  70. vocab_size: int = 40478
  71. n_positions: int = 512
  72. n_embd: int = 768
  73. n_layer: int = 12
  74. n_head: int = 12
  75. afn: str = "gelu"
  76. resid_pdrop: float | int = 0.1
  77. embd_pdrop: float | int = 0.1
  78. attn_pdrop: float | int = 0.1
  79. layer_norm_epsilon: float = 1e-5
  80. initializer_range: float = 0.02
  81. summary_type: str = "cls_index"
  82. summary_use_proj: bool = True
  83. summary_activation: str | None = None
  84. summary_proj_to_labels: bool = True
  85. summary_first_dropout: float | int = 0.1
  86. pad_token_id: int | None = None
  87. bos_token_id: int | None = None
  88. eos_token_id: int | list[int] | None = None
  89. tie_word_embeddings: bool = True
  90. __all__ = ["OpenAIGPTConfig"]