<jupyter_start><jupyter_text><jupyter_code>import tensorflow as tf
(x_train, y_train), (x_test, y_test) = tf.keras.datasets.reuters.load_data(num_words=10000)
x_train.shape, y_train.shape, x_test.shape, y_test.shape, 
print(y_train[5], x_train[50])
pad_x_train = tf.keras.preprocessing.sequence.pad_sequences(x_train, maxlen=500)
len(pad_x_train[50])
import numpy as np
np.unique(y_train)
len(np.unique(y_train))<jupyter_output><empty_output><jupyter_text>make model<jupyter_code>model = tf.keras.Sequential()
model.add(tf.keras.layers.Embedding(input_length=500, input_dim=10000, output_dim=42)) # input layer
model.add(tf.keras.layers.LSTM(24, return_sequences=True, activation='tanh'))
model.add(tf.keras.layers.LSTM(12, activation='tanh'))
model.add(tf.keras.layers.Flatten()) # hidden layer
model.add(tf.keras.layers.Dense(46, activation='softmax')) # output layer

model.compile(optimizer='adam', loss='sparse_categorical_crossentropy') #gadget
hist = model.fit(pad_x_train, y_train, epochs=100, validation_split=0.3, batch_size=256)<jupyter_output><empty_output><jupyter_text>evaluation<jupyter_code>hist.history.keys()
# 학습 시켰던 데이터
model.evaluate(pad_x_train, y_train)
pad_x_train= tf.keras.preprocessing.sequence.pad_sequences(x_train, maxlen=500)
pad_x_test= tf.keras.preprocessing.sequence.pad_sequences(x_test, maxlen=500)
def pad_make(x_data):
  pad_x= tf.keras.preprocessing.sequence.pad_sequences(x_data, maxlen=500)
  return pad_x
pad_make_x = pad_make(x_test)
model.evaluate(pad_make_x, y_test)
pad_make(x_test)
model.evaluate(pad_x_test, y_test)
import matplotlib.pyplot as plt
hist.history['loss']
plt.plot(hist.history['loss'])
plt.plot(hist.history['val_loss'])
plt.show()
plt.plot(hist.history['acc'])
plt.plot(hist.history['val_acc'])
plt.show()<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.14627363737486096, 'fraction_numerical': 0.025583982202447165, 'mean_word_length': 9.459302325581396, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 13, 'https://': 0, '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': '3', 'dir': 'jupyter-structured-clean-dedup', 'id': '93732', 'license': 'Apache-2.0', 'n_tokens_mistral': 765, 'n_tokens_neox': 725, 'n_words': 89, 'path': 'reuter_LSTM.ipynb', 'repo_name': 'creamcheesesteak/test_deeplearning', 'size': '1798'}