检查目标时出错:预期embedding_44具有形状(50,50),但数组具有形状(40435100,1)

时间:2019-06-02 14:30:38

标签: python keras lstm

我正在尝试使用lstm查找重复的问题,与该链接中与我相关的问题几乎相同:https://medium.com/@sabber/classifying-yelp-review-comments-using-lstm-and-word-embeddings-part-1-eb2275e4066b

所有对lstm进行排序的标记化都已完成!但是当我拟合模型时,错误会发生在keras嵌入中。它工作正常,但我不知道我做了什么更改,现在最终变成这样=检查目标时出错:预期embedding_44具有形状(50,50)但得到形状为数组(40435100,1)

我已经尝试了几乎所有方法,但没有用,请帮忙!!对不起,如果我用英语表达的方式激怒了您。

她是我的代码

from keras.layers.embeddings import Embedding
import numpy as np
from keras.layers import LSTM
from keras.preprocessing.sequence import pad_sequences
from keras.preprocessing.text import Tokenizer , text_to_word_sequence

tokenizer = Tokenizer()
sequences = tokenizer.texts_to_sequences(df['question1'])
sequences2 = tokenizer.texts_to_sequences(df['question2'])
sequences3 =  tokenizer.texts_to_sequences(df['is_duplicate'])
data = pad_sequences(sequences, maxlen=50)
data2 = pad_sequences(sequences2, maxlen=50)
data3 = pad_sequences(sequences3, maxlen = 100)

Input= np.concatenate((data,data2), axis = 0)


Input = Input.reshape((1,40435100 , 1))        
Output = data3.reshape((1,40435100 ,1 ))

Mainmodel = Sequential()
Mainmodel.add(LSTM(50, dropout=0.2, recurrent_dropout=0.2))
Mainmodel.add(Embedding(80871, 50, input_length=50))
Mainmodel.compile(loss='mean_absolute_error', optimizer='adam',  metrics=['accuracy'])


X_train,X_test,y_train,y_test = train_test_split( Input,  Output,   test_size = 0.2, random_state = 4)

Final = Mainmodel.fit(X_train, y_train, epochs = 2, validation_data =    (X_test,y_test)) 

here the error shows up: checking target: expected embedding_44 to have shape (50, 50) but got   array with shape (40435100, 1)

Expected output is just to start the training process but got stuck in Mainmodel.fit

0 个答案:

没有答案