main computation graph here: 1.embedding-->2.CONV-BN-RELU-MAX_POOLING-->3.linear classifier
(self)
| 62 | self.b_projection = tf.get_variable("b_projection",shape=[self.num_classes]) #[label_size] #ADD 2017.06.09 |
| 63 | |
| 64 | def inference(self): |
| 65 | """main computation graph here: 1.embedding-->2.CONV-BN-RELU-MAX_POOLING-->3.linear classifier""" |
| 66 | # 1.=====>get emebedding of words in the sentence |
| 67 | self.embedded_words = tf.nn.embedding_lookup(self.Embedding,self.input_x)#[None,sentence_length,embed_size] |
| 68 | self.sentence_embeddings_expanded=tf.expand_dims(self.embedded_words,-1) #[None,sentence_length,embed_size,1). expand dimension so meet input requirement of 2d-conv |
| 69 | |
| 70 | # 2.=====>loop each filter size. for each filter, do:convolution-pooling layer(a.create filters,b.conv,c.apply nolinearity,d.max-pooling)---> |
| 71 | # you can use:tf.nn.conv2d;tf.nn.relu;tf.nn.max_pool; feature shape is 4-d. feature is a new variable |
| 72 | #if self.use_mulitple_layer_cnn: # this may take 50G memory. |
| 73 | # print("use multiple layer CNN") |
| 74 | # h=self.cnn_multiple_layers() |
| 75 | #else: # this take small memory, less than 2G memory. |
| 76 | print("use single layer CNN") |
| 77 | h=self.cnn_single_layer() |
| 78 | #5. logits(use linear layer)and predictions(argmax) |
| 79 | with tf.name_scope("output"): |
| 80 | logits = tf.matmul(h,self.W_projection) + self.b_projection #shape:[None, self.num_classes]==tf.matmul([None,self.embed_size],[self.embed_size,self.num_classes]) |
| 81 | return logits |
| 82 | |
| 83 | def cnn_single_layer(self): |
| 84 | pooled_outputs = [] |
no test coverage detected