小编Dol*_*a34的帖子

警告:警告:tensorflow:Model 是用形状 (None, 150) 构建的,但它在形状不兼容的输入上被调用 (None, 1)

所以我试图建立一个词嵌入模型,但我一直收到这个错误。在训练过程中,准确率没有变化,val_loss 保持“nan”

数据的原始形状是

x.shape, y.shape
((94556,), (94556, 2557))
Run Code Online (Sandbox Code Playgroud)

然后我重塑它:

xr= np.asarray(x).astype('float32').reshape((-1,1))
yr= np.asarray(y).astype('float32').reshape((-1,1))
((94556, 1), (241779692, 1))
Run Code Online (Sandbox Code Playgroud)

然后我通过我的模型运行它

model = Sequential()
model.add(Embedding(2557, 64, input_length=150, embeddings_initializer='glorot_uniform'))
model.add(Flatten())
model.add(Reshape((64,), input_shape=(94556, 1)))
model.add(Dense(512, activation='sigmoid'))
model.add(Dense(128, activation='sigmoid'))
model.add(Dense(64, activation='relu'))
model.add(Dense(10, activation='sigmoid'))
model.add(Dense(1, activation='relu'))
# compile the mode
model.compile(optimizer='adam', loss='categorical_crossentropy', metrics=['accuracy'])
# summarize the model
print(model.summary())
plot_model(model, show_shapes = True, show_layer_names=False)
Run Code Online (Sandbox Code Playgroud)

训练后,我得到了每个时期的恒定准确度和 val_loss nan

history=model.fit(xr, yr, epochs=20, batch_size=32, validation_split=3/9)

Epoch 1/20
WARNING:tensorflow:Model was constructed with shape (None, 150) for input Tensor("embedding_6_input:0", shape=(None, 150), dtype=float32), but …
Run Code Online (Sandbox Code Playgroud)

python reshape keras tensorflow word-embedding

5
推荐指数
1
解决办法
2万
查看次数

标签 统计

keras ×1

python ×1

reshape ×1

tensorflow ×1

word-embedding ×1