()
| 204 | #e.g. given inputs:[1,0,1,1,0]; outputs:[0,1,1,1,0]. |
| 205 | #invoke test() below to test the model in this toy task. |
| 206 | def test(): |
| 207 | #below is a function test; if you use this for text classifiction, you need to transform sentence to indices of vocabulary first. then feed data to the graph. |
| 208 | num_classes=5 |
| 209 | learning_rate=0.001 |
| 210 | batch_size=8 |
| 211 | decay_steps=1000 |
| 212 | decay_rate=0.95 |
| 213 | sequence_length=5 |
| 214 | vocab_size=10000 |
| 215 | embed_size=100 |
| 216 | is_training=True |
| 217 | dropout_keep_prob=1.0 #0.5 |
| 218 | filter_sizes=[2,3,4] |
| 219 | num_filters=128 |
| 220 | multi_label_flag=True |
| 221 | textRNN=TextCNN(filter_sizes,num_filters,num_classes, learning_rate, batch_size, decay_steps, decay_rate,sequence_length,vocab_size,embed_size,is_training,multi_label_flag=multi_label_flag) |
| 222 | with tf.Session() as sess: |
| 223 | sess.run(tf.global_variables_initializer()) |
| 224 | for i in range(500): |
| 225 | input_x=np.random.randn(batch_size,sequence_length) #[None, self.sequence_length] |
| 226 | input_x[input_x>=0]=1 |
| 227 | input_x[input_x <0] = 0 |
| 228 | input_y_multilabel=get_label_y(input_x) |
| 229 | loss,possibility,W_projection_value,_=sess.run([textRNN.loss_val,textRNN.possibility,textRNN.W_projection,textRNN.train_op], |
| 230 | feed_dict={textRNN.input_x:input_x,textRNN.input_y_multilabel:input_y_multilabel, |
| 231 | textRNN.dropout_keep_prob:dropout_keep_prob,textRNN.tst:False}) |
| 232 | print(i,"loss:",loss,"-------------------------------------------------------") |
| 233 | print("label:",input_y_multilabel);#print("possibility:",possibility) |
| 234 | |
| 235 | def get_label_y(input_x): |
| 236 | length=input_x.shape[0] |
nothing calls this directly
no test coverage detected