original_docstring: Get loss based on triplet type.
docstring: Get loss based on triplet type.
docstring_tokens: Get loss based on triplet type .
code: def _get_loss(self):
      """Get loss based on triplet type."""
  
      if self.triplet_type == 'a':
        self.score_anchor_pos = self._scores_pairwise(self.nn_anchor, self.nn_pos)
        self.score_anchor_neg = self._scores_pairwise(self.nn_anchor, self.nn_neg)
        self.score_pos_neg = self._scores_pairwise(self.nn_pos, self.nn_neg)
  
        self.score_neg = tf.minimum(self.score_anchor_neg, self.score_pos_neg)
        self.loss_triplet = (tf.reduce_sum(tf.nn.relu(self.score_anchor_pos -
                                                      self.score_neg + 1)))
        tf.logging.info('Set symmetric triplet loss')
  
      else:
  
        self.score_anchor_pos = self._scores_pairwise(self.nn_anchor,
                                                      self.nn_pos)
        self.score_anchor_all_neg = self._scores_all_negs(self.nn_anchor,
                                                          self.nn_neg)
  
        # Loss (changed on Oct 21, 2017 from Alternative 1 to Alternative 2)
        beta = self.beta
        difference = (tf.expand_dims(self.score_anchor_pos/beta, 1) -
                      self.score_anchor_all_neg/beta)  # postives x negatives
  
        # Alternative 1 - log-sum-exp loss
        # log(\sum_j(exp(d+ - dj-)))
        # loss = tf.reduce_sum(beta * tf.reduce_logsumexp(difference, 1), 0)
  
        # Alternative 2 - log(1 + \sum_j(exp(d+ - dj-))), makes it more robust
        difference_padded = tf.pad(difference, [[0, 0], [0, 1]])
        loss = tf.reduce_sum(beta * tf.reduce_logsumexp(difference_padded, 1), 0)
        self.loss_triplet = loss
  
        tf.logging.info('Set batch triplet loss')
code_tokens: def _get_loss ( self ) : if self . triplet_type == 'a' : self . score_anchor_pos = self . _scores_pairwise ( self . nn_anchor , self . nn_pos ) self . score_anchor_neg = self . _scores_pairwise ( self . nn_anchor , self . nn_neg ) self . score_pos_neg = self . _scores_pairwise ( self . nn_pos , self . nn_neg ) self . score_neg = tf . minimum ( self . score_anchor_neg , self . score_pos_neg ) self . loss_triplet = ( tf . reduce_sum ( tf . nn . relu ( self . score_anchor_pos - self . score_neg + 1 ) ) ) tf . logging . info ( 'Set symmetric triplet loss' ) else : self . score_anchor_pos = self . _scores_pairwise ( self . nn_anchor , self . nn_pos ) self . score_anchor_all_neg = self . _scores_all_negs ( self . nn_anchor , self . nn_neg ) beta = self . beta difference = ( tf . expand_dims ( self . score_anchor_pos / beta , 1 ) - self . score_anchor_all_neg / beta ) difference_padded = tf . pad ( difference , [ [ 0 , 0 ] , [ 0 , 1 ] ] ) loss = tf . reduce_sum ( beta * tf . reduce_logsumexp ( difference_padded , 1 ) , 0 ) self . loss_triplet = loss tf . logging . info ( 'Set batch triplet loss' )
short_docstring: Get loss based on triplet type.
short_docstring_tokens: Get loss based on triplet type .
comment: """Get loss based on triplet type."""$SEP$# Loss (changed on Oct 21, 2017 from Alternative 1 to Alternative 2)$SEP$# postives x negatives$SEP$# Alternative 1 - log-sum-exp loss$SEP$# log(\sum_j(exp(d+ - dj-)))$SEP$# loss = tf.reduce_sum(beta * tf.reduce_logsumexp(difference, 1), 0)$SEP$# Alternative 2 - log(1 + \sum_j(exp(d+ - dj-))), makes it more robust