<jupyter_start><jupyter_text><jupyter_code>https://github.com/vikaskumar04121998/practical-for-deep-learning/blob/main/LSTM.ipynb
import keras
from keras.datasets import mnist
from keras.models import Sequential
from keras.layers import Dense, Dropout, LSTM
from keras.optimizers import Adam
(X_train, y_train),(X_test, y_test) = mnist.load_data()  # unpacks images to x_train/x_test and labels to y_train/y_test

X_train = X_train.astype('float32') / 255.0
X_test = X_test.astype('float32') / 255.0
classifier = Sequential()

classifier.add(LSTM(128, input_shape=(X_train.shape[1:]), return_sequences=True))
classifier.add(Dropout(0.2))
classifier.add(LSTM(128))

classifier.add(Dense(64, activation='relu'))
classifier.add(Dropout(0.2))

classifier.add(Dense(10, activation='softmax'))
classifier.summary()
classifier.compile( loss='sparse_categorical_crossentropy',optimizer=Adam(lr=0.001, decay=1e-6),metrics=['accuracy'] )
history=classifier.fit(X_train,y_train,epochs=6,validation_data=(X_test, y_test))
test_loss, test_acc = classifier.evaluate(X_test, y_test)
print('Test Loss: {}'.format(test_loss))
print('Test Accuracy: {}'.format(test_acc))
from matplotlib import pyplot as plt
plt.clf()
loss = history.history['loss']
val_loss = history.history['val_loss']
epochs = range(1, len(loss) + 1)
plt.plot(epochs, loss, 'g', label='Training loss')
plt.plot(epochs, val_loss, 'y', label='Validation loss')
plt.title('Training and validation loss')
plt.xlabel('Epochs')
plt.ylabel('Loss')
plt.legend()
plt.show()
plt.clf()
acc = history.history['accuracy']
val_acc = history.history['val_accuracy']
plt.plot(epochs, acc, 'g', label='Training acc')
plt.plot(epochs, val_acc, 'y', label='Validation acc')
plt.title('Training and validation accuracy')
plt.xlabel('Epochs')
plt.ylabel('Accuracy')
plt.legend()
plt.show()<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.16054054054054054, 'fraction_numerical': 0.023783783783783784, 'mean_word_length': 8.029268292682927, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, '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': '265788', 'license': 'CC0-1.0', 'n_tokens_mistral': 737, 'n_tokens_neox': 688, 'n_words': 123, 'path': 'LSTM.ipynb', 'repo_name': 'vikaskumar04121998/practical-for-deep-learning', 'size': '1850'}