Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

type error #91

Open
erenat77 opened this issue Aug 27, 2021 · 5 comments
Open

type error #91

erenat77 opened this issue Aug 27, 2021 · 5 comments

Comments

@erenat77
Copy link

/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)
@ljsun
Copy link

ljsun commented Aug 27, 2021

Unfortunately, I ran into the same problem, and solved the issue by downgrading to tensorflow=2.3

@czf1009
Copy link

czf1009 commented Sep 25, 2021

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.

@lgalant
Copy link

lgalant commented Mar 9, 2022

I got it to work by following @czf1009 advice.
This is what I did:

  1. 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)

  1. 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!

@bcazur
Copy link

bcazur commented May 25, 2022

Created #94 with the solution from @lgalant

@Serpong
Copy link

Serpong commented Jan 30, 2023

Thanks everybody,
#94 helped me.

TL;DR

  1. in file {venv}/lib/python3.X/site-packages/bert/transformer.py

    from tensorflow.python import keras
    

    to

    from tensorflow import keras
    
  2. in file {venv}/lib/python3.X/site-packages/bert/attention.py

    from tensorflow.python import keras
    from tensorflow.python.keras import backend as K
    

    to

    from tensorflow import keras
    from tensorflow.keras import backend as K
    

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants