tensorflow 실행중 학습이 전혀 되지 않습니다.

import numpy as np
import tensorflow as tf
sess = tf.Session()

x = [[1,0,0,0],# 4*4  #h
        [0,1,0,0], #e
        [0,0,1,0], #l
        [0,0,0,1]] #o

y = [[0,1,0,0], # 5*4
        [0,0,1,0],
        [0,0,1,0],
        [0,0,0,1]]

c_ = 0.5 * tf.constant([[1,0,0,0], # 4*4
                        [0,2,0,0],
                        [0,0,3,0],
                        [0,0,0,2]], dtype=tf.float32)

h_ = 0.5 * tf.constant([[1,0,0,0], # 4*4
                       [0,1,0,0],
                       [0,0,1,0],
                       [0,0,0,1]], dtype=tf.float32)

X = tf.placeholder(dtype=tf.float32, shape=[None, 4])
Y = tf.placeholder(dtype=tf.float32, shape=[None, 4])
W = tf.Variable(tf.random_normal([4, 1]))
b = tf.Variable(tf.random_normal([1]))
sess.run(tf.global_variables_initializer())

#he
#el
#ll
#lo

seq_len = 4
num_units = 4

class lstm:
    def build(c, h):
        args = tf.concat((X,h), axis=1)

        out_size = 4 * num_units
        proj_size = args.shape[-1]

        weights = tf.ones([proj_size, out_size]) * 0.5

        out = tf.matmul(args, weights)

        bias = tf.ones([out_size]) * 0.5

        concat = out + bias

        i, j, f, o = tf.split(concat, 4, 1)

        g = tf.tanh(j)

        def sigmoid_array(x):
            return 1 / (1 + tf.exp(-x))

        forget_bias = 1.0

        sigmoid_f = sigmoid_array(f + forget_bias)

        sigmoid_array(i) * g

        new_c = c * sigmoid_f + sigmoid_array(i) * g

        new_h = tf.tanh(new_c) * sigmoid_array(o)

        return new_c, new_h

ta_c = tf.TensorArray(size=seq_len, dtype=tf.float32)
ta_h = tf.TensorArray(size=seq_len, dtype=tf.float32)

def body(last_state, last_output, step, ta_c, ta_h):

    output = lstm.build(last_state, last_output)[0]
    state = lstm.build(last_state, last_output)[1]
    ta_c = ta_c.write(step, state)
    ta_h = ta_h.write(step, output)
    return state, output, tf.add(step, 1), ta_c, ta_h


timesteps = seq_len

steps = lambda a, b, step, c, d: tf.less(step, timesteps)

lstm_output, lstm_state, step, ta_c, ta_h = tf.while_loop(steps, body, (c_, h_, 0, ta_c, ta_h), parallel_iterations=20)

output = lstm_output[-1]
output = tf.reshape(output, [-1, 4])
logits = tf.matmul(lstm_output, W) + b

cost = tf.reduce_mean(tf.nn.softmax_cross_entropy_with_logits_v2(logits=logits, labels=Y))
train = tf.train.AdamOptimizer(0.1).minimize(cost)

is_correct = tf.equal(tf.argmax(logits, 1), tf.argmax(Y, 1))
accuracy = tf.reduce_mean(tf.cast(is_correct, tf.float32))

sess.run(tf.global_variables_initializer())

for i in range(1000):
    sess.run(train, feed_dict={X:x, Y:y})
    a, c = sess.run([accuracy, cost],feed_dict={X:x, Y:y})
    print("##############",a)
    print("##############",c)

구차한 변명이지만 이 코드를 며칠 동안 잡고 있었지만 코스트가 왜 내려가지 않는지 전혀 알지 못 하겠습니다...

############## 0.0
############## 1.3862944
############## 0.0
############## 1.3862944
############## 0.0
############## 1.3862944
############## 0.0
############## 1.3862944
############## 0.0
############## 1.3862944

X플레이스 홀더를 식 내부에 넣어서 새로웃 output과 rnn cell을 연결하였다고 생각했는데 그게 아니었던 것 같습니다. 뭐가 문제일까요..? 도움이 필요합니다ㅠㅠ....

ᕕ( ᐛ )ᕗ
로그인이 필요합니다

작성한 답변에 다른 개발자들이 댓글을 작성하거나 댓글에 좋아요/싫어요를 할 수 있기 때문에 계정을 필요로 합니다.