configuration.py 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. # Copyright 2021-2022 The Alibaba DAMO NLP Team Authors.
  2. # Copyright 2018 The Google AI Language Team Authors and The HuggingFace Inc. team.
  3. # Copyright (c) 2018, NVIDIA CORPORATION. All rights reserved.
  4. #
  5. # Licensed under the Apache License, Version 2.0 (the "License");
  6. # you may not use this file except in compliance with the License.
  7. # You may obtain a copy of the License at
  8. #
  9. # http://www.apache.org/licenses/LICENSE-2.0
  10. #
  11. # Unless required by applicable law or agreed to in writing, software
  12. # distributed under the License is distributed on an "AS IS" BASIS,
  13. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  14. # See the License for the specific language governing permissions and
  15. # limitations under the License.
  16. """ PLUG model configuration """
  17. from transformers.configuration_utils import PretrainedConfig
  18. class PlugConfig(PretrainedConfig):
  19. r"""
  20. Configuration objects inherit from :class:`~transformers.PretrainedConfig` and can be used to control the model
  21. outputs. Read the documentation from :class:`~transformers.PretrainedConfig` for more information.
  22. Args:
  23. vocab_size (:obj:`int`, `optional`, defaults to 30522):
  24. Vocabulary size of the BERT model. Defines the number of different tokens that can be represented by the
  25. :obj:`inputs_ids` passed when calling :class:`~transformers.BertModel` or
  26. :class:`~transformers.TFBertModel`.
  27. hidden_size (:obj:`int`, `optional`, defaults to 768):
  28. Dimensionality of the encoder layers and the pooler layer.
  29. num_hidden_layers (:obj:`int`, `optional`, defaults to 12):
  30. Number of hidden layers in the Transformer encoder.
  31. num_attention_heads (:obj:`int`, `optional`, defaults to 12):
  32. Number of attention heads for each attention layer in the Transformer encoder.
  33. intermediate_size (:obj:`int`, `optional`, defaults to 3072):
  34. Dimensionality of the "intermediate" (often named feed-forward) layer in the Transformer encoder.
  35. hidden_act (:obj:`str` or :obj:`Callable`, `optional`, defaults to :obj:`"gelu"`):
  36. The non-linear activation function (function or string) in the encoder and pooler. If string,
  37. :obj:`"gelu"`, :obj:`"relu"`, :obj:`"silu"` and :obj:`"gelu_new"` are supported.
  38. hidden_dropout_prob (:obj:`float`, `optional`, defaults to 0.1):
  39. The dropout probability for all fully connected layers in the embeddings, encoder, and pooler.
  40. attention_probs_dropout_prob (:obj:`float`, `optional`, defaults to 0.1):
  41. The dropout ratio for the attention probabilities.
  42. max_position_embeddings (:obj:`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 (:obj:`int`, `optional`, defaults to 2):
  46. The vocabulary size of the :obj:`token_type_ids` passed when calling :class:`~transformers.BertModel` or
  47. :class:`~transformers.TFBertModel`.
  48. initializer_range (:obj:`float`, `optional`, defaults to 0.02):
  49. The standard deviation of the truncated_normal_initializer for initializing all weight matrices.
  50. layernorm_epsilon (:obj:`float`, `optional`, defaults to 1e-12):
  51. The epsilon used by the layer normalization layers.
  52. dec_hidden_layers (:obj:`int`, `optional`, defaults to 12):
  53. Number of hidden layers in the Transformer decoder.
  54. attn_separate (:obj:`bool`, `optional`, defaults to false):
  55. Whether or not to separate the q, k, v of attention.
  56. Examples::
  57. >>> import PlugModel, PlugConfig
  58. >>> configuration = PlugConfig()
  59. >>> # Initializing a model from the configuration
  60. >>> model = PlugModel(configuration)
  61. >>> # Accessing the model configuration
  62. >>> configuration = model.config
  63. """
  64. model_type = 'plug'
  65. def __init__(self,
  66. encoder='roberta',
  67. encoder_pth='roberta-base',
  68. max_pos=512,
  69. share_emb=False,
  70. dec_layers=12,
  71. dec_hidden_size=768,
  72. dec_heads=8,
  73. dec_ff_size=3072,
  74. dec_dropout=0.2,
  75. use_bert_emb=True,
  76. label_smoothing=0.1,
  77. block_trigram=False,
  78. **kwargs):
  79. super().__init__(**kwargs)
  80. self.encoder = encoder
  81. self.encoder_pth = encoder_pth
  82. self.max_pos = max_pos
  83. self.share_emb = share_emb
  84. self.dec_layers = dec_layers
  85. self.dec_hidden_size = dec_hidden_size
  86. self.dec_heads = dec_heads
  87. self.dec_ff_size = dec_ff_size
  88. self.dec_dropout = dec_dropout
  89. self.use_bert_emb = use_bert_emb
  90. self.label_smoothing = label_smoothing
  91. # Translator
  92. self.block_trigram = block_trigram