Constructs BertConfig. Args: vocab_size_or_config_json_file: Vocabulary size of `inputs_ids` in `BertModel`. hidden_size: Size of the encoder layers and the pooler layer. num_hidden_layers: Number of hidden layers in the Transformer encoder. n
(self,
vocab_size_or_config_json_file,
hidden_size=768,
num_hidden_layers=12,
num_attention_heads=12,
intermediate_size=3072,
batch_size=8,
hidden_act="gelu",
hidden_dropout_prob=0.1,
attention_probs_dropout_prob=0.1,
max_position_embeddings=512,
type_vocab_size=2,
initializer_range=0.02,
fp16=False)
| 147 | """ |
| 148 | |
| 149 | def __init__(self, |
| 150 | vocab_size_or_config_json_file, |
| 151 | hidden_size=768, |
| 152 | num_hidden_layers=12, |
| 153 | num_attention_heads=12, |
| 154 | intermediate_size=3072, |
| 155 | batch_size=8, |
| 156 | hidden_act="gelu", |
| 157 | hidden_dropout_prob=0.1, |
| 158 | attention_probs_dropout_prob=0.1, |
| 159 | max_position_embeddings=512, |
| 160 | type_vocab_size=2, |
| 161 | initializer_range=0.02, |
| 162 | fp16=False): |
| 163 | """Constructs BertConfig. |
| 164 | |
| 165 | Args: |
| 166 | vocab_size_or_config_json_file: Vocabulary size of `inputs_ids` in `BertModel`. |
| 167 | hidden_size: Size of the encoder layers and the pooler layer. |
| 168 | num_hidden_layers: Number of hidden layers in the Transformer encoder. |
| 169 | num_attention_heads: Number of attention heads for each attention layer in |
| 170 | the Transformer encoder. |
| 171 | intermediate_size: The size of the "intermediate" (i.e., feed-forward) |
| 172 | layer in the Transformer encoder. |
| 173 | hidden_act: The non-linear activation function (function or string) in the |
| 174 | encoder and pooler. If string, "gelu", "relu" and "swish" are supported. |
| 175 | hidden_dropout_prob: The dropout probability for all fully connected |
| 176 | layers in the embeddings, encoder, and pooler. |
| 177 | attention_probs_dropout_prob: The dropout ratio for the attention |
| 178 | probabilities. |
| 179 | max_position_embeddings: The maximum sequence length that this model might |
| 180 | ever be used with. Typically set this to something large just in case |
| 181 | (e.g., 512 or 1024 or 2048). |
| 182 | type_vocab_size: The vocabulary size of the `token_type_ids` passed into |
| 183 | `BertModel`. |
| 184 | initializer_range: The sttdev of the truncated_normal_initializer for |
| 185 | initializing all weight matrices. |
| 186 | """ |
| 187 | if isinstance(vocab_size_or_config_json_file, str): |
| 188 | with open(vocab_size_or_config_json_file, "r", encoding='utf-8') as reader: |
| 189 | json_config = json.loads(reader.read()) |
| 190 | self.__dict__.update(json_config) |
| 191 | elif isinstance(vocab_size_or_config_json_file, int): |
| 192 | self.vocab_size = vocab_size_or_config_json_file |
| 193 | self.hidden_size = hidden_size |
| 194 | self.num_hidden_layers = num_hidden_layers |
| 195 | self.num_attention_heads = num_attention_heads |
| 196 | self.batch_size = batch_size |
| 197 | self.hidden_act = hidden_act |
| 198 | self.intermediate_size = intermediate_size |
| 199 | self.hidden_dropout_prob = hidden_dropout_prob |
| 200 | self.attention_probs_dropout_prob = attention_probs_dropout_prob |
| 201 | self.max_position_embeddings = max_position_embeddings |
| 202 | self.type_vocab_size = type_vocab_size |
| 203 | self.initializer_range = initializer_range |
| 204 | self.fp16 = fp16 |
| 205 | else: |
| 206 | raise ValueError("First argument must be either a vocabulary size (int)" |