Aman Oswal
Aman Oswal

Reputation: 49

Many To One LSTM

I am trying to solve a multiclass classification problem with 1,00,000 examples, 128 time-steps, and 7 input features. Possible output classes are 5. My code for the model is

model = Sequential()
model.add(LSTM(5 , input_shape=(128, 7)))
model.compile(loss="binary_crossentropy", optimizer="adam", metrics=["accuracy"])
model.fit(v_s,y_s)

I want to know how does the model understands I want an output of [1,5] only from the last node after receiving the last time step input, which is to act like many to one LSTM. The other way model can think is getting 5 atomic outputs from the last 5 nodes(many to many). How will I do the latter?

Upvotes: 0

Views: 69

Answers (1)

user12501244
user12501244

Reputation: 11

See this link: https://keras.io/getting-started/sequential-model-guide/ The output of above code is a sequence of dimension 5 which will act as prediction for 5 classes. So the above model is running properly.

model = Sequential()
model.add(LSTM(50 , input_shape=(128, 7)))
model.compile(loss="binary_crossentropy", optimizer="adam", metrics=["accuracy"])
model.fit(v_s,y_s)

This will produce incorrect output

Upvotes: 1

Related Questions