0

I used Jupyter Notebook to do ELMo to extract features. However, when I am trying to run the code

!pip install tensorflow
!pip install tensorflow-hub
import tensorflow_hub as hub
import tensorflow as tf
elmo = hub.Module("https://tfhub.dev/google/elmo/2", trainig = True)

it gives error

AttributeError: module 'tensorflow_hub' has no attribute 'Module'

My tensorflow and tensorflow_hub version are:

TensorFlow version: 2.15.0
TensorFlow Hub version: 0.16.1

I've tried to search ways online, but I couldn't find similar error. I think it might because of the versions, and I tried to downgrade the tensorflow, but it still not work.

EDIT 1: Now I am running the code below:

import tensorflow as tf
import tensorflow_hub as hub    

elmo = tf.compat.v1.Module("https://tfhub.dev/google/elmo/3", trainable=True)

This is the error I got:

TypeError: Module.__init__() got an unexpected keyword argument 'trainable'

EDIT 2: I am following the example use from elmo model. The code is

elmo = hub.Module("https://www.kaggle.com/models/google/elmo/frameworks/TensorFlow1/variations/elmo/versions/3", trainable=True)

I just replace the hub.Module() using tf.compat.v1.Module, that is why I passing trainable.

However, even I run this code:

elmo = tf.compat.v1.Module("https://tfhub.dev/google/elmo/3")

I got this error:

ValueError: 'https://tfhub.dev/google/elmo/3' is not a valid module name. Module names must be valid Python identifiers (e.g. a valid class name).
2
  • you posted a link that requires login to see. You code is not reproducible since you haven't included the imports. Please edit your question and include the imports to the libraries you are using. Commented Feb 26, 2024 at 9:49
  • Hi, I am sorry I didn't realize that. I had edited my question, thank you! Commented Feb 26, 2024 at 9:55

2 Answers 2

0

If you look at the changelog

https://github.com/tensorflow/hub/releases?page=2

Release 0.5.0

Made hub.Module usable within tf.compat.v1.wrap_function.

Hub.Module was for TF1, when using TF2 you need to use the compat attribute.

So use, tf.compat.v1.Module instead

If instead you use TF1 (not recommended since it's very old) you can still use tf.Module as stated in changelog 0.7

Release 0.7.0

For TF1, hub.Module and it's associated APIs remain available.
Sign up to request clarification or add additional context in comments.

6 Comments

Am I supposed to run 'tf.compat.v1.Module' before running 'hub.Module()'? I did this but I still received the same error
not before. hub.Module is now accesible via tf.compat.v1.Module so instead of doing hub.Module(...) you do tf.compat.v1.Module(...) (or you can install and use TF1
Thanks for your help, but I encountered the error Module.__init__() got an unexpected keyword argument 'trainable', I tried to search for solutions, but still no luck
We cannot see what you are running. Add your code in the question (append it at the end of the original question) so we can see what code are you running
I've edited my original question
|
0

TensorFlow Hub 0.7.0 Use hub.load() and hub.KerasLayer with TF2 (also works in 1.15).

I use hub.load() and it's work.

1 Comment

While this loads the module, the subsequent but I get is AttributeError: 'AutoTrackable' object has no attribute 'get_input_info_dict'

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.