MCPcopy Create free account
hub / github.com/brightmart/text_classification / loss

Method loss

a02_TextCNN/p7_TextCNN_model.py:174–183  ·  view source on GitHub ↗
(self,l2_lambda=0.0001)

Source from the content-addressed store, hash-verified

172 return loss
173
174 def loss(self,l2_lambda=0.0001):#0.001
175 with tf.name_scope("loss"):
176 #input: `logits`:[batch_size, num_classes], and `labels`:[batch_size]
177 #output: A 1-D `Tensor` of length `batch_size` of the same type as `logits` with the softmax cross entropy loss.
178 losses = tf.nn.sparse_softmax_cross_entropy_with_logits(labels=self.input_y, logits=self.logits);#sigmoid_cross_entropy_with_logits.#losses=tf.nn.softmax_cross_entropy_with_logits(labels=self.input_y,logits=self.logits)
179 #print("1.sparse_softmax_cross_entropy_with_logits.losses:",losses) # shape=(?,)
180 loss=tf.reduce_mean(losses)#print("2.loss.loss:", loss) #shape=()
181 l2_losses = tf.add_n([tf.nn.l2_loss(v) for v in tf.trainable_variables() if 'bias' not in v.name]) * l2_lambda
182 loss=loss+l2_losses
183 return loss
184
185 def train_old(self):
186 """based on the loss, use SGD to update parameter"""

Callers 1

__init__Method · 0.95

Calls

no outgoing calls

Tested by

no test coverage detected