bert-utils icon indicating copy to clipboard operation
bert-utils copied to clipboard

When run BertVector

Open manxin0821 opened this issue 6 years ago • 14 comments

Exception in thread Thread-4: Traceback (most recent call last): File "/home/ubuntu/anaconda3/envs/tensorflow_p36/lib/python3.6/threading.py", line 916, in _bootstrap_inner self.run() File "/home/ubuntu/anaconda3/envs/tensorflow_p36/lib/python3.6/threading.py", line 864, in run self._target(*self._args, **self._kwargs) File "/home/ubuntu/bert-utils/extract_feature.py", line 83, in predict_from_queue for i in prediction: File "/home/ubuntu/anaconda3/envs/tensorflow_p36/lib/python3.6/site-packages/tensorflow/python/estimator/estimator.py", line 577, in predict features, None, model_fn_lib.ModeKeys.PREDICT, self.config) File "/home/ubuntu/anaconda3/envs/tensorflow_p36/lib/python3.6/site-packages/tensorflow/python/estimator/estimator.py", line 1195, in _call_model_fn model_fn_results = self._model_fn(features=features, **kwargs) File "/home/ubuntu/bert-utils/extract_feature.py", line 60, in model_fn graph_def.ParseFromString(f.read()) File "/home/ubuntu/anaconda3/envs/tensorflow_p36/lib/python3.6/site-packages/tensorflow/python/lib/io/file_io.py", line 125, in read self._preread_check() File "/home/ubuntu/anaconda3/envs/tensorflow_p36/lib/python3.6/site-packages/tensorflow/python/lib/io/file_io.py", line 85, in _preread_check compat.as_bytes(self.__name), 1024 * 512, status) File "/home/ubuntu/anaconda3/envs/tensorflow_p36/lib/python3.6/site-packages/tensorflow/python/util/compat.py", line 61, in as_bytes (bytes_or_text,)) TypeError: Expected binary or unicode string, got None

manxin0821 avatar Feb 05 '19 16:02 manxin0821

please show me the code

terrifyzhao avatar Feb 12 '19 02:02 terrifyzhao

I tried exactly the code you uploaded... Bv = bertvector() On Mon, Feb 11, 2019 at 9:32 PM joe.zhao [email protected] wrote:

please show me the code

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/terrifyzhao/bert-utils/issues/1#issuecomment-462589627, or mute the thread https://github.com/notifications/unsubscribe-auth/AHls8x3usgB5BsZgLVVvFgsGT_v_uoZuks5vMifKgaJpZM4aji-7 .

-- Best regards,

Nancy, Man Xin

manxin0821 avatar Feb 12 '19 23:02 manxin0821

I haven't come across this problem,maybe the reason is that the code will generates a temporary file(it is graph file),But you don't have read and write access to the file

terrifyzhao avatar Feb 14 '19 06:02 terrifyzhao

i have same problem os : win10

from extract_feature import BertVector bv = BertVector()

