How to save/load a tensorflow hub module to/from a custom path?

  • Take the URL and change it from:

https://tfhub.dev/google/universal-sentence-encoder/1

To:

https://storage.googleapis.com/tfhub-modules/google/universal-sentence-encoder/1.tar.gz

  • Download using Curl or browser.
  • Extract to a prefered location (e.g. /home/admin/embed/)
  • Change your code to:

.

import tensorflow_hub as hub 
embed = hub.load('/home/admin/embed/')

You can download your model need from url + '?tf-hub-format=compressed'

i tried downloading elmo and it worked

url = https://tfhub.dev/google/elmo/2 + '?tf-hub-format=compressed'

eg: https://tfhub.dev/google/elmo/2?tf-hub-format=compressed

the model will be downloaded as a tarfile to your machine.

once you untar the file, it will have tfhub_module.pb