'A inference method, see T2TModel.'

def infer(self, features=None, decode_length=50, beam_size=1, top_beams=1, last_position_only=False, alpha=0.0):

    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 ('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, 1, 1, 1), dtype=tf.int64)
    features['targets'] = initial_output
    (sharded_logits, _) = self.model_fn(features, False, last_position_only=last_position_only)
    sharded_samples = self._data_parallelism(tf.argmax, sharded_logits, 4)
    samples = tf.concat(sharded_samples, 0)
    with tf.variable_scope(tf.get_variable_scope(), reuse=True):
        features['targets'] = samples
        (sharded_logits, _) = self.model_fn(features, False, last_position_only=last_position_only)
        sharded_samples = self._data_parallelism(tf.argmax, sharded_logits, 4)
        samples = tf.concat(sharded_samples, 0)
    if (inputs_old is not None):
        features['inputs'] = inputs_old
    return samples