I:BERT_VEC:[graph:opt: 35]:model config: D:/bert/b2/bert-utils\chinese_L-12_H-768_A-12/bert_config.json I:BERT_VEC:[graph:opt: 41]:build graph... I:BERT_VEC:[graph:opt: 92]:load parameters from checkpoint... I:BERT_VEC:[graph:opt: 94]:freeze... INFO:tensorflow:Froze 181 variables. INFO:tensorflow:Converted 181 variables to const ops. I:BERT_VEC:[graph:opt: 97]:optimize... E:BERT_VEC:[graph:opt:110]:fail to optimize the graph! E:BERT_VEC:[graph:opt:111]:[Errno 2] No such file or directory: 'D:/bert/b2/bert-utils\chinese_L-12_H-768_A-12/../tmp/result/tmp930th5rk' WARNING:tensorflow:Using temporary folder as model directory: C:\Users\ADMINI~1\AppData\Local\Temp\tmpnr2b3oim INFO:tensorflow:Using config: {'_model_dir': 'C:\Users\ADMINI~1\AppData\Local\Temp\tmpnr2b3oim', '_tf_random_seed': None, '_save_summary_steps': 100, '_save_checkpoints_steps': None, '_save_checkpoints_secs': 600, '_session_config': gpu_options { per_process_gpu_memory_fraction: 1.0 allow_growth: true } graph_options { optimizer_options { global_jit_level: ON_1 } } , '_keep_checkpoint_max': 5, '_keep_checkpoint_every_n_hours': 10000, '_log_step_count_steps': 100, '_train_distribute': None, '_device_fn': None, '_protocol': None, '_eval_distribute': None, '_experimental_distribute': None, '_service': None, '_cluster_spec': <tensorflow.python.training.server_lib.ClusterSpec object at 0x000001E280056588>, '_task_type': 'worker', '_task_id': 0, '_global_id_in_cluster': 0, '_master': '', '_evaluation_master': '', '_is_chief': True, '_num_ps_replicas': 0, '_num_worker_replicas': 1} INFO:tensorflow:Could not find trained model in model_dir: C:\Users\ADMINI~1\AppData\Local\Temp\tmpnr2b3oim, running initialization to predict. INFO:tensorflow:Calling model_fn. Exception in thread Thread-6: Traceback (most recent call last): File "C:\Users\Administrator\Anaconda3\lib\threading.py", line 916, in _bootstrap_inner self.run() File "C:\Users\Administrator\Anaconda3\lib\threading.py", line 864, in run self._target(*self._args, **self._kwargs) File "D:/bert/b2/bert-utils\extract_feature.py", line 83, in predict_from_queue for i in prediction: File "C:\Users\Administrator\Anaconda3\lib\site-packages\tensorflow\python\estimator\estimator.py", line 577, in predict features, None, model_fn_lib.ModeKeys.PREDICT, self.config) File "C:\Users\Administrator\Anaconda3\lib\site-packages\tensorflow\python\estimator\estimator.py", line 1195, in _call_model_fn model_fn_results = self._model_fn(features=features, **kwargs) File "D:/bert/b2/bert-utils\extract_feature.py", line 60, in model_fn graph_def.ParseFromString(f.read()) File "C:\Users\Administrator\Anaconda3\lib\site-packages\tensorflow\python\lib\io\file_io.py", line 125, in read self._preread_check() File "C:\Users\Administrator\Anaconda3\lib\site-packages\tensorflow\python\lib\io\file_io.py", line 85, in _preread_check compat.as_bytes(self.__name), 1024 * 512, status) File "C:\Users\Administrator\Anaconda3\lib\site-packages\tensorflow\python\util\compat.py", line 61, in as_bytes (bytes_or_text,)) TypeError: Expected binary or unicode string, got None

xhero05 avatar Feb 18 '19 12:02 xhero05

我也遇到了同样的问题

bound2020 avatar Feb 21 '19 07:02 bound2020

i have the same problem. create file directory for output file first.

zhouygg avatar Feb 22 '19 09:02 zhouygg

I added the code to create the output folders automatically, please pull the code again

terrifyzhao avatar Feb 22 '19 09:02 terrifyzhao

