Closed 121eddie closed 3 years ago
I have the same problem too. Have you solved this problem?
Yes, please note the comment in the examples from the readme:
# use in Keras Model here, and call model.build()
for example, you could try:
# use in Keras Model here, and call model.build()
model = keras.models.Sequential([
keras.layers.InputLayer(input_shape=(128,)),
l_bert,
keras.layers.Lambda(lambda x: x[:, 0, :]),
keras.layers.Dense(2)
])
model.build(input_shape=(None, 128))
without model.build()
no weights get instantiated by keras, therefore the checkpoint cannot be loaded.
Because this is such a common problem when using bert-for-tf2 for the first time, I'll add a descriptive assertion like:
AssertionError: BertModelLayer weights have not been instantiated yet. Please add the layer in a Keras model and call model.build() first!
Windows 10 64, Python 3.7.9, Tensorflow 2.3.1 GPU, Cuda 10.1.243
Trying to import pretrained google bert