(attn_dists, padding_mask)
return coverage_loss
Calculates the coverage loss from the attention distributions.

  Args:
    attn_dists: The attention distributions for each decoder timestep. A list length max_dec_steps containing shape (batch_size, attn_length)
    padding_mask: shape (batch_size, max_dec_steps).

  Returns:
    coverage_loss: scalar
Calculates the coverage loss from the attention distributions.
Calculates the coverage loss from the attention distributions .
def _coverage_loss(attn_dists, padding_mask):
  """Calculates the coverage loss from the attention distributions.

  Args:
    attn_dists: The attention distributions for each decoder timestep. A list length max_dec_steps containing shape (batch_size, attn_length)
    padding_mask: shape (batch_size, max_dec_steps).

  Returns:
    coverage_loss: scalar
  """
  coverage = tf.zeros_like(attn_dists[0]) # shape (batch_size, attn_length). Initial coverage is zero.
  covlosses = [] # Coverage loss per decoder timestep. Will be list length max_dec_steps containing shape (batch_size).
  for a in attn_dists:
    covloss = tf.reduce_sum(tf.minimum(a, coverage), [1]) # calculate the coverage loss for this step
    covlosses.append(covloss)
    coverage += a # update the coverage vector
  coverage_loss = _mask_and_avg(covlosses, padding_mask)
  return coverage_loss
def _coverage_loss ( attn_dists , padding_mask ) : coverage = tf . zeros_like ( attn_dists [ 0 ] ) # shape (batch_size, attn_length). Initial coverage is zero. covlosses = [ ] # Coverage loss per decoder timestep. Will be list length max_dec_steps containing shape (batch_size). for a in attn_dists : covloss = tf . reduce_sum ( tf . minimum ( a , coverage ) , [ 1 ] ) # calculate the coverage loss for this step covlosses . append ( covloss ) coverage += a # update the coverage vector coverage_loss = _mask_and_avg ( covlosses , padding_mask ) return coverage_loss