Created
June 30, 2020 07:48
-
-
Save deelipku23/e6b963a6e1a4a76a565984ace11e6fcd to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def create_model(model_name): | |
config = BertConfig() | |
config.output_hidden_states = False | |
question_bert_model = TFBertModel.from_pretrained(model_name, config=config) | |
answer_bert_model = TFBertModel.from_pretrained(model_name, config=config) | |
question_enc = tf.keras.layers.Input((MAX_SEQUENCE_LENGTH,), dtype=tf.int32) | |
question_mask = tf.keras.layers.Input((MAX_SEQUENCE_LENGTH,), dtype=tf.int32) | |
question_type_ids = tf.keras.layers.Input((MAX_SEQUENCE_LENGTH,), dtype=tf.int32) | |
answer_enc = tf.keras.layers.Input((MAX_SEQUENCE_LENGTH,), dtype=tf.int32) | |
answer_mask = tf.keras.layers.Input((MAX_SEQUENCE_LENGTH,), dtype=tf.int32) | |
answer_type_ids = tf.keras.layers.Input((MAX_SEQUENCE_LENGTH,), dtype=tf.int32) | |
question_bert = question_bert_model(question_enc, attention_mask=question_mask, token_type_ids=question_type_ids)[0] | |
answer_bert = answer_bert_model(answer_enc, attention_mask=answer_mask, token_type_ids=answer_type_ids)[0] | |
question_bert_summary = tf.keras.layers.Flatten()(tf.keras.layers.AveragePooling1D(MAX_SEQUENCE_LENGTH)(question_bert)) | |
answer_bert_summary = tf.keras.layers.Flatten()(tf.keras.layers.AveragePooling1D(MAX_SEQUENCE_LENGTH)(answer_bert)) | |
combined_bert_summary = tf.keras.layers.Concatenate()([question_bert_summary, answer_bert_summary]) | |
dropout_bert = tf.keras.layers.Dropout(0.2)(combined_bert_summary) | |
output = tf.keras.layers.Dense(30, activation='sigmoid')(dropout_bert) | |
model = tf.keras.models.Model(inputs=[question_enc, question_mask, question_type_ids, answer_enc, answer_mask, answer_type_ids], outputs=output) | |
return model |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment