def get_tf_tensor(self, rel_name,
                    shard_id = -1):
    """Get the Tensor that represents a relation.

    Args:
      rel_name: string naming a declared relation
      shard_id: the i'th shard of the matrix. -1 if the matrix is not sharded.

    Returns:
      tf.SparseTensor

    Raises:
      RuntimeError: If the expression has no initial value.
    """
    if shard_id < 0:
      return super(DistributedNeuralQueryContext, self).get_tf_tensor(rel_name)

    sharded_rel_name = self._sharded_rel_name(rel_name, shard_id)
    # construct tensor if it's not been created before, and cache it.
    if sharded_rel_name not in self._cached_tensor:
      if sharded_rel_name not in self._np_initval:
        raise RuntimeError('KG relation named %r has no initial value.' %
                           sharded_rel_name)
      if self.is_dense(rel_name):
        raise TypeError(
            'DistributedNeuralQueryContext does not support dense relation %d' %
            rel_name)

      m = self._np_initval[sharded_rel_name]
      n_rows, n_cols = m.shape
      data_m = np.transpose(np.vstack([m.row, m.col]))
      if self.is_trainable(rel_name):  # construct tf variable if trainable
        data_var_name = 'nql/%s_values' % rel_name
        data_var = tf.Variable(m.data, trainable=True, name=data_var_name)
        sparse_tensor = tf.SparseTensor(data_m, data_var, [n_rows, n_cols])
        assert self._declaration[rel_name].underlying_parameter is None
        self._declaration[rel_name].underlying_parameters[shard_id] = data_var
      else:  # if not trainable, construct a constant tensor
        sparse_tensor = tf.SparseTensor(data_m, m.data, [n_rows, n_cols])

      self._cached_tensor[sharded_rel_name] = sparse_tensor
    return self._cached_tensor[sharded_rel_name]
Get the Tensor that represents a relation.

    Args:
      rel_name: string naming a declared relation
      shard_id: the i'th shard of the matrix. -1 if the matrix is not sharded.

    Returns:
      tf.SparseTensor

    Raises:
      RuntimeError: If the expression has no initial value.
    
language/nql/nql/dist.py