MCPcopy Create free account
hub / github.com/THUDM/GLM / BertConfig

Class BertConfig

model/modeling_bert.py:166–262  ·  view source on GitHub ↗

Configuration class to store the configuration of a `BertModel`.

Source from the content-addressed store, hash-verified

164
165
166class BertConfig(object):
167 """Configuration class to store the configuration of a `BertModel`.
168 """
169
170 def __init__(self,
171 vocab_size_or_config_json_file,
172 hidden_size=768,
173 num_hidden_layers=12,
174 num_attention_heads=12,
175 intermediate_size=3072,
176 hidden_act="gelu",
177 hidden_dropout_prob=0.1,
178 attention_probs_dropout_prob=0.1,
179 max_position_embeddings=512,
180 type_vocab_size=2,
181 initializer_range=0.02,
182 deep_init=False,
183 fp32_layernorm=False,
184 fp32_embedding=False,
185 fp32_tokentypes=False,
186 layernorm_epsilon=1e-12):
187 """Constructs BertConfig.
188
189 Args:
190 vocab_size_or_config_json_file: Vocabulary size of `inputs_ids` in `BertModel`.
191 hidden_size: Size of the encoder layers and the pooler layer.
192 num_hidden_layers: Number of hidden layers in the Transformer encoder.
193 num_attention_heads: Number of attention heads for each attention layer in
194 the Transformer encoder.
195 intermediate_size: The size of the "intermediate" (i.e., feed-forward)
196 layer in the Transformer encoder.
197 hidden_act: The non-linear activation function (function or string) in the
198 encoder and pooler. If string, "gelu", "relu" and "swish" are supported.
199 hidden_dropout_prob: The dropout probabilitiy for all fully connected
200 layers in the embeddings, encoder, and pooler.
201 attention_probs_dropout_prob: The dropout ratio for the attention
202 probabilities.
203 max_position_embeddings: The maximum sequence length that this model might
204 ever be used with. Typically set this to something large just in case
205 (e.g., 512 or 1024 or 2048).
206 type_vocab_size: The vocabulary size of the `token_type_ids` passed into
207 `BertModel`.
208 initializer_range: The sttdev of the truncated_normal_initializer for
209 initializing all weight matrices.
210 """
211 if isinstance(vocab_size_or_config_json_file, str):
212 with open(vocab_size_or_config_json_file, "r", encoding='utf-8') as reader:
213 json_config = json.loads(reader.read())
214 for key, value in json_config.items():
215 self.__dict__[key] = value
216 elif isinstance(vocab_size_or_config_json_file, int):
217 self.vocab_size = vocab_size_or_config_json_file
218 self.hidden_size = hidden_size
219 self.num_hidden_layers = num_hidden_layers
220 self.num_attention_heads = num_attention_heads
221 self.hidden_act = hidden_act
222 self.intermediate_size = intermediate_size
223 self.hidden_dropout_prob = hidden_dropout_prob

Callers 1

from_dictMethod · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected