code: def _padding_for_dimension(data, axis, pad_value):
      """Tile `pad_value` so it can be used to pad `data` at the given axis.
  
      Returns a tensor `result` that has the same shape as `data` up to dimension
      `axis`, but where each value `data[i0...iaxis]` is replaced by `pad_value`.
      I.e., returns `result[i0...iaxis, j0...jN] = pad_value[j0...jN]`
      (where `N=rank(pad_value)`).
  
      Args:
        data: The potentially ragged tensor that will be padded.
        axis: The axis along which padding will be added.
        pad_value: The padding value that should be used, or None if no padding will
          be added.  `rank(pad_value)` must be `rank(data) - axis`, and
          `pad_value.shape[1:]` must be compatible with `data.shape[axis + 1:]`.
  
      Returns:
        A padding tensor with the same rank as `data`, which can be concatenated
        to `data` to add padding.
      """
      if pad_value is None:
          return None
  
      # Verify shape compatibility.
      pad_value.shape[1:].assert_is_compatible_with(
          data.shape[axis:][1:]
      )
  
      if not isinstance(data, ragged_tensor.RaggedTensor):
          data_shape = array_ops.shape(data)
          pad_shape = array_ops.shape(pad_value)
          outer_dimensions = data_shape[:axis]
          expanded_pad_shape = array_ops.concat(
              [array_ops.ones_like(outer_dimensions), pad_shape], axis=0
          )
          tile_multiples = array_ops.concat(
              [outer_dimensions, array_ops.ones_like(pad_shape)], axis=0
          )
          tiled_padding = array_ops.tile(
              array_ops.reshape(pad_value, expanded_pad_shape),
              tile_multiples,
          )
          tiled_padding.set_shape(
              data.shape[:axis].concatenate(pad_value.shape)
          )
          return tiled_padding
  
      assert axis >= 0
      # Return the padding as-is if we're padding the outermost dimension.
      if axis == 0:
          return pad_value
  
      elif axis == 1:
          if isinstance(pad_value, ragged_tensor.RaggedTensor):
              pad_rank = (
                  array_ops.rank(pad_value.flat_values)
                  + pad_value.ragged_rank
              )
              pad_nrows = pad_value.nrows()
          else:
              pad_rank = array_ops.rank(pad_value)
              pad_nrows = array_ops.shape(
                  pad_value, out_type=dtypes.int64
              )[0]
  
          # Return a RaggedTensor that has the same number of rows as `data`, where
          # each row contains a single copy of `pad_value`.
          data_nrows = data.nrows()
          pad_repeats = array_ops.concat(
              [
                  [math_ops.cast(data_nrows, dtypes.int32)],
                  array_ops.ones([pad_rank - 1], dtypes.int32),
              ],
              axis=0,
          )
          result_values = array_ops.tile(pad_value, pad_repeats)
          return ragged_tensor.RaggedTensor.from_row_splits(
              result_values,
              math_ops.range(0, data_nrows + 1) * pad_nrows,
          )
  
      else:  # Recurse if axis>1.
          return ragged_tensor.RaggedTensor.from_row_splits(
              _padding_for_dimension(data.values, axis - 1, pad_value),
              data.row_splits,
          )
  
file_path: text/tensorflow_text/python/ops/pad_along_dimension_op.py
imports: from __future__ import absolute_import
  from __future__ import print_function
  from tensorflow.python.framework import dtypes
  from tensorflow.python.framework import errors
  from tensorflow.python.framework import ops
  from tensorflow.python.ops import array_ops
  from tensorflow.python.ops import math_ops
  from tensorflow.python.ops.ragged import ragged_tensor
label_desc: Use image node_id 3 for calling a global function with example usage: _padding_for_dimension(data, axis, pad_value) and returns: None, tiled_padding, pad_value, ragged_tensor, ragged_tensor