- 머신러닝스터디/2016
- 머신러닝스터디/2016/2016_03_19
- 머신러닝스터디/2016/2016_03_26
- 머신러닝스터디/2016/2016_04_02
- 머신러닝스터디/2016/2016_04_09
- 머신러닝스터디/2016/2016_04_16
- 머신러닝스터디/2016/2016_04_30
- 머신러닝스터디/2016/2016_05_07
- 머신러닝스터디/2016/2016_05_14
- 머신러닝스터디/2016/2016_05_21
- 머신러닝스터디/2016/2016_05_28
- 머신러닝스터디/2016/2016_06_04
- 머신러닝스터디/2016/2016_06_11
- 머신러닝스터디/2016/2016_06_18
- 머신러닝스터디/2016/2016_07_02
- 머신러닝스터디/2016/2016_07_09
- 머신러닝스터디/2016/2016_07_16
- 머신러닝스터디/2016/2016_07_23
- 머신러닝스터디/2016/2016_07_30
- 머신러닝스터디/2016/2016_08_06
- 머신러닝스터디/2016/2016_08_13
- 머신러닝스터디/2016/2016_08_20
- 머신러닝스터디/2016/2016_08_27
- 머신러닝스터디/2016/2016_09_03
- 머신러닝스터디/2016/2016_09_10
- 머신러닝스터디/2016/2016_09_24
- 머신러닝스터디/2016/2016_10_01
- 머신러닝스터디/2016/2016_10_08
- 머신러닝스터디/2016/2016_10_29
- 머신러닝스터디/2016/2016_11_05
- 머신러닝스터디/2016/2016_12_10
- 머신러닝스터디/2016/목차
내용 ¶
- Embedding에는 word index가 필요함.
- 초기에 Tokenizer로 word frequency를 input으로 썼는데 학습이 잘 안됨.
- http://keras.io/layers/embeddings/
- 초기에 Tokenizer로 word frequency를 input으로 썼는데 학습이 잘 안됨.
tokenizer = Tokenizer(nb_words=1000) X_train = tokenizer.sequences_to_matrix(X_train, mode="freq")
- optimizer
- adamax 를 썼는데 accuracy가 50% 대에 머무름
- tensorflow는 adamax를 제공하지 않음. keras 자체 구현됨(code).
- tensorflow는 adamax를 제공하지 않음. keras 자체 구현됨(code).
- adamax 를 썼는데 accuracy가 50% 대에 머무름
코드 ¶
import keras import numpy as np from keras.datasets import imdb from keras.preprocessing.text import Tokenizer from keras.models import Sequential from keras.layers import Dense, Dropout, Embedding, LSTM (X_train, y_train), (X_test, y_test) = imdb.load_data(nb_words=1000) from keras.preprocessing.sequence import pad_sequences X_train = pad_sequences(X_train, 1000) X_test = pad_sequences(X_test, 1000) model = Sequential() model.add(Embedding(1000, 64, input_length=1000)) model.add(LSTM(output_dim=32, activation='sigmoid', inner_activation='hard_sigmoid')) model.add(Dense(16, activation="relu")) model.add(Dropout(0.5)) model.add(Dense(8, activation="relu")) model.add(Dropout(0.5)) model.add(Dense(1, activation="sigmoid")) model.compile(loss="binary_crossentropy", optimizer="adagrad", metrics=["accuracy"]) model.fit(X_train, y_train, batch_size=500, nb_epoch=100) model.evaluate(X_test, y_test, batch_size=1000) pred = model.predict(X_test, batch_size=20000) print (pred[0], y_test[0]) print (pred[1], y_test[1]) print (pred[2], y_test[2])