keras - 尝试训练 NLP 模型时出现值错误
问题描述
'''
epochs = 2 #### before: 30 #### setting lower to save time
input_text = Input(shape=(400, ))
input_title = Input(shape=(20, ))
input_nontext = Input(shape=(25, )) ######## input_nontext = Input(shape=(25, ))
# Text
text_embeddings = Embedding(NUM_WORDS_TEXT, output_dim=100,
embeddings_initializer=Constant(wiki_weights_text),
input_length=400, trainable=False)(input_text)
LSTM_text = LSTM(100, return_sequences=False)(text_embeddings)
dense_text = Dense(1, activation="linear")(LSTM_text)
# Title
title_embeddings = Embedding(NUM_WORDS_TITLE, output_dim=100,
embeddings_initializer=Constant(wiki_weights_title),
input_length=20, trainable=False)(input_title)
LSTM_title = LSTM(100, return_sequences=False)(title_embeddings)
dense_title = Dense(1, activation="linear")(LSTM_title)
# Concatenate
concat = concatenate([dense_text, dense_title, input_nontext])
dense_full = Dense(1024, activation="relu")(concat)
dense_full = Dense(512, activation="relu")(dense_full)
dense_full = Dense(256, activation="relu")(dense_full)
output_layer = Dense(1, activation="linear")(dense_full)
model = Model(inputs=[input_text, input_title, input_nontext], outputs = output_layer)
model.compile(loss = losses.LogCosh(), optimizer = "adam", metrics=['mae', 'mse'])
print(model.summary())
callbacks = [EarlyStopping(monitor='val_loss', patience=3, verbose=1, min_delta=0.01, restore_best_weights=True)]
story = model.fit([X_tr_int_pad_text, X_tr_int_pad_title, X_train_text.drop(columns=["summary_clean", "name_clean"])],
y_train_text, epochs=epochs, verbose=1, batch_size=256, validation_split=0.2, callbacks=callbacks)
'''
我收到以下错误:ValueError: Error when checks input: expected input_53 to have shape (25,) but got array with shape (4,)
由于我已经在第 5 行定义了形状,所以我不明白为什么会出现这个错误。任何帮助将不胜感激,谢谢!
解决方案
推荐阅读
- c# - IIS 托管网站未在另一台机器上运行。尽我所能,但无法找到问题
- javascript - 如何在不使用php javascript提交的情况下在多选下拉列表中输出所有选定选项的文本
- c++ - 如何在 C++ VS 中使用原始字符串文字(编码问题)
- javascript - 更改背景图像 css 导致添加额外的 div
- parsing - 防止 objdump 换行
- c++ - 如何将 void 转换为 typedef void(...)(float)
- codeigniter - Codeigniter 不是 CHMOD 777 目录
- sql - 如果它们的值组合外观大于 1,则基于 2 列的组合将表列与表的其他列更新
- android - ConnectivityManager.getActiveNetworkInfo() / NetworkInfo 在 API 29 中已弃用。有什么替代方案?
- java - 在Java中从String转换为Json Array时获得空Json Array