Python modeling.BertConfig() Examples

The following are 30 code examples of modeling.BertConfig(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module modeling , or try the search function .
Example #1
Source File: modeling_test.py    From bert-qa with MIT License 5 votes vote down vote up
def test_config_to_json_string(self):
    config = modeling.BertConfig(vocab_size=99, hidden_size=37)
    obj = json.loads(config.to_json_string())
    self.assertEqual(obj["vocab_size"], 99)
    self.assertEqual(obj["hidden_size"], 37) 
Example #2
Source File: modeling_test.py    From text_bert_cnn with MIT License 5 votes vote down vote up
def test_config_to_json_string(self):
    config = modeling.BertConfig(vocab_size=99, hidden_size=37)
    obj = json.loads(config.to_json_string())
    self.assertEqual(obj["vocab_size"], 99)
    self.assertEqual(obj["hidden_size"], 37) 
Example #3
Source File: modeling_test.py    From BERT-Classification-Tutorial with Apache License 2.0 5 votes vote down vote up
def test_config_to_json_string(self):
        config = modeling.BertConfig(vocab_size=99, hidden_size=37)
        obj = json.loads(config.to_json_string())
        self.assertEqual(obj["vocab_size"], 99)
        self.assertEqual(obj["hidden_size"], 37) 
Example #4
Source File: modeling_test.py    From Extending-Google-BERT-as-Question-and-Answering-model-and-Chatbot with Apache License 2.0 5 votes vote down vote up
def test_config_to_json_string(self):
    config = modeling.BertConfig(vocab_size=99, hidden_size=37)
    obj = json.loads(config.to_json_string())
    self.assertEqual(obj["vocab_size"], 99)
    self.assertEqual(obj["hidden_size"], 37) 
Example #5
Source File: modeling_test.py    From models with Apache License 2.0 5 votes vote down vote up
def test_config_to_json_string(self):
    config = modeling.BertConfig(vocab_size=99, hidden_size=37)
    obj = json.loads(config.to_json_string())
    self.assertEqual(obj["vocab_size"], 99)
    self.assertEqual(obj["hidden_size"], 37) 
Example #6
Source File: modeling_test.py    From gobbli with Apache License 2.0 5 votes vote down vote up
def test_config_to_json_string(self):
    config = modeling.BertConfig(vocab_size=99, hidden_size=37)
    obj = json.loads(config.to_json_string())
    self.assertEqual(obj["vocab_size"], 99)
    self.assertEqual(obj["hidden_size"], 37) 
Example #7
Source File: modeling_test.py    From DeepCT with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def test_config_to_json_string(self):
    config = modeling.BertConfig(vocab_size=99, hidden_size=37)
    obj = json.loads(config.to_json_string())
    self.assertEqual(obj["vocab_size"], 99)
    self.assertEqual(obj["hidden_size"], 37) 
Example #8
Source File: modeling_test.py    From bert_serving with Apache License 2.0 5 votes vote down vote up
def test_config_to_json_string(self):
    config = modeling.BertConfig(vocab_size=99, hidden_size=37)
    obj = json.loads(config.to_json_string())
    self.assertEqual(obj["vocab_size"], 99)
    self.assertEqual(obj["hidden_size"], 37) 
Example #9
Source File: modeling_test.py    From models with Apache License 2.0 5 votes vote down vote up
def test_config_to_json_string(self):
    config = modeling.BertConfig(vocab_size=99, hidden_size=37)
    obj = json.loads(config.to_json_string())
    self.assertEqual(obj["vocab_size"], 99)
    self.assertEqual(obj["hidden_size"], 37) 
Example #10
Source File: modeling_test.py    From nlp_research with MIT License 5 votes vote down vote up
def test_config_to_json_string(self):
    config = modeling.BertConfig(vocab_size=99, hidden_size=37)
    obj = json.loads(config.to_json_string())
    self.assertEqual(obj["vocab_size"], 99)
    self.assertEqual(obj["hidden_size"], 37) 
Example #11
Source File: modeling_test.py    From tsalib with Apache License 2.0 5 votes vote down vote up
def test_config_to_json_string(self):
    config = modeling.BertConfig(vocab_size=99, hidden_size=32)
    obj = json.loads(config.to_json_string())
    self.assertEqual(obj["vocab_size"], 99)
    self.assertEqual(obj["hidden_size"], 32) 
Example #12
Source File: modeling_test.py    From bert with Apache License 2.0 5 votes vote down vote up
def test_config_to_json_string(self):
    config = modeling.BertConfig(vocab_size=99, hidden_size=37)
    obj = json.loads(config.to_json_string())
    self.assertEqual(obj["vocab_size"], 99)
    self.assertEqual(obj["hidden_size"], 37) 
Example #13
Source File: modeling_test.py    From bert-as-language-model with Apache License 2.0 5 votes vote down vote up
def test_config_to_json_string(self):
    config = modeling.BertConfig(vocab_size=99, hidden_size=37)
    obj = json.loads(config.to_json_string())
    self.assertEqual(obj["vocab_size"], 99)
    self.assertEqual(obj["hidden_size"], 37) 
Example #14
Source File: modeling_test.py    From SIGIR19-BERT-IR with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def test_config_to_json_string(self):
    config = modeling.BertConfig(vocab_size=99, hidden_size=37)
    obj = json.loads(config.to_json_string())
    self.assertEqual(obj["vocab_size"], 99)
    self.assertEqual(obj["hidden_size"], 37) 
Example #15
Source File: modeling_test.py    From delft with Apache License 2.0 5 votes vote down vote up
def test_config_to_json_string(self):
    config = modeling.BertConfig(vocab_size=99, hidden_size=37)
    obj = json.loads(config.to_json_string())
    self.assertEqual(obj["vocab_size"], 99)
    self.assertEqual(obj["hidden_size"], 37) 
Example #16
Source File: modeling_test.py    From uai-sdk with Apache License 2.0 5 votes vote down vote up
def test_config_to_json_string(self):
    config = modeling.BertConfig(vocab_size=99, hidden_size=37)
    obj = json.loads(config.to_json_string())
    self.assertEqual(obj["vocab_size"], 99)
    self.assertEqual(obj["hidden_size"], 37) 
Example #17
Source File: modeling_test.py    From KBQA-BERT with MIT License 5 votes vote down vote up
def test_config_to_json_string(self):
    config = modeling.BertConfig(vocab_size=99, hidden_size=37)
    obj = json.loads(config.to_json_string())
    self.assertEqual(obj["vocab_size"], 99)
    self.assertEqual(obj["hidden_size"], 37) 
Example #18
Source File: train_bert_toy_task.py    From text_classification with MIT License 5 votes vote down vote up
def bert_train_fn():
    is_training=True
    hidden_size = 768
    num_labels = 10
    #batch_size=128
    max_seq_length=512
    use_one_hot_embeddings = False
    bert_config = modeling.BertConfig(vocab_size=21128, hidden_size=hidden_size, num_hidden_layers=12,
                                      num_attention_heads=12,intermediate_size=3072)

    input_ids = tf.placeholder(tf.int32, [batch_size, max_seq_length], name="input_ids")
    input_mask = tf.placeholder(tf.int32, [batch_size, max_seq_length], name="input_mask")
    segment_ids = tf.placeholder(tf.int32, [batch_size,max_seq_length],name="segment_ids")
    label_ids = tf.placeholder(tf.float32, [batch_size,num_labels], name="label_ids")
    loss, per_example_loss, logits, probabilities, model = create_model(bert_config, is_training, input_ids, input_mask,
                                                                        segment_ids, label_ids, num_labels,
                                                                        use_one_hot_embeddings)
    # 1. generate or load training/validation/test data. e.g. train:(X,y). X is input_ids,y is labels.

    # 2. train the model by calling create model, get loss
    gpu_config = tf.ConfigProto()
    gpu_config.gpu_options.allow_growth = True
    sess = tf.Session(config=gpu_config)
    sess.run(tf.global_variables_initializer())
    for i in range(1000):
        input_ids_=np.ones((batch_size,max_seq_length),dtype=np.int32)
        input_mask_=np.ones((batch_size,max_seq_length),dtype=np.int32)
        segment_ids_=np.ones((batch_size,max_seq_length),dtype=np.int32)
        label_ids_=np.ones((batch_size,num_labels),dtype=np.float32)
        feed_dict = {input_ids: input_ids_, input_mask: input_mask_,segment_ids:segment_ids_,label_ids:label_ids_}
        loss_ = sess.run([loss], feed_dict)
        print("loss:",loss_)
    # 3. eval the model from time to time 
Example #19
Source File: modeling_test.py    From BERT_STS-B with Apache License 2.0 5 votes vote down vote up
def test_config_to_json_string(self):
    config = modeling.BertConfig(vocab_size=99, hidden_size=37)
    obj = json.loads(config.to_json_string())
    self.assertEqual(obj["vocab_size"], 99)
    self.assertEqual(obj["hidden_size"], 37) 
Example #20
Source File: modeling_test.py    From BERT-sentiment--classification with Apache License 2.0 5 votes vote down vote up
def test_config_to_json_string(self):
    config = modeling.BertConfig(vocab_size=99, hidden_size=37)
    obj = json.loads(config.to_json_string())
    self.assertEqual(obj["vocab_size"], 99)
    self.assertEqual(obj["hidden_size"], 37) 
Example #21
Source File: modeling_test.py    From training with Apache License 2.0 5 votes vote down vote up
def test_config_to_json_string(self):
    config = modeling.BertConfig(vocab_size=99, hidden_size=37)
    obj = json.loads(config.to_json_string())
    self.assertEqual(obj["vocab_size"], 99)
    self.assertEqual(obj["hidden_size"], 37) 
Example #22
Source File: modeling_test.py    From training with Apache License 2.0 5 votes vote down vote up
def test_config_to_json_string(self):
    config = modeling.BertConfig(vocab_size=99, hidden_size=37)
    obj = json.loads(config.to_json_string())
    self.assertEqual(obj["vocab_size"], 99)
    self.assertEqual(obj["hidden_size"], 37) 
Example #23
Source File: modeling_test.py    From adapter-bert with Apache License 2.0 5 votes vote down vote up
def test_config_to_json_string(self):
    config = modeling.BertConfig(vocab_size=99, hidden_size=37)
    obj = json.loads(config.to_json_string())
    self.assertEqual(obj["vocab_size"], 99)
    self.assertEqual(obj["hidden_size"], 37) 
Example #24
Source File: modeling_test.py    From pynlp with MIT License 5 votes vote down vote up
def test_config_to_json_string(self):
    config = modeling.BertConfig(vocab_size=99, hidden_size=37)
    obj = json.loads(config.to_json_string())
    self.assertEqual(obj["vocab_size"], 99)
    self.assertEqual(obj["hidden_size"], 37) 
Example #25
Source File: modeling_test.py    From pynlp with MIT License 5 votes vote down vote up
def test_config_to_json_string(self):
    config = modeling.BertConfig(vocab_size=99, hidden_size=37)
    obj = json.loads(config.to_json_string())
    self.assertEqual(obj["vocab_size"], 99)
    self.assertEqual(obj["hidden_size"], 37) 
Example #26
Source File: train_bert_toy_task.py    From pynlp with MIT License 5 votes vote down vote up
def bert_train_fn():
    is_training=True
    hidden_size = 768
    num_labels = 10
    #batch_size=128
    max_seq_length=512
    use_one_hot_embeddings = False
    bert_config = modeling.BertConfig(vocab_size=21128, hidden_size=hidden_size, num_hidden_layers=12,
                                      num_attention_heads=12,intermediate_size=3072)

    input_ids = tf.placeholder(tf.int32, [batch_size, max_seq_length], name="input_ids")
    input_mask = tf.placeholder(tf.int32, [batch_size, max_seq_length], name="input_mask")
    segment_ids = tf.placeholder(tf.int32, [batch_size,max_seq_length],name="segment_ids")
    label_ids = tf.placeholder(tf.float32, [batch_size,num_labels], name="label_ids")
    loss, per_example_loss, logits, probabilities, model = create_model(bert_config, is_training, input_ids, input_mask,
                                                                        segment_ids, label_ids, num_labels,
                                                                        use_one_hot_embeddings)
    # 1. generate or load training/validation/test data. e.g. train:(X,y). X is input_ids,y is labels.

    # 2. train the model by calling create model, get loss
    gpu_config = tf.ConfigProto()
    gpu_config.gpu_options.allow_growth = True
    sess = tf.Session(config=gpu_config)
    sess.run(tf.global_variables_initializer())
    for i in range(1000):
        input_ids_=np.ones((batch_size,max_seq_length),dtype=np.int32)
        input_mask_=np.ones((batch_size,max_seq_length),dtype=np.int32)
        segment_ids_=np.ones((batch_size,max_seq_length),dtype=np.int32)
        label_ids_=np.ones((batch_size,num_labels),dtype=np.float32)
        feed_dict = {input_ids: input_ids_, input_mask: input_mask_,segment_ids:segment_ids_,label_ids:label_ids_}
        loss_ = sess.run([loss], feed_dict)
        print("loss:",loss_)
    # 3. eval the model from time to time 
Example #27
Source File: modeling_test.py    From dl4marco-bert with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def test_config_to_json_string(self):
    config = modeling.BertConfig(vocab_size=99, hidden_size=37)
    obj = json.loads(config.to_json_string())
    self.assertEqual(obj["vocab_size"], 99)
    self.assertEqual(obj["hidden_size"], 37) 
Example #28
Source File: modeling_test.py    From BERT-for-Sequence-Labeling-and-Text-Classification with Apache License 2.0 5 votes vote down vote up
def test_config_to_json_string(self):
    config = modeling.BertConfig(vocab_size=99, hidden_size=37)
    obj = json.loads(config.to_json_string())
    self.assertEqual(obj["vocab_size"], 99)
    self.assertEqual(obj["hidden_size"], 37) 
Example #29
Source File: modeling_test.py    From MedicalRelationExtraction with MIT License 5 votes vote down vote up
def test_config_to_json_string(self):
    config = modeling.BertConfig(vocab_size=99, hidden_size=37)
    obj = json.loads(config.to_json_string())
    self.assertEqual(obj["vocab_size"], 99)
    self.assertEqual(obj["hidden_size"], 37) 
Example #30
Source File: modeling_test.py    From coref with Apache License 2.0 5 votes vote down vote up
def test_config_to_json_string(self):
    config = modeling.BertConfig(vocab_size=99, hidden_size=37)
    obj = json.loads(config.to_json_string())
    self.assertEqual(obj["vocab_size"], 99)
    self.assertEqual(obj["hidden_size"], 37)