I:BERT_VEC:[graph:opt: 42]:build graph... I:BERT_VEC:[graph:opt: 95]:load parameters from checkpoint... I:BERT_VEC:[graph:opt: 97]:freeze... INFO:tensorflow:Froze 181 variables. INFO:tensorflow:Converted 181 variables to const ops. I:BERT_VEC:[graph:opt:100]:optimize... I:BERT_VEC:[graph:opt:108]:write graph to a tmp file: D:\opensource\bert-utils-master\tmp\result\tmpr8i4x_4o WARNING:tensorflow:Using temporary folder as model directory: C:\Users\ADMINI~1\AppData\Local\Temp\tmpuoe5xqbz INFO:tensorflow:Using config: {'_model_dir': 'C:\Users\ADMINI~1\AppData\Local\Temp\tmpuoe5xqbz', '_tf_random_seed': None, '_save_summary_steps': 100, '_save_checkpoints_steps': None, '_save_checkpoints_secs': 600, '_session_config': gpu_options { per_process_gpu_memory_fraction: 1 allow_growth: true }

The folder will change while running extract feature. next time i get the following error when i run the same script in Spyder:

Reloaded modules: modeling, tokenization, graph, args I:BERT_VEC:[graph:opt: 36]:model config: D:\opensource\bert-utils-master\chinese_L-12_H-768_A-12/bert_config.json I:BERT_VEC:[graph:opt: 42]:build graph... I:BERT_VEC:[graph:opt: 95]:load parameters from checkpoint... I:BERT_VEC:[graph:opt: 97]:freeze... INFO:tensorflow:Froze 181 variables. INFO:tensorflow:Converted 181 variables to const ops. I:BERT_VEC:[graph:opt:100]:optimize... I:BERT_VEC:[graph:opt:108]:write graph to a tmp file: D:\opensource\bert-utils-master\tmp\result\tmp_ojuei03 WARNING:tensorflow:Using temporary folder as model directory: C:\Users\ADMINI~1\AppData\Local\Temp\tmp2hmoh95j INFO:tensorflow:Using config: {'_model_dir': 'C:\Users\ADMINI~1\AppData\Local\Temp\tmp2hmoh95j', '_tf_random_seed': None, '_save_summary_steps': 100, '_save_checkpoints_steps': None, '_save_checkpoints_secs': 600, '_session_config': gpu_options { per_process_gpu_memory_fraction: 1 allow_growth: true } graph_options { optimizer_options { global_jit_level: ON_1 } } , '_keep_checkpoint_max': 5, '_keep_checkpoint_every_n_hours': 10000, '_log_step_count_steps': 100, '_train_distribute': None, '_device_fn': None, '_service': None, '_cluster_spec': <tensorflow.python.training.server_lib.ClusterSpec object at 0x0000023208A94C88>, '_task_type': 'worker', '_task_id': 0, '_global_id_in_cluster': 0, '_master': '', '_evaluation_master': '', '_is_chief': True, '_num_ps_replicas': 0, '_num_worker_replicas': 1} INFO:tensorflow:Could not find trained model in model_dir: C:\Users\ADMINI~1\AppData\Local\Temp\tmp2hmoh95j, running initialization to predict. INFO:tensorflow:Calling model_fn. Exception in thread Thread-8: Traceback (most recent call last): File "C:\ProgramData\Anaconda3\lib\site-packages\tensorflow\python\framework\importer.py", line 418, 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 "C:\ProgramData\Anaconda3\lib\threading.py", line 916, in _bootstrap_inner self.run() File "C:\ProgramData\Anaconda3\lib\threading.py", line 864, in run self._target(*self._args, **self._kwargs) File "D:/opensource/bert-utils-master/extract_feature.py", line 83, in predict_from_queue for i in prediction: File "C:\ProgramData\Anaconda3\lib\site-packages\tensorflow\python\estimator\estimator.py", line 543, in predict features, None, model_fn_lib.ModeKeys.PREDICT, self.config) File "C:\ProgramData\Anaconda3\lib\site-packages\tensorflow\python\estimator\estimator.py", line 1133, in _call_model_fn model_fn_results = self._model_fn(features=features, **kwargs) File "D:/opensource/bert-utils-master/extract_feature.py", line 66, in model_fn return_elements=['final_encodes:0']) File "C:\ProgramData\Anaconda3\lib\site-packages\tensorflow\python\util\deprecation.py", line 454, in new_func return func(*args, **kwargs) File "C:\ProgramData\Anaconda3\lib\site-packages\tensorflow\python\framework\importer.py", line 422, in import_graph_def raise ValueError(str(e)) ValueError: Requested return tensor 'final_encodes:0' not found in graph def

zhouygg avatar Feb 23 '19 03:02 zhouygg

the path of the folder doesn't affect the output,the output has processed in graph.py,please confirm whether the version of tensorflow is greater than 1.11

terrifyzhao avatar Feb 25 '19 07:02 terrifyzhao

File "C:\ProgramData\Anaconda3\lib\site-packages\tensorflow\python\framework\importer.py", line 422, in import_graph_def raise ValueError(str(e)) ValueError: Requested return tensor 'final_encodes:0' not found in graph def


only run one script at a same time

terrifyzhao avatar Feb 25 '19 07:02 terrifyzhao

这个怎么解决 好痛苦

huangxiancun avatar May 30 '19 06:05 huangxiancun

看到你update 了 多谢🙏

huangxiancun avatar May 30 '19 06:05 huangxiancun

I:BERT_VEC:[graph:opt: 42]:build graph...

