I m试图利用<代码>tensorflow.keras建立一个模型,在模型中,我获得两个含有预先界定的重量的嵌入层(在汇编模型时,我能优化)。 我在推论期间的目标是将<条码> 插入_layer_1作为考表,以便获得<条码>的份量。 根据具体指标,因此,我保留<代码>可互用=True。
<代码> 重量_matrix :(288,3569)
,我谨获得<代码>的印本_layer_1。 (星号为(288,3569)
)和<编码> 嵌入_layer_2。 (斜体为<代码>(3569,288))。 因此,基本上在<条码>中插入_layer_2,即<条码>的转换。
该网络是:
import tensorflow as tf
from tensorflow.keras import Sequential
from tensorflow.keras.layers import Flatten, Embedding, Dot, Flatten
input_dim=288
output_dim=3569
model_1 = Sequential()
embedding_layer_1 = Embedding(input_dim=input_dim, output_dim=output_dim, name= embedding_layer_1 , dtype= float64 , trainable=True, input_length=1)
embedding_layer_1.build((None,))
model_1.add(embedding_layer_1)
model_1.layers[0].set_weights([weights_matrix])
model_1.add(Flatten())
model_2 = Sequential()
embedding_layer_2 = Embedding(input_dim=input_dim, output_dim=output_dim, name= embedding_layer_2 , dtype= float64 , trainable=True, input_length=1)
embedding_layer_2.build((None,))
model_2.add(embedding_layer_2)
model_2.layers[0].set_weights([role_skill_matrix])
model_2.add(Flatten())
dot_product = Dot(axes=-1)([model_1.output, model_2.output])
model = Sequential([model_1, model_2, dot_product])
model.summary()
我有以下错误。 我尝试了上述网络的各种变化,如转播、嵌入_layer_1
,并试图获取的印本_layer_1
及其移植,以及其他各种改动,但没有任何效果。
I m using
tensorflow==2.8.0
and keras==2.8.0
.
model = Sequential([model_1, model_2, dot_product])
File "/Users/ayalaallon/opt/anaconda3/envs/ml-pipeline/lib/python3.8/site-packages/tensorflow/python/training/tracking/base.py", line 629, in _method_wrapper
result = method(self, *args, **kwargs)
File "/Users/ayalaallon/opt/anaconda3/envs/ml-pipeline/lib/python3.8/site-packages/keras/utils/traceback_utils.py", line 67, in error_handler
raise e.with_traceback(filtered_tb) from None
File "/Users/ayalaallon/opt/anaconda3/envs/ml-pipeline/lib/python3.8/site-packages/keras/engine/sequential.py", line 178, in add
raise TypeError( The added layer must be an instance of class Layer.
TypeError: The added layer must be an instance of class Layer. Received: layer=KerasTensor(type_spec=TensorSpec(shape=(None, 1), dtype=tf.float32, name=None), name= dot/Squeeze:0 , description="created by layer dot ") of type <class keras.engine.keras_tensor.KerasTensor >.
Process finished with exit code 1