import tensorflow as tf

    return tf.train.Example(
        features=tf.train.Features(feature=feature_dict)).SerializeToString()

  def _deserialize(self, serialized_data, batch_size):
    """Convert serialized TFRecords into tensors.

    Args:
      serialized_data: A tensor containing serialized records.
      batch_size: The data arrives pre-batched, so batch size is needed to
        deserialize the data.
    """
    feature_map = _TRAIN_FEATURE_MAP if self._is_training else _EVAL_FEATURE_MAP
    features = tf.parse_single_example(serialized_data, feature_map)

    users = tf.reshape(tf.decode_raw(
        features[movielens.USER_COLUMN], rconst.USER_DTYPE), (batch_size,))
    items = tf.reshape(tf.decode_raw(
        features[movielens.ITEM_COLUMN], rconst.ITEM_DTYPE), (batch_size,))

    def decode_binary(data_bytes):
      # tf.decode_raw does not support bool as a decode type. As a result it is
      # necessary to decode to int8 (7 of the bits will be ignored) and then
      # cast to bool.
      return tf.reshape(tf.cast(tf.decode_raw(data_bytes, tf.int8), tf.bool),
                        (batch_size,))

    if self._is_training:
      mask_start_index = tf.decode_raw(
