@@ -41,7 +41,7 @@ def make_batch(seq_data):
4141 # label 값을 one-hot 인코딩으로 넘겨줘야 하지만,
4242 # 이 예제에서 사용할 손실 함수인 sparse_softmax_cross_entropy_with_logits 는
4343 # one-hot 인코딩을 사용하지 않으므로 index 를 그냥 넘겨주면 됩니다.
44- target_batch .append ([ target ] )
44+ target_batch .append (target )
4545
4646 return input_batch , target_batch
4747
@@ -67,7 +67,7 @@ def make_batch(seq_data):
6767# 출력값과의 계산을 위한 원본값의 형태는 다음과 같습니다.
6868# [batch size, time steps]
6969# 기존처럼 one-hot 인코딩을 사용한다면 입력값의 형태는 [None, n_class] 여야합니다.
70- Y = tf .placeholder (tf .int32 , [None , 1 ])
70+ Y = tf .placeholder (tf .int32 , [None ])
7171
7272W = tf .Variable (tf .random_normal ([n_hidden , n_class ]))
7373b = tf .Variable (tf .random_normal ([n_class ]))
@@ -90,17 +90,10 @@ def make_batch(seq_data):
9090outputs = tf .transpose (outputs , [1 , 0 , 2 ])
9191outputs = outputs [- 1 ]
9292model = tf .matmul (outputs , W ) + b
93- # 단, sparse_softmax_cross_entropy_with_logits 함수의 labels 는
94- # one-hot 인코딩을 사용하지 않기 때문에, 1차원 배열로 넘겨줍니다. (time step 이 1이기 때문)
95- # [[1]]
96- # [[2]]
97- # [[3]]
98- # ... -> [1], [2], [3] ...
99- labels = tf .reshape (Y , [- 1 ])
10093
10194cost = tf .reduce_mean (
10295 tf .nn .sparse_softmax_cross_entropy_with_logits (
103- logits = model , labels = labels ))
96+ logits = model , labels = Y ))
10497
10598optimizer = tf .train .AdamOptimizer (learning_rate ).minimize (cost )
10699
@@ -127,7 +120,7 @@ def make_batch(seq_data):
127120# 레이블값이 정수이므로 예측값도 정수로 변경해줍니다.
128121prediction = tf .cast (tf .argmax (model , 1 ), tf .int32 )
129122# one-hot 인코딩이 아니므로 입력값을 그대로 비교합니다.
130- prediction_check = tf .equal (prediction , labels )
123+ prediction_check = tf .equal (prediction , Y )
131124accuracy = tf .reduce_mean (tf .cast (prediction_check , tf .float32 ))
132125
133126# wor, coo, lov, kis 를 가지고 단어를 추측해보겠습니다.
0 commit comments