configuration_flaubert.py 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  1. # Copyright 2019-present CNRS, Facebook Inc. and the HuggingFace Inc. team.
  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. """Flaubert configuration"""
  15. from huggingface_hub.dataclasses import strict
  16. from ...configuration_utils import PreTrainedConfig
  17. from ...utils import auto_docstring
  18. @auto_docstring(checkpoint="flaubert/flaubert_base_uncased")
  19. @strict
  20. class FlaubertConfig(PreTrainedConfig):
  21. r"""
  22. pre_norm (`bool`, *optional*, defaults to `False`):
  23. Whether to apply the layer normalization before or after the feed forward layer following the attention in
  24. each layer (Vaswani et al., Tensor2Tensor for Neural Machine Translation. 2018)
  25. emb_dim (`int`, *optional*, defaults to 2048):
  26. The dimensionality of embedding layer.
  27. gelu_activation (`bool`, *optional*, defaults to True):
  28. Whether to use GeLU activation function.
  29. sinusoidal_embeddings (`bool`, *optional*, defaults to `False`):
  30. Whether or not to use sinusoidal positional embeddings instead of absolute positional embeddings.
  31. causal (`bool`, *optional*, defaults to `False`):
  32. Whether or not the model should behave in a causal manner. Causal models use a triangular attention mask in
  33. order to only attend to the left-side context instead if a bidirectional context.
  34. asm (`bool`, *optional*, defaults to `False`):
  35. Whether or not to use an adaptive log softmax projection layer instead of a linear layer for the prediction
  36. layer.
  37. n_langs (`int`, *optional*, defaults to 1):
  38. The number of languages the model handles. Set to 1 for monolingual models.
  39. use_lang_emb (`bool`, *optional*, defaults to `True`)
  40. Whether to use language embeddings. Some models use additional language embeddings, see [the multilingual
  41. models page](http://huggingface.co/transformers/multilingual.html#xlm-language-embeddings) for information
  42. on how to use them.
  43. embed_init_std (`float`, *optional*, defaults to 2048^-0.5):
  44. The standard deviation of the truncated_normal_initializer for initializing the embedding matrices.
  45. embed_init_std (`float`, *optional*, defaults to `2048**-0.5`):
  46. Initializer std for embedding layers.
  47. bos_index (`int`, *optional*, defaults to 0):
  48. The index of the beginning of sentence token in the vocabulary.
  49. eos_index (`int`, *optional*, defaults to 1):
  50. The index of the end of sentence token in the vocabulary.
  51. pad_index (`int`, *optional*, defaults to 2):
  52. The index of the padding token in the vocabulary.
  53. unk_index (`int`, *optional*, defaults to 3):
  54. The index of the unknown token in the vocabulary.
  55. mask_index (`int`, *optional*, defaults to 5):
  56. The index of the masking token in the vocabulary.
  57. is_encoder (`bool`, *optional*, defaults to True):
  58. Whether the model is used as an encoder.
  59. summary_type (`string`, *optional*, defaults to "first"):
  60. Argument used when doing sequence summary. Used in the sequence classification and multiple choice models.
  61. Has to be one of the following options:
  62. - `"last"`: Take the last token hidden state (like XLNet).
  63. - `"first"`: Take the first token hidden state (like BERT).
  64. - `"mean"`: Take the mean of all tokens hidden states.
  65. - `"cls_index"`: Supply a Tensor of classification token position (like GPT/GPT-2).
  66. - `"attn"`: Not implemented now, use multi-head attention.
  67. summary_use_proj (`bool`, *optional*, defaults to `True`):
  68. Argument used when doing sequence summary. Used in the sequence classification and multiple choice models.
  69. Whether or not to add a projection after the vector extraction.
  70. summary_activation (`str`, *optional*):
  71. Argument used when doing sequence summary. Used in the sequence classification and multiple choice models.
  72. Pass `"tanh"` for a tanh activation to the output, any other value will result in no activation.
  73. summary_proj_to_labels (`bool`, *optional*, defaults to `True`):
  74. Used in the sequence classification and multiple choice models.
  75. Whether the projection outputs should have `config.num_labels` or `config.hidden_size` classes.
  76. summary_first_dropout (`float`, *optional*, defaults to 0.1):
  77. Used in the sequence classification and multiple choice models.
  78. The dropout ratio to be used after the projection and activation.
  79. start_n_top (`int`, *optional*, defaults to 5):
  80. Used in the SQuAD evaluation script.
  81. end_n_top (`int`, *optional*, defaults to 5):
  82. Used in the SQuAD evaluation script.
  83. mask_token_id (`int`, *optional*, defaults to 0):
  84. Model agnostic parameter to identify masked tokens when generating text in an MLM context.
  85. lang_id (`int`, *optional*, defaults to 1):
  86. The ID of the language used by the model. This parameter is used when generating text in a given language.
  87. """
  88. model_type = "flaubert"
  89. attribute_map = {
  90. "hidden_size": "emb_dim",
  91. "num_attention_heads": "n_heads",
  92. "num_hidden_layers": "n_layers",
  93. "n_words": "vocab_size", # For backward compatibility
  94. "bos_index": "bos_token_id",
  95. "eos_index": "eos_token_id",
  96. "pad_index": "pad_token_id",
  97. }
  98. pre_norm: bool = False
  99. layerdrop: float | int = 0.0
  100. vocab_size: int = 30145
  101. emb_dim: int = 2048
  102. n_layers: int = 12
  103. n_heads: int = 16
  104. dropout: float | int = 0.1
  105. attention_dropout: float | int = 0.1
  106. gelu_activation: bool = True
  107. sinusoidal_embeddings: bool = False
  108. causal: bool = False
  109. asm: bool = False
  110. n_langs: int = 1
  111. use_lang_emb: bool = True
  112. max_position_embeddings: int = 512
  113. embed_init_std: float = 2048**-0.5
  114. layer_norm_eps: float = 1e-12
  115. init_std: float = 0.02
  116. bos_index: int = 0
  117. eos_index: int = 1
  118. pad_index: int = 2
  119. unk_index: int = 3
  120. mask_index: int = 5
  121. is_encoder: bool = True
  122. summary_type: str = "first"
  123. summary_use_proj: bool = True
  124. summary_activation: str | None = None
  125. summary_proj_to_labels: bool = True
  126. summary_first_dropout: float | int = 0.1
  127. start_n_top: int = 5
  128. end_n_top: int = 5
  129. mask_token_id: int = 0
  130. lang_id: int = 0
  131. pad_token_id: int | None = 2
  132. bos_token_id: int | None = 0
  133. eos_token_id: int | list[int] | None = 1
  134. tie_word_embeddings: bool = True
  135. __all__ = ["FlaubertConfig"]