신은섭(Shin Eun Seop)

kin LB8768

1 +__pychache__/
...\ No newline at end of file ...\ No newline at end of file
No preview for this file type
No preview for this file type
...@@ -84,10 +84,10 @@ if __name__ == '__main__': ...@@ -84,10 +84,10 @@ if __name__ == '__main__':
84 84
85 # User options 85 # User options
86 args.add_argument('--output', type=int, default=1) 86 args.add_argument('--output', type=int, default=1)
87 - args.add_argument('--epochs', type=int, default=10) 87 + args.add_argument('--epochs', type=int, default=100)
88 args.add_argument('--batch', type=int, default=3000) 88 args.add_argument('--batch', type=int, default=3000)
89 args.add_argument('--strmaxlen', type=int, default=400) 89 args.add_argument('--strmaxlen', type=int, default=400)
90 - args.add_argument('--embedding', type=int, default=20) 90 + args.add_argument('--embedding', type=int, default=30)
91 args.add_argument('--threshold', type=float, default=0.5) 91 args.add_argument('--threshold', type=float, default=0.5)
92 config = args.parse_args() 92 config = args.parse_args()
93 93
...@@ -97,30 +97,39 @@ if __name__ == '__main__': ...@@ -97,30 +97,39 @@ if __name__ == '__main__':
97 # 모델의 specification 97 # 모델의 specification
98 input_size = config.embedding*config.strmaxlen 98 input_size = config.embedding*config.strmaxlen
99 output_size = 1 99 output_size = 1
100 - learning_rate = 0.01 100 + learning_rate = 0.001
101 character_size = 251 101 character_size = 251
102 102
103 x = tf.placeholder(tf.int32, [None, config.strmaxlen]) 103 x = tf.placeholder(tf.int32, [None, config.strmaxlen])
104 y_ = tf.placeholder(tf.float32, [None, output_size]) 104 y_ = tf.placeholder(tf.float32, [None, output_size])
105 keep_probs = tf.placeholder(tf.float32) 105 keep_probs = tf.placeholder(tf.float32)
106 # 임베딩 106 # 임베딩
107 - char_embedding = tf.get_variable('char_embedding', [character_size, config.embedding]) 107 + with tf.name_scope('embedding'):
108 - embedded_chars_base = tf.nn.embedding_lookup(char_embedding, x) 108 + char_embedding = tf.get_variable('char_embedding', [character_size, config.embedding])
109 - embedded = tf.expand_dims(embedded_chars_base, -1) 109 + embedded_chars_base = tf.nn.embedding_lookup(char_embedding, x)
110 - print("emb", embedded.shape) 110 + embedded = tf.expand_dims(embedded_chars_base, -1)
111 - ## MODEL 111 + print("emb", embedded.shape)
112 - l3_1 = tf.layers.conv2d(embedded, 512, [3, config.embedding], activation=tf.nn.relu)
113 - print("l3-1", l3_1.shape)
114 - l3_1 = tf.layers.max_pooling2d(l3_1, [character_size-3+1, 1])
115 - print("l3-1 pool", l3_1.shape)
116 - l3_2 = tf.layers.conv2d(l3_1, 1024, [3, config.embedding], activation=tf.nn.relu)
117 - l3_2 = tf.layers.max_pooling2d(l3_2, [character_size-3+1, 1])
118 - l3_3 = tf.layers.conv2d(l3_2, 512, [3, config.embedding], activation=tf.nn.relu)
119 - l3_3 = tf.layers.max_pooling2d(l3_3, [character_size-3+1, 1])
120 - flatten = tf.fontrib.layers.flatten(l3_3)
121 112
122 - drop = tf.layers.dropout(l3_2, keep_probs) 113 + # MODEL
123 - output_sigmoid = tf.layers.dense(flatten, output_size, activation=tf.nn.sigmoid) 114 + l2_conv = tf.layers.conv2d(embedded, 256, [2, config.embedding], activation=tf.nn.relu)
115 + print("l2", l2_conv.shape)
116 + l2_pool = tf.layers.max_pooling2d(l2_conv, [character_size-2+1, 1], strides=(1,1))
117 + print("l2 pool", l2_pool.shape)
118 +
119 + l3_conv = tf.layers.conv2d(embedded, 256, [3, config.embedding], activation=tf.nn.relu)
120 + print("l3", l3_conv.shape)
121 + l3_pool = tf.layers.max_pooling2d(l3_conv, [character_size-3+1, 1], strides=(1,1))
122 + print("l3 pool", l3_pool.shape)
123 +
124 + concat = tf.concat([l2_pool, l3_pool], 3)
125 + print('concat', concat.shape)
126 + flatten = tf.contrib.layers.flatten(concat)
127 + print('flattne', flatten.shape)
128 +
129 + dense = tf.layers.dense(flatten, 256, activation=tf.nn.relu)
130 +
131 + drop = tf.layers.dropout(dense, keep_probs)
132 + output_sigmoid = tf.layers.dense(drop, output_size, activation=tf.nn.sigmoid)
124 133
125 134
126 # loss와 optimizer 135 # loss와 optimizer
...@@ -149,7 +158,7 @@ if __name__ == '__main__': ...@@ -149,7 +158,7 @@ if __name__ == '__main__':
149 avg_loss = 0.0 158 avg_loss = 0.0
150 for i, (data, labels) in enumerate(_batch_loader(dataset, config.batch)): 159 for i, (data, labels) in enumerate(_batch_loader(dataset, config.batch)):
151 _, loss = sess.run([train_step, binary_cross_entropy], 160 _, loss = sess.run([train_step, binary_cross_entropy],
152 - feed_dict={x: data, y_: labels, keep_probs: 0.9}) 161 + feed_dict={x: data, y_: labels, keep_probs: 1.})
153 print('Batch : ', i + 1, '/', one_batch_size, 162 print('Batch : ', i + 1, '/', one_batch_size,
154 ', BCE in this minibatch: ', float(loss)) 163 ', BCE in this minibatch: ', float(loss))
155 avg_loss += float(loss) 164 avg_loss += float(loss)
......