configuration_prophetnet.py 3.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. # Copyright 2020 The Microsoft Authors 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. """ProphetNet 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="microsoft/prophetnet-large-uncased")
  19. @strict
  20. class ProphetNetConfig(PreTrainedConfig):
  21. r"""
  22. ngram (`int`, *optional*, defaults to 2):
  23. Number of future tokens to predict. Set to 1 to be same as traditional Language model to predict next first
  24. token.
  25. num_buckets (`int`, *optional*, defaults to 32):
  26. The number of buckets to use for each attention layer. This is for relative position calculation. See the
  27. [T5 paper](see https://huggingface.co/papers/1910.10683) for more details.
  28. relative_max_distance (`int`, *optional*, defaults to 128):
  29. Relative distances greater than this number will be put into the last same bucket. This is for relative
  30. position calculation. See the [T5 paper](see https://huggingface.co/papers/1910.10683) for more details.
  31. disable_ngram_loss (`bool`, *optional*, defaults to `False`):
  32. Whether be trained predicting only the next first token.
  33. eps (`float`, *optional*, defaults to 0.0):
  34. Controls the `epsilon` parameter value for label smoothing in the loss calculation. If set to 0, no label
  35. smoothing is performed.
  36. """
  37. model_type = "prophetnet"
  38. keys_to_ignore_at_inference = ["past_key_values"]
  39. attribute_map = {
  40. "num_attention_heads": "num_encoder_attention_heads",
  41. }
  42. activation_dropout: float | int = 0.1
  43. activation_function: str = "gelu"
  44. vocab_size: int = 30522
  45. hidden_size: int = 1024
  46. encoder_ffn_dim: int = 4096
  47. num_encoder_layers: int = 12
  48. num_encoder_attention_heads: int = 16
  49. decoder_ffn_dim: int = 4096
  50. num_decoder_layers: int = 12
  51. num_decoder_attention_heads: int = 16
  52. attention_dropout: float | int = 0.1
  53. dropout: float | int = 0.1
  54. max_position_embeddings: int = 512
  55. init_std: float = 0.02
  56. is_encoder_decoder: bool = True
  57. add_cross_attention: bool = True
  58. decoder_start_token_id: int | None = 0
  59. ngram: int = 2
  60. num_buckets: int = 32
  61. relative_max_distance: int = 128
  62. disable_ngram_loss: bool = False
  63. eps: float = 0.0
  64. use_cache: bool = True
  65. pad_token_id: int | None = 0
  66. bos_token_id: int | None = 1
  67. eos_token_id: int | list[int] | None = 2
  68. is_decoder: bool = False
  69. tie_word_embeddings: bool = True
  70. @property
  71. def num_hidden_layers(self) -> int:
  72. return self.num_encoder_layers
  73. @num_hidden_layers.setter
  74. def num_hidden_layers(self, value):
  75. raise NotImplementedError(
  76. "This model does not support the setting of `num_hidden_layers`. Please set `num_encoder_layers` and"
  77. " `num_decoder_layers`."
  78. )
  79. __all__ = ["ProphetNetConfig"]