'Tensorflow hub issue: Can't load embedding model after last update
This code has been working until last tf_hub update. I think, the problem is in the tensorflow_text module, that I haven't installed. But when I try to execute "pip install tensorflow_text==2.3.0" command (copied from the official tf_hub page) it throws back the error. I also tried to install it manually from github repo, but the package is still not available. Thanks.
embed = hub.load("https://tfhub.dev/google/universal-sentence-encoder/4")
---------------------------------------------------------------------------
RuntimeError Traceback (most recent call last)
G:\Anaconda\lib\site-packages\tensorflow\python\training\py_checkpoint_reader.py in get_tensor(self, tensor_str)
69 return CheckpointReader.CheckpointReader_GetTensor(
---> 70 self, compat.as_bytes(tensor_str))
71 # TODO(b/143319754): Remove the RuntimeError casting logic once we resolve the
RuntimeError:
During handling of the above exception, another exception occurred:
OpError Traceback (most recent call last)
<ipython-input-8-c716b77a9bc1> in <module>
----> 1 embed = hub.load("https://tfhub.dev/google/universal-sentence-encoder/4")
G:\Anaconda\lib\site-packages\tensorflow_hub\module_v2.py in load(handle, tags, options)
112 module_path, tags=tags, options=options)
113 else:
--> 114 obj = tf_v1.saved_model.load_v2(module_path, tags=tags)
115 obj._is_hub_module_v1 = is_hub_module_v1 # pylint: disable=protected-access
116 return obj
G:\Anaconda\lib\site-packages\tensorflow\python\saved_model\load.py in load(export_dir, tags, options)
601 ValueError: If `tags` don't match a MetaGraph in the SavedModel.
602 """
--> 603 return load_internal(export_dir, tags, options)
604
605
G:\Anaconda\lib\site-packages\tensorflow\python\saved_model\load.py in load_internal(export_dir, tags, options, loader_cls)
631 try:
632 loader = loader_cls(object_graph_proto, saved_model_proto, export_dir,
--> 633 ckpt_options)
634 except errors.NotFoundError as err:
635 raise FileNotFoundError(
G:\Anaconda\lib\site-packages\tensorflow\python\saved_model\load.py in __init__(self, object_graph_proto, saved_model_proto, export_dir, ckpt_options)
129
130 self._load_all()
--> 131 self._restore_checkpoint()
132
133 for node in self._nodes:
G:\Anaconda\lib\site-packages\tensorflow\python\saved_model\load.py in _restore_checkpoint(self)
328 self._checkpoint_options).expect_partial()
329 else:
--> 330 load_status = saver.restore(variables_path, self._checkpoint_options)
331 load_status.assert_existing_objects_matched()
332 checkpoint = load_status._checkpoint
G:\Anaconda\lib\site-packages\tensorflow\python\training\tracking\util.py in restore(self, save_path, options)
1280 dtype_map = reader.get_variable_to_dtype_map()
1281 try:
-> 1282 object_graph_string = reader.get_tensor(base.OBJECT_GRAPH_PROTO_KEY)
1283 except errors_impl.NotFoundError:
1284 # The object graph proto does not exist in this checkpoint. Try the
G:\Anaconda\lib\site-packages\tensorflow\python\training\py_checkpoint_reader.py in get_tensor(self, tensor_str)
72 # issue with throwing python exceptions from C++.
73 except RuntimeError as e:
---> 74 error_translator(e)
75
76
G:\Anaconda\lib\site-packages\tensorflow\python\training\py_checkpoint_reader.py in error_translator(e)
46 raise errors_impl.InternalError(None, None, error_message)
47 else:
---> 48 raise errors_impl.OpError(None, None, error_message, errors_impl.UNKNOWN)
49
50
OpError:
C:\Users\usr>pip install tensorflow_text v==2.3.0 ERROR: Could not find a version that satisfies the requirement tensorflow_text (from versions: none) ERROR: No matching distribution found for tensorflow_text
Solution 1:[1]
This code is working fine in Tensorflow 2.7 in Anaconda jupyter notebook. Please specify the Tensorflow version you are using while running this code.
!pip install tensorflow-hub
import tensorflow_hub as hub
embed = hub.load("https://tfhub.dev/google/universal-sentence-encoder/4")
There is no need to install the tensorflow_text to run this piece of code. However I have found there is typo error in your traceback error while installing tensorflow_text.
It should be as below:
!pip install tensorflow_text==2.3.0
Please check this link to access the Universal Sentence Encoder on TF-Hub.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | TFer2 |
