configuration_bart.py 2.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. # Copyright 2021 The Fairseq Authors 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. """BART 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="facebook/bart-large")
  19. @strict
  20. class BartConfig(PreTrainedConfig):
  21. r"""
  22. Example:
  23. ```python
  24. >>> from transformers import BartConfig, BartModel
  25. >>> # Initializing a BART facebook/bart-large style configuration
  26. >>> configuration = BartConfig()
  27. >>> # Initializing a model (with random weights) from the facebook/bart-large style configuration
  28. >>> model = BartModel(configuration)
  29. >>> # Accessing the model configuration
  30. >>> configuration = model.config
  31. ```"""
  32. model_type = "bart"
  33. keys_to_ignore_at_inference = ["past_key_values"]
  34. attribute_map = {
  35. "num_attention_heads": "encoder_attention_heads",
  36. "hidden_size": "d_model",
  37. "num_hidden_layers": "encoder_layers",
  38. }
  39. vocab_size: int = 50265
  40. max_position_embeddings: int = 1024
  41. encoder_layers: int | None = 12
  42. encoder_ffn_dim: int | None = 4096
  43. encoder_attention_heads: int | None = 16
  44. decoder_layers: int | None = 12
  45. decoder_ffn_dim: int | None = 4096
  46. decoder_attention_heads: int | None = 16
  47. encoder_layerdrop: float | None = 0.0
  48. decoder_layerdrop: float | None = 0.0
  49. activation_function: str | None = "gelu"
  50. d_model: int | None = 1024
  51. dropout: float | int | None = 0.1
  52. attention_dropout: float | int | None = 0.0
  53. activation_dropout: float | int | None = 0.0
  54. init_std: float | None = 0.02
  55. classifier_dropout: float | int | None = 0.0
  56. scale_embedding: bool | None = False
  57. use_cache: bool = True
  58. pad_token_id: int | None = 1
  59. bos_token_id: int | None = 0
  60. eos_token_id: int | list[int] | None = 2
  61. is_encoder_decoder: bool | None = True
  62. decoder_start_token_id: int | None = 2
  63. forced_eos_token_id: int | list[int] | None = 2
  64. is_decoder: bool | None = False
  65. tie_word_embeddings: bool = True
  66. def __post_init__(self, **kwargs):
  67. # Set the default `num_labels` only if `id2label` is not
  68. # yet set, i.e. user didn't pass `id2label/lable2id` in kwargs
  69. if self.id2label is None:
  70. self.num_labels = kwargs.pop("num_labels", 3)
  71. super().__post_init__(**kwargs)
  72. __all__ = ["BartConfig"]