def sequence_loss_by_example(inputs, targets, weights, loss_function, average_across_timesteps=True, name=None):
 if ((len(targets) != len(inputs)) or (len(weights) != len(inputs))):
  raise ValueError(('Lengths of logits, weights, and targets must be the same %d, %d, %d.' % (len(inputs), len(weights), len(targets))))
 with tf.op_scope(((inputs + targets) + weights), name, 'sequence_loss_by_example'):
  log_perp_list = []
  for (inp, target, weight) in zip(inputs, targets, weights):
   crossent = loss_function(inp, target)
   log_perp_list.append((crossent * weight))
  log_perps = tf.add_n(log_perp_list)
  if average_across_timesteps:
   total_size = tf.add_n(weights)
   total_size += 1e-12
   log_perps /= total_size
 return log_perps

def sequence_loss_by_example ( inputs , targets , weights , loss_function , average_across_timesteps = True , name = None ) : if ( ( len ( targets ) != len ( inputs ) ) or ( len ( weights ) != len ( inputs ) ) ) : raise ValueError ( ( 'Lengths of logits, weights, and targets must be the same %d, %d, %d.' % ( len ( inputs ) , len ( weights ) , len ( targets ) ) ) ) with tf . op_scope ( ( ( inputs + targets ) + weights ) , name , 'sequence_loss_by_example' ) : log_perp_list = [ ] for ( inp , target , weight ) in zip ( inputs , targets , weights ) : crossent = loss_function ( inp , target ) log_perp_list . append ( ( crossent * weight ) ) log_perps = tf . add_n ( log_perp_list ) if average_across_timesteps : total_size = tf . add_n ( weights ) total_size += 1e-12 log_perps /= total_size return log_perps
sampled softmax loss for a sequence of inputs .