<jupyter_start><jupyter_text>make model<jupyter_code>model = tf.keras.models.Sequential()
model.add(tf.keras.layers.Embedding(input_dim = 10000, output_dim = 24, input_length = 500)) # 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', metrics = ['acc']) # gadget
# hist = model.fit(pad_x_train, y_train, epochs=5, validation_split=0.3, batch_size=128)
hist = model.fit(pad_x_train, y_train, epochs=100, validation_split=0.3, batch_size=256)<jupyter_output>Epoch 1/100
25/25 [==============================] - 23s 765ms/step - loss: 3.7162 - acc: 0.2941 - val_loss: 3.4252 - val_acc: 0.3532
Epoch 2/100
25/25 [==============================] - 18s 735ms/step - loss: 3.2217 - acc: 0.3510 - val_loss: 2.9977 - val_acc: 0.3532
Epoch 3/100
25/25 [==============================] - 19s 750ms/step - loss: 2.8443 - acc: 0.3510 - val_loss: 2.6756 - val_acc: 0.3532
Epoch 4/100
25/25 [==============================] - 19s 750ms/step - loss: 2.6061 - acc: 0.3510 - val_loss: 2.5135 - val_acc: 0.3532
Epoch 5/100
25/25 [==============================] - 19s 747ms/step - loss: 2.5009 - acc: 0.3510 - val_loss: 2.4469 - val_acc: 0.3532
Epoch 6/100
25/25 [==============================] - 19s 747ms/step - loss: 2.4585 - acc: 0.3510 - val_loss: 2.4190 - val_acc: 0.3532
Epoch 7/100
25/25 [==============================] - 18s 740ms/step - loss: 2.4396 - acc: 0.3510 - val_loss: 2.4052 - val_acc: 0.3532
Epoch 8/100
25/25 [==============================] - 18s 734ms[...]<jupyter_text>Evaluation<jupyter_code># 학습 시켰던 데이터
model.evaluate(pad_x_train, y_train)  # epoches: 5, batch_zise: 128 --> loss: 2.4052 (loss율이 너무 높음, 0으로 근접해야 함) - acc: 0.3517

# # x_test 데이터 전처리
# # 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)
# 데이터 전처리 function 만들기
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)
# 학습 시키지 않은 데이터
# model.evaluate(pad_x_test, y_test)    # loss: 2.4171 - acc: 0.3620 (학습시킨 데이터에 비해서 loss율이 높음 -> 모델 학습이 잘됨)
import matplotlib.pyplot as plt
plt.plot(hist.history['loss'])
plt.plot(hist.history['val_loss'], 'r-')
plt.show()
plt.plot(hist.history['acc'])
plt.plot(hist.history['val_acc'], 'r-')
plt.show()
from sklearn.metrics import classification_report
y_train_pred = model.predict(pad_x_train)
y_train_pred[0]
import numpy as np
y_pred = np.argmax(y_train_pred, axis=1)
y_pred.shape
len(y_train)
print(classification_report(y_train, y_pred))
y_test_pred = model.predict(pad_x_test)
y_pred = np.argmax(y_test_pred, axis=1)
print(classification_report(y_test, y_pred))<jupyter_output>precision    recall  f1-score   support

           0       0.00      0.00      0.00        12
           1       0.20      0.04      0.06       105
           2       0.00      0.00      0.00        20
           3       0.92      0.88      0.90       813
           4       0.86      0.71      0.78       474
           5       0.00      0.00      0.00         5
           6       0.00      0.00      0.00        14
           7       0.00      0.00      0.00         3
           8       0.07      0.32      0.11        38
           9       0.00      0.00      0.00        25
          10       0.00      0.00      0.00        30
          11       0.22      0.43      0.29        83
          12       0.00      0.00      0.00        13
          13       0.06      0.19      0.09        37
          14       0.00      0.00      0.00         2
          15       0.00      0.00      0.00         9
          16       0.15      0.17      0.16        99
          17       0.00    [...]<jupyter_text>ServiceTOKYO, Aug 6 (Reuters) - Two Belarus coaches who cut short sprinter Krystsina Tsimanouskaya's Tokyo Games have had their accreditation revoked and were removed from the athletes village, the IOC said on Friday.<jupyter_code># 문장 입력
# ---> 숫자(사전을 기준) ---> [ ,  ,  , ...] ---> pad_sequence


model.predict<jupyter_output><empty_output>