I:BERT_VEC:[graph:opt: 95]:load parameters from checkpoint... I:BERT_VEC:[graph:opt: 97]:freeze... INFO:tensorflow:Froze 181 variables. INFO:tensorflow:Converted 181 variables to const ops. I:BERT_VEC:[graph:opt:100]:optimize... I:BERT_VEC:[graph:opt:108]:write graph to a tmp file: D:\opensource\bert-utils-master\tmp\result\tmpr8i4x_4o WARNING:tensorflow:Using temporary folder as model directory: C:\Users\ADMINI~1\AppData\Local\Temp\tmpuoe5xqbz INFO:tensorflow:Using config: {'_model_dir': 'C:\Users\ADMINI~1\AppData\Local\Temp\tmpuoe5xqbz', '_tf_random_seed': None, '_save_summary_steps': 100, '_save_checkpoints_steps': None, '_save_checkpoints_secs': 600, '_session_config': gpu_options { per_process_gpu_memory_fraction: 1 allow_growth: true } The folder will change while running extract feature. next time i get the following error when i run the same script in Spyder:

Reloaded modules: modeling, tokenization, graph, args I:BERT_VEC:[graph:opt: 36]:model config: D:\opensource\bert-utils-master\chinese_L-12_H-768_A-12/bert_config.json I:BERT_VEC:[graph:opt: 42]:build graph... I:BERT_VEC:[graph:opt: 95]:load parameters from checkpoint... I:BERT_VEC:[graph:opt: 97]:freeze... INFO:tensorflow:Froze 181 variables. INFO:tensorflow:Converted 181 variables to const ops. I:BERT_VEC:[graph:opt:100]:optimize... I:BERT_VEC:[graph:opt:108]:write graph to a tmp file: D:\opensource\bert-utils-master\tmp\result\tmp_ojuei03 WARNING:tensorflow:Using temporary folder as model directory: C:\Users\ADMINI~1\AppData\Local\Temp\tmp2hmoh95j INFO:tensorflow:Using config: {'_model_dir': 'C:\Users\ADMINI~1\AppData\Local\Temp\tmp2hmoh95j', '_tf_random_seed': None, '_save_summary_steps': 100, '_save_checkpoints_steps': None, '_save_checkpoints_secs': 600, '_session_config': gpu_options { per_process_gpu_memory_fraction: 1 allow_growth: true } graph_options { optimizer_options { global_jit_level: ON_1 } } , '_keep_checkpoint_max': 5, '_keep_checkpoint_every_n_hours': 10000, '_log_step_count_steps': 100, '_train_distribute': None, '_device_fn': None, '_service': None, '_cluster_spec': <tensorflow.python.training.server_lib.ClusterSpec object at 0x0000023208A94C88>, '_task_type': 'worker', '_task_id': 0, '_global_id_in_cluster': 0, '_master': '', '_evaluation_master': '', '_is_chief': True, '_num_ps_replicas': 0, '_num_worker_replicas': 1} INFO:tensorflow:Could not find trained model in model_dir: C:\Users\ADMINI~1\AppData\Local\Temp\tmp2hmoh95j, running initialization to predict. INFO:tensorflow:Calling model_fn. Exception in thread Thread-8: Traceback (most recent call last): File "C:\ProgramData\Anaconda3\lib\site-packages\tensorflow\python\framework\importer.py", line 418, 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 "C:\ProgramData\Anaconda3\lib\threading.py", line 916, in _bootstrap_inner self.run() File "C:\ProgramData\Anaconda3\lib\threading.py", line 864, in run self._target(*self._args, **self._kwargs) File "D:/opensource/bert-utils-master/extract_feature.py", line 83, in predict_from_queue for i in prediction: File "C:\ProgramData\Anaconda3\lib\site-packages\tensorflow\python\estimator\estimator.py", line 543, in predict features, None, model_fn_lib.ModeKeys.PREDICT, self.config) File "C:\ProgramData\Anaconda3\lib\site-packages\tensorflow\python\estimator\estimator.py", line 1133, in _call_model_fn model_fn_results = self._model_fn(features=features, **kwargs) File "D:/opensource/bert-utils-master/extract_feature.py", line 66, in model_fn return_elements=['final_encodes:0']) File "C:\ProgramData\Anaconda3\lib\site-packages\tensorflow\python\util\deprecation.py", line 454, in new_func return func(*args, **kwargs) File "C:\ProgramData\Anaconda3\lib\site-packages\tensorflow\python\framework\importer.py", line 422, in import_graph_def raise ValueError(str(e)) ValueError: Requested return tensor 'final_encodes:0' not found in graph def

Today, i meet this problem,then,i deal with it successfully, Whether you can check your code get BertVector() instence in one cycle or not?

huangxiancun avatar May 30 '19 07:05 huangxiancun

这个问题应该是模型量化后存储路径的问题 args.py 里面有2个输出路径 output_dir 和 graph_file 如果自己更改了路径需要注意相对目录路径 当然你也可以不存储 让optimize_graph()直接输出量化后的计算图

Roshanson avatar Nov 25 '19 09:11 Roshanson