configuration_canine.py 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. # Copyright Google AI and The HuggingFace Inc. team. All rights reserved.
  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. """CANINE 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/canine-s")
  19. @strict
  20. class CanineConfig(PreTrainedConfig):
  21. r"""
  22. downsampling_rate (`int`, *optional*, defaults to 4):
  23. The rate at which to downsample the original character sequence length before applying the deep Transformer
  24. encoder.
  25. upsampling_kernel_size (`int`, *optional*, defaults to 4):
  26. The kernel size (i.e. the number of characters in each window) of the convolutional projection layer when
  27. projecting back from `hidden_size`*2 to `hidden_size`.
  28. num_hash_functions (`int`, *optional*, defaults to 8):
  29. The number of hash functions to use. Each hash function has its own embedding matrix.
  30. num_hash_buckets (`int`, *optional*, defaults to 16384):
  31. The number of hash buckets to use.
  32. local_transformer_stride (`int`, *optional*, defaults to 128):
  33. The stride of the local attention of the first shallow Transformer encoder. Defaults to 128 for good
  34. TPU/XLA memory alignment.
  35. Example:
  36. ```python
  37. >>> from transformers import CanineConfig, CanineModel
  38. >>> # Initializing a CANINE google/canine-s style configuration
  39. >>> configuration = CanineConfig()
  40. >>> # Initializing a model (with random weights) from the google/canine-s style configuration
  41. >>> model = CanineModel(configuration)
  42. >>> # Accessing the model configuration
  43. >>> configuration = model.config
  44. ```"""
  45. model_type = "canine"
  46. hidden_size: int = 768
  47. num_hidden_layers: int = 12
  48. num_attention_heads: int = 12
  49. intermediate_size: int = 3072
  50. hidden_act: str = "gelu"
  51. hidden_dropout_prob: float | int = 0.1
  52. attention_probs_dropout_prob: float | int = 0.1
  53. max_position_embeddings: int = 16384
  54. type_vocab_size: int = 16
  55. initializer_range: float = 0.02
  56. layer_norm_eps: float = 1e-12
  57. pad_token_id: int | None = 0
  58. bos_token_id: int | None = 0xE000
  59. eos_token_id: int | list[int] | None = 0xE001
  60. downsampling_rate: int = 4
  61. upsampling_kernel_size: int = 4
  62. num_hash_functions: int = 8
  63. num_hash_buckets: int = 16384
  64. local_transformer_stride: int = 128 # Good TPU/XLA memory alignment
  65. __all__ = ["CanineConfig"]