title: Why is the use of return_sequences giving different results across different environments?
body: <p>When I use return_sequences = true, for a LSTM layer, before adding a dense layer it sometimes results in an error depending upon the environment. I believe it mainly depends on the version of tensorflow and keras. If I am using tensorflow <code>2.1.0</code> and Keras <code>2.3.0</code>, I get the following error -</p>
  <p><code>standardize_input_data</code>                                                                                                      <code>'with shape ' + str(data_shape))                                                                                    ValueError: Error when checking target: expected dense_2 to have 3 dimensions, but got array with shape (7000, 1)</code></p>
  <p>However, if I use tensorflow <code>2.9.1</code> and keras <code>2.9.0</code> I do not get any error.</p>
  <p>Here is some minimal working sample code -</p>
  <pre><code>import os
  import pandas as pd
  from sklearn import preprocessing
  from collections import deque
  import random
  import numpy as np
  import time
  import random
  from keras.models import Sequential
  from keras.layers import Dense, Dropout, LSTM, BatchNormalization, Input
  from keras.models import load_model
  import keras
  from sklearn.datasets import make_classification
  from sklearn.model_selection import train_test_split
  import pickle
  
  epochs = 10
  batch_size = 64
  
  X, y = make_classification(n_samples=10000, n_features=3, n_classes=3, n_informative=3, n_redundant=0, n_repeated=0 ,weights=[0.5,0.5,0.5])
  X = X.reshape(X.shape[0], 1, 3)
  y = y.reshape(-1, 1)
  X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.3, random_state=0)
  
  inputs = Input(shape=(X_train.shape[1:]))
  outputs = LSTM(128, input_shape=(X_train.shape[1:]), return_sequences=True)(inputs)
  outputs = Dropout(0.2)(outputs)
  outputs = BatchNormalization()(outputs)
  outputs = LSTM(128, input_shape=(X_train.shape[1:]), return_sequences=True)(outputs)
  outputs = Dropout(0.2)(outputs)
  outputs = BatchNormalization()(outputs)
  outputs = Dense(32, activation=&quot;relu&quot;, kernel_initializer=&quot;glorot_uniform&quot;)(outputs)
  outputs = Dropout(0.2)(outputs)
  outputs = Dense(3, activation=&quot;softmax&quot;, kernel_initializer=&quot;glorot_uniform&quot;)(outputs)
  
  model = keras.Model(inputs, outputs)
  
  opt = keras.optimizers.Adam(lr=0.0001, decay=1e-6)
  
  model.compile(loss='sparse_categorical_crossentropy',
               optimizer=opt,
               metrics=['accuracy'])
  
  model.fit(X_train, y_train,
            batch_size=batch_size, 
            epochs=epochs,
            validation_data=(X_test, y_test))
  </code></pre>