<jupyter_start><jupyter_text>https://machinelearningmastery.com/lstm-autoencoders/<jupyter_code># LSTM Autoencoder predict sequence
from numpy import array

from tensorflow.keras.models import Sequential
from tensorflow.keras.layers import LSTM, Dense, RepeatVector, TimeDistributed
from tensorflow.keras.utils import plot_model
# Define input sequence
seq_in = array([0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9])
# Reshape input into [samples, timesteps, features]
n_in = len(seq_in)
seq_in = seq_in.reshape((1, n_in, 1))
# Prepare output sequence
seq_out = seq_in[:, 1:, :]
n_out = n_in - 1
# Define model
model = Sequential()
model.add(LSTM(100, activation='relu', input_shape=(n_in,1)))
model.add(RepeatVector(n_out))
model.add(LSTM(100, activation='relu', return_sequences=True))
model.add(TimeDistributed(Dense(1)))
model.compile(optimizer='adam', loss='mse')
plot_model(model, show_shapes=True, to_file='predict_lstm_autoencoder.png')
# Fit model
model.fit(seq_in, seq_out, epochs=3000, verbose=0)
# Demonstrate recreation
yhat = model.predict(seq_in, verbose=0)
print(yhat[0,:,0])<jupyter_output>[0.19999112 0.30012015 0.39973423 0.5000296  0.60014915 0.7000598
 0.79989016 0.900015  ]
{'fraction_non_alphanumeric': 0.1407035175879397, 'fraction_numerical': 0.08877721943048576, 'mean_word_length': 6.810457516339869, 'pattern_counts': {'":': 0, '<': 4, '<?xml version=': 0, '>': 4, 'https://': 1, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '1', 'dir': 'jupyter-structured-clean-dedup', 'id': '138884', 'license': 'MIT', 'n_tokens_mistral': 533, 'n_tokens_neox': 464, 'n_words': 94, 'path': '3_Image_Related_Neural_Networks/Autoencoders/LSTMautoencoderPredict.ipynb', 'repo_name': 'vladiant/SoftUniDeepLearning2019', 'size': '1194'}