[英]Issue in creating Keras Model Input tensors to a Model must come from `keras.layers.Input`?
for some reason I am trying to create my Keras model but it won't work.出于某种原因,我正在尝试创建我的 Keras 模型,但它不起作用。 I get this error ValueError: Input tensors to a Model must come from
keras.layers.Input
.我收到此错误 ValueError: Input
keras.layers.Input
to a Model must come from keras.layers.Input
。 Received: (missing previous layer metadata).收到:(缺少前一层元数据)。 [Error when creating the model last line]
[创建模型最后一行时出错]
I tried separating the inputs but it didn't work, any help please?我尝试将输入分开,但没有用,请问有什么帮助吗? Here's a snippet of my code
这是我的代码片段
word_embedding_layer = emb.get_keras_embedding(trainable = True,
input_length = 20,
name='word_embedding_layer')
pos_embedding_layer = Embedding(output_dim = 5,
input_dim = 56,
input_length = 20,
name='pos_embedding_layer')
inputs_and_embeddings = [(Input(shape = (sent_maxlen,),
dtype="int32",
name = "word_inputs"),
word_embedding_layer),
(Input(shape = (sent_maxlen,),
dtype="int32",
name = "predicate_inputs"),
word_embedding_layer),
(Input(shape = (sent_maxlen,),
dtype="int32",
name = "postags_inputs"),
pos_embedding_layer),
]
## --------> 9] Concat all inputs and run on deep network
## Concat all inputs and run on deep network
outputI = predict_layer(dropout(latent_layers(keras.layers.concatenate([embed(inp)
for inp, embed in inputs_and_embeddings],
axis = -1))))
## --------> 10]Build model
model = Model( map(itemgetter(0), inputs_and_embeddings),[outputI])
The model only accepts Input
s.该模型只接受
Input
s。 You can't pass embeddings to the inputs of a model.您不能将嵌入传递给模型的输入。
inputs = [Input(sent_maxlen,), dtype='int32', name='word_inputs'),
Input(sent_maxlen,), dtype='int32', name='predicate_inputs')
Input(sent_maxlen,), dtype='int32', name='postags_inputs')]
embeddings = [word_embedding_layer(inputs[0]),
word_embedding_layer(inputs[1]),
pos_embedding_layer(inputs[2])]
Sounds like this:听起来像这样:
outputI = predict_layer(dropout(latent_layers(keras.layers.concatenate(embeddings))))
## --------> 10]Build model
model = Model(inputs, outputI)
you need to convert yours embeddings(either from keras or any other external model like Glove, Bert) into keras inputs like this您需要将您的嵌入(来自 keras 或任何其他外部模型(如 Glove、Bert))转换为这样的 keras 输入
headline_embeddings = model.encode(headlines) #from bert
snippets_embeddings = model.encode(snippets)#from bert
h_embeddings = np.asarray(snippets_embeddings) #into numpy format
s_embeddings = np.asarray(headline_embeddings)
headline = Input(name = 'h_embeddings', shape = [1]) #converting into keras inputs
snippet = Input(name = 's_embeddings', shape = [1])
model = Model(inputs = ([headline, snippet]), outputs = merged) #keras model input
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.