'A slow greedy inference method.
Quadratic time in decode_length.
Args:
features: an map of string to `Tensor`
decode_length: an integer.  How many additional timesteps to decode.
last_position_only: a boolean, speed-up by computing last position only.
Returns:
samples: an integer `Tensor`.
logits: `Tensor` of shape [batch_size, time, 1, 1, vocab_size].
losses: a dictionary: {loss-name (string): floating point `Scalar`}'

def _greedy_infer(self, features, decode_length, last_position_only):

    if (not features):
        features = {}
    inputs_old = None
    if (('inputs' in features) and (len(features['inputs'].shape) < 4)):
        inputs_old = features['inputs']
        features['inputs'] = tf.expand_dims(features['inputs'], 2)
    if (not self.has_input):
        features['partial_targets'] = tf.to_int64(features['inputs'])
    def infer_step(recent_output, recent_logits, unused_loss):
        'Inference    step.'
        recent_output.set_shape([None, None, None, 1])
        padded = tf.pad(recent_output, [[0, 0], [0, 1], [0, 0], [0, 0]])
        features['targets'] = padded
        (samples, logits, losses) = self.sample(features, last_position_only=last_position_only)
        if last_position_only:
            cur_sample = samples[:, (-1), :, :]
        else:
            cur_sample = samples[:, tf.shape(recent_output)[1], :, :]
        cur_sample = tf.to_int64(tf.expand_dims(cur_sample, axis=1))
        samples = tf.concat([recent_output, cur_sample], axis=1)
        samples.set_shape([None, None, None, 1])
        logits = tf.concat([recent_logits, logits[0][:, (-1):]], 1)
        loss = sum(losses.values())
        return (samples, logits, loss)
    if ('partial_targets' in features):
        initial_output = tf.convert_to_tensor(features['partial_targets'])
    else:
        batch_size = tf.shape(features['inputs'])[0]
        initial_output = tf.zeros((batch_size, 0, 1, 1), dtype=tf.int64)
    initial_output = tf.slice(initial_output, [0, 0, 0, 0], tf.shape(initial_output))
    target_modality = self._hparams.problems[self._problem_idx].target_modality
    if _is_class_modality(target_modality):
        decode_length = 1
    else:
        decode_length = (tf.shape(features['inputs'])[1] + decode_length)
    result = initial_output
    logits = tf.zeros((batch_size, 0, 1, 1, target_modality.top_dimensionality))
    logits.set_shape([None, None, None, None, None])
    loss = 0.0
    (result, logits, loss) = tf.while_loop((lambda result, logits, loss: (tf.shape(result)[1] < decode_length)), infer_step, [result, logits, loss], shape_invariants=[tf.TensorShape([None, None, None, None]), tf.TensorShape([None, None, None, None, None]), tf.TensorShape([])], back_prop=False, parallel_iterations=1)
    if (inputs_old is not None):
        features['inputs'] = inputs_old
    losses = {'training': loss}
    return (result, logits, losses)
