<jupyter_start><jupyter_text><jupyter_code>from tensorflow.keras.datasets import imdb
vocab_size = 2000
(x_train,y_train),(x_test,y_test) = imdb.load_data(num_words=vocab_size)
x_train.shape,x_test.shape,y_train.shape,y_test.shape
print(x_train[1])
import numpy as np
len(x_train[1]),len(x_train[200])
from tensorflow.keras.preprocessing.sequence import pad_sequences
X_train = pad_sequences(x_train, maxlen=300)
import tensorflow as tf
model = tf.keras.models.Sequential()
import numpy as np
np.unique(y_train)<jupyter_output><empty_output><jupyter_text>tf.keras.layers.Embedding(보케블러리 사이즈, 차원 사이즈 , 랭스=패드시퀀스 값)<jupyter_code>model.add(tf.keras.layers.Embedding(input_dim=vocab_size, output_dim=50, input_length=300))
model.add(tf.keras.layers.GlobalAveragePooling1D())
model.add(tf.keras.layers.Dense(1,activation='sigmoid'))

model.compile(optimizer='adam', loss='binary_crossentropy', )
hist = model.fit(X_train,y_train, epochs=10, batch_size=128, validation_split=0.2)
model.predict(X_train[5:6]) # loss: 0.6932 - val_loss: 0.6931<jupyter_output><empty_output><jupyter_text>[Callback EarlyStopping](https://www.tensorflow.org/api_docs/python/tf/keras/callbacks/EarlyStopping)tf.keras.callbacks.EarlyStopping교육 중 합당하게 도달하거나 튀면 에포크만큼 진행하지 않고 멈춤벨리데이션 로스가 올라가기 직전에서 (과적합막음) 멈춤```tf.keras.callbacks.EarlyStopping(    monitor='val_loss', min_delta=0, patience=0, verbose=0,    mode='auto', baseline=None, restore_best_weights=False)```모니터(monitor=) 하는 값이 (patience)의 갯수 만큼 모드(mode)에 맞게 동작햇으면 멈춰라<jupyter_code>es = tf.keras.callbacks.EarlyStopping(monitor='val_loss', patience=4, mode ='min', verbose=1)
es
hist = model.fit(X_train,y_train, epochs=20, batch_size=128, validation_split=0.2, callbacks=[es])<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.1397228637413395, 'fraction_numerical': 0.028868360277136258, 'mean_word_length': 9.134502923976608, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 13, 'https://': 1, 'lorem ipsum': 0, 'www.': 1, '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': '380623', 'license': 'Apache-2.0', 'n_tokens_mistral': 821, 'n_tokens_neox': 834, 'n_words': 96, 'path': 'NLP/AverageWordEmbedding.ipynb', 'repo_name': 'ginttone/multi_deeplearning', 'size': '1732'}