tensorflow.python.framework.erro
2019-08-09 本文已影响0人
菜菜鑫
使用Bert生成句向量,使用github上的bert-utils项目
使用方式为
bert = BertVector()
x_pad = bert.encode(contents)
报以下信息错误:
Exception in thread Thread-4:
Traceback (most recent call last):
File "/usr/local/lib/python3.6/dist-packages/tensorflow/python/framework/importer.py", line 427, in import_graph_def
graph._c_graph, serialized, options) # pylint: disable=protected-access
tensorflow.python.framework.errors_impl.InvalidArgumentError: Requested return tensor 'final_encodes:0' not found in graph def
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/usr/lib/python3.6/threading.py", line 916, in _bootstrap_inner
self.run()
File "/usr/lib/python3.6/threading.py", line 864, in run
self._target(*self._args, **self._kwargs)
File "/home/brx/Documents/Projects/Classification/Biaoqian-cnn-rnn/bert_utils/extract_feature.py", line 89, in predict_from_queue
for i in prediction:
File "/usr/local/lib/python3.6/dist-packages/tensorflow_estimator/python/estimator/estimator.py", line 619, in predict
features, None, ModeKeys.PREDICT, self.config)
File "/usr/local/lib/python3.6/dist-packages/tensorflow_estimator/python/estimator/estimator.py", line 1146, in _call_model_fn
model_fn_results = self._model_fn(features=features, **kwargs)
File "/home/brx/Documents/Projects/Classification/Biaoqian-cnn-rnn/bert_utils/extract_feature.py", line 72, in model_fn
return_elements=['final_encodes:0'])
File "/usr/local/lib/python3.6/dist-packages/tensorflow/python/util/deprecation.py", line 507, in new_func
return func(*args, **kwargs)
File "/usr/local/lib/python3.6/dist-packages/tensorflow/python/framework/importer.py", line 431, in import_graph_def
raise ValueError(str(e))
ValueError: Requested return tensor 'final_encodes:0' not found in graph def
看到github上bert-util2的Issue中的
<https://github.com/terrifyzhao/bert-utils/issues/1>
这里指出,不要在循环中使用或多次调用BertVector(),检查自己的代码,保证BertVector()只被声明一次,而bert.encode(contents)可以被多次使用,问题解决.