1
model = Sequential()
model.add(Embedding(630, 210))
model.add(LSTM(1024, dropout = 0.2, return_sequences = True))
model.add(LSTM(1024, dropout = 0.2, return_sequences = True))
model.add(Dense(210, activation = 'softmax'))
model.compile(loss = 'categorical_crossentropy', optimizer = 'adam', metrics = ['accuracy'])
filepath = 'ner_2-{epoch:02d}-{loss:.5f}.hdf5'
checkpoint = ModelCheckpoint(filepath, monitor = 'loss', verbose = 1, save_best_only = True, mode = 'min')
callback_list = [checkpoint]
model.fit(X, y , epochs = 20, batch_size = 1024, callbacks = callback_list)
X:輸入矢量是形狀(204564,630,1)keras LSTM模型的輸入和輸出的尺寸不匹配
Y的:目標矢量是形狀的(204564,210,1)
即,每630個投入210個輸出已經被預測但代碼拋出上編譯以下錯誤
ValueError Traceback (most recent call last)
<ipython-input-57-05a6affb6217> in <module>()
50 callback_list = [checkpoint]
51
---> 52 model.fit(X, y , epochs = 20, batch_size = 1024, callbacks = callback_list)
53 print('successful')
ValueError: Error when checking model input: expected embedding_8_input to have 2 dimensions, but got array with shape (204564, 630, 1)
你有一個尺寸太多了,爲什麼它(204564,630,1)而不僅僅是(204564,630)? –
實際上 - 對於630個序列元素中的每一個,您都有210個預測中的一個。您對整個序列有210個預測。你能詳細說明你的'y'代表什麼嗎? –
它似乎也錯誤地定義了「嵌入」層。你的詞彙量和你想要的嵌入暗淡是什麼? –