Created
November 15, 2020 11:50
-
-
Save negedng/cfba4590ef241cfd90f699dbb2c76278 to your computer and use it in GitHub Desktop.
Updated v3 BERT model from https://tfhub.dev/tensorflow/bert_en_uncased_L-12_H-768_A-12/3
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
import tensorflow_text as text # Registers the ops. | |
import tensorflow as tf | |
import tensorflow_hub as hub | |
# text_input = ["This is a sample sentence."] | |
text_input = tf.keras.layers.Input(shape=(), dtype=tf.string) | |
preprocessor = hub.KerasLayer( | |
"https://tfhub.dev/tensorflow/bert_en_uncased_preprocess/1") | |
encoder_inputs = preprocessor(text_input) # dict with keys: 'input_mask', 'input_type_ids', 'input_word_ids' | |
encoder = hub.KerasLayer( | |
"https://tfhub.dev/tensorflow/bert_en_uncased_L-12_H-768_A-12/3", | |
trainable=True) | |
outputs = encoder(encoder_inputs) | |
pooled_output = outputs["pooled_output"] # [batch_size, 768]. | |
sequence_output = outputs["sequence_output"] # [batch_size, seq_length, 768]. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment