type error
/usr/local/lib/python3.6/dist-packages/bert/model.py:80 call *
output = self.encoders_layer(embedding_output, mask=mask, training=training)
/usr/local/lib/python3.6/dist-packages/keras/engine/base_layer.py:1030 __call__ **
self._maybe_build(inputs)
/usr/local/lib/python3.6/dist-packages/keras/engine/base_layer.py:2659 _maybe_build
self.build(input_shapes) # pylint:disable=not-callable
/usr/local/lib/python3.6/dist-packages/bert/transformer.py:209 build
self.input_spec = keras.layers.InputSpec(shape=input_shape)
/usr/local/lib/python3.6/dist-packages/keras/engine/base_layer.py:2777 __setattr__
super(tf.__internal__.tracking.AutoTrackable, self).__setattr__(name, value) # pylint: disable=bad-super-call
/usr/local/lib/python3.6/dist-packages/tensorflow/python/training/tracking/base.py:530 _method_wrapper
result = method(self, *args, **kwargs)
/usr/local/lib/python3.6/dist-packages/keras/engine/base_layer.py:1297 input_spec
'Got: {}'.format(v))
TypeError: Layer input_spec must be an instance of InputSpec. Got: InputSpec(shape=(None, 128, 768), ndim=3)
Unfortunately, I ran into the same problem, and solved the issue by downgrading to tensorflow=2.3
This is cause by mix usage of tensorflow.python.keras and tensorflow.keras, when i replace all tensorflow.python.keras by tensorflow.keras, it work.
I got it to work by following @czf1009 advice. This is what I did:
- I cloned the latest versions of this repos into my virtual environment (venv) lib/python3.8/site-packages folder
- bert-for-tf2
- params-flow
- params-py
(I believe these can be cloned to a local folder as well)
- I modified the following files on the bert (bert-for-tf2) repo
- transformer.py *attention.py
Where it says "from tensorflow.python import keras" replaced by "from tensorflow import keras"
3)To remove some warnings , I pip installed gast==0.3.3 and abs-py=1.0.0
Hope it helps!
Created https://github.com/kpe/bert-for-tf2/pull/94 with the solution from @lgalant
Thanks everybody, #94 helped me.
TL;DR
-
in file {venv}/lib/python3.X/site-packages/bert/transformer.py
from tensorflow.python import kerasto
from tensorflow import keras -
in file {venv}/lib/python3.X/site-packages/bert/attention.py
from tensorflow.python import keras from tensorflow.python.keras import backend as Kto
from tensorflow import keras from tensorflow.keras import backend as K