2017-04-06 1 views
0

私のLSTMモデルに何が問題なのか迷っています。私は11の入力と2つの出力クラス(ワンホットエンコード)と非常に迅速に、1バッチかそこらのように、エラーは出力クラスの1つの%に移動してそこにとどまります。LSTMモデルエラーは1つの出力クラスのパーセントです

私は、印刷重みとバイアスを試してみましたが、それらはすべてのNaNに満ちているように見えます。私は学習率、または層/ユニットと周りの混乱を減らした場合、私はそれがゆっくりと1つのクラスのエラーの%に達するように取得することができます

が、常にその時点までに取得しているようです。あなたは1ホットエンコーディングを使用sparse_softmax_cross_entropy_with_logits代わりのtf.nn.softmax_cross_entropy_with_logitsを持っているので

num_units = 30 
num_layers = 50 
dropout_rate = 0.80 
learning_rate=0.0001 
batch_size = 180 
epoch = 1 

input_classes = len(train_input[0]) 
output_classes = len(train_output[0]) 

data = tf.placeholder(tf.float32, [None, input_classes, 1]) #Number of examples, number of input, dimension of each input 
target = tf.placeholder(tf.float32, [None, output_classes]) #one-hot encoded: [1,0] = bad, [0,1] = good 
dropout = tf.placeholder(tf.float32) 

cell = tf.contrib.rnn.LSTMCell(num_units, state_is_tuple=True) 
cell = tf.contrib.rnn.DropoutWrapper(cell, output_keep_prob=dropout) 
cell = tf.contrib.rnn.MultiRNNCell([cell] * num_layers, state_is_tuple=True) 

#Input shape [batch_size, max_time, depth], output shape: [batch_size, max_time, cell.output_size] 
val, _ = tf.nn.dynamic_rnn(cell, data, dtype=tf.float32) 

val = tf.transpose(val, [1, 0, 2]) #reshapes it to [sequence_size, batch_size, depth] 

#get last entry as it includes previous results 
last = tf.gather(val, int(val.get_shape()[0]) - 1) 

weight = tf.get_variable("W", shape=[num_units, output_classes], initializer=tf.contrib.layers.xavier_initializer()) 
bias = tf.get_variable("B", shape=[output_classes], initializer=tf.contrib.layers.xavier_initializer()) 
logits = tf.matmul(last, weight) + bias 

prediction = tf.nn.softmax_cross_entropy_with_logits(logits=logits, labels=target) 
prediction = tf.clip_by_value(prediction, 1e-10,100.0) 

cost = tf.reduce_mean(prediction) 

optimizer = tf.train.AdamOptimizer(learning_rate=learning_rate) 
minimize = optimizer.minimize(cost) 

mistakes = tf.not_equal(tf.argmax(target, 1), tf.argmax(logits, 1)) 
error = tf.reduce_mean(tf.cast(mistakes, tf.float32)) 

init_op = tf.global_variables_initializer() 
saver = tf.train.Saver() 
sess = tf.Session() 
sess.run(init_op) 

no_of_batches = int((len(train_input))/batch_size) 
for i in range(epoch): 
    ptr = 0 
    for j in range(no_of_batches): 
     inp, out = train_input[ptr:ptr+batch_size], train_output[ptr:ptr+batch_size] 
     ptr+=batch_size 
     sess.run(minimize,{data: inp, target: out, dropout: dropout_rate }) 

sess.close() 
+0

メモリの通知のいずれかのうちはありますか? –

+0

@ShamaneSiriwardhanaいいえ、間違いなし。私も複数のマシンで試してみました。 – nemasu

答えて

1

は、ここでは、コードです。

は2つの機能の違いを理解するために、このstackoverflowの答えを参照してください。
1

+0

ああ、私は実際にその記事を読んだが、それを後ろに持っていた。これまで、私はさまざまなコスト関数も試していたと言われていましたが、以前はコード= predictor = tf.nn.softmax(tf.matmul(last、weight)+ bias)と予測= tf.nn.softmax(tf.matmul最後に、体重)+バイアス)。しかし、同じことが起こります。 – nemasu

+0

正確さは変わらない?それは一つの価値に固執していますか? –

+0

ミニバッチサイズが5のように非常に小さい場合は、値を決めるのに通常約1〜3のミニバッチが必要です。バッチサイズが大きい場合は、エラー率1クラスパーセンテージで即座に解決します。明らかに、これは他のパラメータに依存します。ほとんどの場合、即時です。また、ラベルを疎テンソルに変換し、sparse_softmax_cross_entropy_with_logitsを使用しましたが、同じ結果が得られます。たとえば、私のテストデータは[0,1]クラスの約32%を占めており、精度はすぐに変わり、変更されません。 – nemasu

関連する問題