我尝试使用tfhub将GlobalAvgPooling层包装到google albert输出层。这是我的代码:
import tensorflow_hub as hub
import tensorflow as tf
from tensorflow import keras
q_in = keras.layers.Input(shape=(None,), dtype=tf.int32, name="word_ids")
q2_in = keras.layers.Input(shape=(None,), dtype=tf.int32, name="masks")
q3_in = keras.layers.Input(shape=(None,), dtype=tf.int32, name="segment_ids")
albert_module = hub.Module('https://tfhub.dev/google/albert_base/2', trainable=True)
albert_inputs = dict(input_ids=q_in, input_mask=q2_in, segment_ids=q3_in)
albert_outputs = albert_module(albert_inputs, signature="tokens", as_dict=True)["sequence_output"]
pooled = keras.layers.GlobalAveragePooling1D()(albert_outputs)
我遇到以下错误:
Traceback (most recent call last):
File "<input>", line 1, in <module>
File "E:\Python36\lib\site-packages\tensorflow_core\python\keras\engine\base_layer.py", line 802, in __call__
base_layer_utils.create_keras_history(inputs)
File "E:\Python36\lib\site-packages\tensorflow_core\python\keras\engine\base_layer_utils.py", line 184, in create_keras_history
_, created_layers = _create_keras_history_helper(tensors, set(), [])
File "E:\Python36\lib\site-packages\tensorflow_core\python\keras\engine\base_layer_utils.py", line 231, in _create_keras_history_helper
layer_inputs, processed_ops, created_layers)
File "E:\Python36\lib\site-packages\tensorflow_core\python\keras\engine\base_layer_utils.py", line 231, in _create_keras_history_helper
layer_inputs, processed_ops, created_layers)
File "E:\Python36\lib\site-packages\tensorflow_core\python\keras\engine\base_layer_utils.py", line 231, in _create_keras_history_helper
layer_inputs, processed_ops, created_layers)
File "E:\Python36\lib\site-packages\tensorflow_core\python\keras\engine\base_layer_utils.py", line 229, in _create_keras_history_helper
constants[i] = backend.function([], op_input)([])
File "E:\Python36\lib\site-packages\tensorflow_core\python\keras\backend.py", line 3476, in __call__
run_metadata=self.run_metadata)
File "E:\Python36\lib\site-packages\tensorflow_core\python\client\session.py", line 1472, in __call__
run_metadata_ptr)
tensorflow.python.framework.errors_impl.FailedPreconditionError: Error while reading resource variable module/bert/encoder/transformer/group_0/inner_group_0/ffn_1/intermediate/output/dense/bias from Container: localhost. This could mean that the variable was uninitialized. Not found: Resource localhost/module/bert/encoder/transformer/group_0/inner_group_0/ffn_1/intermediate/output/dense/bias/class tensorflow::Var does not exist.
[[{{node module_apply_tokens/bert/encoder/transformer/group_0_11/layer_11/inner_group_0/ffn_1/intermediate/output/dense/add/ReadVariableOp}}]]
任何建议或帮助,我们将不胜感激!预先感谢!