我對神經網絡相當陌生,我正在用LSTM做我自己的「Hello World」,而不是複製一些東西。我選擇了一個簡單的邏輯如下:LSTM訓練模式
輸入3個時步。第一個是1或0,另外2個是隨機數。預期輸出與輸入的第一個時間步相同。數據饋送看起來像:
_X0=[1,5,9] _Y0=[1] _X1=[0,5,9] _Y1=[0] ... 200 more records like this.
這個簡單的(?)邏輯可以訓練100%的準確性。我進行了很多測試,我發現最有效的模型是3個LSTM圖層,每個圖層都有15個隱藏單元。這在22個時期後返回100%的準確度。但是我注意到了一些我很難理解的東西:在前12個時代,模型根本沒有任何進展,而是通過準確度(acc。停留0.5)來衡量,而且只有分類交叉測量的邊際進度(從0.69到0.65 )。然後從時代12到時代22,它的訓練速度非常快,精度爲1.0。問題是:爲什麼培訓會像這樣發生?爲什麼前12個時代沒有取得進展,爲什麼12到22年的效率更高?
這裏是我的全部代碼:
from keras.models import Sequential
from keras.layers import Input, Dense, Dropout, LSTM
from keras.models import Model
import helper
from keras.utils.np_utils import to_categorical
x_,y_ = helper.rnn_csv_toXY("LSTM_hello.csv",3,"target")
y_binary = to_categorical(y_)
model = Sequential()
model.add(LSTM(15, input_shape=(3,1),return_sequences=True))
model.add(LSTM(15,return_sequences=True))
model.add(LSTM(15, return_sequences=False))
model.add(Dense(2, activation='softmax', kernel_initializer='RandomUniform'))
model.compile(optimizer='adam',
loss='categorical_crossentropy',
metrics=['acc'])
model.fit(x_, y_binary, epochs=100)
您正在使用哪種版本的Keras?你可以發佈培訓日誌嗎? – nemo
我使用Keras 2.0.3 – Manngo