【问题标题】:LSTM autoencoder for variable length text input in keras用于 keras 中可变长度文本输入的 LSTM 自动编码器
【发布时间】:2018-04-11 13:17:16
【问题描述】:

这里 padded_docs.shape=(736,50)。因为它是一个自动编码器,输入和输出是相同的。最后一个 LSTM 层的输出是 3 维的,但是作为输出保留的 padded_docs 是 2 维的。如何解决这个问题?

df1=pd.read_csv('snapdeal_data.csv')


df1=df1.head(1000)
df2=df1['Review_Text']
labels=df1['B_Helpfulness']

# encode full sentence into vector
encoded_docs=[one_hot(d,vocab_size) for d in X_train]
print encoded_docs

#####Padding encoded sequence of words
max_length=50
padded_docs = sequence.pad_sequences(encoded_docs, maxlen=max_length, padding='pre')
print padded_docs

model = Sequential()
timesteps = padded_docs.shape[1]
input_dim = max_length
#inputs = Input(shape=(input_dim,))
model.add(Embedding(vocab_size+1, 100,weights=[embedding_matrix],input_length=max_length,trainable=False))
model.add(LSTM(200,return_sequences = True))
model.add(LSTM(100,return_sequences = True))
model.add(LSTM(50))
model.add(RepeatVector(timesteps)) 
model.add(LSTM(100,return_sequences = True))
model.add(LSTM(200,return_sequences = True))
model.add(LSTM(input_dim,return_sequences = True))

model.compile(loss='mean_squared_error', optimizer='Adam')
model.summary()
    `model.fit(padded_docs,padded_docs,epochs=100,batch_size=1,shuffle=True, verbose=2)`


ValueError: Error when checking target: expected lstm_6 to have 3 dimensions, but got array with shape (736, 50)

【问题讨论】:

    标签: keras lstm autoencoder


    【解决方案1】:

    我认为 return_sequences=True 不应保留在任何基于 LSTM 的架构的最后一层。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-12-26
      • 1970-01-01
      • 2018-09-15
      • 2016-11-06
      • 2019-10-13
      • 1970-01-01
      • 2017-11-27
      • 1970-01-01
      相关资源
      最近更新 更多