configuration_fnet.py 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. # coding=utf-8
  2. # Copyright 2021 Google AI and The HuggingFace Inc. team. 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. """FNet model configuration"""
  16. from ...configuration_utils import PretrainedConfig
  17. from ...utils import logging
  18. logger = logging.get_logger(__name__)
  19. class FNetConfig(PretrainedConfig):
  20. r"""
  21. This is the configuration class to store the configuration of a [`FNetModel`]. It is used to instantiate an FNet
  22. model according to the specified arguments, defining the model architecture. Instantiating a configuration with the
  23. defaults will yield a similar configuration to that of the FNet
  24. [google/fnet-base](https://huggingface.co/google/fnet-base) architecture.
  25. Configuration objects inherit from [`PretrainedConfig`] and can be used to control the model outputs. Read the
  26. documentation from [`PretrainedConfig`] for more information.
  27. Args:
  28. vocab_size (`int`, *optional*, defaults to 32000):
  29. Vocabulary size of the FNet model. Defines the number of different tokens that can be represented by the
  30. `inputs_ids` passed when calling [`FNetModel`] or [`TFFNetModel`].
  31. hidden_size (`int`, *optional*, defaults to 768):
  32. Dimension of the encoder layers and the pooler layer.
  33. num_hidden_layers (`int`, *optional*, defaults to 12):
  34. Number of hidden layers in the Transformer encoder.
  35. intermediate_size (`int`, *optional*, defaults to 3072):
  36. Dimension of the "intermediate" (i.e., feed-forward) layer in the Transformer encoder.
  37. hidden_act (`str` or `function`, *optional*, defaults to `"gelu_new"`):
  38. The non-linear activation function (function or string) in the encoder and pooler. If string, `"gelu"`,
  39. `"relu"`, `"selu"` and `"gelu_new"` are supported.
  40. hidden_dropout_prob (`float`, *optional*, defaults to 0.1):
  41. The dropout probability for all fully connected layers in the embeddings, encoder, and pooler.
  42. max_position_embeddings (`int`, *optional*, defaults to 512):
  43. The maximum sequence length that this model might ever be used with. Typically set this to something large
  44. just in case (e.g., 512 or 1024 or 2048).
  45. type_vocab_size (`int`, *optional*, defaults to 4):
  46. The vocabulary size of the `token_type_ids` passed when calling [`FNetModel`] or [`TFFNetModel`].
  47. initializer_range (`float`, *optional*, defaults to 0.02):
  48. The standard deviation of the truncated_normal_initializer for initializing all weight matrices.
  49. layer_norm_eps (`float`, *optional*, defaults to 1e-12):
  50. The epsilon used by the layer normalization layers.
  51. use_tpu_fourier_optimizations (`bool`, *optional*, defaults to `False`):
  52. Determines whether to use TPU optimized FFTs. If `True`, the model will favor axis-wise FFTs transforms.
  53. Set to `False` for GPU/CPU hardware, in which case n-dimensional FFTs are used.
  54. tpu_short_seq_length (`int`, *optional*, defaults to 512):
  55. The sequence length that is expected by the model when using TPUs. This will be used to initialize the DFT
  56. matrix only when *use_tpu_fourier_optimizations* is set to `True` and the input sequence is shorter than or
  57. equal to 4096 tokens.
  58. Example:
  59. ```python
  60. >>> from transformers import FNetConfig, FNetModel
  61. >>> # Initializing a FNet fnet-base style configuration
  62. >>> configuration = FNetConfig()
  63. >>> # Initializing a model (with random weights) from the fnet-base style configuration
  64. >>> model = FNetModel(configuration)
  65. >>> # Accessing the model configuration
  66. >>> configuration = model.config
  67. ```"""
  68. model_type = "fnet"
  69. def __init__(
  70. self,
  71. vocab_size=32000,
  72. hidden_size=768,
  73. num_hidden_layers=12,
  74. intermediate_size=3072,
  75. hidden_act="gelu_new",
  76. hidden_dropout_prob=0.1,
  77. max_position_embeddings=512,
  78. type_vocab_size=4,
  79. initializer_range=0.02,
  80. layer_norm_eps=1e-12,
  81. use_tpu_fourier_optimizations=False,
  82. tpu_short_seq_length=512,
  83. pad_token_id=3,
  84. bos_token_id=1,
  85. eos_token_id=2,
  86. **kwargs,
  87. ):
  88. super().__init__(pad_token_id=pad_token_id, bos_token_id=bos_token_id, eos_token_id=eos_token_id, **kwargs)
  89. self.vocab_size = vocab_size
  90. self.max_position_embeddings = max_position_embeddings
  91. self.hidden_size = hidden_size
  92. self.num_hidden_layers = num_hidden_layers
  93. self.intermediate_size = intermediate_size
  94. self.hidden_act = hidden_act
  95. self.hidden_dropout_prob = hidden_dropout_prob
  96. self.initializer_range = initializer_range
  97. self.type_vocab_size = type_vocab_size
  98. self.layer_norm_eps = layer_norm_eps
  99. self.use_tpu_fourier_optimizations = use_tpu_fourier_optimizations
  100. self.tpu_short_seq_length = tpu_short_seq_length