def _extract_argmax_and_embed(embedding, output_projection=None, update_embedding=True):
 def loop_function(prev, _):
  'function that feed previous model output rather than ground truth.'
  if (output_projection is not None):
   prev = tf.nn.xw_plus_b(prev, output_projection[0], output_projection[1])
  prev_symbol = tf.argmax(prev, 1)
  emb_prev = tf.nn.embedding_lookup(embedding, prev_symbol)
  if (not update_embedding):
   emb_prev = tf.stop_gradient(emb_prev)
  return emb_prev
 return loop_function

def _extract_argmax_and_embed ( embedding , output_projection = None , update_embedding = True ) : def loop_function ( prev , _ ) : if ( output_projection is not None ) : prev = tf . nn . xw_plus_b ( prev , output_projection [ 0 ] , output_projection [ 1 ] ) prev_symbol = tf . argmax ( prev , 1 ) emb_prev = tf . nn . embedding_lookup ( embedding , prev_symbol ) if ( not update_embedding ) : emb_prev = tf . stop_gradient ( emb_prev ) return emb_prev return loop_function
get a loop_function that extracts the previous symbol and embeds it .