(self, features, training)
return loss, {"logits": logits_BxTxV}
Create model.

    Args:
      features: dictionary of tensors including "inputs" [batch, input_len] and
        "targets" [batch, output_len]
      training: bool of whether the mode is training.

    Returns:
     Tuple of (loss, outputs): Loss is a scalar. Output is a dictionary of
       tensors, containing model's output logits.
Create model.
Create model .
def __call__(self, features, training):
    """Create model.

    Args:
      features: dictionary of tensors including "inputs" [batch, input_len] and
        "targets" [batch, output_len]
      training: bool of whether the mode is training.

    Returns:
     Tuple of (loss, outputs): Loss is a scalar. Output is a dictionary of
       tensors, containing model's output logits.
    """
    if "inputs" not in features or "targets" not in features:
      raise ValueError("Require inputs and targets keys in features.")

    context = self._encode(features, training)
    self._context = context
    targets_BxT = features["targets"]
    bias_1xTxT = attention.upper_triangle_bias(
        tf.shape(targets_BxT)[1], self._dtype)
    states_BxTxD = self._embedding_layer(targets_BxT, True)
    states_BxTxD = tf.pad(states_BxTxD, [[0, 0], [1, 0], [0, 0]])[:, :-1, :]
    states_BxTxD = timing.add_time_signal(states_BxTxD)
    states_BxTxD = self._dropout_fn(states_BxTxD, training)
    with tf.variable_scope(self._decoder_scope_name, reuse=tf.AUTO_REUSE):
      states_BxTxD = transformer_block.stack(self._decoder_layers, training,
                                             states_BxTxD, bias_1xTxT,
                                             context["memory"],
                                             context["memory_bias"])
      states_BxTxD = contrib_layers.layer_norm(states_BxTxD, begin_norm_axis=2)
    logits_BxTxV = self._embedding_layer(states_BxTxD, False)
    targets_mask_BxT = tf.cast(tf.greater(targets_BxT, 0), self._dtype)
    loss = tf.losses.softmax_cross_entropy(
        tf.one_hot(targets_BxT, self._vocab_size),
        logits_BxTxV,
        label_smoothing=self._label_smoothing,
        weights=targets_mask_BxT)
    return loss, {"logits": logits_BxTxV}
def __call__ ( self , features , training ) : if "inputs" not in features or "targets" not in features : raise ValueError ( "Require inputs and targets keys in features." ) context = self . _encode ( features , training ) self . _context = context targets_BxT = features [ "targets" ] bias_1xTxT = attention . upper_triangle_bias ( tf . shape ( targets_BxT ) [ 1 ] , self . _dtype ) states_BxTxD = self . _embedding_layer ( targets_BxT , True ) states_BxTxD = tf . pad ( states_BxTxD , [ [ 0 , 0 ] , [ 1 , 0 ] , [ 0 , 0 ] ] ) [ : , : - 1 , : ] states_BxTxD = timing . add_time_signal ( states_BxTxD ) states_BxTxD = self . _dropout_fn ( states_BxTxD , training ) with tf . variable_scope ( self . _decoder_scope_name , reuse = tf . AUTO_REUSE ) : states_BxTxD = transformer_block . stack ( self . _decoder_layers , training , states_BxTxD , bias_1xTxT , context [ "memory" ] , context [ "memory_bias" ] ) states_BxTxD = contrib_layers . layer_norm ( states_BxTxD , begin_norm_axis = 2 ) logits_BxTxV = self . _embedding_layer ( states_BxTxD , False ) targets_mask_BxT = tf . cast ( tf . greater ( targets_BxT , 0 ) , self . _dtype ) loss = tf . losses . softmax_cross_entropy ( tf . one_hot ( targets_BxT , self . _vocab_size ) , logits_BxTxV , label_smoothing = self . _label_smoothing , weights = targets_mask_BxT ) return loss , { "logits" : logits_BxTxV }