How to fix “RuntimeError: Missing implementation that supports: loader” when calling hub.text_embedding_column method?

心不动则不痛 提交于 2020-12-30 06:37:14

问题


I'm trying to fit a text classification model. Therefore i wanted to use the text_embedding_column function provided by tensorflow-hub. Unfortunately i get a runtime error

import tensorflow_hub as hub
embedded_text_feature_column = hub.text_embedding_column(
    key="sentence", 
    module_spec="https://tfhub.dev/google/nnlm-en-dim128/1")

The error i get is the following:

RuntimeError                              Traceback (most recent call last)
<ipython-input-18-df9239a27166> in <module>()
      2 embedded_text_feature_column = hub.text_embedding_column(
      3     key="sentence",
----> 4     module_spec="https://tfhub.dev/google/nnlm-en-dim128/1")

/anaconda3/lib/python3.6/site-packages/tensorflow_hub/feature_column.py in text_embedding_column(key, module_spec, trainable)
     72      ValueError: if module_spec is not suitable for use in this feature column.
     73   
---> 74   module_spec = module.as_module_spec(module_spec)
     75   _check_module_is_text_embedding(module_spec)
     76   return _TextEmbeddingColumn(key=key, module_spec=module_spec,

/anaconda3/lib/python3.6/site-packages/tensorflow_hub/module.py in as_module_spec(spec)
     31     return spec
     32   elif isinstance(spec, six.string_types):
---> 33     return load_module_spec(spec)
     34   else:
     35     raise ValueError("Unknown module spec type: %r" % type(spec))

/anaconda3/lib/python3.6/site-packages/tensorflow_hub/module.py in load_module_spec(path)
     56   
     57   path = registry.resolver(path)
---> 58   return registry.loader(path)
     59 
     60 

/anaconda3/lib/python3.6/site-packages/tensorflow_hub/registry.py in __call__(self, *args, **kwargs)
     43     raise RuntimeError(
     44         "Missing implementation that supports: %s(*%r, **%r)" % (
---> 45             self._name, args, kwargs))
     46 
     47 

RuntimeError: Missing implementation that supports: loader(*('/var/folders/pc/h0fr0z2x1pjbmdb63mhn84_w0000gn/T/tfhub_modules/32f2b2259e1cc8ca58c876921748361283e73997',), **{})

回答1:


I walked through the same error and this is how I solved it;

My error was:

RuntimeError: Missing implementation that supports: loader(*('C:\\Users\\Alber\\AppData\\Local\\Temp\\tfhub_modules\\a7fe827a4e68369aab0fa6a65479cd37c499e0f4',), **{})

So the problem was with the following path:

C:/Users/Alber/AppData/Local/Temp/tfhub_modules/a7fe827a4e68369aab0fa6a65479cd37c499e0f4

Just with the explorer I checked the path and found that the a7fe827a4e68369aab0fa6a65479cd37c499e0f4 folder was empty. I don't know why but that shouldn't happen.

Then I just deleted the a7fe827a4e68369aab0fa6a65479cd37c499e0f4 folder and even the tf_hub folder (because I didn't have any other thing but I think it's not necessary to remove the tf_hub folder).

After that I run the script and it downloaded again the required modules normally

INFO:tensorflow:Using C:\Users\Alber\AppData\Local\Temp\tfhub_modules to cache modules.
INFO:tensorflow:Downloading TF-Hub Module 'https://tfhub.dev/google/nnlm-es-dim128-with-normalization/1'.
INFO:tensorflow:Downloading https://tfhub.dev/google/nnlm-es-dim128-with-normalization/1: 38.58MB
...



回答2:


The tensorflow 2 has new method for hub called as KerasLayer (https://www.tensorflow.org/hub). Using that solved my problem.

import tensorflow as tf

import tensorflow_hub as hub

module_url = "https://tfhub.dev/google/nnlm-en-dim128/2"

embed = hub.KerasLayer(module_url)

embeddings = embed(["A long sentence.", "single-word",
                      "http://example.com"])


来源:https://stackoverflow.com/questions/54029556/how-to-fix-runtimeerror-missing-implementation-that-supports-loader-when-cal

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!